i2bill_acquirer_attendance_record_model.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package model
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "strings"
  6. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  7. "git.i2edu.net/i2/go-zero/core/stores/sqlx"
  8. "git.i2edu.net/i2/go-zero/core/stringx"
  9. "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx"
  10. )
  11. var (
  12. i2billAcquirerAttendanceRecordFieldNames = builderx.RawFieldNames(&I2billAcquirerAttendanceRecord{})
  13. i2billAcquirerAttendanceRecordRows = strings.Join(i2billAcquirerAttendanceRecordFieldNames, ",")
  14. i2billAcquirerAttendanceRecordRowsExpectAutoSet = strings.Join(stringx.Remove(i2billAcquirerAttendanceRecordFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
  15. i2billAcquirerAttendanceRecordRowsWithPlaceHolder = strings.Join(stringx.Remove(i2billAcquirerAttendanceRecordFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
  16. )
  17. type (
  18. I2billAcquirerAttendanceRecordModel interface {
  19. Insert(data I2billAcquirerAttendanceRecord) (sql.Result, error)
  20. FindOne(id int64) (*I2billAcquirerAttendanceRecord, error)
  21. Update(data I2billAcquirerAttendanceRecord) error
  22. Delete(id int64) error
  23. }
  24. defaultI2billAcquirerAttendanceRecordModel struct {
  25. conn sqlx.SqlConn
  26. table string
  27. }
  28. I2billAcquirerAttendanceRecord struct {
  29. Date sql.NullTime `db:"date" json:"date"`
  30. UserId sql.NullInt64 `db:"user_id" json:"user_id"` // 用户id
  31. StartLat sql.NullString `db:"start_lat" json:"start_lat"`
  32. StartAddress sql.NullString `db:"start_address" json:"start_address"` // 上班地址
  33. EndAddress sql.NullString `db:"end_address" json:"end_address"` // 下班地址
  34. StartTime sql.NullTime `db:"start_time" json:"start_time"` // 上班时间
  35. EndTime sql.NullTime `db:"end_time" json:"end_time"` // 下班时间
  36. DelFlag sql.NullInt64 `db:"del_flag" json:"del_flag"`
  37. Id int64 `db:"id" json:"id"`
  38. EndLat sql.NullString `db:"end_lat" json:"end_lat"`
  39. CreateTime sql.NullTime `db:"create_time" json:"create_time"`
  40. }
  41. )
  42. func (t *I2billAcquirerAttendanceRecord) TableName() string {
  43. return "i2bill_acquirer_attendance_record"
  44. }
  45. func NewI2billAcquirerAttendanceRecordModel(conn sqlx.SqlConn) I2billAcquirerAttendanceRecordModel {
  46. return &defaultI2billAcquirerAttendanceRecordModel{
  47. conn: conn,
  48. table: "`i2bill_acquirer_attendance_record`",
  49. }
  50. }
  51. func (m *defaultI2billAcquirerAttendanceRecordModel) Insert(data I2billAcquirerAttendanceRecord) (sql.Result, error) {
  52. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, i2billAcquirerAttendanceRecordRowsExpectAutoSet)
  53. ret, err := m.conn.Exec(query, data.Date, data.UserId, data.StartLat, data.StartAddress, data.EndAddress, data.StartTime, data.EndTime, data.DelFlag, data.EndLat)
  54. return ret, err
  55. }
  56. func (m *defaultI2billAcquirerAttendanceRecordModel) FindOne(id int64) (*I2billAcquirerAttendanceRecord, error) {
  57. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", i2billAcquirerAttendanceRecordRows, m.table)
  58. var resp I2billAcquirerAttendanceRecord
  59. err := m.conn.QueryRow(&resp, query, id)
  60. switch err {
  61. case nil:
  62. return &resp, nil
  63. case sqlc.ErrNotFound:
  64. return nil, ErrNotFound
  65. default:
  66. return nil, err
  67. }
  68. }
  69. func (m *defaultI2billAcquirerAttendanceRecordModel) Update(data I2billAcquirerAttendanceRecord) error {
  70. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, i2billAcquirerAttendanceRecordRowsWithPlaceHolder)
  71. _, err := m.conn.Exec(query, data.Date, data.UserId, data.StartLat, data.StartAddress, data.EndAddress, data.StartTime, data.EndTime, data.DelFlag, data.EndLat, data.Id)
  72. return err
  73. }
  74. func (m *defaultI2billAcquirerAttendanceRecordModel) Delete(id int64) error {
  75. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  76. _, err := m.conn.Exec(query, id)
  77. return err
  78. }