|
@@ -3,11 +3,11 @@ package com.flow.job;
|
|
import com.flow.entity.Notify;
|
|
import com.flow.entity.Notify;
|
|
import com.flow.entity.User;
|
|
import com.flow.entity.User;
|
|
import com.flow.mapstruct.NotifyRowMapper;
|
|
import com.flow.mapstruct.NotifyRowMapper;
|
|
-import com.flow.mapstruct.UserRowMapper;
|
|
|
|
import dm.jdbc.filter.stat.json.JSONObject;
|
|
import dm.jdbc.filter.stat.json.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -16,6 +16,7 @@ import org.springframework.web.client.RestTemplate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
@@ -34,7 +35,6 @@ import java.util.stream.Collectors;
|
|
public class SendUskyJob {
|
|
public class SendUskyJob {
|
|
|
|
|
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
- // private static final String USKY_URL = "https://gateway.usky.cn/prod-api/system/mceReceive/addMceNew";
|
|
|
|
private static final String USKY_URL = "http://172.16.66.143:9886/mceReceive/addMceNew";
|
|
private static final String USKY_URL = "http://172.16.66.143:9886/mceReceive/addMceNew";
|
|
private static final String USKY_TEST_URL = "http://192.168.10.165:13200/offline-api/system/mceReceive/addMceNew";
|
|
private static final String USKY_TEST_URL = "http://192.168.10.165:13200/offline-api/system/mceReceive/addMceNew";
|
|
|
|
|
|
@@ -44,6 +44,9 @@ public class SendUskyJob {
|
|
@Autowired
|
|
@Autowired
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
|
+
|
|
// 每30秒执行一次
|
|
// 每30秒执行一次
|
|
@Scheduled(fixedRate = 30000)
|
|
@Scheduled(fixedRate = 30000)
|
|
public void executeTask() {
|
|
public void executeTask() {
|
|
@@ -71,19 +74,40 @@ public class SendUskyJob {
|
|
public void sendUsky(List<Notify> unSend) {
|
|
public void sendUsky(List<Notify> unSend) {
|
|
int successCount = 0;
|
|
int successCount = 0;
|
|
int failCount = 0;
|
|
int failCount = 0;
|
|
|
|
+
|
|
|
|
+ // 构建消息发送请求体
|
|
|
|
+ JSONObject sendJson = new JSONObject();
|
|
|
|
+
|
|
for (Notify send : unSend) {
|
|
for (Notify send : unSend) {
|
|
String subject = send.getSubject();
|
|
String subject = send.getSubject();
|
|
String approvalResult = "";
|
|
String approvalResult = "";
|
|
|
|
+ Object approvalNode = send.getParams().get("approvalNode");
|
|
switch (subject) {
|
|
switch (subject) {
|
|
case "申请已通过":
|
|
case "申请已通过":
|
|
approvalResult = "审批通过";
|
|
approvalResult = "审批通过";
|
|
|
|
+ if (approvalNode != null) {
|
|
|
|
+ sendJson.put("approvalNode", approvalNode);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case "新的审批任务":
|
|
case "新的审批任务":
|
|
|
|
+ approvalResult = "审批中";
|
|
|
|
+ if (approvalNode != null) {
|
|
|
|
+ sendJson.put("approvalNode", approvalNode);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
case "催办":
|
|
case "催办":
|
|
approvalResult = "审批中";
|
|
approvalResult = "审批中";
|
|
|
|
+ sendJson.put("approvalNode", extractContentInBrackets(send.getContent()));
|
|
break;
|
|
break;
|
|
case "申请拒绝":
|
|
case "申请拒绝":
|
|
approvalResult = "审批驳回";
|
|
approvalResult = "审批驳回";
|
|
|
|
+ if (approvalNode != null) {
|
|
|
|
+ sendJson.put("approvalNode", approvalNode);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "审批提醒":
|
|
|
|
+ approvalResult = "审批超时";
|
|
|
|
+ sendJson.put("approvalNode", extractContentInBrackets(send.getContent()));
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,18 +121,16 @@ public class SendUskyJob {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- JSONObject sendJson = new JSONObject()
|
|
|
|
- .put("infoTypeName", "OA审批")
|
|
|
|
- .put("infoType", 3)
|
|
|
|
- .put("infoTitle", "OA审批")
|
|
|
|
- .put("infoContent", userNamesMap.get(send.getSender()) + send.getSubject())
|
|
|
|
- .put("userName", send.getSender())
|
|
|
|
- .put("userNames", Collections.singletonList(send.getReceiver()))
|
|
|
|
- .put("id", send.getId())
|
|
|
|
- .put("approvalResult", approvalResult)
|
|
|
|
- .put("processName", send.getSubject())
|
|
|
|
- .put("approvalNode", extractContentInBrackets(send.getContent()))
|
|
|
|
- .put("realName", userNamesMap.get(send.getSender()));
|
|
|
|
|
|
+ sendJson.put("infoTypeName", "OA审批");
|
|
|
|
+ sendJson.put("infoType", 3);
|
|
|
|
+ sendJson.put("infoTitle", "OA审批");
|
|
|
|
+ sendJson.put("infoContent", userNamesMap.get(send.getSender()) + send.getSubject());
|
|
|
|
+ sendJson.put("userName", send.getSender());
|
|
|
|
+ sendJson.put("userNames", Collections.singletonList(send.getReceiver()));
|
|
|
|
+ sendJson.put("id", send.getId());
|
|
|
|
+ sendJson.put("approvalResult", approvalResult);
|
|
|
|
+ sendJson.put("processName", send.getContent());
|
|
|
|
+ sendJson.put("realName", userNamesMap.get(send.getSender()));
|
|
|
|
|
|
String sendJsonString = sendJson.toString();
|
|
String sendJsonString = sendJson.toString();
|
|
log.info("准备发送 {} 的消息:{} ", send.getSender(), sendJsonString);
|
|
log.info("准备发送 {} 的消息:{} ", send.getSender(), sendJsonString);
|
|
@@ -138,21 +160,23 @@ public class SendUskyJob {
|
|
|
|
|
|
// 查询未发送消息的用户名与真实姓名
|
|
// 查询未发送消息的用户名与真实姓名
|
|
public List<User> unSendUser(List<String> userNames) {
|
|
public List<User> unSendUser(List<String> userNames) {
|
|
|
|
+ if (userNames == null || userNames.isEmpty()) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
|
|
- System.out.println(userNames);
|
|
|
|
-
|
|
|
|
- // 构建IN子句的参数占位符
|
|
|
|
- String inClause = userNames.stream()
|
|
|
|
- .map(name -> "?")
|
|
|
|
- .collect(Collectors.joining(", "));
|
|
|
|
|
|
+ // 构建IN子句的参数
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("userNames", userNames);
|
|
|
|
|
|
- System.out.println(inClause);
|
|
|
|
|
|
+ String sql = "SELECT username, name FROM sys_user WHERE username IN (:userNames)";
|
|
|
|
|
|
- String sql = "SELECT username, name FROM sys_user WHERE username IN (" + inClause + ")";
|
|
|
|
- return jdbcTemplate.query(
|
|
|
|
|
|
+ return namedParameterJdbcTemplate.query(
|
|
sql,
|
|
sql,
|
|
- userNames.toArray(new Object[0]),
|
|
|
|
- new UserRowMapper()
|
|
|
|
|
|
+ params,
|
|
|
|
+ (rs, rowNum) -> new User(
|
|
|
|
+ rs.getString("username"),
|
|
|
|
+ rs.getString("name")
|
|
|
|
+ )
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|