ccf_stock_excel.go 4.1 KB

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