Skip to content

Commit

Permalink
[Bug][Alert] fix wechat'app mode send msg problems (DataLinkDC#3487)
Browse files Browse the repository at this point in the history
Co-authored-by: Zzm0809 <934230207@qq.com>
  • Loading branch information
15673602562 and Zzm0809 authored May 15, 2024
1 parent 10fdbde commit 3c52ead
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hutool.core.text.StrFormatter;
import cn.hutool.json.JSONUtil;

/**
Expand All @@ -60,7 +58,8 @@ public class WeChatSender {
WeChatSender(Map<String, Object> config) {
this.wechatParams = JSONUtil.toBean(JSONUtil.toJsonStr(config), WechatParams.class);
if (wechatParams.isAtAll()) {
wechatParams.getAtUsers().add("all");
wechatParams.getAtUsers().clear();
wechatParams.getAtUsers().add("@all");
}
if (wechatParams.getSendType().equals(WeChatType.CHAT.getValue())) {
requireNonNull(wechatParams.getWebhook(), WeChatConstants.WEB_HOOK + " must not null");
Expand All @@ -86,11 +85,10 @@ public Map<String, Object> buildTemplateParams(String title, String content) {
if (wechatParams.getSendType().equals(WeChatType.APP.getValue())) {
params.put(WeChatConstants.ALERT_TEMPLATE_AGENT_ID, wechatParams.getAgentId());
}
List<String> atUsers = wechatParams.getAtUsers().isEmpty()
? new ArrayList<>()
: wechatParams.getAtUsers().stream()
.map(u -> StrFormatter.format("<@{}>", u))
.collect(Collectors.toList());
List<String> atUsers = new ArrayList<>();
if (!wechatParams.getAtUsers().isEmpty()) {
atUsers.addAll(wechatParams.getAtUsers());
}
params.put(WeChatConstants.ALERT_TEMPLATE_AT_USERS, atUsers);
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class FreeMarkerHolder {
*/
public FreeMarkerHolder() {
configuration.setTemplateLoader(stringLoader);
configuration.setNumberFormat("computer");
configuration.setDefaultEncoding("UTF-8");
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
Expand Down
2 changes: 1 addition & 1 deletion dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export default {
'rc.ai.accessKeySecretPleaseHolder': 'Please enter AccessKeySecret',
'rc.ai.action': 'Interface method',
'rc.ai.actionPleaseHolder': 'Please enter the interface method',
'rc.ai.agentId': 'AgentId',
'rc.ai.agentId': 'App ID(AgentId)',
'rc.ai.agentIdPleaseHolder': 'Please enter AgentId',
'rc.ai.sendUrl': 'QiWei Send Addr',
'rc.ai.sendUrlPleaseHolder': 'Please enter the sending address or the proxy address',
Expand Down
2 changes: 1 addition & 1 deletion dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export default {
'rc.ai.accessKeySecretPleaseHolder': '请输入AccessKeySecret',
'rc.ai.action': '接口方法',
'rc.ai.actionPleaseHolder': '请输入接口方法',
'rc.ai.agentId': '代理ID',
'rc.ai.agentId': '应用ID(AgentId)',
'rc.ai.agentIdPleaseHolder': '请输入 AgentId',
'rc.ai.sendUrl': '企微发送地址',
'rc.ai.sendUrlPleaseHolder': '请输入发送地址可输入代理地址',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { FormSingleColumnList } from '@/components/FormSingleColumnList';
import { SWITCH_OPTIONS } from '@/services/constants';
import { Alert } from '@/types/RegCenter/data';
import { Alert } from '@/types/RegCenter/data.d';
import { l } from '@/utils/intl';
import {
ProForm,
Expand Down
5 changes: 5 additions & 0 deletions dinky-web/src/types/RegCenter/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ declare namespace Alert {
note: string;
};

export enum AlertInstanceOfWechatSubType {
WECHAT= 'wechat',
APP= 'app'
}

/**
* alert instance params sub type
*/
Expand Down

0 comments on commit 3c52ead

Please sign in to comment.