chenlu
2025-11-26 00f14bfc32af9a921d172320212828c95a4d8f68
north-glass-erp/src/main/java/com/example/erp/service/pp/ReportService.java
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.TypeReference;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.erp.common.AsyncQueryExecutor;
import com.example.erp.entity.sd.*;
import com.example.erp.tools.AreaComputed.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -12,10 +13,6 @@
import com.example.erp.dto.pp.*;
import com.example.erp.entity.pp.DamageDetails;
import com.example.erp.entity.pp.Report;
import com.example.erp.entity.sd.BasicData;
import com.example.erp.entity.sd.OrderDetail;
import com.example.erp.entity.sd.OrderGlassDetail;
import com.example.erp.entity.sd.ProductDetail;
import com.example.erp.mapper.pp.*;
import com.example.erp.mapper.sd.*;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +26,9 @@
import java.sql.Date;
import java.sql.SQLOutput;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
@@ -53,6 +53,7 @@
    FlowCardMapper flowCardMapper;
    private ReportingWorkMapper reportingWorkMapper;
    private final OrderMapper orderMapper;
    @Resource
    private AsyncQueryExecutor asyncExecutor;
@@ -82,7 +83,10 @@
                              .eq("prod_id", orderDetail.getProductId())
                              .eq("glass_sort",dto1.getTechnologyNumber())
                      );
              dto1.setGlassName(productDetail.getDetail());
              if(productDetail!=null){
                  dto1.setGlassName(productDetail.getDetail());
              }
            //basicData.getNickname().equals("stepC")
          }else if(basicData.getNickname().equals("stepC")){
              OrderGlassDetail orderGlassDetailGroup = orderGlassDetailMapper
@@ -133,7 +137,7 @@
                         ProductionSchedulingMapper productionSchedulingMapper, FlowCardMapper flowCardMapper,
                         OrderGlassDetailMapper orderGlassDetailMapper, BasicDataMapper basicDataMapper,
                         ProductDetailMapper productDetailMapper, OrderDetailMapper orderDetailMapper,
                         ReportingWorkMapper reportingWorkMapper, DamageDetailsMapper damageDetailsMapper) {
                         ReportingWorkMapper reportingWorkMapper, DamageDetailsMapper damageDetailsMapper, OrderMapper orderMapper) {
        this.reportMapper = reportMapper;
        this.orderProcessDetailMapper = orderProcessDetailMapper;
        this.productionSchedulingMapper = productionSchedulingMapper;
@@ -144,6 +148,7 @@
        this.orderDetailMapper = orderDetailMapper;
        this.reportingWorkMapper = reportingWorkMapper;
        this.damageDetailsMapper = damageDetailsMapper;
        this.orderMapper = orderMapper;
    }
    //流程卡进度方法
@@ -302,8 +307,6 @@
        }
        map.put("data",dataList );
        map.put("mergeCells", rowCount);
