RemindDriverKeyLocalController.java
7.32 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
package com.ruoyi.controller.dss;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.domain.OrderEntity;
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.location.LinggangKeyWorkLocation;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
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;
@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.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<LinggangKeyWorkLocation> linggangKeyWorkLocations = null;
List<Equipment> equipments = null;
if (0 < size) {
Set<Long> schedulingIds = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
linggangKeyWorkLocations = linggangKeyWorkLocationService.listRecent(null, schedulingIds);
if (CollectionUtils.isNotEmpty(linggangKeyWorkLocations)) {
Set<String> deviceIds = linggangKeyWorkLocations.stream().map(LinggangKeyWorkLocation::getDevice).collect(Collectors.toSet());
equipments = equipmentService.listNameAndIDBydeviceIds(deviceIds);
}
}
RemindDriverReportVo reportVo = new RemindDriverReportVo();
reportVo.setCount(linggangSchedulings.stream().filter(ls -> StringUtils.equalsAnyIgnoreCase(ls.getBcType(), "out")).count());
if (CollectionUtils.isNotEmpty(linggangKeyWorkLocations)) {
List<RemindKeyInfoLocalVo> remindKeyInfoLocalVoList = new ArrayList<>();
for (int i = 0; i < size; i = i + 2) {
RemindKeyInfoLocalVo localVo = new RemindKeyInfoLocalVo();
localVo.setNbbm(linggangSchedulings.get(i).getNbbm());
int index = i;
Optional<LinggangKeyWorkLocation> optional = linggangKeyWorkLocations.stream().filter(kl -> Objects.equals(kl.getSchedulingId(), linggangSchedulings.get(index).getId())).findFirst();
if (optional.isPresent()) {
localVo.setKeyInfoStatus(optional.get().getType());
localVo.setYardName(optional.get().getYardName());
if (CollectionUtils.isNotEmpty(equipments)) {
Optional<LinggangKeyWorkLocation> finalOptional = optional;
Optional<Equipment> equipmentOptional = equipments.stream().filter(e -> Objects.equals(e.getDeviceId(), finalOptional.get().getDevice())).findFirst();
equipmentOptional.ifPresent(equipment -> localVo.setEquipmentName(equipment.getName()));
if (i == 0) {
}
}
if (i + 1 < size) {
optional = linggangKeyWorkLocations.stream().filter(kl -> Objects.equals(kl.getSchedulingId(), linggangSchedulings.get(index).getId())).findFirst();
if (optional.isPresent()) {
localVo.setReturnYardName(optional.get().getYardName());
if (CollectionUtils.isNotEmpty(equipments)) {
Optional<LinggangKeyWorkLocation> finalOptional = optional;
Optional<Equipment> equipmentOptional = equipments.stream().filter(e -> Objects.equals(e.getDeviceId(), finalOptional.get().getDevice())).findFirst();
equipmentOptional.ifPresent(equipment -> localVo.setReturnEquipmentName(equipment.getName()));
}
}
}
}
remindKeyInfoLocalVoList.add(localVo);
}
Optional<LinggangScheduling> opt = linggangSchedulings.stream().filter(f -> Objects.nonNull(f.getSignInId())).max(Comparator.comparing(LinggangScheduling::getFcsjT));
if (opt.isPresent()) {
Optional<LinggangKeyWorkLocation> optional = linggangKeyWorkLocations.stream().filter(kl -> Objects.equals(kl.getSchedulingId(), opt.get().getId())).findFirst();
if (optional.isPresent()) {
Optional<Equipment> equipmentOptional = equipments.stream().filter(e -> Objects.equals(e.getDeviceId(), optional.get().getDevice())).findFirst();
equipmentOptional.ifPresent(equipment -> reportVo.setCurrentKeyLocaltion(equipment.getName()));
}
} else {
Optional<LinggangKeyWorkLocation> optional = linggangKeyWorkLocations.stream().filter(kl -> Objects.equals(kl.getSchedulingId(), linggangSchedulings.get(0).getId())).findFirst();
if (optional.isPresent()) {
Optional<Equipment> equipmentOptional = equipments.stream().filter(e -> Objects.equals(e.getDeviceId(), optional.get().getDevice())).findFirst();
equipmentOptional.ifPresent(equipment -> reportVo.setCurrentKeyLocaltion(equipment.getName()));
}
}
reportVo.setRemindKeyInfoLocalVoList(remindKeyInfoLocalVoList);
}
return ResponseResult.success(reportVo);
}
}