Fancy
2024-10-17 bf8fafcf455f201123905c804b41c3c231b4cbd8
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.dy.pmsOther.screen;
 
 
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.dy.common.springUtil.SpringContextUtil;
import com.dy.pmsGlobal.daoOth.OthStatisticWorkloadMapper;
import com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper;
import com.dy.pmsGlobal.daoSta.*;
import com.dy.pmsGlobal.pojoSta.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
 
@Slf4j
@Service
public class ScreenReportSv {
    private StaDeviceLastMapper deviceLastDao;
    private StaDeviceLifeMapper deviceLifeDao;
    private StaWipSnExMapper wipSnExDao;
    private StaDeviceProductionLogMapper deviceProductionLogDao;
    private StaRepairInfoMapper repairInfoDao;
    private PrAssemblyPlanMapper assemblyPlanDao;
    private OthStatisticWorkloadMapper workloadDao;
 
    @Autowired
    public void setDeviceLastDao(StaDeviceLastMapper deviceLastDao) {
        this.deviceLastDao = deviceLastDao;
    }
 
    @Autowired
    public void setDeviceLifeDao(StaDeviceLifeMapper deviceLifeDao) {
        this.deviceLifeDao = deviceLifeDao;
    }
 
    @Autowired
    public void setWipSnExDao(StaWipSnExMapper wipSnExDao) {
        this.wipSnExDao = wipSnExDao;
    }
 
    @Autowired
    public void setDeviceProductionLogDao(StaDeviceProductionLogMapper deviceProductionLogDao) {
        this.deviceProductionLogDao = deviceProductionLogDao;
    }
 
    @Autowired
    public void setAssemblyPlanDao(PrAssemblyPlanMapper assemblyPlanDao) {
        this.assemblyPlanDao = assemblyPlanDao;
    }
 
    @Autowired
    public void setRepairInfoDao(StaRepairInfoMapper repairInfoDao) {
        this.repairInfoDao = repairInfoDao;
    }
 
    @Autowired
    public void setWorkloadDao(OthStatisticWorkloadMapper workloadDao) {
        this.workloadDao = workloadDao;
    }
 
    public Map<String, Object> getDeviceInfo(String deviceNo) {
        if (StringUtils.isBlank(deviceNo)) {
            return null;
        }
        // 查询设备信息
        StaDeviceLast deviceLast = deviceLastDao.selectByDeviceNo(deviceNo);
        if (deviceLast == null) {
            return null;
        }
        Map<String, Object> deviceInfo = new HashMap<>();
        deviceInfo.put("deviceInfo", deviceLast);
        //查询设备日志
        List<StaDeviceProductionLog> log = deviceProductionLogDao.selectByDeviceNo(deviceNo);
        deviceInfo.put("deviceLog", log);
        // 查询设备生命周期
        List<StaDeviceLife> deviceLife = deviceLifeDao.selectByDeviceNo(deviceNo);
        deviceInfo.put("deviceLife", deviceLife);
        // 查询设备维修信息
        List<StaRepairInfo> repairInfo = repairInfoDao.selectByDeviceNo(deviceNo);
        deviceInfo.put("deviceRepair", repairInfo);
        // 查询设备附件信息
        List<StaWipSnEx> wipSnEx = wipSnExDao.selectByDeviceNo(deviceNo);
        deviceInfo.put("deviceAttach", wipSnEx);
        return deviceInfo;
    }
 
    public List<StaDeviceProductionLog> queryDeviceLog(String startTime, String endTime) {
        Date startDt = parseToDate(startTime, 0);
        Date endDt = parseToDate(endTime, 1);
        //查询设备日志
        List<StaDeviceProductionLog> log = deviceProductionLogDao.selectProductLog("", startDt, endDt);
        return log;
    }
 
    private Date parseToDate(String strDt, long offDays) {
        LocalDateTime dt = LocalDateTime.of(LocalDate.now().plusDays(offDays), LocalTime.of(0, 0, 0)); // 今天24点
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if (strDt.matches("\\d{4}(-\\d{2}){2} \\d{2}(:\\d{2}){2}")) {//2024-08-15 00:00:00
            dt = LocalDateTime.parse(strDt, dtf);
        } else if (strDt.matches("\\d{4}(-\\d{2}){2}")) {
            dt = LocalDateTime.of(LocalDate.parse(strDt, dtf1), LocalTime.of(0, 0, 0));
        }
        Date date = Date.from(dt.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }
 
    public List<JSONObject> queryPlanList() {
        List<JSONObject> list = assemblyPlanDao.queryPlanList();
        Map<String, JSONObject> map = new ConcurrentHashMap<>(); // 使用并发安全的Map
        for (JSONObject item : list) {
            String planId = String.valueOf(item.getObj("planId"));
            JSONObject innerObject = new JSONObject()
                    .set("nodeId", String.valueOf(item.getObj("nodeId")))
                    .set("content", item.getObj("content"));
            if (map.containsKey(planId)) {
                JSONArray array = (JSONArray) map.get(planId).get("nodes");
                array.add(innerObject);
            } else {
                JSONArray array = new JSONArray();
                array.add(innerObject);
                JSONObject outObject = new JSONObject()
                        .set("planId", planId)
                        .set("planName", item.getObj("planName"))
                        .set("nodes", array);
                map.put(planId, outObject);
            }
        }
        return map.values().stream().collect(Collectors.toList());
    }
}