sa_compare.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. package semantic_analysis
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. saModel "eta/eta_api/models/semantic_analysis"
  7. "eta/eta_api/services"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "html"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // SaCompareController 语义分析-文档比对
  17. type SaCompareController struct {
  18. controllers.BaseAuthController
  19. }
  20. // Save
  21. // @Title 保存比对
  22. // @Description 保存比对
  23. // @Param request body saModel.SaCompareSaveReq true "type json string"
  24. // @Success 200 Ret=200 操作成功
  25. // @router /compare/save [post]
  26. func (this *SaCompareController) Save() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. if br.ErrMsg == "" {
  30. br.IsSendEmail = false
  31. }
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. var req saModel.SaCompareSaveReq
  36. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  37. br.Msg = "参数解析异常!"
  38. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  39. return
  40. }
  41. req.Title = strings.TrimSpace(req.Title)
  42. if req.Title == "" {
  43. br.Msg = "请输入比对名称"
  44. return
  45. }
  46. if req.ClassifyId <= 0 {
  47. br.Msg = "请选择比对分类"
  48. return
  49. }
  50. if len(req.CompareList) == 0 {
  51. br.Msg = "请选择比对文档"
  52. return
  53. }
  54. //secIds := make([]int, 0)
  55. for _, d := range req.CompareList {
  56. if d.SaDocId <= 0 {
  57. br.Msg = "文档ID有误"
  58. return
  59. }
  60. //for _, s := range d.SectionList {
  61. // if !utils.InArrayByInt(secIds, s.SaDocSectionId) {
  62. // secIds = append(secIds, s.SaDocSectionId)
  63. // }
  64. //}
  65. }
  66. // 标题去重
  67. existItem := new(saModel.SaCompare)
  68. existCond := fmt.Sprintf(` AND %s = ?`, saModel.SaCompareColumns.Title)
  69. existPars := make([]interface{}, 0)
  70. existPars = append(existPars, req.Title)
  71. e := existItem.GetItemByCondition(existCond, existPars)
  72. if e != nil && e.Error() != utils.ErrNoRow() {
  73. br.Msg = "获取重名标题的比对失败"
  74. br.ErrMsg = "获取重名标题比对失败, Err: " + e.Error()
  75. return
  76. }
  77. if existItem != nil && existItem.SaCompareId > 0 {
  78. if existItem.SaCompareId != req.SaCompareId {
  79. br.Msg = "标题已存在"
  80. return
  81. }
  82. }
  83. nowTime := time.Now().Local()
  84. compareClassifyItem := new(saModel.SaCompareClassify)
  85. if e := compareClassifyItem.GetItemById(req.ClassifyId); e != nil {
  86. br.Msg = "操作失败"
  87. br.ErrMsg = "获取比对分类信息失败, Err: " + e.Error()
  88. return
  89. }
  90. compareItem := new(saModel.SaCompare)
  91. updateCols := make([]string, 0)
  92. if req.SaCompareId > 0 {
  93. // 编辑
  94. if e := compareItem.GetItemById(req.SaCompareId); e != nil {
  95. br.Msg = "操作失败"
  96. br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
  97. return
  98. }
  99. compareItem.ClassifyId = req.ClassifyId
  100. compareItem.ClassifyName = compareClassifyItem.ClassifyName
  101. compareItem.Title = req.Title
  102. compareItem.ModifyTime = nowTime
  103. updateCols = []string{
  104. saModel.SaCompareColumns.ClassifyId, saModel.SaCompareColumns.ClassifyName, saModel.SaCompareColumns.Title,
  105. saModel.SaCompareColumns.ModifyTime,
  106. }
  107. } else {
  108. // 新增
  109. compareItem.ClassifyId = req.ClassifyId
  110. compareItem.ClassifyName = compareClassifyItem.ClassifyName
  111. compareItem.Title = req.Title
  112. compareItem.SysAdminId = this.SysUser.AdminId
  113. compareItem.SysAdminName = this.SysUser.RealName
  114. compareItem.CreateTime = nowTime
  115. compareItem.ModifyTime = nowTime
  116. }
  117. // 标签匹配
  118. labelOB := new(saModel.SaLabel)
  119. labelCond := ``
  120. labelPars := make([]interface{}, 0)
  121. labelFields := []string{saModel.SaLabelColumns.SaLabelId, saModel.SaLabelColumns.LabelName}
  122. labelItems, e := labelOB.GetItemsByCondition(labelCond, labelPars, labelFields, "")
  123. if e != nil {
  124. br.Msg = "操作失败"
  125. br.ErrMsg = "获取标签列表失败, Err: " + e.Error()
  126. return
  127. }
  128. labelMap := make(map[int]string)
  129. for _, l := range labelItems {
  130. labelMap[l.SaLabelId] = l.LabelName
  131. }
  132. // 段落和标签
  133. compareDocs := make([]*saModel.SaCompareDoc, 0)
  134. compareLabels := make([]*saModel.SaCompareLabel, 0)
  135. for _, v := range req.CompareList {
  136. compareDocs = append(compareDocs, &saModel.SaCompareDoc{
  137. DocId: v.SaDocId,
  138. })
  139. for _, s := range v.SectionList {
  140. for _, l := range s.LabelIds {
  141. compareLabels = append(compareLabels, &saModel.SaCompareLabel{
  142. DocId: v.SaDocId,
  143. SectionId: s.SaDocSectionId,
  144. LabelId: l,
  145. LabelName: labelMap[l],
  146. IsPart: s.IsPart,
  147. StartIndex: s.StartIndex,
  148. EndIndex: s.EndIndex,
  149. Content: html.EscapeString(s.Content),
  150. SysAdminId: this.SysUser.AdminId,
  151. SysAdminName: this.SysUser.RealName,
  152. CreateTime: nowTime,
  153. })
  154. }
  155. }
  156. }
  157. // 新增/更新比对
  158. if req.SaCompareId > 0 {
  159. if e := saModel.UpdateSaCompare(compareItem, compareDocs, compareLabels, updateCols); e != nil {
  160. br.Msg = "保存失败"
  161. br.ErrMsg = "更新比对失败, Err: " + e.Error()
  162. return
  163. }
  164. } else {
  165. if e := saModel.CreateSaCompare(compareItem, compareDocs, compareLabels); e != nil {
  166. br.Msg = "保存失败"
  167. br.ErrMsg = "新增比对失败, Err: " + e.Error()
  168. return
  169. }
  170. }
  171. // 获取表格数据
  172. compLabCond := fmt.Sprintf(` AND a.%s = ?`, saModel.SaCompareLabelColumns.CompareId)
  173. compLabPars := make([]interface{}, 0)
  174. compLabPars = append(compLabPars, compareItem.SaCompareId)
  175. compLabs, e := saModel.GetSaCompareLabelByCond(compLabCond, compLabPars)
  176. if e != nil {
  177. br.Msg = "操作失败"
  178. br.ErrMsg = "获取比对标签列表失败, ErrMsg: " + e.Error()
  179. return
  180. }
  181. resp, e := services.FormatCompareLabels2TableData(compLabs)
  182. if e != nil {
  183. br.Msg = "操作失败"
  184. br.ErrMsg = "获取比对表格数据失败, ErrMsg: " + e.Error()
  185. return
  186. }
  187. resp.SaCompareId = compareItem.SaCompareId
  188. br.Data = resp
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = "操作成功"
  192. }
  193. // PageList
  194. // @Title 文档比对列表
  195. // @Description 文档比对列表
  196. // @Param Keyword query string false "关键词"
  197. // @Param ClassifyId query int false "分类ID"
  198. // @Success 200 Ret=200 获取成功
  199. // @router /compare/page_list [get]
  200. func (this *SaCompareController) PageList() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. if br.ErrMsg == "" {
  204. br.IsSendEmail = false
  205. }
  206. this.Data["json"] = br
  207. this.ServeJSON()
  208. }()
  209. keyword := this.GetString("Keyword", "")
  210. classifyId, _ := this.GetInt("ClassifyId", 0)
  211. var startSize int
  212. pageSize, _ := this.GetInt("PageSize")
  213. currentIndex, _ := this.GetInt("CurrentIndex")
  214. if pageSize <= 0 {
  215. pageSize = utils.PageSize20
  216. }
  217. if currentIndex <= 0 {
  218. currentIndex = 1
  219. }
  220. startSize = paging.StartIndex(currentIndex, pageSize)
  221. itemOB := new(saModel.SaCompare)
  222. cond := ``
  223. pars := make([]interface{}, 0)
  224. if keyword != "" {
  225. kw := "%" + keyword + "%"
  226. cond += fmt.Sprintf(` AND %s LIKE ?`, saModel.SaCompareColumns.Title)
  227. pars = append(pars, kw)
  228. }
  229. if classifyId > 0 {
  230. cond += fmt.Sprintf(` AND %s = ?`, saModel.SaCompareColumns.ClassifyId)
  231. pars = append(pars, classifyId)
  232. }
  233. total, list, e := itemOB.GetPageItemsByCondition(startSize, pageSize, cond, pars, []string{}, "")
  234. if e != nil {
  235. br.Msg = "获取失败"
  236. br.ErrMsg = "获取文档列表失败, Err: " + e.Error()
  237. return
  238. }
  239. respList := make([]*saModel.SaCompareItem, 0)
  240. for i := range list {
  241. v := new(saModel.SaCompareItem)
  242. v.SaCompareId = list[i].SaCompareId
  243. v.ClassifyId = list[i].ClassifyId
  244. v.ClassifyName = list[i].ClassifyName
  245. v.Title = list[i].Title
  246. v.ResultImg = list[i].ResultImg
  247. v.SysAdminId = list[i].SysAdminId
  248. v.SysAdminName = list[i].SysAdminName
  249. v.CreateTime = list[i].CreateTime.Format(utils.FormatDateTime)
  250. respList = append(respList, v)
  251. }
  252. page := paging.GetPaging(currentIndex, pageSize, total)
  253. resp := &saModel.SaComparePageListResp{
  254. Paging: page,
  255. List: respList,
  256. }
  257. br.Data = resp
  258. br.Ret = 200
  259. br.Success = true
  260. br.Msg = "获取成功"
  261. }
  262. // UpdateResultImg
  263. // @Title 更新比对结果图片
  264. // @Description 更新比对结果图片
  265. // @Param request body saModel.SaCompareUpdateResultImgReq true "type json string"
  266. // @Success 200 Ret=200 操作成功
  267. // @router /compare/update_result_img [post]
  268. func (this *SaCompareController) UpdateResultImg() {
  269. br := new(models.BaseResponse).Init()
  270. defer func() {
  271. if br.ErrMsg == "" {
  272. br.IsSendEmail = false
  273. }
  274. this.Data["json"] = br
  275. this.ServeJSON()
  276. }()
  277. var req saModel.SaCompareUpdateResultImgReq
  278. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  279. br.Msg = "参数解析异常!"
  280. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  281. return
  282. }
  283. if req.SaCompareId <= 0 {
  284. br.Msg = "参数有误"
  285. return
  286. }
  287. if req.ResultImg == "" {
  288. br.Msg = "请选择结果图片"
  289. return
  290. }
  291. compareItem := new(saModel.SaCompare)
  292. if e := compareItem.GetItemById(req.SaCompareId); e != nil {
  293. br.Msg = "操作失败"
  294. br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
  295. return
  296. }
  297. updateCols := []string{saModel.SaCompareColumns.ResultImg, saModel.SaCompareColumns.ModifyTime}
  298. compareItem.ResultImg = req.ResultImg
  299. compareItem.ModifyTime = time.Now().Local()
  300. if e := compareItem.Update(updateCols); e != nil {
  301. br.Msg = "操作失败"
  302. br.ErrMsg = "更新语义分析图片失败, Err: " + e.Error()
  303. return
  304. }
  305. br.Ret = 200
  306. br.Success = true
  307. br.Msg = "操作成功"
  308. }
  309. // Detail
  310. // @Title 比对详情
  311. // @Description 比对详情
  312. // @Param CompareId query int true "比对ID"
  313. // @Success 200 Ret=200 获取成功
  314. // @router /compare/detail [get]
  315. func (this *SaCompareController) Detail() {
  316. br := new(models.BaseResponse).Init()
  317. defer func() {
  318. if br.ErrMsg == "" {
  319. br.IsSendEmail = false
  320. }
  321. this.Data["json"] = br
  322. this.ServeJSON()
  323. }()
  324. compareId, _ := this.GetInt("CompareId", 0)
  325. if compareId <= 0 {
  326. br.Msg = "参数有误"
  327. return
  328. }
  329. compareItem := new(saModel.SaCompare)
  330. if e := compareItem.GetItemById(compareId); e != nil {
  331. br.Msg = "获取失败"
  332. br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
  333. return
  334. }
  335. // 比对文档IDs
  336. compDocOB := new(saModel.SaCompareDoc)
  337. compDocCond := fmt.Sprintf(` AND %s = ?`, saModel.SaCompareDocColumns.CompareId)
  338. compDocPars := make([]interface{}, 0)
  339. compDocPars = append(compDocPars, compareItem.SaCompareId)
  340. compDocs, e := compDocOB.GetItemsByCondition(compDocCond, compDocPars, []string{saModel.SaCompareDocColumns.DocId}, "")
  341. if e != nil {
  342. br.Msg = "获取失败"
  343. br.ErrMsg = "获取比对文档失败, Err: " + e.Error()
  344. return
  345. }
  346. compDocIds := make([]int, 0)
  347. for _, d := range compDocs {
  348. compDocIds = append(compDocIds, d.DocId)
  349. }
  350. // 比对详情
  351. detail := new(saModel.SaCompareDetail)
  352. detail.SaCompareId = compareItem.SaCompareId
  353. detail.ClassifyId = compareItem.ClassifyId
  354. detail.ClassifyName = compareItem.ClassifyName
  355. detail.Title = compareItem.Title
  356. detail.ResultImg = compareItem.ResultImg
  357. detail.SysAdminId = compareItem.SysAdminId
  358. detail.SysAdminName = compareItem.SysAdminName
  359. detail.CreateTime = compareItem.CreateTime.Format(utils.FormatDateTime)
  360. // 文档详情
  361. docDetail, e := services.GetSaCompareDetailByDocIds(compDocIds, compareId, this.SysUser.AdminId)
  362. if e != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取比对详情信息失败, ErrMsg: " + e.Error()
  365. return
  366. }
  367. detail.HeadLabel = docDetail.HeadLabel
  368. detail.DocList = docDetail.DocList
  369. detail.KeywordsList = docDetail.KeywordsList
  370. br.Data = detail
  371. br.Ret = 200
  372. br.Success = true
  373. br.Msg = "获取成功"
  374. }
  375. // SelectDocs
  376. // @Title 选择比对文档
  377. // @Description 选择比对文档
  378. // @Param DocIds query string true "文档IDs"
  379. // @Success 200 Ret=200 获取成功
  380. // @router /compare/select_docs [get]
  381. func (this *SaCompareController) SelectDocs() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. if br.ErrMsg == "" {
  385. br.IsSendEmail = false
  386. }
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. docIdStr := this.GetString("DocIds", "")
  391. if docIdStr == "" {
  392. br.Msg = "请选择文档"
  393. return
  394. }
  395. docIds := make([]int, 0)
  396. docIdArr := strings.Split(docIdStr, ",")
  397. if len(docIdArr) == 0 {
  398. br.Msg = "请选择文档"
  399. return
  400. }
  401. if len(docIdArr) > 10 {
  402. br.Msg = "最多支持选择10个文档"
  403. return
  404. }
  405. for i := range docIdArr {
  406. d, e := strconv.Atoi(docIdArr[i])
  407. if e != nil {
  408. br.Msg = "文档ID有误"
  409. return
  410. }
  411. docIds = append(docIds, d)
  412. }
  413. resp, e := services.GetSaCompareDetailByDocIds(docIds, 0, this.SysUser.AdminId)
  414. if e != nil {
  415. br.Msg = "获取失败"
  416. br.ErrMsg = "获取选择的文档详情失败, ErrMsg: " + e.Error()
  417. return
  418. }
  419. br.Data = resp
  420. br.Ret = 200
  421. br.Success = true
  422. br.Msg = "获取成功"
  423. }
  424. // Del
  425. // @Title 删除语义分析
  426. // @Description 删除语义分析
  427. // @Param request body saModel.SaCompareDelReq true "type json string"
  428. // @Success 200 Ret=200 操作成功
  429. // @router /compare/del [post]
  430. func (this *SaCompareController) Del() {
  431. br := new(models.BaseResponse).Init()
  432. defer func() {
  433. if br.ErrMsg == "" {
  434. br.IsSendEmail = false
  435. }
  436. this.Data["json"] = br
  437. this.ServeJSON()
  438. }()
  439. var req saModel.SaCompareDelReq
  440. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  441. br.Msg = "参数解析异常!"
  442. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  443. return
  444. }
  445. if req.SaCompareId <= 0 {
  446. br.Msg = "参数有误"
  447. return
  448. }
  449. // TODO:可能会有只让自己或者管理员删除的需求,目前无
  450. item := new(saModel.SaCompare)
  451. e := item.GetItemById(req.SaCompareId)
  452. if e != nil {
  453. if e.Error() == utils.ErrNoRow() {
  454. br.Msg = "文档比对已被删除, 请刷新页面"
  455. return
  456. }
  457. br.Msg = "操作失败"
  458. br.ErrMsg = "获取语义分析比对信息失败, Err: " + e.Error()
  459. return
  460. }
  461. // 删除比对及相关
  462. if e = saModel.DelSaCompare(item.SaCompareId); e != nil {
  463. br.Msg = "操作失败"
  464. br.ErrMsg = "删除语义分析比对失败, Err: " + e.Error()
  465. return
  466. }
  467. br.Ret = 200
  468. br.Success = true
  469. br.Msg = "操作成功"
  470. }
  471. // SaveKeywords
  472. // @Title 保存关键词
  473. // @Description 保存比对
  474. // @Param request body saModel.SaCompareSearchKeywordSaveReq true "type json string"
  475. // @Success 200 Ret=200 操作成功
  476. // @router /compare/save_keywords [post]
  477. func (this *SaCompareController) SaveKeywords() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. if br.ErrMsg == "" {
  481. br.IsSendEmail = false
  482. }
  483. this.Data["json"] = br
  484. this.ServeJSON()
  485. }()
  486. var req saModel.SaCompareSearchKeywordSaveReq
  487. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  488. br.Msg = "参数解析异常!"
  489. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  490. return
  491. }
  492. if req.SaCompareId <= 0 {
  493. br.Msg = "参数异常"
  494. return
  495. }
  496. keywords := make([]string, 0)
  497. for k := range req.Keywords {
  498. v := strings.TrimSpace(req.Keywords[k])
  499. if v != "" {
  500. keywords = append(keywords, v)
  501. }
  502. }
  503. keywordOB := new(saModel.SaCompareSearchKeyword)
  504. if e := keywordOB.DelAndCreateSearchKeywords(req.SaCompareId, keywords); e != nil {
  505. br.Msg = "操作失败"
  506. br.ErrMsg = "保存搜索关键词失败, Err: " + e.Error()
  507. return
  508. }
  509. br.Ret = 200
  510. br.Success = true
  511. br.Msg = "操作成功"
  512. }
  513. // Move
  514. // @Title 移动比对
  515. // @Description 移动比对
  516. // @Param request body saModel.SaCompareMoveReq true "type json string"
  517. // @Success 200 Ret=200 操作成功
  518. // @router /compare/move [post]
  519. func (this *SaCompareController) Move() {
  520. br := new(models.BaseResponse).Init()
  521. defer func() {
  522. if br.ErrMsg == "" {
  523. br.IsSendEmail = false
  524. }
  525. this.Data["json"] = br
  526. this.ServeJSON()
  527. }()
  528. var req saModel.SaCompareMoveReq
  529. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  530. br.Msg = "参数解析异常!"
  531. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  532. return
  533. }
  534. if req.SaCompareClassifyId <= 0 {
  535. br.Msg = "请选择分类"
  536. return
  537. }
  538. if req.SaCompareId <= 0 {
  539. br.Msg = "参数异常"
  540. return
  541. }
  542. item := new(saModel.SaCompare)
  543. e := item.GetItemById(req.SaCompareId)
  544. if e != nil {
  545. if e.Error() == utils.ErrNoRow() {
  546. br.Msg = "比对已被删除, 请刷新页面"
  547. return
  548. }
  549. br.Msg = "操作失败"
  550. br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
  551. return
  552. }
  553. // 分类
  554. classifyItem := new(saModel.SaCompareClassify)
  555. if e = classifyItem.GetItemById(req.SaCompareClassifyId); e != nil {
  556. br.Msg = "分类信息有误"
  557. br.ErrMsg = "获取比对分类信息失败, Err: " + e.Error()
  558. return
  559. }
  560. // CV的指标库指标的移动, 没有技术, 全是感情~
  561. if req.PrevSaCompareId > 0 {
  562. prevCompare := new(saModel.SaCompare)
  563. if e = prevCompare.GetItemById(req.PrevSaCompareId); e != nil {
  564. if e.Error() == utils.ErrNoRow() {
  565. br.Msg = "上一个比对已被删除, 请刷新页面"
  566. return
  567. }
  568. br.Msg = "操作失败"
  569. br.ErrMsg = "获取上一个比对信息失败, Err: " + e.Error()
  570. return
  571. }
  572. // 如果是在两个比对之间
  573. if req.NextSaCompareId > 0 {
  574. nextCompare := new(saModel.SaCompare)
  575. if e = nextCompare.GetItemById(req.NextSaCompareId); e != nil {
  576. if e.Error() == utils.ErrNoRow() {
  577. br.Msg = "下一个比对已被删除, 请刷新页面"
  578. return
  579. }
  580. br.Msg = "操作失败"
  581. br.ErrMsg = "获取下一个比对信息失败, Err: " + e.Error()
  582. return
  583. }
  584. // 判断上一个比对与当前比对/下一个比对的位置
  585. if prevCompare.Sort == item.Sort || prevCompare.Sort == nextCompare.Sort {
  586. _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 2`)
  587. } else {
  588. if nextCompare.Sort-prevCompare.Sort == 1 {
  589. _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 1`)
  590. }
  591. }
  592. }
  593. item.Sort = prevCompare.Sort + 1
  594. } else {
  595. firstCompare, e := saModel.GetFirstSortSaCompare(req.SaCompareClassifyId)
  596. if e != nil && e.Error() != utils.ErrNoRow() {
  597. br.Msg = "操作失败"
  598. br.ErrMsg = "获取首个比对失败, Err: " + e.Error()
  599. return
  600. }
  601. if firstCompare != nil && firstCompare.Sort == 0 {
  602. _ = saModel.UpdateSaCompareSort(firstCompare.ClassifyId, 0, firstCompare.SaCompareId-1, `sort + 1`)
  603. }
  604. item.Sort = 0
  605. }
  606. // 更新
  607. item.ClassifyId = classifyItem.SaCompareClassifyId
  608. item.ClassifyName = classifyItem.ClassifyName
  609. item.ModifyTime = time.Now().Local()
  610. updateCols := []string{
  611. saModel.SaCompareColumns.ClassifyId, saModel.SaCompareColumns.ClassifyName, saModel.SaCompareColumns.Sort, saModel.SaCompareColumns.ModifyTime,
  612. }
  613. if e = item.Update(updateCols); e != nil {
  614. br.Msg = "操作失败"
  615. br.ErrMsg = "移动比对失败, Err: " + e.Error()
  616. return
  617. }
  618. br.Ret = 200
  619. br.Success = true
  620. br.Msg = "操作成功"
  621. }
  622. // Search
  623. // @Title 文档对比搜索(从es获取)
  624. // @Description 图表模糊搜索(从es获取)
  625. // @Param Keyword query string true "文档对比标题"
  626. // @Success 200 {object} saModel.CompareListByEsResp
  627. // @router /compare/search [get]
  628. func (this *SaCompareController) Search() {
  629. br := new(models.BaseResponse).Init()
  630. defer func() {
  631. this.Data["json"] = br
  632. this.ServeJSON()
  633. }()
  634. sysUser := this.SysUser
  635. if sysUser == nil {
  636. br.Msg = "请登录"
  637. br.ErrMsg = "请登录,SysUser Is Empty"
  638. br.Ret = 408
  639. return
  640. }
  641. pageSize, _ := this.GetInt("PageSize")
  642. currentIndex, _ := this.GetInt("CurrentIndex")
  643. var startSize int
  644. if pageSize <= 0 {
  645. pageSize = utils.PageSize20
  646. }
  647. if currentIndex <= 0 {
  648. currentIndex = 1
  649. }
  650. startSize = paging.StartIndex(currentIndex, pageSize)
  651. keyword := this.GetString("Keyword")
  652. var searchList []*saModel.SaCompareElastic
  653. var total int
  654. var err error
  655. var list []*saModel.SaCompare
  656. saCompare := new(saModel.SaCompare)
  657. existCond := fmt.Sprintf(` AND result_img != ""`)
  658. existPars := make([]interface{}, 0)
  659. if keyword != "" {
  660. existCond += ` AND ( title LIKE ? )`
  661. existPars = append(existPars, utils.GetLikeKeyword(keyword))
  662. }
  663. total, list, err = saCompare.GetPageItemsByCondition(startSize, pageSize, existCond, existPars, []string{}, "")
  664. if err != nil && err.Error() != utils.ErrNoRow() {
  665. br.Msg = "获取失败"
  666. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  667. return
  668. }
  669. for _, v := range list {
  670. tmp := new(saModel.SaCompareElastic)
  671. tmp.SaCompareId = v.SaCompareId
  672. tmp.ResultImg = v.ResultImg
  673. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  674. tmp.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  675. tmp.SysAdminId = v.SysAdminId
  676. tmp.SysAdminName = v.SysAdminName
  677. tmp.ClassifyId = v.ClassifyId
  678. tmp.ClassifyName = v.ClassifyName
  679. tmp.Title = v.Title
  680. searchList = append(searchList, tmp)
  681. }
  682. page := paging.GetPaging(currentIndex, pageSize, total)
  683. resp := saModel.CompareListByEsResp{
  684. Paging: page,
  685. List: searchList,
  686. }
  687. br.Ret = 200
  688. br.Success = true
  689. br.Msg = "获取成功"
  690. br.Data = resp
  691. }