findWorkingUfByCycleLogic.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package logic
  2. import (
  3. "context"
  4. "GtDataStore/app/cmd/organization/internal/svc"
  5. "GtDataStore/app/cmd/organization/pb"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type FindWorkingUfByCycleLogic struct {
  9. ctx context.Context
  10. svcCtx *svc.ServiceContext
  11. logx.Logger
  12. }
  13. func NewFindWorkingUfByCycleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindWorkingUfByCycleLogic {
  14. return &FindWorkingUfByCycleLogic{
  15. ctx: ctx,
  16. svcCtx: svcCtx,
  17. Logger: logx.WithContext(ctx),
  18. }
  19. }
  20. func (l *FindWorkingUfByCycleLogic) FindWorkingUfByCycle(in *pb.FindWorkingUfByCycleReq) (*pb.FindWorkingUfByCycleResp, error) {
  21. // 查询本次CEB的时间, 也就是cycle为0时的时间. 误差为一个周期
  22. var lastId int64 = 0
  23. lastRecord, err := l.svcCtx.WorkingUf.FindLastByCycleAndStep(l.ctx, in.ProjectId, in.DeviceCode, in.FilterCycle-1, in.Step)
  24. if err == nil {
  25. lastId = lastRecord.Id
  26. }
  27. res, err := l.svcCtx.WorkingUf.FindForCycleAndStep(l.ctx, lastId, in.ProjectId, in.DeviceCode, in.FilterCycle, in.Step, in.FilterTimeStart, in.FilterTimeEnd, in.Limit)
  28. if err != nil {
  29. return nil, err
  30. }
  31. list := make([]*pb.WorkingUf, len(res))
  32. for i, one := range res {
  33. list[i] = &pb.WorkingUf{
  34. Id: one.Id,
  35. ProjectId: one.ProjectId,
  36. DeviceCode: one.DeviceCode,
  37. WaterTemperature: one.WaterTemperature,
  38. FeedFlow: one.FeedFlow,
  39. ConFlow: one.ConFlow,
  40. ProductFlow: one.ProductFlow,
  41. FeedPressure: one.FeedPressure,
  42. ConPressure: one.ConPressure,
  43. ProductPressure: one.ProductPressure,
  44. Tmp: one.Tmp,
  45. Flux: one.Flux,
  46. Permeability: one.Permeability,
  47. FeedWqTurbidity: one.FeedWqTurbidity,
  48. FeedWqPh: one.FeedWqPh,
  49. ProductWqPh: one.ProductWqPh,
  50. FeedWqAl: one.FeedWqAl,
  51. ProductWqAl: one.ProductWqAl,
  52. FeedWqFe: one.FeedWqFe,
  53. ProductWqFe: one.ProductWqFe,
  54. FeedWqMn: one.FeedWqMn,
  55. ProductWqMn: one.ProductWqMn,
  56. FeedWqSio2: one.FeedWqSio2,
  57. ProductWqSio2: one.ProductWqSio2,
  58. FeedWqCod: one.FeedWqCod,
  59. ProductWqCod: one.ProductWqCod,
  60. FeedWqP: one.FeedWqP,
  61. ProductWqP: one.ProductWqP,
  62. Step: one.Step,
  63. FilterCycle: one.FilterCycle,
  64. FilterTime: one.FilterTime,
  65. CTime: one.CTime.Format("2006-01-02 15:04:05"),
  66. }
  67. }
  68. return &pb.FindWorkingUfByCycleResp{List: list}, nil
  69. }