chart_info.go 92 KB

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