RemindDriverKeyLocalController.java
11 KB
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
222
223
224
225
226
package com.ruoyi.controller.dss;
import cn.hutool.core.convert.Convert;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.domain.OrderEntity;
import com.ruoyi.domain.caiinfo.CarInfo;
import com.ruoyi.domain.dss.key.location.vo.RemindKeyInfoLocalVo;
import com.ruoyi.domain.dss.scheling.dto.RemindDriverReportDTO;
import com.ruoyi.domain.dss.scheling.vo.RemindDriverReportVo;
import com.ruoyi.domain.key.info.KeyInfo;
import com.ruoyi.domain.key.location.LinggangKeyWorkLocation;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import com.ruoyi.service.carinfo.CarInfoService;
import com.ruoyi.service.key.info.KeyInfoService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import com.ruoyi.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author liujun
* @date 2024年10月09日 15:48
*/
@Slf4j
@RestController
@RequestMapping("/dss")
@Api(tags = "【对接】钥匙提醒功能")
public class RemindDriverKeyLocalController extends BaseController {
@Autowired
private LinggangSchedulingService linggangSchedulingService;
@Autowired
private LinggangKeyWorkLocationService linggangKeyWorkLocationService;
@Autowired
private IEquipmentService equipmentService;
@Autowired
private CarInfoService carInfoService;
@Autowired
private KeyInfoService keyInfoService;
@ApiOperation("司机提醒信息")
@PostMapping(value = "/remind/driver/key/local/report")
public ResponseResult<RemindDriverReportVo> remindDriverKeyLocalReport(@Valid @RequestBody RemindDriverReportDTO request, BindingResult bindingResult) {
// 检查参数绑定结果,如果有错误则返回错误信息
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
// 创建并初始化冷柜调度对象
LinggangScheduling scheduling = new LinggangScheduling();
scheduling.setJobCode(request.getJobCode());
scheduling.setScheduleDate(request.getDate());
scheduling.setStartScheduleDate(request.getDate());
scheduling.setEndScheduleDate(DateUtils.addDays(request.getDate(), 1));
// 创建并初始化订单实体对象,用于排序
OrderEntity orderEntity = new OrderEntity();
orderEntity.setOrder("ascending");
orderEntity.setProp("fcsjT");
// 查询符合条件的冷柜调度列表
List<LinggangScheduling> linggangSchedulings = linggangSchedulingService.list(scheduling, orderEntity);
int size = CollectionUtils.size(linggangSchedulings);
// 初始化钥匙信息和车辆信息列表
List<KeyInfo> keyInfos = null;
List<CarInfo> carInfos = null;
// 如果调度列表不为空,根据调度信息获取车辆信息
if (0 < size) {
Set<String> nbbms = linggangSchedulings.stream().map(LinggangScheduling::getNbbm).collect(Collectors.toSet());
carInfos = carInfoService.list(nbbms);
}
// 如果车辆信息不为空,根据车辆信息获取钥匙信息
if (CollectionUtils.isNotEmpty(carInfos)) {
Set<String> plateNums = carInfos.stream().map(CarInfo::getPlateNum).collect(Collectors.toSet());
keyInfos = keyInfoService.listPlateNums(plateNums);
}
// 计算车辆和钥匙信息的大小
int carSize = CollectionUtils.size(carInfos);
int keyInfoSize = CollectionUtils.size(keyInfos);
// 创建并初始化提醒司机报告视图对象
RemindDriverReportVo reportVo = new RemindDriverReportVo();
List<LinggangScheduling> values = linggangSchedulings.stream().filter(ls -> StringUtils.equalsAnyIgnoreCase(ls.getBcType(), "out")).collect(Collectors.toList());
size = CollectionUtils.size(values);
reportVo.setCount(Convert.toLong(size));
// 如果调度列表不为空,处理每个调度信息,生成提醒信息列表
if (size > 0) {
List<RemindKeyInfoLocalVo> remindKeyInfoLocalVoList = new ArrayList<>();
for (int i = 0; i < size; i++) {
RemindKeyInfoLocalVo localVo = new RemindKeyInfoLocalVo();
localVo.setNbbm(values.get(i).getNbbm());
// 初始化工作位置对象
LinggangKeyWorkLocation workLocation = new LinggangKeyWorkLocation();
if (carSize > 0 && keyInfoSize > 0) {
int index = i;
Optional<CarInfo> optionalCarInfo = carInfos.stream().filter(c -> Objects.equals(c.getNbbm(), values.get(index).getNbbm())).findFirst();
if (optionalCarInfo.isPresent()) {
Optional<KeyInfo> optional = keyInfos.stream().filter(k -> Objects.equals(k.getPlateNum(), optionalCarInfo.get().getPlateNum())).findFirst();
optional.ifPresent(k -> workLocation.setKeyInfoId(k.getId()));
}
}
// 根据钥匙ID和时间获取工作位置信息
List<LinggangKeyWorkLocation> keyWorkLocations = null;
if (Objects.nonNull(workLocation.getKeyInfoId())) {
workLocation.setMaxCreateDate(new Date());
keyWorkLocations = linggangKeyWorkLocationService.getTenByKeyIdAndTime(workLocation);
}
// 处理工作位置信息,确定钥匙状态和相关设备信息
if (CollectionUtils.isNotEmpty(keyWorkLocations)) {
int klSize = CollectionUtils.size(keyWorkLocations);
LinggangKeyWorkLocation sourceKL200 = null;
LinggangKeyWorkLocation sourceKL1 = null;
LinggangKeyWorkLocation sourceKL0 = null;
for (int j = 0; j < klSize; j++) {
if (Objects.equals(keyWorkLocations.get(j).getType1(), 2) && Objects.isNull(sourceKL200)) {
sourceKL200 = keyWorkLocations.get(j);
sourceKL200.setIndex(j);
} else if (Objects.equals(keyWorkLocations.get(j).getType1(), 1) && Objects.isNull(sourceKL1)) {
sourceKL1 = keyWorkLocations.get(j);
sourceKL1.setIndex(j);
} else if (Objects.equals(keyWorkLocations.get(j).getType1(), 0) && Objects.isNull(sourceKL0)) {
sourceKL0 = keyWorkLocations.get(j);
sourceKL0.setIndex(j);
} else if (Objects.nonNull(sourceKL200) && Objects.nonNull(sourceKL0) && Objects.nonNull(sourceKL1)) {
break;
}
}
// 根据工作位置信息设置提醒信息
if (Objects.nonNull(sourceKL0) && Objects.nonNull(sourceKL1) && Objects.nonNull(sourceKL0.getIndex()) && Objects.nonNull(sourceKL1.getIndex())) {
if (sourceKL0.getIndex() > sourceKL1.getIndex()) {
localVo.setKeyInfoStatus(0);
Equipment equipment = equipmentService.getOneByDeviceId(sourceKL1.getDevice());
if (Objects.nonNull(equipment)) {
localVo.setEquipmentName(equipment.getName());
localVo.setYardName(sourceKL0.getYardName());
}
} else {
localVo.setKeyInfoStatus(1);
}
} else if (Objects.nonNull(sourceKL1) && Objects.nonNull(sourceKL1.getIndex())) {
localVo.setKeyInfoStatus(0);
Equipment equipment = equipmentService.getOneByDeviceId(sourceKL1.getDevice());
if (Objects.nonNull(equipment)) {
localVo.setEquipmentName(equipment.getName());
localVo.setYardName(equipment.getYardName());
}
} else if (Objects.nonNull(sourceKL0) && Objects.nonNull(sourceKL0.getIndex())) {
localVo.setKeyInfoStatus(1);
} else if (Objects.nonNull(sourceKL200) && Objects.nonNull(sourceKL200.getIndex())) {
localVo.setKeyInfoStatus(16);
} else {
localVo.setKeyInfoStatus(255);
}
setReturnInfo(sourceKL200, localVo);
remindKeyInfoLocalVoList.add(localVo);
}
}
// 设置报告视图对象的提醒信息列表和当前位置信息
if(CollectionUtils.isNotEmpty(remindKeyInfoLocalVoList)) {
reportVo.setRemindKeyInfoLocalVoList(remindKeyInfoLocalVoList);
reportVo.setCurrentKeyLocaltion(remindKeyInfoLocalVoList.get(0).getEquipmentName());
}
}
// 返回成功响应结果
return ResponseResult.success(reportVo);
}
/**
* 设置返回信息
* 此方法用于将设备信息和场地名称设置到本地提醒信息对象中
*
* @param sourceKL200 来自KL200的源数据对象,包含设备ID和场地名称等信息
* @param localVo 本地提醒信息对象,用于存储返回的设备名称和场地名称
*/
private void setReturnInfo(LinggangKeyWorkLocation sourceKL200, RemindKeyInfoLocalVo localVo) {
// 检查输入对象是否为空,如果任一对象为空,则不执行后续操作
if (Objects.isNull(sourceKL200) || Objects.isNull(localVo)) {
return;
}
// 根据设备ID获取设备信息
Equipment equipment = equipmentService.getOneByDeviceId(sourceKL200.getDevice());
// 检查是否找到对应的设备信息,如果未找到,则不执行后续操作
if (Objects.isNull(equipment)) {
return;
}
// 设置本地提醒信息对象的返回设备名称
localVo.setReturnEquipmentName(equipment.getName());
// 设置本地提醒信息对象的返回场地名称
localVo.setReturnYardName(sourceKL200.getYardName());
}
}