feat: 密码不允许使用最近修改的密码功能

This commit is contained in:
TsMask
2025-03-31 18:31:25 +08:00
parent 15baf77ad3
commit 46b66cda5b
5 changed files with 194 additions and 19 deletions

View File

@@ -0,0 +1,79 @@
package repository
import (
"time"
"be.ems/src/framework/database/db"
"be.ems/src/framework/logger"
"be.ems/src/modules/system/model"
)
// NewSysLogUserPassword 实例化数据层
var NewSysLogUserPassword = &SysLogUserPassword{}
// SysLogUserPasswordRepository 系统_用户密码变更日志表 数据层处理
type SysLogUserPassword struct{}
// SelectByUserId 通过用户ID日志 pageNum为0返回日志列表
func (r SysLogUserPassword) SelectByUserId(userId int64, pageNum int) []model.SysLogUserPassword {
rows := []model.SysLogUserPassword{}
if userId <= 0 {
return rows
}
tx := db.DB("").Model(&model.SysLogUserPassword{})
// 构建查询条件
tx = tx.Where("user_id = ?", userId)
// 查询数据分页
if pageNum > 0 {
tx = tx.Limit(pageNum)
}
err := tx.Order("create_time desc").Find(&rows).Error
if err != nil {
logger.Errorf("query find err => %v", err.Error())
return rows
}
return rows
}
// SelectCountByUserId 通过用户ID日志数量
func (r SysLogUserPassword) SelectCountByUserId(userId int64) int64 {
var total int64 = 0
if userId <= 0 {
return total
}
tx := db.DB("").Model(&model.SysLogUserPassword{})
// 构建查询条件
tx = tx.Where("user_id = ?", userId)
// 查询数量为0直接返回
if err := tx.Count(&total).Error; err != nil || total <= 0 {
return total
}
return total
}
// Insert 新增信息 返回新增的数据ID
func (r SysLogUserPassword) Insert(param model.SysLogUserPassword) int64 {
if param.CreateBy != "" {
param.CreateTime = time.Now().UnixMilli()
}
// 执行插入
if err := db.DB("").Create(&param).Error; err != nil {
logger.Errorf("insert err => %v", err.Error())
return 0
}
return param.ID
}
// DeleteByUserId 删除用户日志信息 返回受影响行数
func (r SysLogUserPassword) DeleteByUserId(userIds []int64) int64 {
if len(userIds) <= 0 {
return 0
}
tx := db.DB("").Where("user_id in ?", userIds)
// 执行删除
if err := tx.Delete(&model.SysLogUserPassword{}).Error; err != nil {
logger.Errorf("delete err => %v", err.Error())
return 0
}
return tx.RowsAffected
}