123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- package semantic_analysis
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "strings"
- "time"
- )
- type SaCompareLabel struct {
- SaCompareLabelId int `gorm:"primaryKey;column:sa_compare_label_id;type:int(10) unsigned;not null"` // 语义分析-文档段落标签Id
- CompareId int `gorm:"index:idx_compare_id;column:compare_id;type:int(10) unsigned;not null;default:0"` // 比对Id
- DocId int `gorm:"index:idx_doc_id;column:doc_id;type:int(10) unsigned;not null;default:0"` // 文档Id
- SectionId int `gorm:"index:idx_section_id;column:section_id;type:int(10) unsigned;not null;default:0"` // 段落Id
- LabelId int `gorm:"index:idx_label_id;column:label_id;type:int(10) unsigned;not null;default:0"` // 标签Id
- LabelName string `gorm:"column:label_name;type:varchar(128);not null;default:''"` // 标签名称
- IsPart int `gorm:"column:is_part;type:tinyint(4) unsigned;not null;default:0"` // 是否为片段:0-整段;1-片段
- StartIndex int `gorm:"column:start_index;type:int(10) unsigned;not null;default:0"` // 片段开始下标
- EndIndex int `gorm:"column:end_index;type:int(10) unsigned;not null;default:0"` // 片段结束下标
- Content string `gorm:"column:content;type:text"` // 内容
- SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
- SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
- CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
- }
- var SaCompareLabelColumns = struct {
- SaCompareLabelId string
- CompareId string
- DocId string
- SectionId string
- LabelId string
- LabelName string
- IsPart string
- StartIndex string
- EndIndex string
- Content string
- SysAdminId string
- SysAdminName string
- CreateTime string
- }{
- SaCompareLabelId: "sa_compare_label_id",
- CompareId: "compare_id",
- DocId: "doc_id",
- SectionId: "section_id",
- LabelId: "label_id",
- LabelName: "label_name",
- IsPart: "is_part",
- StartIndex: "start_index",
- EndIndex: "end_index",
- SysAdminId: "sys_admin_id",
- SysAdminName: "sys_admin_name",
- CreateTime: "create_time",
- }
- func (m *SaCompareLabel) TableName() string {
- return "sa_compare_label"
- }
- func (m *SaCompareLabel) Create() (err error) {
- err = global.DEFAULT_DmSQL.Create(m).Error
- return
- }
- func (m *SaCompareLabel) Update(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
- return
- }
- func (m *SaCompareLabel) Del() (err error) {
- sql := `DELETE FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Exec(sql, m.SaCompareLabelId).Error
- return
- }
- func (m *SaCompareLabel) GetItemById(id int) (err error) {
- sql := `SELECT * FROM sa_compare_label WHERE sa_compare_label_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
- return
- }
- func (m *SaCompareLabel) GetItemByCondition(condition string, pars []interface{}) (err error) {
- sql := `SELECT * FROM sa_compare_label WHERE 1=1 `
- sql += condition
- sql += ` LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
- return
- }
- func (m *SaCompareLabel) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- type SaCompareLabelGroupCount struct {
- DocId int `description:"文档ID"`
- SectionId int `description:"段落ID"`
- LabelId int `description:"标签ID"`
- UseNum int `description:"引用数"`
- }
- func (m *SaCompareLabel) GetGroupCountByCondition(condition string, pars []interface{}, groupRule string) (items []*SaCompareLabelGroupCount, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) AS use_num, %s FROM %s WHERE 1=1 %s GROUP BY %s`, groupRule, m.TableName(), condition, groupRule)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *SaCompareLabel) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompareLabel, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *SaCompareLabel) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompareLabel, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
- err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
- if err != nil {
- return
- }
- sql += ` LIMIT ?,?`
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- // UpdateSaCompareLabelByLabelId 更新比对标签信息
- func UpdateSaCompareLabelByLabelId(labelId int, labelName string) (err error) {
- sql := `UPDATE sa_compare_label SET label_name = ? WHERE label_id = ?`
- err = global.DEFAULT_DmSQL.Exec(sql, labelName, labelId).Error
- return
- }
- // SaCompareLabelItem 比对标签
- type SaCompareLabelItem struct {
- SaCompareLabelId int `description:"比对标签ID"`
- LabelId int `description:"标签ID"`
- LabelName string `description:"标签名称"`
- CompareId int `description:"比对ID"`
- CompareContent string `description:"比对内容(片段)"`
- DocId int `description:"文档ID"`
- Title string `description:"文档标题"`
- SectionId int `description:"段落ID"`
- SectionContent string `description:"段落内容"`
- Sort int `description:"段落排序"`
- }
- // GetSaCompareLabelByCond 获取比对标签
- func GetSaCompareLabelByCond(condition string, pars []interface{}) (items []*SaCompareLabelItem, err error) {
- sql := `SELECT
- a.sa_compare_label_id,
- a.label_id,
- a.label_name,
- a.compare_id,
- a.doc_id,
- a.content AS compare_content,
- b.title,
- c.sa_doc_section_id AS section_id,
- c.content AS section_content,
- c.sort
- FROM
- sa_compare_label AS a
- JOIN sa_doc AS b ON a.doc_id = b.sa_doc_id
- JOIN sa_doc_section AS c ON a.section_id = c.sa_doc_section_id
- WHERE
- 1 = 1 %s
- ORDER BY
- a.doc_id,
- c.sort ASC`
- sql = fmt.Sprintf(sql, condition)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
|