package logic import ( "context" "GtDataStore/app/cmd/organization/internal/svc" "GtDataStore/app/cmd/organization/pb" "github.com/zeromicro/go-zero/core/logx" ) type FindWorkingUfByCycleLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewFindWorkingUfByCycleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindWorkingUfByCycleLogic { return &FindWorkingUfByCycleLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *FindWorkingUfByCycleLogic) FindWorkingUfByCycle(in *pb.FindWorkingUfByCycleReq) (*pb.FindWorkingUfByCycleResp, error) { // 查询本次CEB的时间, 也就是cycle为0时的时间. 误差为一个周期 var lastId int64 = 0 lastRecord, err := l.svcCtx.WorkingUf.FindLastByCycleAndStep(l.ctx, in.ProjectId, in.DeviceCode, in.FilterCycle-1, in.Step) if err == nil { lastId = lastRecord.Id } res, err := l.svcCtx.WorkingUf.FindForCycleAndStep(l.ctx, lastId, in.ProjectId, in.DeviceCode, in.FilterCycle, in.Step, in.FilterTimeStart, in.FilterTimeEnd, in.Limit) if err != nil { return nil, err } list := make([]*pb.WorkingUf, len(res)) for i, one := range res { list[i] = &pb.WorkingUf{ Id: one.Id, ProjectId: one.ProjectId, DeviceCode: one.DeviceCode, WaterTemperature: one.WaterTemperature, FeedFlow: one.FeedFlow, ConFlow: one.ConFlow, ProductFlow: one.ProductFlow, FeedPressure: one.FeedPressure, ConPressure: one.ConPressure, ProductPressure: one.ProductPressure, Tmp: one.Tmp, Flux: one.Flux, Permeability: one.Permeability, FeedWqTurbidity: one.FeedWqTurbidity, FeedWqPh: one.FeedWqPh, ProductWqPh: one.ProductWqPh, FeedWqAl: one.FeedWqAl, ProductWqAl: one.ProductWqAl, FeedWqFe: one.FeedWqFe, ProductWqFe: one.ProductWqFe, FeedWqMn: one.FeedWqMn, ProductWqMn: one.ProductWqMn, FeedWqSio2: one.FeedWqSio2, ProductWqSio2: one.ProductWqSio2, FeedWqCod: one.FeedWqCod, ProductWqCod: one.ProductWqCod, FeedWqP: one.FeedWqP, ProductWqP: one.ProductWqP, Step: one.Step, FilterCycle: one.FilterCycle, FilterTime: one.FilterTime, CTime: one.CTime.Format("2006-01-02 15:04:05"), } } return &pb.FindWorkingUfByCycleResp{List: list}, nil }