From 2c2413760b6467bf62402dba7338bd3bbcbd7341 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期二, 20 五月 2025 14:20:38 +0800
Subject: [PATCH] 添加产量报表功能页面

---
 JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java |  185 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 182 insertions(+), 3 deletions(-)

diff --git a/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java b/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java
index fbdfe0d..242a9f5 100644
--- a/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java
+++ b/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java
@@ -3,8 +3,10 @@
 import cn.smallbun.screw.core.util.CollectionUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.mes.md.entity.KBBTJPDrawingBP;
 import com.mes.md.entity.KBBTProgramsOperationLogBP;
 import com.mes.md.entity.TaskingLog;
+import com.mes.md.mapper.KBBTJPDrawingBPMapper;
 import com.mes.md.mapper.KBBTProgramsOperationLogBPMapper;
 import com.mes.md.mapper.TaskingLogMapper;
 import com.mes.md.service.TaskingLogService;
@@ -12,9 +14,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -31,12 +32,190 @@
 
     @Autowired
     KBBTProgramsOperationLogBPMapper kBBTProgramsOperationLogBPMapper;
+    @Autowired
+    KBBTJPDrawingBPMapper kBBTJPDrawingBPMapper;
+
+    @Override
+    public List<Map> selectMechanicalReport(int dayCount, Date startDate, Date endDate, String taskType, String operationRecord, String lineType) {
+        try {
+            // 鏋勫缓鏌ヨ鏉′欢
+            QueryWrapper<TaskingLog> taskingWrapper = new QueryWrapper<>();
+
+            // 娣诲姞瀹屽伐鐘舵�佽繃婊�
+            taskingWrapper.eq("work_state", "瀹屽伐");
+
+            // 鏃堕棿鑼冨洿澶勭悊
+            if (startDate != null && endDate != null) {
+                taskingWrapper.ge("operation_record_time", startDate)
+                        .le("operation_record_time", endDate);
+            } else if (dayCount > 0) {
+                // 濡傛灉娌℃湁鏃堕棿鑼冨洿锛屼娇鐢ㄩ粯璁ょ殑dayCount
+                Calendar cal = Calendar.getInstance();
+                cal.setTime(new Date());
+                cal.set(Calendar.HOUR_OF_DAY, 0);
+                cal.set(Calendar.MINUTE, 0);
+                cal.set(Calendar.SECOND, 0);
+                cal.set(Calendar.MILLISECOND, 0);
+                cal.add(Calendar.DATE, 1 - dayCount);
+                Date defaultStartDate = cal.getTime();
+                Date defaultEndDate = new Date();
+                
+                taskingWrapper.ge("operation_record_time", defaultStartDate)
+                        .le("operation_record_time", defaultEndDate);
+            }
+
+            // 娣诲姞鍙�夋潯浠�
+            if (taskType != null && !taskType.isEmpty()) {
+                taskingWrapper.eq("task_type", taskType);
+            }
+            if (operationRecord != null && !operationRecord.isEmpty()) {
+                taskingWrapper.like("operation_record", operationRecord);
+            }
+            if (lineType != null && !lineType.isEmpty()) {
+                taskingWrapper.apply("operation_record REGEXP '.*[^0-9]" + lineType + "$'");
+            }
+
+            // 鎸夋椂闂存帓搴�
+            taskingWrapper.orderByDesc("operation_record_time");
+
+            // 鎵ц鏌ヨ
+            List<Map<String, Object>> taskingList = baseMapper.selectMaps(taskingWrapper);
+
+            // 鐩存帴杩斿洖鏌ヨ缁撴灉
+            return new ArrayList<>(taskingList);
+        } catch (Exception e) {
+            log.error("鏌ヨ寮傚父", e);
+            throw e;
+        }
+    }
 
     public List<TaskingLog> findTaskingLog(){
         return new ArrayList<TaskingLog>();
     }
 
     /**
+     * 鏌ヨ dayCount 澶�  瀹屽伐鏁伴噺-鍒嗙嚎璺�
+     */
+    @Override
+    public List<Map> selectTaskingLog(int dayCount) {
+        Calendar cal = Calendar.getInstance();
+        //璁剧疆褰撳墠鏃堕棿
+        cal.setTime(new Date());
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        cal.add(Calendar.DATE, 1-dayCount);
+        Date startDate = cal.getTime();
+
+        QueryWrapper<KBBTJPDrawingBP> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("CAST(PlanDate AS DATE) AS CreateDate,isNull(sum(task_quantity),0) as task_quantity_sum")
+                .gt("PlanDate",startDate).groupBy("CAST(PlanDate AS DATE)")
+                .orderByAsc("CAST(PlanDate AS DATE)");
+        List<Map> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
+
+        List<Map<String, Object>> listTasking1 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
+                .select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
+                .eq("task_type", "瀹氬埗")
+                .eq("operation_record", "鏃嬭浆1")
+                .eq("operation_mode", "缁撴潫")
+                .gt("operation_record_time", startDate)
+                .groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
+        List<Map<String, Object>> listTasking2 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
+                .select("task_type,operation_record,operation_mode,DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time,count(1) as count")
+                .eq("task_type", "瀹氬埗")
+                .eq("operation_record", "鏃嬭浆2")
+                .eq("operation_mode", "缁撴潫")
+                .gt("operation_record_time", startDate)
+                .groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
+
+        //鏍囧噯涓婄墖璁板綍
+        List<Map<String, Object>> loadTaskingList1 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
+                .select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
+                .eq("task_type", "鏍囧噯")
+                .eq("operation_record", "涓婄墖1")
+                .eq("operation_mode", "缁撴潫")
+                .gt("operation_record_time", startDate)
+                .groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
+        List<Map<String, Object>> loadTaskingList2 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
+                .select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
+                .eq("task_type", "鏍囧噯")
+                .eq("operation_record", "涓婄墖2")
+                .eq("operation_mode", "缁撴潫")
+                .gt("operation_record_time", startDate)
+                .groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
+
+        // 瀛樺偍姣忔潯绾胯矾鐨勬暟鎹�
+        Map<String, Map<String, Integer>> lineDataMap = new HashMap<>();
+        lineDataMap.put("line1", new HashMap<>());
+        lineDataMap.put("line2", new HashMap<>());
+
+        // 澶勭悊绗竴鏉$嚎璺暟鎹�
+        // 澶勭悊鏃嬭浆1缁撴潫璁板綍
+        for (Map<String, Object> map : listTasking1) {
+            String date = map.get("operation_record_time").toString();
+            int count = Integer.parseInt(map.get("count").toString());
+            Map<String, Integer> line1Map = lineDataMap.get("line1");
+            line1Map.put(date, line1Map.getOrDefault(date, 0) + count);
+        }
+        // 澶勭悊绾胯矾1涓婄墖璁板綍
+        for (Map<String, Object> map : loadTaskingList1) {
+            String date = map.get("operation_record_time").toString();
+            int count = Integer.parseInt(map.get("count").toString());
+            Map<String, Integer> line1Map = lineDataMap.get("line1");
+            line1Map.put(date, line1Map.getOrDefault(date, 0) + count);
+        }
+
+        // 澶勭悊绗簩鏉$嚎璺暟鎹�
+        // 澶勭悊鏃嬭浆2缁撴潫璁板綍
+        for (Map<String, Object> map : listTasking2) {
+            String date = map.get("operation_record_time").toString();
+            int count = Integer.parseInt(map.get("count").toString());
+            Map<String, Integer> line2Map = lineDataMap.get("line2");
+            line2Map.put(date, line2Map.getOrDefault(date, 0) + count);
+        }
+        // 澶勭悊绾胯矾2涓婄墖璁板綍
+        for (Map<String, Object> map : loadTaskingList2) {
+            String date = map.get("operation_record_time").toString();
+            int count = Integer.parseInt(map.get("count").toString());
+            Map<String, Integer> line2Map = lineDataMap.get("line2");
+            line2Map.put(date, line2Map.getOrDefault(date, 0) + count);
+        }
+
+
+        //log.info("瀹㈡埛琛ㄨ鍒掗噺锛歿},{},{}",list,listTasking1,listTasking2);
+        List<Map> Result=new ArrayList<>();
+        for (int i=0;i<dayCount;i++){
+            Date thisdate=cal.getTime();
+            cal.add(Calendar.DATE, 1);
+            Map thisMap=new HashMap<>();
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String dateString = sdf.format(thisdate);
+            thisMap.put("date",dateString);
+            
+            // 鑾峰彇涓�绾挎暟鎹�
+            thisMap.put("line1", lineDataMap.get("line1").getOrDefault(dateString, 0));
+            
+            // 鑾峰彇浜岀嚎鏁版嵁
+            thisMap.put("line2", lineDataMap.get("line2").getOrDefault(dateString, 0));
+
+            if (list.size()>0 && list.get(0).get("CreateDate").toString().equals(dateString)){
+                thisMap.put("plan",list.get(0).get("task_quantity_sum"));
+                list.remove(0);
+            }else{
+                thisMap.put("plan",0);
+            }
+            Result.add(thisMap);
+        }
+
+        return Result;
+    }
+    /**
      * 鍥炰紶鎶ュ伐鏁版嵁+ 璁惧鐜荤拑杩囩墖璁板綍缁� 涔濈墽
      */
     @Override

--
Gitblit v1.8.0