maycur_public_offering_company.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // MaycurPublicOfferingCompany 每刻报销-公募销售表
  9. type MaycurPublicOfferingCompany struct {
  10. Id int `orm:"column(id);pk"`
  11. Name string `description:"客户名称"`
  12. ShortName string `description:"客户简称"`
  13. Social string `description:"社会信用代码"`
  14. SaleNames string `description:"销售姓名(多个)"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. func (m *MaycurPublicOfferingCompany) TableName() string {
  19. return "maycur_public_offering_company"
  20. }
  21. func (m *MaycurPublicOfferingCompany) Create() (err error) {
  22. o := orm.NewOrm()
  23. id, err := o.Insert(m)
  24. if err != nil {
  25. return
  26. }
  27. m.Id = int(id)
  28. return
  29. }
  30. func (m *MaycurPublicOfferingCompany) CreateMulti(items []*MaycurPublicOfferingCompany) (err error) {
  31. if len(items) == 0 {
  32. return
  33. }
  34. o := orm.NewOrm()
  35. _, err = o.InsertMulti(len(items), items)
  36. return
  37. }
  38. func (m *MaycurPublicOfferingCompany) Update(cols []string) (err error) {
  39. o := orm.NewOrm()
  40. _, err = o.Update(m, cols...)
  41. return
  42. }
  43. func (m *MaycurPublicOfferingCompany) Del() (err error) {
  44. o := orm.NewOrm()
  45. sql := `DELETE FROM maycur_public_offering_company WHERE id = ? LIMIT 1`
  46. _, err = o.Raw(sql, m.Id).Exec()
  47. return
  48. }
  49. func (m *MaycurPublicOfferingCompany) GetItemById(id int) (err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM maycur_public_offering_company WHERE id = ? LIMIT 1`
  52. err = o.Raw(sql, id).QueryRow(&m)
  53. return
  54. }
  55. func (m *MaycurPublicOfferingCompany) GetItemByCondition(condition string, pars []interface{}) (err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM maycur_public_offering_company WHERE 1=1 `
  58. sql += condition
  59. sql += ` LIMIT 1`
  60. err = o.Raw(sql, pars).QueryRow(&m)
  61. return
  62. }
  63. func (m *MaycurPublicOfferingCompany) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. o := orm.NewOrm()
  65. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  66. err = o.Raw(sql, pars).QueryRow(&count)
  67. return
  68. }
  69. func (m *MaycurPublicOfferingCompany) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*MaycurPublicOfferingCompany, err error) {
  70. o := orm.NewOrm()
  71. fields := strings.Join(fieldArr, ",")
  72. if len(fieldArr) == 0 {
  73. fields = `*`
  74. }
  75. order := `ORDER BY create_time DESC`
  76. if orderRule != "" {
  77. order = ` ORDER BY ` + orderRule
  78. }
  79. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  80. _, err = o.Raw(sql, pars).QueryRows(&items)
  81. return
  82. }