| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.utils.TaskCodeGenerator; |
| | | import com.ruoyi.common.config.ImageUrlConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import com.ruoyi.system.domain.vo.TaskUpdateVO; |
| | | import com.ruoyi.system.domain.vo.TaskStatisticsVO; |
| | | import com.ruoyi.system.domain.enums.TaskStatus; |
| | | import com.ruoyi.system.mapper.SysTaskMapper; |
| | | 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.SysTaskAssigneeMapper; |
| | | import com.ruoyi.system.mapper.VehicleInfoMapper; |
| | | import com.ruoyi.system.domain.VehicleInfo; |
| | | import com.ruoyi.system.service.ISysTaskService; |
| | | import com.ruoyi.system.service.ILegacySystemSyncService; |
| | | import com.ruoyi.system.service.ITaskAttachmentSyncService; |
| | | import com.ruoyi.system.event.TaskCreatedEvent; |
| | | import com.ruoyi.system.event.TaskAssignedEvent; |
| | | import com.ruoyi.system.event.TaskStatusChangedEvent; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | |
| | |
| | | */ |
| | | @Service |
| | | public class SysTaskServiceImpl implements ISysTaskService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(SysTaskServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private SysTaskMapper sysTaskMapper; |
| | |
| | | |
| | | @Autowired |
| | | private ApplicationEventPublisher eventPublisher; |
| | | |
| | | @Autowired |
| | | private ImageUrlConfig imageUrlConfig; |
| | | |
| | | @Autowired(required = false) |
| | | private ITaskAttachmentSyncService taskAttachmentSyncService; |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | /** |
| | | * 查询任务管理 |
| | |
| | | @Override |
| | | @Transactional |
| | | public int insertSysTask(TaskCreateVO createVO) { |
| | | String username = SecurityUtils.getUsername(); |
| | | SysTask task = new SysTask(); |
| | | task.setTaskCode(generateTaskCode()); |
| | | task.setTaskType(createVO.getTaskType()); |
| | |
| | | task.setCreatorId(SecurityUtils.getUserId()); |
| | | // 优先使用前端传入的部门ID,如果没有则使用当前用户的部门ID |
| | | task.setDeptId(createVO.getDeptId() != null ? createVO.getDeptId() : SecurityUtils.getDeptId()); |
| | | task.setCreateBy(SecurityUtils.getUsername()); |
| | | task.setCreateBy(username); |
| | | task.setCreateTime(DateUtils.getNowDate()); |
| | | task.setUpdateBy(SecurityUtils.getUsername()); |
| | | task.setUpdateBy(username); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | task.setRemark(createVO.getRemark()); |
| | | task.setDelFlag("0"); |
| | |
| | | |
| | | // 保存执行人员信息(包含角色类型) |
| | | if (result > 0 && createVO.getAssignees() != null && !createVO.getAssignees().isEmpty()) { |
| | | saveTaskAssignees(task.getTaskId(), createVO.getAssignees()); |
| | | saveTaskAssignees(task.getTaskId(), createVO.getAssignees(),username); |
| | | } |
| | | |
| | | // 保存急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType())) { |
| | | saveEmergencyInfo(task.getTaskId(), createVO); |
| | | saveEmergencyInfo(task.getTaskId(),username, createVO,null,null); |
| | | } |
| | | |
| | | // 保存福祉车扩展信息 |
| | | if (result > 0 && "WELFARE".equals(createVO.getTaskType())) { |
| | | saveWelfareInfo(task.getTaskId(), createVO); |
| | | saveWelfareInfo(task.getTaskId(),SecurityUtils.getUsername(), createVO); |
| | | } |
| | | |
| | | // 记录操作日志 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 新增任务管理(允许从外部传入用户信息、部门信息和时间信息) |
| | | * |
| | | * @param createVO 任务创建对象 |
| | | * @param userId 用户ID |
| | | * @param deptId 部门ID |
| | | * @param createTime 创建时间 |
| | | * @param updateTime 更新时间 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int insertTask(TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId, Long userId,String userName, Long deptId, Date createTime, Date updateTime) { |
| | | SysTask task = new SysTask(); |
| | | if(createVO.getTaskCode()!=null){ |
| | | task.setTaskCode(createVO.getTaskCode()); |
| | | }else{ |
| | | task.setTaskCode(generateTaskCode()); |
| | | } |
| | | task.setTaskType(createVO.getTaskType()); |
| | | task.setTaskStatus(TaskStatus.PENDING.getCode()); |
| | | task.setTaskDescription(createVO.getTaskDescription()); |
| | | task.setPlannedStartTime(createVO.getPlannedStartTime()); |
| | | task.setPlannedEndTime(createVO.getPlannedEndTime()); |
| | | task.setActualStartTime(createVO.getActualStartTime()); |
| | | task.setActualEndTime(createVO.getActualEndTime()); |
| | | task.setAssigneeId(createVO.getAssigneeId()); |
| | | // 使用外部传入的用户ID和部门ID |
| | | task.setCreatorId(userId); |
| | | task.setDeptId(deptId); |
| | | task.setCreateBy(userName); |
| | | // 使用外部传入的创建时间和更新时间 |
| | | task.setCreateTime(createTime); |
| | | task.setUpdateTime(updateTime); |
| | | task.setUpdateBy(userName); |
| | | task.setRemark(createVO.getRemark()); |
| | | task.setDelFlag("0"); |
| | | |
| | | |
| | | |
| | | // 设置通用地址和坐标信息 |
| | | 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.getPlannedStartTime() != null) { |
| | | task.setPlannedStartTime(createVO.getPlannedStartTime()); |
| | | } |
| | | 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); |
| | | |
| | | // 保存车辆关联信息 |
| | | if (result > 0 && createVO.getVehicleIds() != null && !createVO.getVehicleIds().isEmpty()) { |
| | | for (Long vehicleId : createVO.getVehicleIds()) { |
| | | SysTaskVehicle taskVehicle = new SysTaskVehicle(); |
| | | taskVehicle.setTaskId(task.getTaskId()); |
| | | taskVehicle.setVehicleId(vehicleId); |
| | | taskVehicle.setAssignTime(updateTime); |
| | | taskVehicle.setAssignBy(userName); |
| | | taskVehicle.setStatus("ASSIGNED"); |
| | | taskVehicle.setCreateBy(userName); |
| | | taskVehicle.setCreateTime(createTime); |
| | | taskVehicle.setUpdateBy(userName); |
| | | taskVehicle.setUpdateTime(updateTime); |
| | | |
| | | sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle); |
| | | } |
| | | } |
| | | |
| | | // 保存执行人员信息(包含角色类型) |
| | | if (result > 0 && createVO.getAssignees() != null && !createVO.getAssignees().isEmpty()) { |
| | | saveTaskAssignees(task.getTaskId(), createVO.getAssignees(),userName); |
| | | } |
| | | |
| | | // 保存急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType())) { |
| | | saveEmergencyInfo(task.getTaskId(),userName, createVO, serviceOrderId, dispatchOrderId); |
| | | } |
| | | |
| | | // 保存福祉车扩展信息 |
| | | if (result > 0 && "WELFARE".equals(createVO.getTaskType())) { |
| | | saveWelfareInfo(task.getTaskId(),userName, createVO); |
| | | } |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | | recordTaskLog(task.getTaskId(), "CREATE", "创建任务", null, |
| | | "任务类型:" + createVO.getTaskType(), userId, userName); |
| | | } |
| | | |
| | | // 发布任务创建事件 |
| | | if (result > 0) { |
| | | eventPublisher.publishEvent(new TaskCreatedEvent( |
| | | this, |
| | | task.getTaskId(), |
| | | task.getTaskCode(), |
| | | task.getTaskType(), |
| | | userId, |
| | | userName |
| | | )); |
| | | } |
| | | |
| | | // 发布任务分配事件 |
| | | if (result > 0 && createVO.getAssignees() != null && !createVO.getAssignees().isEmpty()) { |
| | | List<Long> assigneeIds = createVO.getAssignees().stream() |
| | | .map(assignee -> assignee.getUserId()) |
| | | .collect(Collectors.toList()); |
| | | List<String> assigneeNames = createVO.getAssignees().stream() |
| | | .map(assignee -> assignee.getUserName()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | eventPublisher.publishEvent(new TaskAssignedEvent( |
| | | this, |
| | | task.getTaskId(), |
| | | task.getTaskCode(), |
| | | assigneeIds, |
| | | assigneeNames, |
| | | userId, |
| | | userName |
| | | )); |
| | | } |
| | | |
| | | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 修改任务管理 |
| | | * |
| | | * @param updateVO 任务更新对象 |
| | |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | task.setRemark(updateVO.getRemark()); |
| | | |
| | | // 如果更新了部门ID |
| | | if (updateVO.getDeptId() != null) { |
| | | task.setDeptId(updateVO.getDeptId()); |
| | | } |
| | | |
| | | // 重新计算预计公里数 |
| | | calculateEstimatedDistance(task); |
| | | |
| | | int result = sysTaskMapper.updateSysTask(task); |
| | | |
| | | // 更新车辆关联 |
| | | if (result > 0 && updateVO.getVehicleIds() != null && !updateVO.getVehicleIds().isEmpty()) { |
| | | // 查询现有的车辆关联 |
| | | List<SysTaskVehicle> existingVehicles = sysTaskVehicleMapper.selectSysTaskVehicleByTaskId(updateVO.getTaskId()); |
| | | List<Long> existingVehicleIds = existingVehicles.stream() |
| | | .map(SysTaskVehicle::getVehicleId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 比较新旧车辆ID列表,判断是否有变化 |
| | | boolean vehiclesChanged = !new HashSet<>(existingVehicleIds).equals(new HashSet<>(updateVO.getVehicleIds())); |
| | | |
| | | // 只有车辆发生变化时才更新 |
| | | if (vehiclesChanged) { |
| | | // 删除旧的车辆关联 |
| | | sysTaskVehicleMapper.deleteSysTaskVehicleByTaskId(updateVO.getTaskId()); |
| | | |
| | | // 添加新的车辆关联 |
| | | Date now = DateUtils.getNowDate(); |
| | | String currentUser = SecurityUtils.getUsername(); |
| | | for (Long vehicleId : updateVO.getVehicleIds()) { |
| | | SysTaskVehicle taskVehicle = new SysTaskVehicle(); |
| | | taskVehicle.setTaskId(updateVO.getTaskId()); |
| | | taskVehicle.setVehicleId(vehicleId); |
| | | taskVehicle.setAssignTime(now); |
| | | taskVehicle.setAssignBy(currentUser); |
| | | taskVehicle.setCreateTime(now); |
| | | sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 更新急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && updateVO.getEmergencyInfo() != null) { |
| | | updateEmergencyInfo(updateVO.getTaskId(), updateVO); |
| | | } |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int uploadAttachment(Long taskId, MultipartFile file, String category) { |
| | | public Long uploadAttachment(Long taskId, MultipartFile file, String category) { |
| | | try { |
| | | // 上传文件 |
| | | String fileName = FileUploadUtils.upload("/task", file); |
| | | String filePath = FileUploadUtils.getDefaultBaseDir() + fileName; |
| | | // 上传文件,返回相对路径(如:/task/2025/01/15/xxx.jpg) |
| | | String fileName = category+"_"+System.currentTimeMillis()+"_"+file.getOriginalFilename(); |
| | | |
| | | fileName=saveLocalPath(fileName,file.getInputStream()); |
| | | |
| | | SysTaskAttachment attachment = new SysTaskAttachment(); |
| | | attachment.setTaskId(taskId); |
| | | attachment.setFileName(file.getOriginalFilename()); |
| | | attachment.setFilePath(filePath); |
| | | // 保存相对路径,不包含 baseDir |
| | | attachment.setFilePath(fileName); |
| | | attachment.setFileSize(file.getSize()); |
| | | attachment.setFileType(getFileType(file.getOriginalFilename())); |
| | | attachment.setAttachmentCategory(category); |
| | | attachment.setUploadTime(DateUtils.getNowDate()); |
| | | attachment.setUploadBy(SecurityUtils.getUsername()); |
| | | |
| | | int result = sysTaskAttachmentMapper.insertSysTaskAttachment(attachment); |
| | | Long result = sysTaskAttachmentMapper.insertSysTaskAttachment(attachment); |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | |
| | | recordTaskLog(taskId, "UPDATE", "上传附件", null, |
| | | "上传文件:" + file.getOriginalFilename() + "(分类:" + categoryDesc + ")", |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | |
| | | |
| | | } |
| | | |
| | | return result; |
| | | return attachment.getAttachmentId(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("文件上传失败:" + e.getMessage()); |
| | | } |
| | |
| | | * @param accessToken 微信AccessToken |
| | | * @param mediaId 微信mediaId |
| | | * @param category 附件分类 |
| | | * @return 结果 |
| | | * @return 返回附件ID |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int uploadAttachmentFromWechat(Long taskId, String accessToken, String mediaId, String category) { |
| | | public Long uploadAttachmentFromWechat(Long taskId, String accessToken, String mediaId, String category) { |
| | | try { |
| | | // 从微信服务器下载文件 |
| | | String wechatUrl = String.format( |
| | |
| | | String fileName = "wx_" + mediaId.substring(0, Math.min(20, mediaId.length())) + "_" + System.currentTimeMillis() + ".jpg"; |
| | | |
| | | // 保存到本地 |
| | | String baseDir = FileUploadUtils.getDefaultBaseDir(); |
| | | String datePath = DateUtils.datePath(); |
| | | String uploadDir = baseDir + "/task/" + datePath; |
| | | |
| | | // 创建目录 |
| | | File uploadPath = new File(uploadDir); |
| | | if (!uploadPath.exists()) { |
| | | uploadPath.mkdirs(); |
| | | } |
| | | |
| | | // 保存文件 |
| | | String filePath = uploadDir + "/" + fileName; |
| | | File file = new File(filePath); |
| | | try (FileOutputStream fos = new FileOutputStream(file)) { |
| | | fos.write(fileBytes); |
| | | } |
| | | |
| | | String relativeFilePath = saveLocalPath(fileName, fileBytes); |
| | | |
| | | // 保存附件记录 |
| | | SysTaskAttachment attachment = new SysTaskAttachment(); |
| | | attachment.setTaskId(taskId); |
| | | attachment.setFileName(fileName); |
| | | attachment.setFilePath(filePath); |
| | | // 保存相对路径 |
| | | attachment.setFilePath(relativeFilePath); |
| | | attachment.setFileSize((long) fileBytes.length); |
| | | attachment.setFileType("jpg"); |
| | | attachment.setAttachmentCategory(category); |
| | | attachment.setUploadTime(DateUtils.getNowDate()); |
| | | attachment.setUploadBy(SecurityUtils.getUsername()); |
| | | |
| | | int result = sysTaskAttachmentMapper.insertSysTaskAttachment(attachment); |
| | | Long result = sysTaskAttachmentMapper.insertSysTaskAttachment(attachment); |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | |
| | | recordTaskLog(taskId, "UPDATE", "上传附件", null, |
| | | "通过微信上传文件:" + fileName + "(分类:" + categoryDesc + ")", |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | |
| | | |
| | | } |
| | | |
| | | return result; |
| | | return attachment.getAttachmentId(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("从微信上传文件失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | private static String saveLocalPath(String fileName, byte[] fileBytes) throws IOException { |
| | | String baseDir = FileUploadUtils.getDefaultBaseDir(); |
| | | String datePath = DateUtils.datePath(); |
| | | String uploadDir = baseDir + "/task/" + datePath; |
| | | |
| | | // 创建目录 |
| | | File uploadPath = new File(uploadDir); |
| | | if (!uploadPath.exists()) { |
| | | uploadPath.mkdirs(); |
| | | } |
| | | |
| | | // 保存文件 |
| | | String filePath = uploadDir + "/" + fileName; |
| | | File file = new File(filePath); |
| | | try (FileOutputStream fos = new FileOutputStream(file)) { |
| | | fos.write(fileBytes); |
| | | } |
| | | |
| | | // 生成相对路径(不包含baseDir) |
| | | String relativeFilePath = "/task/" + datePath + "/" + fileName; |
| | | return relativeFilePath; |
| | | } |
| | | |
| | | private String saveLocalPath(String fileName,InputStream stream){ |
| | | String baseDir = FileUploadUtils.getDefaultBaseDir(); |
| | | String datePath = DateUtils.datePath(); |
| | | String uploadDir = baseDir + "/task/" + datePath; |
| | | |
| | | // 创建目录 |
| | | File uploadPath = new File(uploadDir); |
| | | if (!uploadPath.exists()) { |
| | | uploadPath.mkdirs(); |
| | | } |
| | | |
| | | // 保存文件 |
| | | String filePath = uploadDir + "/" + fileName; |
| | | //将inputstream写入文件 |
| | | try (OutputStream os = new FileOutputStream(filePath)) { |
| | | byte[] buffer = new byte[1024]; // 缓冲区,减少 IO 次数 |
| | | int bytesRead; |
| | | // 循环读取输入流中的数据,写入输出流 |
| | | while ((bytesRead = stream.read(buffer)) != -1) { |
| | | os.write(buffer, 0, bytesRead); |
| | | } |
| | | os.flush(); // 强制刷新缓冲区,确保数据写入文件 |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 生成相对路径(不包含baseDir) |
| | | String relativeFilePath = "/task/" + datePath + "/" + fileName; |
| | | return relativeFilePath; |
| | | } |
| | | |
| | | /** |
| | | * 从 URL 下载文件 |
| | | */ |
| | |
| | | */ |
| | | @Override |
| | | public SysTaskAttachment getAttachmentById(Long attachmentId) { |
| | | return sysTaskAttachmentMapper.selectSysTaskAttachmentByAttachmentId(attachmentId); |
| | | SysTaskAttachment attachment = sysTaskAttachmentMapper.selectSysTaskAttachmentByAttachmentId(attachmentId); |
| | | if (attachment != null) { |
| | | // 拼接完整URL |
| | | buildAttachmentUrl(attachment); |
| | | } |
| | | return attachment; |
| | | } |
| | | |
| | | @Override |
| | | public List<SysTaskAttachment> getAttachmentsByTaskId(Long taskId) { |
| | | return sysTaskAttachmentMapper.selectSysTaskAttachmentByTaskId(taskId); |
| | | } |
| | | |
| | | /** |
| | |
| | | // 查询关联车辆 |
| | | task.setAssignedVehicles(sysTaskVehicleMapper.selectSysTaskVehicleByTaskId(taskId)); |
| | | // 查询附件 |
| | | task.setAttachments(sysTaskAttachmentMapper.selectSysTaskAttachmentByTaskId(taskId)); |
| | | List<SysTaskAttachment> attachments = sysTaskAttachmentMapper.selectSysTaskAttachmentByTaskId(taskId); |
| | | // 为每个附件拼接完整URL |
| | | if (attachments != null && !attachments.isEmpty()) { |
| | | attachments.forEach(this::buildAttachmentUrl); |
| | | } |
| | | task.setAttachments(attachments); |
| | | // 查询操作日志 |
| | | task.setOperationLogs(sysTaskLogMapper.selectSysTaskLogByTaskId(taskId)); |
| | | // 加载急救转运扩展信息 |
| | |
| | | } |
| | | } |
| | | return task; |
| | | } |
| | | |
| | | /** |
| | | * 检查车辆是否有正在进行中的任务 |
| | | * 正在进行中的任务是指状态不为:PENDING(待处理)、COMPLETED(已完成)、CANCELLED(已取消)的任务 |
| | | * |
| | | * @param vehicleId 车辆ID |
| | | * @return 正在进行中的任务列表 |
| | | */ |
| | | @Override |
| | | public List<SysTask> checkVehicleActiveTasks(Long vehicleId) { |
| | | return sysTaskMapper.selectActiveTasksByVehicleId(vehicleId); |
| | | } |
| | | |
| | | /** |
| | | * 检查任务是否已关联旧系统服务单ID |
| | | * |
| | | * @param taskId 任务ID |
| | | * @return true-已关联,false-未关联 |
| | | */ |
| | | @Override |
| | | public boolean hasLegacyServiceOrdId(Long taskId) { |
| | | // 只有急救转运任务才有旧系统ID |
| | | SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | if (task != null && "EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | return emergencyInfo != null && emergencyInfo.getLegacyServiceOrdId() != null; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 检查任务是否已关联旧系统调度单ID |
| | | * |
| | | * @param taskId 任务ID |
| | | * @return true-已关联,false-未关联 |
| | | */ |
| | | @Override |
| | | public boolean hasLegacyDispatchOrdId(Long taskId) { |
| | | // 只有急救转运任务才有旧系统ID |
| | | SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | if (task != null && "EMERGENCY_TRANSFER".equals(task.getTaskType())) { |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | return emergencyInfo != null && emergencyInfo.getLegacyDispatchOrdId() != null; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 根据旧系统服务单ID检查是否存在任务 |
| | | * |
| | | * @param legacyServiceOrdId 旧系统服务单ID |
| | | * @return true-存在,false-不存在 |
| | | */ |
| | | @Override |
| | | public boolean existsByLegacyServiceOrdId(Long legacyServiceOrdId) { |
| | | if (legacyServiceOrdId == null) { |
| | | return false; |
| | | } |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectByLegacyServiceOrdId(legacyServiceOrdId); |
| | | return emergencyInfo != null; |
| | | } |
| | | |
| | | /** |
| | | * 根据旧系统调度单ID检查是否存在任务 |
| | | * |
| | | * @param legacyDispatchOrdId 旧系统调度单ID |
| | | * @return true-存在,false-不存在 |
| | | */ |
| | | @Override |
| | | public boolean existsByLegacyDispatchOrdId(Long legacyDispatchOrdId) { |
| | | if (legacyDispatchOrdId == null) { |
| | | return false; |
| | | } |
| | | SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectByLegacyDispatchOrdId(legacyDispatchOrdId); |
| | | return emergencyInfo != null; |
| | | } |
| | | |
| | | @Autowired |
| | |
| | | * @param taskId 任务ID |
| | | * @param assignees 执行人员信息列表 |
| | | */ |
| | | private void saveTaskAssignees(Long taskId, java.util.List<TaskCreateVO.AssigneeInfo> assignees) { |
| | | private void saveTaskAssignees(Long taskId, java.util.List<TaskCreateVO.AssigneeInfo> assignees,String userName) { |
| | | if (assignees == null || assignees.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | java.util.List<SysTaskAssignee> taskAssignees = new java.util.ArrayList<>(); |
| | | Date now = DateUtils.getNowDate(); |
| | | String currentUser = SecurityUtils.getUsername(); |
| | | String currentUser = userName; |
| | | |
| | | for (int i = 0; i < assignees.size(); i++) { |
| | | TaskCreateVO.AssigneeInfo assigneeInfo = assignees.get(i); |
| | |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建对象 |
| | | */ |
| | | private void saveEmergencyInfo(Long taskId, TaskCreateVO createVO) { |
| | | private void saveEmergencyInfo(Long taskId,String createUserName, TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId) { |
| | | SysTaskEmergency emergencyInfo = new SysTaskEmergency(); |
| | | emergencyInfo.setTaskId(taskId); |
| | | |
| | |
| | | .collect(Collectors.joining(",")); |
| | | emergencyInfo.setDiseaseIds(diseaseIdsStr); |
| | | } |
| | | |
| | | |
| | | if(serviceOrderId!=null){ |
| | | emergencyInfo.setLegacyServiceOrdId(Long.parseLong(serviceOrderId)); |
| | | emergencyInfo.setSyncStatus(2); |
| | | emergencyInfo.setSyncTime(new Date()); |
| | | emergencyInfo.setSyncErrorMsg("旧系统同步过来"); |
| | | } |
| | | if(dispatchOrderId!=null){ |
| | | emergencyInfo.setLegacyDispatchOrdId(Long.parseLong(dispatchOrderId)); |
| | | emergencyInfo.setDispatchSyncStatus(2); |
| | | emergencyInfo.setDispatchSyncTime(new Date()); |
| | | emergencyInfo.setDispatchSyncErrorMsg("旧系统同步过来"); |
| | | |
| | | // 系统字段 |
| | | } |
| | | // 系统字段 |
| | | emergencyInfo.setCreateTime(DateUtils.getNowDate()); |
| | | emergencyInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | emergencyInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | emergencyInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | emergencyInfo.setCreateBy(createUserName); |
| | | emergencyInfo.setUpdateBy(createUserName); |
| | | |
| | | sysTaskEmergencyMapper.insertSysTaskEmergency(emergencyInfo); |
| | | } |
| | | |
| | | /** |
| | | * 更新急救转运任务扩展信息 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param updateVO 任务更新对象 |
| | | */ |
| | | private void updateEmergencyInfo(Long taskId, TaskUpdateVO updateVO) { |
| | | // 查询现有的扩展信息 |
| | | SysTaskEmergency existingInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | if (existingInfo == null) { |
| | | // 如果不存在,则创建新的 |
| | | existingInfo = new SysTaskEmergency(); |
| | | existingInfo.setTaskId(taskId); |
| | | existingInfo.setCreateTime(DateUtils.getNowDate()); |
| | | existingInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | } |
| | | |
| | | TaskUpdateVO.EmergencyInfoVO emergencyInfo = updateVO.getEmergencyInfo(); |
| | | |
| | | // 更新患者信息 |
| | | if (emergencyInfo.getPatientContact() != null) { |
| | | existingInfo.setPatientContact(emergencyInfo.getPatientContact()); |
| | | } |
| | | if (emergencyInfo.getPatientPhone() != null) { |
| | | existingInfo.setPatientPhone(emergencyInfo.getPatientPhone()); |
| | | } |
| | | if (emergencyInfo.getPatientName() != null) { |
| | | existingInfo.setPatientName(emergencyInfo.getPatientName()); |
| | | } |
| | | if (emergencyInfo.getPatientGender() != null) { |
| | | existingInfo.setPatientGender(emergencyInfo.getPatientGender()); |
| | | } |
| | | if (emergencyInfo.getPatientIdCard() != null) { |
| | | existingInfo.setPatientIdCard(emergencyInfo.getPatientIdCard()); |
| | | } |
| | | if (emergencyInfo.getPatientCondition() != null) { |
| | | existingInfo.setPatientCondition(emergencyInfo.getPatientCondition()); |
| | | } |
| | | |
| | | // 更新转出医院信息 |
| | | if (emergencyInfo.getHospitalOutId() != null) { |
| | | existingInfo.setHospitalOutId(emergencyInfo.getHospitalOutId()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutName() != null) { |
| | | existingInfo.setHospitalOutName(emergencyInfo.getHospitalOutName()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutDepartment() != null) { |
| | | existingInfo.setHospitalOutDepartment(emergencyInfo.getHospitalOutDepartment()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutDepartmentId() != null) { |
| | | existingInfo.setHospitalOutDepartmentId(emergencyInfo.getHospitalOutDepartmentId()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutBedNumber() != null) { |
| | | existingInfo.setHospitalOutBedNumber(emergencyInfo.getHospitalOutBedNumber()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutAddress() != null) { |
| | | existingInfo.setHospitalOutAddress(emergencyInfo.getHospitalOutAddress()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutLongitude() != null) { |
| | | existingInfo.setHospitalOutLongitude(emergencyInfo.getHospitalOutLongitude()); |
| | | } |
| | | if (emergencyInfo.getHospitalOutLatitude() != null) { |
| | | existingInfo.setHospitalOutLatitude(emergencyInfo.getHospitalOutLatitude()); |
| | | } |
| | | |
| | | // 更新转入医院信息 |
| | | if (emergencyInfo.getHospitalInId() != null) { |
| | | existingInfo.setHospitalInId(emergencyInfo.getHospitalInId()); |
| | | } |
| | | if (emergencyInfo.getHospitalInName() != null) { |
| | | existingInfo.setHospitalInName(emergencyInfo.getHospitalInName()); |
| | | } |
| | | if (emergencyInfo.getHospitalInDepartment() != null) { |
| | | existingInfo.setHospitalInDepartment(emergencyInfo.getHospitalInDepartment()); |
| | | } |
| | | if (emergencyInfo.getHospitalInDepartmentId() != null) { |
| | | existingInfo.setHospitalInDepartmentId(emergencyInfo.getHospitalInDepartmentId()); |
| | | } |
| | | if (emergencyInfo.getHospitalInBedNumber() != null) { |
| | | existingInfo.setHospitalInBedNumber(emergencyInfo.getHospitalInBedNumber()); |
| | | } |
| | | if (emergencyInfo.getHospitalInAddress() != null) { |
| | | existingInfo.setHospitalInAddress(emergencyInfo.getHospitalInAddress()); |
| | | } |
| | | if (emergencyInfo.getHospitalInLongitude() != null) { |
| | | existingInfo.setHospitalInLongitude(emergencyInfo.getHospitalInLongitude()); |
| | | } |
| | | if (emergencyInfo.getHospitalInLatitude() != null) { |
| | | existingInfo.setHospitalInLatitude(emergencyInfo.getHospitalInLatitude()); |
| | | } |
| | | |
| | | // 更新费用信息 |
| | | if (emergencyInfo.getTransferDistance() != null) { |
| | | existingInfo.setTransferDistance(emergencyInfo.getTransferDistance()); |
| | | } |
| | | if (emergencyInfo.getTransferPrice() != null) { |
| | | existingInfo.setTransferPrice(emergencyInfo.getTransferPrice()); |
| | | } |
| | | |
| | | // 更新病情ID列表 |
| | | if (updateVO.getDiseaseIds() != null && !updateVO.getDiseaseIds().isEmpty()) { |
| | | String diseaseIdsStr = updateVO.getDiseaseIds().stream() |
| | | .map(String::valueOf) |
| | | .collect(Collectors.joining(",")); |
| | | existingInfo.setDiseaseIds(diseaseIdsStr); |
| | | } else { |
| | | // 如果病情ID列表为空,清空该字段 |
| | | existingInfo.setDiseaseIds(null); |
| | | } |
| | | |
| | | // 系统字段 |
| | | existingInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | existingInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | |
| | | // 执行更新 |
| | | sysTaskEmergencyMapper.updateSysTaskEmergency(existingInfo); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建对象 |
| | | */ |
| | | private void saveWelfareInfo(Long taskId, TaskCreateVO createVO) { |
| | | private void saveWelfareInfo(Long taskId,String userName, TaskCreateVO createVO) { |
| | | SysTaskWelfare welfareInfo = new SysTaskWelfare(); |
| | | welfareInfo.setTaskId(taskId); |
| | | |
| | |
| | | // 系统字段 |
| | | welfareInfo.setCreateTime(DateUtils.getNowDate()); |
| | | welfareInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | welfareInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | welfareInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | welfareInfo.setCreateBy(userName); |
| | | welfareInfo.setUpdateBy(userName); |
| | | |
| | | sysTaskWelfareMapper.insertSysTaskWelfare(welfareInfo); |
| | | } |
| | |
| | | default: return "其他"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 构建附件的完整URL |
| | | * |
| | | * @param attachment 附件对象 |
| | | */ |
| | | private void buildAttachmentUrl(SysTaskAttachment attachment) { |
| | | if (attachment != null && StringUtils.isNotEmpty(attachment.getFilePath())) { |
| | | String imageUrl = imageUrlConfig.getImageUrl(); |
| | | if (StringUtils.isNotEmpty(imageUrl)) { |
| | | // 拼接完整URL:域名 + 相对路径 |
| | | attachment.setFileUrl(imageUrl + attachment.getFilePath()); |
| | | } else { |
| | | // 如果未配置域名,直接使用相对路径 |
| | | attachment.setFileUrl(attachment.getFilePath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |