chart_info.go 85 KB

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