package logic import ( "GtDataStore/app/cmd/organization/internal/svc" "GtDataStore/app/cmd/organization/pb" "GtDataStore/app/model" "context" "github.com/zeromicro/go-zero/core/logx" ) type GetWorkingValveByCodeLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetWorkingValveByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWorkingValveByCodeLogic { return &GetWorkingValveByCodeLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *GetWorkingValveByCodeLogic) GetWorkingValveByCode(in *pb.DcWorkingReq) (*pb.GetWorkingValveByCodeResp, error) { offset := (in.Page - 1) * in.PageSize res, err := l.svcCtx.WorkingValve.Search(l.ctx, in.ProjectId, in.DeviceCode, in.Stime, in.Etime, offset, in.PageSize, in.Order) if err != nil && err != model.ErrNotFound { return nil, err } list := make([]*pb.WorkingValve, len(res)) for i, one := range res { list[i] = &pb.WorkingValve{ Id: one.Id, ProjectId: one.ProjectId, DeviceCode: one.DeviceCode, Adjust: one.Adjust, Opening: one.Opening, Closed: one.Closed, Opened: one.Opened, FaultStatus: one.FaultStatus, CTime: one.CTime.Format("2006-01-02 15:04:05"), } } return &pb.GetWorkingValveByCodeResp{ List: list, }, nil }