From ebf2ae5abadc06765fcc17e89ff3d2ad1a421bb8 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期五, 08 十二月 2023 13:35:49 +0800
Subject: [PATCH] 设备加工工件个数报表

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcProcessCountController.java |   22 ++++++-
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcProcessCountMapper.xml      |   39 +++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcProcessCountDto.java               |   18 ++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcProcessCountMapper.java         |   13 ++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcProcessCountVo.java                 |    9 ++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/ProcessCountServiceImpl.java |   50 ++++++++++++++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IProcessCountService.java         |   17 +++++
 7 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcProcessCountController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcProcessCountController.java
index 29e9c9c..9b1599c 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcProcessCountController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcProcessCountController.java
@@ -1,14 +1,26 @@
 package org.jeecg.modules.mdc.controller;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.mdc.dto.MdcProcessCountDto;
 import org.jeecg.modules.mdc.entity.MdcProcessCount;
 import org.jeecg.modules.mdc.service.IProcessCountService;
+import org.jeecg.modules.mdc.vo.MdcProcessCountVo;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * @author Lius
@@ -32,7 +44,7 @@
      * @param pageSize
      * @param req
      * @return
-     *//*
+     */
     @AutoLog(value = "mdc璁惧鍔犲伐涓暟琛�-鍒嗛〉鍒楄〃鏌ヨ")
     @ApiOperation(value = "mdc璁惧鍔犲伐涓暟琛�-鍒嗛〉鍒楄〃鏌ヨ", notes = "mdc璁惧鍔犲伐涓暟琛�-鍒嗛〉鍒楄〃鏌ヨ")
     @GetMapping(value = "/list")
@@ -40,6 +52,10 @@
                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                    HttpServletRequest req) {
-
-    }*/
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = user.getId();
+        Page<MdcProcessCountDto> page = new Page<MdcProcessCountDto>(pageNo, pageSize);
+        IPage<MdcProcessCountDto> pageList = processCountService.pageList(userId, page, mdcProcessCountVo, req);
+        return Result.OK(pageList);
+    }
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcProcessCountDto.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcProcessCountDto.java
new file mode 100644
index 0000000..076b602
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcProcessCountDto.java
@@ -0,0 +1,18 @@
+package org.jeecg.modules.mdc.dto;
+
+import lombok.Data;
+
+/**
+ * @author Lius
+ * @date 2023/12/8 10:38
+ */
+@Data
+public class MdcProcessCountDto {
+    private String equipmentId;
+    private String equipmentName;
+    private String driveType;
+    private String theData;
+    private String sequenceNumber;
+    private Long duration;
+    private Integer processCount;
+}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcProcessCountMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcProcessCountMapper.java
index 198b7db..4606be3 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcProcessCountMapper.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcProcessCountMapper.java
@@ -1,8 +1,12 @@
 package org.jeecg.modules.mdc.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.mdc.dto.MdcProcessCountDto;
 import org.jeecg.modules.mdc.entity.MdcProcessCount;
