sa_doc_section.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package semantic_analysis
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. )
  8. type SaDocSection struct {
  9. SaDocSectionId int `orm:"column(sa_doc_section_id);pk" gorm:"primaryKey" description:"段落ID"`
  10. DocId int `description:"文档ID"`
  11. Content string `description:"段落内容"`
  12. Sort int `description:"排序"`
  13. }
  14. var SaDocSectionColumns = struct {
  15. SaDocSectionId string
  16. DocId string
  17. Content string
  18. Sort string
  19. }{
  20. SaDocSectionId: "sa_doc_section_id",
  21. DocId: "doc_id",
  22. Content: "content",
  23. Sort: "sort",
  24. }
  25. func (m *SaDocSection) TableName() string {
  26. return "sa_doc_section"
  27. }
  28. func (m *SaDocSection) Create() (err error) {
  29. o := global.DbMap[utils.DbNameMaster]
  30. err = o.Create(m).Error
  31. return
  32. }
  33. func (m *SaDocSection) Update(cols []string) (err error) {
  34. o := global.DbMap[utils.DbNameMaster]
  35. err = o.Select(cols).Updates(m).Error
  36. return
  37. }
  38. func (m *SaDocSection) Del() (err error) {
  39. o := global.DbMap[utils.DbNameMaster]
  40. sql := `DELETE FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1`
  41. err = o.Exec(sql, m.SaDocSectionId).Error
  42. return
  43. }
  44. func (m *SaDocSection) GetItemById(id int) (err error) {
  45. o := global.DbMap[utils.DbNameMaster]
  46. sql := `SELECT * FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1`
  47. err = o.Raw(sql, id).First(&m).Error
  48. return
  49. }
  50. func (m *SaDocSection) GetItemByCondition(condition string, pars []interface{}) (err error) {
  51. o := global.DbMap[utils.DbNameMaster]
  52. sql := `SELECT * FROM sa_doc_section WHERE 1=1 `
  53. sql += condition
  54. sql += ` LIMIT 1`
  55. err = o.Raw(sql, pars...).First(&m).Error
  56. return
  57. }
  58. func (m *SaDocSection) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  59. o := global.DbMap[utils.DbNameMaster]
  60. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  61. err = o.Raw(sql, pars...).Scan(&count).Error
  62. return
  63. }
  64. func (m *SaDocSection) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocSection, err error) {
  65. o := global.DbMap[utils.DbNameMaster]
  66. fields := strings.Join(fieldArr, ",")
  67. if len(fieldArr) == 0 {
  68. fields = `*`
  69. }
  70. order := `ORDER BY sort ASC`
  71. if orderRule != "" {
  72. order = ` ORDER BY ` + orderRule
  73. }
  74. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  75. err = o.Raw(sql, pars...).Find(&items).Error
  76. return
  77. }
  78. func (m *SaDocSection) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaDocSection, err error) {
  79. o := global.DbMap[utils.DbNameMaster]
  80. fields := strings.Join(fieldArr, ",")
  81. if len(fieldArr) == 0 {
  82. fields = `*`
  83. }
  84. order := `ORDER BY sort ASC`
  85. if orderRule != "" {
  86. order = ` ORDER BY ` + orderRule
  87. }
  88. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  89. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  90. if err = o.Raw(totalSql, pars...).Scan(&total).Error; err != nil {
  91. return
  92. }
  93. sql += ` LIMIT ?,?`
  94. pars = append(pars, startSize, pageSize)
  95. err = o.Raw(sql, pars...).Find(&items).Error
  96. return
  97. }
  98. type SaDocSectionItem struct {
  99. SaDocSection
  100. UseNum int `description:"整段引用数量"`
  101. UsePartNum int `description:"片段引用数量"`
  102. }