framework.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. package ai_predict_model
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. aiPredictModel "eta/eta_api/models/ai_predict_model"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strings"
  10. "time"
  11. )
  12. // AiPredictModelFrameworkController 模型框架
  13. type AiPredictModelFrameworkController struct {
  14. controllers.BaseAuthController
  15. }
  16. // List
  17. // @Title 列表
  18. // @Description 列表
  19. // @Param AdminId query int false "创建人ID"
  20. // @Param Visibility query int false "范围: 0-所有; 1-私有; 2-公开"
  21. // @Param Keyword query string false "关键词"
  22. // @Success 200 Ret=200 获取成功
  23. // @router /framework/list [get]
  24. func (c *AiPredictModelFrameworkController) List() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. if br.ErrMsg == "" {
  28. br.IsSendEmail = false
  29. }
  30. c.Data["json"] = br
  31. c.ServeJSON()
  32. }()
  33. sysUser := c.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. adminId, _ := c.GetInt("AdminId")
  41. keyword := c.GetString("Keyword")
  42. keyword = strings.TrimSpace(keyword)
  43. frameworkOb := new(aiPredictModel.AiPredictModelFramework)
  44. cond := ``
  45. pars := make([]interface{}, 0)
  46. if adminId > 0 {
  47. cond += fmt.Sprintf(` AND %s = ?`, aiPredictModel.AiPredictModelFrameworkColumns.AdminId)
  48. pars = append(pars, adminId)
  49. }
  50. if keyword != "" {
  51. cond += fmt.Sprintf(` AND %s LIKE ?`, aiPredictModel.AiPredictModelFrameworkColumns.FrameworkName)
  52. pars = append(pars, "%"+keyword+"%")
  53. }
  54. orderRule := `sort ASC, create_time DESC`
  55. list, e := frameworkOb.GetItemsByCondition(cond, pars, []string{}, orderRule)
  56. if e != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取框架列表失败, Err: " + e.Error()
  59. return
  60. }
  61. resp := make([]*aiPredictModel.AiPredictModelFrameworkItem, 0)
  62. for _, v := range list {
  63. t := aiPredictModel.FormatAiPredictModelFramework2Item(v, make([]*aiPredictModel.AiPredictModelFrameworkNodeItem, 0))
  64. if t.AdminId == sysUser.AdminId || utils.IsAdminRole(sysUser.RoleTypeCode) {
  65. t.Button.OpButton = true
  66. t.Button.DeleteButton = true
  67. t.Button.MoveButton = true
  68. }
  69. resp = append(resp, t)
  70. }
  71. br.Data = resp
  72. br.Ret = 200
  73. br.Success = true
  74. br.Msg = "获取成功"
  75. }
  76. // Add
  77. // @Title 新增框架
  78. // @Description 新增框架
  79. // @Param request body aiPredictModel.AiPredictModelFrameworkAddReq true "type json string"
  80. // @Success 200 Ret=200 操作成功
  81. // @router /framework/add [post]
  82. func (c *AiPredictModelFrameworkController) Add() {
  83. br := new(models.BaseResponse).Init()
  84. defer func() {
  85. if br.ErrMsg == "" {
  86. br.IsSendEmail = false
  87. }
  88. c.Data["json"] = br
  89. c.ServeJSON()
  90. }()
  91. sysUser := c.SysUser
  92. if sysUser == nil {
  93. br.Msg = "请登录"
  94. br.ErrMsg = "请登录,SysUser Is Empty"
  95. br.Ret = 408
  96. return
  97. }
  98. // 参数校验
  99. var req aiPredictModel.AiPredictModelFrameworkAddReq
  100. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  101. br.Msg = "参数解析异常!"
  102. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  103. return
  104. }
  105. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  106. if req.FrameworkName == "" {
  107. br.Msg = "框架名称不可为空"
  108. return
  109. }
  110. // 重名校验
  111. {
  112. ob := new(aiPredictModel.AiPredictModelFramework)
  113. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, aiPredictModel.AiPredictModelFrameworkColumns.FrameworkName, aiPredictModel.AiPredictModelFrameworkColumns.AdminId)
  114. pars := make([]interface{}, 0)
  115. pars = append(pars, req.FrameworkName, sysUser.AdminId)
  116. exist, e := ob.GetItemByCondition(cond, pars)
  117. if e != nil && e.Error() != utils.ErrNoRow() {
  118. br.Msg = "操作失败"
  119. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  120. return
  121. }
  122. if exist != nil {
  123. br.Msg = "框架名称已存在,请重新输入"
  124. return
  125. }
  126. }
  127. now := time.Now().Local()
  128. frameworkCode := utils.MD5(fmt.Sprint(now.UnixMilli()))
  129. item := new(aiPredictModel.AiPredictModelFramework)
  130. item.FrameworkName = req.FrameworkName
  131. item.FrameworkCode = frameworkCode
  132. item.FrameworkImg = req.FrameworkImg
  133. item.FrameworkContent = req.FrameworkContent
  134. item.AdminId = sysUser.AdminId
  135. item.AdminName = sysUser.RealName
  136. item.CreateTime = now
  137. item.ModifyTime = now
  138. nodes := make([]*aiPredictModel.AiPredictModelFrameworkNode, 0)
  139. itemNodes := make([]*aiPredictModel.AiPredictModelFrameworkNodeItem, 0)
  140. if len(req.Nodes) > 0 {
  141. for _, v := range req.Nodes {
  142. if v.AiPredictModelIndexId <= 0 {
  143. continue
  144. }
  145. t := new(aiPredictModel.AiPredictModelFrameworkNode)
  146. t.FrameworkName = req.FrameworkName
  147. t.NodeId = v.NodeId
  148. t.NodeName = v.NodeName
  149. t.AiPredictModelIndexId = v.AiPredictModelIndexId
  150. t.CreateTime = now
  151. nodes = append(nodes, t)
  152. num := 1
  153. // 响应节点数据
  154. td := aiPredictModel.FormatAiPredictModelFrameworkNode2Item(t, num, map[int]*aiPredictModel.AiPredictModelIndex{})
  155. itemNodes = append(itemNodes, td)
  156. }
  157. }
  158. if e := item.CreateFrameworkAndNodes(item, nodes); e != nil {
  159. br.Msg = "操作失败"
  160. br.ErrMsg = "新增框架及节点失败, Err: " + e.Error()
  161. return
  162. }
  163. detail := aiPredictModel.FormatAiPredictModelFramework2Item(item, itemNodes)
  164. br.Data = detail
  165. br.Ret = 200
  166. br.Success = true
  167. br.Msg = "操作成功"
  168. br.IsAddLog = true
  169. }
  170. // Edit
  171. // @Title 编辑框架
  172. // @Description 编辑框架
  173. // @Param request body aiPredictModel.AiPredictModelFrameworkEditReq true "type json string"
  174. // @Success 200 Ret=200 操作成功
  175. // @router /framework/edit [post]
  176. func (c *AiPredictModelFrameworkController) Edit() {
  177. br := new(models.BaseResponse).Init()
  178. defer func() {
  179. if br.ErrMsg == "" {
  180. br.IsSendEmail = false
  181. }
  182. c.Data["json"] = br
  183. c.ServeJSON()
  184. }()
  185. sysUser := c.SysUser
  186. if sysUser == nil {
  187. br.Msg = "请登录"
  188. br.ErrMsg = "请登录,SysUser Is Empty"
  189. br.Ret = 408
  190. return
  191. }
  192. // 参数校验
  193. var req aiPredictModel.AiPredictModelFrameworkEditReq
  194. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  195. br.Msg = "参数解析异常!"
  196. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  197. return
  198. }
  199. if req.AiPredictModelFrameworkId <= 0 {
  200. br.Msg = "参数有误"
  201. br.ErrMsg = fmt.Sprintf("参数有误, AiPredictModelFrameworkId: %d", req.AiPredictModelFrameworkId)
  202. return
  203. }
  204. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  205. if req.FrameworkName == "" {
  206. br.Msg = "框架名称不可为空"
  207. return
  208. }
  209. frameworkOb := new(aiPredictModel.AiPredictModelFramework)
  210. item, e := frameworkOb.GetItemById(req.AiPredictModelFrameworkId)
  211. if e != nil {
  212. if e.Error() == utils.ErrNoRow() {
  213. br.Msg = "框架不存在, 请刷新页面"
  214. return
  215. }
  216. br.Msg = "操作失败"
  217. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  218. return
  219. }
  220. // 操作权限校验
  221. if item.AdminId != sysUser.AdminId && !utils.IsAdminRole(sysUser.RoleTypeCode) {
  222. br.Msg = "您没有权限操作该框架"
  223. return
  224. }
  225. // 重名校验
  226. {
  227. ob := new(aiPredictModel.AiPredictModelFramework)
  228. cond := fmt.Sprintf(` AND %s <> ? AND %s = ? AND %s = ?`, ob.PrimaryId(), aiPredictModel.AiPredictModelFrameworkColumns.FrameworkName, aiPredictModel.AiPredictModelFrameworkColumns.AdminId)
  229. pars := make([]interface{}, 0)
  230. pars = append(pars, req.AiPredictModelFrameworkId, req.FrameworkName, sysUser.AdminId)
  231. exist, e := ob.GetItemByCondition(cond, pars)
  232. if e != nil && e.Error() != utils.ErrNoRow() {
  233. br.Msg = "操作失败"
  234. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  235. return
  236. }
  237. if exist != nil {
  238. br.Msg = "框架名称已存在,请重新输入"
  239. return
  240. }
  241. }
  242. now := time.Now().Local()
  243. item.FrameworkName = req.FrameworkName
  244. item.FrameworkImg = req.FrameworkImg
  245. item.FrameworkContent = req.FrameworkContent
  246. item.ModifyTime = now
  247. updateCols := []string{"FrameworkName", "FrameworkImg", "FrameworkContent", "ModifyTime"}
  248. nodes := make([]*aiPredictModel.AiPredictModelFrameworkNode, 0)
  249. itemNodes := make([]*aiPredictModel.AiPredictModelFrameworkNodeItem, 0)
  250. if len(req.Nodes) > 0 {
  251. for _, v := range req.Nodes {
  252. if v.AiPredictModelIndexId <= 0 {
  253. continue
  254. }
  255. t := new(aiPredictModel.AiPredictModelFrameworkNode)
  256. t.AiPredictModelFrameworkId = req.AiPredictModelFrameworkId
  257. t.FrameworkName = req.FrameworkName
  258. t.NodeId = v.NodeId
  259. t.NodeName = v.NodeName
  260. t.AiPredictModelIndexId = v.AiPredictModelIndexId
  261. t.CreateTime = now
  262. nodes = append(nodes, t)
  263. // 响应节点数据
  264. td := aiPredictModel.FormatAiPredictModelFrameworkNode2Item(t, 1, map[int]*aiPredictModel.AiPredictModelIndex{})
  265. itemNodes = append(itemNodes, td)
  266. }
  267. }
  268. if e := item.EditFrameworkAndNodes(item, updateCols, nodes); e != nil {
  269. br.Msg = "操作失败"
  270. br.ErrMsg = "编辑框架及节点失败, Err: " + e.Error()
  271. return
  272. }
  273. detail := aiPredictModel.FormatAiPredictModelFramework2Item(item, itemNodes)
  274. br.Data = detail
  275. br.Ret = 200
  276. br.Success = true
  277. br.Msg = "操作成功"
  278. br.IsAddLog = true
  279. }
  280. // Remove
  281. // @Title 删除框架
  282. // @Description 删除视频
  283. // @Param request body aiPredictModel.AiPredictModelFrameworkRemoveReq true "type json string"
  284. // @Success 200 Ret=200 操作成功
  285. // @router /framework/remove [post]
  286. func (c *AiPredictModelFrameworkController) Remove() {
  287. br := new(models.BaseResponse).Init()
  288. defer func() {
  289. if br.ErrMsg == "" {
  290. br.IsSendEmail = false
  291. }
  292. c.Data["json"] = br
  293. c.ServeJSON()
  294. }()
  295. sysUser := c.SysUser
  296. if sysUser == nil {
  297. br.Msg = "请登录"
  298. br.ErrMsg = "请登录,SysUser Is Empty"
  299. br.Ret = 408
  300. return
  301. }
  302. // 参数校验
  303. var req aiPredictModel.AiPredictModelFrameworkRemoveReq
  304. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  305. br.Msg = "参数解析异常!"
  306. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  307. return
  308. }
  309. if req.AiPredictModelFrameworkId <= 0 {
  310. br.Msg = "参数有误"
  311. br.ErrMsg = fmt.Sprintf("参数有误, AiPredictModelFrameworkId: %d", req.AiPredictModelFrameworkId)
  312. return
  313. }
  314. ob := new(aiPredictModel.AiPredictModelFramework)
  315. item, e := ob.GetItemById(req.AiPredictModelFrameworkId)
  316. if e != nil {
  317. if e.Error() == utils.ErrNoRow() {
  318. br.Ret = 200
  319. br.Success = true
  320. br.Msg = "操作成功"
  321. return
  322. }
  323. br.Msg = "操作失败"
  324. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  325. return
  326. }
  327. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && item.AdminId != sysUser.AdminId {
  328. br.Msg = "无权操作"
  329. return
  330. }
  331. if e := item.RemoveFrameworkAndNodes(req.AiPredictModelFrameworkId); e != nil {
  332. br.Msg = "操作失败"
  333. br.ErrMsg = "删除框架失败, Err: " + e.Error()
  334. return
  335. }
  336. br.Ret = 200
  337. br.Success = true
  338. br.Msg = "操作成功"
  339. br.IsAddLog = true
  340. }
  341. // Rename
  342. // @Title 重命名框架
  343. // @Description 重命名框架
  344. // @Param request body aiPredictModel.AiPredictModelFrameworkRenameReq true "type json string"
  345. // @Success 200 Ret=200 操作成功
  346. // @router /framework/rename [post]
  347. func (c *AiPredictModelFrameworkController) Rename() {
  348. br := new(models.BaseResponse).Init()
  349. defer func() {
  350. if br.ErrMsg == "" {
  351. br.IsSendEmail = false
  352. }
  353. c.Data["json"] = br
  354. c.ServeJSON()
  355. }()
  356. sysUser := c.SysUser
  357. if sysUser == nil {
  358. br.Msg = "请登录"
  359. br.ErrMsg = "请登录,SysUser Is Empty"
  360. br.Ret = 408
  361. return
  362. }
  363. // 参数校验
  364. var req aiPredictModel.AiPredictModelFrameworkRenameReq
  365. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  366. br.Msg = "参数解析异常!"
  367. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  368. return
  369. }
  370. if req.AiPredictModelFrameworkId <= 0 {
  371. br.Msg = "参数有误"
  372. br.ErrMsg = fmt.Sprintf("参数有误, AiPredictModelFrameworkId: %d", req.AiPredictModelFrameworkId)
  373. return
  374. }
  375. req.FrameworkName = strings.TrimSpace(req.FrameworkName)
  376. if req.FrameworkName == "" {
  377. br.Msg = "框架名称不可为空"
  378. return
  379. }
  380. frameworkOb := new(aiPredictModel.AiPredictModelFramework)
  381. item, e := frameworkOb.GetItemById(req.AiPredictModelFrameworkId)
  382. if e != nil {
  383. if e.Error() == utils.ErrNoRow() {
  384. br.Msg = "框架不存在, 请刷新页面"
  385. return
  386. }
  387. br.Msg = "操作失败"
  388. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  389. return
  390. }
  391. // 操作权限校验
  392. if item.AdminId != sysUser.AdminId && !utils.IsAdminRole(sysUser.RoleTypeCode) {
  393. br.Msg = "您没有权限操作该框架"
  394. return
  395. }
  396. // 重名校验
  397. {
  398. ob := new(aiPredictModel.AiPredictModelFramework)
  399. cond := fmt.Sprintf(` AND %s <> ? AND %s = ? AND %s = ?`, ob.PrimaryId(), aiPredictModel.AiPredictModelFrameworkColumns.FrameworkName, aiPredictModel.AiPredictModelFrameworkColumns.AdminId)
  400. pars := make([]interface{}, 0)
  401. pars = append(pars, req.AiPredictModelFrameworkId, req.FrameworkName, sysUser.AdminId)
  402. exist, e := ob.GetItemByCondition(cond, pars)
  403. if e != nil && e.Error() != utils.ErrNoRow() {
  404. br.Msg = "操作失败"
  405. br.ErrMsg = "获取重名框架失败, Err: " + e.Error()
  406. return
  407. }
  408. if exist != nil {
  409. br.Msg = "框架名称已存在,请重新输入"
  410. return
  411. }
  412. }
  413. now := time.Now().Local()
  414. item.FrameworkName = req.FrameworkName
  415. item.ModifyTime = now
  416. updateCols := []string{"FrameworkName", "ModifyTime"}
  417. if e := item.Update(updateCols); e != nil {
  418. br.Msg = "操作失败"
  419. br.ErrMsg = "框架重命名失败, Err: " + e.Error()
  420. return
  421. }
  422. br.Ret = 200
  423. br.Success = true
  424. br.Msg = "操作成功"
  425. }
  426. // Move
  427. // @Title 移动排序
  428. // @Description 移动排序
  429. // @Param request body aiPredictModel.AiPredictModelFrameworkMoveReq true "type json string"
  430. // @Success 200 Ret=200 操作成功
  431. // @router /framework/move [post]
  432. func (c *AiPredictModelFrameworkController) Move() {
  433. br := new(models.BaseResponse).Init()
  434. defer func() {
  435. if br.ErrMsg == "" {
  436. br.IsSendEmail = false
  437. }
  438. c.Data["json"] = br
  439. c.ServeJSON()
  440. }()
  441. sysUser := c.SysUser
  442. if sysUser == nil {
  443. br.Msg = "请登录"
  444. br.ErrMsg = "请登录,SysUser Is Empty"
  445. br.Ret = 408
  446. return
  447. }
  448. // 参数校验
  449. var req aiPredictModel.AiPredictModelFrameworkMoveReq
  450. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  451. br.Msg = "参数解析异常!"
  452. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  453. return
  454. }
  455. if req.AiPredictModelFrameworkId <= 0 {
  456. br.Msg = "参数有误"
  457. br.ErrMsg = fmt.Sprintf("参数有误, AiPredictModelFrameworkId: %d", req.AiPredictModelFrameworkId)
  458. return
  459. }
  460. frameworkOb := new(aiPredictModel.AiPredictModelFramework)
  461. item, e := frameworkOb.GetItemById(req.AiPredictModelFrameworkId)
  462. if e != nil {
  463. if e.Error() == utils.ErrNoRow() {
  464. br.Msg = "框架不存在, 请刷新页面"
  465. return
  466. }
  467. br.Msg = "操作失败"
  468. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  469. return
  470. }
  471. updateCols := make([]string, 0)
  472. // 上一个兄弟节点
  473. if req.PrevAiPredictModelFrameworkId > 0 {
  474. prev, e := frameworkOb.GetItemById(req.PrevAiPredictModelFrameworkId)
  475. if e != nil {
  476. br.Msg = "操作失败"
  477. br.ErrMsg = "获取上一个兄弟节点失败, Err: " + e.Error()
  478. return
  479. }
  480. // 两个兄弟节点之间
  481. if req.NextAiPredictModelFrameworkId > 0 {
  482. next, e := frameworkOb.GetItemById(req.PrevAiPredictModelFrameworkId)
  483. if e != nil {
  484. br.Msg = "操作失败"
  485. br.ErrMsg = "获取下一个兄弟节点失败, Err: " + e.Error()
  486. return
  487. }
  488. // 如果上一个与下一个排序权重是一致的, 那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2, 自己变成上一个兄弟的排序权重+1
  489. if prev.Sort == next.Sort || prev.Sort == item.Sort {
  490. strUpdate := `sort + 2`
  491. _ = aiPredictModel.UpdateAiPredictModelFrameworkSort(sysUser.AdminId, prev.AiPredictModelFrameworkId, prev.Sort, strUpdate)
  492. } else {
  493. // 如果下一个排序权重正好是上一个节点的下一层, 那么需要再加一层了
  494. if next.Sort-prev.Sort == 1 {
  495. //变更兄弟节点的排序
  496. strUpdate := `sort + 1`
  497. _ = aiPredictModel.UpdateAiPredictModelFrameworkSort(sysUser.AdminId, 0, prev.Sort, strUpdate)
  498. }
  499. }
  500. }
  501. // 上一个兄弟节点sort+1
  502. item.Sort = prev.Sort + 1
  503. item.ModifyTime = time.Now()
  504. updateCols = append(updateCols, "Sort", "ModifyTime")
  505. } else {
  506. first, err := aiPredictModel.GetFirstAiPredictModelFramework()
  507. if err != nil && err.Error() != utils.ErrNoRow() {
  508. br.Msg = "操作失败"
  509. br.ErrMsg = "获取我的模型框架排首位的数据失败, Err:" + err.Error()
  510. return
  511. }
  512. if first != nil && first.Sort == 0 {
  513. strUpdate := ` sort + 1 `
  514. _ = aiPredictModel.UpdateAiPredictModelFrameworkSort(sysUser.AdminId, first.AiPredictModelFrameworkId-1, 0, strUpdate)
  515. }
  516. // 排首位
  517. item.Sort = 0
  518. item.ModifyTime = time.Now()
  519. updateCols = append(updateCols, "Sort", "ModifyTime")
  520. }
  521. if len(updateCols) > 0 {
  522. if e := item.Update(updateCols); e != nil {
  523. br.Msg = "操作失败"
  524. br.ErrMsg = "更新框架排序失败, Err: " + e.Error()
  525. return
  526. }
  527. }
  528. br.Ret = 200
  529. br.Success = true
  530. br.Msg = "操作成功"
  531. }
  532. // Detail
  533. // @Title 框架详情
  534. // @Description 框架详情
  535. // @Param AiPredictModelFrameworkId query int true "框架ID"
  536. // @Success 200 Ret=200 操作成功
  537. // @router /framework/detail [get]
  538. func (c *AiPredictModelFrameworkController) Detail() {
  539. br := new(models.BaseResponse).Init()
  540. defer func() {
  541. if br.ErrMsg == "" {
  542. br.IsSendEmail = false
  543. }
  544. c.Data["json"] = br
  545. c.ServeJSON()
  546. }()
  547. sysUser := c.SysUser
  548. if sysUser == nil {
  549. br.Msg = "请登录"
  550. br.ErrMsg = "请登录,SysUser Is Empty"
  551. br.Ret = 408
  552. return
  553. }
  554. frameworkId, _ := c.GetInt("AiPredictModelFrameworkId")
  555. if frameworkId <= 0 {
  556. br.Msg = "参数有误"
  557. br.ErrMsg = fmt.Sprintf("参数有误, AiPredictModelFrameworkId: %d", frameworkId)
  558. return
  559. }
  560. frameworkOb := new(aiPredictModel.AiPredictModelFramework)
  561. item, e := frameworkOb.GetItemById(frameworkId)
  562. if e != nil {
  563. if e.Error() == utils.ErrNoRow() {
  564. br.Msg = "框架不存在, 请刷新页面"
  565. return
  566. }
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取框架失败, Err: " + e.Error()
  569. return
  570. }
  571. // 获取节点
  572. nodeOb := new(aiPredictModel.AiPredictModelFrameworkNode)
  573. nodeCond := ` AND ai_predict_model_framework_id = ?`
  574. nodePars := make([]interface{}, 0)
  575. nodePars = append(nodePars, frameworkId)
  576. nodes, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
  577. if e != nil {
  578. br.Msg = "获取失败"
  579. br.ErrMsg = "获取框架节点失败, Err: " + e.Error()
  580. return
  581. }
  582. // 模型标的map
  583. aiPredictModelIndexMap := make(map[int]*aiPredictModel.AiPredictModelIndex)
  584. {
  585. aiPredictModelIndexIdList := make([]interface{}, 0)
  586. for _, v := range nodes {
  587. if v.AiPredictModelIndexId > 0 {
  588. aiPredictModelIndexIdList = append(aiPredictModelIndexIdList, v.AiPredictModelIndexId)
  589. }
  590. }
  591. indexIdNum := len(aiPredictModelIndexIdList)
  592. if indexIdNum > 0 {
  593. indexObj := aiPredictModel.AiPredictModelIndex{}
  594. indexList, e := indexObj.GetItemsByCondition(` AND ai_predict_model_index_id in (`+utils.GetOrmInReplace(indexIdNum)+`)`, aiPredictModelIndexIdList, []string{}, "")
  595. if e != nil {
  596. if e.Error() == utils.ErrNoRow() {
  597. br.Msg = "框架不存在, 请刷新页面"
  598. return
  599. }
  600. br.Msg = "获取失败"
  601. br.ErrMsg = "获取标的列表失败, Err: " + e.Error()
  602. return
  603. }
  604. for _, v := range indexList {
  605. aiPredictModelIndexMap[v.AiPredictModelIndexId] = v
  606. }
  607. }
  608. }
  609. // 格式化响应数据
  610. itemNodes := make([]*aiPredictModel.AiPredictModelFrameworkNodeItem, 0)
  611. for _, v := range nodes {
  612. if v.NodeId == "" {
  613. continue
  614. }
  615. num := 1
  616. itemNodes = append(itemNodes, aiPredictModel.FormatAiPredictModelFrameworkNode2Item(v, num, aiPredictModelIndexMap))
  617. }
  618. detail := aiPredictModel.FormatAiPredictModelFramework2Item(item, itemNodes)
  619. br.Data = detail
  620. br.Ret = 200
  621. br.Success = true
  622. br.Msg = "操作成功"
  623. }