package com.example.erp.service.pp; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.example.erp.entity.pp.FlowCard; import com.example.erp.mapper.pp.ReportMapper; import com.example.erp.mapper.sd.OrderProcessDetailMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.sql.Date; import java.util.*; import java.util.stream.Collectors; @Service @DS("pp") public class ReportService { private final ReportMapper reportMapper; private final OrderProcessDetailMapper orderProcessDetailMapper; public ReportService(ReportMapper reportMapper, OrderProcessDetailMapper orderProcessDetailMapper) { this.reportMapper = reportMapper; this.orderProcessDetailMapper = orderProcessDetailMapper; } //流程卡进度方法 public Map processCardProgressSv(String orderId, List columns) { Map map = new HashMap<>(); //获取表格内容数据 map.put("data", reportMapper.processCardProgressMp(orderId)); //获取表头工序筛选数据 List> processFilterList = orderProcessDetailMapper.filterOrderProcess(orderId); List> processList = processFilterList; List filterList = new ArrayList<>(); //循环遍历数组,判断此序号当前的工序 for (int i = 1; i < processFilterList.size(); i++) { filterList.add(processFilterList.get(i).get("process")); List> lastProcessList = orderProcessDetailMapper.filterLastProcess( orderId, String.valueOf(processFilterList.get(i).get("order_number")), String.valueOf(processFilterList.get(i).get("technology_number")), String.valueOf(processFilterList.get(i).get("id")) ); if(!lastProcessList.isEmpty()){ int finalI = i; lastProcessList.forEach(lastProcess -> { if(filterList.contains(lastProcess.get("process"))){ processList.add(lastProcess); } }); } } // 使用HashSet来记录已经遇到的value值 Set seenValues = new HashSet<>(); // 创建一个新的List来存储结果 List> uniqueList = new ArrayList<>(); // 反向遍历原始List for (int i = processList.size() - 1; i >= 0; i--) { Map maps = processList.get(i); String value = maps.values().iterator().next(); // 假设每个Map只有一个value // 如果value还没有被看到过,就添加到结果List和HashSet中 if (!seenValues.contains(value)) { uniqueList.add(0, maps); // 添加到结果List的开头,以保持原顺序 seenValues.add(value); } } map.put("title", uniqueList ); List> getRowCount = orderProcessDetailMapper.getGlassLRow(orderId); List> rowCount = new ArrayList<>(); columns.forEach(col ->{ getRowCount.forEach(row ->{ Map getRow = new HashMap<>(); // { row: 0, col: 1, rowspan: 3, colspan: 0}, getRow.put("row",row.get("RowNum")); getRow.put("col",col); getRow.put("rowspan",row.get("rowCount")); getRow.put("colspan",0); rowCount.add(getRow); }); }); map.put("mergeCells",rowCount); return map; } }