chart_info.go 87 KB

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