refactor(users): 更新用户活动表名并添加日志记录

将用户活动表名从'user_activities'改为't_user_activities',并在服务中添加详细的日志记录逻辑。
This commit is contained in:
richarjiang
2025-08-21 14:52:09 +08:00
parent 73f53ac5e4
commit 513d6e071d
2 changed files with 6 additions and 1 deletions

View File

@@ -47,7 +47,7 @@ export interface UserActivityAttributes {
export interface UserActivityCreationAttributes extends Optional<UserActivityAttributes, 'id' | 'createdAt' | 'updatedAt' | 'remark'> { } export interface UserActivityCreationAttributes extends Optional<UserActivityAttributes, 'id' | 'createdAt' | 'updatedAt' | 'remark'> { }
@Table({ @Table({
tableName: 'user_activities', tableName: 't_user_activities',
timestamps: true, timestamps: true,
indexes: [ indexes: [
{ {

View File

@@ -40,6 +40,8 @@ export class UserActivityService {
const today = dayjs().format('YYYY-MM-DD'); // YYYY-MM-DD 格式 const today = dayjs().format('YYYY-MM-DD'); // YYYY-MM-DD 格式
try { try {
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}`);
const existingLogin = await this.userActivityModel.findOne({ const existingLogin = await this.userActivityModel.findOne({
where: { where: {
userId, userId,
@@ -49,6 +51,7 @@ export class UserActivityService {
}); });
if (!existingLogin) { if (!existingLogin) {
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}, 不存在记录,自动创建`);
await this.recordActivity(userId, { await this.recordActivity(userId, {
activityType: ActivityType.LOGIN, activityType: ActivityType.LOGIN,
activityDate: today, activityDate: today,
@@ -56,6 +59,8 @@ export class UserActivityService {
remark: '用户拉取profile接口自动记录', remark: '用户拉取profile接口自动记录',
}); });
} }
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}, 已存在记录,无需创建`);
} catch (error) { } catch (error) {
this.logger.error(`检查并记录今日登录失败: ${error.message}`, error.stack); this.logger.error(`检查并记录今日登录失败: ${error.message}`, error.stack);
// 不抛出错误,避免影响主要业务流程 // 不抛出错误,避免影响主要业务流程