郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.gkhy.safePlatform.safeCheck.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserRPCRespDTO;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.safeCheck.entity.AbnormalWorkOrder;
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckRfid;
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTask;
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota;
import com.gkhy.safePlatform.safeCheck.enums.DelectStatusEnum;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckSmartScreenRepsDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskAndQuotaRespDTO;
import com.gkhy.safePlatform.safeCheck.rpc.apimodel.model.resp.SafeCheckTaskAndQuotaExcepOrderRPCRespDTO;
import com.gkhy.safePlatform.safeCheck.rpc.apimodel.model.resp.SafeCheckTaskAndQuotaGBRfidAndExcpOrderRPCRespDTO;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckMinioAccessService;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckSmartScreenService;
import com.gkhy.safePlatform.safeCheck.service.baseService.AbnormalWorkOrderService;
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckRfidService;
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckTaskAndQuotaService;
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckTaskService;
import com.gkhy.safePlatform.safeCheck.util.UserInfoUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class SafeCheckSmartScreenServiceImpl implements SafeCheckSmartScreenService {
 
    @DubboReference(check = false)
    private AccountAuthService accountAuthService;
 
 
    @Autowired
    private SafeCheckTaskService taskService;
 
    @Autowired
    private SafeCheckTaskAndQuotaService taskAndQuotaService;
 
    @Autowired
    private SafeCheckRfidService safeCheckRfidService;
 
    @Autowired
    private AbnormalWorkOrderService abnormalWorkOrderService;
 
    @Autowired
    private SafeCheckMinioAccessService safeCheckMinioAccessService;
 
    /**
     * @description 根据巡检任务id获取所有的巡检链数据,对相同的rfid进行分组反馈
     */
    @Transactional
    @Override
    public List<SafeCheckSmartScreenRepsDTO> getSmartScreenData(Long taskId) {
 
        if (taskId == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务id不能为空");
        }
        SafeCheckTask task = taskService.getTaskById(taskId);
        if (task == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"任务不存在");
        }
        List<SafeCheckTaskAndQuota> taskAndQuotasSource = taskAndQuotaService.listTaskAndQuotaByTaskId(taskId);
 
 
        if (taskAndQuotasSource == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"该任务无对应的巡检链数据");
        }
        List<SafeCheckTaskAndQuotaRespDTO> taskAndQuotas = taskAndQuotasSource.stream().map((taskAndQuotaSource)->{
            SafeCheckTaskAndQuotaRespDTO taskAndQuota = new SafeCheckTaskAndQuotaRespDTO();
            BeanUtils.copyProperties(taskAndQuotaSource,taskAndQuota);
            return taskAndQuota;
        }).collect(Collectors.toList());
 
 
        List<SafeCheckSmartScreenRepsDTO> smartScreenDataS = new ArrayList<>();
        //首先获取有哪些巡检点 利用set属性进行去重
        HashSet<String> rfids = new HashSet<>();
 
        for (SafeCheckTaskAndQuotaRespDTO taskAndQuota : taskAndQuotas) {
            String rfid = taskAndQuota.getRfid();
            rfids.add(rfid);
        }
        if (rfids.size() == 0){
            return smartScreenDataS;
        }
 
        for (String rfid : rfids) {
            SafeCheckSmartScreenRepsDTO smartScreenData = new SafeCheckSmartScreenRepsDTO();
            List<SafeCheckTaskAndQuotaRespDTO> points = new ArrayList<>();
            HashSet<String> regionNames = new HashSet<>();
            for (int i = 0; i < taskAndQuotas.size(); i++) {
                String sonRfid = taskAndQuotas.get(i).getRfid();
                if (rfid.equals(sonRfid)){
                    if(smartScreenData.getRfid() == null){
                        SafeCheckRfid safeCheckRfid = safeCheckRfidService.getRfid(rfid, DelectStatusEnum.DELECT_NO.getStatus().intValue());
                        if (safeCheckRfid.getRfidImage() == null){
                            smartScreenData.setRfidImage(null);
                        }else {
                            String rfidImageAddress = safeCheckMinioAccessService.viewFile(safeCheckRfid.getRfidImage());
                            smartScreenData.setRfidImage(rfidImageAddress);
                        }
                        smartScreenData.setId(taskAndQuotas.get(i).getTaskId());
                        smartScreenData.setTaskUuid(taskAndQuotas.get(i).getTaskUuid());
                        smartScreenData.setRfid(taskAndQuotas.get(i).getRfid());
                        smartScreenData.setRfidName(taskAndQuotas.get(i).getRfidName());
                    }
                    regionNames.add(taskAndQuotas.get(i).getRegion());
                    points.add(taskAndQuotas.get(i));
                    smartScreenData.setPoints(points);
                }
            }
            ArrayList<String> regions = new ArrayList<>();
            for (String regionName : regionNames) {
                if (regionName != null){
                    regions.add(regionName);
                }
            }
            smartScreenData.setRegion(regions);
            smartScreenDataS.add(smartScreenData);
        }
        return smartScreenDataS;
    }
 
    /**
     * @description 根据巡检任务id获取该任务的异常工单信息
     */
    @Override
    public List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> getSmartScreenExcepOrderInfos(Long taskId) {
        LambdaQueryWrapper<AbnormalWorkOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AbnormalWorkOrder::getTaskId,taskId)
                .orderByDesc(AbnormalWorkOrder::getOccurrenceTime);
        List<AbnormalWorkOrder> abnormalWorkOrders = abnormalWorkOrderService.list(wrapper);
        if (CollectionUtils.isEmpty(abnormalWorkOrders)){
            return null;
        }
        List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> dtos = abnormalWorkOrders.stream().map((abnormalWorkOrder) -> {
            SafeCheckTaskAndQuotaExcepOrderRPCRespDTO excepOrderRPCRespDTO = new SafeCheckTaskAndQuotaExcepOrderRPCRespDTO();
            BeanUtils.copyProperties(abnormalWorkOrder, excepOrderRPCRespDTO);
            return excepOrderRPCRespDTO;
        }).collect(Collectors.toList());
        return dtos;
    }
 
    /**
     * @description 根据巡检任务id获取所有的巡检链数据,对相同的rfid进行分组反馈 以及异常信息
     */
    @Override
    public SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO getSmartScreenDataAndExcOrderInfo(Long taskId) {
        SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO dto = new SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO();
        List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> excepOrderInfos = getSmartScreenExcepOrderInfos(taskId);
        List<SafeCheckSmartScreenRepsDTO> screenData = getSmartScreenData(taskId);
        dto.setExcepOrder(excepOrderInfos);
        dto.setRfidInfos(screenData);
        return dto;
    }
}