predict_edb_info.go 64 KB

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