feat: 优化数据结构 & 新增用药提醒卡片
This commit is contained in:
parent
650b6a416b
commit
410b4b44dd
59
README.md
59
README.md
@ -43,6 +43,23 @@ interface Remind {
|
||||
* id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 所有者信息,绑定用户表的open_id
|
||||
*/
|
||||
owner: string;
|
||||
/**
|
||||
* 接收消息相关信息
|
||||
*/
|
||||
subscriber: {
|
||||
/**
|
||||
* 接收者类型
|
||||
*/
|
||||
type: "open_id" | "user_id" | "union_id" | "email" | "chat_id";
|
||||
/**
|
||||
* 接收者Id
|
||||
*/
|
||||
id: string;
|
||||
};
|
||||
/**
|
||||
* 卡片信息,用于绘制初始卡片、确认卡片、取消卡片、延迟卡片
|
||||
*/
|
||||
@ -52,7 +69,7 @@ interface Remind {
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* 提醒内容
|
||||
* 提醒内容,会覆盖默认内容
|
||||
*/
|
||||
content: string;
|
||||
/**
|
||||
@ -69,21 +86,27 @@ interface Remind {
|
||||
delayText: string;
|
||||
} | null;
|
||||
/**
|
||||
* 卡片模板ID
|
||||
* 卡片模板信息
|
||||
*/
|
||||
templateId: string;
|
||||
/**
|
||||
* 确认之后的卡片模板ID
|
||||
*/
|
||||
confirmTemplateId: string;
|
||||
/**
|
||||
* 取消之后的卡片模板ID
|
||||
*/
|
||||
cancelTemplateId: string;
|
||||
/**
|
||||
* 延迟之后的卡片模板ID
|
||||
*/
|
||||
delayTemplateId: string;
|
||||
templateInfo: {
|
||||
/**
|
||||
* 卡片模板ID
|
||||
*/
|
||||
|
||||
pendingTemplateId: string;
|
||||
/**
|
||||
* 确认之后的卡片模板ID
|
||||
*/
|
||||
cancelededTemplateId: string;
|
||||
/**
|
||||
* 取消之后的卡片模板ID
|
||||
*/
|
||||
cancelTemplateId: string;
|
||||
/**
|
||||
* 延迟之后的卡片模板ID
|
||||
*/
|
||||
delayedTemplateId: string;
|
||||
} | null;
|
||||
/**
|
||||
* 重复类型
|
||||
* single: 一次性
|
||||
@ -114,10 +137,6 @@ interface Remind {
|
||||
* 每月的几号,当frequency为monthly时有效
|
||||
*/
|
||||
dayOfMonth: number;
|
||||
/**
|
||||
* 今年的哪天提醒,当frequency为single时有效,格式为MM-dd
|
||||
*/
|
||||
day: string;
|
||||
/**
|
||||
* 每年的哪天提醒,当frequency为yearly时有效,格式为MM-dd
|
||||
*/
|
||||
@ -161,7 +180,7 @@ interface RemindRecord {
|
||||
* confirmed: 已确认
|
||||
* canceled: 已取消
|
||||
*/
|
||||
status: "pending" | "delay" | "confirmed" | "canceled";
|
||||
status: "pending" | "delayed" | "confirmed" | "canceled";
|
||||
/**
|
||||
* 本次提醒时间,格式为yyyy-MM-dd HH:mm
|
||||
*/
|
||||
|
59
dataDeclare.ts → typings.d.ts
vendored
59
dataDeclare.ts → typings.d.ts
vendored
@ -6,6 +6,23 @@ interface Remind {
|
||||
* id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 所有者信息,绑定用户表的open_id
|
||||
*/
|
||||
owner: string;
|
||||
/**
|
||||
* 接收消息相关信息
|
||||
*/
|
||||
subscriber: {
|
||||
/**
|
||||
* 接收者类型
|
||||
*/
|
||||
type: "open_id" | "user_id" | "union_id" | "email" | "chat_id";
|
||||
/**
|
||||
* 接收者Id
|
||||
*/
|
||||
id: string;
|
||||
};
|
||||
/**
|
||||
* 卡片信息,用于绘制初始卡片、确认卡片、取消卡片、延迟卡片
|
||||
*/
|
||||
@ -15,7 +32,7 @@ interface Remind {
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* 提醒内容
|
||||
* 提醒内容,会覆盖默认内容
|
||||
*/
|
||||
content: string;
|
||||
/**
|
||||
@ -32,21 +49,27 @@ interface Remind {
|
||||
delayText: string;
|
||||
} | null;
|
||||
/**
|
||||
* 卡片模板ID
|
||||
* 卡片模板信息
|
||||
*/
|
||||
templateId: string;
|
||||
/**
|
||||
* 确认之后的卡片模板ID
|
||||
*/
|
||||
confirmTemplateId: string;
|
||||
/**
|
||||
* 取消之后的卡片模板ID
|
||||
*/
|
||||
cancelTemplateId: string;
|
||||
/**
|
||||
* 延迟之后的卡片模板ID
|
||||
*/
|
||||
delayTemplateId: string;
|
||||
templateInfo: {
|
||||
/**
|
||||
* 卡片模板ID
|
||||
*/
|
||||
|
||||
pendingTemplateId: string;
|
||||
/**
|
||||
* 确认之后的卡片模板ID
|
||||
*/
|
||||
cancelededTemplateId: string;
|
||||
/**
|
||||
* 取消之后的卡片模板ID
|
||||
*/
|
||||
cancelTemplateId: string;
|
||||
/**
|
||||
* 延迟之后的卡片模板ID
|
||||
*/
|
||||
delayedTemplateId: string;
|
||||
} | null;
|
||||
/**
|
||||
* 重复类型
|
||||
* single: 一次性
|
||||
@ -77,10 +100,6 @@ interface Remind {
|
||||
* 每月的几号,当frequency为monthly时有效
|
||||
*/
|
||||
dayOfMonth: number;
|
||||
/**
|
||||
* 今年的哪天提醒,当frequency为single时有效,格式为MM-dd
|
||||
*/
|
||||
day: string;
|
||||
/**
|
||||
* 每年的哪天提醒,当frequency为yearly时有效,格式为MM-dd
|
||||
*/
|
||||
@ -118,7 +137,7 @@ interface RemindRecord {
|
||||
* confirmed: 已确认
|
||||
* canceled: 已取消
|
||||
*/
|
||||
status: "pending" | "delay" | "confirmed" | "canceled";
|
||||
status: "pending" | "delayed" | "confirmed" | "canceled";
|
||||
/**
|
||||
* 本次提醒时间,格式为yyyy-MM-dd HH:mm
|
||||
*/
|
131
utils/Card/genCard.js
Normal file
131
utils/Card/genCard.js
Normal file
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* 根据提醒信息生成卡片
|
||||
* @param {*} remindInfo
|
||||
* @param {*} cardType
|
||||
*/
|
||||
module.exports.genCard = async (
|
||||
remindInfo,
|
||||
cardType
|
||||
) => {
|
||||
const { cardInfo, templateInfo } = remindInfo;
|
||||
// 优先模板信息
|
||||
if (templateInfo) {
|
||||
return {
|
||||
type: "template",
|
||||
data: {
|
||||
template_id: templateInfo[`${cardType}TemplateId`],
|
||||
},
|
||||
};
|
||||
}
|
||||
// 其次卡片信息
|
||||
const { title, content, confirmText, cancelText, delayText } = cardInfo;
|
||||
const { frequency, time, dayOfWeek, dayOfMonth, dayOfYear } = remindInfo;
|
||||
// 组织提醒时间
|
||||
let remindTimeText = "";
|
||||
switch (frequency) {
|
||||
case "single":
|
||||
remindTimeText = `${dayOfYear} ${time}`;
|
||||
break;
|
||||
case "daily":
|
||||
remindTimeText = `每天 ${time}`;
|
||||
break;
|
||||
case "weekly":
|
||||
remindTimeText = `每周${dayOfWeek} ${time}`;
|
||||
break;
|
||||
case "monthly":
|
||||
remindTimeText = `每月${dayOfMonth}日 ${time}`;
|
||||
break;
|
||||
case "yearly":
|
||||
remindTimeText = `每年${dayOfYear} ${time}`;
|
||||
break;
|
||||
case "workday":
|
||||
remindTimeText = `工作日 ${time}`;
|
||||
break;
|
||||
case "holiday":
|
||||
remindTimeText = `节假日 ${time}`;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 判定卡片状态
|
||||
let cardStatus = ''
|
||||
switch (cardType) {
|
||||
case 'delayed':
|
||||
cardStatus = ' (已延期)'
|
||||
break;
|
||||
case 'canceled':
|
||||
cardStatus = ' (已取消)'
|
||||
break;
|
||||
case 'confirmed':
|
||||
cardStatus = ' (已确认)'
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 组织卡片内容
|
||||
const mdContent = content || `**提醒时间:**\n${remindTimeText}\n\n**提醒内容:**\n${title}`;
|
||||
const actions = [];
|
||||
// 只有未交互卡片才显示按钮
|
||||
if (cardType === "pending") {
|
||||
if (confirmText) {
|
||||
actions.push({
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: confirmText,
|
||||
},
|
||||
type: "primary",
|
||||
value: {
|
||||
result: "confirmed",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (delayText) {
|
||||
actions.push({
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: delayText,
|
||||
},
|
||||
type: "default",
|
||||
value: {
|
||||
result: "delayed",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (cancelText) {
|
||||
actions.push({
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: cancelText,
|
||||
},
|
||||
type: "danger",
|
||||
value: {
|
||||
result: "canceled",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
elements: [
|
||||
{
|
||||
tag: "div",
|
||||
text: {
|
||||
content: mdContent,
|
||||
tag: "lark_md"
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: "action",
|
||||
actions,
|
||||
}
|
||||
],
|
||||
header: {
|
||||
title: {
|
||||
content: `${title}${cardStatus}`,
|
||||
tag: "plain_text",
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
63
utils/Card/rowCard/medicine_main.json
Normal file
63
utils/Card/rowCard/medicine_main.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"alt": {
|
||||
"content": "",
|
||||
"tag": "plain_text"
|
||||
},
|
||||
"img_key": "img_v2_a74b2092-9f61-44d2-ab4c-45f9c4e083el",
|
||||
"tag": "img"
|
||||
},
|
||||
{
|
||||
"tag": "div",
|
||||
"text": {
|
||||
"content": " **本次包含药品:**\n美沙拉嗪 \\* 1\n复方谷氨酰胺 \\* 4",
|
||||
"tag": "lark_md"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "我吃完了"
|
||||
},
|
||||
"type": "primary",
|
||||
"value": {
|
||||
"result": "confirmed"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "延迟提醒"
|
||||
},
|
||||
"type": "default",
|
||||
"value": {
|
||||
"result": "delay"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "淦,忘吃了"
|
||||
},
|
||||
"type": "danger",
|
||||
"value": {
|
||||
"result": "canceled"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"header": {
|
||||
"title": {
|
||||
"content": "🎉 帝君喊你吃药!",
|
||||
"tag": "plain_text"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
const fetch = require('node-fetch');
|
||||
const {
|
||||
getTenantAccessToken
|
||||
} = require('./pb');
|
||||
} = require('../pb');
|
||||
|
||||
module.exports.sendCard = async (receive_id_type, receive_id, msg_type, content) => {
|
||||
const URL = `https://open.f.mioffice.cn/open-apis/im/v1/messages?receive_id_type=${receive_id_type}`
|
Loading…
x
Reference in New Issue
Block a user