xiangpei
2024-07-23 f5e1051a7e6d3ffccc815a631d8be372d772c58f
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package com.ycl.platform.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.platform.domain.entity.WorkOrder;
import com.ycl.platform.domain.entity.YwThreshold;
import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult;
import com.ycl.platform.mapper.WorkOrderMapper;
import com.ycl.platform.mapper.YwThresholdMapper;
import com.ycl.platform.service.IYwThresholdService;
import constant.CompareConstant;
import constant.YwThreadConstants;
import enumeration.general.BusinessTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.DateUtils;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 运维阈值Service业务层处理
 *
 * @author gonghl
 * @date 2024-07-19
 */
@Service
public class YwThresholdServiceImpl extends ServiceImpl<YwThresholdMapper, YwThreshold> implements IYwThresholdService {
    @Autowired
    private YwThresholdMapper ywThresholdMapper;
 
    /**
     * 查询运维阈值
     *
     * @param id 运维阈值主键
     * @return 运维阈值
     */
    @Override
    public YwThreshold selectYwThresholdById(Long id) {
        return ywThresholdMapper.selectYwThresholdById(id);
    }
 
    /**
     * 查询运维阈值列表
     *
     * @param ywThreshold 运维阈值
     * @return 运维阈值
     */
    @Override
    public Map<String, List<YwThreshold>> selectYwThresholdList(YwThreshold ywThreshold) {
        List<YwThreshold> ywThresholds = ywThresholdMapper.selectYwThresholdList(ywThreshold);
        Map<String, List<YwThreshold>> map = ywThresholds.stream().collect(Collectors.groupingBy(YwThreshold::getMonitorType));
        return map;
    }
 
    /**
     * 新增运维阈值
     *
     * @param ywThreshold 运维阈值
     * @return 结果
     */
    @Override
    public int insertYwThreshold(YwThreshold ywThreshold) {
        ywThreshold.setCreateTime(DateUtils.getNowDate());
        return ywThresholdMapper.insertYwThreshold(ywThreshold);
    }
 
    /**
     * 修改运维阈值
     *
     * @param list 运维阈值
     * @return 结果
     */
    @Override
    public Boolean updateYwThreshold(List<YwThreshold> list) {
        list.forEach(item -> item.setCreateTime(new Date()));
        return updateBatchById(list);
    }
 
    /**
     * 批量删除运维阈值
     *
     * @param ids 需要删除的运维阈值主键
     * @return 结果
     */
    @Override
    public int deleteYwThresholdByIds(Long[] ids) {
        return ywThresholdMapper.deleteYwThresholdByIds(ids);
    }
 
    /**
     * 删除运维阈值信息
     *
     * @param id 运维阈值主键
     * @return 结果
     */
    @Override
    public int deleteYwThresholdById(Long id) {
        return ywThresholdMapper.deleteYwThresholdById(id);
    }
 
 
    @Override
    public void faceCheck(List list) {
 
    }
 
    @Override
    public void videoCheck(List list) {
 
    }
 
