ai_summary.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. package ai
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/ai_summary"
  6. "eta/eta_api/models/sandbox"
  7. aiSummaryService "eta/eta_api/services/ai_summary"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "strconv"
  12. "time"
  13. )
  14. // AiSummaryClassifyItems
  15. // @Title 获取所有ai纪要分类接口
  16. // @Description 获取所有ai纪要分类接口
  17. // @Param IsShowMe query bool true "是否只看我的,true、false"
  18. // @Success 200 {object} data_manage.ChartClassifyListResp
  19. // @router /summary/classify/list [get]
  20. func (this *AiController) AiSummaryClassifyItems() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. resp := new(ai_summary.AiSummaryClassifyListResp)
  27. aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
  28. isShowMe, _ := this.GetBool("IsShowMe")
  29. if isShowMe {
  30. errMsg, err := aiSummaryService.GetAiSummaryClassifyListForMe(*this.SysUser, resp, aiSummaryClassifyId)
  31. if err != nil {
  32. br.Msg = errMsg
  33. br.ErrMsg = err.Error()
  34. return
  35. }
  36. br.Ret = 200
  37. br.Success = true
  38. br.Msg = "获取成功"
  39. br.Data = resp
  40. fmt.Println("source my classify")
  41. return
  42. }
  43. rootList, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
  44. if err != nil && err.Error() != utils.ErrNoRow() {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  47. return
  48. }
  49. for k := range rootList {
  50. rootList[k].UniqueCode = strconv.Itoa(rootList[k].AiSummaryClassifyId) + "_" + strconv.Itoa(rootList[k].AiSummaryId)
  51. }
  52. classifyAll, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
  53. if err != nil && err.Error() != utils.ErrNoRow() {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  56. return
  57. }
  58. for k := range classifyAll {
  59. classifyAll[k].UniqueCode = strconv.Itoa(classifyAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(classifyAll[k].AiSummaryId)
  60. }
  61. nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
  62. for k := range rootList {
  63. rootNode := rootList[k]
  64. aiSummaryService.AiSummaryClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  65. nodeAll = append(nodeAll, rootNode)
  66. }
  67. resp.AllNodes = nodeAll
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "获取成功"
  71. br.Data = resp
  72. }
  73. // @Title 新增ai纪要分类
  74. // @Description 新增ai纪要分类接口
  75. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  76. // @Success 200 Ret=200 保存成功
  77. // @router /summary/classify/add [post]
  78. func (this *AiController) AddSandboxClassify() {
  79. br := new(models.BaseResponse).Init()
  80. defer func() {
  81. this.Data["json"] = br
  82. this.ServeJSON()
  83. }()
  84. var req ai_summary.AddAiSummaryClassifyReq
  85. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  86. if err != nil {
  87. br.Msg = "参数解析异常!"
  88. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  89. return
  90. }
  91. if req.ClassifyName == "" {
  92. br.Msg = "请输入分类名称"
  93. br.IsSendEmail = false
  94. return
  95. }
  96. if req.ParentId < 0 {
  97. br.Msg = "参数错误"
  98. br.IsSendEmail = false
  99. return
  100. }
  101. count, err := ai_summary.GetAiSummaryClassifyCount(req.ClassifyName, req.ParentId)
  102. if err != nil {
  103. br.Msg = "判断名称是否已存在失败"
  104. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  105. return
  106. }
  107. if count > 0 {
  108. br.Msg = "分类名称已存在,请重新输入"
  109. br.IsSendEmail = false
  110. return
  111. }
  112. //获取该层级下最大的排序数
  113. maxSort, err := ai_summary.GetAiSummaryClassifyMaxSort(req.ParentId)
  114. classify := new(ai_summary.AiSummaryClassify)
  115. classify.ParentId = req.ParentId
  116. classify.ClassifyName = req.ClassifyName
  117. classify.HasData = 0
  118. classify.CreateTime = time.Now()
  119. classify.ModifyTime = time.Now()
  120. classify.SysUserId = this.SysUser.AdminId
  121. classify.SysUserRealName = this.SysUser.RealName
  122. classify.Level = req.Level + 1
  123. classify.Sort = maxSort + 1
  124. _, err = ai_summary.AddAiSummaryClassify(classify)
  125. if err != nil {
  126. br.Msg = "保存分类失败"
  127. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  128. return
  129. }
  130. br.Ret = 200
  131. br.Msg = "保存成功"
  132. br.Success = true
  133. }
  134. // @Title 修改ai纪要分类
  135. // @Description 修改ai纪要分类接口
  136. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  137. // @Success 200 Ret=200 修改成功
  138. // @router /summary/classify/edit [post]
  139. func (this *AiController) EditAiSummaryClassify() {
  140. br := new(models.BaseResponse).Init()
  141. defer func() {
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. var req ai_summary.EditAiSummaryClassifyReq
  146. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  147. if err != nil {
  148. br.Msg = "参数解析异常!"
  149. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  150. return
  151. }
  152. if req.ClassifyName == "" {
  153. br.Msg = "请输入分类名称"
  154. br.IsSendEmail = false
  155. return
  156. }
  157. if req.AiSummaryClassifyId <= 0 {
  158. br.Msg = "参数错误"
  159. br.IsSendEmail = false
  160. return
  161. }
  162. err = ai_summary.EditSandboxClassify(req.AiSummaryClassifyId, req.ClassifyName)
  163. if err != nil {
  164. br.Msg = "保存失败"
  165. br.ErrMsg = "保存失败,Err:" + err.Error()
  166. return
  167. }
  168. br.Ret = 200
  169. br.Msg = "保存成功"
  170. br.Success = true
  171. br.IsAddLog = true
  172. }
  173. // @Title 删除纪要分类检测接口
  174. // @Description 删除纪要分类检测接口
  175. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  176. // @Success 200 Ret=200 检测成功
  177. // @router /summary/classify/delete/check [post]
  178. func (this *AiController) DeleteSandboxClassifyCheck() {
  179. br := new(models.BaseResponse).Init()
  180. defer func() {
  181. this.Data["json"] = br
  182. this.ServeJSON()
  183. }()
  184. var req ai_summary.AiSummaryClassifyDeleteCheckReq
  185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  186. if err != nil {
  187. br.Msg = "参数解析异常!"
  188. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  189. return
  190. }
  191. if req.AiSummaryClassifyId < 0 {
  192. br.Msg = "参数错误"
  193. br.IsSendEmail = false
  194. return
  195. }
  196. var deleteStatus int
  197. var tipsMsg string
  198. //删除分类
  199. if req.AiSummaryClassifyId > 0 {
  200. //判断分类下,是否含有纪要
  201. count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  202. if err != nil {
  203. br.Msg = "删除失败"
  204. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  205. return
  206. }
  207. if count > 0 {
  208. deleteStatus = 1
  209. tipsMsg = "该分类下关联沙盘不可删除"
  210. }
  211. }
  212. if deleteStatus != 1 {
  213. classifyCount, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  214. if err != nil && err.Error() != utils.ErrNoRow() {
  215. br.Msg = "删除失败"
  216. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  217. return
  218. }
  219. if classifyCount > 0 {
  220. deleteStatus = 2
  221. tipsMsg = "确认删除当前目录及包含的子目录吗"
  222. }
  223. }
  224. if deleteStatus == 0 {
  225. tipsMsg = "可删除,进行删除操作"
  226. }
  227. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  228. resp.DeleteStatus = deleteStatus
  229. resp.TipsMsg = tipsMsg
  230. br.Ret = 200
  231. br.Msg = "检测成功"
  232. br.Success = true
  233. br.Data = resp
  234. }
  235. // @Title 删除纪要分类/纪要
  236. // @Description 删除纪要分类/纪要接口
  237. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  238. // @Success 200 Ret=200 删除成功
  239. // @router /summary/classify/delete [post]
  240. func (this *AiController) DeleteAiSummaryClassify() {
  241. br := new(models.BaseResponse).Init()
  242. defer func() {
  243. this.Data["json"] = br
  244. this.ServeJSON()
  245. }()
  246. sysUser := this.SysUser
  247. if sysUser == nil {
  248. br.Msg = "请登录"
  249. br.ErrMsg = "请登录,SysUser Is Empty"
  250. br.Ret = 408
  251. return
  252. }
  253. var req ai_summary.DeleteAiSummaryClassifyReq
  254. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  255. if err != nil {
  256. br.Msg = "参数解析异常!"
  257. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  258. return
  259. }
  260. if req.AiSummaryClassifyId < 0 && req.AiSummaryId <= 0 {
  261. br.Msg = "参数错误"
  262. br.IsSendEmail = false
  263. return
  264. }
  265. //删除分类
  266. if req.AiSummaryClassifyId > 0 && req.AiSummaryId == 0 {
  267. //判断是否含有纪要
  268. count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  269. if err != nil && err.Error() != utils.ErrNoRow() {
  270. br.Msg = "删除失败"
  271. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  272. return
  273. }
  274. if count > 0 {
  275. br.Msg = "该目录下存在纪要,不可删除"
  276. br.IsSendEmail = false
  277. return
  278. }
  279. err = ai_summary.DeleteAiSummaryClassify(req.AiSummaryClassifyId)
  280. if err != nil {
  281. br.Msg = "删除失败"
  282. br.ErrMsg = "删除失败,Err:" + err.Error()
  283. return
  284. }
  285. }
  286. //删除沙盘
  287. if req.AiSummaryId > 0 {
  288. summaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
  289. if err != nil {
  290. if err.Error() == utils.ErrNoRow() {
  291. br.Msg = "沙盘已删除,请刷新页面"
  292. br.ErrMsg = "指标不存在,Err:" + err.Error()
  293. return
  294. } else {
  295. br.Msg = "删除失败"
  296. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  297. return
  298. }
  299. }
  300. if summaryInfo == nil {
  301. br.Msg = "纪要已删除,请刷新页面"
  302. return
  303. }
  304. err = ai_summary.DelAiSummaryById(req.AiSummaryId)
  305. if err != nil {
  306. br.Msg = err.Error()
  307. return
  308. }
  309. }
  310. br.Ret = 200
  311. br.Msg = "删除成功"
  312. br.Success = true
  313. br.IsAddLog = true
  314. }
  315. // AiSummaryClassifyMove
  316. // @Title 纪要分类移动接口
  317. // @Description 纪要分类移动接口
  318. // @Success 200 {object} data_manage.MoveChartClassifyReq
  319. // @router /summary/classify/move [post]
  320. func (this *AiController) AiSummaryClassifyMove() {
  321. br := new(models.BaseResponse).Init()
  322. defer func() {
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. sysUser := this.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. br.Ret = 408
  331. return
  332. }
  333. var req ai_summary.MoveAiSummaryClassifyReq
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. if req.AiSummaryClassifyId <= 0 {
  341. br.Msg = "参数错误"
  342. br.ErrMsg = "分类id小于等于0"
  343. return
  344. }
  345. //判断分类是否存在
  346. aiSummaryClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.AiSummaryClassifyId)
  347. if err != nil {
  348. br.Msg = "移动失败"
  349. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  350. return
  351. }
  352. updateCol := make([]string, 0)
  353. // 判断移动的是分类还是沙盘
  354. if req.AiSummaryId > 0 {
  355. //判断分类是否存在
  356. count, _ := ai_summary.GetAiSummaryClassifyCountById(req.AiSummaryClassifyId)
  357. if count <= 0 {
  358. br.Msg = "分类已被删除,不可移动,请刷新页面"
  359. return
  360. }
  361. aiSummaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
  362. if err != nil {
  363. br.Msg = "移动失败"
  364. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  365. return
  366. }
  367. //如果改变了分类,那么移动该图表数据
  368. // 11/22 ETA逻辑优化去除名称重复限制
  369. if aiSummaryInfo.ClassifyId != req.ParentClassifyId {
  370. ////查询需要修改的分类下是否存在同一个图表名称
  371. //tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.ParentClassifyId, aiSummaryInfo.Name)
  372. //if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  373. // br.Msg = "移动失败"
  374. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  375. // return
  376. //}
  377. //if tmpSandboxInfo != nil {
  378. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  379. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  380. // return
  381. //}
  382. err = ai_summary.MoveAiSummary(req.AiSummaryId, req.ParentClassifyId)
  383. if err != nil {
  384. br.Msg = "移动失败"
  385. br.ErrMsg = "移动失败,Err:" + err.Error()
  386. return
  387. }
  388. }
  389. //移动排序
  390. updateCol := make([]string, 0)
  391. //如果有传入 上一个兄弟节点分类id
  392. if req.PrevId > 0 {
  393. if req.PrevType == 1 {
  394. //上一个兄弟节点
  395. prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
  396. if err != nil {
  397. br.Msg = "移动失败"
  398. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  399. return
  400. }
  401. //如果是移动在两个兄弟节点之间
  402. if req.NextId > 0 {
  403. if req.NextType == 1 {
  404. //上一个节点是分类 下一个节点是分类的情况
  405. //下一个兄弟节点
  406. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  407. if err != nil {
  408. br.Msg = "移动失败"
  409. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  410. return
  411. }
  412. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  413. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  414. //变更兄弟节点的排序
  415. updateSortStr := `sort + 2`
  416. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  417. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  418. } else {
  419. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  420. if nextClassify.Sort-prevClassify.Sort == 1 {
  421. //变更兄弟节点的排序
  422. updateSortStr := `sort + 1`
  423. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  424. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  425. }
  426. }
  427. } else {
  428. //上一个节点是分类 下一个节点是沙盘的情况
  429. //下一个兄弟节点
  430. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  431. if err != nil {
  432. br.Msg = "移动失败"
  433. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  434. return
  435. }
  436. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  437. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryInfo.Sort {
  438. //变更兄弟节点的排序
  439. updateSortStr := `sort + 2`
  440. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  441. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  442. } else {
  443. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  444. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  445. //变更兄弟节点的排序
  446. updateSortStr := `sort + 1`
  447. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
  448. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  449. }
  450. }
  451. }
  452. }
  453. aiSummaryInfo.Sort = prevClassify.Sort + 1
  454. aiSummaryInfo.ModifyTime = time.Now()
  455. updateCol = append(updateCol, "Sort", "ModifyTime")
  456. } else {
  457. prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
  458. if err != nil {
  459. br.Msg = "移动失败"
  460. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  461. return
  462. }
  463. //如果是移动在两个兄弟节点之间
  464. if req.NextId > 0 {
  465. if req.NextType == 1 {
  466. //上一个节点是沙盘 下一个节点是分类的情况
  467. //下一个兄弟节点
  468. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  469. if err != nil {
  470. br.Msg = "移动失败"
  471. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  472. return
  473. }
  474. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  475. if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  476. //变更兄弟节点的排序
  477. updateSortStr := `sort + 2`
  478. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  479. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  480. } else {
  481. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  482. if nextClassify.Sort-prevAiSumary.Sort == 1 {
  483. //变更兄弟节点的排序
  484. updateSortStr := `sort + 1`
  485. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  486. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  487. }
  488. }
  489. } else {
  490. //上一个节点是沙盘 下一个节点是沙盘的情况
  491. //下一个兄弟节点
  492. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  493. if err != nil {
  494. br.Msg = "移动失败"
  495. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  496. return
  497. }
  498. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  499. if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryInfo.Sort {
  500. //变更兄弟节点的排序
  501. updateSortStr := `sort + 2`
  502. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  503. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  504. } else {
  505. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  506. if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
  507. //变更兄弟节点的排序
  508. updateSortStr := `sort + 1`
  509. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  510. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  511. }
  512. }
  513. }
  514. }
  515. aiSummaryInfo.Sort = prevAiSumary.Sort + 1
  516. aiSummaryInfo.ModifyTime = time.Now()
  517. updateCol = append(updateCol, "Sort", "ModifyTime")
  518. }
  519. } else {
  520. // prevId为0,也就是沙盘移到最前端
  521. firstClassify, err := ai_summary.GetFirstAiSummaryByClassifyId(req.AiSummaryClassifyId)
  522. if err != nil && err.Error() != utils.ErrNoRow() {
  523. br.Msg = "移动失败"
  524. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  525. return
  526. }
  527. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  528. if firstClassify != nil && firstClassify.Sort == 0 {
  529. updateSortStr := ` sort + 1 `
  530. _ = ai_summary.UpdateAiSummarySortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.AiSummaryId-1, updateSortStr)
  531. }
  532. aiSummaryInfo.Sort = 0 //那就是排在第一位
  533. aiSummaryInfo.ModifyTime = time.Now()
  534. updateCol = append(updateCol, "Sort", "ModifyTime")
  535. }
  536. //更新
  537. if len(updateCol) > 0 {
  538. err = aiSummaryInfo.Update(updateCol)
  539. if err != nil {
  540. br.Msg = "移动失败"
  541. br.ErrMsg = "修改失败,Err:" + err.Error()
  542. return
  543. }
  544. }
  545. } else {
  546. //移动的是分类
  547. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  548. if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  549. parentChartClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.ParentClassifyId)
  550. if err != nil {
  551. br.Msg = "移动失败"
  552. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  553. return
  554. }
  555. aiSummaryClassifyInfo.ParentId = parentChartClassifyInfo.AiSummaryClassifyId
  556. aiSummaryClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  557. aiSummaryClassifyInfo.ModifyTime = time.Now()
  558. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  559. } else if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  560. //改为一级分类
  561. aiSummaryClassifyInfo.ParentId = req.ParentClassifyId
  562. aiSummaryClassifyInfo.Level = 1
  563. aiSummaryClassifyInfo.ModifyTime = time.Now()
  564. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  565. }
  566. //如果有传入 上一个兄弟节点分类id
  567. if req.PrevId > 0 {
  568. if req.PrevType == 1 {
  569. //上一个节点是分类
  570. //上一个兄弟节点
  571. prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
  572. if err != nil {
  573. br.Msg = "移动失败"
  574. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  575. return
  576. }
  577. //如果是移动在两个兄弟节点之间
  578. if req.NextId > 0 {
  579. if req.NextType == 1 {
  580. //上一个节点是分类 下一个节点是分类的情况
  581. //下一个兄弟节点
  582. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  583. if err != nil {
  584. br.Msg = "移动失败"
  585. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  586. return
  587. }
  588. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  589. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  590. //变更兄弟节点的排序
  591. updateSortStr := `sort + 2`
  592. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  593. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  594. } else {
  595. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  596. if nextClassify.Sort-prevClassify.Sort == 1 {
  597. //变更兄弟节点的排序
  598. updateSortStr := `sort + 1`
  599. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  600. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  601. }
  602. }
  603. } else {
  604. //上一个节点是分类 下一个节点是沙盘的情况
  605. //下一个兄弟节点
  606. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  607. if err != nil {
  608. br.Msg = "移动失败"
  609. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  610. return
  611. }
  612. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  613. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  614. //变更兄弟节点的排序
  615. updateSortStr := `sort + 2`
  616. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  617. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  618. } else {
  619. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  620. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  621. //变更兄弟节点的排序
  622. updateSortStr := `sort + 1`
  623. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
  624. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  625. }
  626. }
  627. }
  628. }
  629. aiSummaryClassifyInfo.Sort = prevClassify.Sort + 1
  630. aiSummaryClassifyInfo.ModifyTime = time.Now()
  631. updateCol = append(updateCol, "Sort", "ModifyTime")
  632. } else {
  633. //上一个节点是沙盘
  634. prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
  635. if err != nil {
  636. br.Msg = "移动失败"
  637. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  638. return
  639. }
  640. //如果是移动在两个兄弟节点之间
  641. if req.NextId > 0 {
  642. if req.NextType == 1 {
  643. //上一个节点是沙盘 下一个节点是分类的情况
  644. //下一个兄弟节点
  645. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  646. if err != nil {
  647. br.Msg = "移动失败"
  648. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  649. return
  650. }
  651. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  652. if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  653. //变更兄弟节点的排序
  654. updateSortStr := `sort + 2`
  655. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  656. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  657. } else {
  658. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  659. if nextClassify.Sort-prevAiSumary.Sort == 1 {
  660. //变更兄弟节点的排序
  661. updateSortStr := `sort + 1`
  662. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  663. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  664. }
  665. }
  666. } else {
  667. //上一个节点是沙盘 下一个节点是沙盘的情况
  668. //下一个兄弟节点
  669. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  670. if err != nil {
  671. br.Msg = "移动失败"
  672. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  673. return
  674. }
  675. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  676. if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  677. //变更兄弟节点的排序
  678. updateSortStr := `sort + 2`
  679. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  680. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  681. } else {
  682. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  683. if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
  684. //变更兄弟节点的排序
  685. updateSortStr := `sort + 1`
  686. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  687. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  688. }
  689. }
  690. }
  691. }
  692. aiSummaryClassifyInfo.Sort = prevAiSumary.Sort + 1
  693. aiSummaryClassifyInfo.ModifyTime = time.Now()
  694. updateCol = append(updateCol, "Sort", "ModifyTime")
  695. }
  696. } else {
  697. firstClassify, err := ai_summary.GetFirstAiSummaryClassifyByParentId(aiSummaryClassifyInfo.ParentId)
  698. if err != nil && err.Error() != utils.ErrNoRow() {
  699. br.Msg = "移动失败"
  700. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  701. return
  702. }
  703. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  704. if firstClassify != nil && firstClassify.Sort == 0 {
  705. updateSortStr := ` sort + 1 `
  706. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(firstClassify.ParentId, firstClassify.AiSummaryClassifyId-1, 0, updateSortStr)
  707. }
  708. aiSummaryClassifyInfo.Sort = 0 //那就是排在第一位
  709. aiSummaryClassifyInfo.ModifyTime = time.Now()
  710. updateCol = append(updateCol, "Sort", "ModifyTime")
  711. }
  712. //更新
  713. if len(updateCol) > 0 {
  714. err = aiSummaryClassifyInfo.Update(updateCol)
  715. if err != nil {
  716. br.Msg = "移动失败"
  717. br.ErrMsg = "修改失败,Err:" + err.Error()
  718. return
  719. }
  720. }
  721. }
  722. br.Ret = 200
  723. br.Success = true
  724. br.Msg = "移动成功"
  725. }
  726. // @Title Ai纪要列表接口
  727. // @Description Ai纪要列表接口
  728. // @Param PageSize query int true "每页数据条数"
  729. // @Param CurrentIndex query int true "当前页页码,从1开始"
  730. // @Param AiSummaryClassifyId query int true "分类id"
  731. // @Param KeyWord query string true "搜索关键词"
  732. // @Param IsShowMe query bool true "是否只看我的,true、false"
  733. // @Success 200 {object} data_manage.ChartListResp
  734. // @router /summary/list [get]
  735. func (this *AiController) AiSummaryList() {
  736. br := new(models.BaseResponse).Init()
  737. defer func() {
  738. this.Data["json"] = br
  739. this.ServeJSON()
  740. }()
  741. sysUser := this.SysUser
  742. if sysUser == nil {
  743. br.Msg = "请登录"
  744. br.ErrMsg = "请登录,SysUser Is Empty"
  745. br.Ret = 408
  746. return
  747. }
  748. aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
  749. pageSize, _ := this.GetInt("PageSize")
  750. currentIndex, _ := this.GetInt("CurrentIndex")
  751. keyWord := this.GetString("KeyWord")
  752. var total int
  753. page := paging.GetPaging(currentIndex, pageSize, total)
  754. var startSize int
  755. if pageSize <= 0 {
  756. pageSize = utils.PageSize20
  757. }
  758. if currentIndex <= 0 {
  759. currentIndex = 1
  760. }
  761. startSize = paging.StartIndex(currentIndex, pageSize)
  762. var condition string
  763. var pars []interface{}
  764. if aiSummaryClassifyId > 0 {
  765. sandboxClassifyIds, err := ai_summary.GetAiSummaryClassify(aiSummaryClassifyId)
  766. if err != nil && err.Error() != utils.ErrNoRow() {
  767. br.Msg = "获取图表信息失败"
  768. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  769. return
  770. }
  771. condition += " AND ai_summary_classify_id IN(" + sandboxClassifyIds + ") "
  772. //pars = append(pars, chartClassifyId)
  773. }
  774. if keyWord != "" {
  775. condition += ` AND ( classify_name LIKE '%` + keyWord + `%' )`
  776. }
  777. //只看我的
  778. isShowMe, _ := this.GetBool("IsShowMe")
  779. if isShowMe {
  780. condition += ` AND sys_user_id = ? `
  781. pars = append(pars, sysUser.AdminId)
  782. }
  783. //获取图表信息
  784. list, err := ai_summary.GetAiSummaryListByCondition(condition, pars, startSize, pageSize)
  785. if err != nil && err.Error() != utils.ErrNoRow() {
  786. br.Success = true
  787. br.Msg = "获取沙盘信息失败"
  788. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  789. return
  790. }
  791. for i, v := range list {
  792. ids, err := ai_summary.GetAiSummaryAllParentByClassifyId(v.ClassifyId)
  793. if err != nil {
  794. br.Msg = "获取父级信息错误!"
  795. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  796. return
  797. }
  798. list[i].ParentIds = ids
  799. }
  800. resp := new(ai_summary.AiSummaryListResp)
  801. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  802. items := make([]*ai_summary.AiSummaryItems, 0)
  803. resp.Paging = page
  804. resp.List = items
  805. br.Ret = 200
  806. br.Success = true
  807. br.Msg = "获取成功"
  808. return
  809. }
  810. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  811. if err != nil && err.Error() != utils.ErrNoRow() {
  812. br.Msg = "获取指标信息失败"
  813. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  814. return
  815. }
  816. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  817. resp.Paging = page
  818. resp.List = list
  819. br.Ret = 200
  820. br.Success = true
  821. br.Msg = "获取成功"
  822. br.Data = resp
  823. }