feat: 优化数据结构 & 新增用药提醒卡片

This commit is contained in:
zhaoyingbo 2023-08-19 11:50:55 +08:00
parent 650b6a416b
commit 410b4b44dd
5 changed files with 273 additions and 41 deletions

View File

@ -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
*/

View File

@ -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
View 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",
},
},
}
};

View 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"
}
}
}

View File

@ -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}`