KeyBoxController.java
7.18 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
package com.ruoyi.controller.dss;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.ConstDriverProperties;
import com.ruoyi.common.TipEnum;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.caiinfo.CarInfo;
import com.ruoyi.domain.dss.key.location.dto.WorkPlateV2DTO;
import com.ruoyi.domain.dss.key.location.vo.WorkPlateV2Vo;
import com.ruoyi.domain.equipment.linke.log.LingangEquipmentLinkeLog;
import com.ruoyi.domain.key.info.KeyInfo;
import com.ruoyi.domain.key.info.box.dto.KeyBoxQueryDTO;
import com.ruoyi.domain.key.info.box.vo.KeyBoxVo;
import com.ruoyi.domain.key.location.LinggangKeyWorkLocation;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.service.carinfo.CarInfoService;
import com.ruoyi.service.dss.KeyBoxVoService;
import com.ruoyi.service.equipment.linke.log.LingangEquipmentLinkeLogService;
import com.ruoyi.service.key.info.KeyInfoService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.text.ParseException;
import java.util.Date;
import java.util.Objects;
/**
* @author liujun
* @date 2024年06月25日 13:04
*/
@RestController
@RequestMapping("/dss")
@Api(tags = "【蓝斯一期】钥匙信息")
public class KeyBoxController extends BaseController {
@Autowired
private LingangEquipmentLinkeLogService lingangEquipmentLinkeLogService;
@Autowired
private KeyBoxVoService keyBoxVoService;
@Autowired
private LinggangKeyWorkLocationService linggangKeyWorkLocationService;
@Autowired
private LinggangSchedulingService schedulingService;
@Autowired
private KeyInfoService keyInfoService;
@Autowired
private CarInfoService carInfoService;
@PostMapping(value = "/keybox/findKey")
@ApiOperation("钥匙信息查询")
public ResponseResult<KeyBoxVo> listSelect(@Valid @RequestBody KeyBoxQueryDTO request,BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
LingangEquipmentLinkeLog linkeLog = saveLog(request);
return keyBoxVoService.listSelect(request, linkeLog);
}
@PostMapping(value = "/Driver/workPlateV2")
@ApiOperation("司机获取当前工作的车辆钥匙信息")
public ResponseResult<WorkPlateV2Vo> workPlateV2(@Valid @RequestBody WorkPlateV2DTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
try {
LinggangScheduling scheduling = queryScheduling(dto);
if (Objects.isNull(scheduling)) {
return ResponseResult.error(TipEnum.TIP_3.getCode(), TipEnum.TIP_3.getMsg());
}
LinggangKeyWorkLocation workLocation = queryKeyWorkLocation(scheduling.getKeyInfoId(), scheduling.getScheduleDate(), dto);
if (Objects.isNull(workLocation)) {
return ResponseResult.error(TipEnum.TIP_4.getCode(), TipEnum.TIP_4.getMsg());
}
KeyInfo keyInfo = queryKeyInfo(scheduling.getKeyInfoId());
if (Objects.isNull(keyInfo)) {
return ResponseResult.error(TipEnum.TIP_404.getCode(), TipEnum.TIP_404.getMsg());
}
CarInfo carInfo = queryCarInfo(scheduling.getNbbm());
if (Objects.isNull(carInfo)) {
return ResponseResult.error(TipEnum.TIP_404.getCode(), TipEnum.TIP_404.getMsg());
}
WorkPlateV2Vo vo = convertWorkPlateV2Vo(scheduling, workLocation, keyInfo, carInfo);
return ResponseResult.success(vo);
} catch (ParseException e) {
logger.error("司机获取当前工作的车辆钥匙信息异常:[{}]", dto, e);
}
return ResponseResult.error();
}
/***
* 查询排班
* @author liujun
* @date 2024/7/16 17:05
* @param dto
* @return com.ruoyi.domain.scheduling.LinggangScheduling
*/
private LinggangScheduling queryScheduling(WorkPlateV2DTO dto) throws ParseException {
LinggangScheduling scheduling = new LinggangScheduling();
scheduling.setJobCode(dto.getStaffCode());
String dateStr = DateUtils.YYYY_MM_DD.format(dto.getTime());
scheduling.setScheduleDate(DateUtils.YYYY_MM_DD.parse(dateStr));
String bcType = Objects.equals(0, dto.getEventType()) ? ConstDriverProperties.BC_TYPE_OUT : Objects.equals(1, dto.getEventType()) ? ConstDriverProperties.BC_TYPE_IN : "other";
scheduling.setBcType(bcType);
return schedulingService.getOne(scheduling);
}
/***
* 根据排班时间和钥匙ID查询钥匙
* @author liujun
* @date 2024/7/16 17:05
* @param keyId
* @param scheduleDate
* @param dto
* @return com.ruoyi.domain.key.location.LinggangKeyWorkLocation
*/
private LinggangKeyWorkLocation queryKeyWorkLocation(Integer keyId, Date scheduleDate, WorkPlateV2DTO dto) {
LinggangKeyWorkLocation workLocation = new LinggangKeyWorkLocation();
workLocation.setKeyInfoId(keyId);
workLocation.setScheduleDate(scheduleDate);
return linggangKeyWorkLocationService.getOne(workLocation);
}
private KeyInfo queryKeyInfo(Integer keyId) {
return keyInfoService.getById(keyId);
}
private CarInfo queryCarInfo(String nbbm) {
CarInfo carInfo = new CarInfo();
carInfo.setNbbm(nbbm);
return carInfoService.getOne(carInfo);
}
/***
* 保存链接日志
* @author liujun
* @date 2024/6/25 15:24
* @param request
* @return com.ruoyi.domain.equipment.linke.log.LingangEquipmentLinkeLog
*/
private LingangEquipmentLinkeLog saveLog(KeyBoxQueryDTO request) {
LingangEquipmentLinkeLog linkeLog = new LingangEquipmentLinkeLog();
linkeLog.setDevice(request.getDevice());
linkeLog.setCreateTime(new Date());
linkeLog.setPassingReferences(JSON.toJSONString(request));
linkeLog.setUrl("/dss/keybox/findKey");
lingangEquipmentLinkeLogService.save(linkeLog);
return linkeLog;
}
private WorkPlateV2Vo convertWorkPlateV2Vo(LinggangScheduling scheduling, LinggangKeyWorkLocation workLocation, KeyInfo keyInfo, CarInfo carInfo) {
WorkPlateV2Vo vo = new WorkPlateV2Vo();
vo.setYardId(Convert.toStr(keyInfo.getYardId()));
// vo.setYardName(keyInfo.getY)
vo.setDevice(workLocation.getDevice());
vo.setCabinetNo(workLocation.getCabinetNo());
vo.setPlateNum(carInfo.getPlateNum());
return vo;
}
}