Commit f176c2b0 by chenjinjing

no message

parent 9970093d
......@@ -28,48 +28,48 @@ export function initQuarterlyNotificationTask() {
/**
* 检查并执行季度任务
*/
async function checkAndExecuteQuarterlyTasks() {
const now = new Date();
console.log(`检查季度任务执行时间: ${now.toLocaleString()}`);
// async function checkAndExecuteQuarterlyTasks() {
// const now = new Date();
// console.log(`检查季度任务执行时间: ${now.toLocaleString()}`);
try {
// 1. 检查是否需要重置填报截止提醒已读状态(季度第一个月1号凌晨3点)
if (shouldResetDeadlineReminder(now)) {
console.log('开始重置填报截止提醒已读状态...');
await resetDeadlineReminderReadStatusForAllEnterprises();
console.log('填报截止提醒已读状态重置完成');
}
// try {
// // 1. 检查是否需要重置填报截止提醒已读状态(季度第一个月1号凌晨3点)
// if (shouldResetDeadlineReminder(now)) {
// console.log('开始重置填报截止提醒已读状态...');
// await resetDeadlineReminderReadStatusForAllEnterprises();
// console.log('填报截止提醒已读状态重置完成');
// }
// 2. 检查是否需要重置季度填报提醒已读状态(季度最后一个月最后一周的第一天)
if (shouldResetQuarterlyReminder(now)) {
console.log('开始重置季度填报提醒已读状态...');
await resetQuarterlyReminderReadStatusForAllEnterprises();
console.log('季度填报提醒已读状态重置完成');
}
} catch (error) {
console.error('季度任务执行失败:', error);
}
}
// // 2. 检查是否需要重置季度填报提醒已读状态(季度最后一个月最后一周的第一天)
// if (shouldResetQuarterlyReminder(now)) {
// console.log('开始重置季度填报提醒已读状态...');
// await resetQuarterlyReminderReadStatusForAllEnterprises();
// console.log('季度填报提醒已读状态重置完成');
// }
// } catch (error) {
// console.error('季度任务执行失败:', error);
// }
// }
/**
* 判断是否需要重置填报截止提醒
*/
function shouldResetDeadlineReminder(now: Date): boolean {
const momentNow = moment(now);
// 检查是否是季度第一个月的一号
const month = momentNow.month(); // 0-11
const date = momentNow.date();
const hour = momentNow.hour();
// 季度第一个月:1月(0), 4月(3), 7月(6), 10月(9)
const isQuarterFirstMonth = [0, 3, 6, 9].includes(month);
// const isFirstDay = date === 1;
// const isTargetHour = hour === 3; // 凌晨3点
return isQuarterFirstMonth;
}
// /**
// * 判断是否需要重置填报截止提醒
// */
// function shouldResetDeadlineReminder(now: Date): boolean {
// const momentNow = moment(now);
// // 检查是否是季度第一个月的一号
// const month = momentNow.month(); // 0-11
// const date = momentNow.date();
// const hour = momentNow.hour();
// // 季度第一个月:1月(0), 4月(3), 7月(6), 10月(9)
// const isQuarterFirstMonth = [0, 3, 6, 9].includes(month);
// // const isFirstDay = date === 1;
// // const isTargetHour = hour === 3; // 凌晨3点
// return isQuarterFirstMonth;
// }
/**
......@@ -139,57 +139,15 @@ function shouldResetQuarterlyReminder(now: Date): boolean {
/**
* 为所有企业重置填报截止提醒已读状态
*/
async function resetDeadlineReminderReadStatusForAllEnterprises() {
// 获取目标季度信息
const targetQuarter = getCurrentQuarter();
// 使用新的查询方法
const deadlineMessages = await getMessagesByQuarter(
MSGTYPE.填报截止提醒,
targetQuarter.year,
targetQuarter.quarter
);
// 获取所有企业
const allEnterprises = await getAllEnterprises();
// 为每个企业重置已读状态
for (const enterprise of allEnterprises) {
// 查找该企业对应的消息
const enterpriseMessage = deadlineMessages.find(msg => {
try {
const eIdArray = JSON.parse(msg.eId || '[]');
return eIdArray.includes(enterprise.eId) || eIdArray.length === 0;
} catch {
return false;
}
});
if (enterpriseMessage) {
await resetMessageReadStatus(enterprise.eId, enterpriseMessage.msgId);
}
}
}
/**
* 为所有企业重置季度填报提醒已读状态
*/
// async function resetQuarterlyReminderReadStatusForAllEnterprises() {
// // 获取下一季度信息
// const nextQuarter = getNextQuarter();
// const quarterNames = ["一", "二", "三", "四"];
// const quarterName = quarterNames[nextQuarter.quarter - 1];
// async function resetDeadlineReminderReadStatusForAllEnterprises() {
// // 获取目标季度信息
// const targetQuarter = getCurrentQuarter();
// // 查找季度填报提醒消息(msgType = 1)
// const quarterlyMessages = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息通知表,
// {
// msgType: MSGTYPE.季度填报提醒,
// // msgTitle: { "%like%": `${nextQuarter.year}年第${quarterName}季度` }
// },
// ["msgId", "eId"]
// // 使用新的查询方法
// const deadlineMessages = await getMessagesByQuarter(
// MSGTYPE.填报截止提醒,
// targetQuarter.year,
// targetQuarter.quarter
// );
// // 获取所有企业
......@@ -198,7 +156,7 @@ async function resetDeadlineReminderReadStatusForAllEnterprises() {
// // 为每个企业重置已读状态
// for (const enterprise of allEnterprises) {
// // 查找该企业对应的消息
// const enterpriseMessage = quarterlyMessages.find(msg => {
// const enterpriseMessage = deadlineMessages.find(msg => {
// try {
// const eIdArray = JSON.parse(msg.eId || '[]');
// return eIdArray.includes(enterprise.eId) || eIdArray.length === 0;
......@@ -213,40 +171,8 @@ async function resetDeadlineReminderReadStatusForAllEnterprises() {
// }
// }
/**
* 为所有企业重置季度填报提醒已读状态
*/
async function resetQuarterlyReminderReadStatusForAllEnterprises() {
// 获取下一季度信息
const nextQuarter = getNextQuarter();
// 使用新的查询方法
const quarterlyMessages = await getMessagesByQuarter(
MSGTYPE.季度填报提醒,
nextQuarter.year,
nextQuarter.quarter
);
// 获取所有企业
const allEnterprises = await getAllEnterprises();
// 为每个企业重置已读状态
for (const enterprise of allEnterprises) {
// 查找该企业对应的消息
const enterpriseMessage = quarterlyMessages.find(msg => {
try {
const eIdArray = JSON.parse(msg.eId || '[]');
return eIdArray.includes(enterprise.eId) || eIdArray.length === 0;
} catch {
return false;
}
});
if (enterpriseMessage) {
await resetMessageReadStatus(enterprise.eId, enterpriseMessage.msgId);
}
}
}
/**
......@@ -406,127 +332,6 @@ export async function getPopupNotifications(eId: string) {
/**
* 获取企业通知列表
*/
// export async function getNotificationList(eId: string) {
// // 查询消息表,获取所有给该企业或所有企业的消息
// const messageFields = ["msgId", "msgType", "msgTitle", "createTime", "effectiveTime", "msgContent", "eId", "isPop"];
// // 查询条件:eId包含该企业或eId为空数组(发给所有企业)
// const selectParam = {
// "%or%": [
// { eId: { "%like%": eId } }, // 包含该企业ID
// { eId: '[]' } // 发给所有企业
// ]
// };
// let messageList = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息通知表,
// selectParam,
// messageFields
// );
// // 过滤过期消息
// const currentTime = getMySqlMs();
// messageList = messageList.filter(message =>
// !message.effectiveTime || message.effectiveTime > currentTime
// );
// // 按创建时间排序
// messageList.sort((a, b) =>
// new Date(b.createTime).valueOf() - new Date(a.createTime).valueOf()
// );
// // 获取已读状态
// const readStatusFields = ["readId", "msgId", "eId", "readTime", "isRead"];
// const readStatusList = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息已读状态表,
// { eId: eId },
// readStatusFields
// );
// // 创建已读状态映射
// const readStatusMap = new Map();
// readStatusList.forEach(status => {
// readStatusMap.set(status.msgId, status);
// });
// // 存储需要创建的未读记录
// const unreadRecordsToCreate = [];
// // 构建返回数据
// const dataList = messageList.map(message => {
// // 解析企业ID数组
// let eIdArray: string[] = [];
// if (message.eId) {
// try {
// eIdArray = JSON.parse(message.eId);
// } catch (error) {
// console.error('解析 eId 失败:', error);
// }
// }
// // 获取已读状态
// const readStatus = readStatusMap.get(message.msgId);
// let isRead = false;
// let readTime = null;
// let readId = null;
// if (readStatus) {
// // 如果已有记录,使用现有状态
// isRead = readStatus.isRead === 1;
// readTime = readStatus.readTime;
// readId = readStatus.readId;
// } else {
// // 如果没有记录,标记为未读,并准备创建记录
// isRead = false;
// readTime = null;
// readId = randomId(TABLEID.企业消息已读状态表); // 尚未创建,没有readId
// // 收集需要创建的未读记录
// unreadRecordsToCreate.push({
// msgId: message.msgId,
// readId,
// eId: eId,
// readTime: null,
// isRead: 0, // 0表示未读
// createTime: getMySqlMs() // 添加创建时间
// });
// }
// return {
// msgId: message.msgId,
// readId,
// msgType: message.msgType,
// msgTitle: message.msgTitle,
// msgContent: message.msgContent,
// eId: eIdArray,
// isPop: message.isPop === 1,
// isRead: isRead,
// effectiveTime: message.effectiveTime ? moment(message.effectiveTime).format("YYYY-MM-DD HH:mm:ss") : null,
// readTime: readTime ? moment(readTime).format("YYYY-MM-DD HH:mm:ss") : null,
// createTime: moment(message.createTime).format("YYYY-MM-DD HH:mm:ss")
// };
// });
// // 批量创建未读记录(如果有需要创建的)
// if (unreadRecordsToCreate.length > 0) {
// try {
// // 这里需要实现批量插入数据的函数
// await createUnreadRecords(unreadRecordsToCreate);
// } catch (error) {
// console.error('创建未读记录失败:', error);
// // 这里可以根据需要决定是否抛出错误
// }
// }
// return { dataList };
// }
/**
* 获取企业通知列表
*/
export async function getNotificationList(eId: string) {
// 查询消息表,获取所有给该企业或所有企业的消息
const messageFields = ["msgId", "msgType", "msgTitle", "createTime", "effectiveTime", "msgContent", "eId", "isPop"];
......@@ -751,60 +556,189 @@ export async function markNotificationAsRead(eId: string, msgId: string, readId:
return { isSuccess: true };
}
/**
* 获取上一季度信息
*/
function getLastQuarter(): { year: number; quarter: number } {
const currentQuarter = getCurrentQuarter();
let lastYear = currentQuarter.year;
let lastQuarter = currentQuarter.quarter - 1;
if (lastQuarter < 1) {
lastQuarter = 4;
lastYear = currentQuarter.year - 1;
}
return { year: lastYear, quarter: lastQuarter };
}
/**
* 计算下一季度的第一天(填报开始时间)
*/
function calculateNextQuarterFirstDay(year: number, quarter: number): string {
// 上一季度的下一季度第一天就是填报开始时间
let nextYear = year;
let nextQuarter = quarter + 1;
if (nextQuarter > 4) {
nextQuarter = 1;
nextYear = year + 1;
}
// 计算下一季度的第一个月
let startMonth = 0;
if (nextQuarter === 1) startMonth = 0; // 1月
else if (nextQuarter === 2) startMonth = 3; // 4月
else if (nextQuarter === 3) startMonth = 6; // 7月
else startMonth = 9; // 10月
return moment(`${nextYear}-${(startMonth + 1).toString().padStart(2, '0')}-01`)
.format('YYYY-MM-DD');
}
/**
* 判断是否需要重置填报截止提醒 - 修正逻辑
*/
function shouldResetDeadlineReminder(now: Date): boolean {
const momentNow = moment(now);
// 检查是否是季度第一个月的一号
const month = momentNow.month(); // 0-11
const date = momentNow.date();
// 季度第一个月:1月(0), 4月(3), 7月(6), 10月(9)
const isQuarterFirstMonth = [0, 3, 6, 9].includes(month);
const isFirstDay = date === 1;
return isQuarterFirstMonth && isFirstDay;
}
/**
* 创建填报截止提醒消息模板
*/
function createDeadlineReminderTemplate(year: number, quarter: number) {
const quarterNames = ["一", "二", "三", "四"];
const quarterName = quarterNames[quarter - 1];
// 计算截止时间
const endDate = calculateQuarterFirstMonthEndDate(year, quarter);
return {
msgTitle: `${year}年第${quarterName}季度填报截止提醒`,
msgContent: `${year}年第${quarterName}季度填报将于${endDate}截止,请及时完成填报工作。`,
msgType: MSGTYPE.填报截止提醒
};
}
/**
* 检查并执行季度任务 - 修正逻辑说明
*/
async function checkAndExecuteQuarterlyTasks() {
const now = new Date();
console.log(`检查季度任务执行时间: ${now.toLocaleString()}`);
try {
// 1. 检查是否需要重置填报截止提醒已读状态(季度第一个月1号)
// 例如:2026年1月1日、2026年4月1日、2026年7月1日、2026年10月1日
if (shouldResetDeadlineReminder(now)) {
console.log('开始重置填报截止提醒已读状态...');
await resetDeadlineReminderReadStatusForAllEnterprises();
console.log('填报截止提醒已读状态重置完成');
}
// 2. 检查是否需要重置季度填报提醒已读状态(下一季度开始前一周)
// 例如:2025年12月25日左右提醒2025年第四季度填报
if (shouldResetQuarterlyReminder(now)) {
console.log('开始重置季度填报提醒已读状态...');
await resetQuarterlyReminderReadStatusForAllEnterprises();
console.log('季度填报提醒已读状态重置完成');
}
} catch (error) {
console.error('季度任务执行失败:', error);
}
}
/**
* 处理通知消息模板变量
*/
function processNotificationTemplates(messages: any[]) {
return messages.map(message => {
let processedTitle = message.msgTitle;
let processedContent = message.msgContent;
// function processNotificationTemplates(messages: any[]) {
// return messages.map(message => {
// let processedTitle = message.msgTitle;
// let processedContent = message.msgContent;
// 根据消息类型处理不同的模板变量
if (message.msgType === MSGTYPE.季度填报提醒 || message.msgType === MSGTYPE.填报截止提醒) {
const quarterInfo = extractQuarterInfoFromMessage();
// // 根据消息类型处理不同的模板变量
// if (message.msgType === MSGTYPE.季度填报提醒 || message.msgType === MSGTYPE.填报截止提醒) {
// const quarterInfo = extractQuarterInfoFromMessage();
if (quarterInfo) {
const quarterNames = ["一", "二", "三", "四"];
// if (quarterInfo) {
// const quarterNames = ["一", "二", "三", "四"];
// 添加开始时间、结束时间处理
if (message.msgType === MSGTYPE.填报截止提醒) {
processedTitle = processedTitle
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
// // 添加开始时间、结束时间处理
// if (message.msgType === MSGTYPE.填报截止提醒) {
// processedTitle = processedTitle
// .replace(/\${year}/g, quarterInfo.year.toString())
// .replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
processedContent = processedContent
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
const endTime = calculateQuarterEndTime(quarterInfo.year, quarterInfo.quarter);
processedContent = processedContent.replace(/\${endTime}/g, endTime);
} else if (message.msgType === MSGTYPE.季度填报提醒) {
const nextQuarter = getNextQuarter();
let targetYear = nextQuarter.year;
let targetQuarter = nextQuarter.quarter;
// processedContent = processedContent
// .replace(/\${year}/g, quarterInfo.year.toString())
// .replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
// const endTime = calculateQuarterEndTime(quarterInfo.year, quarterInfo.quarter);
// processedContent = processedContent.replace(/\${endTime}/g, endTime);
// } else if (message.msgType === MSGTYPE.季度填报提醒) {
// const nextQuarter = getNextQuarter();
// let targetYear = nextQuarter.year;
// let targetQuarter = nextQuarter.quarter;
processedTitle = processedTitle
.replace(/\${year}/g, targetYear.toString())
.replace(/\${quarter}/g, quarterNames[targetQuarter - 1]);
// processedTitle = processedTitle
// .replace(/\${year}/g, targetYear.toString())
// .replace(/\${quarter}/g, quarterNames[targetQuarter - 1]);
processedContent = processedContent
.replace(/\${year}/g, targetYear.toString())
.replace(/\${quarter}/g, quarterNames[targetQuarter - 1]);
// processedContent = processedContent
// .replace(/\${year}/g, targetYear.toString())
// .replace(/\${quarter}/g, quarterNames[targetQuarter - 1]);
const startTime = calculateQuarterStartTime(targetYear, targetQuarter);
processedContent = processedContent.replace(/\${startTime}/g, startTime);
}
}
}
// const startTime = calculateQuarterStartTime(targetYear, targetQuarter);
// processedContent = processedContent.replace(/\${startTime}/g, startTime);
// }
// }
// }
return {
...message,
msgTitle: processedTitle,
msgContent: processedContent
};
});
}
// return {
// ...message,
// msgTitle: processedTitle,
// msgContent: processedContent
// };
// });
// }
/**
......@@ -948,80 +882,201 @@ function extractYearAndQuarterFromTitle(title: string): { year: number; quarter:
}
}
/**
* 根据季度信息查询消息
* 处理通知消息模板变量 - 分离两种提醒的逻辑
*/
// async function getMessagesByQuarter(msgType: number, year: number, quarter: number, isTemplate: boolean = true) {
// const quarterNames = ["一", "二", "三", "四"];
// const quarterName = quarterNames[quarter - 1];
// let messages = [];
// if (isTemplate) {
// // 查询模板格式的消息
// const templateTitles = [
// `\${${year}}年第\${${quarter}}季度填报提醒`,
// `\${${year}}年第\${${quarter}}季度`,
// `\${${year}年第\${${quarter}}季度}`,
// `${year}年第${quarter}季度填报提醒`,
// `${year}年第${quarterName}季度填报提醒`
// ];
function processNotificationTemplates(messages: any[]) {
return messages.map(message => {
let processedTitle = message.msgTitle;
let processedContent = message.msgContent;
const quarterNames = ["一", "二", "三", "四"];
// for (const title of templateTitles) {
// const result = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息通知表,
// {
// msgType: msgType,
// msgTitle: { "%like%": title }
// },
// ["msgId", "eId", "msgTitle"]
// );
if (message.msgType === MSGTYPE.季度填报提醒) {
// 季度填报提醒:提醒当前季度的开始填报
const quarterInfo = getQuarterForQuarterlyReminder();
// if (result && result.length > 0) {
// messages = [...messages, ...result];
// }
// }
// // 如果上面的精确查询没找到,尝试模糊查询
// if (messages.length === 0) {
// const fuzzyResult = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息通知表,
// {
// msgType: msgType,
// "%or%": [
// { msgTitle: { "%like%": `${year}年%` } },
// { msgTitle: { "%like%": `\${${year}}年%` } }
// ]
// },
// ["msgId", "eId", "msgTitle"]
// );
processedTitle = processedTitle
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
processedContent = processedContent
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
// 填报开始时间是下一季度的第一天
const startTime = calculateNextQuarterFirstDay(quarterInfo.year, quarterInfo.quarter);
processedContent = processedContent.replace(/\${startTime}/g, startTime);
// // 进一步过滤
// messages = fuzzyResult.filter(msg => {
// const result = extractYearAndQuarterFromTitle(msg.msgTitle);
// return result && result.year === year && result.quarter === quarter;
// });
// }
// } else {
// // 查询已替换格式的消息
// const result = await selectData(
// OPERATIONALDATATYPE.查询多个,
// TABLENAME.企业消息通知表,
// {
// msgType: msgType,
// msgTitle: { "%like%": `${year}年第${quarterName}季度%` }
// },
// ["msgId", "eId"]
// );
console.log(`季度填报提醒处理: ${quarterInfo.year}年Q${quarterInfo.quarter}, 开始时间: ${startTime}`);
} else if (message.msgType === MSGTYPE.填报截止提醒) {
// 填报截止提醒:提醒即将结束的季度的截止时间
const quarterInfo = getQuarterForDeadlineReminder();
processedTitle = processedTitle
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
processedContent = processedContent
.replace(/\${year}/g, quarterInfo.year.toString())
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
// 截止时间是当前季度第一个月的最后一天
const endTime = calculateQuarterFirstMonthEndDate(quarterInfo.year, quarterInfo.quarter);
processedContent = processedContent.replace(/\${endTime}/g, endTime);
console.log(`填报截止提醒处理: ${quarterInfo.year}年Q${quarterInfo.quarter}, 截止时间: ${endTime}`);
}
// messages = result;
// }
return {
...message,
msgTitle: processedTitle,
msgContent: processedContent
};
});
}
/**
* 获取季度填报提醒的季度信息
* 在下一季度开始前一周提醒当前季度
*/
function getQuarterForQuarterlyReminder(): { year: number; quarter: number } {
const now = moment();
const currentYear = now.year();
const currentMonth = now.month(); // 0-11
// return messages;
// }
// 判断当前季度
let quarter = 1;
if (currentMonth >= 0 && currentMonth <= 2) quarter = 1; // 1-3月: Q1
else if (currentMonth >= 3 && currentMonth <= 5) quarter = 2; // 4-6月: Q2
else if (currentMonth >= 6 && currentMonth <= 8) quarter = 3; // 7-9月: Q3
else quarter = 4; // 10-12月: Q4
// 测试当前时间:2025-12-30 应该返回 Q4
console.log(`季度填报提醒季度判断: 当前时间 ${now.format('YYYY-MM-DD')}, 月份 ${currentMonth}, 季度 Q${quarter}`);
return { year: currentYear, quarter };
}
/**
* 获取填报截止提醒的季度信息
* 在季度第一个月1号提醒上一季度的截止
*/
function getQuarterForDeadlineReminder(): { year: number; quarter: number } {
const now = moment();
const currentYear = now.year();
const currentMonth = now.month(); // 0-11
// 填报截止提醒是在季度第一个月1号提醒上一季度的截止
// 例如:2026-01-01提醒2025年Q4的截止
// 判断上一季度
let year = currentYear;
let quarter = 1;
if (currentMonth >= 0 && currentMonth <= 2) { // 1-3月
quarter = 4; // 上一季度是Q4
year = currentYear - 1; // 上一年
} else if (currentMonth >= 3 && currentMonth <= 5) { // 4-6月
quarter = 1; // 上一季度是Q1
} else if (currentMonth >= 6 && currentMonth <= 8) { // 7-9月
quarter = 2; // 上一季度是Q2
} else { // 10-12月
quarter = 3; // 上一季度是Q3
}
// 测试当前时间:2025-12-30 应该还是返回当前季度,但实际触发是在2026-01-01才会返回Q4
console.log(`填报截止提醒季度判断: 当前时间 ${now.format('YYYY-MM-DD')}, 月份 ${currentMonth}, 提醒季度 ${year}年Q${quarter}`);
return { year, quarter };
}
/**
* 为所有企业重置季度填报提醒已读状态
*/
async function resetQuarterlyReminderReadStatusForAllEnterprises() {
// 获取季度填报提醒对应的季度
const quarterInfo = getQuarterForQuarterlyReminder();
console.log(`重置季度填报提醒: ${quarterInfo.year}年第${quarterInfo.quarter}季度`);
const quarterlyMessages = await getMessagesByQuarter(
MSGTYPE.季度填报提醒,
quarterInfo.year,
quarterInfo.quarter
);
const allEnterprises = await getAllEnterprises();
for (const enterprise of allEnterprises) {
const enterpriseMessage = quarterlyMessages.find(msg => {
try {
const eIdArray = JSON.parse(msg.eId || '[]');
return eIdArray.includes(enterprise.eId) || eIdArray.length === 0;
} catch {
return false;
}
});
if (enterpriseMessage) {
await resetMessageReadStatus(enterprise.eId, enterpriseMessage.msgId);
}
}
}
/**
* 为所有企业重置填报截止提醒已读状态
*/
async function resetDeadlineReminderReadStatusForAllEnterprises() {
// 获取填报截止提醒对应的季度(上一季度)
const quarterInfo = getQuarterForDeadlineReminder();
console.log(`重置填报截止提醒: ${quarterInfo.year}年第${quarterInfo.quarter}季度`);
const deadlineMessages = await getMessagesByQuarter(
MSGTYPE.填报截止提醒,
quarterInfo.year,
quarterInfo.quarter
);
const allEnterprises = await getAllEnterprises();
for (const enterprise of allEnterprises) {
const enterpriseMessage = deadlineMessages.find(msg => {
try {
const eIdArray = JSON.parse(msg.eId || '[]');
return eIdArray.includes(enterprise.eId) || eIdArray.length === 0;
} catch {
return false;
}
});
if (enterpriseMessage) {
await resetMessageReadStatus(enterprise.eId, enterpriseMessage.msgId);
}
}
}
/**
* 计算季度第一个月的最后一天(填报截止时间)
*/
function calculateQuarterFirstMonthEndDate(year: number, quarter: number): string {
// 获取季度第一个月
let firstMonth = 0;
if (quarter === 1) firstMonth = 0; // 1月
else if (quarter === 2) firstMonth = 3; // 4月
else if (quarter === 3) firstMonth = 6; // 7月
else firstMonth = 9; // 10月
return moment(`${year}-${(firstMonth + 1).toString().padStart(2, '0')}-01`)
.endOf('month')
.format('YYYY-MM-DD');
}
/**
* 根据季度信息查询消息
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment