refactor(users): 更新用户活动表名并添加日志记录
将用户活动表名从'user_activities'改为't_user_activities',并在服务中添加详细的日志记录逻辑。
This commit is contained in:
@@ -47,7 +47,7 @@ export interface UserActivityAttributes {
|
||||
export interface UserActivityCreationAttributes extends Optional<UserActivityAttributes, 'id' | 'createdAt' | 'updatedAt' | 'remark'> { }
|
||||
|
||||
@Table({
|
||||
tableName: 'user_activities',
|
||||
tableName: 't_user_activities',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
|
||||
@@ -40,6 +40,8 @@ export class UserActivityService {
|
||||
const today = dayjs().format('YYYY-MM-DD'); // YYYY-MM-DD 格式
|
||||
|
||||
try {
|
||||
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}`);
|
||||
|
||||
const existingLogin = await this.userActivityModel.findOne({
|
||||
where: {
|
||||
userId,
|
||||
@@ -49,6 +51,7 @@ export class UserActivityService {
|
||||
});
|
||||
|
||||
if (!existingLogin) {
|
||||
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}, 不存在记录,自动创建`);
|
||||
await this.recordActivity(userId, {
|
||||
activityType: ActivityType.LOGIN,
|
||||
activityDate: today,
|
||||
@@ -56,6 +59,8 @@ export class UserActivityService {
|
||||
remark: '用户拉取profile接口自动记录',
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.log(`检查并记录今日登录 - 用户: ${userId}, 日期: ${today}, 已存在记录,无需创建`);
|
||||
} catch (error) {
|
||||
this.logger.error(`检查并记录今日登录失败: ${error.message}`, error.stack);
|
||||
// 不抛出错误,避免影响主要业务流程
|
||||
|
||||
Reference in New Issue
Block a user