+import org.jeecg.modules.mdc.vo.MdcProcessCountVo;
 
 /**
  * @author Lius
@@ -10,4 +14,13 @@
  */
 public interface MdcProcessCountMapper extends BaseMapper<MdcProcessCount> {
     MdcProcessCount getLastData(@Param("equipmentId") String equipmentId);
+
+    /**
+     * 鍒嗛〉鏌ヨ
+     *
+     * @param page
+     * @param mdcProcessCountVo
+     * @return
+     */
+    IPage<MdcProcessCountDto> pageList(Page<MdcProcessCountDto> page, @Param("mdcProcessCountVo") MdcProcessCountVo mdcProcessCountVo);
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcProcessCountMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcProcessCountMapper.xml
index 555bc70..202d360 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcProcessCountMapper.xml
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcProcessCountMapper.xml
@@ -5,4 +5,43 @@
     <select id="getLastData" resultType="org.jeecg.modules.mdc.entity.MdcProcessCount">
         SELECT TOP 1 * FROM mdc_process_count WHERE equipment_id = #{equipmentId} ORDER BY the_date DESC
     </select>
+
+    <!--鍒嗛〉鏌ヨ-->
+    <select id="pageList" resultType="org.jeecg.modules.mdc.dto.MdcProcessCountDto">
+        SELECT
+            t1.equipment_id equipmentId,
+            MAX(t1.equipment_name) equipmentName,
+            MAX(t2.drive_type) driveType,
+            t1.the_date theDate,
+            t1.sequence_number sequenceNumber,
+            COUNT(*) processCount,
+            SUM(t1.duration) duration
+        FROM
+            mdc_process_count t1
+            LEFT JOIN mdc_equipment t2 ON t1.equipment_id = t2.equipment_id
+        <where>
+            <if test="mdcProcessCountVo.equipmentId != null and mdcProcessCountVo.equipmentId != ''">
+                AND t1.equipment_id = #{ mdcProcessCountVo.equipmentId }
+            </if>
+            <if test="mdcProcessCountVo.equipmentName != null and mdcProcessCountVo.equipmentName != ''">
+                AND t1.equipment_name LIKE CONCAT(CONCAT('%',#{mdcProcessCountVo.equipmentName}),'%')
+            </if>
+            <if test="mdcProcessCountVo.driveType != null and mdcProcessCountVo.driveType != ''">
+                AND t2.drive_type = #{ mdcProcessCountVo.driveType }
+            </if>
+            <if test="mdcProcessCountVo.startTime != null and mdcProcessCountVo.startTime != '' and mdcProcessCountVo.endTime != '' and mdcProcessCountVo.endTime != null">
+                AND t1.the_date BETWEEN #{ mdcProcessCountVo.startTime } AND #{ mdcProcessCountVo.endTime }
+            </if>
+            <if test="mdcProcessCountVo.mdcSectionIds != null and mdcProcessCountVo.mdcSectionIds.size() > 0 ">
+                AND t1.equipment_id IN
+                <foreach collection="mdcProcessCountVo.mdcSectionIds" item="id" index="index" open="(" close=")" separator=",">
+                    #{ id }
+                </foreach>
+            </if>
+        </where>
+        GROUP BY
+            t1.equipment_id,
+            t1.the_date,
+            t1.sequence_number
+    </select>
 </mapper>
\ No newline at end of file
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IProcessCountService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IProcessCountService.java
index e9311ed..08e4346 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IProcessCountService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IProcessCountService.java
@@ -1,7 +1,13 @@
 package org.jeecg.modules.mdc.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.mdc.dto.MdcProcessCountDto;
 import org.jeecg.modules.mdc.entity.MdcProcessCount;
+import org.jeecg.modules.mdc.vo.MdcProcessCountVo;
+
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * @author Lius
@@ -14,4 +20,15 @@
      */
     void runningProcessCount();
 
+    /**
+     * 鍒嗛〉鏌ヨ
+     *
+     * @param userId
+     * @param page
+     * @param mdcProcessCountVo
+     * @param req
+     * @return
+     */
+    IPage<MdcProcessCountDto> pageList(String userId, Page<MdcProcessCountDto> page, MdcProcessCountVo mdcProcessCountVo, HttpServletRequest req);
+
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/ProcessCountServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/ProcessCountServiceImpl.java
index 50fee45..7db1dce 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/ProcessCountServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/ProcessCountServiceImpl.java
@@ -1,19 +1,24 @@
 package org.jeecg.modules.mdc.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
+import org.jeecg.modules.mdc.dto.MdcProcessCountDto;
 import org.jeecg.modules.mdc.entity.*;
 import org.jeecg.modules.mdc.mapper.MdcProcessCountMapper;
 import org.jeecg.modules.mdc.service.*;
 import org.jeecg.modules.mdc.util.DateUtils;
 import org.jeecg.modules.mdc.util.TimeFieldUtils;
 import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo;
+import org.jeecg.modules.mdc.vo.MdcProcessCountVo;
 import org.jeecg.modules.mdc.vo.MdcShiftDateVo;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -47,7 +52,7 @@
     @Transactional(rollbackFor = {Exception.class})
     public void runningProcessCount() {
         // 鑾峰彇鎵�鏈夎澶�
-        List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140244"));
+        List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list();
         List<MdcProcessCount> result = new ArrayList<>();
         for (MdcEquipment mdcEquipment : mdcEquipmentList) {
             List<MdcProcessCount> mdcProcessCountList = processCount(mdcEquipment);
@@ -60,6 +65,49 @@
         }
     }
 
+    /**
+     * 鍒嗛〉鏌ヨ
+     *
+     * @param userId
+     * @param page
+     * @param mdcProcessCountVo
+     * @param req
+     * @return
+     */
+    @Override
+    public IPage<MdcProcessCountDto> pageList(String userId, Page<MdcProcessCountDto> page, MdcProcessCountVo mdcProcessCountVo, HttpServletRequest req) {
+        List<String> equipmentIds = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcProcessCountVo.getParentId()) && StringUtils.isEmpty(mdcProcessCountVo.getEquipmentId())) {
+            if ("2".equals(mdcProcessCountVo.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcProcessCountVo.getParentId());
+            } else {
+                //浜х嚎灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProcessCountVo.getParentId());
+            }
+        } else if (StringUtils.isNotEmpty(mdcProcessCountVo.getEquipmentId())) {
+            //鍗曞彴璁惧淇℃伅
+            mdcProcessCountVo.setMdcSectionIds(Collections.singletonList(mdcProcessCountVo.getEquipmentId()));
+        } else {
+            //鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭�
+            if ("2".equals(mdcProcessCountVo.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
+            } else {
+                //浜х嚎灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
+            }
+        }
+        if (mdcProcessCountVo.getMdcSectionIds() == null || mdcProcessCountVo.getMdcSectionIds().isEmpty()) {
+            mdcProcessCountVo.setMdcSectionIds(equipmentIds);
+        }
+
+        if (mdcProcessCountVo.getMdcSectionIds() == null || mdcProcessCountVo.getMdcSectionIds().isEmpty()) {
+            return null;
+        }
+        return this.baseMapper.pageList(page, mdcProcessCountVo);
+    }
+
     @Transactional(readOnly = true)
     List<MdcProcessCount> processCount(MdcEquipment mdcEquipment) {
         Date initDate = null;
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcProcessCountVo.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcProcessCountVo.java
index 5fe9c6c..1f91d82 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcProcessCountVo.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcProcessCountVo.java
@@ -2,6 +2,8 @@
 
 import lombok.Data;
 
+import java.util.List;
+
 /**
  * @author Lius
  * @date 2023/12/7 16:55
@@ -9,8 +11,13 @@
 @Data
 public class MdcProcessCountVo {
     private String equipmentId;
+    private String equipmentIds;
     private String equipmentName;
     private String driveType;
     private String sequenceNumber;
-    private String theDate;
+    private String startTime;
+    private String endTime;
+    private String parentId;
+    private String typeTree;
+    private List<String> mdcSectionIds;
 }

--
Gitblit v1.9.3