| | |
| | | package com.xiaopeng.maintenance.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.account.XpOperationsUserPositionDTO; |
| | |
| | | import com.xiaopeng.api.model.maintenance.XpErrorType; |
| | | import com.xiaopeng.api.model.maintenance.XpTask; |
| | | import com.xiaopeng.api.model.maintenance.XpTaskRule; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleetOperations; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | import com.xiaopeng.api.query.account.OptionalUsersPageListQuery; |
| | | import com.xiaopeng.api.vo.XpTaskVO; |
| | |
| | | import com.xiaopeng.api.vo.account.XpOperationsUserWithRoleVO; |
| | | import com.xiaopeng.api.vo.automaticPilot.VehiclePosition; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.SensitiveDataCryptoUtil; |
| | | 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.SaveRemoteDrivingAccidentDto; |
| | | import com.xiaopeng.maintenance.dto.SaveRoutineDetailDto; |
| | | import com.xiaopeng.maintenance.dto.SaveVehicleAccidentDto; |
| | | import com.xiaopeng.maintenance.job.AccidentTaskQuartzScheduler; |
| | |
| | | import com.xiaopeng.maintenance.vo.*; |
| | | import com.xiaopeng.maintenance.vo.TaskCleanDetailVO; |
| | | import com.xiaopeng.maintenance.vo.TaskDetectionDetailVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; |
| | | import org.apache.shardingsphere.transaction.core.TransactionType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.geo.Circle; |
| | | import org.springframework.data.geo.Distance; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | 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.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RestController |
| | | @Slf4j |
| | | @Api(tags = "任务管理") |
| | | public class XpTaskController { |
| | | @Resource |
| | | private XpTaskService xpTaskService; |
| | |
| | | |
| | | @Resource |
| | | private AccidentTaskQuartzScheduler accidentTaskQuartzScheduler; |
| | | |
| | | @Resource |
| | | private XpOperationUserClient operationUserClient; |
| | | |
| | | @Resource |
| | | XpFleetClient xpFleetClient; |
| | | |
| | | @ApiOperation(value = "事故类型列表", response = XpErrorType.class, tags = "运维APP-任务中心") |
| | | @GetMapping("/maintenance-app/api/v1/task/errorTypeList") |
| | |
| | | |
| | | VehicleListVO vehicleListVO = new VehicleListVO(); |
| | | vehicleListVO.setId(xpVehicle.getId()); |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class); |
| | | String vin = SensitiveDataCryptoUtil.decryptIfPossible(xpVehicle.getVehicleVin()); |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class); |
| | | if (vehiclePosition != null) { |
| | | double x = vehiclePosition.getPoint().getX(); |
| | | double y = vehiclePosition.getPoint().getY(); |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "车辆事故任务详情", tags = "运维APP-任务中心") |
| | | @GetMapping("/maintenance-app/api/v1/task/vehicleAccidentDetail") |
| | |
| | | */ |
| | | @ApiOperation(value = "删除删除任务/事故", tags = {"管理后台-车辆管理-运营车辆管理"}) |
| | | @DeleteMapping("/api/v1/task/delete/{id}") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.DELETE, |
| | | contentExpression = "'删除任务/事故,id=' + #p0", |
| | | appendRequestData = false |
| | | ) |
| | | public R<?> deleteTaskById(@ApiParam(name = "id", value = "任务ID") @PathVariable Long id) { |
| | | xpTaskService.deleteTaskById(id); |
| | | return R.ok(); |
| | |
| | | if (Objects.isNull(jsonObject)) { |
| | | continue; |
| | | } |
| | | String downloadUrl = jsonObject.getString("url");; |
| | | String downloadUrl = jsonObject.getString("url"); |
| | | ; |
| | | try { |
| | | downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); |
| | | } catch (UnsupportedEncodingException e) { |
| | |
| | | return R.ok(xpTaskService.reassignTaskPageList(query)); |
| | | } |
| | | |
| | | @Resource |
| | | XpFleetClient xpFleetClient; |
| | | @ApiOperation(value = "待改派的工单导出", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/export") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.EXPORT, |
| | | content = "导出待改派工单", |
| | | appendRequestData = true |
| | | ) |
| | | public R<?> export(@RequestBody TaskPageListQuery query, HttpServletResponse response) { |
| | | List<XpTaskVO> list = xpTaskService.exportList(query); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpCruiseCheckInRecordVO.class, list); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("巡游打卡记录.xls", "utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | outputStream.flush(); |
| | | } catch (IOException e) { |
| | | log.error("导出巡游打卡记录失败", e); |
| | | } finally { |
| | | try { |
| | | if (outputStream != null) { |
| | | outputStream.close(); |
| | | } |
| | | if (workbook != null) { |
| | | workbook.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("关闭输出流失败", e); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "可改派的运维人员列表", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/availableUsers") |
| | | public R<PageInfo<XpOperationsUserWithRoleVO>> availableReassignUsers(@RequestBody OptionalUsersPageListQuery query) { |
| | | public R<PageInfo<XpOperationsUserWithRoleVO>> availableReassignUsers(@RequestBody OptionalUsersPageListQuery query1) { |
| | | XpTask task = xpTaskService.getById(query1.getTaskId()); |
| | | // 找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(task.getVehicleLon().doubleValue(), task.getVehicleLat().doubleValue()); |
| | | // 构造半径 |
| | | Distance distanceR = new Distance(10, Metrics.KILOMETERS); |
| | | // 画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | Query query = Query.query(new Criteria().andOperator( |
| | | Criteria.where("location").withinSphere(circle) |
| | | )); |
| | | // 增加时间查询条件:最近1分钟更新的数据 |
| | | int time = 10*60*1000; |
| | | Long oneMinuteAgo = System.currentTimeMillis() - time; |
| | | query.addCriteria(Criteria.where("updateTime").gte(oneMinuteAgo)); |
| | | |
| | | XpTask task = xpTaskService.getById(query.getTaskId()); |
| | | GeoJsonPoint point = |
| | | new GeoJsonPoint( |
| | | task.getVehicleLon().doubleValue(), |
| | | task.getVehicleLat().doubleValue() |
| | | ); |
| | | Query q = new Query(Criteria.where("location").near(point) |
| | | .maxDistance(new Distance(10, Metrics.KILOMETERS).getNormalizedValue())); |
| | | q.with(Sort.by(Sort.Direction.ASC, "dis")); |
| | | List<XpOperationsUserPositionDTO> vehiclePositions = mongoTemplate.find(query, XpOperationsUserPositionDTO.class); |
| | | if(CollUtil.isEmpty(vehiclePositions)){ |
| | | throw new ServiceException("未查询到运维人员"); |
| | | } |
| | | List<Long> data = null ; |
| | | if(StrUtil.isNotBlank(query1.getFleet())){ |
| | | // 查询车队下面面所有人员id和up求交集 |
| | | data = xpFleetClient.idsByFleetName(query1.getFleet()).getData(); |
| | | } |
| | | //vehiclePositions根据距离升序排序 |
| | | vehiclePositions.sort(Comparator.comparing(XpOperationsUserPositionDTO::getDistance)); |
| | | //获取运维人员id |
| | | List<Long> ids = new ArrayList<>(); |
| | | Map<Long, Double> disMap = new HashMap<>(); |
| | | if ( CollUtil.isNotEmpty(data) ) { |
| | | for (XpOperationsUserPositionDTO vehiclePosition : vehiclePositions) { |
| | | if(data.contains(vehiclePosition.getId())){ |
| | | ids.add(vehiclePosition.getId()); |
| | | disMap.put(vehiclePosition.getId(), vehiclePosition.getDistance()); |
| | | } |
| | | } |
| | | }else{ |
| | | for (XpOperationsUserPositionDTO vehiclePosition : vehiclePositions) { |
| | | ids.add(vehiclePosition.getId()); |
| | | disMap.put(vehiclePosition.getId(), vehiclePosition.getDistance()); |
| | | } |
| | | } |
| | | query1.setIds(ids); |
| | | query1.setOrderByField(1); |
| | | PageInfo<XpOperationsUserWithRoleVO> ret = operationUserClient.listByQueryIds(query1).getData(); |
| | | |
| | | List<XpOperationsUserPositionDTO> up = mongoTemplate.find(q, XpOperationsUserPositionDTO.class); |
| | | // 设置距离,然后排序 |
| | | if (ret == null || ret.getRecords() == null || ret.getRecords().isEmpty()) { |
| | | return R.ok(); |
| | | } |
| | | if(CollUtil.isNotEmpty(ids)){ |
| | | R<List<XpFleetOperations>> findListByUserIdsR = xpFleetOperationsClient.findListByUserIds(ids); |
| | | if(findListByUserIdsR.getCode() != R.SUCCESS || findListByUserIdsR.getData().isEmpty()){ |
| | | throw new ServiceException("未查询该车队"); |
| | | } |
| | | // 将查询结果转换为 Map,key 为 userId,value 为 XpFleetOperations 对象 |
| | | Map<Long, XpFleetOperations> fleetOperationsMap = findListByUserIdsR.getData().stream() |
| | | .collect(Collectors.toMap(XpFleetOperations::getOperationsUserId, Function.identity())); |
| | | |
| | | // 查询车队下面面所有人员id和up求交集 |
| | | List<Long> data = xpFleetClient.idsByFleetName(query.getFleet()).getData(); |
| | | |
| | | List<Long> ids = up.stream().map(XpOperationsUserPositionDTO::getId) |
| | | .filter(e -> data!=null && !data.isEmpty() &&!data.contains(e)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | query.setIds(ids); |
| | | PageInfo<XpOperationsUserWithRoleVO> ret = operationUserClient.listByQueryIds(query).getData(); |
| | | |
| | | for (XpOperationsUserWithRoleVO record : ret.getRecords()) { |
| | | if(fleetOperationsMap.containsKey(record.getId())){ |
| | | record.setFleetName(fleetOperationsMap.get(record.getId()).getFleetName()); |
| | | } |
| | | } |
| | | } |
| | | ret.getRecords().forEach(e -> e.setDis(disMap.get(e.getId()))); |
| | | // List<XpOperationsUserWithRoleVO> sorted = ret.getRecords().stream().sorted(Comparator.comparing(XpOperationsUserWithRoleVO::getDis)).collect(Collectors.toList()); |
| | | // ret.setRecords(sorted); |
| | | return R.ok(ret); |
| | | } |
| | | |
| | | @Resource |
| | | private XpOperationUserClient operationUserClient; |
| | | |
| | | @ApiOperation(value = "改派详情", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @GetMapping("/api/v1/task/detail") |
| | |
| | | insuranceInspectionScheduleTask.executeInsuranceInspectionTask(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "创建远程代驾事故任务", tags = "远程代驾") |
| | | @PostMapping("/logan/assistance/v1/task/saveRemoteDrivingAccident") |
| | | public R<?> saveRemoteDrivingAccident(@RequestBody SaveRemoteDrivingAccidentDto dto) { |
| | | XpTask task = xpTaskService.saveRemoteDrivingAccident(dto); |
| | | try { |
| | | XpTaskRule taskRule = xpTaskRuleMapper.selectOne(null); |
| | | Integer processingTimeLimit = taskRule == null ? null : taskRule.getProcessingTimeLimit(); |
| | | accidentTaskQuartzScheduler.scheduleAccidentTimeoutJobs(task.getId(), task.getEndTime(), processingTimeLimit); |
| | | } catch (Exception e) { |
| | | log.error("远程代驾事故任务Quartz调度失败,taskId={}", task == null ? null : task.getId(), e); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "事故类型列表", response = XpErrorType.class, tags = "远程代驾") |
| | | @GetMapping("/logan/assistance/v1/taskManagement/errorTypeList") |
| | | public R<List<XpErrorType>> getErrorTypeList() { |
| | | return xpErrorTypeService.errorTypeList(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "运营后台改派工单", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/taskReassignment") |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.TASK_ORDER_MANAGEMENT, |
| | | operationType = AdminOperationType.EDIT, |
| | | contentExpression = "'运营后台改派工单,taskId=' + #p0.taskId + ',newOperationsUserId=' + #p0.newOperationsUserId", |
| | | appendRequestData = false |
| | | ) |
| | | public R<?> taskReassignment(@RequestBody TaskReassignmentVo vo){ |
| | | xpTaskService.taskReassignment(vo); |
| | | return R.ok(); |
| | | } |
| | | } |