chart_info.go 92 KB

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