sa_doc_section.go 4.2 KB

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