@@ -332,29 +335,47 @@
//        return map;
//    }
    private static String to080000(String s) {
        if (s == null || s.isEmpty()) return null;
        String v = s.trim();
        // 只保留日期部分(前10位 yyyy-MM-dd)
        String datePart = v.length() >= 10 ? v.substring(0, 10) : v;
        return datePart + " 08:00:00";
    private static final DateTimeFormatter DATE_TIME_FMT =
            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    private String toReportTime(String dateStr, String reportTime) {
        if (dateStr == null || dateStr.isEmpty()) {
            return null;
        }
        // 只保留 yyyy-MM-dd,防止前端传完整时间导致 parse 异常
        String onlyDate = dateStr.length() > 10 ? dateStr.substring(0, 10) : dateStr;
        String[] parts = reportTime.split(":");
        int hour   = Integer.parseInt(parts[0]);
        int minute = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
        int second = parts.length > 2 ? Integer.parseInt(parts[2]) : 0;
        LocalDate date = LocalDate.parse(onlyDate);
        LocalTime time = LocalTime.of(hour, minute, second);
        return LocalDateTime.of(date, time).format(DATE_TIME_FMT);
    }
    //跨工序次破
    public Map<String, Object> crossProcessBreakingSv(Integer pageNum, Integer pageSize,
                                                      List<String> selectDate,
                                                      String reportTime,
                                                      CrossProcessBreakingDTO crossProcessBreakingDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        // 默认时间范围:过去 15 天
        String startDate = to080000(LocalDate.now().minusDays(15).toString());
        String endDate   = to080000(LocalDate.now().toString());
        // 默认时间范围:过去 15 天(日期 + reportTime)
        String startDate = toReportTime(LocalDate.now().minusDays(15).toString(), reportTime);
        String endDate   = toReportTime(LocalDate.now().toString(), reportTime);
        // 如果前端传了时间,就用前端日期 + reportTime
        if (selectDate != null && selectDate.size() == 2) {
            if (selectDate.get(0) != null && !selectDate.get(0).isEmpty()) {
                startDate = to080000(selectDate.get(0));
                startDate = toReportTime(selectDate.get(0), reportTime);
            }
            if (selectDate.get(1) != null && !selectDate.get(1).isEmpty()) {
                endDate = to080000(selectDate.get(1));
                endDate = toReportTime(selectDate.get(1), reportTime);
            }
        }
@@ -363,7 +384,6 @@
        // 使用异步线程池
        String finalEndDate = endDate;
        String finalStartDate = startDate;
        System.out.println(finalEndDate+"==="+finalStartDate);
        CompletableFuture<List<CrossProcessBreakingDTO>> dataFuture = asyncExecutor.runAsync(() ->
                reportMapper.getProcessBreaking(offset, pageSize, finalStartDate, finalEndDate, crossProcessBreakingDTO));
@@ -392,19 +412,21 @@
    //非跨工序次破
    public Map<String, Object> notCrossProcessBreakingSv(Integer pageNum, Integer pageSize,
                                                      List<String> selectDate,
                                                      String reportTime,
                                                      CrossProcessBreakingDTO crossProcessBreakingDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        // 默认时间范围:过去 15 天
        String startDate = to080000(LocalDate.now().minusDays(15).toString());
        String endDate   = to080000(LocalDate.now().toString());
        // 默认时间范围:过去 15 天(日期 + reportTime)
        String startDate = toReportTime(LocalDate.now().minusDays(15).toString(), reportTime);
        String endDate   = toReportTime(LocalDate.now().toString(), reportTime);
        // 如果前端传了时间,就用前端日期 + reportTime
        if (selectDate != null && selectDate.size() == 2) {
            if (selectDate.get(0) != null && !selectDate.get(0).isEmpty()) {
                startDate = to080000(selectDate.get(0));
                startDate = toReportTime(selectDate.get(0), reportTime);
            }
            if (selectDate.get(1) != null && !selectDate.get(1).isEmpty()) {
                endDate = to080000(selectDate.get(1));
                endDate = toReportTime(selectDate.get(1), reportTime);
            }
        }
@@ -485,13 +507,14 @@
    public Map<String, Object> workInProgressSv(
            Integer pageNum, Integer pageSize,
            String orderId, String inputProject, String selectProcesses,
            String optionVal, WorkInProgressDTO workInProgressDTO) {
            String optionVal,String terminationVals, WorkInProgressDTO workInProgressDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        if ("null".equals(orderId)) orderId = "";
        if ("null".equals(inputProject)) inputProject = "";
        if ("null".equals(optionVal)) optionVal = "";
        if ("null".equals(terminationVals)) terminationVals = "";
        if ("all".equals(selectProcesses)) selectProcesses = "";
        String laminating = reportMapper.getLaminating(selectProcesses);
@@ -502,6 +525,7 @@
            String finalOrderId = orderId;
            String finalInputProject = inputProject;
            String finalSelectProcesses = selectProcesses;
            String finalTerminationVals = terminationVals;
            CompletableFuture<List<WorkInProgressDTO>> dataList2Future =
                    asyncExecutor.runAsync(() ->
                            reportMapper.workInProgressMpdataList2(
@@ -519,7 +543,7 @@
                totalFuture = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressOrderFootSum(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses,finalTerminationVals, workInProgressDTO));
            } else if ("2".equals(optionVal)) {
                // 流程卡号汇总
@@ -529,25 +553,25 @@
                totalFuture = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressOrderFootSum(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses,finalTerminationVals, workInProgressDTO));
            } else if ("3".equals(optionVal)) {
                dataList1Future = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressMpdataList1(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, laminating, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, laminating,finalTerminationVals, workInProgressDTO));
                totalFuture = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressOrderFootSum(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses,finalTerminationVals, workInProgressDTO));
            } else {
                // 不分组
                dataList1Future = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressMpdataList1(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, laminating, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, laminating,finalTerminationVals, workInProgressDTO));
                totalFuture = asyncExecutor.runAsync(() ->
                        reportMapper.workInProgressOrderFootSum(
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses, workInProgressDTO));
                                offset, pageSize, finalOrderId, finalInputProject, finalSelectProcesses,finalTerminationVals, workInProgressDTO));
            }
            // 等待全部任务完成
