sa_compare_label.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package semantic_analysis
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. type SaCompareLabel struct {
  9. SaCompareLabelId int `orm:"column(sa_compare_label_id);pk" description:"段落标签ID"`
  10. CompareId int `description:"比对ID"`
  11. DocId int `description:"文档ID"`
  12. SectionId int `description:"段落ID"`
  13. LabelId int `description:"标签ID"`
  14. LabelName string `description:"标签名称"`
  15. IsPart int `description:"是否为片段: 0-整段; 1-片段"`
  16. StartIndex int `description:"片段开始下标"`
  17. EndIndex int `description:"片段结束下标"`
  18. Content string `description:"内容"`
  19. SysAdminId int `description:"创建人ID"`
  20. SysAdminName string `description:"创建人姓名"`
  21. CreateTime time.Time `description:"创建时间"`
  22. }
  23. var SaCompareLabelColumns = struct {
  24. SaCompareLabelId string
  25. CompareId string
  26. DocId string
  27. SectionId string
  28. LabelId string
  29. LabelName string
  30. IsPart string
  31. StartIndex string
  32. EndIndex string
  33. Content string
  34. SysAdminId string
  35. SysAdminName string
  36. CreateTime string
  37. }{
  38. SaCompareLabelId: "sa_compare_label_id",
  39. CompareId: "compare_id",
  40. DocId: "doc_id",
  41. SectionId: "section_id",
  42. LabelId: "label_id",
  43. LabelName: "label_name",
  44. IsPart: "is_part",
  45. StartIndex: "start_index",
  46. EndIndex: "end_index",
  47. SysAdminId: "sys_admin_id",
  48. SysAdminName: "sys_admin_name",
  49. CreateTime: "create_time",
  50. }
  51. func (m *SaCompareLabel) TableName() string {
  52. return "sa_compare_label"
  53. }
  54. func (m *SaCompareLabel) Create() (err error) {
  55. o := orm.NewOrm()
  56. id, err := o.Insert(m)
  57. if err != nil {
  58. return
  59. }
  60. m.SaCompareLabelId = int(id)
  61. return
  62. }
  63. func (m *SaCompareLabel) Update(cols []string) (err error) {
  64. o := orm.NewOrm()
  65. _, err = o.Update(m, cols...)
  66. return
  67. }
  68. func (m *SaCompareLabel) Del() (err error) {
  69. o := orm.NewOrm()
  70. sql := `DELETE FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
  71. _, err = o.Raw(sql, m.SaCompareLabelId).Exec()
  72. return
  73. }
  74. func (m *SaCompareLabel) GetItemById(id int) (err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT * FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
  77. err = o.Raw(sql, id).QueryRow(&m)
  78. return
  79. }
  80. func (m *SaCompareLabel) GetItemByCondition(condition string, pars []interface{}) (err error) {
  81. o := orm.NewOrm()
  82. sql := `SELECT * FROM sa_compare_label WHERE 1=1 `
  83. sql += condition
  84. sql += ` LIMIT 1`
  85. err = o.Raw(sql, pars).QueryRow(&m)
  86. return
  87. }
  88. func (m *SaCompareLabel) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  89. o := orm.NewOrm()
  90. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  91. err = o.Raw(sql, pars).QueryRow(&count)
  92. return
  93. }
  94. type SaCompareLabelGroupCount struct {
  95. DocId int `description:"文档ID"`
  96. SectionId int `description:"段落ID"`
  97. LabelId int `description:"标签ID"`
  98. UseNum int `description:"引用数"`
  99. }
  100. func (m *SaCompareLabel) GetGroupCountByCondition(condition string, pars []interface{}, groupRule string) (items []*SaCompareLabelGroupCount, err error) {
  101. o := orm.NewOrm()
  102. sql := fmt.Sprintf(`SELECT COUNT(1) AS use_num, %s FROM %s WHERE 1=1 %s GROUP BY %s`, groupRule, m.TableName(), condition, groupRule)
  103. _, err = o.Raw(sql, pars).QueryRows(&items)
  104. return
  105. }
  106. func (m *SaCompareLabel) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareLabel, err error) {
  107. o := orm.NewOrm()
  108. fields := strings.Join(fieldArr, ",")
  109. if len(fieldArr) == 0 {
  110. fields = `*`
  111. }
  112. order := `ORDER BY create_time DESC`
  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 *SaCompareLabel) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareLabel, err error) {
  121. o := orm.NewOrm()
  122. fields := strings.Join(fieldArr, ",")
  123. if len(fieldArr) == 0 {
  124. fields = `*`
  125. }
  126. order := `ORDER BY create_time DESC`
  127. if orderRule != "" {
  128. order = ` ORDER BY ` + orderRule
  129. }
  130. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  131. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  132. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  133. return
  134. }
  135. sql += ` LIMIT ?,?`
  136. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  137. return
  138. }
  139. // UpdateSaCompareLabelByLabelId 更新比对标签信息
  140. func UpdateSaCompareLabelByLabelId(labelId int, labelName string) (err error) {
  141. o := orm.NewOrm()
  142. sql := `UPDATE sa_compare_label SET label_name = ? WHERE label_id = ?`
  143. _, err = o.Raw(sql, labelName, labelId).Exec()
  144. return
  145. }
  146. // SaCompareLabelItem 比对标签
  147. type SaCompareLabelItem struct {
  148. SaCompareLabelId int `description:"比对标签ID"`
  149. LabelId int `description:"标签ID"`
  150. LabelName string `description:"标签名称"`
  151. CompareId int `description:"比对ID"`
  152. CompareContent string `description:"比对内容(片段)"`
  153. DocId int `description:"文档ID"`
  154. Title string `description:"文档标题"`
  155. SectionId int `description:"段落ID"`
  156. SectionContent string `description:"段落内容"`
  157. Sort int `description:"段落排序"`
  158. }
  159. // GetSaCompareLabelByCond 获取比对标签
  160. func GetSaCompareLabelByCond(condition string, pars []interface{}) (items []*SaCompareLabelItem, err error) {
  161. o := orm.NewOrm()
  162. sql := `SELECT
  163. a.sa_compare_label_id,
  164. a.label_id,
  165. a.label_name,
  166. a.compare_id,
  167. a.doc_id,
  168. a.content AS compare_content,
  169. b.title,
  170. c.sa_doc_section_id AS section_id,
  171. c.content AS section_content,
  172. c.sort
  173. FROM
  174. sa_compare_label AS a
  175. JOIN sa_doc AS b ON a.doc_id = b.sa_doc_id
  176. JOIN sa_doc_section AS c ON a.section_id = c.sa_doc_section_id
  177. WHERE
  178. 1 = 1 %s
  179. ORDER BY
  180. a.doc_id,
  181. c.sort ASC`
  182. sql = fmt.Sprintf(sql, condition)
  183. _, err = o.Raw(sql, pars).QueryRows(&items)
  184. return
  185. }