ccf_stock_excel.go 5.2 KB

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