ai_summary.go 53 KB

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