| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | |
| | | import com.ruoyi.system.domain.SysTaskVehicle; |
| | | import com.ruoyi.system.domain.SysTaskAttachment; |
| | | import com.ruoyi.system.domain.SysTaskLog; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.domain.SysTaskWelfare; |
| | | import com.ruoyi.system.domain.vo.TaskQueryVO; |
| | | import com.ruoyi.system.domain.vo.TaskCreateVO; |
| | | import com.ruoyi.system.domain.vo.TaskUpdateVO; |
| | |
| | | import com.ruoyi.system.mapper.SysTaskVehicleMapper; |
| | | import com.ruoyi.system.mapper.SysTaskAttachmentMapper; |
| | | import com.ruoyi.system.mapper.SysTaskLogMapper; |
| | | import com.ruoyi.system.mapper.SysTaskEmergencyMapper; |
| | | import com.ruoyi.system.mapper.SysTaskWelfareMapper; |
| | | import com.ruoyi.system.mapper.VehicleInfoMapper; |
| | | import com.ruoyi.system.domain.VehicleInfo; |
| | | import com.ruoyi.system.service.ISysTaskService; |
| | |
| | | private SysTaskLogMapper sysTaskLogMapper; |
| | | |
| | | @Autowired |
| | | private SysTaskEmergencyMapper sysTaskEmergencyMapper; |
| | | |
| | | @Autowired |
| | | private SysTaskWelfareMapper sysTaskWelfareMapper; |
| | | |
| | | @Autowired |
| | | private VehicleInfoMapper vehicleInfoMapper; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysTask selectSysTaskByTaskId(Long taskId) { |
| | | return sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | if (task != null) { |
| | | // 加载急救转运扩展信息 |
| | | if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | task.setEmergencyInfo(emergencyInfo); |
| | | } |
| | | // 加载福祉车扩展信息 |
| | | else if ("WELFARE".equals(task.getTaskType())) { |
| | | SysTaskWelfare welfareInfo = sysTaskWelfareMapper.selectSysTaskWelfareByTaskId(taskId); |
| | | task.setWelfareInfo(welfareInfo); |
| | | } |
| | | } |
| | | return task; |
| | | } |
| | | |
| | | /** |
| | |
| | | task.setTaskType(createVO.getTaskType()); |
| | | task.setTaskStatus(TaskStatus.PENDING.getCode()); |
| | | task.setTaskDescription(createVO.getTaskDescription()); |
| | | task.setDepartureAddress(createVO.getDepartureAddress()); |
| | | task.setDestinationAddress(createVO.getDestinationAddress()); |
| | | task.setDepartureLongitude(createVO.getDepartureLongitude()); |
| | | task.setDepartureLatitude(createVO.getDepartureLatitude()); |
| | | task.setDestinationLongitude(createVO.getDestinationLongitude()); |
| | | task.setDestinationLatitude(createVO.getDestinationLatitude()); |
| | | task.setPlannedStartTime(createVO.getPlannedStartTime()); |
| | | task.setPlannedEndTime(createVO.getPlannedEndTime()); |
| | | task.setAssigneeId(createVO.getAssigneeId()); |
| | |
| | | task.setRemark(createVO.getRemark()); |
| | | task.setDelFlag("0"); |
| | | |
| | | // 计算预计公里数 |
| | | calculateEstimatedDistance(task); |
| | | // 设置通用地址和坐标信息 |
| | | if (createVO.getDepartureAddress() != null) { |
| | | task.setDepartureAddress(createVO.getDepartureAddress()); |
| | | } |
| | | if (createVO.getDestinationAddress() != null) { |
| | | task.setDestinationAddress(createVO.getDestinationAddress()); |
| | | } |
| | | if (createVO.getDepartureLongitude() != null) { |
| | | task.setDepartureLongitude(createVO.getDepartureLongitude()); |
| | | } |
| | | if (createVO.getDepartureLatitude() != null) { |
| | | task.setDepartureLatitude(createVO.getDepartureLatitude()); |
| | | } |
| | | if (createVO.getDestinationLongitude() != null) { |
| | | task.setDestinationLongitude(createVO.getDestinationLongitude()); |
| | | } |
| | | if (createVO.getDestinationLatitude() != null) { |
| | | task.setDestinationLatitude(createVO.getDestinationLatitude()); |
| | | } |
| | | if (createVO.getEstimatedDistance() != null) { |
| | | task.setEstimatedDistance(createVO.getEstimatedDistance()); |
| | | } |
| | | |
| | | // 设置急救转运特定信息 |
| | | if (createVO.getTransferTime() != null) { |
| | | task.setPlannedStartTime(createVO.getTransferTime()); |
| | | } |
| | | if (createVO.getTransferDistance() != null) { |
| | | task.setEstimatedDistance(createVO.getTransferDistance()); |
| | | } |
| | | |
| | | // 设置福祉车特定信息 |
| | | if (createVO.getServiceTime() != null) { |
| | | task.setPlannedStartTime(createVO.getServiceTime()); |
| | | } |
| | | if (createVO.getStartAddress() != null) { |
| | | task.setDepartureAddress(createVO.getStartAddress()); |
| | | } |
| | | if (createVO.getEndAddress() != null) { |
| | | task.setDestinationAddress(createVO.getEndAddress()); |
| | | } |
| | | // 设置福祉车公里数 |
| | | if (createVO.getDistance() != null) { |
| | | task.setEstimatedDistance(createVO.getDistance()); |
| | | } |
| | | |
| | | int result = sysTaskMapper.insertSysTask(task); |
| | | |
| | |
| | | |
| | | sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle); |
| | | } |
| | | } |
| | | |
| | | // 保存急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType())) { |
| | | saveEmergencyInfo(task.getTaskId(), createVO); |
| | | } |
| | | |
| | | // 保存福祉车扩展信息 |
| | | if (result > 0 && "WELFARE".equals(createVO.getTaskType())) { |
| | | saveWelfareInfo(task.getTaskId(), createVO); |
| | | } |
| | | |
| | | // 记录操作日志 |
| | |
| | | @Override |
| | | @Transactional |
| | | public int changeTaskStatus(Long taskId, TaskStatus newStatus, String remark) { |
| | | return changeTaskStatusWithLocation(taskId, newStatus, remark, null); |
| | | } |
| | | |
| | | /** |
| | | * 变更任务状态(含GPS位置信息) |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param newStatus 新状态 |
| | | * @param remark 备注 |
| | | * @param locationLog GPS位置信息日志对象 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int changeTaskStatusWithLocation(Long taskId, TaskStatus newStatus, String remark, SysTaskLog locationLog) { |
| | | SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | if (oldTask == null) { |
| | | throw new RuntimeException("任务不存在"); |
| | |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | // 根据状态设置相应的时间 |
| | | if (newStatus == TaskStatus.IN_PROGRESS && oldTask.getActualStartTime() == null) { |
| | | if (newStatus == TaskStatus.DEPARTING && oldTask.getActualStartTime() == null) { |
| | | // 出发中:设置实际开始时间 |
| | | task.setActualStartTime(DateUtils.getNowDate()); |
| | | } else if (newStatus == TaskStatus.IN_PROGRESS && oldTask.getActualStartTime() == null) { |
| | | // 兼容旧数据:任务中状态也设置实际开始时间 |
| | | task.setActualStartTime(DateUtils.getNowDate()); |
| | | } else if (newStatus == TaskStatus.COMPLETED) { |
| | | // 已完成:设置实际结束时间 |
| | | task.setActualEndTime(DateUtils.getNowDate()); |
| | | } |
| | | |
| | | int result = sysTaskMapper.updateTaskStatus(task); |
| | | |
| | | // 记录操作日志 |
| | | // 记录操作日志(含GPS位置信息) |
| | | if (result > 0) { |
| | | recordTaskLog(taskId, "STATUS_CHANGE", "状态变更", |
| | | "状态:" + oldTaskStatus.getInfo(), |
| | | "状态:" + newStatus.getInfo() + ",备注:" + remark, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername(), |
| | | locationLog); |
| | | } |
| | | |
| | | return result; |
| | |
| | | task.setAttachments(sysTaskAttachmentMapper.selectSysTaskAttachmentByTaskId(taskId)); |
| | | // 查询操作日志 |
| | | task.setOperationLogs(sysTaskLogMapper.selectSysTaskLogByTaskId(taskId)); |
| | | // 加载急救转运扩展信息 |
| | | if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | task.setEmergencyInfo(emergencyInfo); |
| | | } |
| | | // 加载福祉车扩展信息 |
| | | else if ("WELFARE".equals(task.getTaskType())) { |
| | | SysTaskWelfare welfareInfo = sysTaskWelfareMapper.selectSysTaskWelfareByTaskId(taskId); |
| | | task.setWelfareInfo(welfareInfo); |
| | | } |
| | | } |
| | | return task; |
| | | } |
| | |
| | | */ |
| | | private void recordTaskLog(Long taskId, String operationType, String operationDesc, |
| | | String oldValue, String newValue, Long operatorId, String operatorName) { |
| | | SysTaskLog log = new SysTaskLog(); |
| | | recordTaskLog(taskId, operationType, operationDesc, oldValue, newValue, |
| | | operatorId, operatorName, null); |
| | | } |
| | | |
| | | /** |
| | | * 记录任务操作日志(含GPS位置信息) |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param operationType 操作类型 |
| | | * @param operationDesc 操作描述 |
| | | * @param oldValue 操作前值 |
| | | * @param newValue 操作后值 |
| | | * @param operatorId 操作人ID |
| | | * @param operatorName 操作人姓名 |
| | | * @param log GPS位置信息日志对象(可为null) |
| | | */ |
| | | private void recordTaskLog(Long taskId, String operationType, String operationDesc, |
| | | String oldValue, String newValue, Long operatorId, String operatorName, |
| | | SysTaskLog log) { |
| | | if (log == null) { |
| | | log = new SysTaskLog(); |
| | | } |
| | | |
| | | log.setTaskId(taskId); |
| | | log.setOperationType(operationType); |
| | | log.setOperationDesc(operationDesc); |
| | |
| | | task.setEstimatedDistance(java.math.BigDecimal.ZERO); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存急救转运任务扩展信息 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建对象 |
| | | */ |
| | | private void saveEmergencyInfo(Long taskId, TaskCreateVO createVO) { |
| | | SysTaskEmergency emergencyInfo = new SysTaskEmergency(); |
| | | emergencyInfo.setTaskId(taskId); |
| | | |
| | | // 设置患者信息 |
| | | if (createVO.getPatient() != null) { |
| | | emergencyInfo.setPatientContact(createVO.getPatient().getContact()); |
| | | emergencyInfo.setPatientPhone(createVO.getPatient().getPhone()); |
| | | emergencyInfo.setPatientName(createVO.getPatient().getName()); |
| | | emergencyInfo.setPatientGender(createVO.getPatient().getGender()); |
| | | emergencyInfo.setPatientIdCard(createVO.getPatient().getIdCard()); |
| | | emergencyInfo.setPatientCondition(createVO.getPatient().getCondition()); |
| | | } |
| | | |
| | | // 设置转出医院信息 |
| | | if (createVO.getHospitalOut() != null) { |
| | | emergencyInfo.setHospitalOutName(createVO.getHospitalOut().getName()); |
| | | emergencyInfo.setHospitalOutDepartment(createVO.getHospitalOut().getDepartment()); |
| | | emergencyInfo.setHospitalOutBedNumber(createVO.getHospitalOut().getBedNumber()); |
| | | emergencyInfo.setHospitalOutAddress(createVO.getHospitalOut().getAddress()); |
| | | emergencyInfo.setHospitalOutLongitude(createVO.getHospitalOut().getLongitude()); |
| | | emergencyInfo.setHospitalOutLatitude(createVO.getHospitalOut().getLatitude()); |
| | | } |
| | | |
| | | // 设置转入医院信息 |
| | | if (createVO.getHospitalIn() != null) { |
| | | emergencyInfo.setHospitalInName(createVO.getHospitalIn().getName()); |
| | | emergencyInfo.setHospitalInDepartment(createVO.getHospitalIn().getDepartment()); |
| | | emergencyInfo.setHospitalInBedNumber(createVO.getHospitalIn().getBedNumber()); |
| | | emergencyInfo.setHospitalInAddress(createVO.getHospitalIn().getAddress()); |
| | | emergencyInfo.setHospitalInLongitude(createVO.getHospitalIn().getLongitude()); |
| | | emergencyInfo.setHospitalInLatitude(createVO.getHospitalIn().getLatitude()); |
| | | } |
| | | |
| | | // 设置费用信息 |
| | | emergencyInfo.setTransferDistance(createVO.getTransferDistance()); |
| | | emergencyInfo.setTransferPrice(createVO.getPrice()); |
| | | |
| | | // 系统字段 |
| | | emergencyInfo.setCreateTime(DateUtils.getNowDate()); |
| | | emergencyInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | emergencyInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | emergencyInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | |
| | | sysTaskEmergencyMapper.insertSysTaskEmergency(emergencyInfo); |
| | | } |
| | | |
| | | /** |
| | | * 保存福祉车任务扩展信息 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建对象 |
| | | */ |
| | | private void saveWelfareInfo(Long taskId, TaskCreateVO createVO) { |
| | | SysTaskWelfare welfareInfo = new SysTaskWelfare(); |
| | | welfareInfo.setTaskId(taskId); |
| | | |
| | | // 设置乘客信息 |
| | | if (createVO.getPassenger() != null) { |
| | | welfareInfo.setPassengerContact(createVO.getPassenger().getContact()); |
| | | welfareInfo.setPassengerPhone(createVO.getPassenger().getPhone()); |
| | | } |
| | | |
| | | // 设置地址信息 |
| | | welfareInfo.setPickupAddress(createVO.getStartAddress()); |
| | | welfareInfo.setDestinationAddress(createVO.getEndAddress()); |
| | | |
| | | // 设置GPS坐标 |
| | | welfareInfo.setPickupLongitude(createVO.getDepartureLongitude()); |
| | | welfareInfo.setPickupLatitude(createVO.getDepartureLatitude()); |
| | | welfareInfo.setDestinationLongitude(createVO.getDestinationLongitude()); |
| | | welfareInfo.setDestinationLatitude(createVO.getDestinationLatitude()); |
| | | |
| | | // 设置距离和费用 |
| | | // 优先使用福祉车专用的distance字段,如果没有则使用通用的estimatedDistance |
| | | BigDecimal serviceDistance = createVO.getDistance() != null ? createVO.getDistance() : createVO.getEstimatedDistance(); |
| | | welfareInfo.setServiceDistance(serviceDistance); |
| | | welfareInfo.setServicePrice(createVO.getPrice()); |
| | | |
| | | // 系统字段 |
| | | welfareInfo.setCreateTime(DateUtils.getNowDate()); |
| | | welfareInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | welfareInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | welfareInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | |
| | | sysTaskWelfareMapper.insertSysTaskWelfare(welfareInfo); |
| | | } |
| | | } |