    /**
     * 判断车辆阈值是否满足下发条件
     *
     * @param list
     */
    @Override
    public void carCheck(List<VehicleDeviceInspectionResult> list) {
        QueryWrapper<YwThreshold> wrapper = new QueryWrapper<>();
        wrapper.eq("monitor_type", BusinessTypeEnum.CAR.name());
        List<YwThreshold> ywThresholds = ywThresholdMapper.selectList(wrapper);
        Map<String, YwThreshold> map = new HashMap<>();
        for (YwThreshold ywThreshold : ywThresholds) {
            String key = ywThreshold.getKey();
            map.put(key, ywThreshold);
        }
        //时钟准确率阈值
        Float clockPercent = Float.valueOf(map.get(YwThreadConstants.Car_ClockPercent).getValue());
        Float clockPercentAuto = Float.valueOf(map.get(YwThreadConstants.Car_ClockPercent).getValueAuto());
        //数据及时率阈值
        Float timelyPercent = Float.valueOf(map.get(YwThreadConstants.Car_TimelyPercent).getValue());
        Float timelyPercentAuto = Float.valueOf(map.get(YwThreadConstants.Car_TimelyPercent).getValueAuto());
        //持续无数据天数阈值
        Integer continueNoDataCount = Integer.valueOf(map.get(YwThreadConstants.Car_ContinueNoDataCount).getValue());
        Integer continueNoDataCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_ContinueNoDataCount).getValueAuto());
        //不唯一数据量阈值
        Integer nouniqueCount = Integer.valueOf(map.get(YwThreadConstants.Car_NouniqueCount).getValue());
        Integer nouniqueCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_NouniqueCount).getValueAuto());
        //白天未识别量阈值
        Integer dayNoNumberCount = Integer.valueOf(map.get(YwThreadConstants.Car_DayNoNumberCount).getValue());
        Integer dayNoNumberCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_DayNoNumberCount).getValueAuto());
        //车辆六项属性不完整量阈值
        Integer noIntegrityCount = Integer.valueOf(map.get(YwThreadConstants.Car_NoIntegrityCount).getValue());
        Integer noIntegrityCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_NoIntegrityCount).getValueAuto());
 
        //处理接口数据
        for (VehicleDeviceInspectionResult result : list) {
            if (result == null) {
                log.error("车辆对象数据为空");
                continue;
            }
            //检查持续无数据天数
            Integer continueNoDataCountResult = result.getContinueNoDataCount();
            check(continueNoDataCount, continueNoDataCountAuto, result, continueNoDataCountResult, "车辆持续无数据天数为空", CompareConstant.MoreThanEq);
            //检查时钟准确率
            Float clockPercentResult = result.getSnapClock().getClockPercent();
            check(clockPercent, clockPercentAuto, result, clockPercentResult, "车辆时钟准确率为空", CompareConstant.LessThanEq);
            //检查数据及时率
            Float timelyPercentResult = result.getSnapTimely().getTimelyPercent();
            check(timelyPercent, timelyPercentAuto, result, timelyPercentResult, "车辆数据及时率为空", CompareConstant.LessThanEq);
            //检查不唯一数据量
            Integer nouniqueCountResult = result.getSnapUnique().getNouniqueCount();
            check(nouniqueCount, nouniqueCountAuto, result, nouniqueCountResult, "车辆不唯一数据量为空", CompareConstant.MoreThanEq);
            //检查白天未识别量
            Integer dayNoNumberCountResult = result.getSnapPlate().getDayNoNumberCount();
            check(dayNoNumberCount, dayNoNumberCountAuto, result, dayNoNumberCountResult, "车辆白天未识别量为空", CompareConstant.MoreThanEq);
            //车辆六项属性不完整量
            Integer noIntegrityCountResult = result.getIntegrity().getNoIntegrityCount();
            check(noIntegrityCount, noIntegrityCountAuto, result, noIntegrityCountResult, "车辆六项属性不完整量为空", CompareConstant.MoreThanEq);
        }
 
    }
 
    private void check(Integer threshold, Integer thresholdAuto, VehicleDeviceInspectionResult result, Integer thresholdResult, String message, String command) {
        if (thresholdResult != null) {
            //大于类型
            if (CompareConstant.MoreThanEq.equals(command)) {
                if (thresholdResult >= thresholdAuto) {
                    //TODO:自动下发工单
                } else if (thresholdResult >= threshold) {
                    //TODO:进入下发工单页面
                }
            } else if (CompareConstant.LessThanEq.equals(command)) {
                //小于类型
                if (thresholdResult <= thresholdAuto) {
                    //TODO:自动下发工单
                } else if (thresholdResult <= threshold) {
                    //TODO:进入下发工单页面
                }
            }
        } else {
            log.error(message + result);
        }
    }
 
    private void check(Float threshold, Float thresholdAuto, VehicleDeviceInspectionResult result, Float thresholdResult, String message, String command) {
        if (thresholdResult != null) {
            //大于类型
            if (CompareConstant.MoreThanEq.equals(command)) {
                if (thresholdResult >= thresholdAuto) {
                    //TODO:自动下发工单
                } else if (thresholdResult >= threshold) {
                    //TODO:进入下发工单页面
                }
            } else if (CompareConstant.LessThanEq.equals(command)) {
                //小于类型
                if (thresholdResult <= thresholdAuto) {
                    //TODO:自动下发工单
                } else if (thresholdResult <= threshold) {
                    //TODO:进入下发工单页面
                }
            }
        } else {
            log.error(message + result);
        }
    }
}