f
This commit is contained in:
77
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
77
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
)
|
||||
|
||||
type GetWhitelistListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetWhitelistListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitelistListLogic {
|
||||
return &GetWhitelistListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func statusToText(status int64) string {
|
||||
switch status {
|
||||
case 1:
|
||||
return "生效"
|
||||
case 2:
|
||||
return "已失效"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWhitelistListLogic) GetWhitelistList(req *types.GetWhitelistListReq) (resp *types.GetWhitelistListResp, err error) {
|
||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||
}
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.PageSize <= 0 || req.PageSize > 100 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
builder := l.svcCtx.UserFeatureWhitelistModel.SelectBuilder().Where("user_id = ?", userID)
|
||||
if req.IdCard != "" {
|
||||
builder = builder.Where("id_card = ?", req.IdCard)
|
||||
}
|
||||
list, total, err := l.svcCtx.UserFeatureWhitelistModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询白名单列表失败, %v", err)
|
||||
}
|
||||
items := make([]types.WhitelistItem, 0, len(list))
|
||||
for _, r := range list {
|
||||
featureName := r.FeatureApiId
|
||||
if f, e := l.svcCtx.FeatureModel.FindOne(l.ctx, r.FeatureId); e == nil {
|
||||
featureName = f.Name
|
||||
}
|
||||
items = append(items, types.WhitelistItem{
|
||||
Id: r.Id,
|
||||
IdCard: r.IdCard,
|
||||
FeatureId: r.FeatureId,
|
||||
FeatureApiId: r.FeatureApiId,
|
||||
FeatureName: featureName,
|
||||
Amount: r.Amount,
|
||||
Status: r.Status,
|
||||
StatusText: statusToText(r.Status),
|
||||
CreateTime: r.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &types.GetWhitelistListResp{Total: total, List: items}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user