123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- package semantic_analysis
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- type SaCompare struct {
- SaCompareId int `gorm:"primaryKey;column:sa_compare_id;type:int(10) unsigned;not null"` // 语义分析-比对Id
- ClassifyId int `gorm:"index:idx_classify_id;column:classify_id;type:int(10) unsigned;not null;default:0"` // 比对分类Id
- ClassifyName string `gorm:"column:classify_name;type:varchar(128);not null;default:''"` // 比对分类名称
- Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 分析标题
- ResultImg string `gorm:"column:result_img;type:varchar(255);not null;default:''"` // 比对结果图片
- 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:''"` // 创建人姓名
- Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序
- CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
- }
- var SaCompareColumns = struct {
- SaCompareId string
- ClassifyId string
- ClassifyName string
- Title string
- ResultImg string
- SysAdminId string
- SysAdminName string
- Sort string
- CreateTime string
- ModifyTime string
- }{
- SaCompareId: "sa_compare_id",
- ClassifyId: "classify_id",
- ClassifyName: "classify_name",
- Title: "title",
- ResultImg: "result_img",
- SysAdminId: "sys_admin_id",
- SysAdminName: "sys_admin_name",
- Sort: "sort",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *SaCompare) TableName() string {
- return "sa_compare"
- }
- func (m *SaCompare) Create() (err error) {
- err = global.DEFAULT_DmSQL.Create(m).Error
- return
- }
- func (m *SaCompare) Update(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
- return
- }
- func (m *SaCompare) Del() (err error) {
- sql := `DELETE FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Exec(sql, m.SaCompareId).Error
- return
- }
- func (m *SaCompare) GetItemById(id int) (err error) {
- sql := `SELECT * FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
- return
- }
- func (m *SaCompare) GetItemByCondition(condition string, pars []interface{}) (err error) {
- sql := `SELECT * FROM sa_compare WHERE 1=1 `
- sql += condition
- sql += ` LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
- return
- }
- func (m *SaCompare) 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
- }
- func (m *SaCompare) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompare, 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 *SaCompare) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompare, 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 ?,?`
- pars = append(pars, startSize, pageSize)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- // SaCompareSaveReq 比对保存请求体
- type SaCompareSaveReq struct {
- SaCompareId int `description:"比对ID"`
- Title string `description:"标题"`
- ClassifyId int `description:"分类ID"`
- CompareList []struct {
- SaDocId int `description:"文档ID"`
- SectionList []struct {
- SaDocSectionId int `description:"段落ID"`
- IsPart int `description:"是否为片段: 0-整段; 1-片段"`
- StartIndex int `description:"片段开始下标"`
- EndIndex int `description:"片段结束下标"`
- Content string `description:"打标签的内容"`
- LabelIds []int `description:"标签IDs"`
- } `description:"段落标签信息"`
- } `description:"比对列表"`
- }
- // SaCompareSaveResp 比对保存响应体
- type SaCompareSaveResp struct {
- SaCompareId int `description:"比对ID"`
- TitleList []string `description:"标题列表"`
- LabelList []*SaCompareSaveRespLabel `description:"标签列表"`
- }
- // SaCompareSaveRespLabel 比对响应标签
- type SaCompareSaveRespLabel struct {
- SaLabelId int `description:"标签ID"`
- LabelName string `description:"标签名称"`
- DocList []*SaCompareSaveRespDoc `description:"文档列表"`
- }
- // SaCompareSaveRespDoc 比对响应文档
- type SaCompareSaveRespDoc struct {
- SaDocId int `description:"文档ID"`
- Title string `description:"文档标题"`
- SectionList []*SaCompareSaveRespSection `description:"段落列表"`
- }
- // SaCompareSaveRespSection 比对响应段落
- type SaCompareSaveRespSection struct {
- SaDocSectionId int `description:"段落ID"`
- IsPart int `description:"是否为片段: 0-否 1-是"`
- Content string `description:"段落内容"`
- }
- type SaComparePageListResp struct {
- List []*SaCompareItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type SaCompareItem struct {
- SaCompareId int `description:"比对ID"`
- ClassifyId int `description:"比对分类ID"`
- ClassifyName string `description:"比对分类名称"`
- Title string `description:"标题"`
- ResultImg string `description:"比对结果图片"`
- SysAdminId int `description:"创建人ID"`
- SysAdminName string `description:"创建人姓名"`
- CreateTime string `description:"创建时间"`
- }
- type SaCompareElastic struct {
- SaCompareId int `description:"比对ID"`
- ClassifyId int `description:"比对分类ID"`
- ClassifyName string `description:"比对分类名称"`
- Title string `description:"标题"`
- ResultImg string `description:"比对结果图片"`
- SysAdminId int `description:"创建人ID"`
- SysAdminName string `description:"创建人姓名"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- }
- // SaCompareUpdateResultImgReq 更新比对结果图片请求体
- type SaCompareUpdateResultImgReq struct {
- SaCompareId int `description:"比对ID"`
- ResultImg string `description:"结果图片"`
- }
- // UpdateSaCompareClassifyByClassifyId 更新比对分类信息
- func UpdateSaCompareClassifyByClassifyId(classifyId int, classifyName string) (err error) {
- sql := `UPDATE sa_compare SET classify_name = ? WHERE classify_id = ?`
- err = global.DEFAULT_DmSQL.Exec(sql, classifyName, classifyId).Error
- return
- }
- // CreateSaCompare 新增比对、比对段落和比对标签
- func CreateSaCompare(compareItem *SaCompare, compareDocs []*SaCompareDoc, compareLabels []*SaCompareLabel) (err error) {
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- // 新增比对
- e := tx.Create(compareItem).Error
- if e != nil {
- err = fmt.Errorf("insert compare err: %v", e)
- return
- }
- // 新增比对段落
- if len(compareDocs) > 0 {
- for i := range compareDocs {
- compareDocs[i].CompareId = compareItem.SaCompareId
- }
- e = tx.CreateInBatches(compareDocs, utils.MultiAddNum).Error
- if e != nil {
- err = fmt.Errorf("insert docs err: %v", e)
- return
- }
- }
- // 新增比对标签
- if len(compareLabels) > 0 {
- for i := range compareLabels {
- compareLabels[i].CompareId = compareItem.SaCompareId
- }
- e = tx.CreateInBatches(compareLabels, utils.MultiAddNum).Error
- if e != nil {
- err = fmt.Errorf("insert labels err: %v", e)
- return
- }
- }
- return
- }
- // UpdateSaCompare 保存比对、比对段落和比对标签
- func UpdateSaCompare(compareItem *SaCompare, compareDocs []*SaCompareDoc, compareLabels []*SaCompareLabel, compareUpCols []string) (err error) {
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- // 删除比对段落和标签
- sql := `DELETE FROM sa_compare_doc WHERE compare_id = ?`
- e := tx.Exec(sql, compareItem.SaCompareId).Error
- if e != nil {
- err = fmt.Errorf("delete docs err: %v", e)
- return
- }
- sql = `DELETE FROM sa_compare_label WHERE compare_id = ?`
- e = tx.Exec(sql, compareItem.SaCompareId).Error
- if e != nil {
- err = fmt.Errorf("delete labels err: %v", e)
- return
- }
- // 更新比对
- e = tx.Select(compareUpCols).Updates(compareItem).Error
- if e != nil {
- err = fmt.Errorf("update compare err: %v", e)
- return
- }
- // 新增比对段落
- if len(compareDocs) > 0 {
- for i := range compareDocs {
- compareDocs[i].CompareId = compareItem.SaCompareId
- }
- e = tx.CreateInBatches(compareDocs, utils.MultiAddNum).Error
- if e != nil {
- err = fmt.Errorf("insert docs err: %v", e)
- return
- }
- }
- // 新增比对标签
- if len(compareLabels) > 0 {
- for i := range compareLabels {
- compareLabels[i].CompareId = compareItem.SaCompareId
- }
- e = tx.CreateInBatches(compareLabels, utils.MultiAddNum).Error
- if e != nil {
- err = fmt.Errorf("insert labels err: %v", e)
- return
- }
- }
- return
- }
- type SaCompareDetail struct {
- SaCompareItem
- HeadLabel []*SaCompareDetailHeadLabel `description:"标签列表"`
- DocList []*SaCompareDetailDoc `description:"文档列表"`
- KeywordsList []string `description:"历史搜索关键词"`
- }
- type SaCompareDetailHeadLabel struct {
- LabelId int `description:"标签ID"`
- LabelName string `description:"标签名称"`
- IsMine int `description:"是否为我的:0-否;1-是"`
- }
- type SaCompareDetailDoc struct {
- DocId int `description:"文档ID"`
- Title string `description:"文档标题"`
- Theme string `description:"文档主题"`
- ClassifyName string `description:"分类名称"`
- SectionList []*SaCompareDetailSection `description:"段落列表"`
- }
- type SaCompareDetailSection struct {
- SectionId int `description:"段落ID"`
- Content string `description:"段落内容"`
- Sort int `description:"段落排序"`
- IsPart int `description:"是否为片段: 0-否; 1-是"`
- StartIndex int `description:"片段开始下标"`
- EndIndex int `description:"片段结束下标"`
- LabelList []*SaCompareDetailFormatLabel `description:"段落标签"`
- }
- type SaCompareDetailFormatLabel struct {
- LabelId int `description:"标签ID"`
- LabelName string `description:"标签名称"`
- IsThis int `description:"是否为当前标签"`
- IsHistory int `description:"是否为历史标签"`
- IsOther int `description:"是否为其他人标签"`
- }
- type SaCompareDelReq struct {
- SaCompareId int `description:"比对ID"`
- }
- // DelSaCompare 删除文档和段落
- func DelSaCompare(compareId int) (err error) {
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- // 删除比对/段落/标签
- sql := `DELETE FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
- e := tx.Exec(sql, compareId).Error
- if e != nil {
- err = fmt.Errorf("delete compare err: %v", e)
- return
- }
- sql = `DELETE FROM sa_compare_doc WHERE compare_id = ?`
- e = tx.Exec(sql, compareId).Error
- if e != nil {
- err = fmt.Errorf("delete docs err: %v", e)
- return
- }
- sql = `DELETE FROM sa_compare_label WHERE compare_id = ?`
- e = tx.Exec(sql, compareId).Error
- if e != nil {
- err = fmt.Errorf("delete labels err: %v", e)
- }
- return
- }
- // SaCompareMoveReq 移动比对请求体
- type SaCompareMoveReq struct {
- SaCompareClassifyId int `description:"比对分类ID"`
- SaCompareId int `description:"比对ID"`
- PrevSaCompareId int `description:"上一个比对ID"`
- NextSaCompareId int `description:"下一个比对ID"`
- }
- // UpdateSaCompareSort 根据分类ID更新排序
- func UpdateSaCompareSort(classifyId, nowSort int, prevId int, updateSort string) (err error) {
- sql := ` UPDATE sa_compare SET sort = ` + updateSort + ` WHERE classify_id = ? AND `
- if prevId > 0 {
- sql += ` ( sort > ? or ( sa_compare_id > ` + fmt.Sprint(prevId) + ` and sort = ` + fmt.Sprint(nowSort) + ` )) `
- }
- err = global.DEFAULT_DmSQL.Exec(sql, classifyId, nowSort).Error
- return
- }
- // GetFirstSortSaCompare 获取排序最前的比对
- func GetFirstSortSaCompare(classifyId int) (item *SaCompare, err error) {
- sql := ` SELECT * FROM sa_compare WHERE classify_id = ? ORDER BY sort ASC,sa_compare_id ASC LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Find(&item).Error
- return
- }
- // CompareListByEsResp 文档对比Es搜索返回
- type CompareListByEsResp struct {
- Paging *paging.PagingItem
- List []*SaCompareElastic
- }
|