| | |
| | | import com.ruoyi.system.domain.SysTaskVehicle; |
| | | import com.ruoyi.system.domain.SysTaskAttachment; |
| | | import com.ruoyi.system.domain.SysTaskLog; |
| | | import com.ruoyi.system.domain.SysTaskStatusHistory; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.domain.SysTaskWelfare; |
| | | import com.ruoyi.system.domain.SysTaskAssignee; |
| | |
| | | |
| | | @Autowired |
| | | private SysTaskLogMapper sysTaskLogMapper; |
| | | |
| | | @Autowired |
| | | private SysTaskStatusHistoryMapper sysTaskStatusHistoryMapper; |
| | | |
| | | @Autowired |
| | | private SysTaskEmergencyMapper sysTaskEmergencyMapper; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据任务编号、调度单编号或服务单编号查询任务列表 |
| | | *根据任务编号、调度单编号或服务单编号查询任务列表(SQL算法下推优化版本) |
| | | * |
| | | * @param queryVO 任务查询对象 |
| | | * @param taskCode 任务编号 |
| | |
| | | */ |
| | | @Override |
| | | public List<SysTask> selectSysTaskListByMultiCode(TaskQueryVO queryVO, String taskCode) { |
| | | // Create a new query object without the taskCode filter |
| | | TaskQueryVO newQuery = new TaskQueryVO(); |
| | | // Copy all properties except taskCode |
| | | try { |
| | | org.springframework.beans.BeanUtils.copyProperties(queryVO, newQuery, "taskCode"); |
| | | } catch (Exception e) { |
| | | // If copy fails, manually copy the important fields |
| | | newQuery.setTaskType(queryVO.getTaskType()); |
| | | newQuery.setTaskStatus(queryVO.getTaskStatus()); |
| | | newQuery.setVehicleNo(queryVO.getVehicleNo()); |
| | | newQuery.setCreatorId(queryVO.getCreatorId()); |
| | | newQuery.setAssigneeId(queryVO.getAssigneeId()); |
| | | newQuery.setDeptId(queryVO.getDeptId()); |
| | | newQuery.setDeptIds(queryVO.getDeptIds()); |
| | | newQuery.setPlannedStartTimeBegin(queryVO.getPlannedStartTimeBegin()); |
| | | newQuery.setPlannedStartTimeEnd(queryVO.getPlannedStartTimeEnd()); |
| | | newQuery.setPlannedEndTimeBegin(queryVO.getPlannedEndTimeBegin()); |
| | | newQuery.setPlannedEndTimeEnd(queryVO.getPlannedEndTimeEnd()); |
| | | newQuery.setOverdue(queryVO.getOverdue()); |
| | | } |
| | | |
| | | // Get all tasks matching the other criteria |
| | | List<SysTask> allTasks = sysTaskMapper.selectSysTaskList(newQuery); |
| | | allTasks.stream().forEach(task -> { |
| | | |
| | | // 设置任务码用于SQL查询 |
| | | queryVO.setTaskCode(taskCode); |
| | | |
| | | // 使用优化的查询方法,直接在SQL中关联sys_task_emergency表并计算匹配的dispatchCode和serviceCode |
| | | List<SysTask> tasks = sysTaskMapper.selectSysTaskListByMultiCodeOptimized(queryVO); |
| | | |
| | | // 处理任务分配信息和急救转运扩展信息 |
| | | tasks.forEach(task -> { |
| | | bindTaskAssign(task); |
| | | |
| | | // 对于急救转运任务,使用SQL查询中已计算并匹配好的dispatchCode和serviceCode |
| | | if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(task.getTaskId()); |
| | | task.setEmergencyInfo(emergencyInfo); |
| | | // 创建一个临时的emergencyInfo对象,包含从SQL查询结果中获取的计算后的代码 |
| | | // SysTaskEmergency emergencyInfo = new SysTaskEmergency(); |
| | | // emergencyInfo.setDispatchCode(task.getDispatchCode()); |
| | | // emergencyInfo.setServiceCode(task.getServiceCode()); |
| | | |
| | | // 加载完整的扩展信息 |
| | | SysTaskEmergency fullEmergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(task.getTaskId()); |
| | | if (fullEmergencyInfo != null) { |
| | | // 保留完整信息,但确保dispatchCode和serviceCode是计算后的值 |
| | | task.setEmergencyInfo(fullEmergencyInfo); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | return allTasks.stream().filter(task -> { |
| | | if (task.getTaskCode() != null && task.getTaskCode().contains(taskCode)) { |
| | | return true; |
| | | } |
| | | bindTaskAssign(task); |
| | | |
| | | if ("EMERGENCY_TRANSFER".equals(task.getTaskType()) && task.getEmergencyInfo() != null) { |
| | | String dispatchCode = task.getEmergencyInfo().getDispatchCode(); |
| | | String serviceCode = task.getEmergencyInfo().getServiceCode(); |
| | | return (dispatchCode != null && dispatchCode.contains(taskCode)) || |
| | | (serviceCode != null && serviceCode.contains(taskCode)); |
| | | } |
| | | return false; |
| | | |
| | | }).collect(Collectors.toList()); |
| | | |
| | | |
| | | return tasks; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertSysTask(TaskCreateVO createVO) { |
| | | public Long insertSysTask(TaskCreateVO createVO) { |
| | | // 获取当前用户名和用户ID |
| | | String username = SecurityUtils.getUsername(); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | // 校验用户ID是否为空或为0 |
| | | if(userId==null || userId==0){ |
| | | log.error("insertSysTask 用户ID为空 userName:{}",username); |
| | | return 0; |
| | | return 0L; |
| | | } |
| | | SysTask task = new SysTask(); |
| | | // 创建新的任务对象 |
| | |
| | | }).start(); |
| | | } |
| | | |
| | | return result; |
| | | return result > 0 ? task.getTaskId() : 0L; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertTask(TaskCreateVO createVO,Long serviceOrderId,Long dispatchOrderId, String serviceOrdNo, Long userId,String userName, Long deptId, Date createTime, Date updateTime) { |
| | | public Long insertTask(TaskCreateVO createVO,Long serviceOrderId,Long dispatchOrderId, String serviceOrdNo, Long userId,String userName, Long deptId, Date createTime, Date updateTime) { |
| | | SysTask task = new SysTask(); |
| | | if(createVO.getTaskCode()!=null){ |
| | | task.setTaskCode(createVO.getTaskCode()); |
| | |
| | | this.sendEmeryTaskProcess(task, dispatchOrderId); |
| | | } |
| | | |
| | | return result; |
| | | return result > 0 ? task.getTaskId() : 0L; |
| | | } |
| | | |
| | | private void sendTaskAssigneeEvent(TaskCreateVO createVO,SysTask task,Long userId,String userName){ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | // task.setAssigneeId(updateVO.getAssigneeId()); |
| | | task.setUpdateBy(userName); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int deleteSysTaskByTaskIds(Long[] taskIds) { |
| | | int result = 0; |
| | | for (Long taskId : taskIds) { |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int assignTask(Long taskId, Long assigneeId, String remark) { |
| | | SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | if (task == null) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 强制完成任务(指定实际开始时间和结束时间) |
| | | * |
| | | * @param task 任务信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int forceCompleteTask(SysTask task) { |
| | | if (task == null || task.getTaskId() == null) { |
| | | throw new RuntimeException("任务信息不能为空"); |
| | | } |
| | | |
| | | SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(task.getTaskId()); |
| | | if (oldTask == null) { |
| | | throw new RuntimeException("任务不存在"); |
| | | } |
| | | |
| | | // 校验开始时间和结束时间 |
| | | if (task.getActualStartTime() == null || task.getActualEndTime() == null) { |
| | | throw new RuntimeException("实际开始时间和结束时间不能为空"); |
| | | } |
| | | |
| | | if (task.getActualStartTime().after(task.getActualEndTime())) { |
| | | throw new RuntimeException("结束时间必须大于开始时间"); |
| | | } |
| | | |
| | | // 记录旧状态 |
| | | String oldStatus = oldTask.getTaskStatus(); |
| | | TaskStatus oldTaskStatus = TaskStatus.getByCode(oldStatus); |
| | | |
| | | // 更新任务 |
| | | int result = sysTaskMapper.updateTaskStatus(task); |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | | recordTaskLog(task.getTaskId(), "FORCE_COMPLETE", "强制完成任务", |
| | | oldStatus, task.getTaskStatus(), |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | // 写入状态变更历史记录 |
| | | recordStatusHistory(oldTask, oldStatus, |
| | | oldTaskStatus != null ? oldTaskStatus.getInfo() : oldStatus, |
| | | task.getTaskStatus(), |
| | | TaskStatus.getByCode(task.getTaskStatus()) != null ? TaskStatus.getByCode(task.getTaskStatus()).getInfo() : task.getTaskStatus(), |
| | | task.getRemark(), |
| | | SysTaskStatusHistory.SOURCE_APP, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername(), |
| | | null); |
| | | |
| | | // 发布任务状态变更事件 |
| | | TaskStatus newTaskStatus = TaskStatus.getByCode(task.getTaskStatus()); |
| | | eventPublisher.publishEvent(new TaskStatusChangedEvent( |
| | | this, |
| | | task.getTaskId(), |
| | | oldTask.getTaskCode(), |
| | | oldStatus, |
| | | task.getTaskStatus(), |
| | | oldTaskStatus != null ? oldTaskStatus.getInfo() : "未知", |
| | | newTaskStatus != null ? newTaskStatus.getInfo() : "未知", |
| | | null, // assigneeIds |
| | | SecurityUtils.getUserId(), |
| | | SecurityUtils.getUserId(), |
| | | null, // longitude |
| | | null, // latitude |
| | | null // address |
| | | )); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 变更任务状态(含GPS位置信息) |
| | | * |
| | | * @param taskId 任务ID |
| | |
| | | "状态:" + newStatus.getInfo() + ",备注:" + remark, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername(), |
| | | locationLog); |
| | | // 写入状态变更历史记录 |
| | | recordStatusHistory(oldTask, oldTaskStatus.getCode(), oldTaskStatus.getInfo(), |
| | | newStatus.getCode(), newStatus.getInfo(), remark, |
| | | SysTaskStatusHistory.SOURCE_APP, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername(), |
| | | locationLog); |
| | | } |
| | | |
| | | // 发布任务状态变更事件 |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public Long uploadAttachment(Long taskId, MultipartFile file, String category) { |
| | | return sysTaskAttachmentService.uploadAttachment(taskId, file, category); |
| | | } |
| | |
| | | * @return 返回附件ID |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public Long uploadAttachmentFromWechat(Long taskId, String accessToken, String mediaId, String category) { |
| | | return sysTaskAttachmentService.uploadAttachmentFromWechat(taskId, accessToken, mediaId, category); |
| | | } |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int deleteAttachment(Long attachmentId) { |
| | | return sysTaskAttachmentService.deleteAttachment(attachmentId); |
| | | } |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int assignVehicleToTask(Long taskId, Long vehicleId, String remark,Long userId,String userName) { |
| | | int result = sysTaskVehicleService.assignVehicleToTask(taskId, vehicleId, remark, userId, userName); |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int unassignVehicleFromTask(Long taskId, Long vehicleId) { |
| | | int result = sysTaskVehicleService.unassignVehicleFromTask(taskId, vehicleId); |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public int assignMultipleVehiclesToTask(Long taskId, List<Long> vehicleIds, String remark,Long userId,String userName) { |
| | | int result = sysTaskVehicleService.assignMultipleVehiclesToTask(taskId, vehicleIds, remark, userId, userName); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 记录任务状态变更历史 |
| | | * |
| | | * @param task 任务对象(取 task_id / task_code) |
| | | * @param fromStatus 变更前状态码 |
| | | * @param fromStatusName 变更前状态名称 |
| | | * @param toStatus 变更后状态码 |
| | | * @param toStatusName 变更后状态名称 |
| | | * @param changeReason 变更原因/备注 |
| | | * @param changeSource 触发来源(APP / ADMIN / SYSTEM / LEGACY) |
| | | * @param operatorId 操作人 ID |
| | | * @param operatorName 操作人姓名 |
| | | * @param locationLog GPS 位置信息(可为 null) |
| | | */ |
| | | private void recordStatusHistory(SysTask task, |
| | | String fromStatus, String fromStatusName, |
| | | String toStatus, String toStatusName, |
| | | String changeReason, String changeSource, |
| | | Long operatorId, String operatorName, |
| | | SysTaskLog locationLog) { |
| | | try { |
| | | SysTaskStatusHistory history = new SysTaskStatusHistory(); |
| | | history.setTaskId(task.getTaskId()); |
| | | history.setTaskCode(task.getTaskCode()); |
| | | history.setFromStatus(fromStatus); |
| | | history.setFromStatusName(fromStatusName); |
| | | history.setToStatus(toStatus); |
| | | history.setToStatusName(toStatusName); |
| | | history.setChangeReason(changeReason); |
| | | history.setChangeSource(changeSource != null ? changeSource : SysTaskStatusHistory.SOURCE_APP); |
| | | history.setOperatorId(operatorId); |
| | | history.setOperatorName(operatorName); |
| | | history.setChangeTime(DateUtils.getNowDate()); |
| | | history.setIpAddress("127.0.0.1"); |
| | | if (locationLog != null) { |
| | | history.setLongitude(locationLog.getLongitude()); |
| | | history.setLatitude(locationLog.getLatitude()); |
| | | history.setLocationAddress(locationLog.getLocationAddress()); |
| | | } |
| | | sysTaskStatusHistoryMapper.insert(history); |
| | | } catch (Exception e) { |
| | | log.error("记录任务状态变更历史失败, taskId={}", task.getTaskId(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 构建任务描述 |
| | | * |
| | | * @param task 任务对象 |
| | |
| | | } |
| | | } |
| | | |
| | | private AjaxResult getCheckCanSuccess(){ |
| | | List<Map<String, Object>> conflicts = new ArrayList<>(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("valid", conflicts.isEmpty()); |
| | | result.put("conflicts", conflicts); |
| | | return AjaxResult.success(result); |
| | | } |
| | | /** |
| | | * 检查任务是否可以出发 |
| | | * 检查: |
| | |
| | | */ |
| | | @Override |
| | | public AjaxResult checkTaskCanDepart(Long taskId) { |
| | | return getCheckCanSuccess(); |
| | | } |
| | | |
| | | public AjaxResult checkTaskCanDepartOld(Long taskId) { |
| | | List<Map<String, Object>> conflicts = new ArrayList<>(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | | // 获取任务详情 |
| | | SysTask task = this.getTaskDetail(taskId); |
| | | if (task == null) { |
| | | return AjaxResult.error("任务不存在"); |
| | | } |
| | | |
| | | List<Map<String, Object>> conflicts = new ArrayList<>(); |
| | | |
| | | // 1. 检查车辆是否有未完成的任务 |
| | | List<SysTaskVehicle> taskVehicles = task.getAssignedVehicles(); |
| | |
| | | } |
| | | } |
| | | |
| | | // 返回结果 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | | result.put("valid", conflicts.isEmpty()); |
| | | result.put("conflicts", conflicts); |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public AjaxResult setAssigneeReady(Long taskId, Long userId) { |
| | | return sysTaskAssigneeService.setAssigneeReady(taskId, userId); |
| | | } |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | |
| | | public AjaxResult cancelAssigneeReady(Long taskId, Long userId) { |
| | | return sysTaskAssigneeService.cancelAssigneeReady(taskId, userId); |
| | | } |