|
@@ -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
|