package commonsrv import ( "Cold_Logistic/internal/pkg/common/global" "Cold_Logistic/internal/server/infra/dao" "Cold_Logistic/internal/server/infra/models" "Cold_Logistic/internal/server/infra/thirdparty/internalservice/clod" "context" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors" ) type CommonService struct { store *dao.DataStore } func NewCommonService(store *dao.DataStore) *CommonService { return &CommonService{store: store} } func (srv *CommonService) ProvinceList(ctx context.Context) (res []*ProvinceListRespVO, err error) { all, err := srv.store.Region().FindAll(ctx) if err != nil { return nil, errors.WithStackOnce(err) } res = buildRegionTree(res, all) return res, nil } func buildRegionTree(result []*ProvinceListRespVO, all []models.Region) []*ProvinceListRespVO { for _, v := range all { if v.ParentId == 0 { result = append(result, &ProvinceListRespVO{ Id: v.Id, Name: v.Name, Children: make([]*ProvinceListRespVO, 0), }) continue } for _, r := range result { if r.Id == v.ParentId { r.Children = append(r.Children, &ProvinceListRespVO{ ParentId: v.ParentId, Id: v.Id, Name: v.Name, Children: make([]*ProvinceListRespVO, 0), }) break } buildRegionTree(r.Children, []models.Region{v}) } } return result } // UserList 冷链3.0用户列表 func (srv *CommonService) UserList(ctx context.Context, req UserListReqVO) (res core.PageListResponse, err error) { if req.UserTokey == "" { accId := global.GetTokenInfoFromContext(ctx).AccountId req.UserTokey, err = srv.store.Account().FindTokenKeyById(ctx, accId) if err != nil { return res, errors.WithStackOnce(err) } } result, err := clod.NewBzdClodService().UserList(ctx, clod.UserListParam{ UserToken: req.UserTokey, Name: req.Search.Name, Page: req.Page.Page, Page_z: req.Page.Size, }) if err != nil { return res, errors.WithStackOnce(err) } res.Total = result.Num res.TotalPage = result.PageSize res.Count = len(result.Data) res.List = result.Data return res, nil } // LogisticList 物流公司列表 func (srv *CommonService) LogisticList(ctx context.Context, req LogisticListReqVO) (res core.PageListResponse, err error) { if req.UserTokey == "" { accId := global.GetTokenInfoFromContext(ctx).AccountId req.UserTokey, err = srv.store.Account().FindTokenKeyById(ctx, accId) if err != nil { return res, errors.WithStackOnce(err) } } result, err := clod.NewBzdClodService().LogisticCompanyList(ctx, clod.LogisticCompanyListParam{ UserTokey: req.UserTokey, TName: req.Search.Name, Page: req.Page.Page, Page_z: req.Page.Size, }) if err != nil { return res, errors.WithStackOnce(err) } res.Total = result.Num res.TotalPage = result.PageSize res.Count = len(result.Data) res.List = result.Data return res, nil }