service.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package devicesrv
  2. import (
  3. "Cold_Logistic/internal/pkg/common/constant"
  4. "Cold_Logistic/internal/server/infra/dao"
  5. "Cold_Logistic/internal/server/infra/thirdparty/internalservice/clod"
  6. "context"
  7. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  9. "strconv"
  10. )
  11. type DeviceService struct {
  12. store *dao.DataStore
  13. }
  14. func NewDeviceService(store *dao.DataStore) *DeviceService {
  15. return &DeviceService{store: store}
  16. }
  17. func (srv DeviceService) DeviceSensorList(ctx context.Context, req DeviceSensorListReqVO) (res DeviceSensorListRespVO, err error) {
  18. clodSrv := clod.NewBzdClodService()
  19. list, err := clodSrv.DeviceSensorList(ctx, req.SnCode)
  20. if err != nil {
  21. return res, errors.WithStackOnce(err)
  22. }
  23. res.SnCode = req.SnCode
  24. res.SnIds = list
  25. return res, nil
  26. }
  27. func (srv DeviceService) SnDataList(ctx context.Context, req SnDataListReqVO) (res core.PageListResponse, err error) {
  28. clodSrv := clod.NewBzdClodService()
  29. ret, err := clodSrv.DeviceSensorDataList(ctx, clod.DeviceSensorDataListParam{
  30. User_tokey: req.UserTokey,
  31. T_snid: req.SnId,
  32. Time_start: req.Search.TimeStart.Format(constant.TimeCriterionFormat),
  33. Time_end: req.Search.TimeEnd.Format(constant.TimeCriterionFormat),
  34. Page: strconv.Itoa(req.Page.Page),
  35. Page_z: strconv.Itoa(req.Page.Size),
  36. })
  37. if err != nil {
  38. return res, errors.WithStackOnce(err)
  39. }
  40. res.Total = ret.Num
  41. res.TotalPage = ret.PageSize
  42. res.Count = len(ret.Data)
  43. res.List = ret
  44. return res, nil
  45. }