VehicleController.java
9.95 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
package cn.com.glsx.admin.modules.controller;
import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.modules.model.*;
import cn.com.glsx.admin.modules.model.export.TrialDriveVehicleExport;
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.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 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.Date;
import java.util.List;
/**
* @Desc:车辆管理
* @Author huangxc
* @Date 2021/5/19
*/
@Slf4j
@RestController
@RequestMapping(value = "/vehicle")
@Api(value = "车辆管理", tags = {"车辆管理"})
public class VehicleController {
@Autowired
private VehicleService vehicleService;
@Autowired
private DeviceService deviceService;
@Autowired
private HttpServletResponse response;
@ApiOperation(value = "试驾车辆列表查询")
@GetMapping("/drivevehicle/search")
public R search(VehicleManageSearch search) {
PageInfo<TrialDriveVehiclePageDTO> pageInfo = vehicleService.searchTrialDrive(search);
return R.ok().putPageData(pageInfo);
}
@ApiOperation(value = "新增试驾车辆")
@SysLog(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查询某条试驾车辆数据(数据回显)")
@GetMapping("/drivevehicle/findbyid")
public R findDriveVehicleById(@RequestParam(required = true) String tempId) {
TrialDriveVehicleEditDTO vehicleEditDTO = vehicleService.findDriveVehicleById(tempId);
return R.ok().data(vehicleEditDTO);
}
@ApiOperation(value = "编辑试驾车辆")
@SysLog(value = "编辑试驾车辆", action = OperateType.EDIT)
@PostMapping("/drivevehicle/update")
public R updateDriveVehicle(@RequestBody @Validated(ValidateGroups.Update.class) TrialDriveVehicleEditBo driveVehicleoBo) {
vehicleService.updateDriveVehicleById(driveVehicleoBo);
return R.ok();
}
@ApiOperation(value = "设备和车辆解绑")
@GetMapping("/unbindSn")
public R unbindDriveVehicle(@RequestParam(required = true) String tempId) {
vehicleService.unbindDriveVehicle(tempId);
return R.ok();
}
@ApiOperation(value = "删除试驾车辆数据")
@GetMapping("/drivevehicle/delete")
@SysLog(value = "删除试驾车辆数据", action = OperateType.DELETE)
public R deleteDriveVehicle(@RequestParam(required = true) String tempId) {
if (StringUtils.isBlank(tempId)) {
return R.error("未选择数据");
}
vehicleService.deleteDriveVehicleAndUnBind(tempId);
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);
}
@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(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);
}
@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 Long brandId) {
List<Carbrand> carBrandList = vehicleService.getSubBrandsByBrandId(brandId);
return R.ok().data(carBrandList);
}
@ApiOperation(value = "车辆系别查询")
@GetMapping("/series")
public R<List<Carseries>> series(@RequestParam Long brandId) {
List<Carseries> carSeriesList = vehicleService.getSeriesByBrandId(brandId);
return R.ok().data(carSeriesList);
}
@ApiOperation(value = "车辆类型查询")
@GetMapping("/types")
public R<List<Cartype>> types(@RequestParam Long seriesId) {
List<Cartype> carTypeList = vehicleService.getTypesBySeriesId(seriesId);
return R.ok().data(carTypeList);
}
@SysLog(value = "保存车型库", action = OperateType.ADD)
@ApiOperation(value = "保存车型库")
@PostMapping("/savetypes")
public R<List<Cartype>> saveVehicleTypes(@RequestBody VehicleTypesBO typesBO) {
vehicleService.saveVehicleTypes(typesBO);
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);
}
}