| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | |
| | | 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 uploadAttachment(Long taskId, MultipartFile file, String category) { |
| | | public Long uploadAttachment(Long taskId, MultipartFile file, String category) { |
| | | try { |
| | | // 上传文件 |
| | | // 上传文件,返回相对路径(如:/task/2025/01/15/xxx.jpg) |
| | | String fileName = FileUploadUtils.upload("/task", file); |
| | | String filePath = FileUploadUtils.getDefaultBaseDir() + fileName; |
| | | |
| | | 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; |
| | |
| | | * @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( |
| | |
| | | fos.write(fileBytes); |
| | | } |
| | | |
| | | // 生成相对路径(不包含baseDir) |
| | | String relativeFilePath = "/task/" + datePath + "/" + fileName; |
| | | |
| | | // 保存附件记录 |
| | | 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()); |
| | | } |
| | |
| | | */ |
| | | @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)); |
| | | // 加载急救转运扩展信息 |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |