package logic import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" admin "lone-services/rpc/admin/pb" "lone-services/services/admin/internal/dao" "lone-services/services/admin/internal/model" "lone-services/services/admin/internal/svc" "lone-services/services/admin/validator" "strconv" "github.com/zeromicro/go-zero/core/logx" ) type AuthorityInfoLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger BaseLogic } func NewAuthorityInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorityInfoLogic { return &AuthorityInfoLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *AuthorityInfoLogic) AuthorityInfo(in *admin.InfoRequest) (*admin.Response, error) { var v validator.AuthorityInfoValidator if fail := l.checkParams(in, &v); fail != nil { return fail, nil } info := dao.AuthorityInfo{} modelObj := model.AuthorityModel{}.Init() w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}} err := modelObj.GetOne(w, &info) if err != nil { return l.fail(utils.ErrorNotFund) } new := dao.AuthorityInfoNew{ AuthorityInfo: info, } if info.Type == dao.TypeData { var items []dao.AuthorityGetJsonIds w = modelbase.Params{Other: map[string]string{"FIND_IN_SET(?, data_ids)": strconv.FormatInt(info.Id, utils.NumberTen)}} err = modelObj.Items(w, &items) if len(items) == utils.NumberThree { w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(items[utils.NumberZero].Id, utils.NumberTen)}} err = modelObj.GetOne(w, &info) new = dao.AuthorityInfoNew{ AuthorityInfo: info, } new.JsonDataAll = items[utils.NumberZero].JsonTreeData new.JsonDataDepartment = items[utils.NumberOne].JsonTreeData new.JsonDataOneself = items[utils.NumberTwo].JsonTreeData } } return l.ok(new) }