dcWorkingMfModel_gen.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. dcWorkingMfFieldNames = builder.RawFieldNames(&DcWorkingMf{})
  16. dcWorkingMfRows = strings.Join(dcWorkingMfFieldNames, ",")
  17. dcWorkingMfRowsExpectAutoSet = strings.Join(stringx.Remove(dcWorkingMfFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. dcWorkingMfRowsWithPlaceHolder = strings.Join(stringx.Remove(dcWorkingMfFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. )
  20. type (
  21. dcWorkingMfModel interface {
  22. MultiInsert(ctx context.Context, datas []DcWorkingMf) (int64, error)
  23. Insert(ctx context.Context, data *DcWorkingMf) (sql.Result, error)
  24. FindOne(ctx context.Context, id int64) (*DcWorkingMf, error)
  25. Update(ctx context.Context, data *DcWorkingMf) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultDcWorkingMfModel struct {
  29. conn sqlx.SqlConn
  30. table string
  31. }
  32. DcWorkingMf 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. FilterTime float64 `db:"filter_time"` // 过滤时间
  62. FilterCycle int64 `db:"filter_cycle"` // 当前过滤周期数
  63. CTime time.Time `db:"c_time"`
  64. }
  65. )
  66. func newDcWorkingMfModel(conn sqlx.SqlConn) *defaultDcWorkingMfModel {
  67. return &defaultDcWorkingMfModel{
  68. conn: conn,
  69. table: "`dc_working_mf`",
  70. }
  71. }
  72. func (m *defaultDcWorkingMfModel) withSession(session sqlx.Session) *defaultDcWorkingMfModel {
  73. return &defaultDcWorkingMfModel{
  74. conn: sqlx.NewSqlConnFromSession(session),
  75. table: "`dc_working_mf`",
  76. }
  77. }
  78. func (m *defaultDcWorkingMfModel) Delete(ctx context.Context, id int64) error {
  79. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  80. _, err := m.conn.ExecCtx(ctx, query, id)
  81. return err
  82. }
  83. func (m *defaultDcWorkingMfModel) FindOne(ctx context.Context, id int64) (*DcWorkingMf, error) {
  84. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcWorkingMfRows, m.table)
  85. var resp DcWorkingMf
  86. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  87. switch err {
  88. case nil:
  89. return &resp, nil
  90. case sqlc.ErrNotFound:
  91. return nil, ErrNotFound
  92. default:
  93. return nil, err
  94. }
  95. }
  96. func (m *defaultDcWorkingMfModel) MultiInsert(ctx context.Context, datas []DcWorkingMf) (int64, error) {
  97. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingMfRowsExpectAutoSet)
  98. if bulk, err := sqlx.NewBulkInserter(m.conn, query); err == nil {
  99. for _, data := range datas {
  100. 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.FilterTime, data.FilterCycle, data.CTime); err != nil {
  101. return 0, err
  102. }
  103. }
  104. bulk.Flush()
  105. return int64(len(datas)), nil
  106. } else {
  107. return 0, err
  108. }
  109. }
  110. func (m *defaultDcWorkingMfModel) Insert(ctx context.Context, data *DcWorkingMf) (sql.Result, error) {
  111. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcWorkingMfRowsExpectAutoSet)
  112. 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.FilterTime, data.FilterCycle, data.CTime)
  113. return ret, err
  114. }
  115. func (m *defaultDcWorkingMfModel) Update(ctx context.Context, data *DcWorkingMf) error {
  116. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcWorkingMfRowsWithPlaceHolder)
  117. _, 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)
  118. return err
  119. }
  120. func (m *defaultDcWorkingMfModel) tableName() string {
  121. return m.table
  122. }