This commit is contained in:
2026-04-28 17:55:09 +08:00
parent 83a1c5ca8a
commit 0817e73dc4
3 changed files with 41 additions and 0 deletions
+13
View File
@@ -36,3 +36,16 @@
- `InitUsersRouter` 中新增 `AutoMigrate(&TabUserLoginFailLog{})`
- 登录成功时清除该用户失败记录;密码错误和用户不存在时调用 `recordLoginFail()` 记录/更新失败日志(24小时内累计次数)
- `recordLoginFail()``TabUserLoginFailLog` 结构体后定义
## apiWarehouse.go 查重完善
- `add_container` 接口:添加同层级容器 Title 查重(`parent_id` + `title` + `deleted_at IS NULL`),重复返回 `container_title_exist`
- `add_item` 接口:已有查重逻辑(`Name` + `SerialNumber`)保持不变
## 完善 updateSysAdminsCash 函数
- 原函数为空,现实现:
1. 查询 `admins` 用户组 ID
2. 查询该组所有成员的 `TabUserGroupBinds` 记录
3. 提取所有 `UserID` 更新到 `sysAdmins` 缓存切片
4. 组不存在或查询失败时清空缓存
+20
View File
@@ -85,7 +85,27 @@ var (
)
func updateSysAdminsCash() {
// 查询 admins 用户组的 ID
var adminGroup TabUserGroups
if models.DB.Where("name = ?", "admins").First(&adminGroup).Error != nil {
// admins 组不存在,清空缓存
sysAdmins = []uint{}
return
}
// 查询 admins 组的所有成员
var binds []TabUserGroupBinds
if models.DB.Where("group_id = ?", adminGroup.ID).Find(&binds).Error != nil {
sysAdmins = []uint{}
return
}
// 更新缓存
newAdmins := make([]uint, 0, len(binds))
for _, bind := range binds {
newAdmins = append(newAdmins, bind.UserID)
}
sysAdmins = newAdmins
}
// recordLoginFail 记录登录失败日志,更新连续失败次数
+8
View File
@@ -210,6 +210,14 @@ func ApiWarehouse(r *gin.RouterGroup) {
}
}
// 查重:同层级下 Title 不能重复
// var dupContainer TabWarehouseContainer
// dupQuery := models.DB.Where("title = ? AND parent_id = ? AND deleted_at IS NULL", from.Title, from.ParentID)
// if dupQuery.First(&dupContainer).Error == nil {
// ReturnJson(ctx, "container_title_exist", nil)
// return
// }
color := from.Color
if color == "" {
color = "#3788d9"