chart_info.go 92 KB

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