chart_info.go 86 KB

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