Commit 34fc5535 by chenjinjing

no message

parent f176c2b0
...@@ -332,6 +332,145 @@ export async function getPopupNotifications(eId: string) { ...@@ -332,6 +332,145 @@ 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 now = new Date();
// messageList = messageList.filter(message => {
// // 检查是否是填报截止提醒 (msgType = 2)
// if (message.msgType === MSGTYPE.填报截止提醒) {
// // 只有在季度第一个月1号才返回
// return shouldResetDeadlineReminder(now);
// }
// // 检查是否是季度填报提醒 (msgType = 1)
// if (message.msgType === MSGTYPE.季度填报提醒) {
// // 只有在季度最后一个月最后一周的周一才返回
// return shouldResetQuarterlyReminder(now);
// }
// // 其他类型的消息直接返回
// return true;
// });
// // 获取已读状态
// 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) { export async function getNotificationList(eId: string) {
// 查询消息表,获取所有给该企业或所有企业的消息 // 查询消息表,获取所有给该企业或所有企业的消息
const messageFields = ["msgId", "msgType", "msgTitle", "createTime", "effectiveTime", "msgContent", "eId", "isPop"]; const messageFields = ["msgId", "msgType", "msgTitle", "createTime", "effectiveTime", "msgContent", "eId", "isPop"];
...@@ -367,8 +506,9 @@ export async function getNotificationList(eId: string) { ...@@ -367,8 +506,9 @@ export async function getNotificationList(eId: string) {
messageList = messageList.filter(message => { messageList = messageList.filter(message => {
// 检查是否是填报截止提醒 (msgType = 2) // 检查是否是填报截止提醒 (msgType = 2)
if (message.msgType === MSGTYPE.填报截止提醒) { if (message.msgType === MSGTYPE.填报截止提醒) {
// 只有在季度第一个月1号才返回 // 修改前:只有在季度第一个月1号才返回
return shouldResetDeadlineReminder(now); // 修改后:在季度第一个月的整个时间段内都返回
return shouldShowDeadlineReminderInFirstMonth(now);
} }
// 检查是否是季度填报提醒 (msgType = 1) // 检查是否是季度填报提醒 (msgType = 1)
...@@ -468,6 +608,28 @@ export async function getNotificationList(eId: string) { ...@@ -468,6 +608,28 @@ export async function getNotificationList(eId: string) {
return { dataList }; return { dataList };
} }
/**
* 判断是否应该在季度第一个月显示填报截止提醒
* 修改:在整个季度第一个月都返回true,而不仅仅是在1号
*/
function shouldShowDeadlineReminderInFirstMonth(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);
// 修改前:只在1号返回
// const isFirstDay = date === 1;
// return isQuarterFirstMonth && isFirstDay;
// 修改后:在整个季度第一个月都返回
return isQuarterFirstMonth;
}
/** /**
* 批量创建未读记录 * 批量创建未读记录
...@@ -619,19 +781,19 @@ function shouldResetDeadlineReminder(now: Date): boolean { ...@@ -619,19 +781,19 @@ function shouldResetDeadlineReminder(now: Date): boolean {
/** /**
* 创建填报截止提醒消息模板 * 创建填报截止提醒消息模板
*/ */
function createDeadlineReminderTemplate(year: number, quarter: number) { // function createDeadlineReminderTemplate(year: number, quarter: number) {
const quarterNames = ["一", "二", "三", "四"]; // const quarterNames = ["一", "二", "三", "四"];
const quarterName = quarterNames[quarter - 1]; // const quarterName = quarterNames[quarter - 1];
// 计算截止时间 // // 计算截止时间
const endDate = calculateQuarterFirstMonthEndDate(year, quarter); // const endDate = calculateQuarterFirstMonthEndDate(year, quarter);
return { // return {
msgTitle: `${year}年第${quarterName}季度填报截止提醒`, // msgTitle: `${year}年第${quarterName}季度填报截止提醒`,
msgContent: `${year}年第${quarterName}季度填报将于${endDate}截止,请及时完成填报工作。`, // msgContent: `${year}年第${quarterName}季度填报将于${endDate}截止,请及时完成填报工作。`,
msgType: MSGTYPE.填报截止提醒 // msgType: MSGTYPE.填报截止提醒
}; // };
} // }
/** /**
* 检查并执行季度任务 - 修正逻辑说明 * 检查并执行季度任务 - 修正逻辑说明
...@@ -922,7 +1084,8 @@ function extractYearAndQuarterFromTitle(title: string): { year: number; quarter: ...@@ -922,7 +1084,8 @@ function extractYearAndQuarterFromTitle(title: string): { year: number; quarter:
.replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]); .replace(/\${quarter}/g, quarterNames[quarterInfo.quarter - 1]);
// 截止时间是当前季度第一个月的最后一天 // 截止时间是当前季度第一个月的最后一天
const endTime = calculateQuarterFirstMonthEndDate(quarterInfo.year, quarterInfo.quarter); // const endTime = calculateQuarterFirstMonthEndDate(quarterInfo.year, quarterInfo.quarter);
const endTime = calculateQuarterFirstMonthEndDate();
processedContent = processedContent.replace(/\${endTime}/g, endTime); processedContent = processedContent.replace(/\${endTime}/g, endTime);
console.log(`填报截止提醒处理: ${quarterInfo.year}年Q${quarterInfo.quarter}, 截止时间: ${endTime}`); console.log(`填报截止提醒处理: ${quarterInfo.year}年Q${quarterInfo.quarter}, 截止时间: ${endTime}`);
...@@ -1064,15 +1227,33 @@ async function resetDeadlineReminderReadStatusForAllEnterprises() { ...@@ -1064,15 +1227,33 @@ async function resetDeadlineReminderReadStatusForAllEnterprises() {
/** /**
* 计算季度第一个月的最后一天(填报截止时间) * 计算季度第一个月的最后一天(填报截止时间)
*/ */
function calculateQuarterFirstMonthEndDate(year: number, quarter: number): string { // function calculateQuarterFirstMonthEndDate(year: number, quarter: number): string {
// 获取季度第一个月 // // 获取季度第一个月
let firstMonth = 0; // let firstMonth = 0;
if (quarter === 1) firstMonth = 0; // 1月 // if (quarter === 1) firstMonth = 0; // 1月
else if (quarter === 2) firstMonth = 3; // 4月 // else if (quarter === 2) firstMonth = 3; // 4月
else if (quarter === 3) firstMonth = 6; // 7月 // else if (quarter === 3) firstMonth = 6; // 7月
else firstMonth = 9; // 10月 // else firstMonth = 9; // 10月
return moment(`${year}-${(firstMonth + 1).toString().padStart(2, '0')}-01`) // return moment(`${year}-${(firstMonth + 1).toString().padStart(2, '0')}-01`)
// .endOf('month')
// .format('YYYY-MM-DD');
// }
/**
* 计算季度第一个月的最后一天(填报截止时间)
* 季度划分:
* Q1: 1月, 2月, 3月 → 第一个月是1月,截止1月31日
* Q2: 4月, 5月, 6月 → 第一个月是4月,截止4月30日
* Q3: 7月, 8月, 9月 → 第一个月是7月,截止7月31日
* Q4: 10月, 11月, 12月 → 第一个月是10月,截止10月31日
*/
function calculateQuarterFirstMonthEndDate(): string {
let thisTime = moment().format("YYYY-MM-DD")
// 使用moment计算该月的最后一天
return moment(thisTime)
.endOf('month') .endOf('month')
.format('YYYY-MM-DD'); .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