sa_compare_label.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package semantic_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. type SaCompareLabel struct {
  9. SaCompareLabelId int `gorm:"primaryKey;column:sa_compare_label_id;type:int(10) unsigned;not null"` // 语义分析-文档段落标签Id
  10. CompareId int `gorm:"index:idx_compare_id;column:compare_id;type:int(10) unsigned;not null;default:0"` // 比对Id
  11. DocId int `gorm:"index:idx_doc_id;column:doc_id;type:int(10) unsigned;not null;default:0"` // 文档Id
  12. SectionId int `gorm:"index:idx_section_id;column:section_id;type:int(10) unsigned;not null;default:0"` // 段落Id
  13. LabelId int `gorm:"index:idx_label_id;column:label_id;type:int(10) unsigned;not null;default:0"` // 标签Id
  14. LabelName string `gorm:"column:label_name;type:varchar(128);not null;default:''"` // 标签名称
  15. IsPart int `gorm:"column:is_part;type:tinyint(4) unsigned;not null;default:0"` // 是否为片段:0-整段;1-片段
  16. StartIndex int `gorm:"column:start_index;type:int(10) unsigned;not null;default:0"` // 片段开始下标
  17. EndIndex int `gorm:"column:end_index;type:int(10) unsigned;not null;default:0"` // 片段结束下标
  18. Content string `gorm:"column:content;type:text"` // 内容
  19. SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  20. SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
  21. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  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. err = global.DEFAULT_DmSQL.Create(m).Error
  56. return
  57. }
  58. func (m *SaCompareLabel) Update(cols []string) (err error) {
  59. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  60. return
  61. }
  62. func (m *SaCompareLabel) Del() (err error) {
  63. sql := `DELETE FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
  64. err = global.DEFAULT_DmSQL.Exec(sql, m.SaCompareLabelId).Error
  65. return
  66. }
  67. func (m *SaCompareLabel) GetItemById(id int) (err error) {
  68. sql := `SELECT * FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
  69. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
  70. return
  71. }
  72. func (m *SaCompareLabel) GetItemByCondition(condition string, pars []interface{}) (err error) {
  73. sql := `SELECT * FROM sa_compare_label WHERE 1=1 `
  74. sql += condition
  75. sql += ` LIMIT 1`
  76. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
  77. return
  78. }
  79. func (m *SaCompareLabel) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  80. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  81. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  82. return
  83. }
  84. type SaCompareLabelGroupCount struct {
  85. DocId int `description:"文档ID"`
  86. SectionId int `description:"段落ID"`
  87. LabelId int `description:"标签ID"`
  88. UseNum int `description:"引用数"`
  89. }
  90. func (m *SaCompareLabel) GetGroupCountByCondition(condition string, pars []interface{}, groupRule string) (items []*SaCompareLabelGroupCount, err error) {
  91. sql := fmt.Sprintf(`SELECT COUNT(1) AS use_num, %s FROM %s WHERE 1=1 %s GROUP BY %s`, groupRule, m.TableName(), condition, groupRule)
  92. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  93. return
  94. }
  95. func (m *SaCompareLabel) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareLabel, err error) {
  96. fields := strings.Join(fieldArr, ",")
  97. if len(fieldArr) == 0 {
  98. fields = `*`
  99. }
  100. order := `ORDER BY create_time DESC`
  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. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  106. return
  107. }
  108. func (m *SaCompareLabel) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareLabel, err error) {
  109. fields := strings.Join(fieldArr, ",")
  110. if len(fieldArr) == 0 {
  111. fields = `*`
  112. }
  113. order := `ORDER BY create_time DESC`
  114. if orderRule != "" {
  115. order = ` ORDER BY ` + orderRule
  116. }
  117. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  118. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  119. err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
  120. if err != nil {
  121. return
  122. }
  123. sql += ` LIMIT ?,?`
  124. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  125. return
  126. }
  127. func UpdateSaCompareLabelByLabelId(labelId int, labelName string) (err error) {
  128. sql := `UPDATE sa_compare_label SET label_name = ? WHERE label_id = ?`
  129. err = global.DEFAULT_DmSQL.Exec(sql, labelName, labelId).Error
  130. return
  131. }
  132. type SaCompareLabelItem struct {
  133. SaCompareLabelId int `description:"比对标签ID"`
  134. LabelId int `description:"标签ID"`
  135. LabelName string `description:"标签名称"`
  136. CompareId int `description:"比对ID"`
  137. CompareContent string `description:"比对内容(片段)"`
  138. DocId int `description:"文档ID"`
  139. Title string `description:"文档标题"`
  140. SectionId int `description:"段落ID"`
  141. SectionContent string `description:"段落内容"`
  142. Sort int `description:"段落排序"`
  143. }
  144. func GetSaCompareLabelByCond(condition string, pars []interface{}) (items []*SaCompareLabelItem, err error) {
  145. sql := `SELECT
  146. a.sa_compare_label_id,
  147. a.label_id,
  148. a.label_name,
  149. a.compare_id,
  150. a.doc_id,
  151. a.content AS compare_content,
  152. b.title,
  153. c.sa_doc_section_id AS section_id,
  154. c.content AS section_content,
  155. c.sort
  156. FROM
  157. sa_compare_label AS a
  158. JOIN sa_doc AS b ON a.doc_id = b.sa_doc_id
  159. JOIN sa_doc_section AS c ON a.section_id = c.sa_doc_section_id
  160. WHERE
  161. 1 = 1 %s
  162. ORDER BY
  163. a.doc_id,
  164. c.sort ASC`
  165. sql = fmt.Sprintf(sql, condition)
  166. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  167. return
  168. }