廖井涛
2025-07-23 25ae4025978ef7498db9790b237fa5a26698b1ec
north-glass-erp/src/main/java/com/example/erp/service/pp/ReportService.java
@@ -3,24 +3,30 @@
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.FlowCardMapper;
import com.example.erp.mapper.pp.ProductionSchedulingMapper;
import com.example.erp.mapper.pp.ReportMapper;
import com.example.erp.mapper.sd.OrderProcessDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import com.example.erp.mapper.pp.ReportingWorkMapper;
import com.example.erp.mapper.sd.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.hutool.core.convert.Convert.toDouble;
@Service
@DS("pp")
@@ -30,11 +36,63 @@
    private final OrderProcessDetailMapper orderProcessDetailMapper;
    private final ProductionSchedulingMapper productionSchedulingMapper;
    private final OrderGlassDetailMapper orderGlassDetailMapper;
    private final BasicDataMapper basicDataMapper;
    private final ProductDetailMapper productDetailMapper;
    private final OrderDetailMapper orderDetailMapper;
    private void mergeTeamsGroupsName(
            List<WorkInProgressDTO> dataList1,
            List<WorkInProgressDTO> dataList2
    ) {
    FlowCardMapper flowCardMapper;
    private ReportingWorkMapper reportingWorkMapper;
    //上工序报工班组
    private void mergeTeamsGroupsName( List<WorkInProgressDTO> dataList1,List<WorkInProgressDTO> dataList2) {
        for (WorkInProgressDTO dto1 : dataList1) {
            //根据当前工序获取 是否为单片、夹胶、或者全部
          BasicData basicData =  basicDataMapper.
                  selectOne(new QueryWrapper<BasicData>()
                          .eq("basic_name", dto1.getThisProcess())
                          .last("limit 1")
                  );
          OrderDetail orderDetail = orderDetailMapper
                .selectOne(
                        new QueryWrapper<OrderDetail>()
                                .eq("order_id", dto1.getOrderId())
                                .eq("order_number", dto1.getOrderNumber())
                );
          //如果为单片,则根据产品名称和工艺编号获取玻璃名称
          if(basicData.getNickname()==null || basicData.getNickname().isEmpty()){
              ProductDetail productDetail = productDetailMapper.
                      selectOne(new QueryWrapper<ProductDetail>()
                              .eq("prod_id", orderDetail.getProductId())
                              .eq("glass_sort",dto1.getTechnologyNumber())
                      );
              dto1.setGlassName(productDetail.getDetail());
          }else if(basicData.getNickname().equals("stepC")){
              OrderGlassDetail orderGlassDetailGroup = orderGlassDetailMapper
                      .selectOne(new QueryWrapper<OrderGlassDetail>()
                              .eq("order_id", dto1.getOrderId())
                              .eq("order_number", dto1.getOrderNumber())
                              .eq("technology_number",dto1.getTechnologyNumber())
                      );
              String glassName = productDetailMapper.getGlassNameByGroup(
                      orderDetail.getProductId(),
                      orderGlassDetailMapper.getMinTechnologyNumberByGroup(dto1.getOrderId(),dto1.getOrderNumber(), String.valueOf(orderGlassDetailGroup.getGroup())),
                      orderGlassDetailMapper.getMaxTechnologyNumberByGroup(dto1.getOrderId(),dto1.getOrderNumber(), String.valueOf(orderGlassDetailGroup.getGroup()))
              );
              dto1.setGlassName(glassName);
          }else{
              dto1.setGlassName(dto1.getProductName());
          }
        }
        Function<WorkInProgressDTO, String> keyFn = dto ->
                dto.getProcessId() + "|" +
                        dto.getOrderNumber() + "|" +
@@ -59,10 +117,20 @@
    }
    public ReportService(ReportMapper reportMapper, OrderProcessDetailMapper orderProcessDetailMapper, ProductionSchedulingMapper productionSchedulingMapper) {
    public ReportService(ReportMapper reportMapper, OrderProcessDetailMapper orderProcessDetailMapper,
                         ProductionSchedulingMapper productionSchedulingMapper, FlowCardMapper flowCardMapper,
                         OrderGlassDetailMapper orderGlassDetailMapper, BasicDataMapper basicDataMapper,
                         ProductDetailMapper productDetailMapper, OrderDetailMapper orderDetailMapper,
                         ReportingWorkMapper reportingWorkMapper) {
        this.reportMapper = reportMapper;
        this.orderProcessDetailMapper = orderProcessDetailMapper;
        this.productionSchedulingMapper = productionSchedulingMapper;
        this.flowCardMapper = flowCardMapper;
        this.orderGlassDetailMapper = orderGlassDetailMapper;
        this.basicDataMapper = basicDataMapper;
        this.productDetailMapper = productDetailMapper;
        this.orderDetailMapper = orderDetailMapper;
        this.reportingWorkMapper = reportingWorkMapper;
    }
    //流程卡进度方法
@@ -173,10 +241,11 @@
        if ("null".equals(optionVal)) {
            optionVal = ("");
        }
        if (selectProcesses.equals("全部")){
            selectProcesses="";
        }
        Map<String, Object> map = new HashMap<>();
        List<WorkInProgressDTO> dataList2  =reportMapper.workInProgressMpdataList2(offset, pageSize, orderId, inputProject, selectProcesses, workInProgressDTO);
        if (optionVal.equals("1")){
            /* 根据销售单号汇总*/
            //map.put("data", reportMapper.workInProgressOrderMp(offset, pageSize, orderId, inputProject, selectProcesses, workInProgressDTO));
@@ -225,7 +294,7 @@
        return map;
    }
    public Map<String, Object> selectDamageReportSv(Integer pageNum, Integer pageSize, Date selectTime1, Date selectTime2, DamageReportDTO damageReportDTO) {
    public Map<String, Object> selectDamageReportSv(Integer pageNum, Integer pageSize, String selectTime1, String selectTime2, DamageReportDTO damageReportDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        Map<String, Object> map = new HashMap<>();
        map.put("data", reportMapper.selectDamageReportMp(offset, pageSize, selectTime1, selectTime2, damageReportDTO));
@@ -237,6 +306,7 @@
    public Map<String, Object> splittingDetailsOutsideSv(String orderId, Report report) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", reportMapper.splittingDetailsOutsideMp(orderId, report));
        map.put("orderOtherMoney", flowCardMapper.selectorderOtherMoney());
        return map;
    }
@@ -413,12 +483,18 @@
        return reportMapper.exportCrossProcessBreakingMp(dates);
    }
    public List exportDamageReportSv(List<LocalDate> dates) {
        if (dates != null && dates.size() > 1) {
            dates.set(1, dates.get(1).plusDays(1)); // 将第二个日期加一天
        }
        System.out.println(dates);
        return reportMapper.exportDamageReportMp(dates);
    //    public List exportTeamOutputSv(Map<String, Object> dates) {
//        List<LocalDate> date= (List<LocalDate>) dates.get("date");
//        String process= (String) dates.get("processes");
//        if (process.equals("全部")){
//            process="";
//        }
//        String laminating = reportMapper.getLaminating(process);
//        return reportMapper.exportTeamOutputMp(date,process,laminating);
//    }
    public List exportDamageReportSv(Map<String, Object> dates) {
        List<LocalDate> date= (List<LocalDate>) dates.get("date");
        return reportMapper.exportDamageReportMp(date);
    }
    public List exportOrderPlanDecompositionSv(List<LocalDate> dates) {
@@ -441,6 +517,9 @@
    public List exportWorkInProgressSv(Map<String, Object> dates) {
        String process= (String) dates.get("processes");
        if (process.equals("全部")){
            process="";
        }
        String inputVal= (String) dates.get("inputVal");
        String project= (String) dates.get("project");
        if ("null".equals(inputVal)) {
@@ -449,7 +528,11 @@
        if ("null".equals(project)) {
            project = "";
        }
        return reportMapper.exportWorkInProgressMp(process,inputVal,project);
        List<WorkInProgressDTO> dataList1  =reportMapper.exportWorkInProgressMp(process,inputVal,project);
        List<WorkInProgressDTO> dataList2  =reportMapper.exportWorkInProgressMpdataList2(process);
        mergeTeamsGroupsName(dataList1, dataList2);
        return dataList1;
    }
    public List exportTaskCompletionStatusSv(Map<String, Object> dates) {
@@ -470,7 +553,7 @@
        return reportMapper.exportYieldMp(date,process);
    }
    public Map<String, Object> teamOutputSv(Integer pageNum, Integer pageSize, Date selectTime1, Date selectTime2, String selectProcesses, TeamOutputDTO teamOutputDTO) {
    public Map<String, Object> teamOutputSv(Integer pageNum, Integer pageSize, String selectTime1, String selectTime2, String selectProcesses, TeamOutputDTO teamOutputDTO) {
        if (selectProcesses.equals("全部")){
            selectProcesses="";
        }
@@ -508,4 +591,143 @@
        String laminating = reportMapper.getLaminating(process);
        return reportMapper.exportTeamOutputMp(date,process,laminating);
    }
    public Map<String, Object> workInProgressCombinationSv(
            Integer pageNum, Integer pageSize,
            String orderId, String inputProject, String selectProcesses,
            String optionVal, WorkInProgressDTO workInProgressDTO) {
        Integer offset = (pageNum - 1) * pageSize;
        if ("null".equals(orderId)) {
            orderId = "";
        }
        if ("null".equals(inputProject)) {
            inputProject = "";
        }
        if ("null".equals(optionVal)) {
            optionVal = "";
        }
        if ("全部".equals(selectProcesses)) {
            selectProcesses = "";
        }
        String laminating = "";
        Map<String, Object> map = new HashMap<>();
        Map<String, Double> totalSumMap = new HashMap<>();
        double totalStockNum = 0;
        double totalStockArea = 0;
        // 获取所有工序
        List<String> processList = reportMapper.selectProcess();
        // 最终数据集合
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (!"".equals(selectProcesses)) {
            laminating = reportingWorkMapper.getProcessLaminating(selectProcesses);
            List<Map<String, Object>> singleResult =
                    reportMapper.getWorkInProgressCombination(selectProcesses, laminating, optionVal);
            if (singleResult != null && !singleResult.isEmpty()) {
                resultList.addAll(singleResult);
            }
            Map<String, Object> total =
                    reportMapper.getWorkInProgressCombinationFootSum(selectProcesses, laminating, optionVal);
            if (total != null) {
                BigDecimal stockNum = (BigDecimal) total.get("stockNum");
                BigDecimal stockArea = (BigDecimal) total.get("stockArea");
                if (stockNum != null) {
                    totalStockNum += stockNum.doubleValue();
                }
                if (stockArea != null) {
                    totalStockArea += stockArea.doubleValue();
                }
            }
        } else {
            for (String process : processList) {
                laminating = reportingWorkMapper.getProcessLaminating(process);
                List<Map<String, Object>> singleResult =
                        reportMapper.getWorkInProgressCombination(process, laminating, optionVal);
                if (singleResult != null && !singleResult.isEmpty()) {
                    resultList.addAll(singleResult);
                }
                Map<String, Object> total =
                        reportMapper.getWorkInProgressCombinationFootSum(process, laminating, optionVal);
                if (total != null) {
                    BigDecimal stockNum = (BigDecimal) total.get("stockNum");
                    BigDecimal stockArea = (BigDecimal) total.get("stockArea");
                    if (stockNum != null) {
                        totalStockNum += stockNum.doubleValue();
                    }
                    if (stockArea != null) {
                        totalStockArea += stockArea.doubleValue();
                    }
                }
            }
        }
        totalSumMap.put("stockNum", totalStockNum);
        totalSumMap.put("stockArea", totalStockArea);
        map.put("data", resultList);
        map.put("total", totalSumMap);
        map.put("process", productionSchedulingMapper.selectProcess());
        return map;
    }
    public List exportWorkInProgressCombinationSv(Map<String, Object> dates) {
        String process= (String) dates.get("processes");
        if (process.equals("全部")){
            process="";
        }
        String inputVal= (String) dates.get("inputVal");
        String project= (String) dates.get("project");
        if ("null".equals(inputVal)) {
            inputVal = "";
        }
        if ("null".equals(project)) {
            project = "";
        }
        String laminating = "";
        // 获取所有工序
        List<String> processList = reportMapper.selectProcess();
        // 最终数据集合
        List<WorkInProgressCombinationDTO> resultList = new ArrayList<>();
        if (!"".equals(process)) {
            laminating = reportingWorkMapper.getProcessLaminating(process);
            List<WorkInProgressCombinationDTO> singleResult =
                    reportMapper.exportWorkInProgressCombination(process, laminating, inputVal);
            if (singleResult != null && !singleResult.isEmpty()) {
                resultList.addAll((Collection<? extends WorkInProgressCombinationDTO>) singleResult);
            }
        } else {
            for (String processVal : processList) {
                laminating = reportingWorkMapper.getProcessLaminating(processVal);
                List<WorkInProgressCombinationDTO> singleResult =
                        reportMapper.exportWorkInProgressCombination(processVal, laminating, inputVal);
                if (singleResult != null && !singleResult.isEmpty()) {
                    resultList.addAll((Collection<? extends WorkInProgressCombinationDTO>) singleResult);
                }
            }
        }
        return resultList;
    }
}