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 |  149 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 124 insertions(+), 25 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 b60c550..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
@@ -35,6 +35,60 @@
     @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>();
     }
@@ -61,19 +115,78 @@
         List<Map> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
 
         List<Map<String, Object>> listTasking1 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
-                .select("operation_record,operation_mode,DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time,count(1) as count")
+                .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("operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .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("operation_record,operation_mode,DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time,count(1) as count")
+                .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("operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .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++){
@@ -84,28 +197,14 @@
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             String dateString = sdf.format(thisdate);
             thisMap.put("date",dateString);
-            if (listTasking1.size()>0&&listTasking1.get(0).get("operation_record_time").toString().equals(dateString)){
+            
+            // 鑾峰彇涓�绾挎暟鎹�
+            thisMap.put("line1", lineDataMap.get("line1").getOrDefault(dateString, 0));
+            
+            // 鑾峰彇浜岀嚎鏁版嵁
+            thisMap.put("line2", lineDataMap.get("line2").getOrDefault(dateString, 0));
 
-                thisMap.put("line1",listTasking1.get(0).get("count"));
-                listTasking1.remove(0);
-            }else{
-                thisMap.put("line1",0);
-            }
-            if (listTasking2.size()>0&&listTasking2.get(0).get("operation_record_time").toString().equals(dateString)){
-                thisMap.put("line2",listTasking2.get(0).get("count"));
-                listTasking2.remove(0);
-            }else{
-                thisMap.put("line2",0);
-            }
-//            if(list.size()>0){
-//                log.info("瀵规瘮:{},{},{}",
-//                        list.get(0).get("CreateDate"),
-//                        dateString,
-//                        list.get(0).get("CreateDate").toString().equals(dateString));
-//            }
-
-            if (list.size()>0&&list.get(0).get("CreateDate").toString().equals(dateString)){
-
+            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{

--
Gitblit v1.8.0