浏览代码

Merge branch 'master' of http://120.55.44.4:10080/gaoyagang/GtDataStore

songxiaohang 1 年之前
父节点
当前提交
a0db5a875c
共有 2 个文件被更改,包括 42 次插入5 次删除
  1. 8 1
      app/cmd/organization/internal/logic/findWorkingUfByCycleLogic.go
  2. 34 4
      app/model/dcWorkingUfModel_gen.go

+ 8 - 1
app/cmd/organization/internal/logic/findWorkingUfByCycleLogic.go

@@ -24,7 +24,14 @@ func NewFindWorkingUfByCycleLogic(ctx context.Context, svcCtx *svc.ServiceContex
 }
 
 func (l *FindWorkingUfByCycleLogic) FindWorkingUfByCycle(in *pb.FindWorkingUfByCycleReq) (*pb.FindWorkingUfByCycleResp, error) {
-	res, err := l.svcCtx.WorkingUf.FindForCycleAndStep(l.ctx, in.ProjectId, in.DeviceCode, in.FilterCycle, in.Step, in.FilterTimeStart, in.FilterTimeEnd, in.Limit)
+	// 查询本次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
 	}

+ 34 - 4
app/model/dcWorkingUfModel_gen.go

@@ -24,7 +24,9 @@ var (
 
 type (
 	dcWorkingUfModel interface {
-		FindForCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error)
+		FindFirstByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error)
+		FindLastByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error)
+		FindForCycleAndStep(ctx context.Context, lastId, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error)
 		MultiInsert(ctx context.Context, datas []DcWorkingUf) (int64, error)
 		Insert(ctx context.Context, data *DcWorkingUf) (sql.Result, error)
 		FindOne(ctx context.Context, id int64) (*DcWorkingUf, error)
@@ -93,10 +95,10 @@ func (m *defaultDcWorkingUfModel) Delete(ctx context.Context, id int64) error {
 	return err
 }
 
-func (m *defaultDcWorkingUfModel) FindForCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error) {
-	query := fmt.Sprintf("select %s from %s where `project_id`=? and `device_code`=? and `filter_cycle`=? and `step`=? and `filter_time` BETWEEN ? and ? order by id desc limit %d", dcWorkingUfRows, m.table, limit)
+func (m *defaultDcWorkingUfModel) FindForCycleAndStep(ctx context.Context, lastId, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error) {
+	query := fmt.Sprintf("select %s from %s where `id`>? and `project_id`=? and `device_code`=? and `filter_cycle`=? and `step`=? and `filter_time` BETWEEN ? and ? order by id desc limit %d", dcWorkingUfRows, m.table, limit)
 	var resp []DcWorkingUf
-	err := m.conn.QueryRowsCtx(ctx, &resp, query, projectId, deviceCode, filterCycle, step, sFilterTime, eFilterTime)
+	err := m.conn.QueryRowsCtx(ctx, &resp, query, lastId, projectId, deviceCode, filterCycle, step, sFilterTime, eFilterTime)
 	switch err {
 	case nil:
 		return resp, nil
@@ -107,6 +109,34 @@ func (m *defaultDcWorkingUfModel) FindForCycleAndStep(ctx context.Context, proje
 	}
 }
 
+func (m *defaultDcWorkingUfModel) FindFirstByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error) {
+	query := fmt.Sprintf("select %s from %s where `project_id`=? and `device_code`=? and `filter_cycle`=? and `step`=? order by id asc limit 1", dcWorkingUfRows, m.table)
+	var resp DcWorkingUf
+	err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode, filterCycle, step)
+	switch err {
+	case nil:
+		return &resp, nil
+	case sqlc.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}
+
+func (m *defaultDcWorkingUfModel) FindLastByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error) {
+	query := fmt.Sprintf("select %s from %s where `project_id`=? and `device_code`=? and `filter_cycle`=? and `step`=? order by id desc limit 1", dcWorkingUfRows, m.table)
+	var resp DcWorkingUf
+	err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode, filterCycle, step)
+	switch err {
+	case nil:
+		return &resp, nil
+	case sqlc.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}
+
 func (m *defaultDcWorkingUfModel) FindOne(ctx context.Context, id int64) (*DcWorkingUf, error) {
 	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcWorkingUfRows, m.table)
 	var resp DcWorkingUf