From e206ea8f7dbb655c0d8868996dae8ff1ff5ed11a Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 12 六月 2025 16:41:19 +0800
Subject: [PATCH] 修改看板大屏,动态获取数据

---
 JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/md/service/impl/TaskingLogServiceImpl.java |  297 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 272 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..6a8b100 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,64 @@
     @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");
+            //(鍗囧簭)
+            taskingWrapper.orderByAsc("operation_record_time");
+            // 鍏堟寜sortOrder鎺掑簭锛屽啀鎸夋椂闂存帓搴�
+            //taskingWrapper.orderByAsc("sort_order", "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 +119,76 @@
         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("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("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 +199,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{
@@ -175,4 +276,150 @@
         }
         return 0;
     }
+
+
+    /**
+     * 鏌ヨ鍗曞皬鏃朵骇閲�
+     * @param dayCount 鏌ヨ澶╂暟
+     * @return Map 鍖呭惈姣忓ぉ涓ゆ潯绾跨殑骞冲潎灏忔椂浜ч噺
+     */
+    @Override
+    public Map<String, Object> findHourlyOutput(int dayCount) {
+        try {
+            // 璁$畻寮�濮嬫椂闂�
+            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, -dayCount + 1);
+            Date startDate = cal.getTime();
+
+            // 鏌ヨ涓�绾挎暟鎹紝鎸夊ぉ鍒嗙粍缁熻鎬讳骇閲忓拰宸ヤ綔灏忔椂鏁�
+            QueryWrapper<TaskingLog> line1Query = new QueryWrapper<>();
+            line1Query.select(
+                    "DATE_FORMAT(operation_record_time, '%Y-%m-%d') as date",
+                    "COUNT(*) as total_count",
+                    "COUNT(DISTINCT DATE_FORMAT(operation_record_time, '%H')) as working_hours"
+                )
+                .eq("operation_record", "鏃嬭浆1")
+                .eq("operation_mode", "缁撴潫")
+                .ge("operation_record_time", startDate)
+                .groupBy("DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("date");
+            List<Map<String, Object>> line1Results = baseMapper.selectMaps(line1Query);
+
+            // 鏌ヨ浜岀嚎鏁版嵁锛屾寜澶╁垎缁勭粺璁℃�讳骇閲忓拰宸ヤ綔灏忔椂鏁�
+            QueryWrapper<TaskingLog> line2Query = new QueryWrapper<>();
+            line2Query.select(
+                    "DATE_FORMAT(operation_record_time, '%Y-%m-%d') as date",
+                    "COUNT(*) as total_count",
+                    "COUNT(DISTINCT DATE_FORMAT(operation_record_time, '%H')) as working_hours"
+                )
+                .eq("operation_record", "鏃嬭浆2")
+                .eq("operation_mode", "缁撴潫")
+                .ge("operation_record_time", startDate)
+                .groupBy("DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
+                .orderByAsc("date");
+            List<Map<String, Object>> line2Results = baseMapper.selectMaps(line2Query);
+
+            // 鍚堝苟缁撴灉
+            Map<String, Object> result = new HashMap<>();
+            Map<String, Map<String, Object>> dailyStats = new HashMap<>();
+
+            // 澶勭悊涓�绾挎暟鎹�
+            for (Map<String, Object> line1Data : line1Results) {
+                String date = (String) line1Data.get("date");
+                int totalCount = ((Number) line1Data.get("total_count")).intValue();
+                int workingHours = ((Number) line1Data.get("working_hours")).intValue();
+                
+                Map<String, Object> dailyData = new HashMap<>();
+                dailyData.put("date", date);
+                dailyData.put("line1Count", totalCount);
+                dailyData.put("line1Hours", workingHours);
+                dailyData.put("line1HourlyAvg", workingHours > 0 ? totalCount / workingHours : 0);
+                
+                dailyStats.put(date, dailyData);
+            }
+
+            // 澶勭悊浜岀嚎鏁版嵁
+            for (Map<String, Object> line2Data : line2Results) {
+                String date = (String) line2Data.get("date");
+                int totalCount = ((Number) line2Data.get("total_count")).intValue();
+                int workingHours = ((Number) line2Data.get("working_hours")).intValue();
+                
+                Map<String, Object> dailyData = dailyStats.computeIfAbsent(date, k -> {
+                    Map<String, Object> newData = new HashMap<>();
+                    newData.put("date", date);
+                    return newData;
+                });
+                
+                dailyData.put("line2Count", totalCount);
+                dailyData.put("line2Hours", workingHours);
+                dailyData.put("line2HourlyAvg", workingHours > 0 ? totalCount / workingHours : 0);
+            }
+
+            // 杞崲涓烘渶缁堢殑杩斿洖鏍煎紡
+            List<Map<String, Object>> finalStats = new ArrayList<>(dailyStats.values());
+
+            // 鎸夋棩鏈熸帓搴�
+            finalStats.sort((a, b) -> ((String)a.get("date")).compareTo((String)b.get("date")));
+
+            result.put("dailyStats", finalStats);
+            return result;
+        } catch (Exception e) {
+            log.error("璁$畻鍗曞皬鏃朵骇閲忓け璐�", e);
+            throw new RuntimeException("璁$畻鍗曞皬鏃朵骇閲忓け璐�: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 鏌ヨ搴撲綅鏁版嵁
+     * 鎸夊簱浣嶇粺璁★細
+     * - 鏍囧噯宸ヨ壓锛氱粺璁′笂鐗�1鍜屼笂鐗�2鐨勮褰�
+     * - 瀹氬埗宸ヨ壓锛氱粺璁℃棆杞�1鍜屾棆杞�2鐨勮褰�
+     */
+    @Override
+    public List<Map<String, Object>> selectWareHouse(int dayCount) {
+        try {
+            // 璁$畻寮�濮嬫椂闂�
+            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, -dayCount + 1);  
+            Date startDate = cal.getTime();
+            
+            // 浣跨敤QueryWrapper鏋勫缓鏌ヨ
+            QueryWrapper<TaskingLog> queryWrapper = new QueryWrapper<>();
+            queryWrapper.select(
+                    "DATE_FORMAT(operation_record_time, '%Y-%m-%d') as date",
+                    "warehouse",
+                    "COUNT(*) as count"
+                )
+                .and(wrapper -> wrapper
+                    .and(w -> w
+                        .eq("task_type", "鏍囧噯")
+                        .in("operation_record", "涓婄墖1", "涓婄墖2")
+                    )
+                    .or(w -> w
+                        .eq("task_type", "瀹氬埗")
+                        .in("operation_record", "鏃嬭浆1", "鏃嬭浆2")
+                    )
+                )
+                .eq("operation_mode", "缁撴潫")
+                .ge("operation_record_time", startDate)
+                .groupBy("DATE_FORMAT(operation_record_time, '%Y-%m-%d')", "warehouse")
+                .orderByAsc("date", "warehouse");
+
+            return baseMapper.selectMaps(queryWrapper);
+
+        } catch (Exception e) {
+            log.error("鏌ヨ搴撲綅鏁版嵁澶辫触", e);
+            throw new RuntimeException("鏌ヨ搴撲綅鏁版嵁澶辫触: " + e.getMessage());
+        }
+    }
 }

--
Gitblit v1.8.0