predict_edb_info.go 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_manage/request"
  8. "eta/eta_api/models/data_manage/response"
  9. "eta/eta_api/services/data"
  10. "eta/eta_api/services/elastic"
  11. "eta/eta_api/utils"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "github.com/shopspring/decimal"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // PredictEdbInfoController 预测指标
  20. type PredictEdbInfoController struct {
  21. controllers.BaseAuthController
  22. }
  23. // EdbChartList
  24. // @Title 预测指标列表接口
  25. // @Description 预测指标列表接口
  26. // @Param PageSize query int true "每页数据条数"
  27. // @Param CurrentIndex query int true "当前页页码,从1开始"
  28. // @Param ClassifyId query int true "分类id"
  29. // @Param AdminId query int false "创建人id"
  30. // @Param IsOnlyMe query bool false "是否只看我的"
  31. // @Success 200 {object} response.PredictEdbInfoListResp
  32. // @router /predict_edb_info/chart/list [get]
  33. func (this *PredictEdbInfoController) EdbChartList() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. br.Ret = 408
  44. return
  45. }
  46. classifyId, _ := this.GetInt("ClassifyId")
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. adminId, _ := this.GetInt("AdminId")
  50. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  51. var total int
  52. page := paging.GetPaging(currentIndex, pageSize, total)
  53. var startSize int
  54. if pageSize <= 0 {
  55. pageSize = utils.PageSize20
  56. }
  57. if currentIndex <= 0 {
  58. currentIndex = 1
  59. }
  60. startSize = paging.StartIndex(currentIndex, pageSize)
  61. var condition string
  62. var pars []interface{}
  63. // 预测指标
  64. condition += ` AND edb_info_type = ? `
  65. pars = append(pars, 1)
  66. // 筛选分类
  67. if classifyId > 0 {
  68. classifyIds, err := data_manage.GetEdbClassify(classifyId)
  69. if err != nil && err.Error() != utils.ErrNoRow() {
  70. br.Msg = "获取分类信息失败"
  71. br.ErrMsg = "获取分类信息失败,GetEdbClassifyById,Err:" + err.Error()
  72. return
  73. }
  74. condition += " AND classify_id IN(" + classifyIds + ") "
  75. }
  76. if adminId > 0 {
  77. condition += " AND sys_user_id = ? "
  78. pars = append(pars, adminId)
  79. }
  80. if isOnlyMe {
  81. condition += " AND sys_user_id = ? "
  82. pars = append(pars, sysUser.AdminId)
  83. }
  84. // 获取当前账号的不可见指标
  85. obj := data_manage.EdbInfoNoPermissionAdmin{}
  86. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  87. if err != nil && err.Error() != utils.ErrNoRow() {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  90. return
  91. }
  92. noPermissionEdbInfoIdList := make([]int, 0)
  93. for _, v := range confList {
  94. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  95. }
  96. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  97. if noPermissionEdbInfoIdNum > 0 {
  98. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  99. pars = append(pars, noPermissionEdbInfoIdList)
  100. }
  101. //获取指标信息
  102. dataCount, list, err := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  103. if err != nil && err.Error() != utils.ErrNoRow() {
  104. br.Success = true
  105. br.Msg = "获取预测指标列表失败"
  106. br.ErrMsg = "获取预测指标列表失败,Err:" + err.Error()
  107. return
  108. }
  109. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  110. list = make([]*data_manage.EdbInfoList, 0)
  111. } else {
  112. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  113. }
  114. resp := response.PredictEdbInfoListResp{
  115. Paging: page,
  116. List: list,
  117. }
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "获取成功"
  121. br.Data = resp
  122. }
  123. // List
  124. // @Title 指标数据列表接口
  125. // @Description 指标数据列表接口
  126. // @Param PageSize query int true "每页数据条数"
  127. // @Param CurrentIndex query int true "当前页页码,从1开始"
  128. // @Param EdbInfoId query int true "指标id"
  129. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  130. // @Success 200 {object} data_manage.EdbInfoListResp
  131. // @router /predict_edb_info/list [get]
  132. func (this *PredictEdbInfoController) List() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. edbInfoId, _ := this.GetInt("EdbInfoId")
  139. keyWord := this.GetString("KeyWord")
  140. pageSize, _ := this.GetInt("PageSize")
  141. currentIndex, _ := this.GetInt("CurrentIndex")
  142. var total int
  143. page := paging.GetPaging(currentIndex, pageSize, total)
  144. var startSize int
  145. if pageSize <= 0 {
  146. pageSize = utils.PageSize20
  147. }
  148. if currentIndex <= 0 {
  149. currentIndex = 1
  150. }
  151. startSize = paging.StartIndex(currentIndex, pageSize)
  152. var condition string
  153. var pars []interface{}
  154. // 指标类型,0:普通指标,1:预测指标
  155. condition += " AND edb_info_type=? "
  156. pars = append(pars, 1)
  157. if edbInfoId > 0 {
  158. condition += " AND edb_info_id=? "
  159. pars = append(pars, edbInfoId)
  160. }
  161. if keyWord != "" {
  162. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  163. //pars = append(pars, keyWord)
  164. //pars = append(pars, keyWord)
  165. }
  166. resp := data_manage.EdbInfoListResp{}
  167. if condition == "" {
  168. item := new(data_manage.EdbInfoList)
  169. resp.Paging = page
  170. resp.Item = item
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. return
  175. }
  176. //获取指标信息
  177. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  178. if err != nil && err.Error() != utils.ErrNoRow() {
  179. br.Success = true
  180. br.Msg = "获取指标信息失败"
  181. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  182. return
  183. }
  184. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  185. item := new(data_manage.EdbInfoList)
  186. resp.Paging = page
  187. resp.Item = item
  188. br.Ret = 200
  189. br.Success = true
  190. br.Msg = "获取成功"
  191. return
  192. }
  193. //获取英文频度
  194. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  195. //查询目录
  196. resultList, _ := data_manage.GetClassifyAllByClassifyId(edbInfoItem.ClassifyId)
  197. // 未来的指标预测数据
  198. predictDataList := make([]*data_manage.EdbData, 0)
  199. var existCondition string
  200. var existPars []interface{}
  201. existCondition += " AND edb_info_id=? "
  202. existPars = append(existPars, edbInfoId)
  203. //查询出所有的关联指标
  204. sourceEdbInfoCalculateMappingList, err := data_manage.GetEdbInfoCalculateListByCondition(existCondition, existPars)
  205. if err != nil {
  206. br.Msg = "获取失败"
  207. br.ErrMsg = "获取预测指标关联信息失败,Err:" + err.Error()
  208. return
  209. }
  210. if len(sourceEdbInfoCalculateMappingList) <= 0 {
  211. br.Msg = "获取失败"
  212. br.ErrMsg = "查找预测指标关联信息失败"
  213. return
  214. }
  215. if edbInfoItem.EdbType == 1 { //普通的预测指标
  216. // 查找该预测指标配置
  217. predictEdbConfList, err := data_manage.GetPredictEdbConfListById(edbInfoId)
  218. if err != nil && err.Error() != utils.ErrNoRow() {
  219. br.Msg = "获取失败"
  220. br.ErrMsg = "获取预测指标配置信息失败,Err:" + err.Error()
  221. return
  222. }
  223. if len(predictEdbConfList) == 0 {
  224. br.Msg = "找不到该预测指标配置"
  225. br.ErrMsg = "找不到该预测指标配置"
  226. return
  227. }
  228. predictEdbConf := predictEdbConfList[0]
  229. //预测数据的配置
  230. edbInfoItem.RuleType = predictEdbConf.RuleType
  231. edbInfoItem.FixedValue = predictEdbConf.FixedValue
  232. // 来源指标
  233. //sourceEdbInfoId := sourceEdbInfoCalculateMappingList[0].FromEdbInfoId
  234. sourceEdbInfoId := predictEdbConf.SourceEdbInfoId
  235. sourceEdbInfoItem, err := data_manage.GetEdbInfoById(sourceEdbInfoId)
  236. if err != nil {
  237. br.Msg = "获取来源指标信息失败"
  238. br.ErrMsg = "获取来源指标信息失败"
  239. if err.Error() != utils.ErrNoRow() {
  240. br.ErrMsg = "获取来源指标信息失败,Err:" + err.Error()
  241. }
  242. br.Success = true
  243. return
  244. }
  245. //获取指标数据(实际已生成)
  246. {
  247. var dataCondition string
  248. var dataPars []interface{}
  249. dataCondition += ` AND edb_info_id=? `
  250. dataPars = append(dataPars, sourceEdbInfoItem.EdbInfoId)
  251. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, sourceEdbInfoItem.Source)
  252. if err != nil && err.Error() != utils.ErrNoRow() {
  253. br.Msg = "获取指标信息失败"
  254. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  255. return
  256. }
  257. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  258. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, sourceEdbInfoItem.Source, pageSize, startSize)
  259. if err != nil {
  260. br.Msg = "获取指标信息失败"
  261. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  262. return
  263. }
  264. edbInfoItem.DataList = dataList
  265. }
  266. // 第一页才需要 获取预测指标未来的数据
  267. if currentIndex == 1 {
  268. allDataList, err := data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, "", "")
  269. if err != nil {
  270. br.Msg = "获取失败"
  271. br.Msg = "获取失败,Err:" + err.Error()
  272. return
  273. }
  274. predictEdbConfDataList := make([]data_manage.PredictEdbConfAndData, 0)
  275. for _, v := range predictEdbConfList {
  276. predictEdbConfDataList = append(predictEdbConfDataList, data_manage.PredictEdbConfAndData{
  277. ConfigId: v.ConfigId,
  278. PredictEdbInfoId: v.PredictEdbInfoId,
  279. SourceEdbInfoId: v.SourceEdbInfoId,
  280. RuleType: v.RuleType,
  281. FixedValue: v.FixedValue,
  282. Value: v.Value,
  283. EndDate: v.EndDate,
  284. ModifyTime: v.ModifyTime,
  285. CreateTime: v.CreateTime,
  286. DataList: make([]*data_manage.EdbDataList, 0),
  287. })
  288. }
  289. tmpPredictDataList, _, _, err, _ := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfDataList, sourceEdbInfoItem.LatestDate, sourceEdbInfoItem.LatestDate, edbInfoItem.EndDate, sourceEdbInfoItem.Frequency, edbInfoItem.DataDateType, allDataList)
  290. if err != nil {
  291. br.Msg = "获取预测指标数据失败"
  292. br.ErrMsg = "获取预测指标数据失败" + err.Error()
  293. return
  294. }
  295. lenTmpPredictDataList := len(tmpPredictDataList)
  296. if lenTmpPredictDataList > 0 {
  297. for i := lenTmpPredictDataList - 1; i >= 0; i-- {
  298. v := tmpPredictDataList[i]
  299. predictDataList = append(predictDataList, &data_manage.EdbData{
  300. EdbDataId: v.EdbDataId,
  301. EdbInfoId: v.EdbInfoId,
  302. DataTime: v.DataTime,
  303. Value: v.Value,
  304. })
  305. }
  306. }
  307. }
  308. } else {
  309. //获取指标数据(实际已生成)
  310. {
  311. var dataCondition string
  312. var dataPars []interface{}
  313. dataCondition += ` AND edb_info_id=? AND data_time <= ? `
  314. dataPars = append(dataPars, edbInfoItem.EdbInfoId, edbInfoItem.LatestDate)
  315. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  316. if err != nil && err.Error() != utils.ErrNoRow() {
  317. br.Msg = "获取指标信息失败"
  318. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  319. return
  320. }
  321. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  322. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  323. if err != nil {
  324. br.Msg = "获取指标信息失败"
  325. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  326. return
  327. }
  328. edbInfoItem.DataList = dataList
  329. }
  330. // 第一页才需要 获取预测指标未来的数据
  331. if currentIndex == 1 {
  332. var dataCondition string
  333. var dataPars []interface{}
  334. dataCondition += ` AND edb_info_id=? AND data_time > ? `
  335. dataPars = append(dataPars, edbInfoItem.EdbInfoId, edbInfoItem.LatestDate)
  336. predictDataList, err = data_manage.GetAllEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source)
  337. if err != nil {
  338. br.Msg = "获取指标信息失败"
  339. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  340. return
  341. }
  342. if err != nil {
  343. br.Msg = "获取预测指标数据失败"
  344. br.ErrMsg = "获取预测指标数据失败" + err.Error()
  345. return
  346. }
  347. }
  348. }
  349. // 如果预测数据没有,那么返回空数组
  350. if predictDataList == nil {
  351. predictDataList = make([]*data_manage.EdbData, 0)
  352. }
  353. edbInfoItem.PredictDataList = predictDataList
  354. // 如果实际数据没有,那么返回空数组
  355. if edbInfoItem.DataList == nil {
  356. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  357. }
  358. resp.Paging = page
  359. resp.Item = edbInfoItem
  360. resp.ClassifyList = resultList
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // Add
  367. // @Title 新增指标接口
  368. // @Description 新增指标接口
  369. // @Param request body request.AddPredictEdbInfoReq true "type json string"
  370. // @Success 200 {object} response.AddEdbInfoResp
  371. // @router /predict_edb_info/add [post]
  372. func (this *PredictEdbInfoController) Add() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. this.Data["json"] = br
  376. this.ServeJSON()
  377. }()
  378. sysUser := this.SysUser
  379. if sysUser == nil {
  380. br.Msg = "请登录"
  381. br.ErrMsg = "请登录,SysUser Is Empty"
  382. br.Ret = 408
  383. return
  384. }
  385. deleteCache := true
  386. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  387. defer func() {
  388. if deleteCache {
  389. utils.Rc.Delete(cacheKey)
  390. }
  391. }()
  392. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  393. deleteCache = false
  394. br.Msg = "系统处理中,请稍后重试!"
  395. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  396. return
  397. }
  398. var req request.AddPredictEdbInfoReq
  399. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  400. if err != nil {
  401. br.Msg = "参数解析异常!"
  402. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  403. return
  404. }
  405. sourceEdbInfoId := req.SourceEdbInfoId
  406. if sourceEdbInfoId <= 0 {
  407. br.Msg = "请选择来源指标"
  408. br.IsSendEmail = false
  409. return
  410. }
  411. if req.EdbName == "" {
  412. br.Msg = "指标名称不能为空"
  413. br.IsSendEmail = false
  414. return
  415. }
  416. if req.ClassifyId <= 0 {
  417. br.Msg = "请选择分类"
  418. br.IsSendEmail = false
  419. return
  420. }
  421. if len(req.RuleList) <= 0 {
  422. br.Msg = "请填写预测规则"
  423. br.IsSendEmail = false
  424. return
  425. }
  426. // 根据截止日期重新排序
  427. ruleList := make([]request.RuleConfig, 0)
  428. {
  429. ruleMap := make(map[string]request.RuleConfig)
  430. dateIntList := make([]int64, 0)
  431. for _, v := range req.RuleList {
  432. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  433. if err != nil {
  434. br.Msg = "配置项中时间异常,请重新选择"
  435. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  436. br.IsSendEmail = false
  437. return
  438. }
  439. dateIntList = append(dateIntList, confEndDate.Unix())
  440. ruleMap[v.EndDate] = v
  441. }
  442. sort.Slice(dateIntList, func(i, j int) bool {
  443. return dateIntList[i] < dateIntList[j]
  444. })
  445. for _, dateInt := range dateIntList {
  446. currDateTime := time.Unix(dateInt, 0)
  447. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  448. if !ok {
  449. br.Msg = "配置项中时间异常,请重新选择"
  450. br.ErrMsg = "配置项中时间异常,请重新选择"
  451. br.IsSendEmail = false
  452. return
  453. }
  454. ruleList = append(ruleList, item)
  455. }
  456. }
  457. req.RuleList = ruleList
  458. //传入操作人
  459. req.AdminId = sysUser.AdminId
  460. req.AdminName = sysUser.RealName
  461. // 添加计算指标
  462. reqJson, err := json.Marshal(req)
  463. if err != nil {
  464. br.Msg = "参数解析异常!"
  465. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  466. return
  467. }
  468. respItem, err := data.SaveBasePredictEdbData(string(reqJson))
  469. if err != nil {
  470. br.Msg = "获取失败"
  471. br.ErrMsg = "获取失败,Err:" + err.Error()
  472. return
  473. }
  474. if respItem.Ret != 200 {
  475. br.Msg = respItem.Msg
  476. br.ErrMsg = respItem.ErrMsg
  477. return
  478. }
  479. resp := respItem.Data
  480. //添加es
  481. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  482. br.Ret = 200
  483. br.Success = true
  484. br.Msg = "保存成功"
  485. br.Data = resp
  486. br.IsAddLog = true
  487. }
  488. // ChartImageSet
  489. // @Title 设置指标的图表图片
  490. // @Description 设置指标的图表图片接口
  491. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  492. // @Success Ret=200 保存成功
  493. // @router /predict_edb_info/image/set [post]
  494. func (this *PredictEdbInfoController) ChartImageSet() {
  495. br := new(models.BaseResponse).Init()
  496. defer func() {
  497. this.Data["json"] = br
  498. this.ServeJSON()
  499. }()
  500. sysUser := this.SysUser
  501. if sysUser == nil {
  502. br.Msg = "请登录"
  503. br.ErrMsg = "请登录,SysUser Is Empty"
  504. br.Ret = 408
  505. return
  506. }
  507. var req data_manage.SetEdbInfoImageReq
  508. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  509. if err != nil {
  510. br.Msg = "参数解析异常!"
  511. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  512. return
  513. }
  514. if req.EdbInfoId > 0 && req.ImageUrl != "" {
  515. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  516. if err != nil {
  517. br.Msg = "保存失败"
  518. br.ErrMsg = "保存失败,Err:" + err.Error()
  519. if err.Error() == utils.ErrNoRow() {
  520. br.Msg = "找不到该指标"
  521. br.ErrMsg = "找不到该指标"
  522. br.IsSendEmail = false
  523. }
  524. return
  525. }
  526. edbInfo.ChartImage = req.ImageUrl
  527. err = edbInfo.Update([]string{"ChartImage"})
  528. if err != nil {
  529. br.Msg = "保存失败"
  530. br.ErrMsg = "保存失败,Err:" + err.Error()
  531. return
  532. }
  533. //修改es数据
  534. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  535. }
  536. br.Ret = 200
  537. br.Success = true
  538. br.Msg = "保存成功"
  539. }
  540. // Edit
  541. // @Title 编辑指标接口
  542. // @Description 编辑指标接口
  543. // @Success 200 {object} request.EditEdbInfoReq
  544. // @router /predict_edb_info/edit [post]
  545. func (this *PredictEdbInfoController) Edit() {
  546. br := new(models.BaseResponse).Init()
  547. defer func() {
  548. this.Data["json"] = br
  549. this.ServeJSON()
  550. }()
  551. sysUser := this.SysUser
  552. if sysUser == nil {
  553. br.Msg = "请登录"
  554. br.ErrMsg = "请登录,SysUser Is Empty"
  555. br.Ret = 408
  556. return
  557. }
  558. var req request.AddPredictEdbInfoReq
  559. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  560. if err != nil {
  561. br.Msg = "参数解析异常!"
  562. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  563. return
  564. }
  565. edbInfoId := req.EdbInfoId
  566. if edbInfoId <= 0 {
  567. br.Msg = "请选择预测指标"
  568. br.IsSendEmail = false
  569. return
  570. }
  571. if req.EdbName == "" {
  572. br.Msg = "指标名称不能为空"
  573. br.IsSendEmail = false
  574. return
  575. }
  576. if req.ClassifyId <= 0 {
  577. br.Msg = "请选择分类"
  578. br.IsSendEmail = false
  579. return
  580. }
  581. if len(req.RuleList) <= 0 {
  582. br.Msg = "请填写预测规则"
  583. br.IsSendEmail = false
  584. return
  585. }
  586. // 根据截止日期重新排序
  587. ruleList := make([]request.RuleConfig, 0)
  588. {
  589. ruleMap := make(map[string]request.RuleConfig)
  590. dateIntList := make([]int64, 0)
  591. for _, v := range req.RuleList {
  592. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  593. if err != nil {
  594. br.Msg = "配置项中时间异常,请重新选择"
  595. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  596. br.IsSendEmail = false
  597. return
  598. }
  599. dateIntList = append(dateIntList, confEndDate.Unix())
  600. ruleMap[v.EndDate] = v
  601. }
  602. sort.Slice(dateIntList, func(i, j int) bool {
  603. return dateIntList[i] < dateIntList[j]
  604. })
  605. for _, dateInt := range dateIntList {
  606. currDateTime := time.Unix(dateInt, 0)
  607. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  608. if !ok {
  609. br.Msg = "配置项中时间异常,请重新选择"
  610. br.ErrMsg = "配置项中时间异常,请重新选择"
  611. br.IsSendEmail = false
  612. return
  613. }
  614. ruleList = append(ruleList, item)
  615. }
  616. }
  617. req.RuleList = ruleList
  618. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  619. if err != nil {
  620. br.Msg = "修改失败"
  621. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  622. return
  623. }
  624. // 编辑权限校验
  625. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  626. if !button.OpButton {
  627. br.Msg = "无权限操作"
  628. br.IsSendEmail = false
  629. return
  630. }
  631. //传入操作人
  632. req.AdminId = sysUser.AdminId
  633. req.AdminName = sysUser.RealName
  634. // 添加计算指标
  635. reqJson, err := json.Marshal(req)
  636. if err != nil {
  637. br.Msg = "参数解析异常!"
  638. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  639. return
  640. }
  641. respItem, err := data.SaveBasePredictEdbData(string(reqJson))
  642. if err != nil {
  643. br.Msg = "获取失败"
  644. br.ErrMsg = "获取失败,Err:" + err.Error()
  645. return
  646. }
  647. if respItem.Ret != 200 {
  648. br.Msg = respItem.Msg
  649. br.ErrMsg = respItem.ErrMsg
  650. return
  651. }
  652. resp := respItem.Data
  653. //修改es
  654. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  655. // 刷新关联指标
  656. go data.EdbInfoRefreshAllFromBaseV2(resp.EdbInfoId, true)
  657. br.Ret = 200
  658. br.Success = true
  659. br.Msg = "修改成功"
  660. br.IsAddLog = true
  661. }
  662. // Refresh
  663. // @Title 指标刷新接口
  664. // @Description 指标刷新接口
  665. // @Param EdbInfoId query int true "指标id"
  666. // @Success Ret=200 刷新成功
  667. // @router /predict_edb_info/refresh [get]
  668. func (this *PredictEdbInfoController) Refresh() {
  669. br := new(models.BaseResponse).Init()
  670. defer func() {
  671. this.Data["json"] = br
  672. this.ServeJSON()
  673. }()
  674. sysUser := this.SysUser
  675. if sysUser == nil {
  676. br.Msg = "请登录"
  677. br.ErrMsg = "请登录,SysUser Is Empty"
  678. br.Ret = 408
  679. return
  680. }
  681. edbInfoId, _ := this.GetInt("EdbInfoId")
  682. if edbInfoId <= 0 {
  683. br.Msg = "参数错误"
  684. br.ErrMsg = "参数错误"
  685. return
  686. }
  687. _, isAsync, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, false)
  688. if errMsg != `` {
  689. br.Msg = errMsg
  690. br.ErrMsg = errMsg
  691. if err != nil {
  692. br.ErrMsg = err.Error()
  693. } else {
  694. br.IsSendEmail = false
  695. }
  696. return
  697. }
  698. br.Ret = 200
  699. br.Success = true
  700. br.Msg = "刷新成功"
  701. if isAsync {
  702. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  703. }
  704. }
  705. // Move
  706. // @Title 移动指标接口
  707. // @Description 移动指标接口
  708. // @Success 200 {object} data_manage.MoveEdbInfoReq
  709. // @router /predict_edb_info/move [post]
  710. func (this *PredictEdbInfoController) Move() {
  711. br := new(models.BaseResponse).Init()
  712. defer func() {
  713. this.Data["json"] = br
  714. this.ServeJSON()
  715. }()
  716. sysUser := this.SysUser
  717. if sysUser == nil {
  718. br.Msg = "请登录"
  719. br.ErrMsg = "请登录,SysUser Is Empty"
  720. br.Ret = 408
  721. return
  722. }
  723. var req data_manage.MoveEdbInfoReq
  724. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  725. if err != nil {
  726. br.Msg = "参数解析异常!"
  727. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  728. return
  729. }
  730. if req.EdbInfoId <= 0 {
  731. br.Msg = "参数错误"
  732. br.ErrMsg = "指标id小于等于0"
  733. return
  734. }
  735. if req.ClassifyId <= 0 {
  736. br.Msg = "请选择分类"
  737. return
  738. }
  739. // 移动预测指标
  740. err, errMsg := data.MovePredictEdbInfo(req.EdbInfoId, req.ClassifyId, req.PrevEdbInfoId, req.NextEdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  741. if errMsg != `` {
  742. br.Msg = errMsg
  743. br.ErrMsg = errMsg
  744. if err != nil {
  745. br.ErrMsg = errMsg + ";Err:" + err.Error()
  746. } else {
  747. br.IsSendEmail = false
  748. }
  749. return
  750. }
  751. br.Ret = 200
  752. br.Success = true
  753. br.Msg = "移动成功"
  754. }
  755. // Detail
  756. // @Title 获取指标详情
  757. // @Description 获取指标详情接口
  758. // @Param EdbInfoId query int true "指标id"
  759. // @Success 200 {object} response.PredictEdbInfo
  760. // @router /predict_edb_info/detail [get]
  761. func (this *PredictEdbInfoController) Detail() {
  762. br := new(models.BaseResponse).Init()
  763. defer func() {
  764. this.Data["json"] = br
  765. this.ServeJSON()
  766. }()
  767. sysUser := this.SysUser
  768. if sysUser == nil {
  769. br.Msg = "请登录"
  770. br.ErrMsg = "请登录,SysUser Is Empty"
  771. br.Ret = 408
  772. return
  773. }
  774. edbInfoId, _ := this.GetInt("EdbInfoId")
  775. if edbInfoId <= 0 {
  776. br.Msg = "参数错误"
  777. br.ErrMsg = "参数错误"
  778. return
  779. }
  780. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  781. if err != nil {
  782. br.Msg = "获取失败"
  783. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  784. return
  785. }
  786. var ruleType int
  787. var fixedValue float64
  788. calculateList := make([]*data_manage.EdbInfoCalculateDetail, 0)
  789. predictEdbConfList := make([]data_manage.PredictEdbConfDetail, 0)
  790. calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
  791. if err != nil {
  792. br.Msg = "获取失败"
  793. br.ErrMsg = "获取失败,Err:" + err.Error()
  794. return
  795. }
  796. if edbInfo.EdbType == 1 {
  797. // 获取所有的指标预测规则配置
  798. tmpPredictEdbConfList, err := data_manage.GetPredictEdbConfListById(edbInfoId)
  799. if err != nil && err.Error() != utils.ErrNoRow() {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取预测指标配置信息失败,Err:" + err.Error()
  802. return
  803. }
  804. for _, v := range tmpPredictEdbConfList {
  805. var tmpPredictEdbConfCalculateMappingDetail []*data_manage.PredictEdbConfCalculateMappingDetail
  806. if v.RuleType == 9 || v.RuleType == 14 {
  807. tmpPredictEdbConfCalculateMappingDetail, err = data_manage.GetPredictEdbConfCalculateMappingDetailListByConfigId(v.PredictEdbInfoId, v.ConfigId)
  808. if err != nil && err.Error() != utils.ErrNoRow() {
  809. br.Msg = "获取失败"
  810. br.ErrMsg = "获取预测指标配置与关联指标信息失败,Err:" + err.Error()
  811. return
  812. }
  813. }
  814. if len(tmpPredictEdbConfCalculateMappingDetail) <= 0 {
  815. tmpPredictEdbConfCalculateMappingDetail = make([]*data_manage.PredictEdbConfCalculateMappingDetail, 0)
  816. }
  817. tmp := data_manage.PredictEdbConfDetail{
  818. ConfigId: v.ConfigId,
  819. PredictEdbInfoId: v.PredictEdbInfoId,
  820. SourceEdbInfoId: v.SourceEdbInfoId,
  821. RuleType: v.RuleType,
  822. FixedValue: v.FixedValue,
  823. Value: v.Value,
  824. EndDate: v.EndDate,
  825. ModifyTime: v.ModifyTime,
  826. CreateTime: v.CreateTime,
  827. CalculateList: tmpPredictEdbConfCalculateMappingDetail,
  828. }
  829. predictEdbConfList = append(predictEdbConfList, tmp)
  830. }
  831. //calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
  832. //if err != nil {
  833. // br.Msg = "获取失败"
  834. // br.ErrMsg = "获取失败,Err:" + err.Error()
  835. // return
  836. //}
  837. if len(predictEdbConfList) == 0 {
  838. br.Msg = "找不到该预测指标配置"
  839. br.ErrMsg = "找不到该预测指标配置"
  840. return
  841. }
  842. predictEdbConf := predictEdbConfList[0]
  843. ruleType = predictEdbConf.RuleType
  844. fixedValue = predictEdbConf.FixedValue
  845. }
  846. findEdbInfoIdList := make([]int, 0)
  847. for k, v := range calculateList {
  848. if v.LatestDate != v.EndDate && v.LatestDate != `` && v.EndDate != `` {
  849. tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
  850. tmpEndDate, _ := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
  851. if tmpEndDate.After(tmpLatestDate) {
  852. findEdbInfoIdList = append(findEdbInfoIdList, v.FromEdbInfoId)
  853. }
  854. }
  855. v.EndValue = v.LatestValue
  856. calculateList[k] = v
  857. }
  858. if len(findEdbInfoIdList) > 0 {
  859. edbDataInsertConfigList, err := data_manage.GetEdbDataInsertConfigByEdbIdList(findEdbInfoIdList)
  860. if err != nil {
  861. br.Msg = "获取失败"
  862. br.ErrMsg = "获取失败插入值失败,Err:" + err.Error()
  863. return
  864. }
  865. edbDataInsertConfigMap := make(map[int]*data_manage.EdbDataInsertConfig)
  866. for _, v := range edbDataInsertConfigList {
  867. edbDataInsertConfigMap[v.EdbInfoId] = v
  868. }
  869. for k, v := range calculateList {
  870. edbDataInsertConfig, ok := edbDataInsertConfigMap[v.FromEdbInfoId]
  871. if !ok {
  872. continue
  873. }
  874. if v.EndDate != `` && v.EndDate == edbDataInsertConfig.Date.Format(utils.FormatDate) {
  875. t, tmpErr := decimal.NewFromString(edbDataInsertConfig.Value)
  876. if tmpErr != nil {
  877. continue
  878. }
  879. v.EndValue, _ = t.Float64()
  880. }
  881. calculateList[k] = v
  882. }
  883. }
  884. // 拟合残差计算相关系数
  885. var correlationStr string
  886. if edbInfo.Source == utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC {
  887. var aEdbInfo, bEdbInfo *data_manage.EdbInfoCalculateDetail
  888. for _, v := range calculateList {
  889. if v.FromTag == "A" {
  890. aEdbInfo = v
  891. continue
  892. }
  893. if v.FromTag == "B" {
  894. bEdbInfo = v
  895. continue
  896. }
  897. }
  898. if aEdbInfo != nil && bEdbInfo != nil {
  899. edbInfoFromTagList := []data_manage.EdbInfoFromTag{
  900. {
  901. EdbInfoId: aEdbInfo.FromEdbInfoId,
  902. FromTag: aEdbInfo.FromTag,
  903. MoveValue: aEdbInfo.MoveValue,
  904. }, {
  905. EdbInfoId: bEdbInfo.FromEdbInfoId,
  906. FromTag: bEdbInfo.FromTag,
  907. MoveValue: bEdbInfo.MoveValue,
  908. },
  909. }
  910. req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
  911. AdminId: sysUser.AdminId,
  912. AdminName: sysUser.RealName,
  913. Formula: edbInfo.CalculateFormula,
  914. EdbInfoIdArr: edbInfoFromTagList,
  915. }
  916. // 计算
  917. val, err, _ := data.CallCalculateComputeCorrelation(req2)
  918. if err == nil {
  919. correlationStr = val
  920. }
  921. }
  922. }
  923. resp := response.PredictEdbInfo{
  924. EdbInfo: *edbInfo,
  925. RuleType: ruleType,
  926. FixedValue: fixedValue,
  927. CalculateList: calculateList,
  928. RuleList: predictEdbConfList,
  929. CorrelationStr: correlationStr,
  930. }
  931. br.Ret = 200
  932. br.Success = true
  933. br.Msg = "获取成功"
  934. br.Data = resp
  935. }
  936. // FilterByEs
  937. // @Title 指标筛选接口
  938. // @Description 指标筛选接口
  939. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  940. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  941. // @Param Frequency query string false "频度"
  942. // @Param IsOnlyMe query bool false "是否只看我的"
  943. // @Param PageSize query int true "每页数据条数"
  944. // @Param CurrentIndex query int true "当前页页码,从1开始"
  945. // @Success 200 {object} data_manage.EdbInfoList
  946. // @router /predict_edb_info/filter_by_es [get]
  947. func (this *PredictEdbInfoController) FilterByEs() {
  948. br := new(models.BaseResponse).Init()
  949. defer func() {
  950. this.Data["json"] = br
  951. this.ServeJSON()
  952. }()
  953. pageSize, _ := this.GetInt("PageSize")
  954. currentIndex, _ := this.GetInt("CurrentIndex")
  955. var total int64
  956. var startSize int
  957. if pageSize <= 0 {
  958. pageSize = utils.PageSize20
  959. }
  960. if currentIndex <= 0 {
  961. currentIndex = 1
  962. }
  963. startSize = paging.StartIndex(currentIndex, pageSize)
  964. keyWord := this.GetString("Keyword")
  965. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  966. //兼容前端
  967. if keyWord == `` {
  968. keyWord = this.GetString("KeyWord")
  969. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  970. }
  971. filterSource, _ := this.GetInt("FilterSource")
  972. if filterSource <= 0 {
  973. filterSource = 1
  974. }
  975. //指标来源
  976. source, _ := this.GetInt("Source")
  977. frequency := this.GetString("Frequency") //频度
  978. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  979. var edbInfoList []*data_manage.EdbInfoList
  980. var err error
  981. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  982. // 获取当前账号的不可见指标
  983. {
  984. obj := data_manage.EdbInfoNoPermissionAdmin{}
  985. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  986. if err != nil && err.Error() != utils.ErrNoRow() {
  987. br.Msg = "获取失败"
  988. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  989. return
  990. }
  991. for _, v := range confList {
  992. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  993. }
  994. }
  995. if keyWord != "" {
  996. var keyWordArr []string
  997. keyWordArr = append(keyWordArr, keyWord)
  998. newKeyWord := strings.Split(keyWord, " ")
  999. keyWordArr = append(keyWordArr, newKeyWord...)
  1000. if isOnlyMe {
  1001. total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, this.SysUser.AdminId)
  1002. } else {
  1003. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, noPermissionEdbInfoIdList)
  1004. }
  1005. } else {
  1006. var condition string
  1007. var pars []interface{}
  1008. // 预测指标
  1009. condition += ` AND edb_info_type = ? `
  1010. pars = append(pars, 1)
  1011. // 无权限指标id
  1012. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  1013. if lenNoPermissionEdbInfoIdList > 0 {
  1014. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  1015. pars = append(pars, noPermissionEdbInfoIdList)
  1016. }
  1017. switch filterSource {
  1018. case 2:
  1019. condition += ` AND frequency='月度' `
  1020. case 3:
  1021. condition += ` AND frequency <> '日度' `
  1022. case 4:
  1023. condition += ` AND edb_type = 1 `
  1024. case 5:
  1025. condition += ` AND source = 32 ` //来源(预测同比值)
  1026. case 6:
  1027. condition += ` AND frequency != ? `
  1028. pars = append(pars, "年度")
  1029. }
  1030. //频度
  1031. if frequency != "" {
  1032. condition += ` AND frequency = ? `
  1033. pars = append(pars, frequency)
  1034. }
  1035. if isOnlyMe {
  1036. condition += " AND sys_user_id = ? "
  1037. pars = append(pars, this.SysUser.AdminId)
  1038. }
  1039. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  1040. }
  1041. if err != nil {
  1042. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  1043. }
  1044. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1045. edbInfoListLen := len(edbInfoList)
  1046. for i := 0; i < edbInfoListLen; i++ {
  1047. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  1048. }
  1049. for i := 0; i < edbInfoListLen; i++ {
  1050. for j := 0; j < edbInfoListLen; j++ {
  1051. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  1052. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  1053. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  1054. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  1055. }
  1056. }
  1057. }
  1058. //新增搜索词记录
  1059. {
  1060. searchKeyword := new(data_manage.SearchKeyword)
  1061. searchKeyword.KeyWord = keyWord
  1062. searchKeyword.CreateTime = time.Now()
  1063. go data_manage.AddSearchKeyword(searchKeyword)
  1064. }
  1065. resp := data_manage.EdbInfoFilterDataResp{
  1066. Paging: page,
  1067. List: edbInfoList,
  1068. }
  1069. br.Ret = 200
  1070. br.Success = true
  1071. br.Msg = "获取成功"
  1072. br.Data = resp
  1073. }
  1074. // RefreshAll
  1075. // @Title 指标全部刷新接口
  1076. // @Description 指标全部刷新接口
  1077. // @Param EdbInfoId query int true "指标id"
  1078. // @Success Ret=200 全部刷新成功
  1079. // @router /predict_edb_info/refresh/all [get]
  1080. func (this *PredictEdbInfoController) RefreshAll() {
  1081. br := new(models.BaseResponse).Init()
  1082. defer func() {
  1083. this.Data["json"] = br
  1084. this.ServeJSON()
  1085. }()
  1086. sysUser := this.SysUser
  1087. if sysUser == nil {
  1088. br.Msg = "请登录"
  1089. br.ErrMsg = "请登录,SysUser Is Empty"
  1090. br.Ret = 408
  1091. return
  1092. }
  1093. edbInfoId, _ := this.GetInt("EdbInfoId")
  1094. if edbInfoId <= 0 {
  1095. br.Msg = "参数错误"
  1096. br.ErrMsg = "参数错误"
  1097. return
  1098. }
  1099. _, isAsync, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, true)
  1100. if errMsg != `` {
  1101. br.Msg = errMsg
  1102. br.ErrMsg = errMsg
  1103. if err != nil {
  1104. br.ErrMsg = err.Error()
  1105. } else {
  1106. br.IsSendEmail = false
  1107. }
  1108. return
  1109. }
  1110. br.Ret = 200
  1111. br.Success = true
  1112. br.Msg = "刷新成功"
  1113. if isAsync {
  1114. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  1115. }
  1116. }
  1117. // DataList
  1118. // @Title 获取指标数据
  1119. // @Description 获取指标数据
  1120. // @Param EdbInfoId query int true "指标ID"
  1121. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  1122. // @Param StartDate query string true "自定义开始日期"
  1123. // @Param EndDate query string true "自定义结束日期"
  1124. // @Param Calendar query string true "公历/农历"
  1125. // @Param SeasonStartDate query string true "季节性图开始日期"
  1126. // @Param SeasonEndDate query string true "季节性图结束日期"
  1127. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  1128. // @Success 200 {object} data_manage.EdbInfoDataResp
  1129. // @router /predict_edb_info/data [get]
  1130. func (this *PredictEdbInfoController) DataList() {
  1131. br := new(models.BaseResponse).Init()
  1132. defer func() {
  1133. this.Data["json"] = br
  1134. this.ServeJSON()
  1135. }()
  1136. sysUser := this.SysUser
  1137. if sysUser == nil {
  1138. br.Msg = "请登录"
  1139. br.ErrMsg = "请登录,SysUser Is Empty"
  1140. br.Ret = 408
  1141. return
  1142. }
  1143. edbInfoId, _ := this.GetInt("EdbInfoId")
  1144. if edbInfoId <= 0 {
  1145. br.Msg = "参数错误"
  1146. return
  1147. }
  1148. dateType, _ := this.GetInt("DateType")
  1149. if dateType <= 0 {
  1150. dateType = 3
  1151. }
  1152. edbInfoType, _ := this.GetInt("EdbInfoType")
  1153. if edbInfoType < 0 {
  1154. edbInfoType = 1
  1155. }
  1156. startDate := this.GetString("StartDate")
  1157. endDate := this.GetString("EndDate")
  1158. startYear, _ := this.GetInt("StartYear")
  1159. chartType, _ := this.GetInt("ChartType")
  1160. if chartType <= 0 {
  1161. chartType = 1
  1162. }
  1163. calendar := this.GetString("Calendar")
  1164. if calendar == "" {
  1165. calendar = "公历"
  1166. }
  1167. isTimeBetween := false //是否是时间区间
  1168. if chartType == 2 {
  1169. dateType = 0
  1170. isTimeBetween = true
  1171. }
  1172. if dateType == 5 {
  1173. isTimeBetween = true
  1174. }
  1175. // 获取预测指标信息
  1176. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1177. if err != nil {
  1178. br.Msg = "获取预测指标信息失败"
  1179. br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error()
  1180. return
  1181. }
  1182. maxYear := 0
  1183. if edbInfo.LatestDate != "" {
  1184. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  1185. maxYear = latestDateT.Year()
  1186. }
  1187. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  1188. if endDate == "" {
  1189. endDate = time.Now().Format(utils.FormatDate)
  1190. }
  1191. if dateType == 10 {
  1192. startDate = ""
  1193. endDate = ""
  1194. }
  1195. // 按钮校验
  1196. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  1197. button.AddButton = false
  1198. dataList, _, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDate, endDate, isTimeBetween)
  1199. //lenDataList := len(dataList)
  1200. //if lenDataList > 0 {
  1201. // tmpValue := dataList[lenDataList-1]
  1202. //
  1203. // // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1204. // if edbInfo.MaxValue < tmpValue.Value {
  1205. // edbInfo.MaxValue = tmpValue.Value
  1206. // }
  1207. //
  1208. // // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1209. // if edbInfo.MinValue > tmpValue.Value {
  1210. // edbInfo.MinValue = tmpValue.Value
  1211. // }
  1212. //}
  1213. // 季节性图、公历、农历处理
  1214. resultDataList, err := data.GetChartDataList(dataList, chartType, calendar, edbInfo.LatestDate, startDate)
  1215. if err != nil {
  1216. br.Msg = "获取失败"
  1217. br.ErrMsg = "获取失败,Err:" + err.Error()
  1218. return
  1219. }
  1220. resp := response.PredictEdbInfoDataResp{
  1221. EdbInfo: edbInfo,
  1222. DataList: resultDataList,
  1223. Button: button,
  1224. }
  1225. br.Ret = 200
  1226. br.Success = true
  1227. br.Msg = "获取成功"
  1228. br.Data = resp
  1229. }
  1230. // ChartDataList
  1231. // @Title 获取指标数据
  1232. // @Description 获取指标数据
  1233. // @Param request body data_manage.AddPredictEdbInfoReq true "type json string"
  1234. // @Success 200 {object} data_manage.EdbInfoDataResp
  1235. // @router /predict_edb_info/chart/data/list [post]
  1236. func (this *PredictEdbInfoController) ChartDataList() {
  1237. br := new(models.BaseResponse).Init()
  1238. defer func() {
  1239. this.Data["json"] = br
  1240. this.ServeJSON()
  1241. }()
  1242. sysUser := this.SysUser
  1243. if sysUser == nil {
  1244. br.Msg = "请登录"
  1245. br.ErrMsg = "请登录,SysUser Is Empty"
  1246. br.Ret = 408
  1247. return
  1248. }
  1249. var req request.PredictEdbInfoChartDataReq
  1250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1251. if req.SourceEdbInfoId <= 0 {
  1252. br.Msg = "参数错误"
  1253. return
  1254. }
  1255. dateType := req.DateType
  1256. startDate := req.StartDate
  1257. endDate := req.EndDate
  1258. //seasonStartDate := req.SeasonStartDate
  1259. //seasonEndDate := req.SeasonEndDate
  1260. startYear := req.StartYear
  1261. calendar := req.Calendar
  1262. if calendar == "" {
  1263. calendar = "公历"
  1264. }
  1265. isTimeBetween := false //是否是时间区间
  1266. if req.ChartType == 2 {
  1267. dateType = 0
  1268. isTimeBetween = true
  1269. }
  1270. if dateType == 5 {
  1271. isTimeBetween = true
  1272. }
  1273. // 规则列表
  1274. // 根据截止日期重新排序
  1275. ruleList := make([]request.RuleConfig, 0)
  1276. {
  1277. ruleMap := make(map[string]request.RuleConfig)
  1278. dateIntList := make([]int64, 0)
  1279. for _, v := range req.RuleList {
  1280. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  1281. if err != nil {
  1282. br.Msg = "配置项中时间异常,请重新选择"
  1283. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  1284. br.IsSendEmail = false
  1285. return
  1286. }
  1287. dateIntList = append(dateIntList, confEndDate.Unix())
  1288. ruleMap[v.EndDate] = v
  1289. }
  1290. sort.Slice(dateIntList, func(i, j int) bool {
  1291. return dateIntList[i] < dateIntList[j]
  1292. })
  1293. for _, dateInt := range dateIntList {
  1294. currDateTime := time.Unix(dateInt, 0)
  1295. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  1296. if !ok {
  1297. br.Msg = "配置项中时间异常,请重新选择"
  1298. br.ErrMsg = "配置项中时间异常,请重新选择"
  1299. br.IsSendEmail = false
  1300. return
  1301. }
  1302. ruleList = append(ruleList, item)
  1303. }
  1304. }
  1305. // 预测指标配置
  1306. predictEdbConfAndDataList := make([]data_manage.PredictEdbConfAndData, 0)
  1307. endDateStr := `` //数据的结束日期
  1308. for _, v := range ruleList {
  1309. endDateStr = v.EndDate //预测指标的结束日期
  1310. confEndDate, err := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
  1311. if err != nil {
  1312. br.Msg = "配置项中时间异常,请重新选择"
  1313. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  1314. return
  1315. }
  1316. // 没有数据,自己瞎测试
  1317. //switch v.RuleType {
  1318. //case 3: //3:同比
  1319. // v.Value = "0.1"
  1320. //case 4: //4:同差
  1321. // v.Value = "10"
  1322. //case 5: //5:环比
  1323. // v.Value = "0.1"
  1324. //case 6: //6:环差
  1325. // v.Value = "0.1"
  1326. //case 7: //7:N期移动均值
  1327. // v.Value = "5"
  1328. //case 8: //8:N期段线性外推值
  1329. // v.Value = "5"
  1330. //}
  1331. tmpDataList := make([]*data_manage.EdbDataList, 0)
  1332. switch v.RuleType {
  1333. case 9:
  1334. // 获取计算参数
  1335. formula, edbInfoList, edbInfoIdBytes, err, errMsg := data.GetCalculateByRuleByNineParams(v)
  1336. if err != nil {
  1337. br.Msg = "计算失败"
  1338. if errMsg != "" {
  1339. br.Msg = errMsg
  1340. }
  1341. br.Msg = err.Error()
  1342. br.IsSendEmail = false
  1343. return
  1344. }
  1345. // 获取计算数据
  1346. tmpDataList, err = data.CalculateByRuleByNine(formula, edbInfoList, edbInfoIdBytes)
  1347. if err != nil {
  1348. br.Msg = "计算失败"
  1349. br.ErrMsg = err.Error()
  1350. br.IsSendEmail = false
  1351. return
  1352. }
  1353. }
  1354. tmpPredictEdbConfAndData := data_manage.PredictEdbConfAndData{
  1355. ConfigId: 0,
  1356. PredictEdbInfoId: 0,
  1357. SourceEdbInfoId: req.SourceEdbInfoId,
  1358. RuleType: v.RuleType,
  1359. FixedValue: 0,
  1360. Value: v.Value,
  1361. EndDate: confEndDate,
  1362. ModifyTime: time.Now(),
  1363. CreateTime: time.Now(),
  1364. DataList: tmpDataList,
  1365. }
  1366. predictEdbConfAndDataList = append(predictEdbConfAndDataList, tmpPredictEdbConfAndData)
  1367. }
  1368. // 来源指标
  1369. sourceEdbInfoItem, err := data_manage.GetEdbInfoById(req.SourceEdbInfoId)
  1370. if err != nil {
  1371. br.Msg = "获取来源指标信息失败"
  1372. br.ErrMsg = "获取来源指标信息失败"
  1373. if err.Error() != utils.ErrNoRow() {
  1374. br.ErrMsg = "获取来源指标信息失败,Err:" + err.Error()
  1375. }
  1376. br.Success = true
  1377. return
  1378. }
  1379. // todo 确认预测指标是否用的是来源指标的最新日期
  1380. maxYear := 0
  1381. if sourceEdbInfoItem.LatestDate != "" {
  1382. latestDateT, _ := time.Parse(utils.FormatDate, sourceEdbInfoItem.LatestDate)
  1383. maxYear = latestDateT.Year()
  1384. }
  1385. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  1386. if endDate == "" {
  1387. endDate = time.Now().Format(utils.FormatDate)
  1388. }
  1389. if dateType == 10 {
  1390. startDate = ""
  1391. endDate = ""
  1392. }
  1393. minValue := sourceEdbInfoItem.MinValue
  1394. maxValue := sourceEdbInfoItem.MaxValue
  1395. allDataList := make([]*data_manage.EdbDataList, 0)
  1396. //获取指标数据(实际已生成)
  1397. dataList, err := data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, startDate, endDate)
  1398. if err != nil {
  1399. br.Msg = "获取失败"
  1400. br.Msg = "获取失败,Err:" + err.Error()
  1401. return
  1402. }
  1403. // 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
  1404. if startDate != `` {
  1405. allDataList, err = data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, "", "")
  1406. if err != nil {
  1407. br.Msg = "获取失败"
  1408. br.Msg = "获取失败,Err:" + err.Error()
  1409. return
  1410. }
  1411. } else {
  1412. allDataList = dataList
  1413. }
  1414. // 获取预测指标未来的数据
  1415. if len(predictEdbConfAndDataList) > 0 {
  1416. predictDataList := make([]*data_manage.EdbDataList, 0)
  1417. if isTimeBetween { //如果是时间区间,那么
  1418. reqEndDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  1419. endDateTime, _ := time.ParseInLocation(utils.FormatDate, req.PredictEndDate, time.Local)
  1420. // 如果选择的时间区间结束日期 晚于 当天,那么预测数据截止到当天
  1421. if reqEndDateTime.Before(endDateTime) {
  1422. endDateStr = endDate
  1423. }
  1424. }
  1425. // 获取预测数据
  1426. var predictMinValue, predictMaxValue float64
  1427. predictDataList, predictMinValue, predictMaxValue, err, errMsg := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfAndDataList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, sourceEdbInfoItem.Frequency, req.DataDateType, allDataList)
  1428. if err != nil {
  1429. br.Msg = "获取预测指标数据失败"
  1430. if errMsg != `` {
  1431. br.Msg = errMsg
  1432. }
  1433. br.ErrMsg = "获取预测指标数据失败:" + err.Error()
  1434. return
  1435. }
  1436. dataList = append(dataList, predictDataList...)
  1437. if len(predictDataList) > 0 {
  1438. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1439. if minValue > predictMinValue {
  1440. minValue = predictMinValue
  1441. }
  1442. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1443. if maxValue < predictMaxValue {
  1444. maxValue = predictMaxValue
  1445. }
  1446. }
  1447. }
  1448. // 季节性图、公历、农历处理
  1449. resultDataList, err := data.GetChartDataList(dataList, req.ChartType, calendar, sourceEdbInfoItem.LatestDate, startDate)
  1450. if err != nil {
  1451. br.Msg = "获取失败"
  1452. br.ErrMsg = "获取失败,Err:" + err.Error()
  1453. return
  1454. }
  1455. resp := response.PredictEdbInfoChartDataResp{
  1456. MinValue: minValue,
  1457. MaxValue: maxValue,
  1458. DataList: resultDataList,
  1459. }
  1460. br.Ret = 200
  1461. br.Success = true
  1462. br.Msg = "获取成功"
  1463. br.Data = resp
  1464. }
  1465. // PredictRuleCalculateByNine
  1466. // @Title 根据预测规则9来计算数据
  1467. // @Description 获取指标数据
  1468. // @Param request body data_manage.RuleConfig true "type json string"
  1469. // @Success 200 {object} data_manage.EdbInfoDataResp
  1470. // @router /predict_edb_info/rule/calculate_by_nine [post]
  1471. func (this *PredictEdbInfoController) PredictRuleCalculateByNine() {
  1472. br := new(models.BaseResponse).Init()
  1473. defer func() {
  1474. this.Data["json"] = br
  1475. this.ServeJSON()
  1476. }()
  1477. sysUser := this.SysUser
  1478. time.Now().AddDate(0, -1, -1).Format(utils.FormatDate)
  1479. if sysUser == nil {
  1480. br.Msg = "请登录"
  1481. br.ErrMsg = "请登录,SysUser Is Empty"
  1482. br.Ret = 408
  1483. return
  1484. }
  1485. var req request.RuleConfig
  1486. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1487. // 获取计算参数
  1488. formula, edbInfoList, edbInfoIdBytes, err, errMsg := data.GetCalculateByRuleByNineParams(req)
  1489. if err != nil {
  1490. br.Msg = "计算失败"
  1491. if errMsg != "" {
  1492. br.Msg = errMsg
  1493. }
  1494. br.Msg = err.Error()
  1495. br.IsSendEmail = false
  1496. return
  1497. }
  1498. // 获取计算数据
  1499. dataList, err := data.CalculateByRuleByNine(formula, edbInfoList, edbInfoIdBytes)
  1500. if err != nil {
  1501. br.Msg = "数据计算失败"
  1502. br.ErrMsg = "数据计算失败:Err:" + err.Error()
  1503. br.IsSendEmail = false
  1504. return
  1505. }
  1506. latestDate := time.Now()
  1507. for _, v := range edbInfoList {
  1508. tmpLatestDate, err := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
  1509. if err != nil {
  1510. continue
  1511. }
  1512. if tmpLatestDate.Before(latestDate) {
  1513. latestDate = tmpLatestDate
  1514. }
  1515. }
  1516. newDataList := make([]*data_manage.EdbDataList, 0)
  1517. lenData := len(dataList)
  1518. if lenData > 0 {
  1519. for i := lenData - 1; i >= 0; i-- {
  1520. newDataList = append(newDataList, dataList[i])
  1521. }
  1522. }
  1523. resp := response.PredictRuleCalculateByNineResp{
  1524. LatestDate: latestDate.Format(utils.FormatDate),
  1525. DataList: newDataList,
  1526. }
  1527. br.Ret = 200
  1528. br.Success = true
  1529. br.Msg = "获取成功"
  1530. br.Data = resp
  1531. }
  1532. // Modify
  1533. // @Title 修改指标信息接口
  1534. // @Description 编辑指标接口
  1535. // @Success 200 {object} request.EditEdbInfoReq
  1536. // @router /predict_edb_info/modify [post]
  1537. func (this *PredictEdbInfoController) Modify() {
  1538. br := new(models.BaseResponse).Init()
  1539. defer func() {
  1540. this.Data["json"] = br
  1541. this.ServeJSON()
  1542. }()
  1543. sysUser := this.SysUser
  1544. if sysUser == nil {
  1545. br.Msg = "请登录"
  1546. br.ErrMsg = "请登录,SysUser Is Empty"
  1547. br.Ret = 408
  1548. return
  1549. }
  1550. var req request.ModifyPredictEdbInfoReq
  1551. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1552. if err != nil {
  1553. br.Msg = "参数解析异常!"
  1554. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1555. return
  1556. }
  1557. edbInfoId := req.EdbInfoId
  1558. if edbInfoId <= 0 {
  1559. br.Msg = "请选择预测指标"
  1560. br.IsSendEmail = false
  1561. return
  1562. }
  1563. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1564. if err != nil {
  1565. br.Msg = "修改失败"
  1566. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1567. return
  1568. }
  1569. // 编辑权限校验
  1570. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  1571. if !button.OpButton {
  1572. br.Msg = "无权限操作"
  1573. br.IsSendEmail = false
  1574. return
  1575. }
  1576. edbInfo.MaxValue = req.MaxValue
  1577. edbInfo.MinValue = req.MinValue
  1578. edbInfo.ModifyTime = time.Now()
  1579. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ModifyTime"})
  1580. if err != nil {
  1581. br.Msg = "获取失败"
  1582. br.ErrMsg = "获取失败,Err:" + err.Error()
  1583. return
  1584. }
  1585. //修改es
  1586. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1587. br.Ret = 200
  1588. br.Success = true
  1589. br.Msg = "修改成功"
  1590. br.IsAddLog = true
  1591. }
  1592. //func init() {
  1593. // r := new(regression.Regression)
  1594. // r.SetObserved("Murders per annum per 1,000,000 inhabitants")
  1595. // r.SetVar(0, "Inhabitants")
  1596. // r.SetVar(1, "Percent with incomes below $5000")
  1597. // r.SetVar(2, "Percent unemployed")
  1598. // r.Train(
  1599. // regression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),
  1600. // regression.DataPoint(13.4, []float64{643000, 20.5, 6.4}),
  1601. // regression.DataPoint(40.7, []float64{635000, 26.3, 9.3}),
  1602. // regression.DataPoint(5.3, []float64{692000, 16.5, 5.3}),
  1603. // regression.DataPoint(24.8, []float64{1248000, 19.2, 7.3}),
  1604. // regression.DataPoint(12.7, []float64{643000, 16.5, 5.9}),
  1605. // regression.DataPoint(20.9, []float64{1964000, 20.2, 6.4}),
  1606. // regression.DataPoint(35.7, []float64{1531000, 21.3, 7.6}),
  1607. // regression.DataPoint(8.7, []float64{713000, 17.2, 4.9}),
  1608. // regression.DataPoint(9.6, []float64{749000, 14.3, 6.4}),
  1609. // regression.DataPoint(14.5, []float64{7895000, 18.1, 6}),
  1610. // regression.DataPoint(26.9, []float64{762000, 23.1, 7.4}),
  1611. // regression.DataPoint(15.7, []float64{2793000, 19.1, 5.8}),
  1612. // regression.DataPoint(36.2, []float64{741000, 24.7, 8.6}),
  1613. // regression.DataPoint(18.1, []float64{625000, 18.6, 6.5}),
  1614. // regression.DataPoint(28.9, []float64{854000, 24.9, 8.3}),
  1615. // regression.DataPoint(14.9, []float64{716000, 17.9, 6.7}),
  1616. // regression.DataPoint(25.8, []float64{921000, 22.4, 8.6}),
  1617. // regression.DataPoint(21.7, []float64{595000, 20.2, 8.4}),
  1618. // regression.DataPoint(25.7, []float64{3353000, 16.9, 6.7}),
  1619. // )
  1620. // r.Run()
  1621. //
  1622. // fmt.Printf("Regression formula:\n%v\n", r.Formula)
  1623. // //fmt.Printf("Regression:\n%s\n", r)
  1624. //}
  1625. //func init() {
  1626. // //data := []float64{4080, 4070, 4070, 4020, 4020, 4010, 3950, 3980, 4000, 3990, 4020}
  1627. // //median, _ := stats.Median(data)
  1628. // //fmt.Println(median) // 3.65
  1629. // //stats.LinearRegression()
  1630. //
  1631. // //data := []float64{ , , , , , , , , }
  1632. //
  1633. // data := []Coordinate{
  1634. // {1, 4080},
  1635. // {2, 4070},
  1636. // {3, 4070},
  1637. // {4, 4020},
  1638. // {5, 4020},
  1639. // {6, 4010},
  1640. // {7, 3950},
  1641. // {8, 3980},
  1642. // {9, 4000},
  1643. // {10, 3990},
  1644. // {11, 4020},
  1645. // }
  1646. //
  1647. // //r, _ := ct(data)
  1648. //
  1649. // ct(data)
  1650. // //fmt.Println(r)
  1651. //
  1652. //}
  1653. //func init() {
  1654. // data.AddOrEditAllEdbInfoToEs()
  1655. //}
  1656. // ClassifyEdbInfoItems
  1657. // @Title 获取分类下指标接口
  1658. // @Description 获取分类下指标接口
  1659. // @Param ClassifyId query int true "分类id"
  1660. // @Param IsShowMe query bool false "是否只看我的"
  1661. // @Success 200 {object} data_manage.EdbClassifyListResp
  1662. // @router /predict_edb_info/items [get]
  1663. func (this *PredictEdbInfoController) ClassifyEdbInfoItems() {
  1664. br := new(models.BaseResponse).Init()
  1665. defer func() {
  1666. this.Data["json"] = br
  1667. this.ServeJSON()
  1668. }()
  1669. classifyId, _ := this.GetInt("ClassifyId")
  1670. if classifyId <= 0 {
  1671. br.Msg = "参数错误,请刷新页面"
  1672. return
  1673. }
  1674. // 是否只看我的
  1675. isShowMe, _ := this.GetBool("IsShowMe")
  1676. // 获取当前账号的不可见指标
  1677. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1678. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  1679. if err != nil && err.Error() != utils.ErrNoRow() {
  1680. br.Msg = "获取失败"
  1681. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1682. return
  1683. }
  1684. noPermissionEdbInfoIdMap := make(map[int]bool)
  1685. for _, v := range confList {
  1686. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  1687. }
  1688. // 如果选择了只看我的,那么只查询归属于我的账号
  1689. sysUserId := 0
  1690. if isShowMe {
  1691. sysUserId = this.SysUser.AdminId
  1692. }
  1693. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, 1, sysUserId)
  1694. if err != nil && err.Error() != utils.ErrNoRow() {
  1695. br.Msg = "获取失败"
  1696. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1697. return
  1698. }
  1699. list := make([]*data_manage.EdbClassifyItems, 0)
  1700. for _, v := range allEdbInfo {
  1701. // 如果指标不可见,那么就不返回该指标
  1702. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  1703. continue
  1704. }
  1705. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
  1706. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  1707. v.Button = button
  1708. list = append(list, v)
  1709. }
  1710. resp := new(data_manage.ClassifyEdbInfoListResp)
  1711. resp.EdbInfoList = list
  1712. br.Ret = 200
  1713. br.Success = true
  1714. br.Msg = "获取成功"
  1715. br.Data = resp
  1716. }