ai_pormpt.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. package ai
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/ai_summary"
  7. "eta_gn/eta_api/models/system"
  8. aiSummaryService "eta_gn/eta_api/services/ai_summary"
  9. "eta_gn/eta_api/utils"
  10. "time"
  11. )
  12. // AiPromptList
  13. // @Title 获取所有ai纪要分类接口-包含沙盘
  14. // @Description 获取所有ai纪要分类接口-包含沙盘
  15. // @Success 200 {object} data_manage.ChartClassifyListResp
  16. // @router /prompt/list [get]
  17. func (this *AiController) AiPromptList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. list, err := ai_summary.GetAiPromptList(this.SysUser.AdminId, 0)
  24. if err != nil {
  25. br.Msg = "获取失败"
  26. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  27. return
  28. }
  29. br.Ret = 200
  30. br.Success = true
  31. br.Msg = "获取成功"
  32. br.Data = list
  33. }
  34. // PromptGroupList
  35. // @Title 获取可见的目录列表
  36. // @Description 获取可见的目录列表接口
  37. // @Success 200 {object} ppt_english.RespGroupList
  38. // @router /prompt/groups [get]
  39. func (this *AiController) PromptGroupList() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. list, err := ai_summary.GetAiPromptShareList()
  46. if err != nil {
  47. br.Msg = err.Error()
  48. return
  49. }
  50. resp := make([]*ai_summary.RespGroupListItem, 0)
  51. publicAdminIdList := make([]int, 0)
  52. publicPromptListMap := make(map[int][]*ai_summary.AiPromptItem)
  53. systemAdminMap := make(map[int]*system.Admin)
  54. for _, v := range list {
  55. publicPromptList, ok := publicPromptListMap[v.SysAdminId]
  56. if !ok {
  57. publicPromptList = make([]*ai_summary.AiPromptItem, 0)
  58. publicAdminIdList = append(publicAdminIdList, v.SysAdminId)
  59. }
  60. systemAdminMap[v.SysAdminId] = &system.Admin{
  61. AdminId: v.SysAdminId,
  62. RealName: v.SysAdminName,
  63. }
  64. publicPromptList = append(publicPromptList, v)
  65. publicPromptListMap[v.SysAdminId] = publicPromptList
  66. }
  67. for _, v := range publicAdminIdList {
  68. systemAdmin, ok := systemAdminMap[v]
  69. if !ok {
  70. continue
  71. }
  72. respGroupPptNameListItemList, ok := publicPromptListMap[v]
  73. if !ok {
  74. respGroupPptNameListItemList = make([]*ai_summary.AiPromptItem, 0)
  75. }
  76. // 分组信息
  77. tmpRespGroupListItem := &ai_summary.RespGroupListItem{
  78. GroupId: int64(systemAdmin.AdminId),
  79. GroupName: systemAdmin.RealName,
  80. AdminId: systemAdmin.AdminId,
  81. IsShare: 1,
  82. PromptList: respGroupPptNameListItemList,
  83. }
  84. resp = append(resp, tmpRespGroupListItem)
  85. }
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "查询成功"
  89. br.Data = resp
  90. return
  91. }
  92. // AddPpt
  93. // @Title 新增提示词
  94. // @Description 新增提示词接口
  95. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  96. // @Success 200 Ret=200 新增成功
  97. // @router /prompt/add [post]
  98. func (this *AiController) AddPrompt() {
  99. br := new(models.BaseResponse).Init()
  100. defer func() {
  101. this.Data["json"] = br
  102. this.ServeJSON()
  103. }()
  104. var req ai_summary.AiPromptAddReq
  105. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  106. if err != nil {
  107. br.Msg = "参数解析异常!"
  108. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  109. return
  110. }
  111. if req.Title == "" {
  112. br.Msg = "标题不能为空"
  113. return
  114. }
  115. var msg string
  116. //获取该层级下最大的排序数
  117. maxSort, err := ai_summary.GetAiPromptMaxSort(this.SysUser.AdminId)
  118. prompt := &ai_summary.AiPrompt{
  119. CreateTime: time.Now(),
  120. ModifyTime: time.Now(),
  121. PromptContent: req.PromptContent,
  122. SysAdminId: this.SysUser.AdminId,
  123. SysAdminName: this.SysUser.RealName,
  124. Title: req.Title,
  125. Sort: maxSort + 1,
  126. }
  127. _, err = ai_summary.AddPropmt(prompt)
  128. if err != nil {
  129. br.Msg = "新增失败"
  130. br.ErrMsg = "新增失败,Err:" + err.Error()
  131. return
  132. }
  133. msg = "新增成功"
  134. br.Ret = 200
  135. br.Success = true
  136. br.Msg = msg
  137. }
  138. // EditPpt
  139. // @Title 编辑提示词
  140. // @Description 编辑提示词接口
  141. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  142. // @Success 200 Ret=200 编辑成功
  143. // @router /prompt/edit [post]
  144. func (this *AiController) EditPrompt() {
  145. br := new(models.BaseResponse).Init()
  146. defer func() {
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. var req ai_summary.AiPromptEditReq
  151. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  152. if err != nil {
  153. br.Msg = "参数解析异常!"
  154. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  155. return
  156. }
  157. if req.Title == "" {
  158. br.Msg = "标题不能为空"
  159. return
  160. }
  161. promptItem := &ai_summary.AiPrompt{
  162. AiPromptId: req.AiPromptId,
  163. PromptContent: req.PromptContent,
  164. Title: req.Title,
  165. CreateTime: time.Time{},
  166. ModifyTime: time.Now(),
  167. }
  168. err = promptItem.Update([]string{"ModifyTime", "PromptContent", "Title"})
  169. if err != nil {
  170. br.Msg = "编辑失败"
  171. br.ErrMsg = "编辑失败,Err:" + err.Error()
  172. return
  173. }
  174. br.Ret = 200
  175. br.Success = true
  176. br.Msg = "编辑成功"
  177. br.IsAddLog = true
  178. }
  179. // DeletePpt
  180. // @Title 删除提示词
  181. // @Description 删除ppt接口
  182. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  183. // @Success 200 Ret=200 删除成功
  184. // @router /prompt/delete [post]
  185. func (this *AiController) DeletePrompt() {
  186. br := new(models.BaseResponse).Init()
  187. defer func() {
  188. this.Data["json"] = br
  189. this.ServeJSON()
  190. }()
  191. var req ai_summary.DeleteAipromptReq
  192. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  193. if err != nil {
  194. br.Msg = "参数解析异常!"
  195. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  196. return
  197. }
  198. if req.AiPromptId <= 0 {
  199. br.Msg = "参数错误"
  200. return
  201. }
  202. promptInfo, err := ai_summary.GetAiPromptById(req.AiPromptId)
  203. if err != nil {
  204. br.Msg = "提示词不存在"
  205. return
  206. }
  207. if promptInfo.SysAdminId != this.SysUser.AdminId {
  208. br.Msg = "无权删除"
  209. return
  210. }
  211. err = ai_summary.DelAiPromptyId(req.AiPromptId)
  212. if err != nil {
  213. br.Msg = "删除失败"
  214. br.ErrMsg = "删除失败,Err:" + err.Error()
  215. return
  216. }
  217. br.Ret = 200
  218. br.Success = true
  219. br.IsAddLog = true
  220. br.Msg = "删除成功"
  221. }
  222. // DetailPrompt
  223. // @Title 获取提示词详情
  224. // @Description 获取提示词详情接口
  225. // @Param AiPromptId query int true "提示词id"
  226. // @Success 200 {object} ppt_english.PptEnglish
  227. // @router /prompt/detail [get]
  228. func (this *AiController) DetailPrompt() {
  229. br := new(models.BaseResponse).Init()
  230. defer func() {
  231. if br.ErrMsg == "" {
  232. br.IsSendEmail = false
  233. }
  234. this.Data["json"] = br
  235. this.ServeJSON()
  236. }()
  237. sysUser := this.SysUser
  238. if sysUser == nil {
  239. br.Msg = "请登录"
  240. br.ErrMsg = "请登录,SysUser Is Empty"
  241. br.Ret = 408
  242. return
  243. }
  244. aiPromptId, _ := this.GetInt("AiPromptId")
  245. promptInfo, err := ai_summary.GetAiPromptById(aiPromptId)
  246. if err != nil {
  247. br.Msg = "提示词不存在"
  248. return
  249. }
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "获取成功"
  253. br.Data = promptInfo
  254. }
  255. // MoveAiPrompt
  256. // @Title 移动提示词
  257. // @Description 移动提示词接口
  258. // @Param request body models.ReqMoveGroupPpt true "type json string"
  259. // @Success 200 Ret=200 移动成功
  260. // @router /prompt/move [post]
  261. func (this *AiController) MoveAiPrompt() {
  262. br := new(models.BaseResponse).Init()
  263. defer func() {
  264. this.Data["json"] = br
  265. this.ServeJSON()
  266. }()
  267. var req ai_summary.ReqMovePrompt
  268. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  269. if err != nil {
  270. br.Msg = "参数解析异常!"
  271. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  272. return
  273. }
  274. if req.AiPromptId <= 0 {
  275. br.Msg = "请输入提示词ID"
  276. return
  277. }
  278. prompt, err := ai_summary.GetAiPromptById(req.AiPromptId)
  279. if err != nil {
  280. if utils.IsErrNoRow(err) {
  281. br.Msg = "当前提示词不存在"
  282. br.ErrMsg = "当前提示词不存在"
  283. return
  284. }
  285. br.Msg = "提示词查询出错"
  286. br.ErrMsg = "提示词查询出错:" + err.Error()
  287. return
  288. }
  289. var updateStr []string
  290. var currentSort, prevSort, nextSort int
  291. currentSort = prompt.Sort
  292. var prevPrompt *ai_summary.AiPrompt
  293. var nextPrompt *ai_summary.AiPrompt
  294. if req.PrevAiPromptId > 0 {
  295. prevPrompt, err = ai_summary.GetAiPromptById(req.PrevAiPromptId)
  296. if err != nil {
  297. if utils.IsErrNoRow(err) {
  298. err = errors.New("目录下的提示词不存在")
  299. return
  300. }
  301. err = errors.New("目录下的提示词查询出错:" + err.Error())
  302. return
  303. }
  304. prevSort = prevPrompt.Sort
  305. }
  306. if req.NextAiPromptId > 0 {
  307. nextPrompt, err = ai_summary.GetAiPromptById(req.NextAiPromptId)
  308. if err != nil {
  309. if utils.IsErrNoRow(err) {
  310. err = errors.New("目录下的提示词不存在")
  311. return
  312. }
  313. err = errors.New("目录下的提示词查询出错:" + err.Error())
  314. return
  315. }
  316. nextSort = nextPrompt.Sort
  317. }
  318. updateStr = append(updateStr, "sort")
  319. //移到两个排序值中间操作
  320. if prevSort >= currentSort {
  321. //往下移动
  322. err = ai_summary.MoveDownPromptBySort(this.SysUser.AdminId, prevSort, currentSort)
  323. if err != nil {
  324. err = errors.New("向下移动提示词出错:" + err.Error())
  325. return
  326. }
  327. prompt.Sort = prevSort
  328. } else if nextSort <= currentSort && nextSort != 0 {
  329. //往上移动
  330. err = ai_summary.MoveUpPromptBySort(this.SysUser.AdminId, nextSort, currentSort)
  331. if err != nil {
  332. err = errors.New("向上移动提示词出错:" + err.Error())
  333. return
  334. }
  335. prompt.Sort = nextSort
  336. }
  337. //更新当前排序
  338. err = prompt.Update(updateStr)
  339. if err != nil {
  340. err = errors.New("移动提示词出错:" + err.Error())
  341. return
  342. }
  343. br.Ret = 200
  344. br.Success = true
  345. br.Msg = "移动成功"
  346. }
  347. // SharePrompt
  348. // @Title 共享/取消共享单个提示词
  349. // @Description 共享/取消共享单个提示词接口
  350. // @Param request body models.ReqPptShare true "type json string"
  351. // @Success 200 {object} models.RespPptShare
  352. // @router /prompt/share [post]
  353. func (this *AiController) SharePrompt() {
  354. br := new(models.BaseResponse).Init()
  355. defer func() {
  356. this.Data["json"] = br
  357. this.ServeJSON()
  358. }()
  359. var req ai_summary.DeleteAipromptReq
  360. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  361. if err != nil {
  362. br.Msg = "参数解析异常!"
  363. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  364. return
  365. }
  366. if req.AiPromptId <= 0 {
  367. br.Msg = "请输入提示词序号"
  368. return
  369. }
  370. err = aiSummaryService.SharePrompt(req.AiPromptId, this.SysUser.AdminId)
  371. if err != nil {
  372. br.Msg = err.Error()
  373. return
  374. }
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "操作成功"
  378. return
  379. }