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
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:
@@ -0,0 +1,76 @@
|
||||
package analysisuserlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
equipmentpb "lone-services/rpc/equipment/pb"
|
||||
"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"
|
||||
)
|
||||
|
||||
const skinAnalyzerType int32 = 3
|
||||
|
||||
type DeviceBindLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeviceBindLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeviceBindLogic {
|
||||
return &DeviceBindLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeviceBindLogic) DeviceBind(in *analysis.DeviceBindReq) (*analysis.Response, error) {
|
||||
var req validator.DeviceBindValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
loginUser := utils.GetUserFromCtx(l.ctx)
|
||||
if !loginUser.Valid || loginUser.ID < utils.NumberOne {
|
||||
return common.FailResponse(utils.ErrorNoLogin), nil
|
||||
}
|
||||
skinType, ok := common.SkinTypeOf(loginUser.ClientCode)
|
||||
if !ok {
|
||||
return common.FailResponse(utils.ErrorAuthority), nil
|
||||
}
|
||||
if l.svcCtx.EquipmentSvcName == utils.StringEmpty {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.EquipmentSvcName)
|
||||
if err != nil {
|
||||
l.Errorf("device bind get equipment rpc: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
out, err := equipmentpb.NewEquipmentClient(cli.Conn()).InternalBindAdd(l.ctx, &equipmentpb.InternalBindAddRequest{
|
||||
UserId: loginUser.ID,
|
||||
UserNickname: loginUser.Name,
|
||||
HostNickname: utils.StringEmpty,
|
||||
HostCode: req.DeviceNo,
|
||||
Type: skinAnalyzerType,
|
||||
SkinType: skinType,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("device bind internal add: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if out == nil {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
return &analysis.Response{
|
||||
Code: out.Code,
|
||||
Msg: out.Msg,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package analysisuserlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
equipmentpb "lone-services/rpc/equipment/pb"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeviceInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeviceInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeviceInfoLogic {
|
||||
return &DeviceInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeviceInfoLogic) DeviceInfo(in *analysis.DeviceInfoReq) (*analysis.Response, error) {
|
||||
loginUser := utils.GetUserFromCtx(l.ctx)
|
||||
if !loginUser.Valid || loginUser.ID < utils.NumberOne {
|
||||
return common.FailResponse(utils.ErrorNoLogin), nil
|
||||
}
|
||||
skinType, ok := common.SkinTypeOf(loginUser.ClientCode)
|
||||
if !ok {
|
||||
return common.FailResponse(utils.ErrorAuthority), nil
|
||||
}
|
||||
if l.svcCtx.EquipmentSvcName == utils.StringEmpty {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.EquipmentSvcName)
|
||||
if err != nil {
|
||||
l.Errorf("device info get equipment rpc: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
out, err := equipmentpb.NewEquipmentClient(cli.Conn()).InternalBindInfo(l.ctx, &equipmentpb.InternalBindInfoRequest{
|
||||
UserId: loginUser.ID,
|
||||
SkinType: skinType,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("device info internal: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if out == nil {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
return &analysis.Response{
|
||||
Code: out.Code,
|
||||
Msg: out.Msg,
|
||||
Data: out.Data,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package analysisuserlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UserAuthDeleteLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserAuthDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAuthDeleteLogic {
|
||||
return &UserAuthDeleteLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserAuthDeleteLogic) UserAuthDelete(in *analysis.UserAuthDeleteReq) (*analysis.Response, error) {
|
||||
var req validator.UserAuthDeleteValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
bizId, _, fail := common.RequireAnalysisUserId(l.ctx)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
if _, err := common.DisableStoreAuth(req.Id, bizId); err != nil {
|
||||
l.Errorf("user auth delete: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
return common.OkResponse(nil), nil
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (l *UserAuthLogic) UserAuth(in *analysis.UserAuthReq) (*analysis.Response,
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
loginUser, fail := common.RequireUserLogin(l.ctx)
|
||||
bizId, _, fail := common.RequireAnalysisUserId(l.ctx)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
@@ -52,11 +52,7 @@ func (l *UserAuthLogic) UserAuth(in *analysis.UserAuthReq) (*analysis.Response,
|
||||
}
|
||||
|
||||
if req.Type == int32(utils.StoreAuthBind) {
|
||||
bizId := loginUser.BizId
|
||||
if bizId < utils.NumberOne {
|
||||
return common.OutResponse(utils.ErrorParams, "业务用户不存在"), nil
|
||||
}
|
||||
if err := common.BindStoreAuth(loginUser.ID, bizId, req.StoreId, req.ValidityTime); err != nil {
|
||||
if err := common.BindStoreAuth(bizId, req.StoreId, req.ValidityTime); err != nil {
|
||||
l.Errorf("user auth bind: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package analysisuserlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UserAuthUpdateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserAuthUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAuthUpdateLogic {
|
||||
return &UserAuthUpdateLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserAuthUpdateLogic) UserAuthUpdate(in *analysis.UserAuthUpdateReq) (*analysis.Response, error) {
|
||||
var req validator.UserAuthUpdateValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
bizId, _, fail := common.RequireAnalysisUserId(l.ctx)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
if _, err := common.UpdateStoreAuthTime(req.Id, bizId, req.ValidityTime); err != nil {
|
||||
l.Errorf("user auth update: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
return common.OkResponse(nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user