chart_info.go 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935
  1. package line_feature
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/controllers"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/data_manage/line_feature/request"
  9. "eta/eta_api/models/data_manage/line_feature/response"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services/alarm_msg"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/data/data_manage_permission"
  14. lineFeatureServ "eta/eta_api/services/data/line_feature"
  15. "eta/eta_api/utils"
  16. "fmt"
  17. "github.com/rdlucklib/rdluck_tools/paging"
  18. "strconv"
  19. "strings"
  20. "time"
  21. )
  22. // LineFeaturesChartInfoController 统计特征图表管理
  23. type LineFeaturesChartInfoController struct {
  24. controllers.BaseAuthController
  25. }
  26. // MultipleGraphConfigSave
  27. // @Title 保存配置接口
  28. // @Description 保存配置接口
  29. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  30. // @Success Ret=200 返回图表id
  31. // @router /config/save [post]
  32. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSave() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. var req request.SaveMultipleGraphConfigReq
  46. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  47. if err != nil {
  48. br.Msg = "参数解析异常!"
  49. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  50. return
  51. }
  52. if req.EdbInfoId <= 0 {
  53. br.Msg = "指标未选择"
  54. br.IsSendEmail = false
  55. return
  56. }
  57. _, err = data_manage.GetEdbInfoById(req.EdbInfoId)
  58. if err != nil {
  59. br.Msg = "指标A异常"
  60. br.ErrMsg = "指标A异常,err:" + err.Error()
  61. if err.Error() == utils.ErrNoRow() {
  62. br.Msg = `指标A不存在`
  63. br.IsSendEmail = false
  64. }
  65. return
  66. }
  67. configSave := request.ConfigSave{
  68. Curve: req.Curve,
  69. StandardDeviation: req.StandardDeviation,
  70. Percentile: req.Percentile,
  71. FrequencyDistribution: req.FrequencyDistribution,
  72. }
  73. configSaveStrByte, err := json.Marshal(configSave)
  74. if err != nil {
  75. br.Msg = `相关性配置异常`
  76. br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
  77. return
  78. }
  79. var multipleGraphConfig *data_manage.MultipleGraphConfig
  80. if req.MultipleGraphConfigId > 0 {
  81. multipleGraphConfig, err = data_manage.GetMultipleGraphConfigById(req.MultipleGraphConfigId)
  82. if err != nil {
  83. br.Msg = `不存在该配置`
  84. br.ErrMsg = `不存在该配置`
  85. return
  86. }
  87. multipleGraphConfig.EdbInfoIdA = req.EdbInfoId
  88. multipleGraphConfig.Curve = string(configSaveStrByte)
  89. multipleGraphConfig.ModifyTime = time.Now()
  90. err = multipleGraphConfig.Update([]string{"EdbInfoIdA", "Curve", "ModifyTime"})
  91. } else {
  92. multipleGraphConfig = &data_manage.MultipleGraphConfig{
  93. //MultipleGraphConfigId: 0,
  94. EdbInfoIdA: req.EdbInfoId,
  95. Curve: string(configSaveStrByte),
  96. SysUserId: this.SysUser.AdminId,
  97. SysUserRealName: this.SysUser.RealName,
  98. ModifyTime: time.Now(),
  99. CreateTime: time.Now(),
  100. }
  101. err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  102. }
  103. if err != nil {
  104. br.Msg = `保存失败`
  105. br.ErrMsg = `保存失败,Err:` + err.Error()
  106. return
  107. }
  108. br.Ret = 200
  109. br.Success = true
  110. br.Msg = "保存成功"
  111. br.Data = multipleGraphConfig
  112. br.IsAddLog = true
  113. }
  114. // MultipleGraphPreview
  115. // @Title 批量添加图表的预览接口
  116. // @Description 批量添加图表的预览接口
  117. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  118. // @Success Ret=200 返回图表id
  119. // @router /preview [post]
  120. func (this *LineFeaturesChartInfoController) MultipleGraphPreview() {
  121. br := new(models.BaseResponse).Init()
  122. defer func() {
  123. this.Data["json"] = br
  124. this.ServeJSON()
  125. }()
  126. sysUser := this.SysUser
  127. if sysUser == nil {
  128. br.Msg = "请登录"
  129. br.ErrMsg = "请登录,SysUser Is Empty"
  130. br.Ret = 408
  131. return
  132. }
  133. var req request.SaveMultipleGraphConfigReq
  134. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  135. if err != nil {
  136. br.Msg = "参数解析异常!"
  137. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  138. return
  139. }
  140. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  141. if err != nil {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  144. return
  145. }
  146. if edbInfoMapping == nil {
  147. br.Msg = "指标不存在"
  148. br.IsSendEmail = false
  149. return
  150. }
  151. resp := response.PreviewMultipleGraphConfigResp{}
  152. chartInfo := new(data_manage.ChartInfoView)
  153. chartInfo.Calendar = `公历`
  154. chartInfo.ChartName = edbInfoMapping.EdbName
  155. // 曲线图表信息
  156. curveConf := req.Curve
  157. maxYear := 0
  158. if edbInfoMapping.LatestDate != "" {
  159. latestDateT, _ := time.Parse(utils.FormatDate, edbInfoMapping.LatestDate)
  160. maxYear = latestDateT.Year()
  161. }
  162. startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxYear)
  163. {
  164. tmpChartInfo := *chartInfo
  165. // 获取图表中的指标数据
  166. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, []*data_manage.ChartEdbInfoMapping{edbInfoMapping}, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
  167. if err != nil {
  168. br.Msg = "获取失败"
  169. if errMsg != `` {
  170. br.Msg = errMsg
  171. }
  172. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  173. return
  174. }
  175. warnEdbList := make([]string, 0)
  176. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  177. for _, v := range edbList {
  178. if v.IsNullData {
  179. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  180. }
  181. chartEdbInfoMapping := *v
  182. chartEdbInfoMapping.IsOrder = false
  183. chartEdbInfoMapping.IsAxis = 1
  184. chartEdbInfoMapping.MinData = curveConf.LeftMin
  185. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  186. chartEdbInfoMapping.ChartColor = `#00F`
  187. chartEdbInfoMapping.ChartWidth = 3
  188. chartEdbInfoMapping.EdbInfoType = 1
  189. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  190. }
  191. if len(warnEdbList) > 0 {
  192. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  193. }
  194. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  195. tmpChartInfo.DateType = curveConf.DateType
  196. tmpChartInfo.StartDate = startDate
  197. tmpChartInfo.EndDate = endDate
  198. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  199. resp.CurveData = response.CurveResp{
  200. ChartInfo: tmpChartInfo,
  201. EdbInfoList: tmpEdbList,
  202. }
  203. }
  204. // 标准差图表信息
  205. {
  206. // 配置了数据才有返回
  207. if req.StandardDeviation.CalculateValue > 0 {
  208. tmpChartInfo := *chartInfo
  209. tmpChartInfo.ChartName = fmt.Sprintf("%s%d期滚动标准差", edbInfoMapping.EdbName, req.StandardDeviation.CalculateValue)
  210. // 获取图表中的指标数据
  211. edbList, dataResp, err, errMsg := lineFeatureServ.GetStandardDeviationData(0, startDate, endDate, edbInfoMapping, req.StandardDeviation.CalculateValue)
  212. if err != nil {
  213. br.Msg = "获取失败"
  214. if errMsg != `` {
  215. br.Msg = errMsg
  216. }
  217. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  218. return
  219. }
  220. warnEdbList := make([]string, 0)
  221. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  222. for _, v := range edbList {
  223. if v.IsNullData {
  224. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  225. }
  226. chartEdbInfoMapping := *v
  227. chartEdbInfoMapping.IsOrder = false
  228. chartEdbInfoMapping.IsAxis = 1
  229. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  230. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  231. chartEdbInfoMapping.ChartColor = `#00F`
  232. chartEdbInfoMapping.ChartWidth = 3
  233. chartEdbInfoMapping.EdbInfoType = 1
  234. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  235. }
  236. if len(warnEdbList) > 0 {
  237. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  238. }
  239. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION
  240. //tmpChartInfo.DateType = curveConf.DateType
  241. //tmpChartInfo.StartDate = startDate
  242. //tmpChartInfo.EndDate = endDate
  243. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  244. resp.StandardDeviationData = response.CurveResp{
  245. ChartInfo: tmpChartInfo,
  246. EdbInfoList: tmpEdbList,
  247. DataResp: dataResp,
  248. }
  249. }
  250. }
  251. // 百分位图表信息
  252. {
  253. // 配置了数据才有返回
  254. if req.Percentile.CalculateValue > 0 && req.Percentile.CalculateUnit != `` {
  255. tmpChartInfo := *chartInfo
  256. tmpChartInfo.ChartName = fmt.Sprintf("%s%d%s百分位", edbInfoMapping.EdbName, req.Percentile.CalculateValue, req.Percentile.CalculateUnit)
  257. // 获取图表中的指标数据
  258. edbList, dataResp, err, errMsg := lineFeatureServ.GetPercentileData(0, startDate, endDate, edbInfoMapping, req.Percentile.CalculateValue, req.Percentile.CalculateUnit, req.Percentile.PercentType)
  259. if err != nil && errMsg != `` {
  260. br.Msg = errMsg
  261. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  262. return
  263. }
  264. if err == nil {
  265. warnEdbList := make([]string, 0)
  266. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  267. for _, v := range edbList {
  268. if v.IsNullData {
  269. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  270. }
  271. chartEdbInfoMapping := *v
  272. chartEdbInfoMapping.IsOrder = false
  273. chartEdbInfoMapping.IsAxis = 1
  274. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  275. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  276. chartEdbInfoMapping.ChartColor = `#00F`
  277. chartEdbInfoMapping.ChartWidth = 3
  278. chartEdbInfoMapping.EdbInfoType = 1
  279. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  280. }
  281. if len(warnEdbList) > 0 {
  282. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  283. }
  284. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE
  285. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  286. resp.PercentileData = response.CurveResp{
  287. ChartInfo: tmpChartInfo,
  288. EdbInfoList: tmpEdbList,
  289. DataResp: dataResp,
  290. }
  291. }
  292. }
  293. }
  294. // 频率分布图表信息
  295. {
  296. // 配置了数据才有返回
  297. if req.FrequencyDistribution.DateType > 0 && req.FrequencyDistribution.FrequencyValue > 0 {
  298. tmpChartInfo := *chartInfo
  299. tmpChartInfo.ChartName = fmt.Sprintf("%s频率和累计频率", edbInfoMapping.EdbName)
  300. // 获取图表中的指标数据
  301. edbList, dataResp, err, errMsg := lineFeatureServ.GetFrequencyDistributionData(0, edbInfoMapping, req.FrequencyDistribution.DateType, req.FrequencyDistribution.FrequencyValue, req.FrequencyDistribution.StartDate, req.FrequencyDistribution.EndDate)
  302. if err != nil && errMsg != `` {
  303. br.Msg = errMsg
  304. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  305. return
  306. }
  307. if err == nil {
  308. warnEdbList := make([]string, 0)
  309. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  310. for _, v := range edbList {
  311. if v.IsNullData {
  312. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  313. }
  314. chartEdbInfoMapping := *v
  315. chartEdbInfoMapping.IsOrder = false
  316. chartEdbInfoMapping.IsAxis = 1
  317. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  318. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  319. chartEdbInfoMapping.ChartColor = `#00F`
  320. chartEdbInfoMapping.ChartWidth = 3
  321. chartEdbInfoMapping.EdbInfoType = 1
  322. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  323. }
  324. if len(warnEdbList) > 0 {
  325. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  326. }
  327. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY
  328. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  329. resp.FrequencyDistributionData = response.CurveResp{
  330. ChartInfo: tmpChartInfo,
  331. EdbInfoList: tmpEdbList,
  332. DataResp: dataResp,
  333. }
  334. }
  335. }
  336. }
  337. br.Ret = 200
  338. br.Success = true
  339. br.Msg = "获取成功"
  340. br.Data = resp
  341. }
  342. // MultipleGraphPreviewCurve
  343. // @Title 批量添加图表的预览曲线图接口(只返回曲线图的数据)
  344. // @Description 批量添加图表的预览曲线图接口
  345. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  346. // @Success Ret=200 返回图表id
  347. // @router /preview_cure [post]
  348. func (this *LineFeaturesChartInfoController) MultipleGraphPreviewCurve() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. this.Data["json"] = br
  352. this.ServeJSON()
  353. }()
  354. sysUser := this.SysUser
  355. if sysUser == nil {
  356. br.Msg = "请登录"
  357. br.ErrMsg = "请登录,SysUser Is Empty"
  358. br.Ret = 408
  359. return
  360. }
  361. var req request.SaveMultipleGraphConfigReq
  362. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  363. if err != nil {
  364. br.Msg = "参数解析异常!"
  365. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  366. return
  367. }
  368. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  369. if err != nil {
  370. br.Msg = "获取失败"
  371. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  372. return
  373. }
  374. if edbInfoMapping == nil {
  375. br.Msg = "指标不存在"
  376. br.IsSendEmail = false
  377. return
  378. }
  379. resp := response.PreviewMultipleGraphConfigResp{}
  380. chartInfo := new(data_manage.ChartInfoView)
  381. chartInfo.Calendar = `公历`
  382. chartInfo.ChartName = edbInfoMapping.EdbName
  383. // 曲线图表信息
  384. {
  385. tmpChartInfo := *chartInfo
  386. curveConf := req.Curve
  387. maxYear := 0
  388. if edbInfoMapping.LatestDate != "" {
  389. latestDateT, _ := time.Parse(utils.FormatDate, edbInfoMapping.LatestDate)
  390. maxYear = latestDateT.Year()
  391. }
  392. startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxYear)
  393. // 获取图表中的指标数据
  394. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, []*data_manage.ChartEdbInfoMapping{edbInfoMapping}, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
  395. if err != nil {
  396. br.Msg = "获取失败"
  397. if errMsg != `` {
  398. br.Msg = errMsg
  399. }
  400. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  401. return
  402. }
  403. warnEdbList := make([]string, 0)
  404. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  405. for _, v := range edbList {
  406. if v.IsNullData {
  407. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  408. }
  409. chartEdbInfoMapping := *v
  410. chartEdbInfoMapping.IsOrder = false
  411. chartEdbInfoMapping.IsAxis = 1
  412. chartEdbInfoMapping.MinData = curveConf.LeftMin
  413. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  414. chartEdbInfoMapping.ChartColor = `#00F`
  415. chartEdbInfoMapping.ChartWidth = 3
  416. chartEdbInfoMapping.EdbInfoType = 1
  417. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  418. }
  419. if len(warnEdbList) > 0 {
  420. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  421. }
  422. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  423. tmpChartInfo.DateType = curveConf.DateType
  424. tmpChartInfo.StartDate = startDate
  425. tmpChartInfo.EndDate = endDate
  426. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  427. resp.CurveData = response.CurveResp{
  428. ChartInfo: tmpChartInfo,
  429. EdbInfoList: tmpEdbList,
  430. }
  431. }
  432. br.Ret = 200
  433. br.Success = true
  434. br.Msg = "获取成功"
  435. br.Data = resp
  436. }
  437. // MultipleGraphConfigSaveChart
  438. // @Title 保存图表接口
  439. // @Description 保存图表接口
  440. // @Param request body request.SaveMultipleGraphChartReq true "type json string"
  441. // @Success Ret=200 返回图表id
  442. // @router /chart/save [post]
  443. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSaveChart() {
  444. br := new(models.BaseResponse).Init()
  445. defer func() {
  446. this.Data["json"] = br
  447. this.ServeJSON()
  448. }()
  449. sysUser := this.SysUser
  450. if sysUser == nil {
  451. br.Msg = "请登录"
  452. br.ErrMsg = "请登录,SysUser Is Empty"
  453. br.Ret = 408
  454. return
  455. }
  456. var req request.SaveMultipleGraphChartReq
  457. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  458. if err != nil {
  459. br.Msg = "参数解析异常!"
  460. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  461. return
  462. }
  463. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  464. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  465. br.Msg = "系统处理中,请稍后重试!"
  466. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  467. return
  468. }
  469. defer func() {
  470. _ = utils.Rc.Delete(cacheKey)
  471. }()
  472. if req.MultipleGraphConfigId <= 0 {
  473. br.Msg = "配置未保存"
  474. br.IsSendEmail = false
  475. return
  476. }
  477. if req.IsSaveAs {
  478. CopyMultipleGraphConfigSaveChart(req, this, br, sysUser)
  479. return
  480. }
  481. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  482. if err != nil {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  485. return
  486. }
  487. if edbInfoMapping == nil {
  488. br.Msg = "指标不存在"
  489. br.IsSendEmail = false
  490. return
  491. }
  492. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  493. if err != nil && err.Error() != utils.ErrNoRow() {
  494. br.Msg = `保存失败`
  495. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  496. return
  497. }
  498. err = nil
  499. var isAdd bool
  500. var chartInfoId int
  501. if multipleGraphConfigChartMapping == nil {
  502. isAdd = true
  503. } else {
  504. chartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  505. if err != nil && err.Error() != utils.ErrNoRow() {
  506. br.Msg = `保存失败`
  507. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  508. return
  509. }
  510. // 说明图还在,没有被删除
  511. if chartInfo != nil {
  512. chartInfoId = multipleGraphConfigChartMapping.ChartInfoId
  513. req.ChartName = chartInfo.ChartName
  514. req.ClassifyId = chartInfo.ChartClassifyId
  515. }
  516. }
  517. var chartInfo *data_manage.ChartInfo
  518. var errMsg string
  519. isSendEmail := true
  520. curveConf := req.Curve
  521. maxYear := 0
  522. if edbInfoMapping.LatestDate != "" {
  523. latestDateT, _ := time.Parse(utils.FormatDate, edbInfoMapping.LatestDate)
  524. maxYear = latestDateT.Year()
  525. }
  526. startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxYear)
  527. switch req.Source {
  528. case utils.CHART_MULTIPLE_GRAPH_CURVE: // 曲线图
  529. curveConf := req.Curve
  530. chartSaveItemList := []*data_manage.ChartSaveItem{
  531. {
  532. EdbInfoId: edbInfoMapping.EdbInfoId,
  533. MaxData: curveConf.LeftMax,
  534. MinData: curveConf.LeftMin,
  535. IsOrder: false,
  536. IsAxis: 1,
  537. EdbInfoType: 1,
  538. //LeadValue: curveConf.LeadValue,
  539. //LeadUnit: curveConf.LeadUnit,
  540. ChartStyle: "spline",
  541. ChartColor: `#00F`,
  542. PredictChartColor: "",
  543. ChartWidth: 3,
  544. Source: utils.CHART_SOURCE_DEFAULT,
  545. },
  546. }
  547. if chartInfoId <= 0 {
  548. addChartReq := data_manage.AddChartInfoReq{
  549. ChartEdbInfoList: chartSaveItemList,
  550. ChartClassifyId: req.ClassifyId,
  551. ChartName: req.ChartName,
  552. ChartType: utils.CHART_TYPE_CURVE,
  553. DateType: curveConf.DateType,
  554. StartDate: curveConf.StartDate,
  555. EndDate: curveConf.EndDate,
  556. Calendar: "公历",
  557. LeftMin: fmt.Sprint(curveConf.LeftMin),
  558. LeftMax: fmt.Sprint(curveConf.LeftMax),
  559. }
  560. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName, this.Lang)
  561. } else {
  562. editChartReq := data_manage.EditChartInfoReq{
  563. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  564. ChartName: req.ChartName,
  565. ChartClassifyId: req.ClassifyId,
  566. ChartEdbInfoList: chartSaveItemList,
  567. ChartType: utils.CHART_TYPE_CURVE,
  568. DateType: curveConf.DateType,
  569. StartDate: curveConf.StartDate,
  570. EndDate: curveConf.EndDate,
  571. Calendar: "公历",
  572. LeftMin: fmt.Sprint(curveConf.LeftMin),
  573. LeftMax: fmt.Sprint(curveConf.LeftMax),
  574. }
  575. chartInfo, err, errMsg, isSendEmail = data.EditChartInfo(editChartReq, sysUser, this.Lang)
  576. if err != nil {
  577. br.Msg = "保存失败"
  578. if errMsg != `` {
  579. br.Msg = errMsg
  580. }
  581. br.ErrMsg = err.Error()
  582. br.IsSendEmail = isSendEmail
  583. return
  584. }
  585. }
  586. default:
  587. var extraConfig string
  588. var chartSource int
  589. var leftMinVal, leftMaxVal, rightMinVal, rightMaxVal float64
  590. // 统计特征-标准差图表
  591. if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION {
  592. chartSource = utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION // 统计特征-标准差图表
  593. standardDeviationConf := req.StandardDeviation
  594. if standardDeviationConf.CalculateValue <= 0 {
  595. br.Msg = "滚动周期需要大于0"
  596. br.IsSendEmail = false
  597. return
  598. }
  599. extraConfig = fmt.Sprint(standardDeviationConf.CalculateValue)
  600. _, dataResp, err, errMsg := lineFeatureServ.GetStandardDeviationData(0, startDate, endDate, edbInfoMapping, req.StandardDeviation.CalculateValue)
  601. if err != nil {
  602. br.Msg = "保存失败"
  603. if errMsg != `` {
  604. br.Msg = errMsg
  605. }
  606. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  607. return
  608. }
  609. leftMinVal = dataResp.MinData
  610. leftMaxVal = dataResp.MaxData
  611. } else if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE {
  612. chartSource = utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE // 统计特征-百分位图表
  613. percentileConf := req.Percentile
  614. if percentileConf.CalculateUnit == `` {
  615. br.Msg = "时间长度频度必选"
  616. br.IsSendEmail = false
  617. return
  618. }
  619. if percentileConf.CalculateValue <= 0 {
  620. br.Msg = "时间长度期数需要大于0"
  621. br.IsSendEmail = false
  622. return
  623. }
  624. extraConfigByte, _ := json.Marshal(percentileConf)
  625. extraConfig = string(extraConfigByte)
  626. // 获取图表中的指标数据
  627. _, dataResp, err, errMsg := lineFeatureServ.GetPercentileData(0, startDate, endDate, edbInfoMapping, req.Percentile.CalculateValue, req.Percentile.CalculateUnit, req.Percentile.PercentType)
  628. if err != nil && errMsg != `` {
  629. br.Msg = errMsg
  630. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  631. return
  632. }
  633. leftMinVal = dataResp.MinData
  634. leftMaxVal = dataResp.MaxData
  635. } else if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_FREQUENCY {
  636. chartSource = utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY // 统计特征-频率分布图表
  637. frequencyDistributionConf := req.FrequencyDistribution
  638. if frequencyDistributionConf.DateType <= 0 {
  639. br.Msg = "日期类型必选"
  640. br.IsSendEmail = false
  641. return
  642. }
  643. if frequencyDistributionConf.FrequencyValue <= 0 {
  644. br.Msg = "频段数必填"
  645. br.IsSendEmail = false
  646. return
  647. }
  648. extraConfigByte, _ := json.Marshal(frequencyDistributionConf)
  649. extraConfig = string(extraConfigByte)
  650. // 获取图表中的指标数据
  651. _, dataResp, err, errMsg := lineFeatureServ.GetFrequencyDistributionData(0, edbInfoMapping, req.FrequencyDistribution.DateType, req.FrequencyDistribution.FrequencyValue, req.FrequencyDistribution.StartDate, req.FrequencyDistribution.EndDate)
  652. if err != nil && errMsg != `` {
  653. br.Msg = errMsg
  654. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  655. return
  656. }
  657. leftMinVal = dataResp.LeftMinValue
  658. leftMaxVal = dataResp.LeftMaxValue
  659. rightMinVal = dataResp.RightMinValue
  660. rightMaxVal = dataResp.RightMaxValue
  661. }
  662. if chartSource <= 0 {
  663. br.Msg = "错误的来源"
  664. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  665. br.IsSendEmail = false
  666. return
  667. }
  668. if chartInfoId <= 0 {
  669. addChartReq := data_manage.AddChartInfoReq{
  670. DateType: curveConf.DateType,
  671. StartDate: curveConf.StartDate,
  672. EndDate: curveConf.StartDate,
  673. ChartClassifyId: req.ClassifyId,
  674. ChartName: req.ChartName,
  675. ChartType: utils.CHART_TYPE_CURVE,
  676. Calendar: "公历",
  677. LeftMin: fmt.Sprint(leftMinVal),
  678. LeftMax: fmt.Sprint(leftMaxVal),
  679. RightMin: fmt.Sprint(rightMinVal),
  680. RightMax: fmt.Sprint(rightMaxVal),
  681. ExtraConfig: extraConfig,
  682. }
  683. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.AddChartInfo(addChartReq, edbInfoMapping, chartSource, sysUser, this.Lang)
  684. } else {
  685. editChartReq := data_manage.EditChartInfoReq{
  686. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  687. ChartName: req.ChartName,
  688. ChartClassifyId: req.ClassifyId,
  689. ChartType: utils.CHART_TYPE_CURVE,
  690. DateType: curveConf.DateType,
  691. StartDate: curveConf.StartDate,
  692. EndDate: curveConf.StartDate,
  693. Calendar: "公历",
  694. LeftMin: fmt.Sprint(leftMinVal),
  695. LeftMax: fmt.Sprint(leftMaxVal),
  696. RightMin: fmt.Sprint(rightMinVal),
  697. RightMax: fmt.Sprint(rightMaxVal),
  698. ExtraConfig: extraConfig,
  699. }
  700. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.EditChartInfo(editChartReq, edbInfoMapping, sysUser, this.Lang)
  701. if err != nil {
  702. br.Msg = "保存失败"
  703. if errMsg != `` {
  704. br.Msg = errMsg
  705. }
  706. br.ErrMsg = err.Error()
  707. br.IsSendEmail = isSendEmail
  708. return
  709. }
  710. }
  711. }
  712. if err != nil {
  713. br.Msg = "保存失败"
  714. if errMsg != `` {
  715. br.Msg = errMsg
  716. }
  717. br.ErrMsg = err.Error()
  718. br.IsSendEmail = isSendEmail
  719. return
  720. }
  721. // 如果图没有建立关联关系,那么就需要添加关系
  722. if isAdd {
  723. multipleGraphConfigChartMapping = &data_manage.MultipleGraphConfigChartMapping{
  724. //Id: 0,
  725. MultipleGraphConfigId: req.MultipleGraphConfigId,
  726. ChartInfoId: chartInfo.ChartInfoId,
  727. Source: req.Source,
  728. ModifyTime: time.Now(),
  729. CreateTime: time.Now(),
  730. }
  731. err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
  732. if err != nil {
  733. br.Msg = "保存失败"
  734. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  735. return
  736. }
  737. } else if multipleGraphConfigChartMapping != nil {
  738. multipleGraphConfigChartMapping.ChartInfoId = chartInfo.ChartInfoId
  739. multipleGraphConfigChartMapping.ModifyTime = time.Now()
  740. err = multipleGraphConfigChartMapping.Update([]string{"ChartInfoId", "ModifyTime"})
  741. if err != nil {
  742. br.Msg = "保存失败"
  743. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  744. return
  745. }
  746. }
  747. //新增操作日志
  748. {
  749. chartLog := new(data_manage.ChartInfoLog)
  750. chartLog.ChartInfoId = chartInfo.ChartInfoId
  751. chartLog.ChartName = req.ChartName
  752. chartLog.ChartClassifyId = req.ClassifyId
  753. chartLog.SysUserId = sysUser.AdminId
  754. chartLog.SysUserRealName = sysUser.RealName
  755. chartLog.UniqueCode = chartInfo.UniqueCode
  756. chartLog.CreateTime = time.Now()
  757. chartLog.Content = string(this.Ctx.Input.RequestBody)
  758. chartLog.Status = "统计特征保存图表"
  759. chartLog.Method = this.Ctx.Input.URI()
  760. go data_manage.AddChartInfoLog(chartLog)
  761. }
  762. resp := new(data_manage.AddChartInfoResp)
  763. resp.ChartInfoId = chartInfo.ChartInfoId
  764. resp.UniqueCode = chartInfo.UniqueCode
  765. resp.ChartType = chartInfo.ChartType
  766. br.Ret = 200
  767. br.Success = true
  768. br.Msg = "保存成功"
  769. br.Data = resp
  770. br.IsAddLog = true
  771. }
  772. // CopyMultipleGraphConfigSaveChart 图表另存为
  773. func CopyMultipleGraphConfigSaveChart(req request.SaveMultipleGraphChartReq, this *LineFeaturesChartInfoController, br *models.BaseResponse, sysUser *system.Admin) {
  774. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  775. if err != nil {
  776. br.Msg = "获取失败"
  777. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  778. return
  779. }
  780. if edbInfoMapping == nil {
  781. br.Msg = "指标不存在"
  782. br.IsSendEmail = false
  783. return
  784. }
  785. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  786. if err != nil && err.Error() != utils.ErrNoRow() {
  787. br.Msg = `保存失败`
  788. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  789. return
  790. }
  791. // 原图
  792. oldChartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  793. if err != nil && err.Error() != utils.ErrNoRow() {
  794. br.Msg = `保存失败`
  795. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  796. return
  797. }
  798. // 说明图还在,没有被删除
  799. if oldChartInfo == nil {
  800. br.Msg = "原图不存在"
  801. br.IsSendEmail = false
  802. }
  803. var chartInfo *data_manage.ChartInfo
  804. var errMsg string
  805. isSendEmail := true
  806. switch req.Source {
  807. case utils.CHART_MULTIPLE_GRAPH_CURVE: // 曲线图
  808. curveConf := req.Curve
  809. chartSaveItemList := []*data_manage.ChartSaveItem{
  810. {
  811. EdbInfoId: edbInfoMapping.EdbInfoId,
  812. MaxData: curveConf.LeftMax,
  813. MinData: curveConf.LeftMin,
  814. IsOrder: false,
  815. IsAxis: 1,
  816. EdbInfoType: 1,
  817. //LeadValue: curveConf.LeadValue,
  818. //LeadUnit: curveConf.LeadUnit,
  819. ChartStyle: "spline",
  820. ChartColor: `#00F`,
  821. PredictChartColor: "",
  822. ChartWidth: 3,
  823. Source: utils.CHART_SOURCE_DEFAULT,
  824. },
  825. }
  826. addChartReq := data_manage.AddChartInfoReq{
  827. ChartEdbInfoList: chartSaveItemList,
  828. ChartClassifyId: req.ClassifyId,
  829. ChartName: req.ChartName,
  830. ChartType: utils.CHART_TYPE_CURVE,
  831. DateType: curveConf.DateType,
  832. StartDate: curveConf.StartDate,
  833. EndDate: curveConf.EndDate,
  834. Calendar: "公历",
  835. LeftMin: fmt.Sprint(curveConf.LeftMin),
  836. LeftMax: fmt.Sprint(curveConf.LeftMax),
  837. }
  838. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName, this.Lang)
  839. default:
  840. if !utils.InArrayByInt([]int{utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE, utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_FREQUENCY}, req.Source) {
  841. br.Msg = "错误的来源"
  842. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  843. br.IsSendEmail = false
  844. return
  845. }
  846. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, req.Source, req.ClassifyId, req.ChartName, edbInfoMapping, oldChartInfo, sysUser, this.Lang)
  847. }
  848. if err != nil {
  849. br.Msg = "保存失败"
  850. if errMsg != `` {
  851. br.Msg = errMsg
  852. }
  853. br.ErrMsg = err.Error()
  854. br.IsSendEmail = isSendEmail
  855. return
  856. }
  857. //新增操作日志
  858. {
  859. chartLog := new(data_manage.ChartInfoLog)
  860. chartLog.ChartInfoId = chartInfo.ChartInfoId
  861. chartLog.ChartName = req.ChartName
  862. chartLog.ChartClassifyId = req.ClassifyId
  863. chartLog.SysUserId = sysUser.AdminId
  864. chartLog.SysUserRealName = sysUser.RealName
  865. chartLog.UniqueCode = chartInfo.UniqueCode
  866. chartLog.CreateTime = time.Now()
  867. chartLog.Content = string(this.Ctx.Input.RequestBody)
  868. chartLog.Status = "统计特征另存为图表"
  869. chartLog.Method = this.Ctx.Input.URI()
  870. go data_manage.AddChartInfoLog(chartLog)
  871. }
  872. resp := new(data_manage.AddChartInfoResp)
  873. resp.ChartInfoId = chartInfo.ChartInfoId
  874. resp.UniqueCode = chartInfo.UniqueCode
  875. resp.ChartType = chartInfo.ChartType
  876. br.Ret = 200
  877. br.Success = true
  878. br.Msg = "保存成功"
  879. br.Data = resp
  880. br.IsAddLog = true
  881. }
  882. // MultipleGraphConfigSaveEdb
  883. // @Title 保存指标接口
  884. // @Description 保存指标接口
  885. // @Param request body request.SaveMultipleGraphEdbReq true "type json string"
  886. // @Success Ret=200 返回指标id
  887. // @router /edb/save [post]
  888. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSaveEdb() {
  889. br := new(models.BaseResponse).Init()
  890. defer func() {
  891. this.Data["json"] = br
  892. this.ServeJSON()
  893. }()
  894. sysUser := this.SysUser
  895. if sysUser == nil {
  896. br.Msg = "请登录"
  897. br.ErrMsg = "请登录,SysUser Is Empty"
  898. br.Ret = 408
  899. return
  900. }
  901. var req request.SaveMultipleGraphEdbReq
  902. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  903. if err != nil {
  904. br.Msg = "参数解析异常!"
  905. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  906. return
  907. }
  908. cacheKey := "CACHE_CHART_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  909. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  910. br.Msg = "系统处理中,请稍后重试!"
  911. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  912. return
  913. }
  914. defer func() {
  915. _ = utils.Rc.Delete(cacheKey)
  916. }()
  917. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  918. if err != nil {
  919. br.Msg = "获取失败"
  920. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  921. return
  922. }
  923. if edbInfoMapping == nil {
  924. br.Msg = "指标不存在"
  925. br.IsSendEmail = false
  926. return
  927. }
  928. // 计算公式
  929. var formula string
  930. var edbSource int
  931. switch req.Source {
  932. case utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION:
  933. edbSource = utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION // 统计特征-标准差
  934. if edbInfoMapping.EdbInfoCategoryType == 1 {
  935. edbSource = utils.DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION // 统计特征-预测标准差
  936. }
  937. standardDeviationConf := req.StandardDeviation
  938. if standardDeviationConf.CalculateValue <= 0 {
  939. br.Msg = "滚动周期需要大于0"
  940. br.IsSendEmail = false
  941. return
  942. }
  943. formula = fmt.Sprint(standardDeviationConf.CalculateValue)
  944. case utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE:
  945. edbSource = utils.DATA_SOURCE_CALCULATE_PERCENTILE // 统计特征-百分位图表
  946. if edbInfoMapping.EdbInfoCategoryType == 1 {
  947. edbSource = utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE // 统计特征-预测标准差
  948. }
  949. percentileConf := req.Percentile
  950. if percentileConf.CalculateUnit == `` {
  951. br.Msg = "时间长度频度必选"
  952. br.IsSendEmail = false
  953. return
  954. }
  955. if percentileConf.CalculateValue <= 0 {
  956. br.Msg = "时间长度期数需要大于0"
  957. br.IsSendEmail = false
  958. return
  959. }
  960. extraConfigByte, _ := json.Marshal(percentileConf)
  961. formula = string(extraConfigByte)
  962. default:
  963. br.Msg = "错误的来源"
  964. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  965. br.IsSendEmail = false
  966. return
  967. }
  968. multipleGraphConfigEdbMapping, err := data_manage.GetMultipleGraphConfigEdbMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  969. if err != nil && err.Error() != utils.ErrNoRow() {
  970. br.Msg = `保存失败`
  971. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  972. return
  973. }
  974. err = nil
  975. var isAdd bool
  976. var edbInfoId int
  977. if multipleGraphConfigEdbMapping == nil {
  978. isAdd = true
  979. } else {
  980. edbInfo, err := data_manage.GetEdbInfoById(multipleGraphConfigEdbMapping.EdbInfoId)
  981. if err != nil && err.Error() != utils.ErrNoRow() {
  982. br.Msg = `保存失败`
  983. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  984. return
  985. }
  986. // 说明指标还在,没有被删除
  987. if edbInfo != nil && !req.IsSaveAs {
  988. edbInfoId = multipleGraphConfigEdbMapping.EdbInfoId
  989. req.EdbName = edbInfo.EdbName
  990. req.ClassifyId = edbInfo.ClassifyId
  991. req.Frequency = edbInfo.Frequency
  992. req.Unit = edbInfo.Unit
  993. }
  994. }
  995. var respItem *data.AddPredictEdbDataResponse
  996. // 0:普通,1:预测
  997. if edbInfoMapping.EdbInfoCategoryType == 0 {
  998. if edbInfoId <= 0 || req.IsSaveAs {
  999. req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
  1000. AdminId: sysUser.AdminId,
  1001. AdminName: sysUser.RealName,
  1002. EdbName: req.EdbName,
  1003. Frequency: req.Frequency,
  1004. Unit: req.Unit,
  1005. ClassifyId: req.ClassifyId,
  1006. Formula: formula,
  1007. Source: edbSource,
  1008. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  1009. Calendar: `公历`,
  1010. }
  1011. // 调用指标库去添加
  1012. reqJson, err := json.Marshal(req2)
  1013. if err != nil {
  1014. br.Msg = "参数解析异常!"
  1015. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1016. return
  1017. }
  1018. respItem, err = data.BatchSaveEdbCalculateData(string(reqJson), this.Lang)
  1019. if err != nil {
  1020. br.Msg = "新增失败"
  1021. br.ErrMsg = "新增失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. } else {
  1025. req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
  1026. EdbInfoId: edbInfoId,
  1027. EdbName: req.EdbName,
  1028. Frequency: req.Frequency,
  1029. Unit: req.Unit,
  1030. ClassifyId: req.ClassifyId,
  1031. Formula: formula,
  1032. Source: edbSource,
  1033. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  1034. Calendar: `公历`,
  1035. }
  1036. // 调用指标库去更新
  1037. reqJson, err := json.Marshal(req2)
  1038. if err != nil {
  1039. br.Msg = "参数解析异常!"
  1040. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1041. return
  1042. }
  1043. respItem, err = data.BatchEditEdbCalculateData(string(reqJson), this.Lang)
  1044. if err != nil {
  1045. br.Msg = "编辑失败"
  1046. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1047. return
  1048. }
  1049. }
  1050. } else {
  1051. req2 := &data_manage.PredictEdbInfoCalculateBatchSaveReq{
  1052. AdminId: sysUser.AdminId,
  1053. AdminName: sysUser.RealName,
  1054. EdbName: req.EdbName,
  1055. Frequency: req.Frequency,
  1056. Unit: req.Unit,
  1057. ClassifyId: req.ClassifyId,
  1058. Formula: formula,
  1059. Source: edbSource,
  1060. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  1061. Calendar: `公历`,
  1062. }
  1063. if edbInfoId > 0 && !req.IsSaveAs {
  1064. req2.EdbInfoId = edbInfoId
  1065. }
  1066. // 调用指标库去添加
  1067. reqJson, err := json.Marshal(req2)
  1068. if err != nil {
  1069. br.Msg = "参数解析异常!"
  1070. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. respItem, err = data.BatchSavePredictEdbData(string(reqJson), this.Lang)
  1074. if err != nil {
  1075. br.Msg = "新增失败"
  1076. br.ErrMsg = "新增失败,Err:" + err.Error()
  1077. return
  1078. }
  1079. }
  1080. if respItem == nil {
  1081. br.Msg = "保存失败"
  1082. br.ErrMsg = "保存失败"
  1083. return
  1084. }
  1085. if respItem.Ret != 200 {
  1086. br.Msg = respItem.Msg
  1087. br.ErrMsg = respItem.ErrMsg
  1088. return
  1089. }
  1090. resp := respItem.Data
  1091. //添加es
  1092. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  1093. // 如果不是另存为的话,那么需要建立配置与指标的关系
  1094. if !req.IsSaveAs {
  1095. // 如果指标没有建立关联关系,那么就需要添加关系
  1096. if isAdd {
  1097. multipleGraphConfigEdbMapping = &data_manage.MultipleGraphConfigEdbMapping{
  1098. //Id: 0,
  1099. MultipleGraphConfigId: req.MultipleGraphConfigId,
  1100. EdbInfoId: resp.EdbInfoId,
  1101. Source: req.Source,
  1102. ModifyTime: time.Now(),
  1103. CreateTime: time.Now(),
  1104. }
  1105. err = data_manage.AddMultipleGraphConfigEdbMapping(multipleGraphConfigEdbMapping)
  1106. if err != nil {
  1107. br.Msg = "保存失败"
  1108. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1109. return
  1110. }
  1111. } else if multipleGraphConfigEdbMapping != nil {
  1112. multipleGraphConfigEdbMapping.EdbInfoId = resp.EdbInfoId
  1113. multipleGraphConfigEdbMapping.ModifyTime = time.Now()
  1114. err = multipleGraphConfigEdbMapping.Update([]string{"EdbInfoId", "ModifyTime"})
  1115. if err != nil {
  1116. br.Msg = "保存失败"
  1117. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1118. return
  1119. }
  1120. }
  1121. }
  1122. //新增操作日志
  1123. //{
  1124. // edbLog := new(data_manage.EdbInfoLog)
  1125. // edbLog.EdbInfoId = resp.EdbInfoId
  1126. // edbLog.SourceName = edbInfo.SourceName
  1127. // edbLog.Source = edbInfo.Source
  1128. // edbLog.EdbCode = edbInfo.EdbCode
  1129. // edbLog.EdbName = req2.EdbName
  1130. // edbLog.ClassifyId = req2.ClassifyId
  1131. // edbLog.SysUserId = sysUser.AdminId
  1132. // edbLog.SysUserRealName = sysUser.RealName
  1133. // edbLog.CreateTime = time.Now()
  1134. // edbLog.Content = string(this.Ctx.Input.RequestBody)
  1135. // edbLog.Status = "多图配置保存指标"
  1136. // edbLog.Method = this.Ctx.Input.URI()
  1137. // go data_manage.AddEdbInfoLog(edbLog)
  1138. //}
  1139. br.Ret = 200
  1140. br.Success = true
  1141. br.Msg = "保存成功"
  1142. br.Data = resp
  1143. br.IsAddLog = true
  1144. }
  1145. // GetMultipleGraphConfig
  1146. // @Title 保存配置接口
  1147. // @Description 保存配置接口
  1148. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  1149. // @Success Ret=200 返回图表id
  1150. // @router /config/detail [get]
  1151. func (this *LineFeaturesChartInfoController) GetMultipleGraphConfig() {
  1152. br := new(models.BaseResponse).Init()
  1153. defer func() {
  1154. this.Data["json"] = br
  1155. this.ServeJSON()
  1156. }()
  1157. sysUser := this.SysUser
  1158. if sysUser == nil {
  1159. br.Msg = "请登录"
  1160. br.ErrMsg = "请登录,SysUser Is Empty"
  1161. br.Ret = 408
  1162. return
  1163. }
  1164. uniqueCode := this.GetString("UniqueCode")
  1165. if uniqueCode == "" {
  1166. br.Msg = "参数错误"
  1167. br.ErrMsg = "参数错误,uniqueCode is empty"
  1168. return
  1169. }
  1170. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1171. if err != nil {
  1172. br.Msg = "获取失败"
  1173. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1174. return
  1175. }
  1176. if chartInfo == nil {
  1177. br.Msg = "获取失败"
  1178. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1179. return
  1180. }
  1181. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  1182. if err != nil {
  1183. br.Msg = "获取失败"
  1184. br.ErrMsg = "获取滚动相关性图表的配置信息失败,Err:" + err.Error()
  1185. return
  1186. }
  1187. multipleGraphConfig, err := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1188. if err != nil {
  1189. br.Msg = `获取失败`
  1190. br.ErrMsg = `获取配置失败,ERR:` + err.Error()
  1191. return
  1192. }
  1193. // 生成的图表
  1194. multipleGraphConfigChartMappingList := make([]response.MultipleGraphConfigChartMapping, 0)
  1195. {
  1196. chartMappingList, err := data_manage.GetMultipleGraphConfigChartMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1197. if err != nil {
  1198. br.Msg = `获取失败`
  1199. br.ErrMsg = `获取关联图表配置失败,ERR:` + err.Error()
  1200. return
  1201. }
  1202. chartInfoIdList := make([]int, 0)
  1203. chartMappingMap := make(map[int]*data_manage.MultipleGraphConfigChartMapping)
  1204. for _, v := range chartMappingList {
  1205. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1206. chartMappingMap[v.ChartInfoId] = v
  1207. }
  1208. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1209. if err != nil {
  1210. br.Msg = `获取失败`
  1211. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1212. return
  1213. }
  1214. for _, v := range chartList {
  1215. if tmpInfo, ok := chartMappingMap[v.ChartInfoId]; ok {
  1216. multipleGraphConfigChartMappingList = append(multipleGraphConfigChartMappingList, response.MultipleGraphConfigChartMapping{
  1217. ChartInfoId: tmpInfo.ChartInfoId,
  1218. Source: tmpInfo.Source,
  1219. MultipleLocationSource: tmpInfo.Source,
  1220. })
  1221. }
  1222. }
  1223. }
  1224. // 生成的指标
  1225. multipleGraphConfigEdbMappingList := make([]response.MultipleGraphConfigEdbMapping, 0)
  1226. {
  1227. edbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1228. if err != nil {
  1229. br.Msg = `获取失败`
  1230. br.ErrMsg = `获取关联指标配置失败,ERR:` + err.Error()
  1231. return
  1232. }
  1233. edbInfoIdList := make([]int, 0)
  1234. edbMappingMap := make(map[int]*data_manage.MultipleGraphConfigEdbMapping)
  1235. for _, v := range edbMappingList {
  1236. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1237. edbMappingMap[v.EdbInfoId] = v
  1238. }
  1239. edbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1240. if err != nil {
  1241. br.Msg = `获取失败`
  1242. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1243. return
  1244. }
  1245. for _, v := range edbList {
  1246. if tmpInfo, ok := edbMappingMap[v.EdbInfoId]; ok {
  1247. multipleGraphConfigEdbMappingList = append(multipleGraphConfigEdbMappingList, response.MultipleGraphConfigEdbMapping{
  1248. EdbInfoId: tmpInfo.EdbInfoId,
  1249. Source: tmpInfo.Source,
  1250. MultipleLocationSource: tmpInfo.Source,
  1251. })
  1252. }
  1253. }
  1254. }
  1255. // 关联指标
  1256. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{multipleGraphConfig.EdbInfoIdA, multipleGraphConfig.EdbInfoIdB})
  1257. if err != nil {
  1258. br.Msg = "获取失败"
  1259. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1260. return
  1261. }
  1262. var config request.ConfigSave
  1263. err = json.Unmarshal([]byte(multipleGraphConfig.Curve), &config)
  1264. if err != nil {
  1265. br.Msg = `相关性配置异常`
  1266. br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
  1267. return
  1268. }
  1269. resp := response.MultipleGraphConfigDetailResp{
  1270. MultipleGraphConfigId: multipleGraphConfigChartMapping.MultipleGraphConfigId,
  1271. Curve: config.Curve,
  1272. StandardDeviation: config.StandardDeviation,
  1273. Percentile: config.Percentile,
  1274. FrequencyDistribution: config.FrequencyDistribution,
  1275. EdbInfoList: mappingList,
  1276. ChartMappingList: multipleGraphConfigChartMappingList,
  1277. EdbMappingList: multipleGraphConfigEdbMappingList,
  1278. }
  1279. br.Ret = 200
  1280. br.Success = true
  1281. br.Msg = "保存成功"
  1282. br.Data = resp
  1283. br.IsAddLog = true
  1284. }
  1285. // Move
  1286. // @Title 移动图表接口
  1287. // @Description 移动图表接口
  1288. // @Success 200 {object} data_manage.MoveChartInfoReq
  1289. // @router /chart_info/move [post]
  1290. func (this *LineFeaturesChartInfoController) Move() {
  1291. br := new(models.BaseResponse).Init()
  1292. defer func() {
  1293. this.Data["json"] = br
  1294. this.ServeJSON()
  1295. }()
  1296. sysUser := this.SysUser
  1297. if sysUser == nil {
  1298. br.Msg = "请登录"
  1299. br.ErrMsg = "请登录,SysUser Is Empty"
  1300. br.Ret = 408
  1301. return
  1302. }
  1303. var req data_manage.MoveChartInfoReq
  1304. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1305. if err != nil {
  1306. br.Msg = "参数解析异常!"
  1307. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1308. return
  1309. }
  1310. if req.ChartInfoId <= 0 {
  1311. br.Msg = "参数错误"
  1312. br.ErrMsg = "图表id小于等于0"
  1313. return
  1314. }
  1315. if req.ChartClassifyId <= 0 {
  1316. br.Msg = "请选择分类"
  1317. return
  1318. }
  1319. //判断分类是否存在
  1320. count, _ := data_manage.GetChartClassifyCountById(req.ChartClassifyId)
  1321. if count <= 0 {
  1322. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1323. return
  1324. }
  1325. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1326. if err != nil {
  1327. br.Msg = "移动失败"
  1328. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1329. return
  1330. }
  1331. if !utils.InArrayByInt([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, chartInfo.Source) {
  1332. br.Msg = "图表异常"
  1333. br.ErrMsg = "分类异常,不是统计特征的图表"
  1334. return
  1335. }
  1336. //如果改变了分类,那么移动该图表数据
  1337. if chartInfo.ChartClassifyId != req.ChartClassifyId {
  1338. //查询需要修改的分类下是否存在同一个图表名称
  1339. tmpChartInfo, tmpErr := data_manage.GetChartInfoByClassifyIdAndName(req.ChartClassifyId, chartInfo.ChartName)
  1340. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1341. br.Msg = "移动失败"
  1342. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1343. return
  1344. }
  1345. if tmpChartInfo != nil {
  1346. br.Msg = "移动失败,同一个分类下图表名称不允许重复"
  1347. br.ErrMsg = "移动失败,同一个分类下图表名称不允许重复"
  1348. return
  1349. }
  1350. err = data_manage.MoveChartInfo(req.ChartInfoId, req.ChartClassifyId)
  1351. if err != nil {
  1352. br.Msg = "移动失败"
  1353. br.ErrMsg = "移动失败,Err:" + err.Error()
  1354. return
  1355. }
  1356. }
  1357. //移动排序
  1358. updateCol := make([]string, 0)
  1359. //如果有传入 上一个兄弟节点分类id
  1360. if req.PrevChartInfoId > 0 {
  1361. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  1362. if err != nil {
  1363. br.Msg = "移动失败"
  1364. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1365. return
  1366. }
  1367. //如果是移动在两个兄弟节点之间
  1368. if req.NextChartInfoId > 0 {
  1369. //下一个兄弟节点
  1370. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  1371. if err != nil {
  1372. br.Msg = "移动失败"
  1373. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1374. return
  1375. }
  1376. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1377. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  1378. //变更兄弟节点的排序
  1379. updateSortStr := `sort + 2`
  1380. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1381. } else {
  1382. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1383. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1384. //变更兄弟节点的排序
  1385. updateSortStr := `sort + 1`
  1386. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1387. }
  1388. }
  1389. }
  1390. chartInfo.Sort = prevChartInfo.Sort + 1
  1391. chartInfo.ModifyTime = time.Now()
  1392. updateCol = append(updateCol, "Sort", "ModifyTime")
  1393. } else {
  1394. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(req.ChartClassifyId)
  1395. if err != nil && err.Error() != utils.ErrNoRow() {
  1396. br.Msg = "移动失败"
  1397. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1398. return
  1399. }
  1400. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1401. if firstClassify != nil && firstClassify.Sort == 0 {
  1402. updateSortStr := ` sort + 1 `
  1403. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1404. }
  1405. chartInfo.Sort = 0 //那就是排在第一位
  1406. chartInfo.ModifyTime = time.Now()
  1407. updateCol = append(updateCol, "Sort", "ModifyTime")
  1408. }
  1409. //更新
  1410. if len(updateCol) > 0 {
  1411. err = chartInfo.Update(updateCol)
  1412. if err != nil {
  1413. br.Msg = "移动失败"
  1414. br.ErrMsg = "修改失败,Err:" + err.Error()
  1415. return
  1416. }
  1417. }
  1418. if err != nil {
  1419. br.Msg = "移动失败"
  1420. br.ErrMsg = "修改失败,Err:" + err.Error()
  1421. return
  1422. }
  1423. //添加es数据
  1424. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  1425. //修改my eta es数据
  1426. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  1427. //新增操作日志
  1428. {
  1429. chartLog := new(data_manage.ChartInfoLog)
  1430. chartLog.ChartName = chartInfo.ChartName
  1431. chartLog.ChartInfoId = req.ChartInfoId
  1432. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1433. chartLog.SysUserId = sysUser.AdminId
  1434. chartLog.SysUserRealName = sysUser.RealName
  1435. chartLog.UniqueCode = chartInfo.UniqueCode
  1436. chartLog.CreateTime = time.Now()
  1437. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1438. chartLog.Status = "移动统计特征图表"
  1439. chartLog.Method = this.Ctx.Input.URL()
  1440. go data_manage.AddChartInfoLog(chartLog)
  1441. }
  1442. br.Ret = 200
  1443. br.Success = true
  1444. br.Msg = "移动成功"
  1445. }
  1446. // List
  1447. // @Title 统计特征图表列表接口
  1448. // @Description 统计特征图表列表接口
  1449. // @Param PageSize query int true "每页数据条数"
  1450. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1451. // @Param ChartClassifyId query int true "分类id"
  1452. // @Param Keyword query string true "搜索关键词"
  1453. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1454. // @Param Source query int true "图表类型,3:统计特征,4:滚动统计特征"
  1455. // @Success 200 {object} data_manage.ChartListResp
  1456. // @router /chart_info/list [get]
  1457. func (this *LineFeaturesChartInfoController) List() {
  1458. br := new(models.BaseResponse).Init()
  1459. defer func() {
  1460. this.Data["json"] = br
  1461. this.ServeJSON()
  1462. }()
  1463. sysUser := this.SysUser
  1464. if sysUser == nil {
  1465. br.Msg = "请登录"
  1466. br.ErrMsg = "请登录,SysUser Is Empty"
  1467. br.Ret = 408
  1468. return
  1469. }
  1470. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1471. pageSize, _ := this.GetInt("PageSize")
  1472. currentIndex, _ := this.GetInt("CurrentIndex")
  1473. keyword := this.GetString("KeyWord")
  1474. var total int
  1475. page := paging.GetPaging(currentIndex, pageSize, total)
  1476. var startSize int
  1477. if pageSize <= 0 {
  1478. pageSize = utils.PageSize20
  1479. }
  1480. if currentIndex <= 0 {
  1481. currentIndex = 1
  1482. }
  1483. startSize = paging.StartIndex(currentIndex, pageSize)
  1484. var condition string
  1485. var pars []interface{}
  1486. // 普通图表
  1487. condition += ` AND source in(?,?,?) `
  1488. pars = append(pars, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY)
  1489. if chartClassifyId > 0 {
  1490. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  1491. if err != nil && err.Error() != utils.ErrNoRow() {
  1492. br.Msg = "获取图表信息失败"
  1493. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1494. return
  1495. }
  1496. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  1497. }
  1498. if keyword != "" {
  1499. condition += ` AND ( chart_name LIKE '%` + keyword + `%' )`
  1500. }
  1501. //只看我的
  1502. isShowMe, _ := this.GetBool("IsShowMe")
  1503. if isShowMe {
  1504. condition += ` AND sys_user_id = ? `
  1505. pars = append(pars, sysUser.AdminId)
  1506. }
  1507. // 获取当前账号的不可见指标
  1508. noPermissionChartIdList := make([]int, 0)
  1509. {
  1510. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1511. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1512. if err != nil && err.Error() != utils.ErrNoRow() {
  1513. br.Msg = "获取失败"
  1514. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1515. return
  1516. }
  1517. for _, v := range confList {
  1518. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1519. }
  1520. }
  1521. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1522. if lenNoPermissionChartIdList > 0 {
  1523. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1524. pars = append(pars, noPermissionChartIdList)
  1525. }
  1526. //获取图表信息
  1527. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  1528. if err != nil && err.Error() != utils.ErrNoRow() {
  1529. br.Success = true
  1530. br.Msg = "获取图表信息失败"
  1531. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1532. return
  1533. }
  1534. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1535. if err != nil && err.Error() != utils.ErrNoRow() {
  1536. br.Msg = "获取图表信息失败"
  1537. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1538. return
  1539. }
  1540. myChartMap := make(map[int]*data_manage.MyChartView)
  1541. for _, v := range myChartList {
  1542. myChartMap[v.ChartInfoId] = v
  1543. }
  1544. listLen := len(list)
  1545. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1546. if listLen > 0 {
  1547. chartInfoIds := ""
  1548. for _, v := range list {
  1549. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1550. }
  1551. if chartInfoIds != "" {
  1552. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1553. //判断是否需要展示英文标识
  1554. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1555. if e != nil {
  1556. br.Msg = "获取失败"
  1557. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1558. return
  1559. }
  1560. for _, v := range edbList {
  1561. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1562. }
  1563. }
  1564. }
  1565. for i := 0; i < listLen; i++ {
  1566. //判断是否需要展示英文标识
  1567. if _, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1568. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, list[i].Source, list[i].ChartType)
  1569. }
  1570. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  1571. list[i].IsAdd = true
  1572. list[i].MyChartId = existItem.MyChartId
  1573. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  1574. }
  1575. }
  1576. resp := new(data_manage.ChartListResp)
  1577. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1578. items := make([]*data_manage.ChartInfoView, 0)
  1579. resp.Paging = page
  1580. resp.List = items
  1581. br.Ret = 200
  1582. br.Success = true
  1583. br.Msg = "获取成功"
  1584. return
  1585. }
  1586. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  1587. if err != nil && err.Error() != utils.ErrNoRow() {
  1588. br.Msg = "获取指标信息失败"
  1589. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1590. return
  1591. }
  1592. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1593. resp.Paging = page
  1594. resp.List = list
  1595. br.Ret = 200
  1596. br.Success = true
  1597. br.Msg = "获取成功"
  1598. br.Data = resp
  1599. }
  1600. // Detail
  1601. // @Title 获取图表详情
  1602. // @Description 获取图表详情接口
  1603. // @Param ChartInfoId query int true "图表id"
  1604. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1605. // @router /chart_info/detail [get]
  1606. func (this *LineFeaturesChartInfoController) Detail() {
  1607. br := new(models.BaseResponse).Init()
  1608. defer func() {
  1609. this.Data["json"] = br
  1610. this.ServeJSON()
  1611. }()
  1612. sysUser := this.SysUser
  1613. if sysUser == nil {
  1614. br.Msg = "请登录"
  1615. br.ErrMsg = "请登录,SysUser Is Empty"
  1616. br.Ret = 408
  1617. return
  1618. }
  1619. chartInfoId, _ := this.GetInt("ChartInfoId")
  1620. if chartInfoId <= 0 {
  1621. br.Msg = "参数有误"
  1622. return
  1623. }
  1624. var err error
  1625. chartInfo := new(data_manage.ChartInfoView)
  1626. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  1627. if err != nil {
  1628. if err.Error() == utils.ErrNoRow() {
  1629. br.Msg = "图被删除,请刷新页面"
  1630. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  1631. return
  1632. }
  1633. br.Msg = "获取失败"
  1634. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1635. return
  1636. }
  1637. if chartInfo.ExtraConfig == `` {
  1638. br.Msg = "获取失败"
  1639. br.ErrMsg = "获取配置信息失败,图表的额外配置信息为空"
  1640. return
  1641. }
  1642. // 获取主题样式
  1643. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  1644. if err != nil {
  1645. br.Msg = "获取失败"
  1646. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  1647. return
  1648. }
  1649. chartInfo.ChartThemeStyle = chartTheme.Config
  1650. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1651. // 获取图表关联指标
  1652. edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  1653. if err != nil {
  1654. br.Msg = "获取失败"
  1655. br.ErrMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  1656. return
  1657. }
  1658. if len(edbMappingList) != 1 {
  1659. br.Msg = "获取失败"
  1660. br.ErrMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  1661. return
  1662. }
  1663. edbMapping := edbMappingList[0]
  1664. var edbList []*data_manage.ChartEdbInfoMapping
  1665. var errMsg string
  1666. var resultResp interface{}
  1667. switch chartInfo.Source {
  1668. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
  1669. calculateValue, err := strconv.Atoi(chartInfo.ExtraConfig)
  1670. if err != nil {
  1671. br.Msg = "获取失败"
  1672. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1673. return
  1674. }
  1675. maxYear := 0
  1676. if edbMapping.LatestDate != "" {
  1677. latestDateT, _ := time.Parse(utils.FormatDate, edbMapping.LatestDate)
  1678. maxYear = latestDateT.Year()
  1679. }
  1680. startDate, endDate := utils.GetDateByDateTypeV2(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate, chartInfo.StartYear, maxYear)
  1681. edbList, resultResp, err, errMsg = lineFeatureServ.GetStandardDeviationData(0, startDate, endDate, edbMapping, calculateValue)
  1682. case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
  1683. var percentileConfig request.Percentile
  1684. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
  1685. if err != nil {
  1686. br.Msg = "获取失败"
  1687. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1688. return
  1689. }
  1690. maxYear := 0
  1691. if edbMapping.LatestDate != "" {
  1692. latestDateT, _ := time.Parse(utils.FormatDate, edbMapping.LatestDate)
  1693. maxYear = latestDateT.Year()
  1694. }
  1695. startDate, endDate := utils.GetDateByDateTypeV2(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate, chartInfo.StartYear, maxYear)
  1696. edbList, resultResp, err, errMsg = lineFeatureServ.GetPercentileData(0, startDate, endDate, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit, percentileConfig.PercentType)
  1697. case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  1698. var frequencyDistributionConfig request.FrequencyDistribution
  1699. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
  1700. if err != nil {
  1701. br.Msg = "获取失败"
  1702. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1703. return
  1704. }
  1705. // 获取图表中的指标数据
  1706. edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
  1707. default:
  1708. errMsg = `错误的图表`
  1709. err = errors.New(fmt.Sprint("错误的图表来源,source", chartInfo.Source))
  1710. }
  1711. if err != nil {
  1712. br.Msg = "获取失败"
  1713. if errMsg != `` {
  1714. br.Msg = errMsg
  1715. }
  1716. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1717. return
  1718. }
  1719. warnEdbList := make([]string, 0)
  1720. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  1721. for _, v := range edbList {
  1722. if v.IsNullData {
  1723. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1724. }
  1725. chartEdbInfoMapping := *v
  1726. chartEdbInfoMapping.IsOrder = false
  1727. chartEdbInfoMapping.IsAxis = 1
  1728. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  1729. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  1730. chartEdbInfoMapping.ChartColor = `#00F`
  1731. chartEdbInfoMapping.ChartWidth = 3
  1732. chartEdbInfoMapping.EdbInfoType = 1
  1733. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  1734. }
  1735. if len(warnEdbList) > 0 {
  1736. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1737. }
  1738. // 判断是否加入我的图库
  1739. if chartInfoId > 0 && chartInfo != nil {
  1740. {
  1741. var myChartCondition string
  1742. var myChartPars []interface{}
  1743. myChartCondition += ` AND a.admin_id=? `
  1744. myChartPars = append(myChartPars, sysUser.AdminId)
  1745. myChartCondition += ` AND a.chart_info_id=? `
  1746. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1747. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1748. if err != nil && err.Error() != utils.ErrNoRow() {
  1749. br.Msg = "获取失败"
  1750. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1751. return
  1752. }
  1753. if myChartList != nil && len(myChartList) > 0 {
  1754. chartInfo.IsAdd = true
  1755. chartInfo.MyChartId = myChartList[0].MyChartId
  1756. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1757. }
  1758. }
  1759. }
  1760. //图表操作权限
  1761. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1762. //判断是否需要展示英文标识
  1763. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  1764. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  1765. // 另存为
  1766. isSaveAs := true
  1767. chartInfo.Button = data_manage.ChartViewButton{
  1768. IsEdit: chartInfo.IsEdit,
  1769. IsEnChart: chartInfo.IsEnChart,
  1770. IsAdd: chartInfo.IsAdd,
  1771. IsCopy: isSaveAs,
  1772. IsSetName: chartInfo.IsSetName,
  1773. }
  1774. chartInfo.HaveOperaAuth = true
  1775. // 指标权限
  1776. {
  1777. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  1778. classifyMap := make(map[int]*data_manage.EdbClassify)
  1779. // 分类
  1780. {
  1781. classifyIdList := make([]int, 0)
  1782. for _, v := range edbList {
  1783. classifyIdList = append(classifyIdList, v.ClassifyId)
  1784. }
  1785. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1786. if tmpErr != nil {
  1787. br.Msg = "获取失败"
  1788. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1789. return
  1790. }
  1791. for _, v := range classifyList {
  1792. classifyMap[v.ClassifyId] = v
  1793. }
  1794. }
  1795. // 遍历到校验map
  1796. for _, v := range edbList {
  1797. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  1798. ClassifyId: v.ClassifyId,
  1799. IsJoinPermission: v.IsJoinPermission,
  1800. EdbInfoId: v.EdbInfoId,
  1801. }
  1802. }
  1803. // 获取所有有权限的指标和分类
  1804. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1805. if err != nil {
  1806. br.Msg = "获取失败"
  1807. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1808. return
  1809. }
  1810. for _, v := range edbList {
  1811. // 数据权限
  1812. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  1813. if !ok {
  1814. continue
  1815. }
  1816. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  1817. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1818. }
  1819. }
  1820. }
  1821. resp := new(data_manage.ChartInfoDetailResp)
  1822. resp.ChartInfo = chartInfo
  1823. resp.EdbInfoList = edbList
  1824. resp.DataResp = resultResp
  1825. br.Ret = 200
  1826. br.Success = true
  1827. br.Msg = "获取成功"
  1828. br.Data = resp
  1829. }
  1830. // DetailFromUniqueCode
  1831. // @Title 根据编码获取图表详情
  1832. // @Description 根据编码获取图表详情接口
  1833. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  1834. // @Param IsCache query bool true "是否走缓存,默认false"
  1835. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  1836. // @router /chart_info/detail/from_unique_code [get]
  1837. func (this *LineFeaturesChartInfoController) DetailFromUniqueCode() {
  1838. br := new(models.BaseResponse).Init()
  1839. defer func() {
  1840. this.Data["json"] = br
  1841. this.ServeJSON()
  1842. }()
  1843. sysUser := this.SysUser
  1844. if sysUser == nil {
  1845. br.Msg = "请登录"
  1846. br.ErrMsg = "请登录,SysUser Is Empty"
  1847. br.Ret = 408
  1848. return
  1849. }
  1850. adminId := sysUser.AdminId
  1851. uniqueCode := this.GetString("UniqueCode")
  1852. if uniqueCode == "" {
  1853. br.Msg = "参数错误"
  1854. br.ErrMsg = "参数错误,uniqueCode is empty"
  1855. return
  1856. }
  1857. //是否走缓存
  1858. isCache, _ := this.GetBool("IsCache")
  1859. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  1860. status := true
  1861. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1862. if err != nil {
  1863. if err.Error() == utils.ErrNoRow() {
  1864. status = false
  1865. } else {
  1866. br.Msg = "获取失败"
  1867. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1868. return
  1869. }
  1870. }
  1871. if chartInfo == nil {
  1872. status = false
  1873. }
  1874. if !status {
  1875. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  1876. resp.EdbInfoList = endInfoList
  1877. resp.ChartInfo = chartInfo
  1878. resp.Status = false
  1879. br.Ret = 200
  1880. br.Success = true
  1881. br.Msg = "获取成功"
  1882. br.Data = resp
  1883. return
  1884. }
  1885. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  1886. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  1887. if utils.Re == nil && isCache {
  1888. if utils.Re == nil && utils.Rc.IsExist(key) {
  1889. if d, e := utils.Rc.RedisBytes(key); e == nil {
  1890. err := json.Unmarshal(d, &resp)
  1891. if err == nil && resp != nil {
  1892. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  1893. var myCond string
  1894. var myPars []interface{}
  1895. myCond += ` AND a.admin_id=? `
  1896. myPars = append(myPars, adminId)
  1897. myCond += ` AND a.chart_info_id=? `
  1898. myPars = append(myPars, chartInfo.ChartInfoId)
  1899. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  1900. if err != nil && err.Error() != utils.ErrNoRow() {
  1901. br.Msg = "获取失败"
  1902. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1903. return
  1904. }
  1905. resp.ChartInfo.IsAdd = false
  1906. resp.ChartInfo.MyChartId = 0
  1907. resp.ChartInfo.MyChartClassifyId = ""
  1908. if myList != nil && len(myList) > 0 {
  1909. resp.ChartInfo.IsAdd = true
  1910. resp.ChartInfo.MyChartId = myList[0].MyChartId
  1911. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  1912. }
  1913. br.Ret = 200
  1914. br.Success = true
  1915. br.Msg = "获取成功"
  1916. br.Data = resp
  1917. return
  1918. }
  1919. }
  1920. }
  1921. }
  1922. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  1923. if !isOk {
  1924. br.Msg = msg
  1925. br.ErrMsg = errMsg
  1926. return
  1927. }
  1928. if !isOk {
  1929. br.Msg = msg
  1930. br.ErrMsg = errMsg
  1931. return
  1932. }
  1933. br.Ret = 200
  1934. br.Success = true
  1935. br.Msg = "获取成功"
  1936. br.Data = resp
  1937. }
  1938. // Refresh
  1939. // @Title 图表刷新接口
  1940. // @Description 图表刷新接口
  1941. // @Param ChartInfoId query int true "图表id"
  1942. // @Param UniqueCode query string true "唯一code"
  1943. // @Success Ret=200 刷新成功
  1944. // @router /chart_info/refresh [get]
  1945. func (this *LineFeaturesChartInfoController) Refresh() {
  1946. br := new(models.BaseResponse).Init()
  1947. defer func() {
  1948. this.Data["json"] = br
  1949. this.ServeJSON()
  1950. }()
  1951. sysUser := this.SysUser
  1952. if sysUser == nil {
  1953. br.Msg = "请登录"
  1954. br.ErrMsg = "请登录,SysUser Is Empty"
  1955. br.Ret = 408
  1956. return
  1957. }
  1958. chartInfoId, _ := this.GetInt("ChartInfoId")
  1959. uniqueCode := this.GetString("UniqueCode")
  1960. if chartInfoId <= 0 && uniqueCode == `` {
  1961. br.Msg = "参数错误"
  1962. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  1963. return
  1964. }
  1965. var chartInfo *data_manage.ChartInfo
  1966. var err error
  1967. if chartInfoId > 0 {
  1968. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  1969. } else {
  1970. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  1971. }
  1972. if err != nil {
  1973. if err.Error() == utils.ErrNoRow() {
  1974. br.Msg = "图表已被删除,无需刷新"
  1975. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1976. return
  1977. }
  1978. br.Msg = "刷新失败"
  1979. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1980. return
  1981. }
  1982. // 刷新图表的指标信息
  1983. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  1984. //清除图表缓存
  1985. {
  1986. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1987. _ = utils.Rc.Delete(key)
  1988. }
  1989. br.Ret = 200
  1990. br.Success = true
  1991. br.Msg = "刷新成功"
  1992. if isAsync {
  1993. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  1994. }
  1995. }
  1996. // Copy
  1997. // @Title 复制并新增图表接口
  1998. // @Description 复制并新增图表接口
  1999. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  2000. // @Success 200 {object} data_manage.AddChartInfoResp
  2001. // @router /chart_info/copy [post]
  2002. func (this *LineFeaturesChartInfoController) Copy() {
  2003. br := new(models.BaseResponse).Init()
  2004. defer func() {
  2005. this.Data["json"] = br
  2006. this.ServeJSON()
  2007. }()
  2008. sysUser := this.SysUser
  2009. if sysUser == nil {
  2010. br.Msg = "请登录"
  2011. br.ErrMsg = "请登录,SysUser Is Empty"
  2012. br.Ret = 408
  2013. return
  2014. }
  2015. deleteCache := true
  2016. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2017. defer func() {
  2018. if deleteCache {
  2019. utils.Rc.Delete(cacheKey)
  2020. }
  2021. }()
  2022. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2023. deleteCache = false
  2024. br.Msg = "系统处理中,请稍后重试!"
  2025. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2026. return
  2027. }
  2028. var req data_manage.CopyAddChartInfoReq
  2029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2030. if err != nil {
  2031. br.Msg = "参数解析异常!"
  2032. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2033. return
  2034. }
  2035. // 获取原图表信息
  2036. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2037. if err != nil {
  2038. br.Msg = "获取原图表信息失败"
  2039. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  2040. return
  2041. }
  2042. if !utils.InArrayByInt([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, oldChartInfo.Source) {
  2043. br.Msg = `错误的图表类型`
  2044. br.IsSendEmail = false
  2045. return
  2046. }
  2047. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(oldChartInfo.ChartInfoId)
  2048. if err != nil && err.Error() != utils.ErrNoRow() {
  2049. br.Msg = `保存失败`
  2050. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  2051. return
  2052. }
  2053. // 获取图表关联指标
  2054. edbMappingList, err := data_manage.GetChartEdbMappingList(oldChartInfo.ChartInfoId)
  2055. if err != nil {
  2056. br.Msg = "获取失败"
  2057. br.ErrMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  2058. return
  2059. }
  2060. if len(edbMappingList) != 1 {
  2061. br.Msg = "获取失败"
  2062. br.ErrMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  2063. return
  2064. }
  2065. edbInfoMapping := edbMappingList[0]
  2066. // 批量设置图
  2067. chartInfo, err, errMsg, isSendEmail := lineFeatureServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, multipleGraphConfigChartMapping.Source, req.ChartClassifyId, req.ChartName, edbInfoMapping, oldChartInfo, sysUser, this.Lang)
  2068. if err != nil {
  2069. br.Msg = "复制失败"
  2070. if errMsg != `` {
  2071. br.Msg = errMsg
  2072. }
  2073. br.ErrMsg = "复制失败,ERR:" + err.Error()
  2074. br.IsSendEmail = isSendEmail
  2075. return
  2076. }
  2077. resp := data_manage.AddChartInfoResp{
  2078. ChartInfoId: chartInfo.ChartInfoId,
  2079. UniqueCode: chartInfo.UniqueCode,
  2080. ChartType: chartInfo.ChartType,
  2081. }
  2082. //新增操作日志
  2083. {
  2084. chartLog := new(data_manage.ChartInfoLog)
  2085. chartLog.ChartInfoId = chartInfo.ChartInfoId
  2086. chartLog.ChartName = chartInfo.ChartName
  2087. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  2088. chartLog.SysUserId = sysUser.AdminId
  2089. chartLog.SysUserRealName = sysUser.RealName
  2090. chartLog.UniqueCode = chartInfo.UniqueCode
  2091. chartLog.CreateTime = time.Now()
  2092. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2093. chartLog.Status = "新增统计特征图表"
  2094. chartLog.Method = this.Ctx.Input.URI()
  2095. go data_manage.AddChartInfoLog(chartLog)
  2096. }
  2097. br.Ret = 200
  2098. br.Data = resp
  2099. br.Success = true
  2100. br.Msg = "保存成功"
  2101. br.IsAddLog = true
  2102. }
  2103. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  2104. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  2105. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2106. adminId := sysUser.AdminId
  2107. // 指标数据map
  2108. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  2109. defer func() {
  2110. if isOk {
  2111. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  2112. {
  2113. //判断是否加入我的图库
  2114. var myChartCondition string
  2115. var myChartPars []interface{}
  2116. myChartCondition += ` AND a.admin_id=? `
  2117. myChartPars = append(myChartPars, adminId)
  2118. myChartCondition += ` AND a.chart_info_id=? `
  2119. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2120. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2121. if err != nil && err.Error() != utils.ErrNoRow() {
  2122. msg = "获取失败"
  2123. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2124. return
  2125. }
  2126. if myChartList != nil && len(myChartList) > 0 {
  2127. chartInfo.IsAdd = true
  2128. chartInfo.MyChartId = myChartList[0].MyChartId
  2129. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2130. }
  2131. }
  2132. resp.ChartInfo.HaveOperaAuth = true
  2133. // 指标权限
  2134. {
  2135. classifyMap := make(map[int]*data_manage.EdbClassify)
  2136. // 分类
  2137. {
  2138. classifyIdList := make([]int, 0)
  2139. for _, v := range resp.EdbInfoList {
  2140. classifyIdList = append(classifyIdList, v.ClassifyId)
  2141. }
  2142. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  2143. if tmpErr != nil {
  2144. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  2145. return
  2146. }
  2147. for _, v := range classifyList {
  2148. classifyMap[v.ClassifyId] = v
  2149. }
  2150. }
  2151. // 指标
  2152. if len(edbClassifyPermissionMap) < 0 {
  2153. edbInfoIdList := make([]int, 0)
  2154. for _, v := range resp.EdbInfoList {
  2155. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  2156. }
  2157. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  2158. if tmpErr != nil {
  2159. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  2160. return
  2161. }
  2162. for _, v := range edbInfoList {
  2163. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2164. ClassifyId: v.ClassifyId,
  2165. IsJoinPermission: v.IsJoinPermission,
  2166. EdbInfoId: v.EdbInfoId,
  2167. }
  2168. }
  2169. }
  2170. // 获取所有有权限的指标和分类
  2171. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2172. if err != nil {
  2173. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  2174. return
  2175. }
  2176. for _, v := range resp.EdbInfoList {
  2177. // 数据权限
  2178. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  2179. if !ok {
  2180. continue
  2181. }
  2182. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  2183. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  2184. }
  2185. }
  2186. }
  2187. }
  2188. if !isOk {
  2189. if errMsg != "" {
  2190. uniqueCode := ""
  2191. if chartInfo != nil {
  2192. uniqueCode = chartInfo.UniqueCode
  2193. }
  2194. tmpTip := fmt.Sprintf("查询图表详情失败,line_feature.GetChartInfoDetailFromUniqueCode UniqueCode:%s,err:%s", uniqueCode, errMsg)
  2195. utils.FileLog.Info(tmpTip)
  2196. go alarm_msg.SendAlarmMsg(tmpTip, 3)
  2197. }
  2198. }
  2199. }()
  2200. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  2201. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  2202. if utils.Re == nil && isCache {
  2203. if utils.Re == nil && utils.Rc.IsExist(key) {
  2204. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  2205. err := json.Unmarshal(chartData, &resp)
  2206. if err != nil || resp == nil {
  2207. return
  2208. }
  2209. isOk = true
  2210. fmt.Println("source redis")
  2211. return
  2212. }
  2213. }
  2214. }
  2215. // 获取主题样式
  2216. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  2217. if err != nil {
  2218. msg = "获取失败"
  2219. errMsg = "获取主题信息失败,Err:" + err.Error()
  2220. return
  2221. }
  2222. chartInfo.ChartThemeStyle = chartTheme.Config
  2223. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  2224. if chartInfo.ExtraConfig == `` {
  2225. msg = "获取失败"
  2226. errMsg = "获取配置信息失败,图表的额外配置信息为空"
  2227. return
  2228. }
  2229. // 获取图表关联指标
  2230. edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfo.ChartInfoId)
  2231. if err != nil {
  2232. msg = "获取失败"
  2233. errMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  2234. return
  2235. }
  2236. if len(edbMappingList) != 1 {
  2237. msg = "获取失败"
  2238. errMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  2239. return
  2240. }
  2241. edbMapping := edbMappingList[0]
  2242. var edbList []*data_manage.ChartEdbInfoMapping
  2243. var resultResp interface{}
  2244. switch chartInfo.Source {
  2245. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
  2246. calculateValue, tmpErr := strconv.Atoi(chartInfo.ExtraConfig)
  2247. if tmpErr != nil {
  2248. msg = "获取失败"
  2249. errMsg = "格式化配置项失败,Err:" + tmpErr.Error()
  2250. return
  2251. }
  2252. maxYear := 0
  2253. if edbMapping.LatestDate != "" {
  2254. latestDateT, _ := time.Parse(utils.FormatDate, edbMapping.LatestDate)
  2255. maxYear = latestDateT.Year()
  2256. }
  2257. startDate, endDate := utils.GetDateByDateTypeV2(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate, chartInfo.StartYear, maxYear)
  2258. edbList, resultResp, err, msg = lineFeatureServ.GetStandardDeviationData(0, startDate, endDate, edbMapping, calculateValue)
  2259. case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
  2260. var percentileConfig request.Percentile
  2261. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
  2262. if err != nil {
  2263. msg = "获取失败"
  2264. errMsg = "格式化配置项失败,Err:" + err.Error()
  2265. return
  2266. }
  2267. maxYear := 0
  2268. if edbMapping.LatestDate != "" {
  2269. latestDateT, _ := time.Parse(utils.FormatDate, edbMapping.LatestDate)
  2270. maxYear = latestDateT.Year()
  2271. }
  2272. startDate, endDate := utils.GetDateByDateTypeV2(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate, chartInfo.StartYear, maxYear)
  2273. edbList, resultResp, err, msg = lineFeatureServ.GetPercentileData(0, startDate, endDate, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit, percentileConfig.PercentType)
  2274. case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  2275. var frequencyDistributionConfig request.FrequencyDistribution
  2276. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
  2277. if err != nil {
  2278. msg = "获取失败"
  2279. errMsg = "格式化配置项失败,Err:" + err.Error()
  2280. return
  2281. }
  2282. // 获取图表中的指标数据
  2283. edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
  2284. default:
  2285. msg = `错误的图表`
  2286. errMsg = fmt.Sprint("错误的图表来源,source", chartInfo.Source)
  2287. return
  2288. }
  2289. if err != nil {
  2290. if msg == `` {
  2291. msg = "获取失败"
  2292. }
  2293. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2294. return
  2295. }
  2296. if chartInfo.ChartInfoId > 0 && chartInfo != nil {
  2297. //判断是否加入我的图库
  2298. {
  2299. var myChartCondition string
  2300. var myChartPars []interface{}
  2301. myChartCondition += ` AND a.admin_id=? `
  2302. myChartPars = append(myChartPars, sysUser.AdminId)
  2303. myChartCondition += ` AND a.chart_info_id=? `
  2304. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2305. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2306. if err != nil && err.Error() != utils.ErrNoRow() {
  2307. msg = "获取失败"
  2308. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2309. return
  2310. }
  2311. if myChartList != nil && len(myChartList) > 0 {
  2312. chartInfo.IsAdd = true
  2313. chartInfo.MyChartId = myChartList[0].MyChartId
  2314. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2315. }
  2316. }
  2317. }
  2318. //图表操作权限
  2319. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  2320. //判断是否需要展示英文标识
  2321. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  2322. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  2323. isSaveAs := true
  2324. // 另存为
  2325. chartInfo.Button = data_manage.ChartViewButton{
  2326. IsEdit: chartInfo.IsEdit,
  2327. IsEnChart: chartInfo.IsEnChart,
  2328. IsAdd: chartInfo.IsAdd,
  2329. IsCopy: isSaveAs,
  2330. IsSetName: chartInfo.IsSetName,
  2331. }
  2332. // 图表的指标来源
  2333. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2334. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2335. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2336. resp.ChartInfo = chartInfo
  2337. resp.EdbInfoList = edbList
  2338. resp.DataResp = resultResp
  2339. resp.Status = true
  2340. // 遍历到校验map
  2341. for _, v := range edbList {
  2342. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2343. ClassifyId: v.ClassifyId,
  2344. IsJoinPermission: v.IsJoinPermission,
  2345. EdbInfoId: v.EdbInfoId,
  2346. }
  2347. }
  2348. // 将数据加入缓存
  2349. if utils.Re == nil {
  2350. d, _ := json.Marshal(resp)
  2351. _ = utils.Rc.Put(key, d, 2*time.Hour)
  2352. }
  2353. isOk = true
  2354. return
  2355. }
  2356. // EnInfoEdit
  2357. // @Title 编辑图表英文信息接口
  2358. // @Description 编辑图表英文信息接口
  2359. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  2360. // @Success Ret=200 编辑成功
  2361. // @router /chart_info/en/edit [post]
  2362. func (this *LineFeaturesChartInfoController) EnInfoEdit() {
  2363. br := new(models.BaseResponse).Init()
  2364. defer func() {
  2365. this.Data["json"] = br
  2366. this.ServeJSON()
  2367. }()
  2368. sysUser := this.SysUser
  2369. if sysUser == nil {
  2370. br.Msg = "请登录"
  2371. br.ErrMsg = "请登录,SysUser Is Empty"
  2372. br.Ret = 408
  2373. return
  2374. }
  2375. var req request.EditChartEnInfoReq
  2376. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2377. if err != nil {
  2378. br.Msg = "参数解析异常!"
  2379. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2380. return
  2381. }
  2382. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  2383. if req.ChartInfoId <= 0 {
  2384. br.Msg = "请选择图表"
  2385. return
  2386. }
  2387. if req.ChartNameEn == "" {
  2388. br.Msg = "请输入英文图表名称"
  2389. return
  2390. }
  2391. //判断指标名称是否存在
  2392. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2393. if err != nil {
  2394. if err.Error() == utils.ErrNoRow() {
  2395. br.Msg = "图表已被删除,请刷新页面"
  2396. br.ErrMsg = "图表已被删除,请刷新页面"
  2397. return
  2398. }
  2399. br.Msg = "获取图表信息失败"
  2400. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2401. return
  2402. }
  2403. // 校验名称是否有重复
  2404. {
  2405. var condition string
  2406. var pars []interface{}
  2407. condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source in (?,?,?)"
  2408. pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY)
  2409. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  2410. if err != nil {
  2411. if err.Error() != utils.ErrNoRow() {
  2412. br.Msg = "判断英文图表名称是否存在失败"
  2413. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  2414. return
  2415. }
  2416. }
  2417. if err == nil && existItem.ChartInfoId > 0 {
  2418. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  2419. return
  2420. }
  2421. }
  2422. chartItem.ChartNameEn = req.ChartNameEn
  2423. chartItem.ModifyTime = time.Now().Local()
  2424. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  2425. br.Msg = "操作失败"
  2426. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  2427. return
  2428. }
  2429. //添加es数据
  2430. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  2431. //修改my eta es数据
  2432. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  2433. //指标 修改es信息
  2434. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2435. //新增操作日志
  2436. {
  2437. chartLog := new(data_manage.ChartInfoLog)
  2438. chartLog.ChartName = chartItem.ChartName
  2439. chartLog.ChartInfoId = req.ChartInfoId
  2440. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  2441. chartLog.SysUserId = sysUser.AdminId
  2442. chartLog.SysUserRealName = sysUser.RealName
  2443. chartLog.UniqueCode = chartItem.UniqueCode
  2444. chartLog.CreateTime = time.Now()
  2445. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2446. chartLog.Status = "编辑统计特征图表英文信息"
  2447. chartLog.Method = this.Ctx.Input.URL()
  2448. go data_manage.AddChartInfoLog(chartLog)
  2449. }
  2450. // 清除缓存
  2451. if utils.Re == nil && utils.Rc != nil {
  2452. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  2453. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  2454. }
  2455. br.Ret = 200
  2456. br.Success = true
  2457. br.Msg = "编辑成功"
  2458. br.IsAddLog = true
  2459. }
  2460. // SearchByEs
  2461. // @Title 图表模糊搜索(从es获取)
  2462. // @Description 图表模糊搜索(从es获取)
  2463. // @Param Keyword query string true "图表名称"
  2464. // @Param IsShowMe query bool true "是否只看我的,true、false"
  2465. // @Param Source query int true "来源,3:统计特征,4:滚动统计特征,默认0:全部"
  2466. // @Success 200 {object} data_manage.ChartInfo
  2467. // @router /chart_info/search_by_es [get]
  2468. func (this *LineFeaturesChartInfoController) SearchByEs() {
  2469. br := new(models.BaseResponse).Init()
  2470. defer func() {
  2471. this.Data["json"] = br
  2472. this.ServeJSON()
  2473. }()
  2474. sysUser := this.SysUser
  2475. if sysUser == nil {
  2476. br.Msg = "请登录"
  2477. br.ErrMsg = "请登录,SysUser Is Empty"
  2478. br.Ret = 408
  2479. return
  2480. }
  2481. pageSize, _ := this.GetInt("PageSize")
  2482. currentIndex, _ := this.GetInt("CurrentIndex")
  2483. var startSize int
  2484. if pageSize <= 0 {
  2485. pageSize = utils.PageSize20
  2486. }
  2487. if currentIndex <= 0 {
  2488. currentIndex = 1
  2489. }
  2490. startSize = paging.StartIndex(currentIndex, pageSize)
  2491. keyword := this.GetString("Keyword")
  2492. //只看我的
  2493. isShowMe, _ := this.GetBool("IsShowMe")
  2494. showSysId := 0
  2495. if isShowMe {
  2496. showSysId = sysUser.AdminId
  2497. }
  2498. sourceList := []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}
  2499. var searchList []*data_manage.ChartInfo
  2500. var total int64
  2501. var err error
  2502. // 获取当前账号的不可见指标
  2503. noPermissionChartIdList := make([]int, 0)
  2504. {
  2505. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2506. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  2507. if err != nil && err.Error() != utils.ErrNoRow() {
  2508. br.Msg = "获取失败"
  2509. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2510. return
  2511. }
  2512. for _, v := range confList {
  2513. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  2514. }
  2515. }
  2516. if keyword != "" {
  2517. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  2518. } else {
  2519. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  2520. if err != nil && err.Error() != utils.ErrNoRow() {
  2521. br.Msg = "获取失败"
  2522. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2523. return
  2524. }
  2525. }
  2526. finalList := make([]*data_manage.ChartInfoMore, 0)
  2527. if len(searchList) > 0 {
  2528. chartInfoIds := ""
  2529. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  2530. for _, v := range searchList {
  2531. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  2532. }
  2533. if chartInfoIds != "" {
  2534. chartInfoIds = strings.Trim(chartInfoIds, ",")
  2535. //判断是否需要展示英文标识
  2536. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  2537. if e != nil {
  2538. br.Msg = "获取失败"
  2539. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  2540. return
  2541. }
  2542. for _, v := range edbList {
  2543. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  2544. }
  2545. }
  2546. for _, v := range searchList {
  2547. tmp := new(data_manage.ChartInfoMore)
  2548. tmp.ChartInfo = *v
  2549. // 图表数据权限
  2550. tmp.HaveOperaAuth = true
  2551. //判断是否需要展示英文标识
  2552. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  2553. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  2554. }
  2555. finalList = append(finalList, tmp)
  2556. }
  2557. }
  2558. //新增搜索词记录
  2559. {
  2560. searchKeyword := new(data_manage.SearchKeyword)
  2561. searchKeyword.KeyWord = keyword
  2562. searchKeyword.CreateTime = time.Now()
  2563. go data_manage.AddSearchKeyword(searchKeyword)
  2564. }
  2565. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2566. resp := data_manage.ChartInfoListByEsResp{
  2567. Paging: page,
  2568. List: finalList,
  2569. }
  2570. br.Ret = 200
  2571. br.Success = true
  2572. br.Msg = "获取成功"
  2573. br.Data = resp
  2574. }
  2575. // BaseInfoEdit
  2576. // @Title 编辑图表基础信息接口
  2577. // @Description 编辑图表基础信息接口
  2578. // @Param request body data_manage.EditChartInfoBaseReq true "type json string"
  2579. // @Success Ret=200 编辑成功
  2580. // @router /chart_info/base/edit [post]
  2581. func (this *LineFeaturesChartInfoController) BaseInfoEdit() {
  2582. br := new(models.BaseResponse).Init()
  2583. defer func() {
  2584. this.Data["json"] = br
  2585. this.ServeJSON()
  2586. }()
  2587. sysUser := this.SysUser
  2588. if sysUser == nil {
  2589. br.Msg = "请登录"
  2590. br.ErrMsg = "请登录,SysUser Is Empty"
  2591. br.Ret = 408
  2592. return
  2593. }
  2594. var req request.EditChartInfoBaseReq
  2595. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2596. if err != nil {
  2597. br.Msg = "参数解析异常!"
  2598. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2599. return
  2600. }
  2601. req.ChartName = strings.Trim(req.ChartName, " ")
  2602. if req.ChartInfoId <= 0 {
  2603. br.Msg = "请选择图表"
  2604. return
  2605. }
  2606. if req.ChartName == "" {
  2607. br.Msg = "请输入英文图表名称"
  2608. return
  2609. }
  2610. //判断指标名称是否存在
  2611. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2612. if err != nil {
  2613. if err.Error() == utils.ErrNoRow() {
  2614. br.Msg = "图表已被删除,请刷新页面"
  2615. br.ErrMsg = "图表已被删除,请刷新页面"
  2616. return
  2617. }
  2618. br.Msg = "获取图表信息失败"
  2619. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2620. return
  2621. }
  2622. // 校验名称是否有重复
  2623. {
  2624. var condition string
  2625. var pars []interface{}
  2626. condition += " AND chart_info_id <> ? AND source in (?,?,?) "
  2627. pars = append(pars, req.ChartInfoId, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY)
  2628. switch this.Lang {
  2629. case utils.EnLangVersion:
  2630. condition += " AND chart_name_en = ? "
  2631. default:
  2632. condition += " AND chart_name = ? "
  2633. }
  2634. pars = append(pars, req.ChartName)
  2635. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  2636. if err != nil {
  2637. if err.Error() != utils.ErrNoRow() {
  2638. br.Msg = "判断英文图表名称是否存在失败"
  2639. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  2640. return
  2641. }
  2642. }
  2643. if err == nil && existItem.ChartInfoId > 0 {
  2644. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  2645. return
  2646. }
  2647. }
  2648. switch this.Lang {
  2649. case utils.EnLangVersion:
  2650. chartItem.ChartNameEn = req.ChartName
  2651. default:
  2652. chartItem.ChartName = req.ChartName
  2653. }
  2654. chartItem.ModifyTime = time.Now().Local()
  2655. if e := chartItem.Update([]string{"ChartName", "ChartNameEn", "ModifyTime"}); e != nil {
  2656. br.Msg = "操作失败"
  2657. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  2658. return
  2659. }
  2660. //添加es数据
  2661. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  2662. //修改my eta es数据
  2663. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  2664. //新增操作日志
  2665. {
  2666. chartLog := new(data_manage.ChartInfoLog)
  2667. chartLog.ChartName = chartItem.ChartName
  2668. chartLog.ChartInfoId = req.ChartInfoId
  2669. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  2670. chartLog.SysUserId = sysUser.AdminId
  2671. chartLog.SysUserRealName = sysUser.RealName
  2672. chartLog.UniqueCode = chartItem.UniqueCode
  2673. chartLog.CreateTime = time.Now()
  2674. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2675. chartLog.Status = "编辑统计特征图表基础信息"
  2676. chartLog.Method = this.Ctx.Input.URL()
  2677. go data_manage.AddChartInfoLog(chartLog)
  2678. }
  2679. // 清除缓存
  2680. if utils.Re == nil && utils.Rc != nil {
  2681. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  2682. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  2683. }
  2684. br.Ret = 200
  2685. br.Success = true
  2686. br.Msg = "编辑成功"
  2687. br.IsAddLog = true
  2688. }