feat: 密码不允许使用最近修改的密码功能
This commit is contained in:
79
src/modules/system/repository/sys_log_user_password.go
Normal file
79
src/modules/system/repository/sys_log_user_password.go
Normal 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(¶m).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
|
||||
}
|
||||
Reference in New Issue
Block a user