sa_compare.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. package semantic_analysis
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_eta_api/controllers"
  7. "hongze/hz_eta_api/models"
  8. saModel "hongze/hz_eta_api/models/semantic_analysis"
  9. "hongze/hz_eta_api/services"
  10. "hongze/hz_eta_api/utils"
  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. for i := range docIdArr {
  402. d, e := strconv.Atoi(docIdArr[i])
  403. if e != nil {
  404. br.Msg = "文档ID有误"
  405. return
  406. }
  407. docIds = append(docIds, d)
  408. }
  409. resp, e := services.GetSaCompareDetailByDocIds(docIds, 0, this.SysUser.AdminId)
  410. if e != nil {
  411. br.Msg = "获取失败"
  412. br.ErrMsg = "获取选择的文档详情失败, ErrMsg: " + e.Error()
  413. return
  414. }
  415. br.Data = resp
  416. br.Ret = 200
  417. br.Success = true
  418. br.Msg = "获取成功"
  419. }
  420. // Del
  421. // @Title 删除语义分析
  422. // @Description 删除语义分析
  423. // @Param request body saModel.SaCompareDelReq true "type json string"
  424. // @Success 200 Ret=200 操作成功
  425. // @router /compare/del [post]
  426. func (this *SaCompareController) Del() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. if br.ErrMsg == "" {
  430. br.IsSendEmail = false
  431. }
  432. this.Data["json"] = br
  433. this.ServeJSON()
  434. }()
  435. var req saModel.SaCompareDelReq
  436. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  437. br.Msg = "参数解析异常!"
  438. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  439. return
  440. }
  441. if req.SaCompareId <= 0 {
  442. br.Msg = "参数有误"
  443. return
  444. }
  445. // TODO:可能会有只让自己或者管理员删除的需求,目前无
  446. item := new(saModel.SaCompare)
  447. e := item.GetItemById(req.SaCompareId)
  448. if e != nil {
  449. if e.Error() == utils.ErrNoRow() {
  450. br.Msg = "文档比对已被删除, 请刷新页面"
  451. return
  452. }
  453. br.Msg = "操作失败"
  454. br.ErrMsg = "获取语义分析比对信息失败, Err: " + e.Error()
  455. return
  456. }
  457. // 删除比对及相关
  458. if e = saModel.DelSaCompare(item.SaCompareId); e != nil {
  459. br.Msg = "操作失败"
  460. br.ErrMsg = "删除语义分析比对失败, Err: " + e.Error()
  461. return
  462. }
  463. br.Ret = 200
  464. br.Success = true
  465. br.Msg = "操作成功"
  466. }
  467. // SaveKeywords
  468. // @Title 保存关键词
  469. // @Description 保存比对
  470. // @Param request body saModel.SaCompareSearchKeywordSaveReq true "type json string"
  471. // @Success 200 Ret=200 操作成功
  472. // @router /compare/save_keywords [post]
  473. func (this *SaCompareController) SaveKeywords() {
  474. br := new(models.BaseResponse).Init()
  475. defer func() {
  476. if br.ErrMsg == "" {
  477. br.IsSendEmail = false
  478. }
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. var req saModel.SaCompareSearchKeywordSaveReq
  483. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  484. br.Msg = "参数解析异常!"
  485. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  486. return
  487. }
  488. if req.SaCompareId <= 0 {
  489. br.Msg = "参数异常"
  490. return
  491. }
  492. keywords := make([]string, 0)
  493. for k := range req.Keywords {
  494. v := strings.TrimSpace(req.Keywords[k])
  495. if v != "" {
  496. keywords = append(keywords, v)
  497. }
  498. }
  499. keywordOB := new(saModel.SaCompareSearchKeyword)
  500. if e := keywordOB.DelAndCreateSearchKeywords(req.SaCompareId, keywords); e != nil {
  501. br.Msg = "操作失败"
  502. br.ErrMsg = "保存搜索关键词失败, Err: " + e.Error()
  503. return
  504. }
  505. br.Ret = 200
  506. br.Success = true
  507. br.Msg = "操作成功"
  508. }
  509. // Move
  510. // @Title 移动比对
  511. // @Description 移动比对
  512. // @Param request body saModel.SaCompareMoveReq true "type json string"
  513. // @Success 200 Ret=200 操作成功
  514. // @router /compare/move [post]
  515. func (this *SaCompareController) Move() {
  516. br := new(models.BaseResponse).Init()
  517. defer func() {
  518. if br.ErrMsg == "" {
  519. br.IsSendEmail = false
  520. }
  521. this.Data["json"] = br
  522. this.ServeJSON()
  523. }()
  524. var req saModel.SaCompareMoveReq
  525. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  526. br.Msg = "参数解析异常!"
  527. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  528. return
  529. }
  530. if req.SaCompareClassifyId <= 0 {
  531. br.Msg = "请选择分类"
  532. return
  533. }
  534. if req.SaCompareId <= 0 {
  535. br.Msg = "参数异常"
  536. return
  537. }
  538. item := new(saModel.SaCompare)
  539. e := item.GetItemById(req.SaCompareId)
  540. if e != nil {
  541. if e.Error() == utils.ErrNoRow() {
  542. br.Msg = "比对已被删除, 请刷新页面"
  543. return
  544. }
  545. br.Msg = "操作失败"
  546. br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
  547. return
  548. }
  549. // 分类
  550. classifyItem := new(saModel.SaCompareClassify)
  551. if e = classifyItem.GetItemById(req.SaCompareClassifyId); e != nil {
  552. br.Msg = "分类信息有误"
  553. br.ErrMsg = "获取比对分类信息失败, Err: " + e.Error()
  554. return
  555. }
  556. // CV的指标库指标的移动, 没有技术, 全是感情~
  557. if req.PrevSaCompareId > 0 {
  558. prevCompare := new(saModel.SaCompare)
  559. if e = prevCompare.GetItemById(req.PrevSaCompareId); e != nil {
  560. if e.Error() == utils.ErrNoRow() {
  561. br.Msg = "上一个比对已被删除, 请刷新页面"
  562. return
  563. }
  564. br.Msg = "操作失败"
  565. br.ErrMsg = "获取上一个比对信息失败, Err: " + e.Error()
  566. return
  567. }
  568. // 如果是在两个比对之间
  569. if req.NextSaCompareId > 0 {
  570. nextCompare := new(saModel.SaCompare)
  571. if e = nextCompare.GetItemById(req.NextSaCompareId); e != nil {
  572. if e.Error() == utils.ErrNoRow() {
  573. br.Msg = "下一个比对已被删除, 请刷新页面"
  574. return
  575. }
  576. br.Msg = "操作失败"
  577. br.ErrMsg = "获取下一个比对信息失败, Err: " + e.Error()
  578. return
  579. }
  580. // 判断上一个比对与当前比对/下一个比对的位置
  581. if prevCompare.Sort == item.Sort || prevCompare.Sort == nextCompare.Sort {
  582. _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 2`)
  583. } else {
  584. if nextCompare.Sort-prevCompare.Sort == 1 {
  585. _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 1`)
  586. }
  587. }
  588. }
  589. item.Sort = prevCompare.Sort + 1
  590. } else {
  591. firstCompare, e := saModel.GetFirstSortSaCompare(req.SaCompareClassifyId)
  592. if e != nil && e.Error() != utils.ErrNoRow() {
  593. br.Msg = "操作失败"
  594. br.ErrMsg = "获取首个比对失败, Err: " + e.Error()
  595. return
  596. }
  597. if firstCompare != nil && firstCompare.Sort == 0 {
  598. _ = saModel.UpdateSaCompareSort(firstCompare.ClassifyId, 0, firstCompare.SaCompareId-1, `sort + 1`)
  599. }
  600. item.Sort = 0
  601. }
  602. // 更新
  603. item.ClassifyId = classifyItem.SaCompareClassifyId
  604. item.ClassifyName = classifyItem.ClassifyName
  605. item.ModifyTime = time.Now().Local()
  606. updateCols := []string{
  607. saModel.SaCompareColumns.ClassifyId, saModel.SaCompareColumns.ClassifyName, saModel.SaCompareColumns.Sort, saModel.SaCompareColumns.ModifyTime,
  608. }
  609. if e = item.Update(updateCols); e != nil {
  610. br.Msg = "操作失败"
  611. br.ErrMsg = "移动比对失败, Err: " + e.Error()
  612. return
  613. }
  614. br.Ret = 200
  615. br.Success = true
  616. br.Msg = "操作成功"
  617. }