sa_compare_doc.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package semantic_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "strings"
  6. )
  7. //type SaCompareDoc struct {
  8. // SaCompareDocId int `orm:"column(sa_compare_doc_id);pk"`
  9. // CompareId int `description:"比对ID"`
  10. // DocId int `description:"文档ID"`
  11. //}
  12. type SaCompareDoc struct {
  13. SaCompareDocId int `gorm:"primaryKey;column:sa_compare_doc_id;type:int(10) unsigned;not null"` // 比对文档Id
  14. CompareId int `gorm:"index:idx_compare_id;column:compare_id;type:int(10) unsigned;not null;default:0"` // 比对Id
  15. DocId int `gorm:"column:doc_id;type:int(10) unsigned;not null;default:0"` // 文档Id
  16. }
  17. var SaCompareDocColumns = struct {
  18. SaCompareDocId string
  19. CompareId string
  20. DocId string
  21. }{
  22. SaCompareDocId: "sa_compare_doc_id",
  23. CompareId: "compare_id",
  24. DocId: "doc_id",
  25. }
  26. func (m *SaCompareDoc) TableName() string {
  27. return "sa_compare_doc"
  28. }
  29. //func (m *SaCompareDoc) Create() (err error) {
  30. // o := orm.NewOrm()
  31. // id, err := o.Insert(m)
  32. // if err != nil {
  33. // return
  34. // }
  35. // m.SaCompareDocId = int(id)
  36. // return
  37. //}
  38. //func (m *SaCompareDoc) Update(cols []string) (err error) {
  39. // o := orm.NewOrm()
  40. // _, err = o.Update(m, cols...)
  41. // return
  42. //}
  43. //func (m *SaCompareDoc) Del() (err error) {
  44. // o := orm.NewOrm()
  45. // sql := `DELETE FROM sa_compare_doc WHERE sa_compare_doc_id = ? LIMIT 1`
  46. // _, err = o.Raw(sql, m.SaCompareDocId).Exec()
  47. // return
  48. //}
  49. //func (m *SaCompareDoc) GetItemById(id int) (err error) {
  50. // o := orm.NewOrm()
  51. // sql := `SELECT * FROM sa_compare_doc WHERE sa_compare_doc_id = ? LIMIT 1`
  52. // err = o.Raw(sql, id).QueryRow(&m)
  53. // return
  54. //}
  55. //func (m *SaCompareDoc) GetItemByCondition(condition string, pars []interface{}) (err error) {
  56. // o := orm.NewOrm()
  57. // sql := `SELECT * FROM sa_compare_doc WHERE 1=1 `
  58. // sql += condition
  59. // sql += ` LIMIT 1`
  60. // err = o.Raw(sql, pars).QueryRow(&m)
  61. // return
  62. //}
  63. //func (m *SaCompareDoc) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. // o := orm.NewOrm()
  65. // sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  66. // err = o.Raw(sql, pars).QueryRow(&count)
  67. // return
  68. //}
  69. func (m *SaCompareDoc) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareDoc, err error) {
  70. //o := orm.NewOrm()
  71. fields := strings.Join(fieldArr, ",")
  72. if len(fieldArr) == 0 {
  73. fields = `*`
  74. }
  75. order := ``
  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. //_, err = o.Raw(sql, pars).QueryRows(&items)
  81. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  82. return
  83. }
  84. //func (m *SaCompareDoc) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareDoc, err error) {
  85. // o := orm.NewOrm()
  86. // fields := strings.Join(fieldArr, ",")
  87. // if len(fieldArr) == 0 {
  88. // fields = `*`
  89. // }
  90. // order := ``
  91. // if orderRule != "" {
  92. // order = ` ORDER BY ` + orderRule
  93. // }
  94. // sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  95. // totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  96. // if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  97. // return
  98. // }
  99. // sql += ` LIMIT ?,?`
  100. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  101. // return
  102. //}
  103. // SaCompareDocSection 比对文档段落信息
  104. type SaCompareDocSection struct {
  105. DocId int `description:"文档ID"`
  106. Title string `description:"文档标题"`
  107. Theme string `description:"文档主题"`
  108. ClassifyName string `description:"分类名称"`
  109. SectionId int `description:"段落ID"`
  110. Content string `description:"段落内容"`
  111. Sort int `description:"段落排序"`
  112. }
  113. // GetSaCompareDocAndSections 获取比对关联的文档段落
  114. //func GetSaCompareDocAndSections(compareId int) (items []*SaCompareDocSection, err error) {
  115. // o := orm.NewOrm()
  116. // sql := `SELECT
  117. // a.doc_id,
  118. // b.title,
  119. // b.theme,
  120. // b.classify_name,
  121. // c.sa_doc_section_id AS section_id,
  122. // c.content,
  123. // c.sort
  124. // FROM
  125. // sa_compare_doc AS a
  126. // JOIN sa_doc AS b ON a.doc_id = b.sa_doc_id
  127. // JOIN sa_doc_section AS c ON a.doc_id = c.doc_id
  128. // WHERE
  129. // a.compare_id = ?
  130. // ORDER BY
  131. // a.doc_id,
  132. // c.sort ASC`
  133. // _, err = o.Raw(sql, compareId).QueryRows(&items)
  134. // return
  135. //}