RemindDriverKeyLocalController.java
9.29 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
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()));
}
}
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);
}
private void setReturnInfo(LinggangKeyWorkLocation sourceKL200, RemindKeyInfoLocalVo localVo) {
if (Objects.isNull(sourceKL200) || Objects.isNull(localVo)) {
return;
}
Equipment equipment = equipmentService.getOneByDeviceId(sourceKL200.getDevice());
if (Objects.isNull(equipment)) {
return;
}
localVo.setReturnEquipmentName(equipment.getName());
localVo.setReturnYardName(sourceKL200.getYardName());
}
}