| | |
| | | package com.xiaopeng.maintenance.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.feignClient.account.XpOperationUserClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; |
| | | import com.xiaopeng.api.model.account.SysUser; |
| | | import com.xiaopeng.api.model.account.XpOperationsUser; |
| | | import com.xiaopeng.api.model.maintenance.XpErrorType; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.api.model.operation.XpWhitelistOperlog; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | import com.xiaopeng.api.vo.account.LoginOperationUser; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.utils.ip.IpUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | import com.xiaopeng.common.security.service.TokenService; |
| | | import com.xiaopeng.evi.oss.service.AliOssService; |
| | | import com.xiaopeng.maintenance.dto.HandleVehicleAccidentDto; |
| | | import com.xiaopeng.maintenance.dto.SaveErrorTaskDto; |
| | | import com.xiaopeng.maintenance.dto.SaveRoutineDetailDto; |
| | | import com.xiaopeng.maintenance.dto.SaveVehicleAccidentDto; |
| | | import com.xiaopeng.maintenance.exportExcel.XpTaskExportExcel; |
| | | import com.xiaopeng.maintenance.model.query.TaskManagementPageListQuery; |
| | | import com.xiaopeng.maintenance.model.query.TaskPageListQuery; |
| | | import com.xiaopeng.maintenance.model.query.XpTaskRecordPageQuery; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | |
| | | /** |
| | | * <p> |
| | | * 运维APP 任务中心 |
| | | * 管理后台 任务工单 |
| | | * </p> |
| | | * |
| | | * @author mitao |
| | |
| | | @Resource |
| | | private IXpErrorTypeService xpErrorTypeService; |
| | | @Resource |
| | | private XpFleetOperationsClient xpFleetOperationsClient; |
| | | private XpOperationUserClient operationUserClient; |
| | | @Resource |
| | | private AliOssService aliOssService; |
| | | @Resource |
| | | private XpVehicleClient xpVehicleClient; |
| | | |
| | | @ApiOperation(value = "事故类型列表", response = XpErrorType.class) |
| | | @GetMapping("/errorTypeList") |
| | | public R<List<XpErrorType>> errorTypeList() { |
| | | return xpErrorTypeService.errorTypeList(); |
| | | } |
| | | @ApiOperation(value = "任务中心列表", response = TaskPageListVO.class) |
| | | |
| | | @ApiOperation(value = "任务中心列表", response = TaskManagementPageListVO.class) |
| | | @PostMapping("/pageList") |
| | | public R<PageInfo<TaskManagementPageListVO>> pageListManagement(@RequestBody TaskManagementPageListQuery query) { |
| | | PageInfo<TaskManagementPageListVO> pageList = xpTaskService.pageListManagement(query); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | @ApiOperation(value = "任务工单导出") |
| | | @PostMapping(value = "/exportExcel") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.EXPORT, |
| | | content = "导出任务工单", |
| | | appendRequestData = true |
| | | ) |
| | | public void exportExcel(@RequestBody TaskManagementPageListQuery query) { |
| | | List<TaskManagementPageListVO> exportList = xpTaskService.exportList(query); |
| | | List<XpTaskExportExcel> taskExportExcels = new ArrayList<>(); |
| | | Integer num = 1; |
| | | for (TaskManagementPageListVO task : exportList) { |
| | | XpTaskExportExcel xpTaskExportExcel = new XpTaskExportExcel(); |
| | | xpTaskExportExcel.setPlateNumber(task.getPlateNumber()); |
| | | xpTaskExportExcel.setTaskCategory(task.getTaskCategory()); |
| | | xpTaskExportExcel.setTaskTypeName(task.getTaskTypeName()); |
| | | xpTaskExportExcel.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); |
| | | xpTaskExportExcel.setTaskDescription(task.getTaskDescription()); |
| | | if (StringUtils.hasLength(task.getHandleUserId())) { |
| | | String[] split = task.getHandleUserId().split(","); |
| | | |
| | | List<XpOperationsUser> users = operationUserClient.listByIds(Arrays.stream(split).map(Long::parseLong).collect(Collectors.toList())).getData(); |
| | | if (users != null) { |
| | | StringBuilder handleUserName = new StringBuilder(); |
| | | for (XpOperationsUser user : users) { |
| | | handleUserName.append(user.getNickName()).append(";"); |
| | | } |
| | | xpTaskExportExcel.setHandleUserName(handleUserName.toString()); |
| | | } |
| | | } |
| | | xpTaskExportExcel.setNumber(num); |
| | | xpTaskExportExcel.setStatus(task.getStatus()); |
| | | LocalDateTime createTime = task.getCreateTime(); |
| | | // 将LocalDateTime转化为yyyy-MM-dd HH:mm:ss格式字符串 |
| | | xpTaskExportExcel.setCreateTime(createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | taskExportExcels.add(xpTaskExportExcel); |
| | | num++; |
| | | } |
| | | //1.获取excel模板 |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpTaskExportExcel.class, taskExportExcels); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("任务工单列表.xls", "utf-8"); |
| | | response.setHeader("Content-dispodition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 管理后台-车辆管理-运营车辆管理-删除任务/事故 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "删除任务/事故") |
| | | @DeleteMapping("/deleteTaskById") |
| | | public R<?> deleteTaskById(@ApiParam(name = "id", value = "任务ID")Long id){ |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.DELETE, |
| | | contentExpression = "'删除任务/事故,id=' + #p0", |
| | | appendRequestData = false |
| | | ) |
| | | public R<?> deleteTaskById(@ApiParam(name = "id", value = "任务ID") Long id) { |
| | | xpTaskService.deleteTaskById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "任务分配") |
| | | @GetMapping("/assigneeTask") |
| | | public R assigneeTask(@ApiParam(name = "id", value = "任务ID") Long id, @ApiParam(name = "handlerUserId", value = "处理人id")Long handlerUserId) { |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.EDIT, |
| | | contentExpression = "'任务分配,id=' + #p0 + ',handlerUserId=' + #p1", |
| | | appendRequestData = false |
| | | ) |
| | | public R assigneeTask(@ApiParam(name = "id", value = "任务ID") Long id, @ApiParam(name = "handlerUserId", value = "处理人id") Long handlerUserId) { |
| | | Long assigneeUserId = tokenService.getLoginUser().getSysUser().getId(); |
| | | return xpTaskService.assigneeTask(id, handlerUserId,assigneeUserId); |
| | | return xpTaskService.assigneeTask(id, handlerUserId, assigneeUserId); |
| | | } |
| | | |
| | | @ApiOperation(value = "创建任务事故") |
| | | @PostMapping("/saveTask") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.ADD, |
| | | contentExpression = "'创建任务事故,vehicleIds=' + #p0.vehicleIds + ',taskTypeId=' + #p0.taskTypeId", |
| | | appendRequestData = false |
| | | ) |
| | | public R saveTask(@RequestBody SaveErrorTaskDto dto) { |
| | | Long reportUserId = tokenService.getLoginUser().getSysUser().getId(); |
| | | xpTaskService.saveTask(dto, reportUserId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "任务详情") |
| | | @GetMapping("/taskDetail") |
| | | public R<TaskManagementDetailVO> taskDetail(Long id) { |
| | | public R<TaskManagementDetailVO> taskDetail(Long id) throws UnsupportedEncodingException { |
| | | return xpTaskService.taskDetail(id); |
| | | } |
| | | |
| | | @ApiOperation(value = "查询车辆不分页列表") |
| | | @PostMapping(" /listVehicle") |
| | | public R<List<VehicleListVO>> listVehicle() { |
| | | // xpVehicleClient.listByIds() |
| | | return R.ok(new ArrayList<>()); |
| | | } |
| | | @ApiOperation(value = "上传车辆事故", tags = "运维APP-任务中心") |
| | | @PostMapping(" /saveVehicleAccident") |
| | | public R saveVehicleAccident(@RequestBody SaveVehicleAccidentDto dto) { |
| | | LoginOperationUser loginOperationUser = tokenService.getLoginOperationUser(); |
| | | XpOperationsUser xpOperationsUser = loginOperationUser.getXpOperationsUser(); |
| | | xpTaskService.saveVehicleAccident(dto, xpOperationsUser); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "车辆其他常规任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /vehicleRoutineDetail") |
| | | public R<TaskRoutineDetailVO> vehicleRoutineDetail(Long id) { |
| | | return xpTaskService.vehicleRoutineDetail(id); |
| | | } |
| | | @ApiOperation(value = "上传车辆其他常规任务详情", tags = "运维APP-任务中心") |
| | | @PostMapping(" /saveRoutineDetail") |
| | | public R saveRoutineDetail(@RequestBody SaveRoutineDetailDto dto) { |
| | | LoginOperationUser loginOperationUser = tokenService.getLoginOperationUser(); |
| | | Long id = loginOperationUser.getId(); |
| | | return xpTaskService.saveRoutineDetail(dto, id); |
| | | } |
| | | @ApiOperation(value = "车辆常规充电任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /chargingDetail") |
| | | public R<TaskChargingDetailVO> chargingDetail(Long id) { |
| | | return xpTaskService.chargingDetail(id); |
| | | } |
| | | |
| | | @ApiOperation(value = "车辆常规维修任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /repairDetail") |
| | | public R<com.xiaopeng.maintenance.vo.TaskRepairDetailVO> repairDetail(Long id) { |
| | | return xpTaskService.repairDetail(id); |
| | | } |
| | | @ApiOperation(value = "车辆常规整备任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /preparationDetail") |
| | | public R<com.xiaopeng.maintenance.vo.TaskPreparationDetailVO> preparationDetail(Long id) { |
| | | return xpTaskService.preparationDetail(id); |
| | | } |
| | | @ApiOperation(value = "车辆常规检测任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /detectionDetail") |
| | | public R<com.xiaopeng.maintenance.vo.TaskDetectionDetailVO> detectionDetail(Long id) { |
| | | return xpTaskService.detectionDetail(id); |
| | | } |
| | | @ApiOperation(value = "车辆常规洗车任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping(" /cleanDetail") |
| | | public R<com.xiaopeng.maintenance.vo.TaskCleanDetailVO> cleanDetail(Long id) { |
| | | return xpTaskService.cleanDetail(id); |
| | | } |
| | | @ApiOperation(value = "处理车辆事故", tags = "运维APP-任务中心") |
| | | @PostMapping(" /handleVehicleAccident") |
| | | @Transactional |
| | | public R handleVehicleAccident(@RequestBody HandleVehicleAccidentDto dto) { |
| | | LoginOperationUser loginOperationUser = tokenService.getLoginOperationUser(); |
| | | XpOperationsUser xpOperationsUser = loginOperationUser.getXpOperationsUser(); |
| | | return xpTaskService.handleVehicleAccident(dto,xpOperationsUser); |
| | | @PostMapping("/listVehicle") |
| | | public R<List<XpVehicle>> listVehicle() throws UnsupportedEncodingException { |
| | | List<XpVehicle> vehicles = xpVehicleClient.listVehicle().getData(); |
| | | if (vehicles == null) { |
| | | return R.ok(new ArrayList<>()); |
| | | } |
| | | for (XpVehicle vehicle : vehicles) { |
| | | String vehiclePictures = vehicle.getVehiclePictures(); |
| | | if (org.apache.commons.lang3.StringUtils.isNotBlank(vehiclePictures)) { |
| | | JSONObject jsonObject = JSONObject.parseObject(vehiclePictures); |
| | | //1 |
| | | String downloadUrl = jsonObject.getString("url");; |
| | | try { |
| | | downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.error("获取图片下载地址失败", e); |
| | | } |
| | | jsonObject.put("url", downloadUrl); |
| | | vehicle.setVehiclePictures(jsonObject.toJSONString()); |
| | | } |
| | | } |
| | | return R.ok(vehicles); |
| | | } |
| | | |
| | | /** |
| | | * 通过车辆id查询任务事故分页列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "通过车辆id查询任务事故分页列表", tags = {"管理后台-车辆管理-运营车辆管理"}) |
| | |
| | | |
| | | |
| | | @ApiOperation(value = "事故类型列表", response = XpErrorType.class, tags = "管理后台-车辆管理-运营车辆管理") |
| | | @GetMapping(" /errorTypeTreeList") |
| | | @GetMapping("/errorTypeTreeList") |
| | | public R<List<XpErrorType>> errorTypeTreeList() { |
| | | return xpErrorTypeService.errorTypeList(); |
| | | } |