feat: 优化钉钉测试消息,支持多种消息类型预览
This commit is contained in:
parent
1c560a8508
commit
43d13d1a95
@ -141,9 +141,114 @@ public class DingTalkController {
|
||||
@Operation(summary = "发送测试消息")
|
||||
@PostMapping("/test-message")
|
||||
public Result<Boolean> sendTestMessage(@RequestBody Map<String, String> params) {
|
||||
String title = params.getOrDefault("title", "测试消息");
|
||||
String content = params.getOrDefault("content", "这是一条来自DesignHub的测试消息");
|
||||
return Result.success(dingTalkService.sendRobotMessage(title, content));
|
||||
String messageType = params.getOrDefault("type", "simple");
|
||||
String title;
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
switch (messageType) {
|
||||
case "task_publish":
|
||||
// 新任务发布样式
|
||||
title = "新任务发布(测试)";
|
||||
content.append("-------------------------------- \n");
|
||||
content.append(" 【 新 任 务 发 布 】 \n");
|
||||
content.append("-------------------------------- \n\n");
|
||||
content.append("任务名称:示例任务标题 \n");
|
||||
content.append("任务编号:TSK20260104001 \n");
|
||||
content.append("任务积分:100 分 \n");
|
||||
content.append("任务数量:5 个 \n");
|
||||
content.append("任务需求类型:3D模型 \n");
|
||||
content.append("品牌:示例品牌 \n");
|
||||
content.append("类目:示例类目 \n");
|
||||
content.append("平台:天猫 \n");
|
||||
content.append("SPU信息:SPU12345 \n");
|
||||
content.append("预估工时:8 小时(接单后开始计时) \n");
|
||||
content.append(" \n");
|
||||
content.append("发起人:张三 \n");
|
||||
content.append("发起部门:市场部 \n");
|
||||
content.append(" \n");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append("前往抢单:qd.yydd.ai \n");
|
||||
content.append("--------------------------------");
|
||||
break;
|
||||
|
||||
case "task_assign":
|
||||
// 任务指派样式
|
||||
title = "任务已指派(测试)";
|
||||
content.append("-------------------------------- \n");
|
||||
content.append(" 【 任 务 已 指 派 】 \n");
|
||||
content.append("-------------------------------- \n\n");
|
||||
content.append("任务名称:示例任务标题 \n");
|
||||
content.append("任务编号:TSK20260104001 \n");
|
||||
content.append("任务积分:100 分 \n");
|
||||
content.append("指派给:李四 \n");
|
||||
content.append("预估工时:8 小时 \n");
|
||||
content.append("发起人:张三 \n");
|
||||
content.append(" \n");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append("请尽快处理!qd.yydd.ai \n");
|
||||
content.append("--------------------------------");
|
||||
break;
|
||||
|
||||
case "task_reject":
|
||||
// 任务驳回样式
|
||||
title = "任务已驳回(测试)";
|
||||
content.append("-------------------------------- \n");
|
||||
content.append(" 【 任 务 已 驳 回 】 \n");
|
||||
content.append("-------------------------------- \n\n");
|
||||
content.append("任务名称:示例任务标题 \n");
|
||||
content.append("任务编号:TSK20260104001 \n");
|
||||
content.append("原处理人:李四 \n");
|
||||
content.append("驳回原因:设计稿不符合要求,请重新修改 \n");
|
||||
content.append(" \n");
|
||||
content.append("--------------------------------");
|
||||
break;
|
||||
|
||||
case "subtask_publish":
|
||||
// 子任务组发布样式
|
||||
title = "子任务组发布(测试)";
|
||||
content.append("-------------------------------- \n");
|
||||
content.append(" 【 子任务组发布 】 \n");
|
||||
content.append("-------------------------------- \n\n");
|
||||
content.append("主任务:示例主任务标题 \n");
|
||||
content.append("任务编号:TSK20260104001 \n");
|
||||
content.append("当前组号:第 2 组 \n");
|
||||
content.append("子任务数:3 个 \n");
|
||||
content.append("组积分:60 分 \n");
|
||||
content.append("任务需求类型:平面设计 \n");
|
||||
content.append(" \n");
|
||||
content.append("子任务列表: \n");
|
||||
content.append(" 1. 首页Banner(20分) \n");
|
||||
content.append(" 2. 详情页设计(25分) \n");
|
||||
content.append(" 3. 主图设计(15分) \n");
|
||||
content.append(" \n");
|
||||
content.append("发起人:张三 \n");
|
||||
content.append("发起部门:市场部 \n");
|
||||
content.append(" \n");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append("前往抢单:qd.yydd.ai \n");
|
||||
content.append("--------------------------------");
|
||||
break;
|
||||
|
||||
default:
|
||||
// 简单测试消息
|
||||
title = params.getOrDefault("title", "系统测试消息");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append(" 【 系 统 测 试 】 \n");
|
||||
content.append("-------------------------------- \n\n");
|
||||
content.append("这是一条来自 DesignHub 系统的测试消息 \n");
|
||||
content.append(" \n");
|
||||
content.append("如果您收到此消息,说明钉钉机器人配置成功! \n");
|
||||
content.append(" \n");
|
||||
content.append("测试时间:").append(java.time.LocalDateTime.now().format(
|
||||
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).append(" \n");
|
||||
content.append(" \n");
|
||||
content.append("-------------------------------- \n");
|
||||
content.append("访问系统:qd.yydd.ai \n");
|
||||
content.append("--------------------------------");
|
||||
break;
|
||||
}
|
||||
|
||||
return Result.success(dingTalkService.sendRobotMessage(title, content.toString()));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取钉钉部门列表")
|
||||
|
||||
@ -51,9 +51,10 @@ export function testDingTalkConnection(config: DingTalkConfig): Promise<boolean>
|
||||
|
||||
/**
|
||||
* 发送测试消息
|
||||
* @param type 消息类型:simple(简单测试), task_publish(新任务发布), task_assign(任务指派), task_reject(任务驳回), subtask_publish(子任务组发布)
|
||||
*/
|
||||
export function sendTestMessage(title: string, content: string): Promise<boolean> {
|
||||
return request.post<Result<boolean>>('/dingtalk/test-message', { title, content })
|
||||
export function sendTestMessage(type: string = 'simple'): Promise<boolean> {
|
||||
return request.post<Result<boolean>>('/dingtalk/test-message', { type })
|
||||
.then(res => res.data)
|
||||
}
|
||||
|
||||
|
||||
@ -710,12 +710,27 @@
|
||||
<template #icon><Icon name="bolt" size="sm" /></template>
|
||||
测试连接
|
||||
</a-button>
|
||||
<a-button @click="handleSendTestMessage" :loading="sendingTestMessage" :disabled="!dingTalkConfig.robotWebhook">
|
||||
发送测试消息
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
|
||||
<a-divider orientation="left">消息测试</a-divider>
|
||||
<a-form-item label="选择消息类型">
|
||||
<a-radio-group v-model:value="testMessageType" button-style="solid">
|
||||
<a-radio-button value="simple">简单测试</a-radio-button>
|
||||
<a-radio-button value="task_publish">新任务发布</a-radio-button>
|
||||
<a-radio-button value="task_assign">任务指派</a-radio-button>
|
||||
<a-radio-button value="task_reject">任务驳回</a-radio-button>
|
||||
<a-radio-button value="subtask_publish">子任务组发布</a-radio-button>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
<a-form-item>
|
||||
<a-button type="primary" @click="handleSendTestMessage" :loading="sendingTestMessage" :disabled="!dingTalkConfig.robotWebhook">
|
||||
<template #icon><Icon name="send" size="sm" /></template>
|
||||
发送测试消息
|
||||
</a-button>
|
||||
<span class="test-message-hint">选择不同类型查看实际消息排版效果</span>
|
||||
</a-form-item>
|
||||
|
||||
<a-divider orientation="left">部门同步</a-divider>
|
||||
<a-alert
|
||||
message="部门同步说明"
|
||||
@ -2595,6 +2610,9 @@ const handleTestDingTalk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 测试消息类型
|
||||
const testMessageType = ref('simple')
|
||||
|
||||
const handleSendTestMessage = async () => {
|
||||
if (!dingTalkConfig.robotWebhook) {
|
||||
message.warning('请先配置机器人Webhook')
|
||||
@ -2603,9 +2621,16 @@ const handleSendTestMessage = async () => {
|
||||
|
||||
sendingTestMessage.value = true
|
||||
try {
|
||||
const result = await sendTestMessage('测试消息', '这是一条来自DesignHub系统的测试消息,如果您收到此消息说明钉钉机器人配置成功!')
|
||||
const result = await sendTestMessage(testMessageType.value)
|
||||
if (result) {
|
||||
message.success('测试消息发送成功!')
|
||||
const typeNames: Record<string, string> = {
|
||||
'simple': '简单测试',
|
||||
'task_publish': '新任务发布',
|
||||
'task_assign': '任务指派',
|
||||
'task_reject': '任务驳回',
|
||||
'subtask_publish': '子任务组发布'
|
||||
}
|
||||
message.success(`"${typeNames[testMessageType.value]}"消息发送成功!`)
|
||||
} else {
|
||||
message.error('测试消息发送失败')
|
||||
}
|
||||
@ -3992,6 +4017,13 @@ watch(activeTab, (value) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 测试消息提示
|
||||
.test-message-hint {
|
||||
margin-left: $space-md;
|
||||
font-size: $font-size-sm;
|
||||
color: $text-tertiary;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user