sa_compare.go 18 KB

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