feat: scan graph
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 37s
CI / bff (push) Successful in 18s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 22s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 21s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 37s
CI / bff (push) Successful in 18s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 22s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 21s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
package analysisadminlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
userpb "lone-services/rpc/user/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type StoreListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewStoreListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreListLogic {
|
||||
return &StoreListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *StoreListLogic) StoreList(in *analysis.AdminStoreListReq) (*analysis.Response, error) {
|
||||
var req validator.AdminStoreListValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outParams(msg), nil
|
||||
}
|
||||
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
keyword := strings.TrimSpace(req.Keyword)
|
||||
var storeBizIds []int64
|
||||
filterByStore := false
|
||||
if keyword != utils.StringEmpty {
|
||||
pageData, err := loadStorePage(l.ctx, keyword, 1, 1000, 0)
|
||||
if err != nil {
|
||||
l.Errorf("admin store list search store: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if len(pageData.Items) > utils.NumberZero {
|
||||
filterByStore = true
|
||||
storeBizIds = make([]int64, 0, len(pageData.Items))
|
||||
for _, row := range pageData.Items {
|
||||
if row.Id > utils.NumberZero {
|
||||
storeBizIds = append(storeBizIds, row.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var accounts []*userpb.BizUserItem
|
||||
var err error
|
||||
if filterByStore {
|
||||
accounts, err = l.loadStoreAccounts(storeBizIds)
|
||||
} else {
|
||||
accounts, err = l.loadStoreAccounts(nil)
|
||||
if err == nil && keyword != utils.StringEmpty {
|
||||
accounts = filterStoreAccountsByKeyword(accounts, keyword)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
l.Errorf("admin store list accounts: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if len(accounts) == utils.NumberZero {
|
||||
return common.OkResponse(modelbase.PageResult{Items: []dao.AdminStoreListItem{}}), nil
|
||||
}
|
||||
|
||||
storeIds := make([]int64, 0, len(accounts))
|
||||
seen := make(map[int64]struct{}, len(accounts))
|
||||
for _, acc := range accounts {
|
||||
if acc.GetBizId() < utils.NumberOne {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[acc.GetBizId()]; ok {
|
||||
continue
|
||||
}
|
||||
seen[acc.GetBizId()] = struct{}{}
|
||||
storeIds = append(storeIds, acc.GetBizId())
|
||||
}
|
||||
storeMap, err := loadStoresByIds(l.ctx, storeIds)
|
||||
if err != nil {
|
||||
l.Errorf("admin store list stores: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
all := make([]dao.AdminStoreListItem, 0, len(accounts))
|
||||
for _, acc := range accounts {
|
||||
store, ok := storeMap[acc.GetBizId()]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
mobile, _ := utils.DecryptPhone(acc.GetMobile())
|
||||
if mobile == utils.StringEmpty {
|
||||
mobile = acc.GetMobile()
|
||||
}
|
||||
storeMobile := store.GetUserMobile()
|
||||
if plain, dErr := utils.DecryptPhone(storeMobile); dErr == nil && plain != utils.StringEmpty {
|
||||
storeMobile = plain
|
||||
}
|
||||
all = append(all, dao.AdminStoreListItem{
|
||||
Id: acc.GetUserId(),
|
||||
StoreId: store.GetId(),
|
||||
Account: utils.DecryptPhoneReplace(mobile),
|
||||
StoreName: store.GetName(),
|
||||
StoreUserName: store.GetUserName(),
|
||||
StoreUserMobile: utils.DecryptPhoneReplace(storeMobile),
|
||||
District: store.GetDistrictIds(),
|
||||
DistrictText: storeDistrictTextFromInfo(store),
|
||||
Address: store.GetAddress(),
|
||||
})
|
||||
}
|
||||
|
||||
count, pageItems := pageSlice(all, req.Page, req.Size)
|
||||
return common.OkResponse(modelbase.PageResult{
|
||||
Count: count,
|
||||
Items: pageItems,
|
||||
}), nil
|
||||
}
|
||||
|
||||
func filterStoreAccountsByKeyword(accounts []*userpb.BizUserItem, keyword string) []*userpb.BizUserItem {
|
||||
if keyword == utils.StringEmpty || len(accounts) == utils.NumberZero {
|
||||
return accounts
|
||||
}
|
||||
enc := utils.GetSearchPhone(keyword)
|
||||
out := make([]*userpb.BizUserItem, 0, len(accounts))
|
||||
for _, acc := range accounts {
|
||||
mobile := acc.GetMobile()
|
||||
if enc != utils.StringEmpty && strings.Contains(mobile, enc) {
|
||||
out = append(out, acc)
|
||||
continue
|
||||
}
|
||||
plain, _ := utils.DecryptPhone(mobile)
|
||||
if plain != utils.StringEmpty && strings.Contains(plain, keyword) {
|
||||
out = append(out, acc)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (l *StoreListLogic) loadStoreAccounts(bizIds []int64) ([]*userpb.BizUserItem, error) {
|
||||
if l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return nil, status.Error(codes.FailedPrecondition, "user service empty")
|
||||
}
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := userpb.NewUserClient(cli.Conn()).InternalUsersByBiz(l.ctx, &userpb.InternalUsersByBizReq{
|
||||
ClientCode: dao.ClientCodeStoreSkin,
|
||||
BizIds: bizIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.GetItems(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user