!93 czh-20260725-getDistinctHandlerNames同时返回工号+姓名
* czh-20260725-getDistinctHandlerNames同时返回工号+姓名 * czh-20260725-移除linkOpenMode和dataFormat默认值 * czh-20260725-移除接收人上限限制 * czh-20260725-IM模块code-review补充修复 * czh-20260725-code-review问题修复
This commit is contained in:
+4
-3
@@ -58,12 +58,13 @@ public class KsimApiClient {
|
||||
HttpHeaders headers = jsonHeaders();
|
||||
headers.add("imOpenApiToken", token);
|
||||
|
||||
String bodyJson = JSON.toJSONString(dto);
|
||||
// 直接 POJO→JSONObject,避免 DTO→String→JSONObject 三重序列化
|
||||
JSONObject body = (JSONObject) JSON.toJSON(dto);
|
||||
String url = ksimProperties.getHost() + "/api-open/v1/msg/sendBatch";
|
||||
log.info("【即时通推送-消息发送】请求体: {}", bodyJson);
|
||||
log.debug("【即时通推送-消息发送】请求体: {}", body.toJSONString());
|
||||
|
||||
ResponseEntity<JSONObject> resp = RestUtil.request(url, HttpMethod.POST, headers, null,
|
||||
JSON.parseObject(bodyJson), JSONObject.class);
|
||||
body, JSONObject.class);
|
||||
|
||||
JSONObject respBody = resp.getBody();
|
||||
int code = respBody != null ? respBody.getIntValue("code") : -1;
|
||||
|
||||
+7
-24
@@ -19,7 +19,6 @@ import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -28,8 +27,6 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("/ksim/test")
|
||||
public class KsimTestController {
|
||||
|
||||
private static final Set<String> ALLOWED_LINK_OPEN_MODES = Set.of("Exe", "Web", "None");
|
||||
|
||||
@PostMapping("/sendBatch")
|
||||
public Result<Map<String, Object>> sendBatch(@RequestBody Map<String, Object> params) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
@@ -47,8 +44,8 @@ public class KsimTestController {
|
||||
String content = (String) params.getOrDefault("content", "");
|
||||
String linkUrl = (String) params.getOrDefault("linkUrl", "");
|
||||
String linkTitle = (String) params.getOrDefault("linkTitle", "");
|
||||
String linkOpenMode = (String) params.getOrDefault("linkOpenMode", "Exe");
|
||||
String dataFormat = (String) params.getOrDefault("dataFormat", "JsonListView");
|
||||
String linkOpenMode = (String) params.getOrDefault("linkOpenMode", "");
|
||||
String dataFormat = (String) params.getOrDefault("dataFormat", "");
|
||||
String data = (String) params.getOrDefault("data", "");
|
||||
|
||||
// --- Step 1: 创建 Token ---
|
||||
@@ -82,25 +79,11 @@ public class KsimTestController {
|
||||
dto.setToUserValueList(toUserValueList);
|
||||
dto.setTitle(title);
|
||||
dto.setContent(content);
|
||||
// 可选字段:传了才设置,不传则不发给 ksim
|
||||
if (data != null && !data.isEmpty()) {
|
||||
dto.setData(data);
|
||||
}
|
||||
if (linkOpenMode != null && !linkOpenMode.isEmpty()) {
|
||||
if (!ALLOWED_LINK_OPEN_MODES.contains(linkOpenMode)) {
|
||||
log.warn("【即时通测试-sendBatch】非法的 linkOpenMode: {}, 已跳过", linkOpenMode);
|
||||
} else {
|
||||
dto.setLinkOpenMode(linkOpenMode);
|
||||
}
|
||||
}
|
||||
if (dataFormat != null && !dataFormat.isEmpty()) {
|
||||
dto.setDataFormat(dataFormat);
|
||||
}
|
||||
if (linkTitle != null && !linkTitle.isEmpty()) {
|
||||
dto.setLinkTitle(linkTitle);
|
||||
}
|
||||
if (linkUrl != null && !linkUrl.isEmpty()) {
|
||||
dto.setLinkUrl(linkUrl);
|
||||
// 可选字段统一通过 setOptionalFields 设置
|
||||
try {
|
||||
dto.setOptionalFields(data, linkOpenMode, dataFormat, linkTitle, linkUrl);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("【即时通测试-sendBatch】可选字段校验失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
String msgUrl = host + "/api-open/v1/msg/sendBatch";
|
||||
|
||||
+30
@@ -1,12 +1,15 @@
|
||||
package org.jeecg.modules.ksim.dto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 对应即时通文档 3.4.3 ReqMsgSendDTO
|
||||
*/
|
||||
public class KsimMsgSendDTO {
|
||||
|
||||
public static final Set<String> ALLOWED_LINK_OPEN_MODES = Set.of("Exe", "Web", "None");
|
||||
|
||||
private String title;
|
||||
private String content;
|
||||
private String toUserKeyType;
|
||||
@@ -17,6 +20,33 @@ public class KsimMsgSendDTO {
|
||||
private String linkTitle;
|
||||
private String linkUrl;
|
||||
|
||||
/**
|
||||
* 设置可选字段。仅当值非空时才设置,避免向 ksim 发送 null 字段。
|
||||
* linkOpenMode 会校验白名单。
|
||||
*/
|
||||
public void setOptionalFields(String data, String linkOpenMode, String dataFormat,
|
||||
String linkTitle, String linkUrl) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
this.data = data;
|
||||
}
|
||||
if (linkOpenMode != null && !linkOpenMode.isEmpty()) {
|
||||
if (!ALLOWED_LINK_OPEN_MODES.contains(linkOpenMode)) {
|
||||
throw new IllegalArgumentException("非法的 linkOpenMode: " + linkOpenMode
|
||||
+ ",允许的值: " + ALLOWED_LINK_OPEN_MODES);
|
||||
}
|
||||
this.linkOpenMode = linkOpenMode;
|
||||
}
|
||||
if (dataFormat != null && !dataFormat.isEmpty()) {
|
||||
this.dataFormat = dataFormat;
|
||||
}
|
||||
if (linkTitle != null && !linkTitle.isEmpty()) {
|
||||
this.linkTitle = linkTitle;
|
||||
}
|
||||
if (linkUrl != null && !linkUrl.isEmpty()) {
|
||||
this.linkUrl = linkUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() { return title; }
|
||||
public void setTitle(String title) { this.title = title; }
|
||||
public String getContent() { return content; }
|
||||
|
||||
+16
-22
@@ -3,6 +3,7 @@ package org.jeecg.modules.ksim.service.impl;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.ksim.client.KsimApiClient;
|
||||
import org.jeecg.modules.ksim.dto.KsimApiResult;
|
||||
import org.jeecg.modules.ksim.dto.KsimMsgSendDTO;
|
||||
@@ -12,14 +13,11 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class KsimMessageServiceImpl implements IKsimMessageService {
|
||||
|
||||
private static final Set<String> ALLOWED_LINK_OPEN_MODES = Set.of("Exe", "Web", "None");
|
||||
|
||||
@Resource
|
||||
private KsimTokenManager tokenManager;
|
||||
|
||||
@@ -31,6 +29,16 @@ public class KsimMessageServiceImpl implements IKsimMessageService {
|
||||
String title, String content,
|
||||
String linkUrl, String linkTitle,
|
||||
String data, String linkOpenMode, String dataFormat) {
|
||||
if (toUserValueList == null || toUserValueList.isEmpty()) {
|
||||
log.warn("【即时通推送-sendBatch】toUserValueList为空,跳过发送");
|
||||
return Result.error("接收人列表为空");
|
||||
}
|
||||
if (oConvertUtils.isEmpty(title)) {
|
||||
log.warn("【即时通推送-sendBatch】title为空");
|
||||
}
|
||||
if (oConvertUtils.isEmpty(content)) {
|
||||
log.warn("【即时通推送-sendBatch】content为空");
|
||||
}
|
||||
String token = tokenManager.getToken();
|
||||
|
||||
KsimMsgSendDTO dto = new KsimMsgSendDTO();
|
||||
@@ -38,25 +46,11 @@ public class KsimMessageServiceImpl implements IKsimMessageService {
|
||||
dto.setToUserValueList(toUserValueList);
|
||||
dto.setTitle(title);
|
||||
dto.setContent(content);
|
||||
// 以下可选字段:传了才设置,不传则不发给 ksim
|
||||
if (data != null && !data.isEmpty()) {
|
||||
dto.setData(data);
|
||||
}
|
||||
if (linkOpenMode != null && !linkOpenMode.isEmpty()) {
|
||||
if (!ALLOWED_LINK_OPEN_MODES.contains(linkOpenMode)) {
|
||||
log.warn("【即时通推送-sendBatch】非法的 linkOpenMode: {}, 已跳过", linkOpenMode);
|
||||
} else {
|
||||
dto.setLinkOpenMode(linkOpenMode);
|
||||
}
|
||||
}
|
||||
if (dataFormat != null && !dataFormat.isEmpty()) {
|
||||
dto.setDataFormat(dataFormat);
|
||||
}
|
||||
if (linkTitle != null && !linkTitle.isEmpty()) {
|
||||
dto.setLinkTitle(linkTitle);
|
||||
}
|
||||
if (linkUrl != null && !linkUrl.isEmpty()) {
|
||||
dto.setLinkUrl(linkUrl);
|
||||
// 可选字段统一通过 setOptionalFields 设置,避免与测试控制器重复
|
||||
try {
|
||||
dto.setOptionalFields(data, linkOpenMode, dataFormat, linkTitle, linkUrl);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("【即时通推送-sendBatch】可选字段校验失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
KsimApiResult<JSONObject> apiResult = apiClient.sendMsg(token, dto);
|
||||
|
||||
Reference in New Issue
Block a user