DssDriverController.java
10 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package com.ruoyi.controller.dss;
import cn.hutool.core.convert.Convert;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.exception.file.FileUploadException;
import com.ruoyi.domain.driver.NewDriver;
import com.ruoyi.domain.driver.dss.syn.DrivePosEnum;
import com.ruoyi.domain.driver.dss.syn.login.dto.LoginDriverDTO;
import com.ruoyi.domain.driver.dss.syn.login.vo.LoginDriverVo;
import com.ruoyi.domain.driver.dss.syn.login.vo.LoginUserInfoVo;
import com.ruoyi.domain.dss.sign.dto.DssGetWineRecordDTO;
import com.ruoyi.domain.dss.sign.dto.DssSignDTO;
import com.ruoyi.domain.dss.sign.dto.DssSignOutDTO;
import com.ruoyi.domain.dss.sign.vo.DssSignVo;
import com.ruoyi.domain.dss.sign.vo.GetWineRecordVo;
import com.ruoyi.domain.dss.sign.vo.SignOutVo;
import com.ruoyi.in.domain.SignIn;
import com.ruoyi.in.service.ISignInService;
import com.ruoyi.pojo.response.SignInResponseVo;
import com.ruoyi.service.driver.NewDriverService;
import com.ruoyi.service.dss.FaceService;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* @author liujun
* @date 2024年07月11日 16:37
*/
@RestController
@Slf4j
@RequestMapping("/dss/Driver")
@Api(tags = "【蓝斯一期】人员信息")
public class DssDriverController extends BaseController {
@Autowired
private NewDriverService newDriverService;
@Autowired
private ISysDictDataService sysDictDataService;
@Autowired
private ISignInService signInService;
@Autowired
private FaceService faceService;
@PostMapping(value = "Login")
@ApiOperation("人员登录设备")
public ResponseResult<LoginDriverVo> login(@Valid @RequestBody LoginDriverDTO loginDriverDTO, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
// Integer id = checkFace();
// if (Objects.isNull(id)) {
// return AjaxResult.error("登陆数据错误,无法识别人脸");
// }
// NewDriver newDriver = newDriverService.getById(id);
NewDriver driver = faceService.checkFace(convertLoginDriverDTO(loginDriverDTO));
return ResponseResult.success(convertNewDriver(driver));
}
@PostMapping(value = "SignIn")
@ApiOperation("人员签到")
public ResponseResult<DssSignVo> sign(@Valid @RequestBody DssSignDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
SignIn signIn = convertSignIn(dto);
try {
AjaxResult ajaxResult = signInService.addSignIn(signIn);
if (ajaxResult.isSuccess()) {
SignInResponseVo responseVo = (SignInResponseVo) ajaxResult.get(AjaxResult.DATA_TAG);
if (Objects.nonNull(responseVo)) {
return ResponseResult.success(convertSignInVo(responseVo));
}
}
return ResponseResult.error(Convert.toInt(ajaxResult.get(AjaxResult.CODE_TAG)), Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG)));
} catch (FileUploadException | IOException e) {
log.error("签到信息异常,传入的参数为:[{}]", dto, e);
return ResponseResult.error();
}
}
@PostMapping(value = "SignOut")
@ApiOperation("人员签退")
public ResponseResult<SignOutVo> signOut(@Valid @RequestBody DssSignOutDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
SignIn signIn = convertSignIn(dto);
try {
AjaxResult ajaxResult = signInService.addSignIn(signIn);
if (Objects.nonNull(ajaxResult) && ajaxResult.isSuccess()) {
return ResponseResult.success(convertSignOutVo(dto));
}
return ResponseResult.error(Convert.toInt(ajaxResult.get(AjaxResult.CODE_TAG)), Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG)));
} catch (FileUploadException | IOException e) {
log.error("签到信息异常,传入的参数为:[{}]", dto, e);
return ResponseResult.error();
}
}
@GetMapping(value = "GetWineRecord")
@ApiOperation("校验司机酒测记录是否有效")
public ResponseResult<GetWineRecordVo> getWineRecord(@Valid @RequestBody DssGetWineRecordDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
SignIn signIn = convertSignIn(dto);
SignIn dataSignIn = signInService.getLastOne(signIn);
return ResponseResult.success(convertGetWineRecordVo(dataSignIn));
}
/***
* 登陆转换
* @author liujun
* @date 2024/7/11 17:26
* @param newDriver
* @return com.ruoyi.domain.driver.dss.syn.login.vo.LoginDriverVo
*/
private LoginDriverVo convertNewDriver(NewDriver newDriver) {
LoginDriverVo loginDriverVo = new LoginDriverVo();
loginDriverVo.setDriverCode(newDriver.getIcRfid());
loginDriverVo.setDriverName(newDriver.getPersonnelName());
loginDriverVo.setWorkCode(newDriver.getJobCode());
loginDriverVo.setStaffCode(newDriver.getJobCode());
loginDriverVo.setStaffType(DrivePosEnum.getObjValueOfLabel(newDriver.getPosts()));
loginDriverVo.setCropFacePhotoUrl(newDriver.getImage());
loginDriverVo.setBlueTooth(newDriver.getBlueTooth());
loginDriverVo.setFaceFeature(newDriver.getFaceFeature());
loginDriverVo.setSynState(newDriver.getInteger());
loginDriverVo.setSynContent(newDriver.getSyncontent());
loginDriverVo.setCsn(newDriver.getCsn());
int healThCheck = 0;
SysDictData dictData = querySystData(newDriver.getPosts(), "healthCheck");
if (Objects.nonNull(dictData) && StringUtils.isNotEmpty(dictData.getDictValue())) {
healThCheck = Convert.toInt(dictData.getDictValue());
}
loginDriverVo.setHealthCheck(healThCheck);
loginDriverVo.setSignInType(signInService.signInType(newDriver));
loginDriverVo.setSignOutType(signInService.signOutType(newDriver));
Set<Integer> postSets = new HashSet<>();
loginDriverVo.setStaffTypeItem(postSets);
LoginUserInfoVo loginUserInfoVo = new LoginUserInfoVo();
loginUserInfoVo.setStaffId(Convert.toStr(newDriver.getId()));
loginUserInfoVo.setStaffName(newDriver.getPersonnelName());
loginUserInfoVo.setIcCardNo(newDriver.getIcRfid());
loginUserInfoVo.setFacePhotoPath(newDriver.getImage());
loginDriverVo.setUserInfo(loginUserInfoVo);
return loginDriverVo;
}
/***
* 查询数据字典
* @author liujun
* @date 2024/7/12 10:15
* @return com.ruoyi.common.core.domain.entity.SysDictData
*/
private SysDictData querySystData(String disKey, String type) {
SysDictData sysDictData = new SysDictData();
sysDictData.setStatus("0");
sysDictData.setDictType(type);
sysDictData.setDiscKey(disKey);
return sysDictDataService.getOne(sysDictData);
}
private NewDriver convertLoginDriverDTO(LoginDriverDTO loginDriverDTO) {
NewDriver driver = new NewDriver();
driver.setImage(loginDriverDTO.getAuthValue());
// driver.setIcCardCode()
return driver;
}
private SignIn convertSignIn(DssSignDTO dto) {
SignIn signIn = new SignIn();
signIn.setDeviceId(dto.getDevice());
// signIn.setImage();
signIn.setJobCode(dto.getStaffCode());
signIn.setAlcoholIntake(Convert.toBigDecimal(dto.getTestValue()));
signIn.setCreateTime(dto.getSignTime());
signIn.setType(1);
// SysDictData sysDictData = querySystData(null,"drunkenness");
// if(Objects.nonNull(sysDictData)){
//
// }
return signIn;
}
private SignIn convertSignIn(DssSignOutDTO dto) {
SignIn signIn = new SignIn();
signIn.setDeviceId(dto.getDevice());
// signIn.setImage();
signIn.setJobCode(dto.getDriverCode());
signIn.setCreateTime(dto.getLogoutTime());
signIn.setType(2);
// SysDictData sysDictData = querySystData(null,"drunkenness");
// if(Objects.nonNull(sysDictData)){
//
// }
return signIn;
}
private SignIn convertSignIn(DssGetWineRecordDTO dto) {
SignIn signIn = new SignIn();
signIn.setJobCode(dto.getStaffCode());
signIn.setDeviceId(dto.getDevice());
return signIn;
}
private DssSignVo convertSignInVo(SignInResponseVo responseVo) {
DssSignVo vo = new DssSignVo();
vo.setTestId(Convert.toStr(responseVo.getId()));
Integer testResult = Objects.equals(responseVo.getExType(), 3) ? 2 : 0;
vo.setTestResult(testResult);
Integer result = Objects.isNull(responseVo.getStatus()) ? 0 : responseVo.getStatus() - 1;
vo.setResult(result);
return vo;
}
private SignOutVo convertSignOutVo(DssSignOutDTO dto) {
return new SignOutVo(dto.getDevice(), dto.getDriverCode(), dto.getLogoutTime());
}
private GetWineRecordVo convertGetWineRecordVo(SignIn signIn) {
GetWineRecordVo vo = new GetWineRecordVo();
vo.setCheckTime(signIn.getCreateTime());
vo.setCheck(Objects.equals(signIn.getType(), 0));
return vo;
}
}