huang
2025-05-20 2c2413760b6467bf62402dba7338bd3bbcbd7341
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",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));
//            }
            // 获取一线数据
            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{