getWorkingValveByCodeLogic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package logic
  2. import (
  3. "GtDataStore/app/cmd/organization/internal/svc"
  4. "GtDataStore/app/cmd/organization/pb"
  5. "GtDataStore/app/model"
  6. "context"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type GetWorkingValveByCodeLogic struct {
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. logx.Logger
  13. }
  14. func NewGetWorkingValveByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWorkingValveByCodeLogic {
  15. return &GetWorkingValveByCodeLogic{
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. Logger: logx.WithContext(ctx),
  19. }
  20. }
  21. func (l *GetWorkingValveByCodeLogic) GetWorkingValveByCode(in *pb.DcWorkingReq) (*pb.GetWorkingValveByCodeResp, error) {
  22. offset := (in.Page - 1) * in.PageSize
  23. res, err := l.svcCtx.WorkingValve.Search(l.ctx, in.ProjectId, in.DeviceCode, in.Stime, in.Etime, offset, in.PageSize, in.Order)
  24. if err != nil && err != model.ErrNotFound {
  25. return nil, err
  26. }
  27. list := make([]*pb.WorkingValve, len(res))
  28. for i, one := range res {
  29. list[i] = &pb.WorkingValve{
  30. Id: one.Id,
  31. ProjectId: one.ProjectId,
  32. DeviceCode: one.DeviceCode,
  33. Adjust: one.Adjust,
  34. Opening: one.Opening,
  35. Closed: one.Closed,
  36. Opened: one.Opened,
  37. FaultStatus: one.FaultStatus,
  38. CTime: one.CTime.Format("2006-01-02 15:04:05"),
  39. }
  40. }
  41. return &pb.GetWorkingValveByCodeResp{
  42. List: list,
  43. }, nil
  44. }