VehicleController.java
19.4 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
package cn.com.glsx.admin.modules.controller;
import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.common.enums.ResultEnum;
import cn.com.glsx.admin.common.exception.AdminException;
import cn.com.glsx.admin.modules.model.*;
import cn.com.glsx.admin.modules.model.export.TrialDriveVehicleExport;
import cn.com.glsx.admin.modules.model.export.VehicleInfoReportExport;
import cn.com.glsx.admin.modules.model.imports.TrialDriveVehicleImport;
import cn.com.glsx.admin.modules.model.imports.TrialDriveVehicleImportListener;
import cn.com.glsx.admin.modules.model.imports.VehicleInfoImport;
import cn.com.glsx.admin.modules.model.imports.VehicleInfoImportListener;
import cn.com.glsx.admin.modules.model.param.*;
import cn.com.glsx.admin.modules.service.DeviceService;
import cn.com.glsx.admin.modules.service.VehicleService;
import cn.com.glsx.admin.modules.utils.FileIOUtil;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageInfo;
import com.glsx.biz.common.base.entity.*;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Desc:车辆管理
* @Author huangxc
* @Date 2021/5/19
*/
@Slf4j
@RestController
@RequestMapping(value = "/vehicle")
@Api(value = "车辆管理", tags = {"车辆管理"})
public class VehicleController {
private final static String MODULE = "试驾车辆管理";
@Autowired
private VehicleService vehicleService;
@Autowired
private DeviceService deviceService;
@Autowired
private HttpServletResponse response;
@ApiOperation(value = "试驾车辆列表查询")
@SysLog(module = MODULE, value = "试驾车辆列表查询", action = OperateType.QUERY)
@GetMapping("/drivevehicle/search")
public R search(VehicleManageSearch search) {
PageInfo<TrialDriveVehiclePageDTO> pageInfo = vehicleService.searchTrialDrive(search);
return R.ok().putPageData(pageInfo);
}
@ApiOperation(value = "查询该组织下没有绑定为试驾车辆的列表")
@SysLog(module = MODULE, value = "查询该组织下没有绑定为试驾车辆的列表", action = OperateType.QUERY)
@GetMapping("/drivevehicle/listtestdrive")
public R listTestDriveVehicle(TestVehicleSearch testVehicleVo) {
PageInfo<TestVehicleDTO> testDriveVehicleList = vehicleService.listTestDriveVehicle(testVehicleVo);
return R.ok().putPageData(testDriveVehicleList);
}
@ApiOperation(value = "新增绑定试驾车辆")
@SysLog(module = MODULE, value = "新增绑定试驾车辆", action = OperateType.ADD)
@PostMapping("/drivevehicle/addtestdrive")
public R addTestDriveVehicle(@RequestBody TestDriveVehicleBo testDriveData) {
if (testDriveData == null) {
return R.error("输入的数据不能为空===");
}
List<TestVehicleBo> testVehicleBos = testDriveData.getTestDriveData();
for (TestVehicleBo testVehicleBo : testVehicleBos) {
vehicleService.addTestDriveVehicle(testVehicleBo);
}
return R.ok();
}
@Deprecated
@ApiOperation(value = "新增试驾车辆")
@SysLog(module = MODULE, value = "新增试驾车辆", action = OperateType.ADD)
@PostMapping("/drivevehicle/add")
public R addDriveVehicle(@RequestBody @Validated(ValidateGroups.Insert.class) TrialDriveVehicleBo driveVehicleBo) {
vehicleService.addDriveVehicle(driveVehicleBo);
return R.ok();
}
@ApiOperation(value = "根据id查询某条试驾车辆数据(数据回显)")
@SysLog(module = MODULE, value = "根据id查询某条试驾车辆数据(数据回显)", action = OperateType.QUERY)
@GetMapping("/drivevehicle/findbyid")
public R findDriveVehicleById(@RequestParam String tempId) {
TrialDriveVehicleEditDTO vehicleEditDTO = vehicleService.findDriveVehicleById(tempId);
return R.ok().data(vehicleEditDTO);
}
@ApiOperation(value = "编辑试驾车辆")
@SysLog(module = MODULE, value = "编辑试驾车辆", action = OperateType.EDIT)
@PostMapping("/drivevehicle/update")
public R updateDriveVehicle(@RequestBody @Validated(ValidateGroups.Update.class) TrialDriveVehicleEditBo driveVehicleoBo) {
vehicleService.updateDriveVehicleById(driveVehicleoBo);
return R.ok();
}
@Deprecated
@ApiOperation(value = "设备和车辆解绑")
@SysLog(module = MODULE, value = "设备和车辆解绑", action = OperateType.EDIT)
@GetMapping("/unbindSn")
public R unbindDriveVehicle(@RequestParam(required = true) String tempId) {
vehicleService.unbindDriveVehicle(tempId);
return R.ok();
}
@ApiOperation(value = "删除试驾车辆数据")
@SysLog(module = MODULE, value = "删除试驾车辆数据", action = OperateType.DELETE)
@GetMapping("/drivevehicle/delete")
public R deleteDriveVehicle(@RequestParam Long id, @RequestParam String sn) {
vehicleService.deleteDriveVehicleAndUnBind(id, sn);
return R.ok();
}
@ApiOperation(value = "导出试驾车辆数据")
@GetMapping("/drivevehicle/export")
public void exportDriveVehicle(VehicleManageSearch search) throws Exception {
List<TrialDriveVehicleExport> list = vehicleService.exportDriveVehicle(search);
String fileName = "试驾车辆_" + DateUtils.formatSerial(new Date());
String sheetName = "Sheet1";
EasyExcelUtils.writeExcel(response, list, fileName, sheetName, TrialDriveVehicleExport.class);
}
@Deprecated
@ApiOperation(value = "导入试驾车辆数据")
@PostMapping(value = "/drivevehicle/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R importDriveVehicle(@RequestParam("file") MultipartFile file) throws IOException {
TrialDriveVehicleImportListener listener = new TrialDriveVehicleImportListener(vehicleService, deviceService);
EasyExcel.read(file.getInputStream(), TrialDriveVehicleImport.class, listener)
.head(TrialDriveVehicleImport.class)
.ignoreEmptyRow(false)
.sheet().doRead();
BaseImportInfo importInfo = listener.getBaseImportInfo();
return R.ok().data(importInfo);
}
/**
* 试驾车辆管理-下载车辆导入模板
*
* @throws Exception
*/
@ApiOperation(value = "下载车辆管理导入模板")
@GetMapping(value = "/drivevehicle/downloadtemplate")
public void downloadTemplate() throws Exception {
InputStream inputStream = VehicleController.class.getResourceAsStream("/templates/importVehicle.xlsx");
String fileName = "车辆管理导入模板";
FileIOUtil.download(inputStream, FileIOUtil.MimeType.EXCEL2007, fileName, response);
}
@ApiOperation(value = "下载导入失败的文件")
@GetMapping(value = "/drivevehicle/downloadFailFile")
public void downloadFailFile(String failSeqNoFile) throws Exception {
InputStream inputStream = vehicleService.downloadFailExcelFile(failSeqNoFile);
String fileName = "试驾车辆_" + DateUtils.formatSerial(new Date());
FileIOUtil.download(inputStream, FileIOUtil.MimeType.EXCEL2007, fileName, response);
}
@PostMapping(value = "/drivevehicle/syncVehicleInfo", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
@SysLog(module = MODULE, value = "同步车辆信息", action = OperateType.API, saveLog = false)
@ApiOperation(value = "同步车辆信息")
public R syncVehicleDeviceInfo(@RequestBody @Validated(ValidateGroups.Insert.class) SyncVehicleBo vehicleBo) {
try {
String chanle = vehicleBo.getChanle();
if (StringUtils.isNotBlank(chanle) && Constants.SYNC_CHANNEL_TIMED_TASK.equals(chanle)) {
vehicleService.syncVehicleDeviceLinkFence(vehicleBo);
} else {
return R.error("同步渠道不正确。chanle:" + chanle);
}
} catch (Exception e) {
log.info("同步车辆信息 异常:message:" + e.getMessage());
return R.error(e.getMessage());
}
return R.ok();
}
@ApiOperation(value = "车辆设备关联列表查询")
@GetMapping("/linksns/search")
public R search(VehicleSearch search) {
PageInfo<VehicleLinkSnsDTO> pageInfo = vehicleService.linkSnsSearch(search);
return R.ok().putPageData(pageInfo);
}
@ApiOperation(value = "车型管理列表查询")
@GetMapping("/tenanttypes/search")
public R tenantTypesSearch(TenantTypesSearch search) {
PageInfo<TenantTypesDTO> pageInfo = vehicleService.tenantTypesSearch(search);
return R.ok().putPageData(pageInfo);
}
@SysLog(module = "车型库管理", value = "删除车型库", action = OperateType.DELETE)
@ApiOperation(value = "删除车型库")
@GetMapping("/tenanttypes/delete")
public R deleteTenantTypes(@RequestParam Long tenantId) {
vehicleService.deleteTenantTypes(tenantId);
return R.ok();
}
@ApiOperation(value = "车辆品牌系别查询")
@GetMapping("/brandseries")
public R<List<CarBrandSelected>> brandsSeries(@RequestParam("full") Boolean full) {
List<CarBrandSelected> carBrandSeriesList = vehicleService.getCarBrandSeriesList(full);
return R.ok().data(carBrandSeriesList);
}
@ApiOperation(value = "车辆品牌查询")
@GetMapping("/brands")
public R<List<Carbrand>> brands() {
List<Carbrand> carBrandList = vehicleService.getAllBrandList();
return R.ok().data(carBrandList);
}
@ApiOperation(value = "车辆子品牌查询")
@GetMapping("/subbrands")
public R<List<Carbrand>> subBrands(@RequestParam Integer brandId) {
List<Carbrand> carBrandList = vehicleService.getSubBrandsByBrandId(brandId);
return R.ok().data(carBrandList);
}
@ApiOperation(value = "车辆系别查询")
@GetMapping("/series")
public R<List<Carseries>> series(@RequestParam Integer brandId) {
List<Carseries> carSeriesList = vehicleService.getSeriesByBrandId(brandId);
return R.ok().data(carSeriesList);
}
@ApiOperation(value = "车辆类型查询")
@GetMapping("/types")
public R<List<Cartype>> types(@RequestParam Integer seriesId) {
List<Cartype> carTypeList = vehicleService.getTypesBySeriesId(seriesId);
return R.ok().data(carTypeList);
}
@SysLog(module = "车型库管理", value = "保存车型库", action = OperateType.ADD)
@ApiOperation(value = "保存车型库")
@PostMapping("/savetypes")
public R<List<Cartype>> saveVehicleTypes(@RequestBody VehicleTypesBO typesBO) {
TenantTypesDTO typesDTO = vehicleService.getTenantTypes(typesBO.getTenantId());
//新增且车型库已经存在
if (typesBO.getFrom() == 1 && typesDTO != null) {
throw new AdminException(ResultEnum.TENANT_VEHICLE_TYPES_EXISTED);
}
vehicleService.saveVehicleTypes(typesBO, ShieldContextHolder.getUserId());
return R.ok();
}
@ApiOperation(value = "获取组织配置的车型库")
@GetMapping("/gettenanttypes")
public R<TenantTypesDTO> getTenantTypes(@RequestParam Long tenantId) {
TenantTypesDTO typesDTO = vehicleService.getTenantTypes(tenantId);
return R.ok().data(typesDTO);
}
@ApiOperation(value = "获取车型库配置树")
@GetMapping("/getSelectedTypeTree")
public R<List<CarInfoSelected>> getTypeSelectedTree() {
List<CarInfoSelected> selectedTree = vehicleService.getTypeSelectedTree(ShieldContextHolder.getVisibleTenantIds());
return R.ok().data(selectedTree);
}
/**
* 车辆信息表
*
* @param search 搜索条件
* @return 统一返回结果
*/
@ApiOperation(value = "车辆信息列表查询")
@SysLog(module = "车辆管理", value = "车辆信息列表查询", action = OperateType.QUERY)
@GetMapping("/vehicleinfo/search")
public R vehicleInfoSearch(VehicleInfoSearch search) {
PageInfo<VehicleInfoPageDTO> pageInfo = vehicleService.searchVehicleInfo(search);
return R.ok().putPageData(pageInfo);
}
@ApiOperation(value = "导出车辆信息列表")
@SysLog(module = "车辆管理", value = "导出车辆信息列表", action = OperateType.QUERY)
@GetMapping("/vehicleinfo/export")
public void exportVehicleInfo(VehicleInfoSearch search) throws Exception {
List<VehicleInfoReportExport> vehicleInfoList = vehicleService.exportVehicleInfo(search);
String fileName = "车辆信息列表_" + DateUtils.formatSerial(new Date());
String sheetName = "Sheet1";
EasyExcelUtils.writeExcel(response, vehicleInfoList, fileName, sheetName, VehicleInfoReportExport.class);
}
@ApiOperation(value = "导入车辆信息列表")
@PostMapping(value = "/vehicleinfo/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R importVehicleInfo(@RequestParam("file") MultipartFile file) throws IOException {
VehicleInfoImportListener listener = new VehicleInfoImportListener(vehicleService, deviceService);
EasyExcel.read(file.getInputStream(), VehicleInfoImport.class, listener)
.head(VehicleInfoImport.class)
.ignoreEmptyRow(false)
.sheet().doRead();
BaseImportInfo importInfo = listener.getBaseImportInfo();
return R.ok().data(importInfo);
}
@ApiOperation(value = "下载车辆信息导入模板")
@GetMapping(value = "/vehicleinfo/downloadtemplate")
public void downloadVehicleInfoTemplate() throws Exception {
InputStream inputStream = VehicleController.class.getResourceAsStream("/templates/importVehicleInfo.xlsx");
String fileName = "车辆信息导入模板";
FileIOUtil.download(inputStream, FileIOUtil.MimeType.EXCEL2007, fileName, response);
}
@ApiOperation(value = "验证试驾设备")
@SysLog(module = "车辆管理", value = "验证试驾设备", action = OperateType.QUERY)
@GetMapping("/vehicleinfo/verifydevice")
public R verifydevice(@RequestParam String sn) {
// 校验设备号是否存在
boolean snExist = deviceService.checkSnLocalAndRemote(sn);
if (!snExist) {
return R.error(1001, sn + "该设备不存在").data(false);
}
// 校验设备号是否已经绑定
boolean bindSn = deviceService.checkBindSn(sn);
if (!bindSn) {
return R.error(1001, sn + "该设备已经绑定").data(false);
}
return R.ok(sn + "设备验证通过").data(true);
}
@ApiOperation(value = "新增车辆信息")
@SysLog(module = "车辆管理", value = "新增试驾车辆", action = OperateType.ADD)
@PostMapping("/vehicleinfo/save")
public R saveVehicleInfo(@RequestBody @Validated(ValidateGroups.Insert.class) VehicleInfoVo vehicleInfoVo) {
// 校验设备号
List<String> noExistSnList = new ArrayList<>();
List<String> bindSnList = new ArrayList<>();
// 获取设备数据集合
List<DeviceInfoDto> deviceInfoDtos = vehicleInfoVo.getDeviceInfoDtos();
for (DeviceInfoDto deviceInfoDto : deviceInfoDtos) {
// 校验设备号是否存在
boolean snExist = deviceService.checkSnLocalAndRemote(deviceInfoDto.getSn());
if (!snExist) {
noExistSnList.add(deviceInfoDto.getSn());
}
// 校验设备号是否已经绑定
boolean bindSn = deviceService.checkBindSn(deviceInfoDto.getSn());
if (!bindSn) {
bindSnList.add(deviceInfoDto.getSn());
}
}
if (CollectionUtil.isNotEmpty(noExistSnList)) {
noExistSnList = noExistSnList.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
return R.error(StringUtils.join(noExistSnList, ",") + "设备不存在,请重新输入");
}
if (CollectionUtil.isNotEmpty(bindSnList)) {
bindSnList = bindSnList.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
return R.error(StringUtils.join(bindSnList, ",") + "设备已经绑定,请重新输入");
}
vehicleService.addVehicleInfo(vehicleInfoVo);
return R.ok();
}
@ApiOperation(value = "编辑车辆信息")
@SysLog(module = "车辆管理", value = "编辑车辆信息", action = OperateType.EDIT)
@PostMapping("/vehicleinfo/update")
public R updateVehicleInfo(@RequestBody @Validated(ValidateGroups.Update.class) VehicleInfoVo vehicleInfoVo) {
vehicleService.updateVehicleInfo(vehicleInfoVo);
return R.ok();
}
@ApiOperation(value = "根据id查询某条车辆信息(数据回显)")
@SysLog(value = "查询车辆信息", action = OperateType.QUERY)
@GetMapping("/vehicleinfo/findone")
public R findVehicleInfoById(@RequestParam Long id) {
VehicleInfoVo vehicleInfoVo = vehicleService.findVehicleInfoById(id);
return R.ok().data(vehicleInfoVo);
}
@ApiOperation(value = "删除车辆信息数据")
@GetMapping("/vehicleinfo/delete")
@SysLog(module = MODULE, value = "删除车辆信息数据", action = OperateType.DELETE)
public R deleteVehicleInfo(@RequestParam Long vehicleId, @RequestParam String sn) {
vehicleService.deleteVehicleInfo(vehicleId, sn);
return R.ok();
}
@ApiOperation(value = "根据sn获取设备型号")
@SysLog(module = "车辆管理", value = "根据sn获取设备型号", action = OperateType.QUERY)
@GetMapping("/vehicleinfo/getclassifynamebysn")
public R getDeviceClassifyNameBysn(@RequestParam String sn) {
String deviceClassifyName = deviceService.getDeviceClassifyNameBysn(sn);
return R.ok().data(deviceClassifyName);
}
/**
* 一键调频
*
* @return
*/
@ApiOperation(value = "一键调频")
@SysLog(module = "车辆管理", value = "一键调频", action = OperateType.QUERY)
@PostMapping(value = "/adjFreq")
public R adjFreq(@RequestBody DeviceWorkModel model) {
if (StringUtils.isNullOrEmpty(model.getSn())) {
return R.error("sn号为空");
}
vehicleService.adjFreq(model);
return R.ok("调频成功!");
}
/**
* 根据设备号获取调频操作详情
*
* @param sn 设备号
* @return
*/
@ApiOperation(value = "根据设备号获取调频操作详情")
@SysLog(module = "车辆管理", value = "根据设备号获取调频操作详情", action = OperateType.QUERY)
@GetMapping("/getadjfreqinfo")
public R getAdjFreqInfo(@RequestParam String sn) {
if (StringUtils.isNullOrEmpty(sn)) {
return R.error("设备号sn不能为空");
}
List<DeviceFreqModel> freqInfos = vehicleService.getAdjFreqInfo(sn);
return R.ok("获取调频详情成功!").data(freqInfos);
}
}