廖井涛
2024-04-12 e3cc5fb859a4e3c56c1dfa4d7892b233a30874fa
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
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.DamageDetails;
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.time.LocalDate;
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;
    }
 
    public Map<String,Object> crossProcessBreakingSv(Integer pageNum, Integer pageSize, List<String> selectDate, DamageDetails damageDetails) {
        Integer offset = (pageNum-1)*pageSize;
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("data",reportMapper.getProcessBreaking(offset, pageSize, startDate, endDate, damageDetails));
        map.put("total",reportMapper.getProcessBreakingTotal(offset, pageSize, startDate, endDate, damageDetails));
        List<String> list = new ArrayList<>();
        list.add(startDate);
        list.add(endDate);
        map.put("selectDate",list);
//        map.put("total",orderMapper.getPageTotal(offset, pageSize, startDate, endDate, orderDetail));
        return map;
    }
}