| | |
| | | package com.ruoyi.web.controller.task; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.service.ILegacySystemSyncService; |
| | | import com.ruoyi.system.service.ITaskDispatchSyncService; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | @Qualifier("tiandituMapService") |
| | | private IMapService mapService; |
| | | |
| | | @Autowired |
| | | private ILegacySystemSyncService legacySystemSyncService; |
| | | |
| | | @Autowired |
| | | private ITaskDispatchSyncService taskDispatchSyncService; |
| | | |
| | | /** |
| | | * 查询任务管理列表(后台管理端) |
| | |
| | | @Log(title = "任务管理", businessType = BusinessType.INSERT) |
| | | @PostMapping("/admin") |
| | | public AjaxResult adminAdd(@RequestBody TaskCreateVO createVO) { |
| | | return toAjax(sysTaskService.insertSysTask(createVO)); |
| | | Long taskId = sysTaskService.insertSysTask(createVO); |
| | | return taskId > 0 ? AjaxResult.success("新增成功").put("taskId", taskId) : AjaxResult.error("新增失败"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 新增任务(APP端) |
| | |
| | | @Log(title = "任务创建", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult appAdd(@RequestBody TaskCreateVO createVO) { |
| | | return toAjax(sysTaskService.insertSysTask(createVO)); |
| | | Long taskId = sysTaskService.insertSysTask(createVO); |
| | | return taskId > 0 ? AjaxResult.success("新增成功").put("taskId", taskId) : AjaxResult.error("新增失败"); |
| | | } |
| | | |
| | | /** |
| | | * 检查任务是否重复(根据联系人电话和创建日期) |
| | | * @param phone 联系人电话 |
| | | * @param createDate 任务创建日期(格式:YYYY-MM-DD) |
| | | * @return 是否存在重复任务 |
| | | */ |
| | | @GetMapping("/checkDuplicate") |
| | | public AjaxResult checkDuplicate( |
| | | @RequestParam("phone") String phone, |
| | | @RequestParam("createDate") String createDate) { |
| | | |
| | | if (StringUtils.isEmpty(phone) || StringUtils.isEmpty(createDate)) { |
| | | return AjaxResult.error("参数不能为空"); |
| | | } |
| | | |
| | | boolean isDuplicate = sysTaskService.checkTaskDuplicate(phone, createDate); |
| | | |
| | | if (isDuplicate) { |
| | | return AjaxResult.error("该联系电话在该日期已有任务,不能重复提交"); |
| | | } |
| | | |
| | | return AjaxResult.success("未发现重复任务"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return error("无效的任务状态"); |
| | | } |
| | | |
| | | // 如果是取消状态,保存取消原因 |
| | | if (newStatus == TaskStatus.CANCELLED && StringUtils.isNotEmpty(request.getCancelReason())) { |
| | | sysTaskService.saveCancelInfo(taskId, request.getCancelReason()); |
| | | } |
| | | |
| | | // 如果是强制完成,更新实际开始时间和结束时间 |
| | | if (newStatus == TaskStatus.COMPLETED && request.getActualStartTime() != null && request.getActualEndTime() != null) { |
| | | SysTask task = new SysTask(); |
| | | task.setTaskId(taskId); |
| | | task.setTaskStatus(newStatus.getCode()); |
| | | //将String转成Date |
| | | |
| | | task.setActualStartTime(DateUtils.parseDate(request.getActualStartTime())); |
| | | task.setActualEndTime(DateUtils.parseDate(request.getActualEndTime())); |
| | | task.setRemark(request.getRemark()); |
| | | task.setUpdateBy(SecurityUtils.getUsername()); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | int result = sysTaskService.forceCompleteTask(task); |
| | | return toAjax(result); |
| | | } |
| | | |
| | | // 如果包含GPS位置信息,使用带位置的方法 |
| | | if (request.getLatitude() != null && request.getLongitude() != null) { |
| | | String address= mapService.reverseGeocoding(request.getLongitude(), request.getLatitude()); |
| | | request.setLocationAddress(address); |
| | | SysTaskLog locationLog = new SysTaskLog(); |
| | | locationLog.setLatitude(request.getLatitude()); |
| | | locationLog.setLongitude(request.getLongitude()); |
| | | locationLog.setLocationAddress(request.getLocationAddress()); |
| | | locationLog.setLocationProvince(request.getLocationProvince()); |
| | | locationLog.setLocationCity(request.getLocationCity()); |
| | | locationLog.setLocationDistrict(request.getLocationDistrict()); |
| | | locationLog.setGpsAccuracy(request.getGpsAccuracy()); |
| | | locationLog.setAltitude(request.getAltitude()); |
| | | locationLog.setSpeed(request.getSpeed()); |
| | | locationLog.setHeading(request.getHeading()); |
| | | SysTaskLog locationLog = getLocationLog(request); |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatusWithLocation(taskId, newStatus, request.getRemark(), locationLog)); |
| | | } |
| | | |
| | | return toAjax(sysTaskService.changeTaskStatus(taskId, newStatus, request.getRemark())); |
| | | } |
| | | |
| | | private static SysTaskLog getLocationLog(ChangeStatusRequest request) { |
| | | SysTaskLog locationLog = new SysTaskLog(); |
| | | locationLog.setLatitude(request.getLatitude()); |
| | | locationLog.setLongitude(request.getLongitude()); |
| | | locationLog.setLocationAddress(request.getLocationAddress()); |
| | | locationLog.setLocationProvince(request.getLocationProvince()); |
| | | locationLog.setLocationCity(request.getLocationCity()); |
| | | locationLog.setLocationDistrict(request.getLocationDistrict()); |
| | | locationLog.setGpsAccuracy(request.getGpsAccuracy()); |
| | | locationLog.setAltitude(request.getAltitude()); |
| | | locationLog.setSpeed(request.getSpeed()); |
| | | locationLog.setHeading(request.getHeading()); |
| | | return locationLog; |
| | | } |
| | | |
| | | /** |
| | |
| | | private Double altitude; |
| | | private Double speed; |
| | | private Double heading; |
| | | |
| | | // 取消相关字段 |
| | | private String cancelReason; // 取消原因(关联数据字典task_cancel_reason) |
| | | |
| | | // 强制完成相关字段 |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm") |
| | | private String actualStartTime; // 实际开始时间 |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm") |
| | | private String actualEndTime; // 实际结束时间 |
| | | |
| | | public String getTaskStatus() { |
| | | return taskStatus; |
| | |
| | | public void setHeading(Double heading) { |
| | | this.heading = heading; |
| | | } |
| | | |
| | | public String getCancelReason() { |
| | | return cancelReason; |
| | | } |
| | | |
| | | public void setCancelReason(String cancelReason) { |
| | | this.cancelReason = cancelReason; |
| | | } |
| | | |
| | | public String getActualStartTime() { |
| | | return actualStartTime; |
| | | } |
| | | |
| | | public void setActualStartTime(String actualStartTime) { |
| | | this.actualStartTime = actualStartTime; |
| | | } |
| | | |
| | | public String getActualEndTime() { |
| | | return actualEndTime; |
| | | } |
| | | |
| | | public void setActualEndTime(String actualEndTime) { |
| | | this.actualEndTime = actualEndTime; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 手动同步服务单到旧系统 |
| | | * 当服务单同步失败或未同步时,可以通过此接口手动触发同步 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:edit')") |
| | | @Log(title = "手动同步服务单", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/syncServiceOrder/{taskId}") |
| | | public AjaxResult syncServiceOrder(@PathVariable Long taskId) { |
| | | try { |
| | | // 查询任务信息 |
| | | SysTask task = sysTaskService.selectSysTaskByTaskId(taskId); |
| | | if (task == null) { |
| | | return error("任务不存在"); |
| | | } |
| | | |
| | | // 只支持急救转运任务 |
| | | if (!"EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | return error("只有急救转运任务才能同步到旧系统"); |
| | | } |
| | | |
| | | // 调用同步服务 |
| | | Long serviceOrdId = legacySystemSyncService.syncEmergencyTaskToLegacy(taskId); |
| | | |
| | | if (serviceOrdId != null && serviceOrdId > 0) { |
| | | return success("服务单同步成功,ServiceOrdID: " + serviceOrdId); |
| | | } else { |
| | | return error("服务单同步失败,请查看同步错误信息"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("手动同步服务单异常,taskId: {}", taskId, e); |
| | | return error("同步异常: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 手动同步调度单到旧系统 |
| | | * 当调度单同步失败或未同步时,可以通过此接口手动触发同步 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('task:general:edit')") |
| | | @Log(title = "手动同步调度单", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/syncDispatchOrder/{taskId}") |
| | | public AjaxResult syncDispatchOrder(@PathVariable Long taskId) { |
| | | try { |
| | | // 查询任务信息 |
| | | SysTask task = sysTaskService.selectSysTaskByTaskId(taskId); |
| | | if (task == null) { |
| | | return error("任务不存在"); |
| | | } |
| | | |
| | | // 只支持急救转运任务 |
| | | if (!"EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | return error("只有急救转运任务才能同步到旧系统"); |
| | | } |
| | | |
| | | // 查询急救转运扩展信息 |
| | | SysTaskEmergency emergency = sysTaskEmergencyService.selectSysTaskEmergencyByTaskId(taskId); |
| | | if (emergency == null) { |
| | | return error("急救转运扩展信息不存在"); |
| | | } |
| | | |
| | | // 必须先有服务单 |
| | | if (emergency.getLegacyServiceOrdId() == null || emergency.getLegacyServiceOrdId() <= 0) { |
| | | return error("请先同步服务单"); |
| | | } |
| | | |
| | | // 调用同步服务 |
| | | Long dispatchOrdId = taskDispatchSyncService.syncDispatch(taskId); |
| | | |
| | | if (dispatchOrdId != null && dispatchOrdId > 0) { |
| | | return success("调度单同步成功,DispatchOrdID: " + dispatchOrdId); |
| | | } else { |
| | | return error("调度单同步失败,请查看同步错误信息"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("手动同步调度单异常,taskId: {}", taskId, e); |
| | | return error("同步异常: " + e.getMessage()); |
| | | } |
| | | } |
| | | } |