dcWorkingUfModel_gen.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Code generated by goctl. DO NOT EDIT.
  2. package model
  3. import (
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/zeromicro/go-zero/core/stores/builder"
  10. "github.com/zeromicro/go-zero/core/stores/sqlc"
  11. "github.com/zeromicro/go-zero/core/stores/sqlx"
  12. "github.com/zeromicro/go-zero/core/stringx"
  13. )
  14. var (
  15. dcWorkingUfFieldNames = builder.RawFieldNames(&DcWorkingUf{})
  16. dcWorkingUfRows = strings.Join(dcWorkingUfFieldNames, ",")
  17. dcWorkingUfRowsExpectAutoSet = strings.Join(stringx.Remove(dcWorkingUfFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. dcWorkingUfRowsWithPlaceHolder = strings.Join(stringx.Remove(dcWorkingUfFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. )
  20. type (
  21. dcWorkingUfModel interface {
  22. FindFirstByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error)
  23. FindLastByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error)
  24. FindForCycleAndStep(ctx context.Context, lastId, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error)
  25. MultiInsert(ctx context.Context, datas []DcWorkingUf) (int64, error)
  26. Insert(ctx context.Context, data *DcWorkingUf) (sql.Result, error)
  27. FindOne(ctx context.Context, id int64) (*DcWorkingUf, error)
  28. Update(ctx context.Context, data *DcWorkingUf) error
  29. Delete(ctx context.Context, id int64) error
  30. }
  31. defaultDcWorkingUfModel struct {
  32. conn sqlx.SqlConn
  33. table string
  34. }
  35. DcWorkingUf struct {
  36. Id int64 `db:"id"`
  37. ProjectId int64 `db:"project_id"`
  38. DeviceCode string `db:"device_code"`
  39. WaterTemperature float64 `db:"water_temperature"` // 水温 摄氏度
  40. FeedFlow float64 `db:"feed_flow"` // 进水流量
  41. ConFlow float64 `db:"con_flow"` // 浓水流量
  42. ProductFlow float64 `db:"product_flow"` // 产水流量
  43. FeedPressure float64 `db:"feed_pressure"` // 进水压力
  44. ConPressure float64 `db:"con_pressure"` // 浓水压力
  45. ProductPressure float64 `db:"product_pressure"` // 产水压力
  46. Tmp float64 `db:"tmp"` // 跨膜压差
  47. Flux float64 `db:"flux"` // 膜通量
  48. Permeability float64 `db:"permeability"` // 渗透率
  49. FeedWqTurbidity float64 `db:"feed_wq_turbidity"` // 进水浊度
  50. FeedWqPh int64 `db:"feed_wq_ph"` // 进水 PH 值
  51. ProductWqPh int64 `db:"product_wq_ph"` // 产水 PH 值
  52. FeedWqAl float64 `db:"feed_wq_al"` // 进水水质:铝
  53. ProductWqAl float64 `db:"product_wq_al"` // 产水水质:铝
  54. FeedWqFe float64 `db:"feed_wq_fe"` // 进水水质:铁
  55. ProductWqFe float64 `db:"product_wq_fe"` // 产水水质:铁
  56. FeedWqMn float64 `db:"feed_wq_mn"` // 进水水质:锰
  57. ProductWqMn float64 `db:"product_wq_mn"` // 产水水质:锰
  58. FeedWqSio2 float64 `db:"feed_wq_sio2"` // 进水水质:二氧化硅
  59. ProductWqSio2 float64 `db:"product_wq_sio2"` // 产水水质:二氧化硅
  60. FeedWqCod float64 `db:"feed_wq_cod"` // 进水水质:COD
  61. ProductWqCod float64 `db:"product_wq_cod"` // 产水水质:COD
  62. FeedWqP float64 `db:"feed_wq_p"` // 进水水质:磷
  63. ProductWqP float64 `db:"product_wq_p"` // 产水水质:磷
  64. Step int64 `db:"step"` // 设备当前步序值
  65. FilterTime float64 `db:"filter_time"` // 过滤时间
  66. FilterCycle int64 `db:"filter_cycle"` // 当前过滤周期数
  67. CTime time.Time `db:"c_time"`
  68. }
  69. )
  70. func newDcWorkingUfModel(conn sqlx.SqlConn) *defaultDcWorkingUfModel {
  71. return &defaultDcWorkingUfModel{
  72. conn: conn,
  73. table: "`dc_working_uf`",
  74. }
  75. }
  76. func (m *defaultDcWorkingUfModel) withSession(session sqlx.Session) *defaultDcWorkingUfModel {
  77. return &defaultDcWorkingUfModel{
  78. conn: sqlx.NewSqlConnFromSession(session),
  79. table: "`dc_working_uf`",
  80. }
  81. }
  82. func (m *defaultDcWorkingUfModel) Delete(ctx context.Context, id int64) error {
  83. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  84. _, err := m.conn.ExecCtx(ctx, query, id)
  85. return err
  86. }
  87. func (m *defaultDcWorkingUfModel) FindForCycleAndStep(ctx context.Context, lastId, projectId int64, deviceCode string, filterCycle int64, step int64, sFilterTime, eFilterTime float64, limit int64) ([]DcWorkingUf, error) {
  88. 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)
  89. var resp []DcWorkingUf
  90. err := m.conn.QueryRowsCtx(ctx, &resp, query, lastId, projectId, deviceCode, filterCycle, step, sFilterTime, eFilterTime)
  91. switch err {
  92. case nil:
  93. return resp, nil
  94. case sqlc.ErrNotFound:
  95. return nil, ErrNotFound
  96. default:
  97. return nil, err
  98. }
  99. }
  100. func (m *defaultDcWorkingUfModel) FindFirstByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error) {
  101. 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)
  102. var resp DcWorkingUf
  103. err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode, filterCycle, step)
  104. switch err {
  105. case nil:
  106. return &resp, nil
  107. case sqlc.ErrNotFound:
  108. return nil, ErrNotFound
  109. default:
  110. return nil, err
  111. }
  112. }
  113. func (m *defaultDcWorkingUfModel) FindLastByCycleAndStep(ctx context.Context, projectId int64, deviceCode string, filterCycle int64, step int64) (*DcWorkingUf, error) {
  114. 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)
  115. var resp DcWorkingUf
  116. err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode, filterCycle, step)
  117. switch err {
  118. case nil:
  119. return &resp, nil
  120. case sqlc.ErrNotFound:
  121. return nil, ErrNotFound
  122. default:
  123. return nil, err
  124. }
  125. }
  126. func (m *defaultDcWorkingUfModel) FindOne(ctx context.Context, id int64) (*DcWorkingUf, error) {
  127. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcWorkingUfRows, m.table)
  128. var resp DcWorkingUf
  129. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  130. switch err {
  131. case nil:
  132. return &resp, nil
  133. case sqlc.ErrNotFound:
  134. return nil, ErrNotFound
  135. default:
  136. return nil, err
  137. }
  138. }
  139. func (m *defaultDcWorkingUfModel) MultiInsert(ctx context.Context, datas []DcWorkingUf) (int64, error) {
  140. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingUfRowsExpectAutoSet)
  141. if bulk, err := sqlx.NewBulkInserter(m.conn, query); err == nil {
  142. for _, data := range datas {
  143. if err = bulk.Insert(data.ProjectId, data.DeviceCode, data.WaterTemperature, data.FeedFlow, data.ConFlow, data.ProductFlow, data.FeedPressure, data.ConPressure, data.ProductPressure, data.Tmp, data.Flux, data.Permeability, data.FeedWqTurbidity, data.FeedWqPh, data.ProductWqPh, data.FeedWqAl, data.ProductWqAl, data.FeedWqFe, data.ProductWqFe, data.FeedWqMn, data.ProductWqMn, data.FeedWqSio2, data.ProductWqSio2, data.FeedWqCod, data.ProductWqCod, data.FeedWqP, data.ProductWqP, data.Step, data.FilterTime, data.FilterCycle, data.CTime); err != nil {
  144. return 0, err
  145. }
  146. }
  147. bulk.Flush()
  148. return int64(len(datas)), nil
  149. } else {
  150. return 0, err
  151. }
  152. }
  153. func (m *defaultDcWorkingUfModel) Insert(ctx context.Context, data *DcWorkingUf) (sql.Result, error) {
  154. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingUfRowsExpectAutoSet)
  155. ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.WaterTemperature, data.FeedFlow, data.ConFlow, data.ProductFlow, data.FeedPressure, data.ConPressure, data.ProductPressure, data.Tmp, data.Flux, data.Permeability, data.FeedWqTurbidity, data.FeedWqPh, data.ProductWqPh, data.FeedWqAl, data.ProductWqAl, data.FeedWqFe, data.ProductWqFe, data.FeedWqMn, data.ProductWqMn, data.FeedWqSio2, data.ProductWqSio2, data.FeedWqCod, data.ProductWqCod, data.FeedWqP, data.ProductWqP, data.Step, data.FilterTime, data.FilterCycle, data.CTime)
  156. return ret, err
  157. }
  158. func (m *defaultDcWorkingUfModel) Update(ctx context.Context, data *DcWorkingUf) error {
  159. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcWorkingUfRowsWithPlaceHolder)
  160. _, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.WaterTemperature, data.FeedFlow, data.ConFlow, data.ProductFlow, data.FeedPressure, data.ConPressure, data.ProductPressure, data.Tmp, data.Flux, data.FeedWqTurbidity, data.FeedWqPh, data.ProductWqPh, data.FeedWqAl, data.ProductWqAl, data.FeedWqFe, data.ProductWqFe, data.FeedWqMn, data.ProductWqMn, data.FeedWqSio2, data.ProductWqSio2, data.FeedWqCod, data.ProductWqCod, data.FeedWqP, data.ProductWqP, data.Step, data.FilterTime, data.FilterCycle, data.CTime, data.Id)
  161. return err
  162. }
  163. func (m *defaultDcWorkingUfModel) tableName() string {
  164. return m.table
  165. }