index.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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/models/ai_predict_model/request"
  8. "eta/eta_api/models/data_manage"
  9. dataSourceModel "eta/eta_api/models/data_source"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/elastic"
  14. "eta/eta_api/utils"
  15. "fmt"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "github.com/tealeg/xlsx"
  18. "os"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // AiPredictModelIndexController AI预测模型标的
  24. type AiPredictModelIndexController struct {
  25. controllers.BaseAuthController
  26. }
  27. // List
  28. // @Title 标的列表
  29. // @Description 标的列表
  30. // @Param PageSize query int true "每页数据条数"
  31. // @Param CurrentIndex query int true "当前页页码,从1开始"
  32. // @Param ClassifyId query int false "分类id"
  33. // @Param IndexId query int false "模型标的ID"
  34. // @Param Keyword query string false "搜索关键词"
  35. // @Success 200 {object} data_manage.ChartListResp
  36. // @router /index/list [get]
  37. func (this *AiPredictModelIndexController) List() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. br.Ret = 408
  48. return
  49. }
  50. pageSize, _ := this.GetInt("PageSize")
  51. currentIndex, _ := this.GetInt("CurrentIndex")
  52. classifyId, _ := this.GetInt("ClassifyId")
  53. indexId, _ := this.GetInt("IndexId")
  54. keyword := this.GetString("KeyWord")
  55. if keyword == "" {
  56. keyword = this.GetString("Keyword")
  57. }
  58. keyword = strings.TrimSpace(keyword)
  59. resp := new(aiPredictModel.AiPredictModelIndexPageListResp)
  60. // 分页
  61. var startSize int
  62. if pageSize <= 0 {
  63. pageSize = utils.PageSize20
  64. }
  65. if currentIndex <= 0 {
  66. currentIndex = 1
  67. }
  68. startSize = paging.StartIndex(currentIndex, pageSize)
  69. // 分类
  70. classifyIdName := make(map[int]string)
  71. {
  72. classifyOb := new(aiPredictModel.AiPredictModelClassify)
  73. list, e := classifyOb.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  74. if e != nil {
  75. br.Msg = "获取失败"
  76. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  77. return
  78. }
  79. for _, v := range list {
  80. classifyIdName[v.AiPredictModelClassifyId] = v.ClassifyName
  81. }
  82. }
  83. // 筛选条件
  84. highlightMap := make(map[int]string)
  85. indexOb := new(aiPredictModel.AiPredictModelIndex)
  86. var cond string
  87. var pars []interface{}
  88. {
  89. if indexId > 0 {
  90. cond += fmt.Sprintf(" AND %s = ?", indexOb.Cols().PrimaryId)
  91. pars = append(pars, indexId)
  92. }
  93. if classifyId > 0 {
  94. cond += fmt.Sprintf(" AND %s = ?", indexOb.Cols().ClassifyId)
  95. pars = append(pars, classifyId)
  96. }
  97. //if keyword != "" {
  98. // cond += fmt.Sprintf(" AND %s LIKE ?", indexOb.Cols().IndexName)
  99. // pars = append(pars, fmt.Sprint("%", keyword, "%"))
  100. //}
  101. // 有关键词从es中搜索
  102. if keyword != "" {
  103. _, list, e := elastic.SearchDataSourceIndex(utils.EsDataSourceIndexName, keyword, utils.DATA_SOURCE_AI_PREDICT_MODEL, 0, []int{}, []int{}, []string{}, startSize, pageSize)
  104. if e != nil {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = fmt.Sprintf("ES-搜索手工指标列表失败, %v", e)
  107. return
  108. }
  109. if len(list) == 0 {
  110. resp.List = make([]*aiPredictModel.AiPredictModelIndexItem, 0)
  111. br.Ret = 200
  112. br.Success = true
  113. br.Msg = "获取成功"
  114. br.Data = resp
  115. return
  116. }
  117. var ids []int
  118. for _, v := range list {
  119. ids = append(ids, v.PrimaryId)
  120. highlightMap[v.PrimaryId] = v.SearchText
  121. }
  122. cond += fmt.Sprintf(` AND %s IN (%s)`, indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  123. pars = append(pars, ids)
  124. }
  125. }
  126. // 获取列表
  127. total, e := indexOb.GetCountByCondition(cond, pars)
  128. if e != nil {
  129. br.Msg = "获取失败"
  130. br.ErrMsg = fmt.Sprintf("获取标的总数失败, %v", e)
  131. return
  132. }
  133. list, e := indexOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, pageSize)
  134. if e != nil {
  135. br.Msg = "获取失败"
  136. br.ErrMsg = fmt.Sprintf("获取分页列表失败, %v", e)
  137. return
  138. }
  139. pageList := make([]*aiPredictModel.AiPredictModelIndexItem, 0)
  140. for _, v := range list {
  141. t := v.Format2Item()
  142. t.ClassifyName = classifyIdName[v.ClassifyId]
  143. // 搜索高亮
  144. t.SearchText = v.IndexName
  145. s := highlightMap[v.AiPredictModelIndexId]
  146. if s != "" {
  147. t.SearchText = s
  148. }
  149. pageList = append(pageList, t)
  150. }
  151. page := paging.GetPaging(currentIndex, pageSize, total)
  152. resp.Paging = page
  153. resp.List = pageList
  154. br.Data = resp
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. }
  159. // Import
  160. // @Title 导入标的和数据
  161. // @Description 导入标的和数据
  162. // @Param IndexFile query file true "标的文件"
  163. // @Success 200 Ret=200 录入成功
  164. // @router /index/import [post]
  165. func (this *AiPredictModelIndexController) Import() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. if br.ErrMsg == "" {
  169. br.IsSendEmail = false
  170. }
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. sysUser := this.SysUser
  175. if sysUser == nil {
  176. br.Msg = "请登录"
  177. br.ErrMsg = "请登录,SysUser Is Empty"
  178. br.Ret = 408
  179. return
  180. }
  181. file, _, e := this.GetFile("IndexFile")
  182. if e != nil {
  183. br.Msg = "导入失败"
  184. br.ErrMsg = fmt.Sprintf("获取文件失败, %v", e)
  185. return
  186. }
  187. path := "./static/ai_predict_model_temp_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  188. defer func() {
  189. _ = file.Close()
  190. _ = os.Remove(path)
  191. }()
  192. if e = this.SaveToFile("IndexFile", path); e != nil {
  193. br.Msg = "导入失败"
  194. br.ErrMsg = fmt.Sprintf("保存文件失败, %v", e)
  195. return
  196. }
  197. xlFile, e := xlsx.OpenFile(path)
  198. if e != nil {
  199. br.Msg = "导入失败"
  200. br.ErrMsg = fmt.Sprintf("打开excel文件失败, %v", e)
  201. return
  202. }
  203. // 获取分类和用户,遍历时校验
  204. classifyNameId := make(map[string]int)
  205. adminNameId := make(map[string]int)
  206. {
  207. classifyOb := new(aiPredictModel.AiPredictModelClassify)
  208. classifyCond := fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().ParentId)
  209. classifyPars := make([]interface{}, 0)
  210. classifyPars = append(classifyPars, 0) // 只取一级分类(临时过渡方案,业务端只会加一级)
  211. classifies, e := classifyOb.GetItemsByCondition(classifyCond, classifyPars, []string{}, "")
  212. if e != nil {
  213. br.Msg = "导入失败"
  214. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  215. return
  216. }
  217. for _, v := range classifies {
  218. classifyNameId[v.ClassifyName] = v.AiPredictModelClassifyId
  219. }
  220. admins, e := system.GetSysAdminList(``, make([]interface{}, 0), []string{}, "")
  221. if e != nil {
  222. br.Msg = "导入失败"
  223. br.ErrMsg = fmt.Sprintf("获取用户失败, %v", e)
  224. return
  225. }
  226. for _, v := range admins {
  227. adminNameId[v.RealName] = v.AdminId
  228. }
  229. }
  230. // 遍历sheet页
  231. // 列表页:预测标的|分类|模型框架|创建人|预测日期|预测值|预测频度|方向准确率|绝对偏差
  232. type ImportDataColKey struct {
  233. IndexName string
  234. ColKey int
  235. DataDate time.Time
  236. }
  237. imports := make(map[string]*aiPredictModel.AiPredictModelImportData)
  238. importsData := make(map[string]map[time.Time]*aiPredictModel.AiPredictModelData)
  239. importsDailyData := make(map[string]map[time.Time]*aiPredictModel.AiPredictModelData)
  240. for sheetKey, sheet := range xlFile.Sheets {
  241. maxRow := sheet.MaxRow
  242. // 列表页
  243. if sheetKey == 0 {
  244. for i := 0; i < maxRow; i++ {
  245. // 忽略首行标题
  246. if i < 1 {
  247. continue
  248. }
  249. row := sheet.Row(i)
  250. cells := row.Cells
  251. if len(cells) < 9 {
  252. continue
  253. }
  254. // 标的名称
  255. indexName := strings.TrimSpace(cells[0].String())
  256. if indexName == "" {
  257. continue
  258. }
  259. if imports[indexName] == nil {
  260. imports[indexName] = new(aiPredictModel.AiPredictModelImportData)
  261. imports[indexName].Index = new(aiPredictModel.AiPredictModelIndex)
  262. imports[indexName].Data = make([]*aiPredictModel.AiPredictModelData, 0)
  263. }
  264. imports[indexName].Index.IndexName = indexName
  265. imports[indexName].Index.CreateTime = time.Now()
  266. imports[indexName].Index.ModifyTime = time.Now()
  267. // 分类
  268. classifyName := strings.TrimSpace(cells[1].String())
  269. if classifyNameId[classifyName] <= 0 {
  270. br.Msg = fmt.Sprintf("分类:%s不存在", classifyName)
  271. return
  272. }
  273. imports[indexName].Index.ClassifyId = classifyNameId[classifyName]
  274. // 创建人
  275. adminName := strings.TrimSpace(cells[3].String())
  276. if adminNameId[adminName] <= 0 {
  277. br.Msg = fmt.Sprintf("创建人:%s不存在", adminName)
  278. return
  279. }
  280. imports[indexName].Index.SysUserId = adminNameId[adminName]
  281. imports[indexName].Index.SysUserRealName = adminName
  282. // 其余信息
  283. imports[indexName].Index.ModelFramework = strings.TrimSpace(cells[2].String())
  284. strDate := strings.TrimSpace(cells[4].String())
  285. predictDate, _ := utils.GetExcelDate(strDate)
  286. imports[indexName].Index.PredictDate = predictDate
  287. strVal := strings.TrimSpace(cells[5].String())
  288. if strVal == "" {
  289. continue
  290. }
  291. predictVal, _ := strconv.ParseFloat(strVal, 64)
  292. imports[indexName].Index.PredictValue = predictVal
  293. imports[indexName].Index.PredictFrequency = strings.TrimSpace(cells[6].String())
  294. imports[indexName].Index.DirectionAccuracy = strings.TrimSpace(cells[7].String())
  295. imports[indexName].Index.AbsoluteDeviation = strings.TrimSpace(cells[8].String())
  296. }
  297. }
  298. // 月度数据页
  299. if sheetKey == 1 {
  300. // 每五列为一个指标的数据
  301. colKeys := make(map[int]*ImportDataColKey) // 每一列对应的指标名称以及对应的字段序号
  302. for i := 0; i < maxRow; i++ {
  303. // 首行为指标名称
  304. if i == 0 {
  305. nameCol := 0
  306. row := sheet.Row(i)
  307. for ck, cell := range row.Cells {
  308. nameCol += 1
  309. if nameCol > 5 {
  310. nameCol = 1
  311. }
  312. if nameCol == 1 {
  313. // nameCol=1时为指标/数据行则为日期
  314. indexName := strings.TrimSpace(cell.String())
  315. if indexName == "" {
  316. continue
  317. }
  318. importsData[indexName] = make(map[time.Time]*aiPredictModel.AiPredictModelData)
  319. colKeys[ck] = &ImportDataColKey{
  320. ColKey: 1,
  321. IndexName: indexName,
  322. }
  323. // 后面四列分别对应: 实际值|预测值|方向|偏差率, 这里直接加无须考虑是否会越界
  324. colKeys[ck+1] = &ImportDataColKey{
  325. ColKey: 2,
  326. IndexName: indexName,
  327. }
  328. colKeys[ck+2] = &ImportDataColKey{
  329. ColKey: 3,
  330. IndexName: indexName,
  331. }
  332. colKeys[ck+3] = &ImportDataColKey{
  333. ColKey: 4,
  334. IndexName: indexName,
  335. }
  336. colKeys[ck+4] = &ImportDataColKey{
  337. ColKey: 5,
  338. IndexName: indexName,
  339. }
  340. continue
  341. }
  342. }
  343. continue
  344. }
  345. // 第二行为标题,跳过
  346. if i == 1 {
  347. continue
  348. }
  349. // 剩余为数据行
  350. row := sheet.Row(i)
  351. for ck, cell := range row.Cells {
  352. if colKeys[ck] == nil {
  353. continue
  354. }
  355. if colKeys[ck].IndexName == "" {
  356. continue
  357. }
  358. switch colKeys[ck].ColKey {
  359. case 1:
  360. // 日期列
  361. strDate := strings.TrimSpace(cell.String())
  362. dataDate, _ := utils.GetExcelDate(strDate)
  363. if dataDate.IsZero() {
  364. continue
  365. }
  366. colKeys[ck].DataDate = dataDate
  367. colKeys[ck+1].DataDate = dataDate
  368. colKeys[ck+2].DataDate = dataDate
  369. colKeys[ck+3].DataDate = dataDate
  370. colKeys[ck+4].DataDate = dataDate
  371. importRow := imports[colKeys[ck].IndexName]
  372. if importRow == nil {
  373. continue
  374. }
  375. // 新增当前日期数据
  376. importsData[colKeys[ck].IndexName][dataDate] = new(aiPredictModel.AiPredictModelData)
  377. importsData[colKeys[ck].IndexName][dataDate].DataTime = dataDate
  378. importsData[colKeys[ck].IndexName][dataDate].CreateTime = time.Now()
  379. importsData[colKeys[ck].IndexName][dataDate].ModifyTime = time.Now()
  380. importsData[colKeys[ck].IndexName][dataDate].Source = aiPredictModel.ModelDataSourceMonthly
  381. case 2, 3:
  382. // 实际值和预测值, 可能为空
  383. dataDate := colKeys[ck].DataDate
  384. if importsData[colKeys[ck].IndexName][dataDate] == nil {
  385. continue
  386. }
  387. strVal := strings.TrimSpace(cell.String())
  388. if strVal == "" {
  389. continue
  390. }
  391. val, _ := strconv.ParseFloat(strVal, 64)
  392. if colKeys[ck].ColKey == 2 {
  393. importsData[colKeys[ck].IndexName][dataDate].Value.Valid = true
  394. importsData[colKeys[ck].IndexName][dataDate].Value.Float64 = val
  395. } else {
  396. importsData[colKeys[ck].IndexName][dataDate].PredictValue.Valid = true
  397. importsData[colKeys[ck].IndexName][dataDate].PredictValue.Float64 = val
  398. }
  399. case 4, 5:
  400. // 方向/偏差率
  401. dataDate := colKeys[ck].DataDate
  402. if importsData[colKeys[ck].IndexName][dataDate] == nil {
  403. continue
  404. }
  405. str := strings.TrimSpace(cell.String())
  406. if str == "" {
  407. continue
  408. }
  409. if colKeys[ck].ColKey == 4 {
  410. importsData[colKeys[ck].IndexName][dataDate].Direction = str
  411. } else {
  412. importsData[colKeys[ck].IndexName][dataDate].DeviationRate = str
  413. }
  414. default:
  415. continue
  416. }
  417. }
  418. }
  419. }
  420. // 日度数据页
  421. if sheetKey == 2 {
  422. // 每3列为一个指标的数据
  423. colKeys := make(map[int]*ImportDataColKey) // 每一列对应的指标名称以及对应的字段序号
  424. for i := 0; i < maxRow; i++ {
  425. // 首行为指标名称
  426. if i == 0 {
  427. nameCol := 0
  428. row := sheet.Row(i)
  429. for ck, cell := range row.Cells {
  430. nameCol += 1
  431. if nameCol > 3 {
  432. nameCol = 1
  433. }
  434. if nameCol == 1 {
  435. // nameCol=1时为指标/数据行则为日期
  436. indexName := strings.TrimSpace(cell.String())
  437. if indexName == "" {
  438. continue
  439. }
  440. importsDailyData[indexName] = make(map[time.Time]*aiPredictModel.AiPredictModelData)
  441. colKeys[ck] = &ImportDataColKey{
  442. ColKey: 1,
  443. IndexName: indexName,
  444. }
  445. // 后面两列分别对应: 实际值|预测值, 这里直接加无须考虑是否会越界
  446. colKeys[ck+1] = &ImportDataColKey{
  447. ColKey: 2,
  448. IndexName: indexName,
  449. }
  450. colKeys[ck+2] = &ImportDataColKey{
  451. ColKey: 3,
  452. IndexName: indexName,
  453. }
  454. continue
  455. }
  456. }
  457. continue
  458. }
  459. // 第二行为标题,遇到"预测值"单元格,需要取出其中的值作为预测图例名称
  460. if i == 1 {
  461. row := sheet.Row(i)
  462. for ck, cell := range row.Cells {
  463. if colKeys[ck] == nil {
  464. continue
  465. }
  466. if colKeys[ck].IndexName == "" {
  467. continue
  468. }
  469. if colKeys[ck].ColKey != 3 {
  470. continue
  471. }
  472. if imports[colKeys[ck].IndexName] != nil && imports[colKeys[ck].IndexName].Index != nil {
  473. var extraConfig aiPredictModel.AiPredictModelIndexExtraConfig
  474. extraConfig.DailyChart.PredictLegendName = strings.TrimSpace(cell.String())
  475. b, _ := json.Marshal(extraConfig)
  476. imports[colKeys[ck].IndexName].Index.ExtraConfig = string(b)
  477. }
  478. }
  479. continue
  480. }
  481. // 剩余为数据行
  482. row := sheet.Row(i)
  483. for ck, cell := range row.Cells {
  484. if colKeys[ck] == nil {
  485. continue
  486. }
  487. if colKeys[ck].IndexName == "" {
  488. continue
  489. }
  490. switch colKeys[ck].ColKey {
  491. case 1:
  492. // 日期列
  493. strDate := strings.TrimSpace(cell.String())
  494. dataDate, _ := utils.GetExcelDate(strDate)
  495. if dataDate.IsZero() {
  496. continue
  497. }
  498. colKeys[ck].DataDate = dataDate
  499. colKeys[ck+1].DataDate = dataDate
  500. colKeys[ck+2].DataDate = dataDate
  501. importRow := imports[colKeys[ck].IndexName]
  502. if importRow == nil {
  503. continue
  504. }
  505. // 新增当前日期数据
  506. importsDailyData[colKeys[ck].IndexName][dataDate] = new(aiPredictModel.AiPredictModelData)
  507. importsDailyData[colKeys[ck].IndexName][dataDate].DataTime = dataDate
  508. importsDailyData[colKeys[ck].IndexName][dataDate].CreateTime = time.Now()
  509. importsDailyData[colKeys[ck].IndexName][dataDate].ModifyTime = time.Now()
  510. importsDailyData[colKeys[ck].IndexName][dataDate].Source = aiPredictModel.ModelDataSourceDaily
  511. case 2, 3:
  512. // 实际值和预测值, 可能为空
  513. dataDate := colKeys[ck].DataDate
  514. if importsDailyData[colKeys[ck].IndexName][dataDate] == nil {
  515. continue
  516. }
  517. strVal := strings.TrimSpace(cell.String())
  518. if strVal == "" {
  519. continue
  520. }
  521. val, _ := strconv.ParseFloat(strVal, 64)
  522. if colKeys[ck].ColKey == 2 {
  523. importsDailyData[colKeys[ck].IndexName][dataDate].Value.Valid = true
  524. importsDailyData[colKeys[ck].IndexName][dataDate].Value.Float64 = val
  525. } else {
  526. importsDailyData[colKeys[ck].IndexName][dataDate].PredictValue.Valid = true
  527. importsDailyData[colKeys[ck].IndexName][dataDate].PredictValue.Float64 = val
  528. }
  529. default:
  530. continue
  531. }
  532. }
  533. }
  534. }
  535. }
  536. for indexName, v := range importsData {
  537. if imports[indexName] == nil {
  538. continue
  539. }
  540. for _, dateData := range v {
  541. imports[indexName].Data = append(imports[indexName].Data, dateData)
  542. }
  543. }
  544. for indexName, v := range importsDailyData {
  545. if imports[indexName] == nil {
  546. continue
  547. }
  548. for _, dateData := range v {
  549. imports[indexName].Data = append(imports[indexName].Data, dateData)
  550. }
  551. }
  552. importIndexes := make([]*aiPredictModel.AiPredictModelImportData, 0)
  553. for _, v := range imports {
  554. importIndexes = append(importIndexes, v)
  555. }
  556. // 导入指标
  557. if e = services.ImportAiPredictModelIndexAndData(importIndexes, sysUser.AdminId, sysUser.RealName); e != nil {
  558. br.Msg = "操作失败"
  559. br.ErrMsg = fmt.Sprintf("导入指标数据失败, %v", e)
  560. return
  561. }
  562. // 写入es
  563. go func() {
  564. for _, v := range importIndexes {
  565. indexItem := new(dataSourceModel.SearchDataSource)
  566. indexItem.PrimaryId = v.Index.AiPredictModelIndexId
  567. indexItem.IndexName = v.Index.IndexName
  568. indexItem.IndexCode = v.Index.IndexCode
  569. indexItem.ClassifyId = v.Index.ClassifyId
  570. indexItem.Source = utils.DATA_SOURCE_AI_PREDICT_MODEL
  571. indexItem.SourceName = "AI预测模型"
  572. indexItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.Index.CreateTime)
  573. indexItem.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, v.Index.ModifyTime)
  574. docId := fmt.Sprintf("%d-%d", indexItem.Source, indexItem.PrimaryId)
  575. if e := elastic.EsAddOrEditDataSourceIndex(utils.EsDataSourceIndexName, docId, indexItem); e != nil {
  576. utils.FileLog.Info("AI预测模型-写入es失败, %v", e)
  577. continue
  578. }
  579. }
  580. }()
  581. br.Ret = 200
  582. br.Success = true
  583. br.Msg = "操作成功"
  584. }
  585. // Detail
  586. // @Title 标的详情
  587. // @Description 标的详情
  588. // @Param IndexId query int true "标的ID"
  589. // @Success 200 {object} data_manage.ChartListResp
  590. // @router /index/detail [get]
  591. func (this *AiPredictModelIndexController) Detail() {
  592. br := new(models.BaseResponse).Init()
  593. defer func() {
  594. if br.ErrMsg == "" {
  595. br.IsSendEmail = false
  596. }
  597. this.Data["json"] = br
  598. this.ServeJSON()
  599. }()
  600. sysUser := this.SysUser
  601. if sysUser == nil {
  602. br.Msg = "请登录"
  603. br.ErrMsg = "请登录,SysUser Is Empty"
  604. br.Ret = 408
  605. return
  606. }
  607. indexId, _ := this.GetInt("IndexId")
  608. if indexId <= 0 {
  609. br.Msg = "参数有误"
  610. br.ErrMsg = fmt.Sprintf("参数有误, IndexId: %d", indexId)
  611. return
  612. }
  613. resp := new(aiPredictModel.AiPredictModelDetailResp)
  614. indexOb := new(aiPredictModel.AiPredictModelIndex)
  615. indexItem, e := indexOb.GetItemById(indexId)
  616. if e != nil {
  617. if utils.IsErrNoRow(e) {
  618. br.Msg = "标的已被删除,请刷新页面"
  619. return
  620. }
  621. br.Msg = "获取失败"
  622. br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
  623. return
  624. }
  625. // 获取标的数据
  626. monthData, dailyData := make([]*aiPredictModel.AiPredictModelData, 0), make([]*aiPredictModel.AiPredictModelData, 0)
  627. {
  628. tableData := make([]*aiPredictModel.AiPredictModelDataItem, 0)
  629. dataOb := new(aiPredictModel.AiPredictModelData)
  630. dataCond := fmt.Sprintf(` AND %s = ?`, dataOb.Cols().IndexCode)
  631. dataPars := make([]interface{}, 0)
  632. dataPars = append(dataPars, indexItem.IndexCode)
  633. list, e := dataOb.GetItemsByCondition(dataCond, dataPars, []string{}, fmt.Sprintf("%s DESC", dataOb.Cols().DataTime))
  634. if e != nil {
  635. br.Msg = "获取失败"
  636. br.ErrMsg = fmt.Sprintf("获取标的数据失败, %v", e)
  637. return
  638. }
  639. // tableData取月度数据,最多显示10条
  640. count, limit := 0, 10
  641. for _, v := range list {
  642. // 日度数据
  643. if v.Source == aiPredictModel.ModelDataSourceDaily {
  644. dailyData = append(dailyData, v)
  645. continue
  646. }
  647. // 月度数据
  648. if count < limit {
  649. tableData = append(tableData, v.Format2Item())
  650. count += 1
  651. }
  652. monthData = append(monthData, v)
  653. }
  654. resp.TableData = tableData
  655. }
  656. // 月度图表
  657. if len(monthData) > 0 {
  658. chartDetail, e := services.GetAiPredictChartDetailByData(indexItem, monthData, aiPredictModel.ModelDataSourceMonthly)
  659. if e != nil {
  660. br.Msg = "获取失败"
  661. br.ErrMsg = fmt.Sprintf("获取月度图表失败, %v", e)
  662. return
  663. }
  664. resp.ChartView = chartDetail
  665. }
  666. // 日度图表
  667. if len(dailyData) > 0 {
  668. dailyChartDetail, e := services.GetAiPredictChartDetailByData(indexItem, dailyData, aiPredictModel.ModelDataSourceDaily)
  669. if e != nil {
  670. br.Msg = "获取失败"
  671. br.ErrMsg = fmt.Sprintf("获取日度图表失败, %v", e)
  672. return
  673. }
  674. resp.DailyChartView = dailyChartDetail
  675. }
  676. br.Data = resp
  677. br.Ret = 200
  678. br.Success = true
  679. br.Msg = "获取成功"
  680. }
  681. // Save
  682. // @Title 保存标的
  683. // @Description 保存标的
  684. // @Param request body aiPredictModel.AiPredictModelIndexSaveReq true "type json string"
  685. // @Success 200 Ret=200 保存成功
  686. // @router /index/save [post]
  687. func (this *AiPredictModelIndexController) Save() {
  688. br := new(models.BaseResponse).Init()
  689. defer func() {
  690. if br.ErrMsg == "" {
  691. br.IsSendEmail = false
  692. }
  693. this.Data["json"] = br
  694. this.ServeJSON()
  695. }()
  696. sysUser := this.SysUser
  697. if sysUser == nil {
  698. br.Msg = "请登录"
  699. br.ErrMsg = "请登录,SysUser Is Empty"
  700. br.Ret = 408
  701. return
  702. }
  703. var req aiPredictModel.AiPredictModelIndexSaveReq
  704. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  705. br.Msg = "参数解析异常"
  706. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  707. return
  708. }
  709. if req.IndexId < 0 {
  710. br.Msg = "参数有误"
  711. br.ErrMsg = fmt.Sprintf("标的ID有误, IndexId: %d", req.IndexId)
  712. return
  713. }
  714. indexOb := new(aiPredictModel.AiPredictModelIndex)
  715. indexItem, e := indexOb.GetItemById(req.IndexId)
  716. if e != nil {
  717. if utils.IsErrNoRow(e) {
  718. br.Msg = "标的已被删除,请刷新页面"
  719. return
  720. }
  721. br.Msg = "操作失败"
  722. br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
  723. return
  724. }
  725. var extraConfig aiPredictModel.AiPredictModelIndexExtraConfig
  726. if indexItem.ExtraConfig != "" {
  727. if e = json.Unmarshal([]byte(indexItem.ExtraConfig), &extraConfig); e != nil {
  728. br.Msg = "操作失败"
  729. br.ErrMsg = fmt.Sprintf("标的配置解析失败, %v", e)
  730. return
  731. }
  732. }
  733. if req.MonthlyChart != nil {
  734. extraConfig.MonthlyChart.LeftMin = req.MonthlyChart.LeftMin
  735. extraConfig.MonthlyChart.LeftMax = req.MonthlyChart.LeftMax
  736. extraConfig.MonthlyChart.Unit = req.MonthlyChart.Unit
  737. }
  738. if req.DailyChart != nil {
  739. extraConfig.DailyChart.LeftMin = req.DailyChart.LeftMin
  740. extraConfig.DailyChart.LeftMax = req.DailyChart.LeftMax
  741. extraConfig.DailyChart.Unit = req.DailyChart.Unit
  742. }
  743. configByte, _ := json.Marshal(extraConfig)
  744. indexItem.ExtraConfig = string(configByte)
  745. indexItem.ModifyTime = time.Now()
  746. updateCols := []string{indexOb.Cols().ExtraConfig, indexOb.Cols().ModifyTime}
  747. if e = indexItem.Update(updateCols); e != nil {
  748. br.Msg = "操作失败"
  749. br.ErrMsg = fmt.Sprintf("保存标的失败, %v", e)
  750. return
  751. }
  752. br.Ret = 200
  753. br.Msg = "操作成功"
  754. br.Success = true
  755. }
  756. // DashboardSave
  757. // @Title 保存看板
  758. // @Description 保存看板
  759. // @Param request body aiPredictModel.AiPredictModelDashboardSaveReq true "type json string"
  760. // @Success 200 Ret=200 新增成功
  761. // @router /index/dashboard/save [post]
  762. func (this *AiPredictModelIndexController) DashboardSave() {
  763. br := new(models.BaseResponse).Init()
  764. defer func() {
  765. if br.ErrMsg == "" {
  766. br.IsSendEmail = false
  767. }
  768. this.Data["json"] = br
  769. this.ServeJSON()
  770. }()
  771. sysUser := this.SysUser
  772. if sysUser == nil {
  773. br.Msg = "请登录"
  774. br.ErrMsg = "请登录,SysUser Is Empty"
  775. br.Ret = 408
  776. return
  777. }
  778. var req aiPredictModel.AiPredictModelDashboardSaveReq
  779. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  780. br.Msg = "参数解析异常"
  781. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  782. return
  783. }
  784. if req.IndexId <= 0 {
  785. br.Msg = "参数有误"
  786. br.ErrMsg = fmt.Sprintf("参数有误, %d", req.IndexId)
  787. return
  788. }
  789. req.DashboardName = strings.TrimSpace(req.DashboardName)
  790. indexOb := new(aiPredictModel.AiPredictModelIndex)
  791. _, e := indexOb.GetItemById(req.IndexId)
  792. if e != nil {
  793. if utils.IsErrNoRow(e) {
  794. br.Msg = "标的已被删除,请刷新页面"
  795. return
  796. }
  797. br.Msg = "操作失败"
  798. br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
  799. return
  800. }
  801. // 获取看板
  802. var isUpdate bool
  803. var updateCols []string
  804. dashboardItem := new(aiPredictModel.AiPredictModelDashboard)
  805. if req.IndexId > 0 {
  806. cond := fmt.Sprintf(" AND %s = ?", dashboardItem.Cols().AiPredictModelIndexId)
  807. pars := make([]interface{}, 0)
  808. pars = append(pars, req.IndexId)
  809. item, e := dashboardItem.GetItemByCondition(cond, pars, "")
  810. if e != nil && !utils.IsErrNoRow(e) {
  811. br.Msg = "操作失败"
  812. br.ErrMsg = fmt.Sprintf("获取标的看板失败, %v", e)
  813. return
  814. }
  815. if item != nil && item.AiPredictModelIndexId > 0 {
  816. isUpdate = true
  817. dashboardItem = item
  818. dashboardItem.DashboardName = req.DashboardName
  819. dashboardItem.ModifyTime = time.Now()
  820. updateCols = append(updateCols, dashboardItem.Cols().DashboardName, dashboardItem.Cols().ModifyTime)
  821. }
  822. }
  823. if !isUpdate {
  824. dashboardItem.AiPredictModelIndexId = req.IndexId
  825. dashboardItem.DashboardName = req.DashboardName
  826. dashboardItem.SysUserId = sysUser.AdminId
  827. dashboardItem.SysUserRealName = sysUser.RealName
  828. dashboardItem.CreateTime = time.Now()
  829. dashboardItem.ModifyTime = time.Now()
  830. }
  831. // 详情
  832. dashboardDetails := make([]*aiPredictModel.AiPredictModelDashboardDetail, 0)
  833. for i, v := range req.List {
  834. t := &aiPredictModel.AiPredictModelDashboardDetail{
  835. Type: v.Type,
  836. UniqueCode: v.UniqueCode,
  837. Sort: i + 1,
  838. CreateTime: time.Now(),
  839. ModifyTime: time.Now(),
  840. }
  841. dashboardDetails = append(dashboardDetails, t)
  842. }
  843. // 保存
  844. if e := dashboardItem.SaveIndexDashboard(dashboardItem, dashboardDetails, isUpdate, updateCols); e != nil {
  845. br.Msg = "操作失败"
  846. br.ErrMsg = fmt.Sprintf("保存标的看板失败, %v", e)
  847. return
  848. }
  849. br.Ret = 200
  850. br.Success = true
  851. br.Msg = "操作成功"
  852. }
  853. // DashboardDetail
  854. // @Title 看板详情
  855. // @Description 看板详情
  856. // @Param IndexId query int true "标的ID"
  857. // @Success 200 {object} aiPredictModel.AiPredictModelDashboardDetailResp
  858. // @router /index/dashboard/detail [get]
  859. func (this *AiPredictModelIndexController) DashboardDetail() {
  860. br := new(models.BaseResponse).Init()
  861. defer func() {
  862. if br.ErrMsg == "" {
  863. br.IsSendEmail = false
  864. }
  865. this.Data["json"] = br
  866. this.ServeJSON()
  867. }()
  868. sysUser := this.SysUser
  869. if sysUser == nil {
  870. br.Msg = "请登录"
  871. br.ErrMsg = "请登录,SysUser Is Empty"
  872. br.Ret = 408
  873. return
  874. }
  875. indexId, _ := this.GetInt("IndexId")
  876. resp := new(aiPredictModel.AiPredictModelDashboardDetailResp)
  877. indexOb := new(aiPredictModel.AiPredictModelIndex)
  878. indexItem, e := indexOb.GetItemById(indexId)
  879. if e != nil {
  880. if utils.IsErrNoRow(e) {
  881. br.Msg = "标的已被删除,请刷新页面"
  882. return
  883. }
  884. br.Msg = "获取失败"
  885. br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
  886. return
  887. }
  888. resp.CreateUserId = indexItem.SysUserId
  889. resp.CreateUserRealName = indexItem.SysUserRealName
  890. // 获取标的看板
  891. dashboardOb := new(aiPredictModel.AiPredictModelDashboard)
  892. dashboardItem := new(aiPredictModel.AiPredictModelDashboardItem)
  893. {
  894. cond := fmt.Sprintf(" AND %s = ?", dashboardOb.Cols().AiPredictModelIndexId)
  895. pars := make([]interface{}, 0)
  896. pars = append(pars, indexId)
  897. item, e := dashboardOb.GetItemByCondition(cond, pars, "")
  898. if e != nil && !utils.IsErrNoRow(e) {
  899. br.Msg = "操作失败"
  900. br.ErrMsg = fmt.Sprintf("获取标的看板失败, %v", e)
  901. return
  902. }
  903. if item != nil {
  904. dashboardItem = item.Format2Item()
  905. }
  906. }
  907. // 获取看板详情
  908. dashboardDetails := make([]*aiPredictModel.AiPredictModelDashboardDetailItem, 0)
  909. if dashboardItem.DashboardId > 0 {
  910. detailOb := new(aiPredictModel.AiPredictModelDashboardDetail)
  911. cond := fmt.Sprintf(" AND %s = ?", detailOb.Cols().AiPredictModelDashboardId)
  912. pars := make([]interface{}, 0)
  913. pars = append(pars, dashboardItem.DashboardId)
  914. list, e := detailOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", detailOb.Cols().Sort))
  915. if e != nil {
  916. br.Msg = "获取失败"
  917. br.ErrMsg = fmt.Sprintf("获取看板详情失败, %v", e)
  918. return
  919. }
  920. for _, v := range list {
  921. dashboardDetails = append(dashboardDetails, v.Format2Item())
  922. }
  923. }
  924. resp.AiPredictModelDashboardItem = dashboardItem
  925. resp.List = dashboardDetails
  926. br.Data = resp
  927. br.Ret = 200
  928. br.Success = true
  929. br.Msg = "获取成功"
  930. }
  931. // SearchByEs
  932. // @Title 图表模糊搜索(从es获取)
  933. // @Description 图表模糊搜索(从es获取)
  934. // @Param Keyword query string true "图表名称"
  935. // @Param IsShowMe query bool true "是否只看我的,true、false"
  936. // @Param Source query int true "来源,14:日度预测,15:月度预测,默认0:全部14+15"
  937. // @Success 200 {object} data_manage.ChartInfo
  938. // @router /chart/search_by_es [get]
  939. func (this *AiPredictModelIndexController) SearchByEs() {
  940. br := new(models.BaseResponse).Init()
  941. defer func() {
  942. if br.ErrMsg == "" {
  943. br.IsSendEmail = false
  944. }
  945. this.Data["json"] = br
  946. this.ServeJSON()
  947. }()
  948. sysUser := this.SysUser
  949. if sysUser == nil {
  950. br.Msg = "请登录"
  951. br.ErrMsg = "请登录,SysUser Is Empty"
  952. br.Ret = 408
  953. return
  954. }
  955. pageSize, _ := this.GetInt("PageSize")
  956. currentIndex, _ := this.GetInt("CurrentIndex")
  957. var startSize int
  958. if pageSize <= 0 {
  959. pageSize = utils.PageSize20
  960. }
  961. if currentIndex <= 0 {
  962. currentIndex = 1
  963. }
  964. startSize = paging.StartIndex(currentIndex, pageSize)
  965. keyword := this.GetString("Keyword")
  966. keyword = strings.TrimSpace(keyword)
  967. if keyword == "" {
  968. keyword = this.GetString("KeyWord")
  969. keyword = strings.TrimSpace(keyword)
  970. }
  971. //只看我的
  972. isShowMe, _ := this.GetBool("IsShowMe")
  973. showSysId := 0
  974. if isShowMe {
  975. showSysId = sysUser.AdminId
  976. }
  977. source, _ := this.GetInt("Source")
  978. sourceList := make([]int, 0)
  979. if source <= 0 {
  980. sourceList = append(sourceList, utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY, utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY)
  981. } else {
  982. sourceList = append(sourceList, source)
  983. }
  984. var searchList []*data_manage.ChartInfoMore
  985. var total int64
  986. var err error
  987. // 获取当前账号的不可见指标(AI预测的指标为标的均可见)
  988. noPermissionChartIdList := make([]int, 0)
  989. //{
  990. // obj := data_manage.EdbInfoNoPermissionAdmin{}
  991. // confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  992. // if err != nil && !utils.IsErrNoRow(err) {
  993. // br.Msg = "获取失败"
  994. // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  995. // return
  996. // }
  997. // for _, v := range confList {
  998. // noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  999. // }
  1000. //}
  1001. if keyword != "" {
  1002. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1003. } else {
  1004. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1005. if err != nil && !utils.IsErrNoRow(err) {
  1006. br.Msg = "获取失败"
  1007. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. }
  1011. finalList := make([]*data_manage.ChartInfoMore, 0)
  1012. if len(searchList) > 0 {
  1013. chartInfoIds := ""
  1014. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1015. for _, v := range searchList {
  1016. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1017. }
  1018. if chartInfoIds != "" {
  1019. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1020. //判断是否需要展示英文标识
  1021. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1022. if e != nil {
  1023. br.Msg = "获取失败"
  1024. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1025. return
  1026. }
  1027. for _, v := range edbList {
  1028. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1029. }
  1030. }
  1031. for _, v := range searchList {
  1032. tmp := new(data_manage.ChartInfoMore)
  1033. tmp.ChartInfo = v.ChartInfo
  1034. // 图表数据权限
  1035. tmp.HaveOperaAuth = true
  1036. //判断是否需要展示英文标识
  1037. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  1038. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  1039. }
  1040. tmp.SearchText = v.SearchText
  1041. if tmp.SearchText == "" {
  1042. tmp.SearchText = v.ChartName
  1043. }
  1044. finalList = append(finalList, tmp)
  1045. }
  1046. }
  1047. //新增搜索词记录
  1048. {
  1049. searchKeyword := new(data_manage.SearchKeyword)
  1050. searchKeyword.KeyWord = keyword
  1051. searchKeyword.CreateTime = time.Now()
  1052. go data_manage.AddSearchKeyword(searchKeyword)
  1053. }
  1054. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1055. resp := data_manage.ChartInfoListByEsResp{
  1056. Paging: page,
  1057. List: finalList,
  1058. }
  1059. br.Ret = 200
  1060. br.Success = true
  1061. br.Msg = "获取成功"
  1062. br.Data = resp
  1063. }
  1064. // ScriptPathSave
  1065. // @Title 保存保存标的关联脚本路径标的
  1066. // @Description 保存标的关联脚本路径
  1067. // @Param request body request.AiPredictModelIndexSaveScriptPathReq true "type json string"
  1068. // @Success 200 Ret=200 保存成功
  1069. // @router /index/script_path/save [post]
  1070. func (this *AiPredictModelIndexController) ScriptPathSave() {
  1071. br := new(models.BaseResponse).Init()
  1072. defer func() {
  1073. if br.ErrMsg == "" {
  1074. br.IsSendEmail = false
  1075. }
  1076. this.Data["json"] = br
  1077. this.ServeJSON()
  1078. }()
  1079. sysUser := this.SysUser
  1080. if sysUser == nil {
  1081. br.Msg = "请登录"
  1082. br.ErrMsg = "请登录,SysUser Is Empty"
  1083. br.Ret = 408
  1084. return
  1085. }
  1086. var req request.AiPredictModelIndexSaveScriptPathReq
  1087. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1088. br.Msg = "参数解析异常"
  1089. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  1090. return
  1091. }
  1092. if req.IndexId < 0 {
  1093. br.Msg = "参数有误"
  1094. br.ErrMsg = fmt.Sprintf("标的ID有误, IndexId: %d", req.IndexId)
  1095. return
  1096. }
  1097. req.ScriptPath = strings.TrimSpace(req.ScriptPath)
  1098. if req.ScriptPath == "" {
  1099. br.Msg = "标的路径不能为空"
  1100. br.ErrMsg = fmt.Sprintf("标的路径有误, ScriptPath: %s", req.ScriptPath)
  1101. return
  1102. }
  1103. indexOb := new(aiPredictModel.AiPredictModelIndex)
  1104. indexItem, e := indexOb.GetItemById(req.IndexId)
  1105. if e != nil {
  1106. if utils.IsErrNoRow(e) {
  1107. br.Msg = "标的已被删除,请刷新页面"
  1108. return
  1109. }
  1110. br.Msg = "操作失败"
  1111. br.ErrMsg = fmt.Sprintf("获取标的失败, %v", e)
  1112. return
  1113. }
  1114. indexItem.ScriptPath = req.ScriptPath
  1115. indexItem.ModifyTime = time.Now()
  1116. updateCols := []string{indexOb.Cols().ScriptPath, indexOb.Cols().ModifyTime}
  1117. if e = indexItem.Update(updateCols); e != nil {
  1118. br.Msg = "操作失败"
  1119. br.ErrMsg = fmt.Sprintf("保存标的失败, %v", e)
  1120. return
  1121. }
  1122. br.Ret = 200
  1123. br.Msg = "操作成功"
  1124. br.Success = true
  1125. }