| | |
| | | package com.xiaopeng.maintenance.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.account.XpOperationsUserPositionDTO; |
| | | import com.xiaopeng.api.feignClient.account.XpOperationUserClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; |
| | | import com.xiaopeng.api.model.account.XpOperationsUser; |
| | | import com.xiaopeng.api.model.maintenance.XpErrorType; |
| | | import com.xiaopeng.api.model.maintenance.XpTask; |
| | | import com.xiaopeng.api.model.maintenance.XpTaskHandleDetailRoutine; |
| | | import com.xiaopeng.api.model.maintenance.XpTaskRule; |
| | | import com.xiaopeng.api.model.order.XpCruiseOrder; |
| | | 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.LoginOperationUser; |
| | | 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.web.page.PageInfo; |
| | |
| | | import com.xiaopeng.maintenance.schedule.InsuranceInspectionScheduleTask; |
| | | import com.xiaopeng.maintenance.service.IXpErrorTypeService; |
| | | import com.xiaopeng.maintenance.service.XpTaskService; |
| | | import com.xiaopeng.maintenance.vo.*; |
| | | import com.xiaopeng.maintenance.vo.TaskCleanDetailVO; |
| | | import com.xiaopeng.maintenance.vo.TaskDetectionDetailVO; |
| | | import com.xiaopeng.maintenance.vo.VehicleListVO; |
| | | 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.Distance; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | |
| | | 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 java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | @ApiOperation(value = "接收工单", tags = "运维APP-任务中心") |
| | | @PostMapping("/maintenance-app/api/v1/task/accept/{id}") |
| | | public R<?> accept(@PathVariable("id") String id) { |
| | | xpTaskService.accept(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "工单改派", tags = "运维APP-任务中心") |
| | | @PostMapping("/maintenance-app/api/v1/task/reassign") |
| | | public R<?> reassign(@RequestParam("taskId") Long taskId, @RequestParam("comment") String comment) { |
| | | xpTaskService.reassign(taskId, comment); |
| | | public R<?> reassign(@RequestBody TaskReassignVo vo) { |
| | | xpTaskService.reassign(vo.getTaskId(), vo.getComment()); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | return R.ok(xpTask); |
| | | } |
| | | |
| | | @ApiOperation(value = "待改派的工单分页列表", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/pageList") |
| | | public R<PageInfo<XpTaskVO>> reassignTaskPageList(@RequestBody TaskPageListQuery query) { |
| | | return R.ok(xpTaskService.reassignTaskPageList(query)); |
| | | } |
| | | |
| | | @ApiOperation(value = "待改派的工单导出", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/export") |
| | | 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(); |
| | | } |
| | | |
| | | @Resource |
| | | XpFleetClient xpFleetClient; |
| | | |
| | | @ApiOperation(value = "可改派的运维人员列表", tags = {"管理后台-运维执行-任务工单-待改派工单"}) |
| | | @PostMapping("/api/v1/task/reassign/availableUsers") |
| | | public R<PageInfo<XpOperationsUserWithRoleVO>> availableReassignUsers(@RequestBody OptionalUsersPageListQuery query) { |
| | | |
| | | 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> up = mongoTemplate.find(q, XpOperationsUserPositionDTO.class); |
| | | |
| | | Map<Long, Double> disMap = up.stream().collect(Collectors.toMap(XpOperationsUserPositionDTO::getId, XpOperationsUserPositionDTO::getDistance)); |
| | | // 查询车队下面面所有人员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(); |
| | | |
| | | // 设置距离,然后排序 |
| | | 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") |
| | | public R<XpTaskVO> reassignDetail(@RequestParam Long taskId) { |
| | | return R.ok(xpTaskService.detail(taskId)); |
| | | } |
| | | |
| | | @ApiOperation(value = "执行保险年检检测定时任务", tags = {"定时任务"}) |
| | | @GetMapping("/base/task/insurance/execute") |
| | |
| | | insuranceInspectionScheduleTask.executeInsuranceInspectionTask(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |