guoyuji
2024-03-25 a5bd926acdd8817a2da4b755b57a1d7e334a383a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
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<String, Object> processCardProgressSv(String orderId, List<Integer> columns) {
        Map<String, Object> map = new HashMap<>();
        //获取表格内容数据
        map.put("data", reportMapper.processCardProgressMp(orderId));
 
        //获取表头工序筛选数据
        List<Map<String,String>> processFilterList = orderProcessDetailMapper.filterOrderProcess(orderId);
        List<Map<String,String>> processList = processFilterList;
 
        List<String> filterList = new ArrayList<>();
        //循环遍历数组,判断此序号当前的工序
        for (int i = 1; i < processFilterList.size(); i++) {
            filterList.add(processFilterList.get(i).get("process"));
            List<Map<String,String>> 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<String> seenValues = new HashSet<>();
        // 创建一个新的List来存储结果
        List<Map<String, String>> uniqueList = new ArrayList<>();
 
        // 反向遍历原始List
        for (int i = processList.size() - 1; i >= 0; i--) {
            Map<String, String> 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<Map<String,Integer>> getRowCount =  orderProcessDetailMapper.getGlassLRow(orderId);
        List<Map<String,Integer>> rowCount = new ArrayList<>();
        columns.forEach(col ->{
            getRowCount.forEach(row ->{
                Map<String,Integer>  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;
    }
}