f
This commit is contained in:
@@ -2,12 +2,15 @@ package admin_user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
"bdrp-server/app/main/model"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/samber/lo"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/mr"
|
||||
@@ -36,15 +39,7 @@ func (l *AdminGetUserListLogic) AdminGetUserList(req *types.AdminGetUserListReq)
|
||||
// 构建查询条件
|
||||
builder := l.svcCtx.AdminUserModel.SelectBuilder().
|
||||
Where("del_state = ?", 0)
|
||||
if len(req.Username) > 0 {
|
||||
builder = builder.Where("username LIKE ?", "%"+req.Username+"%")
|
||||
}
|
||||
if len(req.RealName) > 0 {
|
||||
builder = builder.Where("real_name LIKE ?", "%"+req.RealName+"%")
|
||||
}
|
||||
if req.Status != -1 {
|
||||
builder = builder.Where("status = ?", req.Status)
|
||||
}
|
||||
builder = applyAdminUserListFilters(builder, req)
|
||||
|
||||
// 设置分页
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
@@ -76,15 +71,7 @@ func (l *AdminGetUserListLogic) AdminGetUserList(req *types.AdminGetUserListReq)
|
||||
} else if taskType == 2 {
|
||||
countBuilder := l.svcCtx.AdminUserModel.SelectBuilder().
|
||||
Where("del_state = ?", 0)
|
||||
if len(req.Username) > 0 {
|
||||
countBuilder = countBuilder.Where("username LIKE ?", "%"+req.Username+"%")
|
||||
}
|
||||
if len(req.RealName) > 0 {
|
||||
countBuilder = countBuilder.Where("real_name LIKE ?", "%"+req.RealName+"%")
|
||||
}
|
||||
if req.Status != -1 {
|
||||
countBuilder = countBuilder.Where("status = ?", req.Status)
|
||||
}
|
||||
countBuilder = applyAdminUserListFilters(countBuilder, req)
|
||||
|
||||
count, err := l.svcCtx.AdminUserModel.FindCount(l.ctx, countBuilder, "id")
|
||||
if err != nil {
|
||||
@@ -147,3 +134,38 @@ func (l *AdminGetUserListLogic) AdminGetUserList(req *types.AdminGetUserListReq)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func applyAdminUserListFilters(builder squirrel.SelectBuilder, req *types.AdminGetUserListReq) squirrel.SelectBuilder {
|
||||
if username := strings.TrimSpace(req.Username); username != "" {
|
||||
builder = builder.Where("username LIKE ?", "%"+username+"%")
|
||||
}
|
||||
if realName := strings.TrimSpace(req.RealName); realName != "" {
|
||||
builder = builder.Where("real_name LIKE ?", "%"+realName+"%")
|
||||
}
|
||||
if req.Status != -1 {
|
||||
builder = builder.Where("status = ?", req.Status)
|
||||
}
|
||||
if startTime, ok := parseAdminUserListTime(req.StartTime, false); ok {
|
||||
builder = builder.Where("create_time >= ?", startTime)
|
||||
}
|
||||
if endTime, ok := parseAdminUserListTime(req.EndTime, true); ok {
|
||||
builder = builder.Where("create_time <= ?", endTime)
|
||||
}
|
||||
return builder
|
||||
}
|
||||
|
||||
func parseAdminUserListTime(raw string, isEnd bool) (time.Time, bool) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return time.Time{}, false
|
||||
}
|
||||
for _, layout := range []string{"2006-01-02 15:04:05", "2006-01-02", time.RFC3339} {
|
||||
if t, err := time.Parse(layout, raw); err == nil {
|
||||
if layout == "2006-01-02" && isEnd {
|
||||
t = t.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
}
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user