dcWorkingUfModel_gen.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. MultiInsert(ctx context.Context, datas []DcWorkingUf) (int64, error)
  23. Insert(ctx context.Context, data *DcWorkingUf) (sql.Result, error)
  24. FindOne(ctx context.Context, id int64) (*DcWorkingUf, error)
  25. Update(ctx context.Context, data *DcWorkingUf) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultDcWorkingUfModel struct {
  29. conn sqlx.SqlConn
  30. table string
  31. }
  32. DcWorkingUf struct {
  33. Id int64 `db:"id"`
  34. ProjectId int64 `db:"project_id"`
  35. DeviceCode string `db:"device_code"`
  36. WaterTemperature float64 `db:"water_temperature"` // 水温 摄氏度
  37. FeedFlow float64 `db:"feed_flow"` // 进水流量
  38. ConFlow float64 `db:"con_flow"` // 浓水流量
  39. ProductFlow float64 `db:"product_flow"` // 产水流量
  40. FeedPressure float64 `db:"feed_pressure"` // 进水压力
  41. ConPressure float64 `db:"con_pressure"` // 浓水压力
  42. ProductPressure float64 `db:"product_pressure"` // 产水压力
  43. Tmp float64 `db:"tmp"` // 跨膜压差
  44. Flux float64 `db:"flux"` // 膜通量
  45. FeedWqTurbidity float64 `db:"feed_wq_turbidity"` // 进水浊度
  46. FeedWqPh int64 `db:"feed_wq_ph"` // 进水 PH 值
  47. ProductWqPh int64 `db:"product_wq_ph"` // 产水 PH 值
  48. FeedWqAl float64 `db:"feed_wq_al"` // 进水水质:铝
  49. ProductWqAl float64 `db:"product_wq_al"` // 产水水质:铝
  50. FeedWqFe float64 `db:"feed_wq_fe"` // 进水水质:铁
  51. ProductWqFe float64 `db:"product_wq_fe"` // 产水水质:铁
  52. FeedWqMn float64 `db:"feed_wq_mn"` // 进水水质:锰
  53. ProductWqMn float64 `db:"product_wq_mn"` // 产水水质:锰
  54. FeedWqSio2 float64 `db:"feed_wq_sio2"` // 进水水质:二氧化硅
  55. ProductWqSio2 float64 `db:"product_wq_sio2"` // 产水水质:二氧化硅
  56. FeedWqCod float64 `db:"feed_wq_cod"` // 进水水质:COD
  57. ProductWqCod float64 `db:"product_wq_cod"` // 产水水质:COD
  58. FeedWqP float64 `db:"feed_wq_p"` // 进水水质:磷
  59. ProductWqP float64 `db:"product_wq_p"` // 产水水质:磷
  60. Step int64 `db:"step"` // 设备当前步序值
  61. CTime time.Time `db:"c_time"`
  62. }
  63. )
  64. func newDcWorkingUfModel(conn sqlx.SqlConn) *defaultDcWorkingUfModel {
  65. return &defaultDcWorkingUfModel{
  66. conn: conn,
  67. table: "`dc_working_uf`",
  68. }
  69. }
  70. func (m *defaultDcWorkingUfModel) withSession(session sqlx.Session) *defaultDcWorkingUfModel {
  71. return &defaultDcWorkingUfModel{
  72. conn: sqlx.NewSqlConnFromSession(session),
  73. table: "`dc_working_uf`",
  74. }
  75. }
  76. func (m *defaultDcWorkingUfModel) Delete(ctx context.Context, id int64) error {
  77. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  78. _, err := m.conn.ExecCtx(ctx, query, id)
  79. return err
  80. }
  81. func (m *defaultDcWorkingUfModel) FindOne(ctx context.Context, id int64) (*DcWorkingUf, error) {
  82. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcWorkingUfRows, m.table)
  83. var resp DcWorkingUf
  84. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  85. switch err {
  86. case nil:
  87. return &resp, nil
  88. case sqlc.ErrNotFound:
  89. return nil, ErrNotFound
  90. default:
  91. return nil, err
  92. }
  93. }
  94. func (m *defaultDcWorkingUfModel) MultiInsert(ctx context.Context, datas []DcWorkingUf) (int64, error) {
  95. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingUfRowsExpectAutoSet)
  96. if bulk, err := sqlx.NewBulkInserter(m.conn, query);err == nil {
  97. for _, data := range datas {
  98. 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.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.CTime);err != nil {
  99. return 0, err
  100. }
  101. }
  102. bulk.Flush()
  103. return int64(len(datas)), nil
  104. } else {
  105. return 0, err
  106. }
  107. }
  108. func (m *defaultDcWorkingUfModel) Insert(ctx context.Context, data *DcWorkingUf) (sql.Result, error) {
  109. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingUfRowsExpectAutoSet)
  110. 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.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.CTime)
  111. return ret, err
  112. }
  113. func (m *defaultDcWorkingUfModel) Update(ctx context.Context, data *DcWorkingUf) error {
  114. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcWorkingUfRowsWithPlaceHolder)
  115. _, 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.CTime, data.Id)
  116. return err
  117. }
  118. func (m *defaultDcWorkingUfModel) tableName() string {
  119. return m.table
  120. }