ai_summary.go 54 KB

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