sa_compare_label.go 6.5 KB

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