ccf_stock_classify.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // CCFStockClassify CCF化纤-装置分类
  10. type CCFStockClassify struct {
  11. CcfStockClassifyId int `orm:"column(ccf_stock_classify_id);pk"`
  12. ClassifyName string `description:"分类名称"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. }
  16. func (m *CCFStockClassify) TableName() string {
  17. return "ccf_stock_classify"
  18. }
  19. type CCFStockClassifyCols struct {
  20. CcfStockClassifyId string
  21. ClassifyName string
  22. CreateTime string
  23. ModifyTime string
  24. }
  25. func (m *CCFStockClassify) Cols() CCFStockClassifyCols {
  26. return CCFStockClassifyCols{
  27. CcfStockClassifyId: "ccf_stock_classify_id",
  28. ClassifyName: "classify_name",
  29. CreateTime: "create_time",
  30. ModifyTime: "modify_time",
  31. }
  32. }
  33. func (m *CCFStockClassify) PrimaryId() string {
  34. return m.Cols().CcfStockClassifyId
  35. }
  36. func (m *CCFStockClassify) Create() (err error) {
  37. o := orm.NewOrmUsingDB("data")
  38. id, err := o.Insert(m)
  39. if err != nil {
  40. return
  41. }
  42. m.CcfStockClassifyId = int(id)
  43. return
  44. }
  45. func (m *CCFStockClassify) CreateMulti(items []*CCFStockClassify) (err error) {
  46. if len(items) == 0 {
  47. return
  48. }
  49. o := orm.NewOrmUsingDB("data")
  50. _, err = o.InsertMulti(len(items), items)
  51. return
  52. }
  53. func (m *CCFStockClassify) Update(cols []string) (err error) {
  54. o := orm.NewOrmUsingDB("data")
  55. _, err = o.Update(m, cols...)
  56. return
  57. }
  58. func (m *CCFStockClassify) Del() (err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  61. _, err = o.Raw(sql, m.CcfStockClassifyId).Exec()
  62. return
  63. }
  64. func (m *CCFStockClassify) MultiDel(menuIds []int) (err error) {
  65. if len(menuIds) == 0 {
  66. return
  67. }
  68. o := orm.NewOrmUsingDB("data")
  69. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  70. _, err = o.Raw(sql, menuIds).Exec()
  71. return
  72. }
  73. func (m *CCFStockClassify) GetItemById(id int) (item *CCFStockClassify, err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  76. err = o.Raw(sql, id).QueryRow(&item)
  77. return
  78. }
  79. func (m *CCFStockClassify) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *CCFStockClassify, err error) {
  80. o := orm.NewOrmUsingDB("data")
  81. order := ``
  82. if orderRule != "" {
  83. order = ` ORDER BY ` + orderRule
  84. }
  85. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  86. err = o.Raw(sql, pars).QueryRow(&item)
  87. return
  88. }
  89. func (m *CCFStockClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  92. err = o.Raw(sql, pars).QueryRow(&count)
  93. return
  94. }
  95. func (m *CCFStockClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*CCFStockClassify, err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. fields := strings.Join(fieldArr, ",")
  98. if len(fieldArr) == 0 {
  99. fields = `*`
  100. }
  101. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  102. if orderRule != "" {
  103. order = ` ORDER BY ` + orderRule
  104. }
  105. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  106. _, err = o.Raw(sql, pars).QueryRows(&items)
  107. return
  108. }
  109. func (m *CCFStockClassify) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*CCFStockClassify, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. fields := strings.Join(fieldArr, ",")
  112. if len(fieldArr) == 0 {
  113. fields = `*`
  114. }
  115. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  116. if orderRule != "" {
  117. order = ` ORDER BY ` + orderRule
  118. }
  119. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  120. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  121. return
  122. }
  123. // CCFStockClassifyItem CCF化纤-装置分类
  124. type CCFStockClassifyItem struct {
  125. ClassifyId int `description:"分类ID"`
  126. ClassifyName string `description:"分类名称"`
  127. CreateTime string `description:"创建时间"`
  128. ModifyTime string `description:"修改时间"`
  129. }
  130. func (m *CCFStockClassify) Format2Item() (item *CCFStockClassifyItem) {
  131. item = new(CCFStockClassifyItem)
  132. item.ClassifyId = m.CcfStockClassifyId
  133. item.ClassifyName = m.ClassifyName
  134. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, m.CreateTime)
  135. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, m.ModifyTime)
  136. return
  137. }