feat: device info and bind
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 31s
CI / admin (push) Successful in 24s
CI / bff (push) Successful in 31s
CI / chore (push) Successful in 27s
CI / equipment (push) Successful in 21s
CI / express (push) Successful in 23s
CI / factory (push) Successful in 21s
CI / message (push) Successful in 21s
CI / order (push) Successful in 22s
CI / payment (push) Successful in 20s
CI / percutaneous (push) Successful in 20s
CI / product (push) Successful in 20s
CI / record (push) Successful in 19s
CI / sale (push) Successful in 19s
CI / support (push) Successful in 20s
CI / task (push) Successful in 19s
CI / user (push) Successful in 21s
CI / wecom (push) Successful in 22s

This commit is contained in:
zzw
2026-10-16 15:36:17 +08:00
parent a65b6d2803
commit 46d3f672bf
42 changed files with 2142 additions and 197 deletions
@@ -0,0 +1,112 @@
package analysisuserlogic
import (
"context"
"time"
"lone-services/pkg/utils"
analysis "lone-services/rpc/analysis/pb"
storepb "lone-services/rpc/store/pb"
"lone-services/services/analysis/internal/dao"
"lone-services/services/analysis/internal/logic/common"
"lone-services/services/analysis/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const authTimeLayout = "2006-01-02 15:04"
type UserAuthListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUserAuthListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAuthListLogic {
return &UserAuthListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UserAuthListLogic) UserAuthList(in *analysis.UserAuthListReq) (*analysis.Response, error) {
bizId, _, fail := common.RequireAnalysisUserId(l.ctx)
if fail != nil {
return fail, nil
}
authList, err := common.ListStoreAuth(bizId)
if err != nil {
l.Errorf("user auth list: %v", err)
return common.FailResponse(utils.Fail), nil
}
if len(authList) == utils.NumberZero {
return common.OkResponse([]dao.StoreAuthItem{}), nil
}
storeMap, err := l.loadStores(authList)
if err != nil {
l.Errorf("user auth list stores: %v", err)
return common.FailResponse(utils.Fail), nil
}
now := time.Now()
list := make([]dao.StoreAuthItem, 0, len(authList))
for _, row := range authList {
store, ok := storeMap[row.StoreId]
if !ok {
continue
}
itemStatus := int(dao.StatusEnabled)
if row.ValidityTime.Time.Before(now) {
itemStatus = int(dao.StatusDisabled)
}
list = append(list, dao.StoreAuthItem{
Id: row.Id,
StoreId: store.Id,
Name: store.Name,
Address: store.Address,
ValidityTime: row.ValidityTime.Format(authTimeLayout),
CreatedAt: row.CreatedAt.Format(authTimeLayout),
Status: itemStatus,
})
}
return common.OkResponse(list), nil
}
func (l *UserAuthListLogic) loadStores(authList []dao.UserStoreAuth) (map[int64]*storepb.InfoResponse, error) {
ids := make([]int64, 0, len(authList))
seen := make(map[int64]struct{}, len(authList))
for _, row := range authList {
if _, ok := seen[row.StoreId]; ok {
continue
}
seen[row.StoreId] = struct{}{}
ids = append(ids, row.StoreId)
}
svcName := utils.GetConfigString("services.store")
if svcName == utils.StringEmpty {
return nil, status.Error(codes.FailedPrecondition, "store service empty")
}
cli, err := svc.GetRpcClient(svcName)
if err != nil {
return nil, err
}
res, err := storepb.NewStoreClient(cli.Conn()).GetInfoByIds(l.ctx, &storepb.IdsRequest{Ids: ids})
if err != nil {
if st, ok := status.FromError(err); ok && st.Message() == utils.ErrorNotFund.Msg {
return map[int64]*storepb.InfoResponse{}, nil
}
return nil, err
}
storeMap := make(map[int64]*storepb.InfoResponse, len(res.GetItems()))
for _, item := range res.GetItems() {
storeMap[item.Id] = item
}
return storeMap, nil
}