sa_doc_section.go 3.3 KB

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