@@ -599,25 +623,31 @@
    public Map<String, Object> selectDamageReportSv(Integer pageNum, Integer pageSize,
                                                    List<String> selectDate,
                                                    String reportTime,
                                                    DamageReportDTO damageReportDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        // 默认时间范围:过去 15 天
        String startDate = to080000(LocalDate.now().minusDays(15).toString());
        String endDate   = to080000(LocalDate.now().toString());
        Integer offset = (pageNum - 1) * pageSize;
        // 默认时间范围:过去 15 天(日期 + reportTime)
        String startDate = toReportTime(LocalDate.now().minusDays(15).toString(), reportTime);
        String endDate   = toReportTime(LocalDate.now().toString(), reportTime);
        // 如果前端传了时间,就用前端日期 + reportTime
        if (selectDate != null && selectDate.size() == 2) {
            if (selectDate.get(0) != null && !selectDate.get(0).isEmpty()) {
                startDate = to080000(selectDate.get(0));
                startDate = toReportTime(selectDate.get(0), reportTime);
            }
            if (selectDate.get(1) != null && !selectDate.get(1).isEmpty()) {
                endDate = to080000(selectDate.get(1));
                endDate = toReportTime(selectDate.get(1), reportTime);
            }
        }
        Map<String, Object> result = new HashMap<>();
        String finalEndDate = endDate;
        String finalStartDate = startDate;
        // 异步任务定义
        Map<String, Object> result = new HashMap<>();
        String finalStartDate = startDate;
        String finalEndDate = endDate;
        // 异步任务定义
        CompletableFuture<List<DamageReportDTO>> dataFuture = asyncExecutor.runAsync(() ->
                reportMapper.selectDamageReportMp(offset, pageSize, finalStartDate, finalEndDate, damageReportDTO));
@@ -627,7 +657,7 @@
        CompletableFuture<Map<String, Float>> footSumFuture = asyncExecutor.runAsync(() ->
                reportMapper.damageReportFootSum(finalStartDate, finalEndDate, damageReportDTO));
        //等待全部任务完成
        // 等待全部任务完成
        CompletableFuture.allOf(dataFuture, totalFuture, footSumFuture).join();
        try {
@@ -638,6 +668,8 @@
            e.printStackTrace();
            throw new RuntimeException("并行查询异常:" + e.getMessage(), e);
        }
        // 回传前端的时间(现在是带时分秒的)
        List<String> list = new ArrayList<>();
        list.add(startDate);
        list.add(endDate);
@@ -645,6 +677,7 @@
        return result;
    }
    public Map<String, Object> splittingDetailsOutsideSv(String orderId, Report report) {
        Map<String, Object> map = new HashMap<>();
@@ -970,13 +1003,17 @@
        }
        String inputVal= (String) dates.get("inputVal");
        String project= (String) dates.get("project");
        if ("null".equals(inputVal)) {
        String terminationVals= dates.get("terminationVals").toString();;
        if (inputVal==null) {
            inputVal = "";
        }
        if ("null".equals(project)) {
        if (project==null) {
            project = "";
        }
        List<WorkInProgressDTO> dataList1  =reportMapper.exportWorkInProgressMp(process,inputVal,project);
        if (terminationVals==null) {
            terminationVals = "";
        }
        List<WorkInProgressDTO> dataList1  =reportMapper.exportWorkInProgressMp(process,inputVal,project,terminationVals);
        List<WorkInProgressDTO> dataList2  =reportMapper.exportWorkInProgressMpdataList2(process);
        mergeTeamsGroupsName(dataList1, dataList2);
@@ -1139,7 +1176,7 @@
    public Map<String, Object> workInProgressCombinationSv(
            Integer pageNum, Integer pageSize,
            String orderId, String inputProject, String selectProcesses,
            String optionVal, WorkInProgressDTO workInProgressDTO) {
            String optionVal,String terminationVal, WorkInProgressDTO workInProgressDTO) {
        Integer offset = (pageNum - 1) * pageSize;
@@ -1151,6 +1188,9 @@
        }
        if ("null".equals(optionVal)) {
            optionVal = "";
        }
        if ("null".equals(terminationVal)) {
            terminationVal = "";
        }
        if ("all".equals(selectProcesses)) {
            selectProcesses = "";
@@ -1168,17 +1208,16 @@
        // 最终数据集合
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (!"".equals(selectProcesses)) {
            laminating = reportingWorkMapper.getProcessLaminating(selectProcesses);
            List<Map<String, Object>> singleResult =
                    reportMapper.getWorkInProgressCombination(selectProcesses, laminating, optionVal);
                    reportMapper.getWorkInProgressCombination(selectProcesses, laminating, optionVal,terminationVal);
            if (singleResult != null && !singleResult.isEmpty()) {
                resultList.addAll(singleResult);
            }
            Map<String, Object> total =
                    reportMapper.getWorkInProgressCombinationFootSum(selectProcesses, laminating, optionVal);
                    reportMapper.getWorkInProgressCombinationFootSum(selectProcesses, laminating, optionVal,terminationVal);
            if (total != null) {
                BigDecimal stockNum = (BigDecimal) total.get("stockNum");
                BigDecimal stockArea = (BigDecimal) total.get("stockArea");
@@ -1196,14 +1235,14 @@
                laminating = reportingWorkMapper.getProcessLaminating(process);
                List<Map<String, Object>> singleResult =
                        reportMapper.getWorkInProgressCombination(process, laminating, optionVal);
                        reportMapper.getWorkInProgressCombination(process, laminating, optionVal,terminationVal);
                if (singleResult != null && !singleResult.isEmpty()) {
                    resultList.addAll(singleResult);
                }
                Map<String, Object> total =
                        reportMapper.getWorkInProgressCombinationFootSum(process, laminating, optionVal);
                        reportMapper.getWorkInProgressCombinationFootSum(process, laminating, optionVal,terminationVal);
                if (total != null) {
                    BigDecimal stockNum = (BigDecimal) total.get("stockNum");
                    BigDecimal stockArea = (BigDecimal) total.get("stockArea");
@@ -1235,11 +1274,15 @@
        }
        String inputVal= (String) dates.get("inputVal");
        String project= (String) dates.get("project");
        if ("null".equals(inputVal)) {
        String terminationVals= dates.get("terminationVals").toString();;
        if (inputVal==null) {
            inputVal = "";
        }
        if ("null".equals(project)) {
        if (project==null) {
            project = "";
        }
        if (terminationVals==null) {
            terminationVals = "";
        }
        String laminating = "";
@@ -1253,7 +1296,7 @@
        if (!"".equals(process)) {
            laminating = reportingWorkMapper.getProcessLaminating(process);
            List<WorkInProgressCombinationDTO> singleResult =
                    reportMapper.exportWorkInProgressCombination(process, laminating, inputVal);
                    reportMapper.exportWorkInProgressCombination(process, laminating, inputVal,terminationVals);
            if (singleResult != null && !singleResult.isEmpty()) {
                resultList.addAll((Collection<? extends WorkInProgressCombinationDTO>) singleResult);
            }
@@ -1264,7 +1307,7 @@
                laminating = reportingWorkMapper.getProcessLaminating(processVal);
                List<WorkInProgressCombinationDTO> singleResult =
                        reportMapper.exportWorkInProgressCombination(processVal, laminating, inputVal);
                        reportMapper.exportWorkInProgressCombination(processVal, laminating, inputVal,terminationVals);
                if (singleResult != null && !singleResult.isEmpty()) {
                    resultList.addAll((Collection<? extends WorkInProgressCombinationDTO>) singleResult);
@@ -1430,11 +1473,10 @@
            dataList.get(i).put("reportWorkQuantityShow",JSON.toJSONString(dataShow));
        }
        Order order = orderMapper.selectOrderId(orderId);
        map.put("mergeCells", rowCount);
        map.put("data",dataList);
        map.put("order",order);
        return  map;
    }