service.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package commonsrv
  2. import (
  3. "Cold_Logistic/internal/pkg/common/global"
  4. "Cold_Logistic/internal/server/infra/dao"
  5. "Cold_Logistic/internal/server/infra/models"
  6. "Cold_Logistic/internal/server/infra/thirdparty/internalservice/clod"
  7. "context"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  10. )
  11. type CommonService struct {
  12. store *dao.DataStore
  13. }
  14. func NewCommonService(store *dao.DataStore) *CommonService {
  15. return &CommonService{store: store}
  16. }
  17. func (srv *CommonService) ProvinceList(ctx context.Context) (res []*ProvinceListRespVO, err error) {
  18. all, err := srv.store.Region().FindAll(ctx)
  19. if err != nil {
  20. return nil, errors.WithStackOnce(err)
  21. }
  22. res = buildRegionTree(res, all)
  23. return res, nil
  24. }
  25. func buildRegionTree(result []*ProvinceListRespVO, all []models.Region) []*ProvinceListRespVO {
  26. for _, v := range all {
  27. if v.ParentId == 0 {
  28. result = append(result, &ProvinceListRespVO{
  29. Id: v.Id,
  30. Name: v.Name,
  31. Children: make([]*ProvinceListRespVO, 0),
  32. })
  33. continue
  34. }
  35. for _, r := range result {
  36. if r.Id == v.ParentId {
  37. r.Children = append(r.Children, &ProvinceListRespVO{
  38. ParentId: v.ParentId,
  39. Id: v.Id,
  40. Name: v.Name,
  41. Children: make([]*ProvinceListRespVO, 0),
  42. })
  43. break
  44. }
  45. buildRegionTree(r.Children, []models.Region{v})
  46. }
  47. }
  48. return result
  49. }
  50. // UserList 冷链3.0用户列表
  51. func (srv *CommonService) UserList(ctx context.Context, req UserListReqVO) (res core.PageListResponse, err error) {
  52. if req.UserTokey == "" {
  53. accId := global.GetTokenInfoFromContext(ctx).AccountId
  54. req.UserTokey, err = srv.store.Account().FindTokenKeyById(ctx, accId)
  55. if err != nil {
  56. return res, errors.WithStackOnce(err)
  57. }
  58. }
  59. result, err := clod.NewBzdClodService().UserList(ctx, clod.UserListParam{
  60. UserToken: req.UserTokey,
  61. Name: req.Search.Name,
  62. Page: req.Page.Page,
  63. Page_z: req.Page.Size,
  64. })
  65. if err != nil {
  66. return res, errors.WithStackOnce(err)
  67. }
  68. res.Total = result.Num
  69. res.TotalPage = result.PageSize
  70. res.Count = len(result.Data)
  71. res.List = result.Data
  72. return res, nil
  73. }
  74. // LogisticList 物流公司列表
  75. func (srv *CommonService) LogisticList(ctx context.Context, req LogisticListReqVO) (res core.PageListResponse, err error) {
  76. if req.UserTokey == "" {
  77. accId := global.GetTokenInfoFromContext(ctx).AccountId
  78. req.UserTokey, err = srv.store.Account().FindTokenKeyById(ctx, accId)
  79. if err != nil {
  80. return res, errors.WithStackOnce(err)
  81. }
  82. }
  83. result, err := clod.NewBzdClodService().LogisticCompanyList(ctx, clod.LogisticCompanyListParam{
  84. UserTokey: req.UserTokey,
  85. TName: req.Search.Name,
  86. Page: req.Page.Page,
  87. Page_z: req.Page.Size,
  88. })
  89. if err != nil {
  90. return res, errors.WithStackOnce(err)
  91. }
  92. res.Total = result.Num
  93. res.TotalPage = result.PageSize
  94. res.Count = len(result.Data)
  95. res.List = result.Data
  96. return res, nil
  97. }