From 2aebbc9601ab439707f69b08e467808df9f7549c Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期五, 07 十一月 2025 11:50:26 +0800
Subject: [PATCH] feat: weixin
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 229 insertions(+), 8 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
index 499b06f..56a2244 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
@@ -6,7 +6,11 @@
import java.util.ArrayList;
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.system.utils.TaskCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,7 +46,11 @@
import com.ruoyi.system.domain.VehicleInfo;
import com.ruoyi.system.service.ISysTaskService;
import com.ruoyi.system.service.ILegacySystemSyncService;
+import com.ruoyi.system.event.TaskCreatedEvent;
+import com.ruoyi.system.event.TaskAssignedEvent;
+import com.ruoyi.system.event.TaskStatusChangedEvent;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
/**
* 浠诲姟绠$悊Service涓氬姟灞傚鐞�
@@ -79,6 +87,9 @@
@Autowired(required = false)
private ILegacySystemSyncService legacySystemSyncService;
+
+ @Autowired
+ private ApplicationEventPublisher eventPublisher;
/**
* 鏌ヨ浠诲姟绠$悊
@@ -229,6 +240,38 @@
"浠诲姟绫诲瀷锛�" + createVO.getTaskType(), SecurityUtils.getUserId(), SecurityUtils.getUsername());
}
+ // 鍙戝竷浠诲姟鍒涘缓浜嬩欢
+ if (result > 0) {
+ eventPublisher.publishEvent(new TaskCreatedEvent(
+ this,
+ task.getTaskId(),
+ task.getTaskCode(),
+ task.getTaskType(),
+ task.getCreatorId(),
+ SecurityUtils.getUsername()
+ ));
+ }
+
+ // 鍙戝竷浠诲姟鍒嗛厤浜嬩欢
+ 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,
+ SecurityUtils.getUserId(),
+ SecurityUtils.getUsername()
+ ));
+ }
+
// 寮傛鍚屾鎬ユ晳杞繍浠诲姟鍒版棫绯荤粺
if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType()) && legacySystemSyncService != null) {
final Long finalTaskId = task.getTaskId();
@@ -320,19 +363,40 @@
@Override
@Transactional
public int assignTask(Long taskId, Long assigneeId, String remark) {
- SysTask task = new SysTask();
- task.setTaskId(taskId);
- task.setAssigneeId(assigneeId);
- task.setUpdateBy(SecurityUtils.getUsername());
- task.setUpdateTime(DateUtils.getNowDate());
+ SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId);
+ if (task == null) {
+ throw new RuntimeException("浠诲姟涓嶅瓨鍦�");
+ }
- int result = sysTaskMapper.assignTask(task);
+ SysTask updateTask = new SysTask();
+ updateTask.setTaskId(taskId);
+ updateTask.setAssigneeId(assigneeId);
+ updateTask.setUpdateBy(SecurityUtils.getUsername());
+ updateTask.setUpdateTime(DateUtils.getNowDate());
+
+ int result = sysTaskMapper.assignTask(updateTask);
// 璁板綍鎿嶄綔鏃ュ織
if (result > 0) {
recordTaskLog(taskId, "ASSIGN", "鍒嗛厤浠诲姟", null,
"鍒嗛厤缁欑敤鎴稩D锛�" + assigneeId + "锛屽娉細" + remark,
SecurityUtils.getUserId(), SecurityUtils.getUsername());
+ }
+
+ // 鍙戝竷浠诲姟鍒嗛厤浜嬩欢
+ if (result > 0) {
+ List<Long> assigneeIds = new ArrayList<>();
+ assigneeIds.add(assigneeId);
+
+ eventPublisher.publishEvent(new TaskAssignedEvent(
+ this,
+ task.getTaskId(),
+ task.getTaskCode(),
+ assigneeIds,
+ null, // 濮撳悕鍒楄〃鍦ㄧ洃鍚櫒涓煡璇�
+ SecurityUtils.getUserId(),
+ SecurityUtils.getUsername()
+ ));
}
return result;
@@ -404,6 +468,30 @@
locationLog);
}
+ // 鍙戝竷浠诲姟鐘舵�佸彉鏇翠簨浠�
+ if (result > 0) {
+ // 鏌ヨ浠诲姟鐨勬墍鏈夋墽琛屼汉
+ List<SysTaskAssignee> assignees = sysTaskAssigneeMapper.selectSysTaskAssigneeByTaskId(taskId);
+ List<Long> assigneeIds = null;
+ if (assignees != null && !assignees.isEmpty()) {
+ assigneeIds = assignees.stream()
+ .map(SysTaskAssignee::getUserId)
+ .collect(Collectors.toList());
+ }
+
+ eventPublisher.publishEvent(new TaskStatusChangedEvent(
+ this,
+ oldTask.getTaskId(),
+ oldTask.getTaskCode(),
+ oldTaskStatus.getCode(),
+ newStatus.getCode(),
+ oldTaskStatus.getInfo(),
+ newStatus.getInfo(),
+ assigneeIds,
+ oldTask.getCreatorId()
+ ));
+ }
+
return result;
}
@@ -412,11 +500,12 @@
*
* @param taskId 浠诲姟ID
* @param file 鏂囦欢
+ * @param category 闄勪欢鍒嗙被
* @return 缁撴灉
*/
@Override
@Transactional
- public int uploadAttachment(Long taskId, MultipartFile file) {
+ public int uploadAttachment(Long taskId, MultipartFile file, String category) {
try {
// 涓婁紶鏂囦欢
String fileName = FileUploadUtils.upload("/task", file);
@@ -428,6 +517,7 @@
attachment.setFilePath(filePath);
attachment.setFileSize(file.getSize());
attachment.setFileType(getFileType(file.getOriginalFilename()));
+ attachment.setAttachmentCategory(category);
attachment.setUploadTime(DateUtils.getNowDate());
attachment.setUploadBy(SecurityUtils.getUsername());
@@ -435,14 +525,112 @@
// 璁板綍鎿嶄綔鏃ュ織
if (result > 0) {
+ String categoryDesc = getCategoryDesc(category);
recordTaskLog(taskId, "UPDATE", "涓婁紶闄勪欢", null,
- "涓婁紶鏂囦欢锛�" + file.getOriginalFilename(),
+ "涓婁紶鏂囦欢锛�" + file.getOriginalFilename() + "(鍒嗙被锛�" + categoryDesc + ")",
SecurityUtils.getUserId(), SecurityUtils.getUsername());
}
return result;
} catch (IOException e) {
throw new RuntimeException("鏂囦欢涓婁紶澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 浠庡井淇ediaId涓婁紶浠诲姟闄勪欢
+ *
+ * @param taskId 浠诲姟ID
+ * @param accessToken 寰俊AccessToken
+ * @param mediaId 寰俊mediaId
+ * @param category 闄勪欢鍒嗙被
+ * @return 缁撴灉
+ */
+ @Override
+ @Transactional
+ public int uploadAttachmentFromWechat(Long taskId, String accessToken, String mediaId, String category) {
+ try {
+ // 浠庡井淇℃湇鍔″櫒涓嬭浇鏂囦欢
+ String wechatUrl = String.format(
+ "https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s",
+ accessToken, mediaId
+ );
+
+ byte[] fileBytes = downloadFromUrl(wechatUrl);
+ if (fileBytes == null || fileBytes.length == 0) {
+ throw new RuntimeException("浠庡井淇′笅杞芥枃浠跺け璐�");
+ }
+
+ // 鐢熸垚鏂囦欢鍚嶏紙浣跨敤mediaId浣滀负鏂囦欢鍚嶇殑涓�閮ㄥ垎锛�
+ 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);
+ }
+
+ // 淇濆瓨闄勪欢璁板綍
+ SysTaskAttachment attachment = new SysTaskAttachment();
+ attachment.setTaskId(taskId);
+ attachment.setFileName(fileName);
+ attachment.setFilePath(filePath);
+ attachment.setFileSize((long) fileBytes.length);
+ attachment.setFileType("jpg");
+ attachment.setAttachmentCategory(category);
+ attachment.setUploadTime(DateUtils.getNowDate());
+ attachment.setUploadBy(SecurityUtils.getUsername());
+
+ int result = sysTaskAttachmentMapper.insertSysTaskAttachment(attachment);
+
+ // 璁板綍鎿嶄綔鏃ュ織
+ if (result > 0) {
+ String categoryDesc = getCategoryDesc(category);
+ recordTaskLog(taskId, "UPDATE", "涓婁紶闄勪欢", null,
+ "閫氳繃寰俊涓婁紶鏂囦欢锛�" + fileName + "(鍒嗙被锛�" + categoryDesc + ")",
+ SecurityUtils.getUserId(), SecurityUtils.getUsername());
+ }
+
+ return result;
+ } catch (Exception e) {
+ throw new RuntimeException("浠庡井淇′笂浼犳枃浠跺け璐ワ細" + e.getMessage());
+ }
+ }
+
+ /**
+ * 浠� URL 涓嬭浇鏂囦欢
+ */
+ private byte[] downloadFromUrl(String fileUrl) throws IOException {
+ URL url = new URL(fileUrl);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setConnectTimeout(10000);
+ connection.setReadTimeout(30000);
+
+ try (InputStream inputStream = connection.getInputStream()) {
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
+
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+
+ return outputStream.toByteArray();
+ } finally {
+ connection.disconnect();
}
}
@@ -477,6 +665,17 @@
}
return result;
+ }
+
+ /**
+ * 鏍规嵁ID鑾峰彇闄勪欢璇︽儏
+ *
+ * @param attachmentId 闄勪欢ID
+ * @return 闄勪欢璇︽儏
+ */
+ @Override
+ public SysTaskAttachment getAttachmentById(Long attachmentId) {
+ return sysTaskAttachmentMapper.selectSysTaskAttachmentByAttachmentId(attachmentId);
}
/**
@@ -610,6 +809,7 @@
VehicleInfo queryParam = new VehicleInfo();
queryParam.setStatus("0"); // 0琛ㄧず姝e父鐘舵��
// 涓嶈缃甦eptId锛屾煡璇㈡墍鏈夐儴闂ㄧ殑杞﹁締
+ queryParam.setDeptId(deptId);
List<VehicleInfo> vehicles = vehicleInfoMapper.selectVehicleInfoList(queryParam);
@@ -970,4 +1170,25 @@
sysTaskWelfareMapper.insertSysTaskWelfare(welfareInfo);
}
+
+ /**
+ * 鑾峰彇闄勪欢鍒嗙被鎻忚堪
+ *
+ * @param category 闄勪欢鍒嗙被浠g爜
+ * @return 鍒嗙被鎻忚堪
+ */
+ private String getCategoryDesc(String category) {
+ if (category == null || category.isEmpty()) {
+ return "鏈垎绫�";
+ }
+ switch (category) {
+ case "1": return "鐭ユ儏鍚屾剰涔�";
+ case "2": return "鐥呬汉璧勬枡";
+ case "3": return "鎿嶄綔璁板綍";
+ case "4": return "鍑鸿溅鍓�";
+ case "5": return "鍑鸿溅鍚�";
+ case "6": return "绯诲畨鍏ㄥ甫";
+ default: return "鍏朵粬";
+ }
+ }
}
--
Gitblit v1.9.1