chart_info.go 93 KB

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