ai_summary.go 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. package ai
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/ai_summary"
  6. "eta_gn/eta_api/models/aimod"
  7. "eta_gn/eta_api/models/sandbox"
  8. saModel "eta_gn/eta_api/models/semantic_analysis"
  9. aiSummaryService "eta_gn/eta_api/services/ai_summary"
  10. "eta_gn/eta_api/services/aiser"
  11. "eta_gn/eta_api/utils"
  12. "fmt"
  13. "strconv"
  14. "time"
  15. "github.com/rdlucklib/rdluck_tools/paging"
  16. )
  17. // AiSummaryClassifyItems
  18. // @Title 获取所有ai纪要分类接口
  19. // @Description 获取所有ai纪要分类接口
  20. // @Param IsShowMe query bool true "是否只看我的,true、false"
  21. // @Success 200 {object} data_manage.ChartClassifyListResp
  22. // @router /summary/classify/list [get]
  23. func (this *AiController) AiSummaryClassifyItems() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. resp := new(ai_summary.AiSummaryClassifyListResp)
  30. aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
  31. isShowMe, _ := this.GetBool("IsShowMe")
  32. if isShowMe {
  33. errMsg, err := aiSummaryService.GetAiSummaryClassifyListForMe(*this.SysUser, resp, aiSummaryClassifyId)
  34. if err != nil {
  35. br.Msg = errMsg
  36. br.ErrMsg = err.Error()
  37. return
  38. }
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. fmt.Println("source my classify")
  44. return
  45. }
  46. rootList, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
  47. if err != nil && !utils.IsErrNoRow(err) {
  48. br.Msg = "获取失败"
  49. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  50. return
  51. }
  52. for k := range rootList {
  53. rootList[k].UniqueCode = strconv.Itoa(rootList[k].AiSummaryClassifyId) + "_" + strconv.Itoa(rootList[k].AiSummaryId)
  54. }
  55. classifyAll, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
  56. if err != nil && !utils.IsErrNoRow(err) {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  59. return
  60. }
  61. for k := range classifyAll {
  62. classifyAll[k].UniqueCode = strconv.Itoa(classifyAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(classifyAll[k].AiSummaryId)
  63. }
  64. nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
  65. for k := range rootList {
  66. rootNode := rootList[k]
  67. aiSummaryService.AiSummaryClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
  68. nodeAll = append(nodeAll, rootNode)
  69. }
  70. resp.AllNodes = nodeAll
  71. br.Ret = 200
  72. br.Success = true
  73. br.Msg = "获取成功"
  74. br.Data = resp
  75. }
  76. // @Title 新增ai纪要分类
  77. // @Description 新增ai纪要分类接口
  78. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  79. // @Success 200 Ret=200 保存成功
  80. // @router /summary/classify/add [post]
  81. func (this *AiController) AddAiSummaryClassify() {
  82. br := new(models.BaseResponse).Init()
  83. defer func() {
  84. this.Data["json"] = br
  85. this.ServeJSON()
  86. }()
  87. var req ai_summary.AddAiSummaryClassifyReq
  88. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  89. if err != nil {
  90. br.Msg = "参数解析异常!"
  91. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  92. return
  93. }
  94. if req.ClassifyName == "" {
  95. br.Msg = "请输入分类名称"
  96. br.IsSendEmail = false
  97. return
  98. }
  99. if req.ParentId < 0 {
  100. br.Msg = "参数错误"
  101. br.IsSendEmail = false
  102. return
  103. }
  104. count, err := ai_summary.GetAiSummaryClassifyCount(req.ClassifyName, req.ParentId)
  105. if err != nil {
  106. br.Msg = "判断名称是否已存在失败"
  107. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  108. return
  109. }
  110. if count > 0 {
  111. br.Msg = "分类名称已存在,请重新输入"
  112. br.IsSendEmail = false
  113. return
  114. }
  115. //获取该层级下最大的排序数
  116. maxSort, err := ai_summary.GetAiSummaryClassifyMaxSort(req.ParentId)
  117. classify := new(ai_summary.AiSummaryClassify)
  118. classify.ParentId = req.ParentId
  119. classify.ClassifyName = req.ClassifyName
  120. classify.HasData = 0
  121. classify.CreateTime = time.Now()
  122. classify.ModifyTime = time.Now()
  123. classify.SysUserId = this.SysUser.AdminId
  124. classify.SysUserRealName = this.SysUser.RealName
  125. classify.Level = req.Level + 1
  126. classify.Sort = maxSort + 1
  127. _, err = ai_summary.AddAiSummaryClassify(classify)
  128. if err != nil {
  129. br.Msg = "保存分类失败"
  130. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Msg = "保存成功"
  135. br.Success = true
  136. }
  137. // @Title 修改ai纪要分类
  138. // @Description 修改ai纪要分类接口
  139. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  140. // @Success 200 Ret=200 修改成功
  141. // @router /summary/classify/edit [post]
  142. func (this *AiController) EditAiSummaryClassify() {
  143. br := new(models.BaseResponse).Init()
  144. defer func() {
  145. this.Data["json"] = br
  146. this.ServeJSON()
  147. }()
  148. var req ai_summary.EditAiSummaryClassifyReq
  149. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  150. if err != nil {
  151. br.Msg = "参数解析异常!"
  152. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  153. return
  154. }
  155. if req.ClassifyName == "" {
  156. br.Msg = "请输入分类名称"
  157. br.IsSendEmail = false
  158. return
  159. }
  160. if req.AiSummaryClassifyId <= 0 {
  161. br.Msg = "参数错误"
  162. br.IsSendEmail = false
  163. return
  164. }
  165. err = ai_summary.EditSandboxClassify(req.AiSummaryClassifyId, req.ClassifyName)
  166. if err != nil {
  167. br.Msg = "保存失败"
  168. br.ErrMsg = "保存失败,Err:" + err.Error()
  169. return
  170. }
  171. br.Ret = 200
  172. br.Msg = "保存成功"
  173. br.Success = true
  174. br.IsAddLog = true
  175. }
  176. // @Title 删除纪要分类检测接口
  177. // @Description 删除纪要分类检测接口
  178. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  179. // @Success 200 Ret=200 检测成功
  180. // @router /summary/classify/delete/check [post]
  181. func (this *AiController) DeleteSandboxClassifyCheck() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. var req ai_summary.AiSummaryClassifyDeleteCheckReq
  188. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  189. if err != nil {
  190. br.Msg = "参数解析异常!"
  191. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  192. return
  193. }
  194. if req.AiSummaryClassifyId < 0 {
  195. br.Msg = "参数错误"
  196. br.IsSendEmail = false
  197. return
  198. }
  199. var deleteStatus int
  200. var tipsMsg string
  201. //删除分类
  202. if req.AiSummaryClassifyId > 0 {
  203. //判断分类下,是否含有纪要
  204. count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  205. if err != nil {
  206. br.Msg = "删除失败"
  207. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  208. return
  209. }
  210. if count > 0 {
  211. deleteStatus = 1
  212. tipsMsg = "该分类下关联沙盘不可删除"
  213. }
  214. }
  215. if deleteStatus != 1 {
  216. classifyCount, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  217. if err != nil && !utils.IsErrNoRow(err) {
  218. br.Msg = "删除失败"
  219. br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
  220. return
  221. }
  222. if classifyCount > 0 {
  223. deleteStatus = 2
  224. tipsMsg = "确认删除当前目录及包含的子目录吗"
  225. }
  226. }
  227. if deleteStatus == 0 {
  228. tipsMsg = "可删除,进行删除操作"
  229. }
  230. resp := new(sandbox.SandboxClassifyDeleteCheckResp)
  231. resp.DeleteStatus = deleteStatus
  232. resp.TipsMsg = tipsMsg
  233. br.Ret = 200
  234. br.Msg = "检测成功"
  235. br.Success = true
  236. br.Data = resp
  237. }
  238. // @Title 删除纪要分类/纪要
  239. // @Description 删除纪要分类/纪要接口
  240. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  241. // @Success 200 Ret=200 删除成功
  242. // @router /summary/classify/delete [post]
  243. func (this *AiController) DeleteAiSummaryClassify() {
  244. br := new(models.BaseResponse).Init()
  245. defer func() {
  246. this.Data["json"] = br
  247. this.ServeJSON()
  248. }()
  249. sysUser := this.SysUser
  250. if sysUser == nil {
  251. br.Msg = "请登录"
  252. br.ErrMsg = "请登录,SysUser Is Empty"
  253. br.Ret = 408
  254. return
  255. }
  256. var req ai_summary.DeleteAiSummaryClassifyReq
  257. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  258. if err != nil {
  259. br.Msg = "参数解析异常!"
  260. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  261. return
  262. }
  263. if req.AiSummaryClassifyId < 0 && req.AiSummaryId <= 0 {
  264. br.Msg = "参数错误"
  265. br.IsSendEmail = false
  266. return
  267. }
  268. //删除分类
  269. if req.AiSummaryClassifyId > 0 && req.AiSummaryId == 0 {
  270. //判断是否含有纪要
  271. childIds := make([]int, 0)
  272. classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
  273. if err != nil && !utils.IsErrNoRow(err) {
  274. br.Msg = "获取失败"
  275. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  276. return
  277. }
  278. classifyAllMap := make(map[int]*ai_summary.AiSummaryClassifyItems)
  279. for _, v := range classifyAll {
  280. classifyAllMap[v.AiSummaryClassifyId] = v
  281. }
  282. aiSummaryService.GetSummaryClassifyChildIds(req.AiSummaryClassifyId, classifyAllMap, &childIds)
  283. condition := ``
  284. pars := make([]interface{}, 0)
  285. if len(childIds) > 0 {
  286. ids := utils.IntArr2joinString(childIds, ",")
  287. condition = ` AND classify_id IN (` + ids + `) `
  288. } else {
  289. condition = ` AND classify_id = ? `
  290. pars = append(pars, req.AiSummaryClassifyId)
  291. }
  292. count, err := ai_summary.GetSummaryCountByCondition(condition, pars)
  293. if err != nil {
  294. br.Msg = "查询失败"
  295. br.ErrMsg = "判断分类下是否有纪要失败,Err:" + err.Error()
  296. return
  297. }
  298. //count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
  299. //if err != nil && !utils.IsErrNoRow(err) {
  300. // br.Msg = "删除失败"
  301. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  302. // return
  303. //}
  304. if count > 0 {
  305. br.Msg = "该目录下存在纪要,不可删除"
  306. br.IsSendEmail = false
  307. return
  308. }
  309. childIds = append(childIds, req.AiSummaryClassifyId)
  310. err = ai_summary.DeleteAiSummaryClassifyByIds(childIds)
  311. if err != nil {
  312. br.Msg = "删除失败"
  313. br.ErrMsg = "删除失败,Err:" + err.Error()
  314. return
  315. }
  316. }
  317. //删除纪要
  318. if req.AiSummaryId > 0 {
  319. summaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
  320. if err != nil {
  321. if utils.IsErrNoRow(err) {
  322. br.Msg = "纪要已删除,请刷新页面"
  323. br.ErrMsg = "指标不存在,Err:" + err.Error()
  324. return
  325. } else {
  326. br.Msg = "删除失败"
  327. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  328. return
  329. }
  330. }
  331. if summaryInfo == nil {
  332. br.Msg = "纪要已删除,请刷新页面"
  333. return
  334. }
  335. if summaryInfo.SysUserId != sysUser.AdminId {
  336. br.Msg = "仅纪要创建人可以删除"
  337. return
  338. }
  339. err = ai_summary.DelAiSummaryById(req.AiSummaryId)
  340. if err != nil {
  341. br.Msg = err.Error()
  342. return
  343. }
  344. }
  345. br.Ret = 200
  346. br.Msg = "删除成功"
  347. br.Success = true
  348. br.IsAddLog = true
  349. }
  350. // AiSummaryClassifyMove
  351. // @Title 纪要分类移动接口
  352. // @Description 纪要分类移动接口
  353. // @Success 200 {object} data_manage.MoveChartClassifyReq
  354. // @router /summary/classify/move [post]
  355. func (this *AiController) AiSummaryClassifyMove() {
  356. br := new(models.BaseResponse).Init()
  357. defer func() {
  358. this.Data["json"] = br
  359. this.ServeJSON()
  360. }()
  361. sysUser := this.SysUser
  362. if sysUser == nil {
  363. br.Msg = "请登录"
  364. br.ErrMsg = "请登录,SysUser Is Empty"
  365. br.Ret = 408
  366. return
  367. }
  368. var req ai_summary.MoveAiSummaryClassifyReq
  369. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  370. if err != nil {
  371. br.Msg = "参数解析异常!"
  372. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  373. return
  374. }
  375. if req.AiSummaryClassifyId <= 0 {
  376. br.Msg = "参数错误"
  377. br.ErrMsg = "分类id小于等于0"
  378. return
  379. }
  380. //判断分类是否存在
  381. aiSummaryClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.AiSummaryClassifyId)
  382. if err != nil {
  383. br.Msg = "移动失败"
  384. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  385. return
  386. }
  387. updateCol := make([]string, 0)
  388. // 判断移动的是分类还是沙盘
  389. if req.AiSummaryId > 0 {
  390. //判断分类是否存在
  391. count, _ := ai_summary.GetAiSummaryClassifyCountById(req.AiSummaryClassifyId)
  392. if count <= 0 {
  393. br.Msg = "分类已被删除,不可移动,请刷新页面"
  394. return
  395. }
  396. aiSummaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
  397. if err != nil {
  398. br.Msg = "移动失败"
  399. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  400. return
  401. }
  402. //如果改变了分类,那么移动该图表数据
  403. // 11/22 ETA逻辑优化去除名称重复限制
  404. if aiSummaryInfo.ClassifyId != req.ParentClassifyId {
  405. ////查询需要修改的分类下是否存在同一个图表名称
  406. //tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.ParentClassifyId, aiSummaryInfo.Name)
  407. //if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
  408. // br.Msg = "移动失败"
  409. // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  410. // return
  411. //}
  412. //if tmpSandboxInfo != nil {
  413. // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
  414. // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
  415. // return
  416. //}
  417. err = ai_summary.MoveAiSummary(req.AiSummaryId, req.ParentClassifyId)
  418. if err != nil {
  419. br.Msg = "移动失败"
  420. br.ErrMsg = "移动失败,Err:" + err.Error()
  421. return
  422. }
  423. }
  424. //移动排序
  425. updateCol := make([]string, 0)
  426. //如果有传入 上一个兄弟节点分类id
  427. if req.PrevId > 0 {
  428. if req.PrevType == 1 {
  429. //上一个兄弟节点
  430. prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
  431. if err != nil {
  432. br.Msg = "移动失败"
  433. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  434. return
  435. }
  436. //如果是移动在两个兄弟节点之间
  437. if req.NextId > 0 {
  438. if req.NextType == 1 {
  439. //上一个节点是分类 下一个节点是分类的情况
  440. //下一个兄弟节点
  441. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  442. if err != nil {
  443. br.Msg = "移动失败"
  444. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  445. return
  446. }
  447. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  448. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  449. //变更兄弟节点的排序
  450. updateSortStr := `sort + 2`
  451. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  452. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  453. } else {
  454. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  455. if nextClassify.Sort-prevClassify.Sort == 1 {
  456. //变更兄弟节点的排序
  457. updateSortStr := `sort + 1`
  458. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  459. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  460. }
  461. }
  462. } else {
  463. //上一个节点是分类 下一个节点是沙盘的情况
  464. //下一个兄弟节点
  465. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  466. if err != nil {
  467. br.Msg = "移动失败"
  468. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  469. return
  470. }
  471. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  472. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryInfo.Sort {
  473. //变更兄弟节点的排序
  474. updateSortStr := `sort + 2`
  475. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  476. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  477. } else {
  478. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  479. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  480. //变更兄弟节点的排序
  481. updateSortStr := `sort + 1`
  482. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
  483. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  484. }
  485. }
  486. }
  487. }
  488. aiSummaryInfo.Sort = prevClassify.Sort + 1
  489. aiSummaryInfo.ModifyTime = time.Now()
  490. updateCol = append(updateCol, "Sort", "ModifyTime")
  491. } else {
  492. prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
  493. if err != nil {
  494. br.Msg = "移动失败"
  495. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  496. return
  497. }
  498. //如果是移动在两个兄弟节点之间
  499. if req.NextId > 0 {
  500. if req.NextType == 1 {
  501. //上一个节点是沙盘 下一个节点是分类的情况
  502. //下一个兄弟节点
  503. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  504. if err != nil {
  505. br.Msg = "移动失败"
  506. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  507. return
  508. }
  509. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  510. if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  511. //变更兄弟节点的排序
  512. updateSortStr := `sort + 2`
  513. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  514. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  515. } else {
  516. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  517. if nextClassify.Sort-prevAiSumary.Sort == 1 {
  518. //变更兄弟节点的排序
  519. updateSortStr := `sort + 1`
  520. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  521. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  522. }
  523. }
  524. } else {
  525. //上一个节点是沙盘 下一个节点是沙盘的情况
  526. //下一个兄弟节点
  527. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  528. if err != nil {
  529. br.Msg = "移动失败"
  530. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  531. return
  532. }
  533. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  534. if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryInfo.Sort {
  535. //变更兄弟节点的排序
  536. updateSortStr := `sort + 2`
  537. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  538. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  539. } else {
  540. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  541. if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
  542. //变更兄弟节点的排序
  543. updateSortStr := `sort + 1`
  544. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  545. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  546. }
  547. }
  548. }
  549. }
  550. aiSummaryInfo.Sort = prevAiSumary.Sort + 1
  551. aiSummaryInfo.ModifyTime = time.Now()
  552. updateCol = append(updateCol, "Sort", "ModifyTime")
  553. }
  554. } else {
  555. // prevId为0,也就是沙盘移到最前端
  556. firstClassify, err := ai_summary.GetFirstAiSummaryByClassifyId(req.AiSummaryClassifyId)
  557. if err != nil && !utils.IsErrNoRow(err) {
  558. br.Msg = "移动失败"
  559. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  560. return
  561. }
  562. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  563. if firstClassify != nil && firstClassify.ClassifyId > 0 && firstClassify.Sort == 0 {
  564. updateSortStr := ` sort + 1 `
  565. _ = ai_summary.UpdateAiSummarySortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.AiSummaryId-1, updateSortStr)
  566. }
  567. aiSummaryInfo.Sort = 0 //那就是排在第一位
  568. aiSummaryInfo.ModifyTime = time.Now()
  569. updateCol = append(updateCol, "Sort", "ModifyTime")
  570. }
  571. //更新
  572. if len(updateCol) > 0 {
  573. err = aiSummaryInfo.Update(updateCol)
  574. if err != nil {
  575. br.Msg = "移动失败"
  576. br.ErrMsg = "修改失败,Err:" + err.Error()
  577. return
  578. }
  579. }
  580. } else {
  581. //移动的是分类
  582. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  583. if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  584. parentChartClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.ParentClassifyId)
  585. if err != nil {
  586. br.Msg = "移动失败"
  587. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  588. return
  589. }
  590. aiSummaryClassifyInfo.ParentId = parentChartClassifyInfo.AiSummaryClassifyId
  591. aiSummaryClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  592. aiSummaryClassifyInfo.ModifyTime = time.Now()
  593. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  594. } else if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
  595. //改为一级分类
  596. aiSummaryClassifyInfo.ParentId = req.ParentClassifyId
  597. aiSummaryClassifyInfo.Level = 1
  598. aiSummaryClassifyInfo.ModifyTime = time.Now()
  599. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  600. }
  601. //如果有传入 上一个兄弟节点分类id
  602. if req.PrevId > 0 {
  603. if req.PrevType == 1 {
  604. //上一个节点是分类
  605. //上一个兄弟节点
  606. prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
  607. if err != nil {
  608. br.Msg = "移动失败"
  609. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  610. return
  611. }
  612. //如果是移动在两个兄弟节点之间
  613. if req.NextId > 0 {
  614. if req.NextType == 1 {
  615. //上一个节点是分类 下一个节点是分类的情况
  616. //下一个兄弟节点
  617. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  618. if err != nil {
  619. br.Msg = "移动失败"
  620. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  621. return
  622. }
  623. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  624. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  625. //变更兄弟节点的排序
  626. updateSortStr := `sort + 2`
  627. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  628. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  629. } else {
  630. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  631. if nextClassify.Sort-prevClassify.Sort == 1 {
  632. //变更兄弟节点的排序
  633. updateSortStr := `sort + 1`
  634. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  635. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  636. }
  637. }
  638. } else {
  639. //上一个节点是分类 下一个节点是沙盘的情况
  640. //下一个兄弟节点
  641. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  642. if err != nil {
  643. br.Msg = "移动失败"
  644. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  645. return
  646. }
  647. //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
  648. if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
  649. //变更兄弟节点的排序
  650. updateSortStr := `sort + 2`
  651. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
  652. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  653. } else {
  654. //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
  655. if nextChartInfo.Sort-prevClassify.Sort == 1 {
  656. //变更兄弟节点的排序
  657. updateSortStr := `sort + 1`
  658. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
  659. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
  660. }
  661. }
  662. }
  663. }
  664. aiSummaryClassifyInfo.Sort = prevClassify.Sort + 1
  665. aiSummaryClassifyInfo.ModifyTime = time.Now()
  666. updateCol = append(updateCol, "Sort", "ModifyTime")
  667. } else {
  668. //上一个节点是沙盘
  669. prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
  670. if err != nil {
  671. br.Msg = "移动失败"
  672. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  673. return
  674. }
  675. //如果是移动在两个兄弟节点之间
  676. if req.NextId > 0 {
  677. if req.NextType == 1 {
  678. //上一个节点是沙盘 下一个节点是分类的情况
  679. //下一个兄弟节点
  680. nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
  681. if err != nil {
  682. br.Msg = "移动失败"
  683. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  684. return
  685. }
  686. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  687. if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  688. //变更兄弟节点的排序
  689. updateSortStr := `sort + 2`
  690. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  691. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  692. } else {
  693. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  694. if nextClassify.Sort-prevAiSumary.Sort == 1 {
  695. //变更兄弟节点的排序
  696. updateSortStr := `sort + 1`
  697. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  698. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  699. }
  700. }
  701. } else {
  702. //上一个节点是沙盘 下一个节点是沙盘的情况
  703. //下一个兄弟节点
  704. nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
  705. if err != nil {
  706. br.Msg = "移动失败"
  707. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  708. return
  709. }
  710. //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
  711. if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
  712. //变更兄弟节点的排序
  713. updateSortStr := `sort + 2`
  714. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  715. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  716. } else {
  717. //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
  718. if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
  719. //变更兄弟节点的排序
  720. updateSortStr := `sort + 1`
  721. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
  722. _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
  723. }
  724. }
  725. }
  726. }
  727. aiSummaryClassifyInfo.Sort = prevAiSumary.Sort + 1
  728. aiSummaryClassifyInfo.ModifyTime = time.Now()
  729. updateCol = append(updateCol, "Sort", "ModifyTime")
  730. }
  731. } else {
  732. firstClassify, err := ai_summary.GetFirstAiSummaryClassifyByParentId(aiSummaryClassifyInfo.ParentId)
  733. if err != nil && !utils.IsErrNoRow(err) {
  734. br.Msg = "移动失败"
  735. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  736. return
  737. }
  738. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  739. if firstClassify != nil && firstClassify.AiSummaryClassifyId > 0 && firstClassify.Sort == 0 {
  740. updateSortStr := ` sort + 1 `
  741. _ = ai_summary.UpdateAiSummaryClassifySortByParentId(firstClassify.ParentId, firstClassify.AiSummaryClassifyId-1, 0, updateSortStr)
  742. }
  743. aiSummaryClassifyInfo.Sort = 0 //那就是排在第一位
  744. aiSummaryClassifyInfo.ModifyTime = time.Now()
  745. updateCol = append(updateCol, "Sort", "ModifyTime")
  746. }
  747. //更新
  748. if len(updateCol) > 0 {
  749. err = aiSummaryClassifyInfo.Update(updateCol)
  750. if err != nil {
  751. br.Msg = "移动失败"
  752. br.ErrMsg = "修改失败,Err:" + err.Error()
  753. return
  754. }
  755. }
  756. }
  757. br.Ret = 200
  758. br.Success = true
  759. br.Msg = "移动成功"
  760. }
  761. // @Title Ai纪要列表接口
  762. // @Description Ai纪要列表接口
  763. // @Param PageSize query int true "每页数据条数"
  764. // @Param CurrentIndex query int true "当前页页码,从1开始"
  765. // @Param AiSummaryClassifyId query int true "分类id"
  766. // @Param KeyWord query string true "搜索关键词"
  767. // @Param IsShowMe query bool true "是否只看我的,true、false"
  768. // @Success 200 {object} data_manage.ChartListResp
  769. // @router /summary/list [get]
  770. func (this *AiController) AiSummaryList() {
  771. br := new(models.BaseResponse).Init()
  772. defer func() {
  773. this.Data["json"] = br
  774. this.ServeJSON()
  775. }()
  776. sysUser := this.SysUser
  777. if sysUser == nil {
  778. br.Msg = "请登录"
  779. br.ErrMsg = "请登录,SysUser Is Empty"
  780. br.Ret = 408
  781. return
  782. }
  783. aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
  784. pageSize, _ := this.GetInt("PageSize")
  785. currentIndex, _ := this.GetInt("CurrentIndex")
  786. keyWord := this.GetString("KeyWord")
  787. var total int
  788. page := paging.GetPaging(currentIndex, pageSize, total)
  789. var startSize int
  790. if pageSize <= 0 {
  791. pageSize = utils.PageSize20
  792. }
  793. if currentIndex <= 0 {
  794. currentIndex = 1
  795. }
  796. startSize = paging.StartIndex(currentIndex, pageSize)
  797. classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
  798. if err != nil && !utils.IsErrNoRow(err) {
  799. br.Msg = "获取失败"
  800. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  801. return
  802. }
  803. classifyAllMap := make(map[int]*ai_summary.AiSummaryClassifyItems)
  804. for _, v := range classifyAll {
  805. classifyAllMap[v.AiSummaryClassifyId] = v
  806. }
  807. var condition string
  808. var pars []interface{}
  809. if aiSummaryClassifyId > 0 {
  810. sandboxClassifyIds, err := ai_summary.GetAiSummaryClassify(aiSummaryClassifyId)
  811. if err != nil && !utils.IsErrNoRow(err) {
  812. br.Msg = "获取图表信息失败"
  813. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  814. return
  815. }
  816. condition += " AND ai_summary_classify_id IN(" + sandboxClassifyIds + ") "
  817. //pars = append(pars, chartClassifyId)
  818. }
  819. if keyWord != "" {
  820. condition += ` AND ( title LIKE '%` + keyWord + `%' )`
  821. }
  822. //只看我的
  823. isShowMe, _ := this.GetBool("IsShowMe")
  824. if isShowMe {
  825. condition += ` AND sys_user_id = ? `
  826. pars = append(pars, sysUser.AdminId)
  827. }
  828. //获取图表信息
  829. list, err := ai_summary.GetAiSummaryListByCondition(condition, pars, startSize, pageSize)
  830. if err != nil && !utils.IsErrNoRow(err) {
  831. br.Success = true
  832. br.Msg = "获取纪要信息失败"
  833. br.ErrMsg = "获取纪要信息失败,Err:" + err.Error()
  834. return
  835. }
  836. for i, v := range list {
  837. parentIds := make([]int, 0)
  838. aiSummaryService.GetSummaryParentIds(v.ClassifyId, classifyAllMap, &parentIds)
  839. ids := utils.IntArr2joinString(parentIds, ",")
  840. //ids, err := ai_summary.GetAiSummaryAllParentByClassifyId(v.ClassifyId)
  841. //if err != nil {
  842. // br.Msg = "获取父级信息错误!"
  843. // br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  844. // return
  845. //}
  846. list[i].ParentIds = ids
  847. }
  848. resp := new(ai_summary.AiSummaryListResp)
  849. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  850. items := make([]*ai_summary.AiSummaryItems, 0)
  851. resp.Paging = page
  852. resp.List = items
  853. br.Ret = 200
  854. br.Success = true
  855. br.Msg = "获取成功"
  856. return
  857. }
  858. dataCount, err := ai_summary.GetAiSummaryListCountByCondition(condition, pars)
  859. if err != nil && !utils.IsErrNoRow(err) {
  860. br.Msg = "获取指标信息失败"
  861. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  862. return
  863. }
  864. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  865. resp.Paging = page
  866. resp.List = list
  867. br.Ret = 200
  868. br.Success = true
  869. br.Msg = "获取成功"
  870. br.Data = resp
  871. }
  872. // @Title Ai纪要详情接口
  873. // @Description Ai纪要详情接口
  874. // @Param AiSummaryId query int true "详情id"
  875. // @Success 200 {object} data_manage.ChartListResp
  876. // @router /summary/detail [get]
  877. func (this *AiController) AiSummaryDetail() {
  878. br := new(models.BaseResponse).Init()
  879. defer func() {
  880. this.Data["json"] = br
  881. this.ServeJSON()
  882. }()
  883. sysUser := this.SysUser
  884. if sysUser == nil {
  885. br.Msg = "请登录"
  886. br.ErrMsg = "请登录,SysUser Is Empty"
  887. br.Ret = 408
  888. return
  889. }
  890. aiSummaryId, _ := this.GetInt("AiSummaryId")
  891. detail, err := ai_summary.GetAiSummaryItemById(aiSummaryId)
  892. if err != nil && !utils.IsErrNoRow(err) {
  893. br.Success = true
  894. br.Msg = "获取沙盘信息失败"
  895. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  896. return
  897. }
  898. resp := ai_summary.AiSummaryDetailResp{
  899. AiSummaryItems: detail,
  900. }
  901. if detail.SaDocId > 0 {
  902. item := new(saModel.SaDoc)
  903. e := item.GetItemById(detail.SaDocId)
  904. if e != nil {
  905. if utils.IsErrNoRow(e) {
  906. br.Msg = "文档已被删除, 请刷新页面"
  907. return
  908. }
  909. br.Msg = "获取失败"
  910. br.ErrMsg = "获取文档信息失败, Err: " + e.Error()
  911. return
  912. }
  913. resp.SaDocTitle = item.Title
  914. resp.SaDocClassifyId = item.ClassifyId
  915. }
  916. br.Data = resp
  917. br.Ret = 200
  918. br.Success = true
  919. br.Msg = "获取成功"
  920. }
  921. // @Title 新增ai纪要
  922. // @Description 新增ai纪要接口
  923. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  924. // @Success 200 Ret=200 保存成功
  925. // @router /summary/add [post]
  926. func (this *AiController) AddAiSummary() {
  927. br := new(models.BaseResponse).Init()
  928. defer func() {
  929. this.Data["json"] = br
  930. this.ServeJSON()
  931. }()
  932. var req ai_summary.AddAiSummaryReq
  933. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  934. if err != nil {
  935. br.Msg = "参数解析异常!"
  936. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  937. return
  938. }
  939. if req.Title == "" {
  940. br.Msg = "请输入名称"
  941. br.IsSendEmail = false
  942. return
  943. }
  944. if req.SummaryContent == "" {
  945. br.Msg = "纪要内容为空"
  946. br.IsSendEmail = false
  947. return
  948. }
  949. if req.ClassifyId < 0 {
  950. br.Msg = "分类id错误"
  951. br.IsSendEmail = false
  952. return
  953. }
  954. //获取该层级下最大的排序数
  955. maxSort, err := ai_summary.GetAiSummaryMaxSort(req.ClassifyId)
  956. summary := &ai_summary.AiSummary{
  957. SaDocId: req.SaDocId,
  958. OriginContent: req.OriginContent,
  959. SummaryContent: req.SummaryContent,
  960. ClassifyId: req.ClassifyId,
  961. SysUserId: this.SysUser.AdminId,
  962. SysUserRealName: this.SysUser.RealName,
  963. Title: req.Title,
  964. CreateTime: time.Now(),
  965. ModifyTime: time.Now(),
  966. OpenaiFileName: req.OpenaiFileName,
  967. OpenaiFilePath: req.OpenaiFilePath,
  968. OriginTitle: req.OriginTitle,
  969. Sort: maxSort + 1,
  970. }
  971. id, err := ai_summary.AddAiSummary(summary)
  972. if err != nil {
  973. br.Msg = "保存分类失败"
  974. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  975. return
  976. }
  977. classify, err := ai_summary.GetAiSummaryClassifyById(req.ClassifyId)
  978. if err != nil {
  979. br.Msg = "获取分类信息失败"
  980. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  981. return
  982. }
  983. resp := ai_summary.AiSummaryAddResp{
  984. AiSummaryId: int(id),
  985. UniqueCode: strconv.Itoa(req.ClassifyId) + "_" + strconv.Itoa(int(id)),
  986. ParentId: classify.ParentId,
  987. }
  988. br.Ret = 200
  989. br.Msg = "保存成功"
  990. br.Success = true
  991. br.Data = resp
  992. }
  993. // @Title 生成ai纪要
  994. // @Description 生成ai纪要接口
  995. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  996. // @Success 200 Ret=200 保存成功
  997. // @router /summary/generate [post]
  998. func (this *AiController) GenerateAiSummary() {
  999. br := new(models.BaseResponse).Init()
  1000. defer func() {
  1001. this.Data["json"] = br
  1002. this.ServeJSON()
  1003. }()
  1004. var req ai_summary.GenerateAiSummaryReq
  1005. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1006. if err != nil {
  1007. br.Msg = "参数解析异常!"
  1008. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1009. return
  1010. }
  1011. req.Prompt, err = aiser.FormatAskContent(req.Prompt)
  1012. if err != nil {
  1013. br.Msg = "提示词错误"
  1014. br.ErrMsg = "提示词错误,FormatAskContent,Err:" + err.Error()
  1015. return
  1016. }
  1017. if req.Prompt == "" {
  1018. br.Msg = "请输入提示词"
  1019. br.IsSendEmail = false
  1020. return
  1021. }
  1022. req.OriginContent, err = aiser.FormatAskContent(req.OriginContent)
  1023. if err != nil {
  1024. br.Msg = "文档内容错误"
  1025. br.ErrMsg = "文档内容错误,FormatAskContent,Err:" + err.Error()
  1026. return
  1027. }
  1028. if req.OriginContent == "" && len(req.OpenaiFileId) == 0 && req.SaDocId <= 0 {
  1029. br.Msg = "请选择文档或输入内容"
  1030. br.IsSendEmail = false
  1031. return
  1032. }
  1033. if req.SaDocId > 0 {
  1034. // 获取段落
  1035. sectionOB := new(saModel.SaDocSection)
  1036. sectionCond := fmt.Sprintf(` AND %s = ?`, saModel.SaDocSectionColumns.DocId)
  1037. sectionPars := make([]interface{}, 0)
  1038. sectionPars = append(sectionPars, req.SaDocId)
  1039. sectionList, e := sectionOB.GetItemsByCondition(sectionCond, sectionPars, []string{}, "")
  1040. if e != nil {
  1041. br.Msg = "获取失败"
  1042. br.ErrMsg = "获取段落信息失败, Err: " + e.Error()
  1043. return
  1044. }
  1045. secIds := make([]int, 0)
  1046. for _, s := range sectionList {
  1047. secIds = append(secIds, s.SaDocSectionId)
  1048. }
  1049. for _, v := range sectionList {
  1050. req.OriginContent += v.Content + "<br>"
  1051. }
  1052. }
  1053. if utils.Re == nil {
  1054. key := "CACHE_CHAT_" + strconv.Itoa(this.SysUser.AdminId)
  1055. cacheVal, err := utils.Rc.RedisInt(key)
  1056. fmt.Println("RedisString:", cacheVal, "err:", err)
  1057. if err != nil && (err.Error() != "redigo: nil returned" && err.Error() != "redis: nil") {
  1058. br.Msg = "获取数据失败!"
  1059. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1060. return
  1061. }
  1062. putVal := 0
  1063. if cacheVal <= 0 {
  1064. putVal = utils.AiChatLimit
  1065. } else {
  1066. putVal = cacheVal - 1
  1067. }
  1068. if putVal <= 0 {
  1069. br.Msg = "您今日" + strconv.Itoa(utils.AiChatLimit) + "次问答已达上限,请明天再来!"
  1070. br.ErrMsg = "您今日" + strconv.Itoa(utils.AiChatLimit) + "次问答已达上限,请明天再来!"
  1071. return
  1072. }
  1073. lastSecond := utils.GetTodayLastSecond()
  1074. utils.Rc.Put(key, putVal, lastSecond)
  1075. }
  1076. resp := new(aimod.ChatResp)
  1077. if req.OriginContent != "" {
  1078. // 直接提问的方式
  1079. //根据提问,获取信息
  1080. ask := req.Prompt + req.OriginContent
  1081. var answer string
  1082. //answerArr := []string{
  1083. // "周度数据显示,成品油现货市场价格跟随原油下跌,但近期相对抗跌,裂解价差走扩。批零价差方面汽油收窄,柴油走扩",
  1084. // "出口利润在原油下跌海外成品油矛盾更大的情况下汽柴油出口窗口完全关闭",
  1085. // "汽油需求在经历五一假期的一段高峰后将回归平稳,总体没有明显矛盾,后期我们担心更多的还是柴油。"}
  1086. //获取主题下的所有信息
  1087. //AiChatTopicId
  1088. //获取主题下的所有信息
  1089. //AiChatTopicId
  1090. historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
  1091. if err != nil && !utils.IsErrNoRow(err) {
  1092. br.Msg = "获取主题历史数据失败!"
  1093. br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. historyChatList := make([]aimod.HistoryChat, 0)
  1097. for _, v := range historyList {
  1098. historyChat := new(aimod.HistoryChat)
  1099. historyChat.Ask = v.Ask
  1100. historyChat.Answer = v.Answer
  1101. historyChatList = append(historyChatList, *historyChat)
  1102. }
  1103. answer, err = aiser.ChatAutoMsg(ask, historyChatList, req.Model)
  1104. if err != nil {
  1105. br.Msg = "获取数据失败!"
  1106. br.ErrMsg = "获取数据失败,ChatAutoMsg,Err:" + err.Error()
  1107. return
  1108. }
  1109. resp.Ask = ask
  1110. resp.Answer = answer
  1111. resp.Model = req.Model
  1112. if req.AiChatTopicId <= 0 { //新增
  1113. name, err := aiser.QueryAskContent(ask)
  1114. if err != nil {
  1115. br.Msg = "获取数据失败!"
  1116. br.ErrMsg = "获取数据失败,QueryAskContent,Err:" + err.Error()
  1117. return
  1118. }
  1119. topic := new(aimod.AiChatTopic)
  1120. topic.TopicName = name
  1121. topic.SysUserId = this.SysUser.AdminId
  1122. topic.SysUserRealName = this.SysUser.RealName
  1123. topic.CreateTime = time.Now()
  1124. topic.ModifyTime = time.Now()
  1125. topicId, err := aimod.AddAiChatTopic(topic)
  1126. if err != nil {
  1127. br.Msg = "获取数据失败!"
  1128. br.ErrMsg = "生成话题失败,Err:" + err.Error()
  1129. return
  1130. }
  1131. resp.AiChatTopicId = int(topicId)
  1132. chatItem := new(aimod.AiChat)
  1133. chatItem.AiChatTopicId = resp.AiChatTopicId
  1134. chatItem.Ask = ask
  1135. chatItem.AskUuid = utils.MD5(ask)
  1136. chatItem.Answer = answer
  1137. chatItem.Model = EnabledModelsForMap[req.Model]
  1138. chatItem.SysUserId = this.SysUser.AdminId
  1139. chatItem.SysUserRealName = this.SysUser.RealName
  1140. chatItem.CreateTime = time.Now()
  1141. chatItem.ModifyTime = time.Now()
  1142. _, err = aimod.AddAiChat(chatItem)
  1143. if err != nil {
  1144. br.Msg = "获取数据失败!"
  1145. br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1146. return
  1147. }
  1148. } else {
  1149. resp.AiChatTopicId = req.AiChatTopicId
  1150. chatItem := new(aimod.AiChat)
  1151. chatItem.AiChatTopicId = resp.AiChatTopicId
  1152. chatItem.Ask = ask
  1153. chatItem.AskUuid = utils.MD5(ask)
  1154. chatItem.Answer = answer
  1155. chatItem.Model = EnabledModelsForMap[req.Model]
  1156. chatItem.SysUserId = this.SysUser.AdminId
  1157. chatItem.SysUserRealName = this.SysUser.RealName
  1158. chatItem.CreateTime = time.Now()
  1159. chatItem.ModifyTime = time.Now()
  1160. _, err = aimod.AddAiChat(chatItem)
  1161. if err != nil {
  1162. br.Msg = "获取数据失败!"
  1163. br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1164. return
  1165. }
  1166. }
  1167. } else if len(req.OpenaiFileId) > 0 {
  1168. // 走文件上传的方式
  1169. //根据提问,获取信息
  1170. ask := req.Prompt
  1171. askUuid := utils.MD5(ask)
  1172. var assistantId, threadId string
  1173. if req.AiChatTopicId > 0 {
  1174. aiChatTopicObj := new(aimod.AiChatTopic)
  1175. aiChatTopicObj.AiChatTopicId = req.AiChatTopicId
  1176. topic, err := aiChatTopicObj.GetAiChatTopicById()
  1177. if err != nil {
  1178. if utils.IsErrNoRow(err) {
  1179. br.Msg = "获取数据失败!"
  1180. br.ErrMsg = "获取数据失败,主题不存在,Err:" + err.Error()
  1181. return
  1182. }
  1183. br.Msg = "获取数据失败!"
  1184. br.ErrMsg = "获取数据失败,GetAiChatTopicById,Err:" + err.Error()
  1185. return
  1186. }
  1187. assistantId = topic.AssistantId
  1188. threadId = topic.ThreadId
  1189. }
  1190. var answer string
  1191. //获取主题下的所有信息
  1192. //AiChatTopicId
  1193. //historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
  1194. //if err != nil && !utils.IsErrNoRow(err) {
  1195. // br.Msg = "获取主题历史数据失败!"
  1196. // br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
  1197. // return
  1198. //}
  1199. frList := make([]aimod.HistoryChat, 0)
  1200. tmpFileIdList := make([]string, 0)
  1201. tmpFileIdList = append(tmpFileIdList, req.OpenaiFileId...)
  1202. //// 历史消息
  1203. //for _, v := range historyList {
  1204. // if v.OpenaiFileId != "" {
  1205. // tmpFileIdList = append(tmpFileIdList, v.OpenaiFileId)
  1206. // } else {
  1207. // historyFr := new(aimod.HistoryChat)
  1208. // historyFr.Ask = v.Ask
  1209. // historyFr.Answer = v.Answer
  1210. // historyFr.OpenaiFileId = tmpFileIdList
  1211. // frList = append(frList, *historyFr)
  1212. // tmpFileIdList = []string{}
  1213. // }
  1214. //}
  1215. // 当前的消息
  1216. {
  1217. frItem := new(aimod.HistoryChat)
  1218. frItem.Ask = ask
  1219. frItem.Answer = ""
  1220. frItem.OpenaiFileId = tmpFileIdList
  1221. frList = append(frList, *frItem)
  1222. }
  1223. fileRetrieveResp, err := aiser.FileRetrieve(assistantId, threadId, req.Model, frList, req.OpenaiFileId)
  1224. if err != nil {
  1225. br.Msg = "获取数据失败!"
  1226. br.ErrMsg = "获取数据失败,FileRetrieve,Err:" + err.Error()
  1227. return
  1228. }
  1229. if fileRetrieveResp != nil {
  1230. if fileRetrieveResp.Ret == 200 {
  1231. assistantId = fileRetrieveResp.Data.AssistantId
  1232. threadId = fileRetrieveResp.Data.ThreadId
  1233. answer = fileRetrieveResp.Data.Answer
  1234. } else {
  1235. br.Msg = "获取数据失败!"
  1236. br.ErrMsg = fileRetrieveResp.Msg
  1237. return
  1238. }
  1239. }
  1240. if req.AiChatTopicId <= 0 { //新增
  1241. name, err := aiser.QueryAskContent(ask)
  1242. if err != nil {
  1243. br.Msg = "获取数据失败!"
  1244. br.ErrMsg = "获取数据失败,QueryAskContent,Err:" + err.Error()
  1245. return
  1246. }
  1247. topic := new(aimod.AiChatTopic)
  1248. topic.TopicName = name
  1249. topic.SysUserId = this.SysUser.AdminId
  1250. topic.SysUserRealName = this.SysUser.RealName
  1251. topic.CreateTime = time.Now()
  1252. topic.ModifyTime = time.Now()
  1253. topic.AssistantId = assistantId
  1254. topic.ThreadId = threadId
  1255. topicId, err := aimod.AddAiChatTopic(topic)
  1256. if err != nil {
  1257. br.Msg = "获取数据失败!"
  1258. br.ErrMsg = "生成话题失败,Err:" + err.Error()
  1259. return
  1260. }
  1261. chatItem := new(aimod.AiChat)
  1262. chatItem.AiChatTopicId = int(topicId)
  1263. chatItem.Ask = ask
  1264. chatItem.AskUuid = utils.MD5(ask)
  1265. chatItem.Answer = answer
  1266. chatItem.Model = EnabledModelsForMap[req.Model]
  1267. chatItem.SysUserId = this.SysUser.AdminId
  1268. chatItem.SysUserRealName = this.SysUser.RealName
  1269. chatItem.CreateTime = time.Now()
  1270. chatItem.ModifyTime = time.Now()
  1271. _, err = aimod.AddAiChat(chatItem)
  1272. if err != nil {
  1273. br.Msg = "获取数据失败!"
  1274. br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1275. return
  1276. }
  1277. req.AiChatTopicId = int(topicId)
  1278. } else {
  1279. chatItem := new(aimod.AiChat)
  1280. chatItem.AiChatTopicId = req.AiChatTopicId
  1281. chatItem.Ask = ask
  1282. chatItem.AskUuid = askUuid
  1283. chatItem.Answer = answer
  1284. chatItem.Model = EnabledModelsForMap[req.Model]
  1285. chatItem.SysUserId = this.SysUser.AdminId
  1286. chatItem.SysUserRealName = this.SysUser.RealName
  1287. chatItem.CreateTime = time.Now()
  1288. chatItem.ModifyTime = time.Now()
  1289. _, err = aimod.AddAiChat(chatItem)
  1290. if err != nil {
  1291. br.Msg = "获取数据失败!"
  1292. br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1293. return
  1294. }
  1295. //更新 assistantId,threadId
  1296. aiChatTopicObj := new(aimod.AiChatTopic)
  1297. //updateParams := make(map[string]interface{})
  1298. //updateParams["assistant_id"] = assistantId
  1299. //updateParams["thread_id"] = threadId
  1300. //updateParams["modify_time"] = time.Now()
  1301. //
  1302. //whereParam := make(map[string]interface{})
  1303. //whereParam["ai_chat_topic_id"] = req.AiChatTopicId
  1304. err = aiChatTopicObj.UpdateAssistantAndThreadId(assistantId, threadId, req.AiChatTopicId)
  1305. if err != nil {
  1306. br.Msg = "获取失败!"
  1307. br.ErrMsg = "修改助手标识失败,Err:" + err.Error()
  1308. return
  1309. }
  1310. }
  1311. resp.Model = aimod.ModelViewMap[req.Model]
  1312. resp.AiChatTopicId = req.AiChatTopicId
  1313. resp.Ask = ask
  1314. resp.Answer = answer
  1315. }
  1316. br.Ret = 200
  1317. br.Success = true
  1318. br.Msg = "获取成功"
  1319. br.Data = resp
  1320. }
  1321. //// @Title 文件上传
  1322. //// @Description 文件上传接口
  1323. //// @Param File query file true "文件"
  1324. //// @Param AiChatTopicId query int true "主题id"
  1325. //// @Success 200 {object} models.ResourceResp
  1326. //// @router /file/upload [post]
  1327. //func (this *AiFileController) FileUpload2() {
  1328. // br := new(models.BaseResponse).Init()
  1329. // defer func() {
  1330. // this.Data["json"] = br
  1331. // this.ServeJSON()
  1332. // }()
  1333. //
  1334. // f, h, err := this.GetFile("File")
  1335. // if err != nil {
  1336. // br.Msg = "获取资源信息失败"
  1337. // br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  1338. // return
  1339. // }
  1340. // model := this.GetString("Model")
  1341. //
  1342. // aiChatTopicId, _ := this.GetInt("AiChatTopicId")
  1343. //
  1344. // uploadFileName := h.Filename //上传的文件名
  1345. // ext := path.Ext(h.Filename)
  1346. // dateDir := time.Now().Format("20060102")
  1347. // uploadDir := utils.STATIC_DIR + "ai/" + dateDir
  1348. // err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  1349. // if err != nil {
  1350. // br.Msg = "存储目录创建失败"
  1351. // br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1352. // return
  1353. // }
  1354. // randStr := utils.GetRandStringNoSpecialChar(28)
  1355. // fileName := randStr + ext
  1356. // fpath := uploadDir + "/" + fileName
  1357. // defer f.Close() //关闭上传文件
  1358. // err = this.SaveToFile("File", fpath)
  1359. // if err != nil {
  1360. // br.Msg = "文件上传失败"
  1361. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1362. // return
  1363. // }
  1364. // resourceUrl := ``
  1365. // ossClient := services.NewOssClient()
  1366. // if ossClient == nil {
  1367. // br.Msg = "上传失败"
  1368. // br.ErrMsg = "初始化OSS服务失败"
  1369. // return
  1370. // }
  1371. // resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
  1372. // if err != nil {
  1373. // br.Msg = "文件上传失败"
  1374. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1375. // return
  1376. // }
  1377. //
  1378. // defer func() {
  1379. // os.Remove(fpath)
  1380. // }()
  1381. //
  1382. // item := new(models.Resource)
  1383. // item.ResourceUrl = resourceUrl
  1384. // item.ResourceType = 1
  1385. // item.CreateTime = time.Now()
  1386. // newId, err := models.AddResource(item)
  1387. // if err != nil {
  1388. // br.Msg = "资源上传失败"
  1389. // br.ErrMsg = "资源上传失败,Err:" + err.Error()
  1390. // return
  1391. // }
  1392. // //调用AI接口,上传文件
  1393. // resp := models.ResourceResp{
  1394. // Id: newId,
  1395. // ResourceUrl: resourceUrl,
  1396. // ResourceName: uploadFileName,
  1397. // }
  1398. // uploadResult, err := aiser.OpenAiFileUpload(resourceUrl, uploadFileName, model)
  1399. // if err != nil {
  1400. // br.Msg = "文件上传失败"
  1401. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1402. // return
  1403. // }
  1404. //
  1405. // var assistantId, threadId string
  1406. // if aiChatTopicId > 0 {
  1407. // aiChatTopicObj := new(aimod.AiChatTopic)
  1408. // aiChatTopicObj.AiChatTopicId = aiChatTopicId
  1409. // topic, err := aiChatTopicObj.GetAiChatTopicById()
  1410. // if err != nil {
  1411. // if utils.IsErrNoRow(err) {
  1412. // br.Msg = "获取数据失败!"
  1413. // br.ErrMsg = "获取数据失败,主题不存在,Err:" + err.Error()
  1414. // return
  1415. // }
  1416. // br.Msg = "获取数据失败!"
  1417. // br.ErrMsg = "获取数据失败,GetAiChatTopicById,Err:" + err.Error()
  1418. // return
  1419. // }
  1420. // assistantId = topic.AssistantId
  1421. // threadId = topic.ThreadId
  1422. // }
  1423. //
  1424. // if aiChatTopicId <= 0 { //新增
  1425. // topic := new(aimod.AiChatTopic)
  1426. // var filenameWithSuffix string
  1427. // filenameWithSuffix = path.Base(uploadFileName)
  1428. // var fileSuffix string
  1429. // fileSuffix = path.Ext(filenameWithSuffix)
  1430. // var filenameOnly string
  1431. // filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
  1432. // topic.TopicName = filenameOnly
  1433. // topic.SysUserId = this.SysUser.AdminId
  1434. // topic.SysUserRealName = this.SysUser.RealName
  1435. // topic.CreateTime = time.Now()
  1436. // topic.ModifyTime = time.Now()
  1437. // topic.AssistantId = assistantId
  1438. // topic.ThreadId = threadId
  1439. // topicId, err := aimod.AddAiChatTopic(topic)
  1440. // if err != nil {
  1441. // br.Msg = "获取数据失败!"
  1442. // br.ErrMsg = "生成话题失败,Err:" + err.Error()
  1443. // return
  1444. // }
  1445. // aiChatTopicId = int(topicId)
  1446. // chatItem := new(aimod.AiChat)
  1447. // chatItem.AiChatTopicId = aiChatTopicId
  1448. // chatItem.Ask = uploadFileName
  1449. // chatItem.AskUuid = utils.MD5(uploadFileName)
  1450. // chatItem.Model = EnabledModelsForMap[model]
  1451. // chatItem.SysUserId = this.SysUser.AdminId
  1452. // chatItem.SysUserRealName = this.SysUser.RealName
  1453. // if uploadResult != nil && uploadResult.Data != nil {
  1454. // chatItem.OpenaiFileId = uploadResult.Data.ID
  1455. // chatItem.OpenaiFileName = uploadFileName
  1456. // }
  1457. // chatItem.OpenaiFilePath = resourceUrl
  1458. // chatItem.CreateTime = time.Now()
  1459. // chatItem.ModifyTime = time.Now()
  1460. // _, err = aimod.AddAiChat(chatItem)
  1461. // if err != nil {
  1462. // br.Msg = "获取数据失败!"
  1463. // br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1464. // return
  1465. // }
  1466. // } else {
  1467. // chatItem := new(aimod.AiChat)
  1468. // chatItem.AiChatTopicId = aiChatTopicId
  1469. // chatItem.Ask = uploadFileName
  1470. // chatItem.AskUuid = utils.MD5(fileName)
  1471. // chatItem.Model = EnabledModelsForMap[model]
  1472. // chatItem.SysUserId = this.SysUser.AdminId
  1473. // chatItem.SysUserRealName = this.SysUser.RealName
  1474. // if uploadResult != nil && uploadResult.Data != nil {
  1475. // chatItem.OpenaiFileId = uploadResult.Data.ID
  1476. // chatItem.OpenaiFileName = uploadFileName
  1477. // }
  1478. // chatItem.OpenaiFilePath = resourceUrl
  1479. // chatItem.CreateTime = time.Now()
  1480. // chatItem.ModifyTime = time.Now()
  1481. // _, err = aimod.AddAiChat(chatItem)
  1482. // if err != nil {
  1483. // br.Msg = "获取数据失败!"
  1484. // br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
  1485. // return
  1486. // }
  1487. // }
  1488. //
  1489. // if uploadResult != nil && uploadResult.Data != nil && uploadResult.Data.ID != "" {
  1490. // uploadObj := new(aimod.FileUploadRecord)
  1491. // uploadObj.AdminId = this.SysUser.AdminId
  1492. // uploadObj.FileUrl = resourceUrl
  1493. // uploadObj.FileName = uploadFileName
  1494. // uploadObj.OpenaiFileId = uploadResult.Data.ID
  1495. // uploadObj.OpenaiFileName = uploadResult.Data.FileName
  1496. // uploadObj.OpenaiObject = uploadResult.Data.Object
  1497. // uploadObj.OpenaiStatus = uploadResult.Data.Status
  1498. // uploadObj.OpenaiPurpose = uploadResult.Data.Purpose
  1499. // uploadObj.OpenaiStatusDetails = uploadResult.Data.StatusDetails
  1500. // uploadObj.OpenaiCreatedAt = uploadResult.Data.CreatedAt
  1501. // uploadObj.CreateTime = time.Now()
  1502. // uploadObj.ModifyTime = time.Now()
  1503. // _, err = uploadObj.AddFileUploadRecord()
  1504. // if err != nil {
  1505. // br.Msg = "上传失败"
  1506. // br.ErrMsg = "上传失败,Err:" + err.Error()
  1507. // return
  1508. // }
  1509. // resp.OpenaiFileId = uploadObj.OpenaiFileId
  1510. // }
  1511. // resp.AiChatTopicId = aiChatTopicId
  1512. // br.Msg = "上传成功"
  1513. // br.Ret = 200
  1514. // br.Success = true
  1515. // br.Data = resp
  1516. // return
  1517. //}
  1518. // AiSummaryClassifyList
  1519. // @Title 获取所有纪要分类接口-不包含沙盘
  1520. // @Description 获取所有纪要分类接口-不包含沙盘
  1521. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1522. // @Success 200 {object} data_manage.ChartClassifyListResp
  1523. // @router /summary/classifyList [get]
  1524. func (this *AiController) AiSummaryClassifyList() {
  1525. br := new(models.BaseResponse).Init()
  1526. defer func() {
  1527. this.Data["json"] = br
  1528. this.ServeJSON()
  1529. }()
  1530. resp := new(ai_summary.AiSummaryClassifyListResp)
  1531. rootList, err := ai_summary.GetAiSummaryClassifyByParentId(0)
  1532. if err != nil && !utils.IsErrNoRow(err) {
  1533. br.Msg = "获取失败"
  1534. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1535. return
  1536. }
  1537. classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
  1538. if err != nil && !utils.IsErrNoRow(err) {
  1539. br.Msg = "获取失败"
  1540. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1541. return
  1542. }
  1543. nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
  1544. for k := range rootList {
  1545. rootNode := rootList[k]
  1546. aiSummaryService.AiSummaryClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  1547. nodeAll = append(nodeAll, rootNode)
  1548. }
  1549. resp.AllNodes = nodeAll
  1550. br.Ret = 200
  1551. br.Success = true
  1552. br.Msg = "获取成功"
  1553. br.Data = resp
  1554. }