chart_info.go 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/response"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services"
  10. "eta_gn/eta_api/services/data"
  11. "eta_gn/eta_api/services/data/data_manage_permission"
  12. "eta_gn/eta_api/services/data/excel"
  13. "eta_gn/eta_api/services/eta_forum"
  14. "eta_gn/eta_api/utils"
  15. "fmt"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "os"
  18. "os/exec"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. type ChartInfoController struct {
  24. controllers.BaseAuthController
  25. }
  26. // @router /chart_info/save [post]
  27. func (this *ChartInfoController) ChartInfoSave() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. var req data_manage.SaveChartInfoReq
  41. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  42. if err != nil {
  43. br.Msg = "参数解析异常!"
  44. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  45. return
  46. }
  47. if req.ChartInfoId > 0 && len(req.ChartEdbInfoList) <= 0 {
  48. br.Msg = "参数错误!"
  49. return
  50. }
  51. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  52. if err != nil {
  53. if utils.IsErrNoRow(err) {
  54. br.Msg = "图表已被删除,请刷新页面!"
  55. br.ErrMsg = "图表已被删除,请刷新页面,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  56. return
  57. }
  58. br.Msg = "获取图表信息失败!"
  59. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  60. return
  61. }
  62. if req.Calendar == "" {
  63. req.Calendar = "公历"
  64. }
  65. err = data_manage.ModifyChartInfoAndMapping(chartItem.EdbInfoIds, &req, chartItem.ChartType)
  66. if err != nil {
  67. br.Msg = "保存失败"
  68. br.ErrMsg = "保存失败,Err:" + err.Error()
  69. return
  70. }
  71. key := utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode
  72. if utils.Re == nil && utils.Rc != nil {
  73. utils.Rc.Delete(key)
  74. }
  75. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  76. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  77. {
  78. chartLog := new(data_manage.ChartInfoLog)
  79. chartLog.ChartName = chartItem.ChartName
  80. chartLog.ChartInfoId = req.ChartInfoId
  81. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  82. chartLog.SysUserId = sysUser.AdminId
  83. chartLog.SysUserRealName = sysUser.RealName
  84. chartLog.UniqueCode = chartItem.UniqueCode
  85. chartLog.CreateTime = time.Now()
  86. chartLog.Content = string(this.Ctx.Input.RequestBody)
  87. chartLog.Status = "修改配置项"
  88. chartLog.Method = this.Ctx.Input.URI()
  89. go data_manage.AddChartInfoLog(chartLog)
  90. }
  91. br.Ret = 200
  92. br.Success = true
  93. br.Msg = "保存成功"
  94. br.IsAddLog = true
  95. }
  96. // @router /chart_info/add [post]
  97. func (this *ChartInfoController) ChartInfoAdd() {
  98. br := new(models.BaseResponse).Init()
  99. defer func() {
  100. this.Data["json"] = br
  101. this.ServeJSON()
  102. }()
  103. sysUser := this.SysUser
  104. if sysUser == nil {
  105. br.Msg = "请登录"
  106. br.ErrMsg = "请登录,SysUser Is Empty"
  107. br.Ret = 408
  108. return
  109. }
  110. deleteCache := true
  111. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  112. defer func() {
  113. if deleteCache {
  114. utils.Rc.Delete(cacheKey)
  115. }
  116. }()
  117. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  118. deleteCache = false
  119. br.Msg = "系统处理中,请稍后重试!"
  120. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  121. return
  122. }
  123. var req data_manage.AddChartInfoReq
  124. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  125. if err != nil {
  126. br.Msg = "参数解析异常!"
  127. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  128. return
  129. }
  130. req.ChartName = strings.Trim(req.ChartName, " ")
  131. if req.ChartName == "" {
  132. br.Msg = "请填写图表名称!"
  133. return
  134. }
  135. if req.ChartClassifyId <= 0 {
  136. br.Msg = "分类参数错误!"
  137. return
  138. }
  139. chartInfo, err, errMsg, isSendEmail := data.AddChartInfo(req, sysUser.AdminId, sysUser.RealName, this.Lang)
  140. if err != nil {
  141. br.Msg = "保存失败"
  142. if errMsg != `` {
  143. br.Msg = errMsg
  144. }
  145. br.ErrMsg = err.Error()
  146. br.IsSendEmail = isSendEmail
  147. return
  148. }
  149. resp := new(data_manage.AddChartInfoResp)
  150. resp.ChartInfoId = chartInfo.ChartInfoId
  151. resp.UniqueCode = chartInfo.UniqueCode
  152. resp.ChartType = req.ChartType
  153. {
  154. chartLog := new(data_manage.ChartInfoLog)
  155. chartLog.ChartInfoId = chartInfo.ChartInfoId
  156. chartLog.ChartName = req.ChartName
  157. chartLog.ChartClassifyId = req.ChartClassifyId
  158. chartLog.SysUserId = sysUser.AdminId
  159. chartLog.SysUserRealName = sysUser.RealName
  160. chartLog.UniqueCode = chartInfo.UniqueCode
  161. chartLog.CreateTime = time.Now()
  162. chartLog.Content = string(this.Ctx.Input.RequestBody)
  163. chartLog.Status = "新增图表"
  164. chartLog.Method = this.Ctx.Input.URI()
  165. go data_manage.AddChartInfoLog(chartLog)
  166. }
  167. br.Ret = 200
  168. br.Success = true
  169. br.Msg = "保存成功"
  170. br.Data = resp
  171. br.IsAddLog = true
  172. }
  173. // @router /chart_info/edit [post]
  174. func (this *ChartInfoController) ChartInfoEdit() {
  175. br := new(models.BaseResponse).Init()
  176. defer func() {
  177. this.Data["json"] = br
  178. this.ServeJSON()
  179. }()
  180. sysUser := this.SysUser
  181. if sysUser == nil {
  182. br.Msg = "请登录"
  183. br.ErrMsg = "请登录,SysUser Is Empty"
  184. br.Ret = 408
  185. return
  186. }
  187. var req data_manage.EditChartInfoReq
  188. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  189. if err != nil {
  190. br.Msg = "参数解析异常!"
  191. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  192. return
  193. }
  194. chartItem, err, errMsg, isSendEmail := data.EditChartInfo(req, sysUser, this.Lang)
  195. if err != nil {
  196. br.Msg = "保存失败"
  197. if errMsg != `` {
  198. br.Msg = errMsg
  199. }
  200. br.ErrMsg = err.Error()
  201. br.IsSendEmail = isSendEmail
  202. return
  203. }
  204. resp := new(data_manage.AddChartInfoResp)
  205. resp.ChartInfoId = chartItem.ChartInfoId
  206. resp.UniqueCode = chartItem.UniqueCode
  207. resp.ChartType = req.ChartType
  208. {
  209. chartLog := new(data_manage.ChartInfoLog)
  210. chartLog.ChartName = chartItem.ChartName
  211. chartLog.ChartInfoId = req.ChartInfoId
  212. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  213. chartLog.SysUserId = sysUser.AdminId
  214. chartLog.SysUserRealName = sysUser.RealName
  215. chartLog.UniqueCode = chartItem.UniqueCode
  216. chartLog.CreateTime = time.Now()
  217. chartLog.Content = string(this.Ctx.Input.RequestBody)
  218. chartLog.Status = "编辑图表"
  219. chartLog.Method = this.Ctx.Input.URL()
  220. go data_manage.AddChartInfoLog(chartLog)
  221. }
  222. br.Ret = 200
  223. br.Success = true
  224. br.Msg = "保存成功"
  225. br.Data = resp
  226. br.IsAddLog = true
  227. }
  228. // @router /chart_info/en/edit [post]
  229. func (this *ChartInfoController) ChartEnInfoEdit() {
  230. br := new(models.BaseResponse).Init()
  231. defer func() {
  232. this.Data["json"] = br
  233. this.ServeJSON()
  234. }()
  235. sysUser := this.SysUser
  236. if sysUser == nil {
  237. br.Msg = "请登录"
  238. br.ErrMsg = "请登录,SysUser Is Empty"
  239. br.Ret = 408
  240. return
  241. }
  242. var req data_manage.EditChartEnInfoReq
  243. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  244. if err != nil {
  245. br.Msg = "参数解析异常!"
  246. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  247. return
  248. }
  249. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  250. if req.ChartInfoId <= 0 {
  251. br.Msg = "请选择图表"
  252. return
  253. }
  254. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  255. if err != nil {
  256. if utils.IsErrNoRow(err) {
  257. br.Msg = "图表已被删除,请刷新页面"
  258. br.ErrMsg = "图表已被删除,请刷新页面"
  259. return
  260. }
  261. br.Msg = "获取图表信息失败"
  262. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  263. return
  264. }
  265. noEdbInfoType := []int{10}
  266. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  267. br.Msg = "请选择指标!"
  268. return
  269. }
  270. var edbCondition string
  271. var edbPars []interface{}
  272. for _, v := range req.ChartEdbInfoList {
  273. edbInfoId := v.EdbInfoId
  274. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  275. if err != nil {
  276. if utils.IsErrNoRow(err) {
  277. br.Msg = "图表不存在!"
  278. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  279. return
  280. } else {
  281. br.Msg = "获取图表信息失败!"
  282. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  283. return
  284. }
  285. }
  286. if edbInfo == nil {
  287. br.Msg = "指标不存在!"
  288. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  289. return
  290. }
  291. if v.EdbNameEn != "" {
  292. edbCondition = ""
  293. edbPars = make([]interface{}, 0)
  294. edbCondition += " AND edb_info_id<>? "
  295. edbPars = append(edbPars, edbInfo.EdbInfoId)
  296. edbCondition += " AND edb_name_en=? "
  297. edbPars = append(edbPars, v.EdbNameEn)
  298. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  299. if err != nil {
  300. if !utils.IsErrNoRow(err) {
  301. br.Msg = "判断英文指标名称是否存在失败"
  302. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  303. return
  304. }
  305. }
  306. if err == nil && edbExist.EdbInfoId > 0 {
  307. br.Msg = edbExist.EdbName + ":" + v.EdbNameEn + "指标名称已存在"
  308. br.ErrMsg = "英文指标名称已存在,请重新填写"
  309. br.IsSendEmail = false
  310. return
  311. }
  312. }
  313. }
  314. if req.ChartNameEn != "" || req.ExtraConfig != `` {
  315. var condition string
  316. var pars []interface{}
  317. condition += " AND chart_info_id<>? "
  318. pars = append(pars, req.ChartInfoId)
  319. condition += " AND chart_name_en=? "
  320. pars = append(pars, req.ChartNameEn)
  321. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  322. if err != nil {
  323. if !utils.IsErrNoRow(err) {
  324. br.Msg = "判断英文图表名称是否存在失败"
  325. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  326. return
  327. }
  328. }
  329. if err == nil && existItem.ChartInfoId > 0 {
  330. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  331. return
  332. }
  333. }
  334. err = data_manage.EditChartEnInfoAndEdbEnInfo(&req)
  335. if err != nil {
  336. br.Msg = "保存失败"
  337. br.ErrMsg = "保存失败,Err:" + err.Error()
  338. return
  339. }
  340. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  341. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  342. for _, v := range req.ChartEdbInfoList {
  343. edbInfoId := v.EdbInfoId
  344. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  345. if err != nil {
  346. if utils.IsErrNoRow(err) {
  347. br.Msg = "图表不存在!"
  348. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  349. return
  350. } else {
  351. br.Msg = "获取图表信息失败!"
  352. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  353. return
  354. }
  355. }
  356. if edbInfo != nil {
  357. go data.AddOrEditEdbInfoToEs(edbInfoId)
  358. }
  359. }
  360. {
  361. chartLog := new(data_manage.ChartInfoLog)
  362. chartLog.ChartName = chartItem.ChartName
  363. chartLog.ChartInfoId = req.ChartInfoId
  364. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  365. chartLog.SysUserId = sysUser.AdminId
  366. chartLog.SysUserRealName = sysUser.RealName
  367. chartLog.UniqueCode = chartItem.UniqueCode
  368. chartLog.CreateTime = time.Now()
  369. chartLog.Content = string(this.Ctx.Input.RequestBody)
  370. chartLog.Status = "编辑图表英文信息"
  371. chartLog.Method = this.Ctx.Input.URL()
  372. go data_manage.AddChartInfoLog(chartLog)
  373. }
  374. if utils.Re == nil && utils.Rc != nil {
  375. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  376. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  377. }
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "编辑成功"
  381. br.IsAddLog = true
  382. }
  383. // @router /chart_info/base/edit [post]
  384. func (this *ChartInfoController) ChartInfoBaseEdit() {
  385. br := new(models.BaseResponse).Init()
  386. defer func() {
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. sysUser := this.SysUser
  391. if sysUser == nil {
  392. br.Msg = "请登录"
  393. br.ErrMsg = "请登录,SysUser Is Empty"
  394. br.Ret = 408
  395. return
  396. }
  397. var req data_manage.EditChartInfoBaseReq
  398. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  399. if err != nil {
  400. br.Msg = "参数解析异常!"
  401. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  402. return
  403. }
  404. req.ChartName = strings.Trim(req.ChartName, " ")
  405. if req.ChartInfoId <= 0 {
  406. br.Msg = "请选择图表"
  407. return
  408. }
  409. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  410. if err != nil {
  411. if utils.IsErrNoRow(err) {
  412. br.Msg = "图表已被删除,请刷新页面"
  413. br.ErrMsg = "图表已被删除,请刷新页面"
  414. return
  415. }
  416. br.Msg = "获取图表信息失败"
  417. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  418. return
  419. }
  420. noEdbInfoType := []int{10}
  421. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  422. br.Msg = "请选择指标!"
  423. return
  424. }
  425. var edbCondition string
  426. var edbPars []interface{}
  427. for _, v := range req.ChartEdbInfoList {
  428. edbInfoId := v.EdbInfoId
  429. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  430. if err != nil {
  431. if utils.IsErrNoRow(err) {
  432. br.Msg = "图表不存在!"
  433. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  434. return
  435. } else {
  436. br.Msg = "获取图表信息失败!"
  437. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  438. return
  439. }
  440. }
  441. if edbInfo == nil {
  442. br.Msg = "指标不存在!"
  443. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  444. return
  445. }
  446. if v.EdbName != "" {
  447. edbCondition = ""
  448. edbPars = make([]interface{}, 0)
  449. edbCondition += " AND edb_info_id<>? "
  450. edbPars = append(edbPars, edbInfo.EdbInfoId)
  451. switch this.Lang {
  452. case utils.EnLangVersion:
  453. edbCondition += " AND edb_name_en =? "
  454. default:
  455. edbCondition += " AND edb_name =? "
  456. }
  457. edbPars = append(edbPars, v.EdbName)
  458. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  459. if err != nil {
  460. if !utils.IsErrNoRow(err) {
  461. br.Msg = "判断英文指标名称是否存在失败"
  462. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  463. return
  464. }
  465. }
  466. if err == nil && edbExist.EdbInfoId > 0 {
  467. br.Msg = edbExist.EdbName + ":" + v.EdbName + "指标名称已存在"
  468. br.ErrMsg = "指标名称已存在,请重新填写"
  469. br.IsSendEmail = false
  470. return
  471. }
  472. }
  473. }
  474. if req.ChartName != "" || req.ExtraConfig != `` {
  475. var condition string
  476. var pars []interface{}
  477. condition += " AND chart_info_id<>? "
  478. pars = append(pars, req.ChartInfoId)
  479. switch this.Lang {
  480. case utils.EnLangVersion:
  481. condition += " AND chart_name_en = ? "
  482. default:
  483. condition += " AND chart_name = ? "
  484. }
  485. pars = append(pars, req.ChartName)
  486. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  487. if err != nil {
  488. if !utils.IsErrNoRow(err) {
  489. br.Msg = "判断英文图表名称是否存在失败"
  490. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  491. return
  492. }
  493. }
  494. if err == nil && existItem.ChartInfoId > 0 {
  495. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  496. return
  497. }
  498. }
  499. err = data_manage.EditChartBaseInfoAndEdbEnInfo(&req, chartItem, this.Lang)
  500. if err != nil {
  501. br.Msg = "保存失败"
  502. br.ErrMsg = "保存失败,Err:" + err.Error()
  503. return
  504. }
  505. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  506. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  507. for _, v := range req.ChartEdbInfoList {
  508. edbInfoId := v.EdbInfoId
  509. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  510. if err != nil {
  511. if utils.IsErrNoRow(err) {
  512. br.Msg = "图表不存在!"
  513. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  514. return
  515. } else {
  516. br.Msg = "获取图表信息失败!"
  517. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  518. return
  519. }
  520. }
  521. if edbInfo != nil {
  522. go data.AddOrEditEdbInfoToEs(edbInfoId)
  523. }
  524. }
  525. {
  526. chartLog := new(data_manage.ChartInfoLog)
  527. chartLog.ChartName = chartItem.ChartName
  528. chartLog.ChartInfoId = req.ChartInfoId
  529. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  530. chartLog.SysUserId = sysUser.AdminId
  531. chartLog.SysUserRealName = sysUser.RealName
  532. chartLog.UniqueCode = chartItem.UniqueCode
  533. chartLog.CreateTime = time.Now()
  534. chartLog.Content = string(this.Ctx.Input.RequestBody)
  535. chartLog.Status = "编辑图表英文信息"
  536. chartLog.Method = this.Ctx.Input.URL()
  537. go data_manage.AddChartInfoLog(chartLog)
  538. }
  539. if utils.Re == nil && utils.Rc != nil {
  540. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  541. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  542. }
  543. br.Ret = 200
  544. br.Success = true
  545. br.Msg = "编辑成功"
  546. br.IsAddLog = true
  547. }
  548. // @router /chart_info/newest [get]
  549. func (this *ChartInfoController) ChartInfoNewest() {
  550. br := new(models.BaseResponse).Init()
  551. defer func() {
  552. this.Data["json"] = br
  553. this.ServeJSON()
  554. }()
  555. item, err := data_manage.GetChartInfoByNewest(1)
  556. if err != nil && !utils.IsErrNoRow(err) {
  557. br.Msg = "获取最新图表失败"
  558. br.ErrMsg = "获取最新图表失败,Err:" + err.Error()
  559. return
  560. }
  561. br.Ret = 200
  562. br.Success = true
  563. br.Msg = "获取成功"
  564. br.Data = item
  565. }
  566. // @router /chart_info/move [post]
  567. func (this *ChartInfoController) ChartInfoMove() {
  568. br := new(models.BaseResponse).Init()
  569. defer func() {
  570. this.Data["json"] = br
  571. this.ServeJSON()
  572. }()
  573. sysUser := this.SysUser
  574. if sysUser == nil {
  575. br.Msg = "请登录"
  576. br.ErrMsg = "请登录,SysUser Is Empty"
  577. br.Ret = 408
  578. return
  579. }
  580. var req data_manage.MoveChartInfoReq
  581. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  582. if err != nil {
  583. br.Msg = "参数解析异常!"
  584. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  585. return
  586. }
  587. if req.ChartInfoId <= 0 {
  588. br.Msg = "参数错误"
  589. br.ErrMsg = "图表id小于等于0"
  590. return
  591. }
  592. if req.ChartClassifyId <= 0 {
  593. br.Msg = "请选择分类"
  594. return
  595. }
  596. count, _ := data_manage.GetChartClassifyCountById(req.ChartClassifyId)
  597. if count <= 0 {
  598. br.Msg = "分类已被删除,不可移动,请刷新页面"
  599. return
  600. }
  601. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  602. if err != nil {
  603. br.Msg = "移动失败"
  604. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  605. return
  606. }
  607. if chartInfo.Source != utils.CHART_SOURCE_DEFAULT {
  608. br.Msg = "图表异常"
  609. br.ErrMsg = "分类异常,不是ETA图库的图表"
  610. return
  611. }
  612. {
  613. haveOperaAuth, err := data_manage_permission.CheckChartPermissionByChartInfoId(chartInfo.ChartInfoId, chartInfo.ChartClassifyId, chartInfo.IsJoinPermission, sysUser.AdminId)
  614. if err != nil {
  615. br.Msg = "移动失败"
  616. br.ErrMsg = "获取图表权限失败,Err:" + err.Error()
  617. return
  618. }
  619. if !haveOperaAuth {
  620. br.Msg = "无操作权限"
  621. br.ErrMsg = "无操作权限"
  622. br.IsSendEmail = false
  623. return
  624. }
  625. }
  626. if chartInfo.ChartClassifyId != req.ChartClassifyId {
  627. tmpChartInfo, tmpErr := data_manage.GetChartInfoByClassifyIdAndName(req.ChartClassifyId, chartInfo.ChartName)
  628. if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
  629. br.Msg = "移动失败"
  630. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  631. return
  632. }
  633. if tmpErr == nil && tmpChartInfo.ChartInfoId > 0 {
  634. br.Msg = "移动失败,同一个分类下图表名称不允许重复"
  635. br.ErrMsg = "移动失败,同一个分类下图表名称不允许重复"
  636. return
  637. }
  638. err = data_manage.MoveChartInfo(req.ChartInfoId, req.ChartClassifyId)
  639. if err != nil {
  640. br.Msg = "移动失败"
  641. br.ErrMsg = "移动失败,Err:" + err.Error()
  642. return
  643. }
  644. }
  645. updateCol := make([]string, 0)
  646. if req.PrevChartInfoId > 0 {
  647. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  648. if err != nil {
  649. br.Msg = "移动失败"
  650. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  651. return
  652. }
  653. if req.NextChartInfoId > 0 {
  654. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  655. if err != nil {
  656. br.Msg = "移动失败"
  657. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  658. return
  659. }
  660. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  661. updateSortStr := `sort + 2`
  662. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  663. } else {
  664. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  665. updateSortStr := `sort + 1`
  666. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  667. }
  668. }
  669. }
  670. chartInfo.Sort = prevChartInfo.Sort + 1
  671. chartInfo.ModifyTime = time.Now()
  672. updateCol = append(updateCol, "Sort", "ModifyTime")
  673. } else {
  674. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(req.ChartClassifyId)
  675. if err != nil && !utils.IsErrNoRow(err) {
  676. br.Msg = "移动失败"
  677. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  678. return
  679. }
  680. if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  681. updateSortStr := ` sort + 1 `
  682. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{chartInfo.Source}, updateSortStr)
  683. }
  684. chartInfo.Sort = 0 //那就是排在第一位
  685. chartInfo.ModifyTime = time.Now()
  686. updateCol = append(updateCol, "Sort", "ModifyTime")
  687. }
  688. if len(updateCol) > 0 {
  689. err = chartInfo.Update(updateCol)
  690. if err != nil {
  691. br.Msg = "移动失败"
  692. br.ErrMsg = "修改失败,Err:" + err.Error()
  693. return
  694. }
  695. }
  696. if err != nil {
  697. br.Msg = "移动失败"
  698. br.ErrMsg = "修改失败,Err:" + err.Error()
  699. return
  700. }
  701. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  702. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  703. {
  704. chartLog := new(data_manage.ChartInfoLog)
  705. chartLog.ChartName = chartInfo.ChartName
  706. chartLog.ChartInfoId = req.ChartInfoId
  707. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  708. chartLog.SysUserId = sysUser.AdminId
  709. chartLog.SysUserRealName = sysUser.RealName
  710. chartLog.UniqueCode = chartInfo.UniqueCode
  711. chartLog.CreateTime = time.Now()
  712. chartLog.Content = string(this.Ctx.Input.RequestBody)
  713. chartLog.Status = "移动图表"
  714. chartLog.Method = this.Ctx.Input.URL()
  715. go data_manage.AddChartInfoLog(chartLog)
  716. }
  717. br.Ret = 200
  718. br.Success = true
  719. br.Msg = "移动成功"
  720. }
  721. // @router /chart_info/detail [get]
  722. func (this *ChartInfoController) ChartInfoDetail() {
  723. br := new(models.BaseResponse).Init()
  724. defer func() {
  725. this.Data["json"] = br
  726. this.ServeJSON()
  727. }()
  728. sysUser := this.SysUser
  729. if sysUser == nil {
  730. br.Msg = "请登录"
  731. br.ErrMsg = "请登录,SysUser Is Empty"
  732. br.Ret = 408
  733. return
  734. }
  735. chartInfoId, _ := this.GetInt("ChartInfoId")
  736. dateType, _ := this.GetInt("DateType")
  737. fmt.Println("dateType:", dateType)
  738. if dateType <= 0 {
  739. dateType = 3
  740. }
  741. startDate := this.GetString("StartDate")
  742. endDate := this.GetString("EndDate")
  743. startYear, _ := this.GetInt("StartYear")
  744. edbInfoId := this.GetString("EdbInfoId")
  745. chartType, _ := this.GetInt("ChartType")
  746. calendar := this.GetString("Calendar")
  747. if calendar == "" {
  748. calendar = "公历"
  749. }
  750. var err error
  751. chartInfo := new(data_manage.ChartInfoView)
  752. chartInfo.HaveOperaAuth = true
  753. if chartInfoId > 0 {
  754. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  755. if err != nil {
  756. if utils.IsErrNoRow(err) {
  757. br.Msg = "该图表已删除,自动查看下一图表"
  758. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  759. br.Ret = 406
  760. return
  761. }
  762. br.Msg = "获取失败"
  763. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  764. return
  765. }
  766. chartType = chartInfo.ChartType
  767. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  768. if err != nil {
  769. br.Msg = "获取失败"
  770. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  771. return
  772. }
  773. chartInfo.ChartThemeStyle = chartTheme.Config
  774. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  775. {
  776. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  777. if err != nil {
  778. br.Msg = "获取失败"
  779. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  780. return
  781. }
  782. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  783. if err != nil {
  784. br.Msg = "获取失败"
  785. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  786. return
  787. }
  788. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  789. }
  790. }
  791. resp := new(data_manage.ChartInfoDetailResp)
  792. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  793. if chartInfoId > 0 {
  794. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  798. return
  799. }
  800. } else {
  801. if edbInfoId != "" {
  802. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  803. if err != nil {
  804. br.Msg = "获取失败"
  805. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  806. return
  807. }
  808. }
  809. }
  810. for _, v := range mappingList {
  811. v.ConvertToResp()
  812. }
  813. extraConfigStr := chartInfo.ExtraConfig
  814. var barConfig data_manage.BarChartInfoReq
  815. if chartInfo != nil && chartInfo.ChartType == 7 {
  816. if chartInfo.BarConfig == `` {
  817. br.Msg = "柱方图未配置"
  818. br.ErrMsg = "柱方图未配置"
  819. return
  820. }
  821. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  822. if err != nil {
  823. br.Msg = "柱方图配置异常"
  824. br.ErrMsg = "柱方图配置异常"
  825. return
  826. }
  827. extraConfigStr = chartInfo.BarConfig
  828. }
  829. yearMax := 0
  830. if dateType == utils.DateTypeNYears {
  831. for _, v := range mappingList {
  832. if v.LatestDate != "" {
  833. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  834. if tErr != nil {
  835. br.Msg = "获取失败"
  836. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  837. return
  838. }
  839. if lastDateT.Year() > yearMax {
  840. yearMax = lastDateT.Year()
  841. }
  842. }
  843. }
  844. }
  845. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  846. if chartInfo.HaveOperaAuth {
  847. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  848. if err != nil {
  849. br.Msg = "获取失败"
  850. if errMsg != `` {
  851. br.Msg = errMsg
  852. }
  853. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  854. return
  855. }
  856. {
  857. classifyMap := make(map[int]*data_manage.EdbClassify)
  858. {
  859. classifyIdList := make([]int, 0)
  860. for _, v := range edbList {
  861. classifyIdList = append(classifyIdList, v.ClassifyId)
  862. }
  863. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  864. if tmpErr != nil {
  865. br.Msg = "获取失败"
  866. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  867. return
  868. }
  869. for _, v := range classifyList {
  870. classifyMap[v.ClassifyId] = v
  871. }
  872. }
  873. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  874. if err != nil {
  875. br.Msg = "获取失败"
  876. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  877. return
  878. }
  879. for _, item := range edbList {
  880. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  881. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  882. }
  883. }
  884. }
  885. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  886. chartInfo.Unit = yDataList[0].Unit
  887. chartInfo.UnitEn = yDataList[0].UnitEn
  888. }
  889. warnEdbList := make([]string, 0)
  890. for _, v := range edbList {
  891. if v.IsNullData {
  892. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  893. }
  894. }
  895. if len(warnEdbList) > 0 {
  896. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  897. }
  898. if chartInfoId > 0 && chartInfo != nil {
  899. {
  900. var myChartCondition string
  901. var myChartPars []interface{}
  902. myChartCondition += ` AND a.admin_id=? `
  903. myChartPars = append(myChartPars, sysUser.AdminId)
  904. myChartCondition += ` AND a.chart_info_id=? `
  905. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  906. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  907. if err != nil && !utils.IsErrNoRow(err) {
  908. br.Msg = "获取失败"
  909. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  910. return
  911. }
  912. if myChartList != nil && len(myChartList) > 0 {
  913. chartInfo.IsAdd = true
  914. chartInfo.MyChartId = myChartList[0].MyChartId
  915. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  916. }
  917. }
  918. if chartInfo.ChartType == 2 {
  919. if chartInfo.SeasonStartDate != "" {
  920. chartInfo.StartDate = chartInfo.SeasonStartDate
  921. chartInfo.EndDate = chartInfo.SeasonEndDate
  922. if chartInfo.DateType == 3 {
  923. chartInfo.DateType = 5
  924. }
  925. }
  926. }
  927. }
  928. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  929. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  930. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  931. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  932. resp.EdbInfoList = edbList
  933. resp.XEdbIdValue = xEdbIdValue
  934. resp.YDataList = yDataList
  935. resp.DataResp = dataResp
  936. }
  937. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  938. chartInfo.Button = data_manage.ChartViewButton{
  939. IsEdit: chartInfo.IsEdit,
  940. IsEnChart: chartInfo.IsEnChart,
  941. IsAdd: chartInfo.IsAdd,
  942. IsCopy: true,
  943. IsSetName: chartInfo.IsSetName,
  944. }
  945. resp.ChartInfo = chartInfo
  946. resp.BarChartInfo = barConfig
  947. br.Ret = 200
  948. br.Success = true
  949. br.Msg = "获取成功"
  950. br.Data = resp
  951. }
  952. // @router /chart_info/detail/preview [post]
  953. func (this *ChartInfoController) PreviewChartInfoDetail() {
  954. br := new(models.BaseResponse).Init()
  955. defer func() {
  956. this.Data["json"] = br
  957. this.ServeJSON()
  958. }()
  959. sysUser := this.SysUser
  960. if sysUser == nil {
  961. br.Msg = "请登录"
  962. br.ErrMsg = "请登录,SysUser Is Empty"
  963. br.Ret = 408
  964. return
  965. }
  966. var req data_manage.PreviewChartInfoReq
  967. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  968. if err != nil {
  969. br.Msg = "参数解析异常!"
  970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  971. return
  972. }
  973. if req.DateType <= 0 {
  974. req.DateType = 3
  975. }
  976. if len(req.ChartEdbInfoList) <= 0 {
  977. br.Msg = "请选择指标"
  978. br.ErrMsg = "指标为空"
  979. br.IsSendEmail = false
  980. return
  981. }
  982. calendar := req.Calendar
  983. if calendar == "" {
  984. calendar = "公历"
  985. }
  986. chartInfo := new(data_manage.ChartInfoView)
  987. chartInfo.ChartType = req.ChartType
  988. edbInfoIdList := make([]int, 0)
  989. edbInfoIdMapping := make(map[int]*data_manage.ChartSaveItem)
  990. for _, v := range req.ChartEdbInfoList {
  991. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  992. edbInfoIdMapping[v.EdbInfoId] = v
  993. }
  994. var chartInfoDataShow data.ChartInfoDataShow
  995. if req.ChartSource == utils.CHART_SOURCE_BALANCE_EXCEL { //来自平衡表图表的数据
  996. excelChartInfoDataShow := new(data.ExcelChartInfoDataShow)
  997. mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, req.ChartEdbInfoList[0].EdbInfoId, "")
  998. if err != nil {
  999. br.Msg = errMsg
  1000. br.ErrMsg = err.Error()
  1001. return
  1002. }
  1003. excelChartInfoDataShow.DataListMap = dataListMap
  1004. excelChartInfoDataShow.MappingListTmp = mappingListTmp
  1005. chartInfoDataShow = excelChartInfoDataShow
  1006. } else {
  1007. chartInfoDataShow = &data.BaseChartInfoDataShow{}
  1008. }
  1009. mappingList, err := chartInfoDataShow.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdList)
  1010. if err != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1013. return
  1014. }
  1015. yearMax := 0
  1016. for k, v := range mappingList {
  1017. if tmpV, ok := edbInfoIdMapping[v.EdbInfoId]; ok {
  1018. v.EdbInfoType = tmpV.EdbInfoType
  1019. v.MaxData = tmpV.MaxData
  1020. v.MinData = tmpV.MinData
  1021. v.IsOrder = tmpV.IsOrder
  1022. v.IsAxis = tmpV.IsAxis
  1023. v.EdbInfoType = tmpV.EdbInfoType
  1024. v.LeadValue = tmpV.LeadValue
  1025. v.LeadUnit = tmpV.LeadUnit
  1026. v.ChartStyle = tmpV.ChartStyle
  1027. v.ChartColor = tmpV.ChartColor
  1028. v.PredictChartColor = tmpV.PredictChartColor
  1029. v.ChartWidth = tmpV.ChartWidth
  1030. if req.DateType == utils.DateTypeNYears && v.LatestDate != "" {
  1031. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1032. if tErr != nil {
  1033. br.Msg = "获取失败"
  1034. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1035. return
  1036. }
  1037. if lastDateT.Year() > yearMax {
  1038. yearMax = lastDateT.Year()
  1039. }
  1040. }
  1041. }
  1042. if req.ChartEdbInfoList[k].IsConvert == 1 {
  1043. v.IsConvert = 1
  1044. v.ConvertType = req.ChartEdbInfoList[k].ConvertType
  1045. v.ConvertValue = req.ChartEdbInfoList[k].ConvertValue
  1046. v.ConvertUnit = req.ChartEdbInfoList[k].ConvertUnit
  1047. v.ConvertEnUnit = req.ChartEdbInfoList[k].ConvertEnUnit
  1048. }
  1049. mappingList[k] = v
  1050. }
  1051. startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, yearMax)
  1052. if startDate == "" {
  1053. br.Msg = "获取失败"
  1054. br.ErrMsg = "获取失败 时间格式错误"
  1055. return
  1056. }
  1057. var seasonExtraConfig string
  1058. if req.ChartType == 2 {
  1059. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  1060. if tErr != nil {
  1061. br.Msg = "季节性图表配置信息异常"
  1062. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  1063. return
  1064. }
  1065. seasonExtraConfig = string(seasonExtra)
  1066. }
  1067. extraConfigStr := chartInfo.ExtraConfig
  1068. var barConfig data_manage.BarChartInfoReq
  1069. if chartInfo != nil && chartInfo.ChartType == 7 {
  1070. if chartInfo.BarConfig == `` {
  1071. br.Msg = "柱方图未配置"
  1072. br.ErrMsg = "柱方图未配置"
  1073. return
  1074. }
  1075. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1076. if err != nil {
  1077. br.Msg = "柱方图配置异常"
  1078. br.ErrMsg = "柱方图配置异常"
  1079. return
  1080. }
  1081. extraConfigStr = chartInfo.BarConfig
  1082. } else if chartInfo != nil && chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  1083. extraConfigStr = req.ExtraConfig
  1084. }
  1085. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbDataV2(0, req.ChartType, calendar, startDate, endDate, mappingList, extraConfigStr, seasonExtraConfig, chartInfoDataShow)
  1086. if err != nil {
  1087. br.Msg = "获取失败"
  1088. if errMsg != `` {
  1089. br.Msg = errMsg
  1090. }
  1091. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. if req.ChartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1095. chartInfo.Unit = yDataList[0].Unit
  1096. chartInfo.UnitEn = yDataList[0].UnitEn
  1097. }
  1098. warnEdbList := make([]string, 0)
  1099. for _, v := range edbList {
  1100. if v.IsNullData {
  1101. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1102. }
  1103. }
  1104. if len(warnEdbList) > 0 {
  1105. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1106. }
  1107. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1108. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1109. chartInfo.Button = data_manage.ChartViewButton{
  1110. IsEdit: chartInfo.IsEdit,
  1111. IsEnChart: chartInfo.IsEnChart,
  1112. IsAdd: chartInfo.IsAdd,
  1113. IsCopy: true,
  1114. IsSetName: chartInfo.IsSetName,
  1115. }
  1116. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1117. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1118. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1119. if req.MarkersLines != "" {
  1120. markerLines := make([]data_manage.MarkersLine, 0)
  1121. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  1122. if err != nil {
  1123. br.Msg = "标识线配置异常"
  1124. br.ErrMsg = "标识线配置异常" + err.Error()
  1125. return
  1126. }
  1127. for i := range markerLines {
  1128. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  1129. if markerLines[i].MarkLineType == 2 {
  1130. if edbList[0].IsAxis == 1 {
  1131. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  1132. if err != nil {
  1133. br.Msg = "标识线配置异常"
  1134. br.ErrMsg = "标识线配置异常" + err.Error()
  1135. return
  1136. }
  1137. markerLines[i].Value = value
  1138. } else {
  1139. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  1140. if err != nil {
  1141. br.Msg = "指标计算标识线获取指标信息异常"
  1142. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  1143. return
  1144. }
  1145. if markerLines[i].TimeIntervalType != 0 {
  1146. startDate = markerLines[i].StartDate.Date
  1147. endDate = markerLines[i].EndDate.Date
  1148. }
  1149. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, startDate, endDate)
  1150. if err != nil {
  1151. br.Msg = "指标计算标识线获取指标数据异常"
  1152. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  1153. return
  1154. }
  1155. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  1156. if err != nil {
  1157. br.Msg = "标识线配置异常"
  1158. br.ErrMsg = "标识线配置异常" + err.Error()
  1159. return
  1160. }
  1161. markerLines[i].Value = value
  1162. }
  1163. }
  1164. }
  1165. }
  1166. markerLineStr, err := json.Marshal(markerLines)
  1167. if err != nil {
  1168. br.Msg = "标识线配置异常"
  1169. br.ErrMsg = "标识线配置异常" + err.Error()
  1170. return
  1171. }
  1172. chartInfo.MarkersLines = string(markerLineStr)
  1173. }
  1174. resp := new(data_manage.ChartInfoDetailResp)
  1175. resp.ChartInfo = chartInfo
  1176. resp.EdbInfoList = edbList
  1177. resp.XEdbIdValue = xEdbIdValue
  1178. resp.YDataList = yDataList
  1179. resp.BarChartInfo = barConfig
  1180. resp.DataResp = dataResp
  1181. br.Ret = 200
  1182. br.Success = true
  1183. br.Msg = "获取成功"
  1184. br.Data = resp
  1185. }
  1186. // @router /chart_info/detail/v2 [get]
  1187. func (this *ChartInfoController) ChartInfoDetailV2() {
  1188. br := new(models.BaseResponse).Init()
  1189. defer func() {
  1190. this.Data["json"] = br
  1191. this.ServeJSON()
  1192. }()
  1193. sysUser := this.SysUser
  1194. if sysUser == nil {
  1195. br.Msg = "请登录"
  1196. br.ErrMsg = "请登录,SysUser Is Empty"
  1197. br.Ret = 408
  1198. return
  1199. }
  1200. chartInfoId, _ := this.GetInt("ChartInfoId")
  1201. if chartInfoId <= 0 {
  1202. br.Msg = "请选择图表"
  1203. br.IsSendEmail = false
  1204. return
  1205. }
  1206. chartInfo, err := data_manage.GetChartInfoViewById(chartInfoId)
  1207. if err != nil {
  1208. if utils.IsErrNoRow(err) {
  1209. br.Msg = "该图表已删除,自动查看下一图表"
  1210. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  1211. br.Ret = 406
  1212. return
  1213. }
  1214. br.Msg = "获取失败"
  1215. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1216. return
  1217. }
  1218. resp := new(data_manage.ChartInfoDetailResp)
  1219. {
  1220. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  1221. if err != nil {
  1222. br.Msg = "获取失败"
  1223. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  1224. return
  1225. }
  1226. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  1227. if err != nil {
  1228. br.Msg = "获取失败"
  1229. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1230. return
  1231. }
  1232. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1233. }
  1234. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  1235. if err != nil {
  1236. br.Msg = "获取失败"
  1237. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  1238. return
  1239. }
  1240. chartInfo.ChartThemeStyle = chartTheme.Config
  1241. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1242. dateType := chartInfo.DateType
  1243. fmt.Println("dateType:", dateType)
  1244. chartType := chartInfo.ChartType
  1245. startDate := chartInfo.StartDate
  1246. endDate := chartInfo.EndDate
  1247. seasonStartDate := chartInfo.SeasonStartDate
  1248. seasonEndDate := chartInfo.SeasonEndDate
  1249. startYear := chartInfo.StartYear
  1250. calendar := chartInfo.Calendar
  1251. if calendar == "" {
  1252. calendar = "公历"
  1253. }
  1254. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  1255. if err != nil {
  1256. br.Msg = "获取失败"
  1257. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1258. return
  1259. }
  1260. if chartType == 2 {
  1261. startDate = seasonStartDate
  1262. endDate = seasonEndDate
  1263. if dateType <= 0 {
  1264. if startDate != "" {
  1265. dateType = 5
  1266. } else {
  1267. dateType = utils.DateTypeNYears
  1268. }
  1269. }
  1270. } else {
  1271. if dateType <= 0 {
  1272. dateType = 3
  1273. }
  1274. }
  1275. yearMax := 0
  1276. if dateType == utils.DateTypeNYears {
  1277. for _, v := range mappingList {
  1278. if v.LatestDate != "" {
  1279. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1280. if tErr != nil {
  1281. br.Msg = "获取失败"
  1282. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1283. return
  1284. }
  1285. if lastDateT.Year() > yearMax {
  1286. yearMax = lastDateT.Year()
  1287. }
  1288. }
  1289. }
  1290. }
  1291. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  1292. if chartInfo.ChartType == 2 {
  1293. chartInfo.StartDate = startDate
  1294. chartInfo.EndDate = endDate
  1295. }
  1296. extraConfigStr := chartInfo.ExtraConfig
  1297. var barConfig data_manage.BarChartInfoReq
  1298. if chartInfo != nil && chartInfo.ChartType == 7 {
  1299. if chartInfo.BarConfig == `` {
  1300. br.Msg = "柱方图未配置"
  1301. br.ErrMsg = "柱方图未配置"
  1302. return
  1303. }
  1304. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1305. if err != nil {
  1306. br.Msg = "柱方图配置异常"
  1307. br.ErrMsg = "柱方图配置异常"
  1308. return
  1309. }
  1310. extraConfigStr = chartInfo.BarConfig
  1311. }
  1312. if chartInfo.HaveOperaAuth {
  1313. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  1314. if err != nil {
  1315. br.Msg = "获取失败"
  1316. if errMsg != `` {
  1317. br.Msg = errMsg
  1318. }
  1319. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1320. return
  1321. }
  1322. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1323. chartInfo.Unit = yDataList[0].Unit
  1324. chartInfo.UnitEn = yDataList[0].UnitEn
  1325. }
  1326. warnEdbList := make([]string, 0)
  1327. for _, v := range edbList {
  1328. if v.IsNullData {
  1329. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1330. }
  1331. }
  1332. if len(warnEdbList) > 0 {
  1333. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1334. }
  1335. if chartInfoId > 0 && chartInfo != nil {
  1336. {
  1337. var myChartCondition string
  1338. var myChartPars []interface{}
  1339. myChartCondition += ` AND a.admin_id=? `
  1340. myChartPars = append(myChartPars, sysUser.AdminId)
  1341. myChartCondition += ` AND a.chart_info_id=? `
  1342. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1343. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1344. if err != nil && !utils.IsErrNoRow(err) {
  1345. br.Msg = "获取失败"
  1346. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1347. return
  1348. }
  1349. if myChartList != nil && len(myChartList) > 0 {
  1350. chartInfo.IsAdd = true
  1351. chartInfo.MyChartId = myChartList[0].MyChartId
  1352. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1353. }
  1354. }
  1355. }
  1356. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1357. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1358. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1359. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1360. {
  1361. classifyMap := make(map[int]*data_manage.EdbClassify)
  1362. {
  1363. classifyIdList := make([]int, 0)
  1364. for _, v := range edbList {
  1365. classifyIdList = append(classifyIdList, v.ClassifyId)
  1366. }
  1367. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1368. if tmpErr != nil {
  1369. br.Msg = "获取失败"
  1370. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1371. return
  1372. }
  1373. for _, v := range classifyList {
  1374. classifyMap[v.ClassifyId] = v
  1375. }
  1376. }
  1377. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1378. if err != nil {
  1379. br.Msg = "获取失败"
  1380. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1381. return
  1382. }
  1383. for _, item := range edbList {
  1384. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1385. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1386. }
  1387. }
  1388. }
  1389. if len(edbList) <= 0 {
  1390. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  1391. }
  1392. resp.EdbInfoList = edbList
  1393. resp.XEdbIdValue = xEdbIdValue
  1394. resp.YDataList = yDataList
  1395. resp.DataResp = dataResp
  1396. } else {
  1397. resp.EdbInfoList = mappingList
  1398. }
  1399. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  1400. chartInfo.Button = data_manage.ChartViewButton{
  1401. IsEdit: chartInfo.IsEdit,
  1402. IsEnChart: chartInfo.IsEnChart,
  1403. IsAdd: chartInfo.IsAdd,
  1404. IsCopy: true,
  1405. IsSetName: chartInfo.IsSetName,
  1406. }
  1407. resp.ChartInfo = chartInfo
  1408. resp.BarChartInfo = barConfig
  1409. br.Ret = 200
  1410. br.Success = true
  1411. br.Msg = "获取成功"
  1412. br.Data = resp
  1413. }
  1414. // @router /chart_info/edb_info/search [get]
  1415. func (this *ChartInfoController) ChartInfoEdbInfoSearch() {
  1416. br := new(models.BaseResponse).Init()
  1417. defer func() {
  1418. this.Data["json"] = br
  1419. this.ServeJSON()
  1420. }()
  1421. sysUser := this.SysUser
  1422. if sysUser == nil {
  1423. br.Msg = "请登录"
  1424. br.ErrMsg = "请登录,SysUser Is Empty"
  1425. br.Ret = 408
  1426. return
  1427. }
  1428. KeyWord := this.GetString("KeyWord")
  1429. var err error
  1430. searchList := make([]*data_manage.ChartEdbInfo, 0)
  1431. searchList, err = data_manage.EdbInfoSearchByKeyWord(KeyWord)
  1432. if err != nil {
  1433. br.Msg = "获取失败"
  1434. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1435. return
  1436. }
  1437. if searchList == nil {
  1438. searchList = make([]*data_manage.ChartEdbInfo, 0)
  1439. }
  1440. lenSearchList := len(searchList)
  1441. for i := 0; i < lenSearchList; i++ {
  1442. searchList[i].EdbNameAlias = searchList[i].EdbName
  1443. }
  1444. for i := 0; i < lenSearchList; i++ {
  1445. for j := 0; j < lenSearchList; j++ {
  1446. if (searchList[i].EdbNameAlias == searchList[j].EdbNameAlias) &&
  1447. (searchList[i].EdbInfoId != searchList[j].EdbInfoId) &&
  1448. !(strings.Contains(searchList[i].EdbName, searchList[i].SourceName)) {
  1449. searchList[i].EdbName = searchList[i].EdbName + "(" + searchList[i].SourceName + ")"
  1450. }
  1451. }
  1452. }
  1453. br.Ret = 200
  1454. br.Success = true
  1455. br.Msg = "获取成功"
  1456. br.Data = searchList
  1457. }
  1458. // @router /chart_info/edb_info/detail [get]
  1459. func (this *ChartInfoController) ChartInfoEdbInfoDetail() {
  1460. br := new(models.BaseResponse).Init()
  1461. defer func() {
  1462. this.Data["json"] = br
  1463. this.ServeJSON()
  1464. }()
  1465. sysUser := this.SysUser
  1466. if sysUser == nil {
  1467. br.Msg = "请登录"
  1468. br.ErrMsg = "请登录,SysUser Is Empty"
  1469. br.Ret = 408
  1470. return
  1471. }
  1472. edbInfoId, _ := this.GetInt("EdbInfoId")
  1473. if edbInfoId <= 0 {
  1474. br.Msg = "参数错误"
  1475. return
  1476. }
  1477. dateType, _ := this.GetInt("DateType")
  1478. if dateType <= 0 {
  1479. dateType = 3
  1480. }
  1481. edbInfoType, _ := this.GetInt("EdbInfoType")
  1482. if edbInfoType < 0 {
  1483. edbInfoType = 1
  1484. }
  1485. leadValue, _ := this.GetInt("LeadValue")
  1486. if leadValue < 0 {
  1487. leadValue = 0
  1488. }
  1489. leadUnit := this.GetString("LeadUnit")
  1490. startDate := this.GetString("StartDate")
  1491. endDate := this.GetString("EndDate")
  1492. startYear, _ := this.GetInt("StartYear")
  1493. isTimeBetween := false //是否是时间区间
  1494. if dateType == 5 {
  1495. isTimeBetween = true
  1496. }
  1497. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1498. if err != nil {
  1499. br.Msg = "获取失败"
  1500. br.Msg = "获取失败,Err:" + err.Error()
  1501. return
  1502. }
  1503. maxYear := 0
  1504. if edbInfo.LatestDate != "" {
  1505. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  1506. maxYear = latestDateT.Year()
  1507. }
  1508. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  1509. if startDate == "" {
  1510. br.Msg = "参数错误"
  1511. br.Msg = "参数错误,无效的查询日期"
  1512. return
  1513. }
  1514. var startDateReal string
  1515. var diffSeconds int64
  1516. if leadValue > 0 && leadUnit != "" {
  1517. var startTimeRealTemp time.Time
  1518. startDateParse, err := time.Parse(utils.FormatDate, startDate)
  1519. if err != nil {
  1520. br.Msg = "获取数据失败"
  1521. br.ErrMsg = "获取数据失败,日期格式错误:startDate:" + startDate
  1522. return
  1523. }
  1524. switch leadUnit {
  1525. case "天":
  1526. startTimeRealTemp = startDateParse.AddDate(0, 0, -leadValue)
  1527. case "月":
  1528. startTimeRealTemp = startDateParse.AddDate(0, -leadValue, 0)
  1529. case "季":
  1530. startTimeRealTemp = startDateParse.AddDate(0, -3*leadValue, 0)
  1531. case "周":
  1532. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*leadValue)
  1533. case "年":
  1534. startTimeRealTemp = startDateParse.AddDate(-leadValue, 0, 0)
  1535. }
  1536. if startTimeRealTemp.Before(startDateParse) {
  1537. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  1538. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  1539. } else {
  1540. startDateReal = startDate
  1541. diffSeconds = 0
  1542. }
  1543. } else {
  1544. startDateReal = startDate
  1545. }
  1546. var dataList []*data_manage.EdbDataList
  1547. var minData, maxData float64
  1548. switch edbInfo.EdbInfoType {
  1549. case 0: //普通源指标
  1550. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1551. if err != nil {
  1552. br.Msg = "获取失败"
  1553. br.Msg = "获取失败,Err:" + err.Error()
  1554. return
  1555. }
  1556. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1557. if err != nil {
  1558. br.Msg = "获取失败"
  1559. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1560. return
  1561. }
  1562. case 1: //预测指标
  1563. tmpDataList, sourceEdbInfoItem, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDateReal, endDate, isTimeBetween)
  1564. if err != nil {
  1565. br.Msg = "获取失败"
  1566. br.Msg = "获取失败,Err:" + err.Error()
  1567. return
  1568. }
  1569. dataList = tmpDataList
  1570. if len(dataList) > 0 && edbInfo.EdbInfoType == 0 {
  1571. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, sourceEdbInfoItem.EdbInfoId, startDateReal, endDate)
  1572. if err != nil {
  1573. br.Msg = "获取失败"
  1574. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1575. return
  1576. }
  1577. tmpValue := dataList[len(dataList)-1]
  1578. if edbInfo.MaxValue < tmpValue.Value {
  1579. maxData = tmpValue.Value
  1580. }
  1581. if edbInfo.MinValue > tmpValue.Value {
  1582. minData = tmpValue.Value
  1583. }
  1584. }
  1585. }
  1586. moveLatestDate := edbInfo.LatestDate
  1587. if diffSeconds != 0 {
  1588. dataListLen := len(dataList)
  1589. for i := 0; i < dataListLen; i++ {
  1590. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  1591. }
  1592. day, err := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  1593. if err != nil {
  1594. br.Msg = "获取失败"
  1595. br.Msg = "获取领先滞后的的日期间隔失败,Err:" + err.Error()
  1596. return
  1597. }
  1598. moveLatestDateTime, err := time.ParseInLocation(utils.FormatDate, moveLatestDate, time.Local)
  1599. if err != nil {
  1600. br.Msg = "获取失败"
  1601. br.Msg = "指标日期转换失败,Err:" + err.Error()
  1602. return
  1603. }
  1604. moveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  1605. }
  1606. mapping := new(data_manage.ChartEdbInfoMapping)
  1607. mapping.EdbInfoId = edbInfo.EdbInfoId
  1608. mapping.EdbInfoCategoryType = edbInfo.EdbInfoType
  1609. mapping.SourceName = edbInfo.SourceName
  1610. mapping.Source = edbInfo.Source
  1611. mapping.EdbCode = edbInfo.EdbCode
  1612. mapping.EdbName = edbInfo.EdbName
  1613. mapping.EdbType = edbInfo.EdbType
  1614. mapping.Frequency = edbInfo.Frequency
  1615. mapping.Unit = edbInfo.Unit
  1616. mapping.StartDate = utils.TimeToFormatDate(edbInfo.StartDate)
  1617. mapping.EndDate = utils.TimeToFormatDate(edbInfo.EndDate)
  1618. mapping.ChartEdbMappingId = 0
  1619. mapping.ChartInfoId = 0
  1620. mapping.MaxData = maxData
  1621. mapping.MinData = minData
  1622. mapping.IsOrder = false
  1623. mapping.IsAxis = 1
  1624. mapping.EdbInfoType = 1
  1625. mapping.LeadValue = 0
  1626. mapping.LeadUnit = ""
  1627. mapping.LeadUnitEn = ""
  1628. mapping.ChartStyle = ""
  1629. mapping.ChartColor = ""
  1630. mapping.PredictChartColor = ""
  1631. mapping.ChartWidth = 0
  1632. mapping.LatestDate = edbInfo.LatestDate
  1633. mapping.MoveLatestDate = moveLatestDate
  1634. mapping.DataList = dataList
  1635. resp := new(data_manage.ChartEdbInfoDetailResp)
  1636. resp.EdbInfo = mapping
  1637. br.Ret = 200
  1638. br.Success = true
  1639. br.Msg = "获取成功"
  1640. br.Data = resp
  1641. }
  1642. // @router /chart_info/search [get]
  1643. func (this *ChartInfoController) ChartInfoSearch() {
  1644. br := new(models.BaseResponse).Init()
  1645. defer func() {
  1646. this.Data["json"] = br
  1647. this.ServeJSON()
  1648. }()
  1649. sysUser := this.SysUser
  1650. if sysUser == nil {
  1651. br.Msg = "请登录"
  1652. br.ErrMsg = "请登录,SysUser Is Empty"
  1653. br.Ret = 408
  1654. return
  1655. }
  1656. keyWord := this.GetString("KeyWord")
  1657. searchList := make([]data_manage.ChartInfoMore, 0)
  1658. isShowMe, _ := this.GetBool("IsShowMe")
  1659. showSysId := 0
  1660. if isShowMe {
  1661. showSysId = sysUser.AdminId
  1662. }
  1663. var keyWordArr []string
  1664. keyWordArr = append(keyWordArr, keyWord)
  1665. if keyWord != "" {
  1666. newKeyWord := strings.Split(keyWord, " ")
  1667. keyWordArr = append(keyWordArr, newKeyWord...)
  1668. }
  1669. existMap := make(map[int]string)
  1670. for _, v := range keyWordArr {
  1671. v = strings.Replace(v, " ", "%", -1)
  1672. newSearchList, err := data_manage.ChartInfoSearchByKeyWord(v, showSysId)
  1673. if err != nil && !utils.IsErrNoRow(err) {
  1674. br.Msg = "获取失败"
  1675. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1676. return
  1677. }
  1678. for _, nv := range newSearchList {
  1679. if _, ok := existMap[nv.ChartInfoId]; !ok {
  1680. searchList = append(searchList, data_manage.ChartInfoMore{
  1681. ChartInfo: *nv,
  1682. })
  1683. }
  1684. existMap[nv.ChartInfoId] = nv.ChartName
  1685. }
  1686. }
  1687. if searchList == nil {
  1688. searchList = make([]data_manage.ChartInfoMore, 0)
  1689. }
  1690. if len(searchList) > 0 {
  1691. classifyIdList := make([]int, 0)
  1692. for _, v := range searchList {
  1693. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1694. }
  1695. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1696. if err != nil {
  1697. br.Msg = "获取失败"
  1698. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  1699. return
  1700. }
  1701. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1702. for _, v := range chartClassifyList {
  1703. chartClassifyMap[v.ChartClassifyId] = v
  1704. }
  1705. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1706. if err != nil {
  1707. br.Msg = "获取失败"
  1708. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  1709. return
  1710. }
  1711. for k, v := range searchList {
  1712. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  1713. searchList[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1714. }
  1715. }
  1716. }
  1717. {
  1718. searchKeyword := new(data_manage.SearchKeyword)
  1719. searchKeyword.KeyWord = keyWord
  1720. searchKeyword.CreateTime = time.Now()
  1721. go data_manage.AddSearchKeyword(searchKeyword)
  1722. }
  1723. br.Ret = 200
  1724. br.Success = true
  1725. br.Msg = "获取成功"
  1726. br.Data = searchList
  1727. }
  1728. // @router /chart_info/search_by_es [get]
  1729. func (this *ChartInfoController) ChartInfoSearchByEs() {
  1730. br := new(models.BaseResponse).Init()
  1731. defer func() {
  1732. this.Data["json"] = br
  1733. this.ServeJSON()
  1734. }()
  1735. sysUser := this.SysUser
  1736. if sysUser == nil {
  1737. br.Msg = "请登录"
  1738. br.ErrMsg = "请登录,SysUser Is Empty"
  1739. br.Ret = 408
  1740. return
  1741. }
  1742. pageSize, _ := this.GetInt("PageSize")
  1743. currentIndex, _ := this.GetInt("CurrentIndex")
  1744. var startSize int
  1745. if pageSize <= 0 {
  1746. pageSize = utils.PageSize20
  1747. }
  1748. if currentIndex <= 0 {
  1749. currentIndex = 1
  1750. }
  1751. startSize = paging.StartIndex(currentIndex, pageSize)
  1752. keyword := this.GetString("Keyword")
  1753. isShowMe, _ := this.GetBool("IsShowMe")
  1754. showSysId := 0
  1755. if isShowMe {
  1756. showSysId = sysUser.AdminId
  1757. }
  1758. var searchList []*data_manage.ChartInfo
  1759. var total int64
  1760. var err error
  1761. noPermissionChartIdList := make([]int, 0)
  1762. {
  1763. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1764. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1765. if err != nil && !utils.IsErrNoRow(err) {
  1766. br.Msg = "获取失败"
  1767. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1768. return
  1769. }
  1770. for _, v := range confList {
  1771. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1772. }
  1773. }
  1774. isEs := false
  1775. if keyword != "" {
  1776. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  1777. isEs = true
  1778. } else {
  1779. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  1780. if err != nil && !utils.IsErrNoRow(err) {
  1781. br.Msg = "获取失败"
  1782. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1783. return
  1784. }
  1785. }
  1786. finalList := make([]*data_manage.ChartInfoMore, 0)
  1787. if len(searchList) > 0 {
  1788. classifyIdList := make([]int, 0)
  1789. chartInfoIdList := make([]int, 0)
  1790. chartInfoIds := ""
  1791. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1792. for _, v := range searchList {
  1793. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1794. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1795. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1796. }
  1797. if chartInfoIds != "" {
  1798. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1799. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1800. if e != nil {
  1801. br.Msg = "获取失败"
  1802. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1803. return
  1804. }
  1805. for _, v := range edbList {
  1806. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1807. }
  1808. }
  1809. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1810. {
  1811. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1812. if err != nil {
  1813. br.Msg = "获取失败"
  1814. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  1815. return
  1816. }
  1817. for _, v := range chartClassifyList {
  1818. chartClassifyMap[v.ChartClassifyId] = v
  1819. }
  1820. }
  1821. if isEs {
  1822. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  1823. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1824. if err != nil {
  1825. br.Msg = "获取失败"
  1826. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  1827. return
  1828. }
  1829. for _, tmpChartInfo := range tmpChartList {
  1830. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  1831. }
  1832. for _, v := range searchList {
  1833. chartViewInfo, ok := chartInfoMap[v.ChartInfoId]
  1834. if !ok {
  1835. continue
  1836. }
  1837. v.IsJoinPermission = chartViewInfo.IsJoinPermission
  1838. }
  1839. }
  1840. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1841. if err != nil {
  1842. br.Msg = "获取失败"
  1843. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  1844. return
  1845. }
  1846. for _, v := range searchList {
  1847. tmp := new(data_manage.ChartInfoMore)
  1848. tmp.ChartInfo = *v
  1849. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  1850. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  1851. }
  1852. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  1853. tmp.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1854. }
  1855. finalList = append(finalList, tmp)
  1856. }
  1857. }
  1858. {
  1859. searchKeyword := new(data_manage.SearchKeyword)
  1860. searchKeyword.KeyWord = keyword
  1861. searchKeyword.CreateTime = time.Now()
  1862. go data_manage.AddSearchKeyword(searchKeyword)
  1863. }
  1864. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1865. resp := data_manage.ChartInfoListByEsResp{
  1866. Paging: page,
  1867. List: finalList,
  1868. }
  1869. br.Ret = 200
  1870. br.Success = true
  1871. br.Msg = "获取成功"
  1872. br.Data = resp
  1873. }
  1874. // @router /chart_info/refresh [get]
  1875. func (this *EdbInfoController) ChartInfoRefresh() {
  1876. br := new(models.BaseResponse).Init()
  1877. defer func() {
  1878. this.Data["json"] = br
  1879. this.ServeJSON()
  1880. }()
  1881. sysUser := this.SysUser
  1882. if sysUser == nil {
  1883. br.Msg = "请登录"
  1884. br.ErrMsg = "请登录,SysUser Is Empty"
  1885. br.Ret = 408
  1886. return
  1887. }
  1888. chartInfoId, _ := this.GetInt("ChartInfoId")
  1889. uniqueCode := this.GetString("UniqueCode")
  1890. if chartInfoId <= 0 && uniqueCode == `` {
  1891. br.Msg = "参数错误"
  1892. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  1893. return
  1894. }
  1895. var chartInfo *data_manage.ChartInfo
  1896. var err error
  1897. if chartInfoId > 0 {
  1898. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  1899. } else {
  1900. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  1901. }
  1902. if err != nil {
  1903. if utils.IsErrNoRow(err) {
  1904. br.Msg = "图表已被删除,无需刷新"
  1905. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1906. return
  1907. }
  1908. br.Msg = "刷新失败"
  1909. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1910. return
  1911. }
  1912. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  1913. if err != nil {
  1914. br.Msg = "刷新失败"
  1915. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  1916. return
  1917. }
  1918. {
  1919. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1920. _ = utils.Rc.Delete(key)
  1921. }
  1922. br.Ret = 200
  1923. br.Success = true
  1924. br.Msg = "刷新成功"
  1925. if isAsync {
  1926. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  1927. }
  1928. }
  1929. // @router /chart_info/image/set [post]
  1930. func (this *ChartInfoController) ChartInfoImageSet() {
  1931. br := new(models.BaseResponse).Init()
  1932. defer func() {
  1933. this.Data["json"] = br
  1934. this.ServeJSON()
  1935. }()
  1936. sysUser := this.SysUser
  1937. if sysUser == nil {
  1938. br.Msg = "请登录"
  1939. br.ErrMsg = "请登录,SysUser Is Empty"
  1940. br.Ret = 408
  1941. return
  1942. }
  1943. var req data_manage.SetChartInfoImageReq
  1944. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1945. if err != nil {
  1946. br.Msg = "参数解析异常!"
  1947. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1948. return
  1949. }
  1950. if req.ChartInfoId > 0 && req.ImageUrl != "" {
  1951. err = data_manage.EditChartInfoImage(&req)
  1952. if err != nil {
  1953. br.Msg = "保存失败"
  1954. br.ErrMsg = "保存失败,Err:" + err.Error()
  1955. return
  1956. }
  1957. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  1958. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  1959. }
  1960. br.Ret = 200
  1961. br.Success = true
  1962. br.Msg = "保存成功"
  1963. }
  1964. // @router /chart_info/detail/from_unique_code [get]
  1965. func (this *ChartInfoController) ChartInfoDetailFromUniqueCode() {
  1966. br := new(models.BaseResponse).Init()
  1967. defer func() {
  1968. this.Data["json"] = br
  1969. this.ServeJSON()
  1970. }()
  1971. sysUser := this.SysUser
  1972. if sysUser == nil {
  1973. br.Msg = "请登录"
  1974. br.ErrMsg = "请登录,SysUser Is Empty"
  1975. br.Ret = 408
  1976. return
  1977. }
  1978. uniqueCode := this.GetString("UniqueCode")
  1979. if uniqueCode == "" {
  1980. br.Msg = "参数错误"
  1981. br.ErrMsg = "参数错误,uniqueCode is empty"
  1982. return
  1983. }
  1984. isCache, _ := this.GetBool("IsCache")
  1985. status := true
  1986. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1987. if err != nil {
  1988. if utils.IsErrNoRow(err) {
  1989. status = false
  1990. } else {
  1991. br.Msg = "获取失败"
  1992. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1993. return
  1994. }
  1995. }
  1996. if chartInfo == nil {
  1997. status = false
  1998. }
  1999. if !status {
  2000. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2001. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  2002. resp.EdbInfoList = endInfoList
  2003. resp.ChartInfo = chartInfo
  2004. resp.Status = false
  2005. return
  2006. }
  2007. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  2008. if !isOk {
  2009. br.Msg = msg
  2010. br.ErrMsg = errMsg
  2011. return
  2012. }
  2013. br.Ret = 200
  2014. br.Success = true
  2015. msg = "获取成功"
  2016. br.Data = resp
  2017. }
  2018. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  2019. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2020. msg = `获取失败`
  2021. adminId := sysUser.AdminId
  2022. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  2023. if err != nil {
  2024. errMsg = "获取图表分类信息失败,Err:" + err.Error()
  2025. return
  2026. }
  2027. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  2028. if err != nil {
  2029. errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  2030. return
  2031. }
  2032. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  2033. defer func() {
  2034. if isOk {
  2035. {
  2036. var myChartCondition string
  2037. var myChartPars []interface{}
  2038. myChartCondition += ` AND a.admin_id=? `
  2039. myChartPars = append(myChartPars, adminId)
  2040. myChartCondition += ` AND a.chart_info_id=? `
  2041. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2042. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2043. if err != nil && !utils.IsErrNoRow(err) {
  2044. msg = "获取失败"
  2045. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2046. return
  2047. }
  2048. if myChartList != nil && len(myChartList) > 0 {
  2049. chartInfo.IsAdd = true
  2050. chartInfo.MyChartId = myChartList[0].MyChartId
  2051. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2052. }
  2053. }
  2054. {
  2055. resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  2056. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
  2057. chartInfo.Button = data_manage.ChartViewButton{
  2058. IsEdit: chartInfo.IsEdit,
  2059. IsEnChart: chartInfo.IsEnChart,
  2060. IsAdd: chartInfo.IsAdd,
  2061. IsCopy: true,
  2062. IsSetName: chartInfo.IsSetName,
  2063. }
  2064. }
  2065. {
  2066. classifyMap := make(map[int]*data_manage.EdbClassify)
  2067. {
  2068. classifyIdList := make([]int, 0)
  2069. for _, v := range resp.EdbInfoList {
  2070. classifyIdList = append(classifyIdList, v.ClassifyId)
  2071. }
  2072. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  2073. if tmpErr != nil {
  2074. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  2075. return
  2076. }
  2077. for _, v := range classifyList {
  2078. classifyMap[v.ClassifyId] = v
  2079. }
  2080. }
  2081. if len(edbClassifyPermissionMap) < 0 {
  2082. edbInfoIdList := make([]int, 0)
  2083. for _, v := range resp.EdbInfoList {
  2084. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  2085. }
  2086. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  2087. if tmpErr != nil {
  2088. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  2089. return
  2090. }
  2091. for _, v := range edbInfoList {
  2092. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2093. ClassifyId: v.ClassifyId,
  2094. IsJoinPermission: v.IsJoinPermission,
  2095. EdbInfoId: v.EdbInfoId,
  2096. }
  2097. }
  2098. }
  2099. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2100. if err != nil {
  2101. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  2102. return
  2103. }
  2104. for _, v := range resp.EdbInfoList {
  2105. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  2106. if !ok {
  2107. continue
  2108. }
  2109. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  2110. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }()
  2116. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  2117. if utils.Re == nil && isCache {
  2118. if utils.Re == nil && utils.Rc.IsExist(key) {
  2119. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  2120. err := json.Unmarshal(redisData, &resp)
  2121. if err != nil || resp == nil {
  2122. return
  2123. }
  2124. isOk = true
  2125. fmt.Println("source redis")
  2126. return
  2127. }
  2128. }
  2129. }
  2130. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  2131. if err != nil {
  2132. msg = "获取失败"
  2133. errMsg = "获取主题信息失败,Err:" + err.Error()
  2134. return
  2135. }
  2136. chartInfo.ChartThemeStyle = chartTheme.Config
  2137. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  2138. chartInfoId := chartInfo.ChartInfoId
  2139. dateType := chartInfo.DateType
  2140. startDate := chartInfo.StartDate
  2141. endDate := chartInfo.EndDate
  2142. startYear := chartInfo.StartYear
  2143. calendar := chartInfo.Calendar
  2144. chartType := chartInfo.ChartType
  2145. if calendar == "" {
  2146. calendar = "公历"
  2147. }
  2148. fmt.Println("a dateType:", dateType)
  2149. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  2150. if err != nil {
  2151. msg = "获取失败"
  2152. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2153. return
  2154. }
  2155. yearMax := 0
  2156. if dateType == utils.DateTypeNYears {
  2157. for _, v := range mappingList {
  2158. if v.LatestDate != "" {
  2159. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  2160. if tErr != nil {
  2161. msg = "获取失败"
  2162. errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  2163. return
  2164. }
  2165. if lastDateT.Year() > yearMax {
  2166. yearMax = lastDateT.Year()
  2167. }
  2168. }
  2169. }
  2170. }
  2171. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  2172. extraConfigStr := chartInfo.ExtraConfig //图表额外数据参数
  2173. var barConfig data_manage.BarChartInfoReq
  2174. if chartInfo != nil && chartInfo.ChartType == 7 {
  2175. if chartInfo.BarConfig == `` {
  2176. msg = "柱方图未配置"
  2177. errMsg = "柱方图未配置"
  2178. return
  2179. }
  2180. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  2181. if err != nil {
  2182. msg = "柱方图配置异常"
  2183. errMsg = "柱方图配置异常"
  2184. return
  2185. }
  2186. extraConfigStr = chartInfo.BarConfig
  2187. }
  2188. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  2189. if err != nil {
  2190. msg = "获取失败"
  2191. if errMsg != `` {
  2192. msg = errMsg
  2193. }
  2194. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2195. return
  2196. }
  2197. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  2198. chartInfo.Unit = yDataList[0].Unit
  2199. chartInfo.UnitEn = yDataList[0].UnitEn
  2200. }
  2201. warnEdbList := make([]string, 0)
  2202. for _, v := range edbList {
  2203. if v.IsNullData {
  2204. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2205. }
  2206. }
  2207. if len(warnEdbList) > 0 {
  2208. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2209. }
  2210. chartViewClassify, _ := data_manage.GetChartClassifyViewById(chartInfo.ChartClassifyId)
  2211. if chartViewClassify != nil {
  2212. chartClassifyParent, _ := data_manage.GetChartClassifyViewById(chartClassify.ParentId)
  2213. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartClassifyParent)
  2214. }
  2215. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartViewClassify)
  2216. if len(edbList) <= 0 {
  2217. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  2218. }
  2219. resp.EdbInfoList = edbList
  2220. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  2221. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2222. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2223. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2224. resp.ChartInfo = chartInfo
  2225. resp.XEdbIdValue = xEdbIdValue
  2226. resp.YDataList = yDataList
  2227. resp.Status = true
  2228. resp.BarChartInfo = barConfig
  2229. resp.DataResp = dataResp
  2230. if utils.Re == nil {
  2231. data, _ := json.Marshal(resp)
  2232. utils.Rc.Put(key, data, 2*time.Hour)
  2233. }
  2234. isOk = true
  2235. for _, v := range edbList {
  2236. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2237. ClassifyId: v.ClassifyId,
  2238. IsJoinPermission: v.IsJoinPermission,
  2239. EdbInfoId: v.EdbInfoId,
  2240. }
  2241. }
  2242. return
  2243. }
  2244. // @router /chart_info/base64Upload [post]
  2245. func (this *ChartInfoController) ChartInfoBase64Upload() {
  2246. br := new(models.BaseResponse).Init()
  2247. defer func() {
  2248. this.Data["json"] = br
  2249. this.ServeJSON()
  2250. }()
  2251. imgData := this.GetString("Img")
  2252. if imgData == "" {
  2253. br.Msg = "图片参数错误"
  2254. br.ErrMsg = "图片参数错误,Img Is Empty"
  2255. return
  2256. }
  2257. resp := new(models.ResourceResp)
  2258. uploadDir := "static/images/"
  2259. if !utils.FileIsExist(uploadDir) {
  2260. err := os.MkdirAll(uploadDir, utils.DIR_MOD)
  2261. if err != nil {
  2262. br.Msg = "图表保存失败"
  2263. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  2264. return
  2265. }
  2266. }
  2267. randStr := utils.GetRandStringNoSpecialChar(28)
  2268. var fileName, outFileName string
  2269. fileName = randStr + ".txt"
  2270. fileName = uploadDir + fileName
  2271. err := utils.SaveToFile(imgData, fileName)
  2272. if err != nil {
  2273. br.Msg = "图片保存失败"
  2274. br.ErrMsg = "图片保存失败,Err:" + err.Error()
  2275. return
  2276. }
  2277. outFileName = randStr + ".png"
  2278. doneChannel := make(chan bool, 1)
  2279. errorChannel := make(chan error, 1)
  2280. cmd := exec.Command("highcharts-export-server", "--infile", fileName, "--constr", "Chart", "--scale", "2", "--workers", "10", "--workLimit", "3", "--outfile", outFileName)
  2281. go func() {
  2282. output, err := cmd.CombinedOutput()
  2283. if err != nil {
  2284. utils.FileLog.Info("execute command failed, output: , error: \n" + string(output) + err.Error())
  2285. errorChannel <- err
  2286. return
  2287. }
  2288. doneChannel <- true
  2289. }()
  2290. select {
  2291. case <-time.After(30 * time.Second):
  2292. utils.FileLog.Info("执行超过30秒 杀死超时进程")
  2293. e := cmd.Process.Kill()
  2294. if e != nil {
  2295. fmt.Println("cmd kill err: ", e.Error())
  2296. utils.FileLog.Info(fmt.Sprintf("cmd kill err: %s", e.Error()))
  2297. br.Msg = "图片生成失败"
  2298. br.ErrMsg = "图片生成失败, 执行超时" + e.Error()
  2299. return
  2300. }
  2301. fmt.Println("timeout kill process")
  2302. case <-doneChannel:
  2303. fmt.Println("done")
  2304. case err := <-errorChannel:
  2305. br.Msg = "文件上传失败"
  2306. br.ErrMsg = fmt.Sprintf("execute command failure err: %s", err.Error())
  2307. fmt.Println("execute command failure err:" + err.Error())
  2308. return
  2309. }
  2310. defer func() {
  2311. os.Remove(fileName)
  2312. os.Remove(outFileName)
  2313. }()
  2314. resourceUrl := ``
  2315. ossClient := services.NewOssClient()
  2316. if ossClient == nil {
  2317. br.Msg = "上传失败"
  2318. br.ErrMsg = "初始化OSS服务失败"
  2319. return
  2320. }
  2321. resourceUrl, err = ossClient.UploadFile(outFileName, outFileName, "")
  2322. if err != nil {
  2323. br.Msg = "文件上传失败"
  2324. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2325. return
  2326. }
  2327. resp.ResourceUrl = resourceUrl
  2328. resp.Source = "convert"
  2329. br.Msg = "上传成功"
  2330. br.Ret = 200
  2331. br.Success = true
  2332. br.Data = resp
  2333. return
  2334. }
  2335. // @router /chart_info/batch_refresh [post]
  2336. func (this *EdbInfoController) BatchChartInfoRefresh() {
  2337. br := new(models.BaseResponse).Init()
  2338. defer func() {
  2339. this.Data["json"] = br
  2340. this.ServeJSON()
  2341. }()
  2342. sysUser := this.SysUser
  2343. if sysUser == nil {
  2344. br.Msg = "请登录"
  2345. br.ErrMsg = "请登录,SysUser Is Empty"
  2346. br.Ret = 408
  2347. return
  2348. }
  2349. var req data_manage.BatchChartRefreshReq
  2350. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2351. if err != nil {
  2352. br.Msg = "参数解析异常!"
  2353. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2354. return
  2355. }
  2356. if req.Source == "" {
  2357. br.Msg = "刷新来源有误"
  2358. return
  2359. }
  2360. if req.PrimaryId <= 0 {
  2361. br.Msg = "刷新对象有误"
  2362. return
  2363. }
  2364. _, chartInfoList, err := data_manage.GetChartInfoListByUniqueCodeSlice(req.ChartInfoCode)
  2365. if len(chartInfoList) <= 0 {
  2366. br.Ret = 200
  2367. br.Success = true
  2368. br.Msg = "刷新成功"
  2369. return
  2370. }
  2371. redisKey := data.GetBatchChartRefreshKey(req.Source, req.PrimaryId, req.SubId)
  2372. err, isAsync := data.BatchChartInfoRefreshV2(chartInfoList, redisKey)
  2373. if err != nil {
  2374. br.Msg = "刷新失败"
  2375. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2376. return
  2377. }
  2378. br.Msg = "刷新成功"
  2379. if isAsync {
  2380. br.Msg = "研报中图表关联指标较多,请10分钟后刷新页面查看最新数据"
  2381. }
  2382. br.Ret = 200
  2383. br.Success = true
  2384. }
  2385. // @router /chart_info/copy [post]
  2386. func (this *ChartInfoController) CopyChartInfo() {
  2387. br := new(models.BaseResponse).Init()
  2388. defer func() {
  2389. this.Data["json"] = br
  2390. this.ServeJSON()
  2391. }()
  2392. sysUser := this.SysUser
  2393. if sysUser == nil {
  2394. br.Msg = "请登录"
  2395. br.ErrMsg = "请登录,SysUser Is Empty"
  2396. br.Ret = 408
  2397. return
  2398. }
  2399. deleteCache := true
  2400. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2401. defer func() {
  2402. if deleteCache {
  2403. utils.Rc.Delete(cacheKey)
  2404. }
  2405. }()
  2406. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2407. deleteCache = false
  2408. br.Msg = "系统处理中,请稍后重试!"
  2409. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2410. return
  2411. }
  2412. var req data_manage.CopyAddChartInfoReq
  2413. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2414. if err != nil {
  2415. br.Msg = "参数解析异常!"
  2416. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2417. return
  2418. }
  2419. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2420. if err != nil {
  2421. br.Msg = "获取原图表信息失败"
  2422. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  2423. return
  2424. }
  2425. req.ChartName = strings.Trim(req.ChartName, " ")
  2426. if req.ChartName == "" {
  2427. br.Msg = "请填写图表名称!"
  2428. return
  2429. }
  2430. if req.ChartClassifyId <= 0 {
  2431. br.Msg = "分类参数错误!"
  2432. return
  2433. }
  2434. chartClassify, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  2435. if err != nil {
  2436. if utils.IsErrNoRow(err) {
  2437. br.Msg = "分类不存在"
  2438. br.ErrMsg = "分类不存在"
  2439. return
  2440. }
  2441. br.Msg = "获取分类信息失败"
  2442. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2443. return
  2444. }
  2445. if chartClassify == nil {
  2446. br.Msg = "分类不存在"
  2447. br.ErrMsg = "分类不存在"
  2448. return
  2449. }
  2450. var condition string
  2451. var pars []interface{}
  2452. condition += " AND chart_classify_id=? "
  2453. pars = append(pars, req.ChartClassifyId)
  2454. condition += " AND chart_name=? AND source = ? "
  2455. pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT)
  2456. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  2457. if err != nil {
  2458. br.Msg = "判断图表名称是否存在失败"
  2459. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  2460. return
  2461. }
  2462. if count > 0 {
  2463. br.Msg = "图表已存在,请重新填写"
  2464. br.IsSendEmail = false
  2465. return
  2466. }
  2467. edbMappingList, err := data_manage.GetChartEdbMappingList(req.ChartInfoId)
  2468. if err != nil {
  2469. br.Msg = "获取图表关联的指标信息失败!"
  2470. return
  2471. }
  2472. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2473. chartInfo := &data_manage.ChartInfo{
  2474. ChartInfoId: 0,
  2475. ChartName: req.ChartName,
  2476. ChartClassifyId: req.ChartClassifyId,
  2477. SysUserId: sysUser.AdminId,
  2478. SysUserRealName: sysUser.RealName,
  2479. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2480. CreateTime: time.Now(),
  2481. ModifyTime: time.Now(),
  2482. DateType: oldChartInfo.DateType,
  2483. StartDate: oldChartInfo.StartDate,
  2484. EndDate: oldChartInfo.EndDate,
  2485. IsSetName: oldChartInfo.IsSetName,
  2486. EdbInfoIds: oldChartInfo.EdbInfoIds,
  2487. ChartType: oldChartInfo.ChartType,
  2488. Calendar: oldChartInfo.Calendar,
  2489. SeasonStartDate: oldChartInfo.SeasonStartDate,
  2490. SeasonEndDate: oldChartInfo.SeasonEndDate,
  2491. ChartImage: oldChartInfo.ChartImage,
  2492. BarConfig: oldChartInfo.BarConfig,
  2493. LeftMin: oldChartInfo.LeftMin,
  2494. LeftMax: oldChartInfo.LeftMax,
  2495. RightMin: oldChartInfo.RightMin,
  2496. RightMax: oldChartInfo.RightMax,
  2497. Right2Min: oldChartInfo.Right2Min,
  2498. Right2Max: oldChartInfo.Right2Max,
  2499. Disabled: oldChartInfo.Disabled,
  2500. Source: oldChartInfo.Source,
  2501. ExtraConfig: oldChartInfo.ExtraConfig,
  2502. SeasonExtraConfig: oldChartInfo.SeasonExtraConfig,
  2503. StartYear: oldChartInfo.StartYear,
  2504. Unit: oldChartInfo.Unit,
  2505. UnitEn: oldChartInfo.UnitEn,
  2506. ChartThemeId: oldChartInfo.ChartThemeId,
  2507. SourcesFrom: oldChartInfo.SourcesFrom,
  2508. Instructions: oldChartInfo.Instructions,
  2509. MarkersLines: oldChartInfo.MarkersLines,
  2510. MarkersAreas: oldChartInfo.MarkersAreas,
  2511. }
  2512. newId, err := data_manage.AddChartInfo(chartInfo)
  2513. if err != nil {
  2514. br.Msg = "保存失败"
  2515. br.ErrMsg = "保存失败,Err:" + err.Error()
  2516. return
  2517. }
  2518. chartInfo.ChartInfoId = int(newId)
  2519. {
  2520. mapList := make([]*data_manage.ChartEdbMapping, 0)
  2521. for _, v := range edbMappingList {
  2522. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2523. mapItem := &data_manage.ChartEdbMapping{
  2524. ChartInfoId: chartInfo.ChartInfoId,
  2525. EdbInfoId: v.EdbInfoId,
  2526. CreateTime: time.Now(),
  2527. ModifyTime: time.Now(),
  2528. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2529. MaxData: v.MaxData,
  2530. MinData: v.MinData,
  2531. IsOrder: v.IsOrder,
  2532. IsAxis: v.IsAxis,
  2533. EdbInfoType: v.EdbInfoType,
  2534. LeadValue: v.LeadValue,
  2535. LeadUnit: v.LeadUnit,
  2536. ChartStyle: v.ChartStyle,
  2537. ChartColor: v.ChartColor,
  2538. ChartWidth: v.ChartWidth,
  2539. Source: v.Source,
  2540. EdbAliasName: v.EdbAliasName,
  2541. IsConvert: v.IsConvert,
  2542. ConvertType: v.ConvertType,
  2543. ConvertValue: v.ConvertValue,
  2544. ConvertUnit: v.ConvertEnUnit,
  2545. ConvertEnUnit: v.ConvertEnUnit,
  2546. }
  2547. mapList = append(mapList, mapItem)
  2548. }
  2549. err = data_manage.AddChartEdbMapping(mapList)
  2550. if err != nil {
  2551. br.Msg = "保存失败"
  2552. br.ErrMsg = "保存失败,Err:" + err.Error()
  2553. return
  2554. }
  2555. }
  2556. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  2557. chartSeriesList, e := data_manage.GetChartSeriesByChartInfoId(oldChartInfo.ChartInfoId)
  2558. if e != nil {
  2559. br.Msg = "获取图表关联的系列信息失败"
  2560. br.ErrMsg = "获取图表关联的系列信息失败,Err:" + e.Error()
  2561. return
  2562. }
  2563. chartSeriesEdbList, e := data_manage.GetChartSeriesEdbByChartInfoId(oldChartInfo.ChartInfoId)
  2564. if err != nil {
  2565. br.Msg = "获取图表关联的系列指标信息失败"
  2566. br.ErrMsg = "获取图表关联的系列指标信息失败,Err:" + err.Error()
  2567. return
  2568. }
  2569. err = data_manage.CopyChartSeriesAndEdbMapping(chartSeriesList, chartSeriesEdbList, chartInfo.ChartInfoId)
  2570. if err != nil {
  2571. br.Msg = "保存失败"
  2572. br.ErrMsg = "保存图表系列失败,Err:" + err.Error()
  2573. return
  2574. }
  2575. }
  2576. go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  2577. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfo.ChartInfoId)
  2578. {
  2579. chartLog := new(data_manage.ChartInfoLog)
  2580. chartLog.ChartInfoId = chartInfo.ChartInfoId
  2581. chartLog.ChartName = req.ChartName
  2582. chartLog.ChartClassifyId = req.ChartClassifyId
  2583. chartLog.SysUserId = sysUser.AdminId
  2584. chartLog.SysUserRealName = sysUser.RealName
  2585. chartLog.UniqueCode = chartInfo.UniqueCode
  2586. chartLog.CreateTime = time.Now()
  2587. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2588. chartLog.Status = "新增图表"
  2589. chartLog.Method = this.Ctx.Input.URI()
  2590. go data_manage.AddChartInfoLog(chartLog)
  2591. }
  2592. br.Ret = 200
  2593. br.Success = true
  2594. br.Msg = "保存成功"
  2595. br.Data = data_manage.AddChartInfoResp{
  2596. ChartInfoId: chartInfo.ChartInfoId,
  2597. UniqueCode: chartInfo.UniqueCode,
  2598. ChartType: chartInfo.ChartType,
  2599. }
  2600. br.IsAddLog = true
  2601. }
  2602. // @router /chart_info/preview_bar [post]
  2603. func (this *ChartInfoController) PreviewBarChartInfo() {
  2604. br := new(models.BaseResponse).Init()
  2605. defer func() {
  2606. this.Data["json"] = br
  2607. this.ServeJSON()
  2608. }()
  2609. var req data_manage.BarChartInfoReq
  2610. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2611. if err != nil {
  2612. br.Msg = "参数解析异常!"
  2613. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2614. return
  2615. }
  2616. sysUser := this.SysUser
  2617. if sysUser == nil {
  2618. br.Msg = "请登录"
  2619. br.ErrMsg = "请登录,SysUser Is Empty"
  2620. br.Ret = 408
  2621. return
  2622. }
  2623. if len(req.EdbInfoIdList) <= 0 {
  2624. br.Msg = "请选择指标"
  2625. return
  2626. }
  2627. if len(req.DateList) <= 0 {
  2628. br.Msg = "请选择日期"
  2629. return
  2630. }
  2631. chartInfo := new(data_manage.ChartInfoView)
  2632. chartType := utils.CHART_TYPE_BAR
  2633. edbInfoIdsList := make([]string, 0)
  2634. convertMap := make(map[int]*data_manage.ChartEdbInfoMapping, 0)
  2635. for _, v := range req.EdbInfoIdList {
  2636. edbInfoIdsList = append(edbInfoIdsList, strconv.Itoa(v.EdbInfoId))
  2637. convertMap[v.EdbInfoId] = &data_manage.ChartEdbInfoMapping{
  2638. IsConvert: v.IsConvert,
  2639. ConvertType: v.ConvertType,
  2640. ConvertValue: v.ConvertValue,
  2641. ConvertUnit: v.ConvertUnit,
  2642. ConvertEnUnit: v.ConvertEnUnit,
  2643. }
  2644. }
  2645. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoId(strings.Join(edbInfoIdsList, ","))
  2646. if err != nil {
  2647. br.Msg = "获取失败"
  2648. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2649. return
  2650. }
  2651. for i, item := range mappingList {
  2652. if _, ok := convertMap[item.EdbInfoId]; ok {
  2653. mappingList[i].ConvertValue = convertMap[item.EdbInfoId].ConvertValue
  2654. mappingList[i].ConvertUnit = convertMap[item.EdbInfoId].ConvertUnit
  2655. mappingList[i].ConvertEnUnit = convertMap[item.EdbInfoId].ConvertEnUnit
  2656. mappingList[i].ConvertType = convertMap[item.EdbInfoId].ConvertType
  2657. mappingList[i].IsConvert = convertMap[item.EdbInfoId].IsConvert
  2658. }
  2659. }
  2660. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, string(this.Ctx.Input.RequestBody), "")
  2661. if err != nil {
  2662. br.Msg = "获取失败"
  2663. if errMsg != `` {
  2664. br.Msg = errMsg
  2665. }
  2666. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2667. return
  2668. }
  2669. if len(yDataList) > 0 {
  2670. chartInfo.Unit = yDataList[0].Unit
  2671. chartInfo.UnitEn = yDataList[0].UnitEn
  2672. }
  2673. warnEdbList := make([]string, 0)
  2674. for _, v := range edbList {
  2675. if v.IsNullData {
  2676. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2677. }
  2678. for _, reqEdb := range req.EdbInfoIdList {
  2679. if v.EdbInfoId == reqEdb.EdbInfoId {
  2680. v.EdbAliasName = reqEdb.Name
  2681. }
  2682. }
  2683. }
  2684. if len(warnEdbList) > 0 {
  2685. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2686. }
  2687. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2688. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2689. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2690. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  2691. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  2692. chartInfo.Button = data_manage.ChartViewButton{
  2693. IsEdit: chartInfo.IsEdit,
  2694. IsEnChart: chartInfo.IsEnChart,
  2695. IsAdd: chartInfo.IsAdd,
  2696. IsCopy: true,
  2697. IsSetName: chartInfo.IsSetName,
  2698. }
  2699. if req.MarkersLines != "" {
  2700. markerLines := make([]data_manage.MarkersLine, 0)
  2701. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  2702. if err != nil {
  2703. br.Msg = "标识线配置异常"
  2704. br.ErrMsg = "标识线配置异常" + err.Error()
  2705. return
  2706. }
  2707. for i := range markerLines {
  2708. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  2709. if markerLines[i].MarkLineType == 2 {
  2710. if edbList[0].IsAxis == 1 {
  2711. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  2712. if err != nil {
  2713. br.Msg = "标识线配置异常"
  2714. br.ErrMsg = "标识线配置异常" + err.Error()
  2715. return
  2716. }
  2717. markerLines[i].Value = value
  2718. } else {
  2719. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  2720. if err != nil {
  2721. br.Msg = "指标计算标识线获取指标信息异常"
  2722. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  2723. return
  2724. }
  2725. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, "", "")
  2726. if err != nil {
  2727. br.Msg = "指标计算标识线获取指标数据异常"
  2728. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  2729. return
  2730. }
  2731. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  2732. if err != nil {
  2733. br.Msg = "标识线配置异常"
  2734. br.ErrMsg = "标识线配置异常" + err.Error()
  2735. return
  2736. }
  2737. markerLines[i].Value = value
  2738. }
  2739. }
  2740. }
  2741. }
  2742. markerLineStr, err := json.Marshal(markerLines)
  2743. if err != nil {
  2744. br.Msg = "标识线配置异常"
  2745. br.ErrMsg = "标识线配置异常" + err.Error()
  2746. return
  2747. }
  2748. chartInfo.MarkersLines = string(markerLineStr)
  2749. }
  2750. resp := new(data_manage.ChartInfoDetailResp)
  2751. resp.ChartInfo = chartInfo
  2752. resp.EdbInfoList = edbList
  2753. resp.XEdbIdValue = xEdbIdValue
  2754. resp.YDataList = yDataList
  2755. resp.DataResp = dataResp
  2756. br.Ret = 200
  2757. br.Success = true
  2758. br.Msg = "获取成功"
  2759. br.Data = resp
  2760. }
  2761. // @router /chart_info/preview/time_section [post]
  2762. func (this *ChartInfoController) PreviewSectionScatterChartInfo() {
  2763. br := new(models.BaseResponse).Init()
  2764. defer func() {
  2765. this.Data["json"] = br
  2766. this.ServeJSON()
  2767. }()
  2768. var req data_manage.PreviewSectionScatterChartReq
  2769. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2770. if err != nil {
  2771. br.Msg = "参数解析异常!"
  2772. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2773. return
  2774. }
  2775. chartInfo := new(data_manage.ChartInfoView)
  2776. sysUser := this.SysUser
  2777. if sysUser == nil {
  2778. br.Msg = "请登录"
  2779. br.ErrMsg = "请登录,SysUser Is Empty"
  2780. br.Ret = 408
  2781. return
  2782. }
  2783. chartType := utils.CHART_TYPE_SECTION_SCATTER
  2784. edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
  2785. if err != nil {
  2786. br.Msg = errMsg
  2787. br.ErrMsg = "添加失败:" + err.Error()
  2788. return
  2789. }
  2790. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  2791. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  2792. if err != nil {
  2793. br.Msg = "获取失败"
  2794. if errMsg != `` {
  2795. br.Msg = errMsg
  2796. }
  2797. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2798. return
  2799. }
  2800. warnEdbList := make([]string, 0)
  2801. for _, v := range edbList {
  2802. if v.IsNullData {
  2803. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2804. }
  2805. }
  2806. if len(warnEdbList) > 0 {
  2807. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2808. }
  2809. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2810. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2811. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2812. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  2813. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  2814. chartInfo.Button = data_manage.ChartViewButton{
  2815. IsEdit: chartInfo.IsEdit,
  2816. IsEnChart: chartInfo.IsEnChart,
  2817. IsAdd: chartInfo.IsAdd,
  2818. IsCopy: true,
  2819. IsSetName: chartInfo.IsSetName,
  2820. }
  2821. resp := new(data_manage.ChartInfoDetailResp)
  2822. resp.ChartInfo = chartInfo
  2823. resp.EdbInfoList = edbList
  2824. resp.XEdbIdValue = xEdbIdValue
  2825. resp.YDataList = yDataList
  2826. resp.DataResp = dataResp
  2827. br.Ret = 200
  2828. br.Success = true
  2829. br.Msg = "获取成功"
  2830. br.Data = resp
  2831. }
  2832. // @router /chart_info/batch_refresh/result [post]
  2833. func (this *EdbInfoController) GetBatchChartRefreshResult() {
  2834. br := new(models.BaseResponse).Init()
  2835. defer func() {
  2836. this.Data["json"] = br
  2837. this.ServeJSON()
  2838. }()
  2839. sysUser := this.SysUser
  2840. if sysUser == nil {
  2841. br.Msg = "请登录"
  2842. br.ErrMsg = "请登录,SysUser Is Empty"
  2843. br.Ret = 408
  2844. return
  2845. }
  2846. var req data_manage.BatchChartRefreshReq
  2847. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2848. if err != nil {
  2849. br.Msg = "参数解析异常!"
  2850. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2851. return
  2852. }
  2853. if req.Source == "" {
  2854. br.Msg = "刷新来源有误"
  2855. return
  2856. }
  2857. if req.PrimaryId <= 0 {
  2858. br.Msg = "刷新对象有误"
  2859. return
  2860. }
  2861. refreshResult := data.CheckBatchChartRefreshResult(req.Source, req.PrimaryId, req.SubId)
  2862. resp := response.ChartRefreshResp{
  2863. RefreshResult: refreshResult,
  2864. }
  2865. br.Data = resp
  2866. br.Ret = 200
  2867. br.Success = true
  2868. }
  2869. // @router /chart_info/preview/radar [post]
  2870. func (this *ChartInfoController) PreviewRadarChartInfo() {
  2871. br := new(models.BaseResponse).Init()
  2872. defer func() {
  2873. this.Data["json"] = br
  2874. this.ServeJSON()
  2875. }()
  2876. var req data_manage.PreviewRadarChartReq
  2877. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2878. if err != nil {
  2879. br.Msg = "参数解析异常!"
  2880. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2881. return
  2882. }
  2883. chartInfo := new(data_manage.ChartInfoView)
  2884. sysUser := this.SysUser
  2885. if sysUser == nil {
  2886. br.Msg = "请登录"
  2887. br.ErrMsg = "请登录,SysUser Is Empty"
  2888. br.Ret = 408
  2889. return
  2890. }
  2891. chartType := utils.CHART_TYPE_RADAR
  2892. if len(req.ChartEdbInfoList) <= 0 {
  2893. br.Msg = "请选择指标"
  2894. return
  2895. }
  2896. edbInfoIdArr := make([]int, 0)
  2897. edbInfoNameMap := make(map[int]string)
  2898. for _, v := range req.ChartEdbInfoList {
  2899. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  2900. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  2901. }
  2902. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  2903. for _, v := range mappingList {
  2904. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  2905. v.EdbAliasName = name
  2906. }
  2907. }
  2908. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  2909. if err != nil {
  2910. br.Msg = "获取失败"
  2911. if errMsg != `` {
  2912. br.Msg = errMsg
  2913. }
  2914. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2915. return
  2916. }
  2917. warnEdbList := make([]string, 0)
  2918. for _, v := range edbList {
  2919. if v.IsNullData {
  2920. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2921. }
  2922. }
  2923. if len(warnEdbList) > 0 {
  2924. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2925. }
  2926. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  2927. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  2928. chartInfo.Button = data_manage.ChartViewButton{
  2929. IsEdit: chartInfo.IsEdit,
  2930. IsEnChart: chartInfo.IsEnChart,
  2931. IsAdd: chartInfo.IsAdd,
  2932. IsCopy: true,
  2933. IsSetName: chartInfo.IsSetName,
  2934. }
  2935. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2936. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2937. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2938. resp := new(data_manage.ChartInfoDetailResp)
  2939. resp.ChartInfo = chartInfo
  2940. resp.EdbInfoList = edbList
  2941. resp.XEdbIdValue = xEdbIdValue
  2942. resp.YDataList = yDataList
  2943. resp.DataResp = dataResp
  2944. br.Ret = 200
  2945. br.Success = true
  2946. br.Msg = "获取成功"
  2947. br.Data = resp
  2948. }
  2949. // @router /chart_info/convert/detail [get]
  2950. func (this *ChartInfoController) ChartInfoConvertDetail() {
  2951. br := new(models.BaseResponse).Init()
  2952. defer func() {
  2953. this.Data["json"] = br
  2954. this.ServeJSON()
  2955. }()
  2956. sysUser := this.SysUser
  2957. if sysUser == nil {
  2958. br.Msg = "请登录"
  2959. br.ErrMsg = "请登录,SysUser Is Empty"
  2960. br.Ret = 408
  2961. return
  2962. }
  2963. chartInfoId, _ := this.GetInt("ChartInfoId")
  2964. dateType, _ := this.GetInt("DateType")
  2965. fmt.Println("dateType:", dateType)
  2966. if dateType <= 0 {
  2967. dateType = 3
  2968. }
  2969. startDate := this.GetString("StartDate")
  2970. endDate := this.GetString("EndDate")
  2971. startYear, _ := this.GetInt("StartYear")
  2972. edbInfoId := this.GetString("EdbInfoId")
  2973. chartType, _ := this.GetInt("ChartType")
  2974. isAxis, _ := this.GetInt("IsAxis")
  2975. calendar := this.GetString("Calendar")
  2976. if calendar == "" {
  2977. calendar = "公历"
  2978. }
  2979. isConvert, _ := this.GetInt("IsConvert")
  2980. convertType, _ := this.GetInt("ConvertType")
  2981. convertValue, _ := this.GetFloat("ConvertValue")
  2982. convertUnit := this.GetString("ConvertUnit")
  2983. convertEnUnit := this.GetString("ConvertEnUnit")
  2984. resp := new(data_manage.ChartInfoDetailResp)
  2985. var err error
  2986. chartInfo := new(data_manage.ChartInfoView)
  2987. chartInfo.HaveOperaAuth = true
  2988. if chartInfoId > 0 {
  2989. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  2990. if err != nil {
  2991. if utils.IsErrNoRow(err) {
  2992. br.Msg = "该图表已删除,自动查看下一图表"
  2993. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  2994. br.Ret = 406
  2995. return
  2996. }
  2997. br.Msg = "获取失败"
  2998. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2999. return
  3000. }
  3001. chartType = chartInfo.ChartType
  3002. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  3003. if err != nil {
  3004. br.Msg = "获取失败"
  3005. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  3006. return
  3007. }
  3008. chartInfo.ChartThemeStyle = chartTheme.Config
  3009. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  3010. {
  3011. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  3012. if err != nil {
  3013. br.Msg = "获取失败"
  3014. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  3015. return
  3016. }
  3017. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  3018. if err != nil {
  3019. br.Msg = "获取失败"
  3020. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3021. return
  3022. }
  3023. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  3024. }
  3025. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  3026. chartInfo.Button = data_manage.ChartViewButton{
  3027. IsEdit: chartInfo.IsEdit,
  3028. IsEnChart: chartInfo.IsEnChart,
  3029. IsAdd: chartInfo.IsAdd,
  3030. IsCopy: true,
  3031. IsSetName: chartInfo.IsSetName,
  3032. }
  3033. }
  3034. if chartInfo.HaveOperaAuth {
  3035. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3036. if chartInfoId > 0 {
  3037. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  3038. if err != nil {
  3039. br.Msg = "获取失败"
  3040. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3041. return
  3042. }
  3043. } else {
  3044. if edbInfoId != "" {
  3045. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  3046. if err != nil {
  3047. br.Msg = "获取失败"
  3048. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3049. return
  3050. }
  3051. if isConvert == 1 && len(mappingList) > 0 {
  3052. for i, _ := range mappingList {
  3053. mappingList[i].IsConvert = 1
  3054. mappingList[i].ConvertType = convertType
  3055. mappingList[i].ConvertValue = convertValue
  3056. mappingList[i].ConvertUnit = convertUnit
  3057. mappingList[i].ConvertEnUnit = convertEnUnit
  3058. }
  3059. }
  3060. }
  3061. }
  3062. extraConfigStr := chartInfo.ExtraConfig
  3063. var barConfig data_manage.BarChartInfoReq
  3064. if chartInfo != nil && chartInfo.ChartType == 7 {
  3065. if chartInfo.BarConfig == `` {
  3066. br.Msg = "柱方图未配置"
  3067. br.ErrMsg = "柱方图未配置"
  3068. return
  3069. }
  3070. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  3071. if err != nil {
  3072. br.Msg = "柱方图配置异常"
  3073. br.ErrMsg = "柱方图配置异常"
  3074. return
  3075. }
  3076. extraConfigStr = chartInfo.BarConfig
  3077. }
  3078. yearMax := 0
  3079. if dateType == utils.DateTypeNYears {
  3080. for _, v := range mappingList {
  3081. if v.LatestDate != "" {
  3082. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  3083. if tErr != nil {
  3084. br.Msg = "获取失败"
  3085. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  3086. return
  3087. }
  3088. if lastDateT.Year() > yearMax {
  3089. yearMax = lastDateT.Year()
  3090. }
  3091. }
  3092. }
  3093. }
  3094. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  3095. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartConvertEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, isAxis)
  3096. if err != nil {
  3097. br.Msg = "获取失败"
  3098. if errMsg != `` {
  3099. br.Msg = errMsg
  3100. }
  3101. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3102. return
  3103. }
  3104. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  3105. chartInfo.Unit = yDataList[0].Unit
  3106. chartInfo.UnitEn = yDataList[0].UnitEn
  3107. }
  3108. warnEdbList := make([]string, 0)
  3109. for _, v := range edbList {
  3110. if v.IsNullData {
  3111. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3112. }
  3113. }
  3114. if len(warnEdbList) > 0 {
  3115. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3116. }
  3117. if chartInfoId > 0 && chartInfo != nil {
  3118. {
  3119. var myChartCondition string
  3120. var myChartPars []interface{}
  3121. myChartCondition += ` AND a.admin_id=? `
  3122. myChartPars = append(myChartPars, sysUser.AdminId)
  3123. myChartCondition += ` AND a.chart_info_id=? `
  3124. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  3125. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  3126. if err != nil && !utils.IsErrNoRow(err) {
  3127. br.Msg = "获取失败"
  3128. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  3129. return
  3130. }
  3131. if myChartList != nil && len(myChartList) > 0 {
  3132. chartInfo.IsAdd = true
  3133. chartInfo.MyChartId = myChartList[0].MyChartId
  3134. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  3135. }
  3136. }
  3137. if chartInfo.ChartType == 2 {
  3138. if chartInfo.SeasonStartDate != "" {
  3139. chartInfo.StartDate = chartInfo.SeasonStartDate
  3140. chartInfo.EndDate = chartInfo.SeasonEndDate
  3141. if chartInfo.DateType == 3 {
  3142. chartInfo.DateType = 5
  3143. }
  3144. }
  3145. }
  3146. }
  3147. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3148. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3149. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3150. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  3151. resp.EdbInfoList = edbList
  3152. resp.XEdbIdValue = xEdbIdValue
  3153. resp.YDataList = yDataList
  3154. resp.DataResp = dataResp
  3155. resp.BarChartInfo = barConfig
  3156. }
  3157. resp.ChartInfo = chartInfo
  3158. br.Ret = 200
  3159. br.Success = true
  3160. br.Msg = "获取成功"
  3161. br.Data = resp
  3162. }
  3163. // @router /chart_info/forum/upload [post]
  3164. func (this *ChartInfoController) UploadToForum() {
  3165. br := new(models.BaseResponse).Init()
  3166. defer func() {
  3167. this.Data["json"] = br
  3168. this.ServeJSON()
  3169. }()
  3170. sysUser := this.SysUser
  3171. if sysUser == nil {
  3172. br.Msg = "请登录"
  3173. br.ErrMsg = "请登录,SysUser Is Empty"
  3174. br.Ret = 408
  3175. return
  3176. }
  3177. var req eta_forum.UploadChartToForumReq
  3178. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3179. if err != nil {
  3180. br.Msg = "参数解析异常!"
  3181. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3182. return
  3183. }
  3184. if req.ChartInfoId <= 0 {
  3185. br.Msg = "请选择图表"
  3186. return
  3187. }
  3188. err, errMsg := eta_forum.UploadChart(req.ChartInfoId, req.Description, sysUser)
  3189. if err != nil {
  3190. br.Msg = errMsg
  3191. br.ErrMsg = err.Error()
  3192. return
  3193. }
  3194. br.Ret = 200
  3195. br.Success = true
  3196. br.Msg = "保存成功"
  3197. }
  3198. // @router /chart_info/forum/update [post]
  3199. func (this *ChartInfoController) UpdateToForum() {
  3200. br := new(models.BaseResponse).Init()
  3201. defer func() {
  3202. this.Data["json"] = br
  3203. this.ServeJSON()
  3204. }()
  3205. sysUser := this.SysUser
  3206. if sysUser == nil {
  3207. br.Msg = "请登录"
  3208. br.ErrMsg = "请登录,SysUser Is Empty"
  3209. br.Ret = 408
  3210. return
  3211. }
  3212. var req eta_forum.UpdateChartToForumReq
  3213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3214. if err != nil {
  3215. br.Msg = "参数解析异常!"
  3216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3217. return
  3218. }
  3219. if req.ChartInfoId <= 0 {
  3220. br.Msg = "请选择图表"
  3221. return
  3222. }
  3223. err, errMsg := eta_forum.UpdateChart(req.ChartInfoId)
  3224. if err != nil {
  3225. br.Msg = errMsg
  3226. br.ErrMsg = err.Error()
  3227. return
  3228. }
  3229. br.Ret = 200
  3230. br.Success = true
  3231. br.Msg = "保存成功"
  3232. }
  3233. // @router /chart_info/forum/delete [post]
  3234. func (this *ChartInfoController) ForumDelete() {
  3235. br := new(models.BaseResponse).Init()
  3236. defer func() {
  3237. this.Data["json"] = br
  3238. this.ServeJSON()
  3239. }()
  3240. sysUser := this.SysUser
  3241. if sysUser == nil {
  3242. br.Msg = "请登录"
  3243. br.ErrMsg = "请登录,SysUser Is Empty"
  3244. br.Ret = 408
  3245. return
  3246. }
  3247. var req eta_forum.DeleteChartReq
  3248. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3249. if err != nil {
  3250. br.Msg = "参数解析异常!"
  3251. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3252. return
  3253. }
  3254. if req.ChartInfoId <= 0 {
  3255. br.Msg = "请选择图表"
  3256. return
  3257. }
  3258. err, errMsg := eta_forum.DeleteChart(req.ChartInfoId)
  3259. if err != nil {
  3260. br.Msg = errMsg
  3261. br.ErrMsg = err.Error()
  3262. return
  3263. }
  3264. br.Ret = 200
  3265. br.Success = true
  3266. br.Msg = "操作成功"
  3267. }
  3268. // @router /chart_info/preview/season [post]
  3269. func (this *ChartInfoController) PreviewSeasonChartInfo() {
  3270. br := new(models.BaseResponse).Init()
  3271. defer func() {
  3272. this.Data["json"] = br
  3273. this.ServeJSON()
  3274. }()
  3275. var req data_manage.PreviewSeasonChartReq
  3276. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3277. if err != nil {
  3278. br.Msg = "参数解析异常!"
  3279. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3280. return
  3281. }
  3282. chartInfo := new(data_manage.ChartInfoView)
  3283. sysUser := this.SysUser
  3284. if sysUser == nil {
  3285. br.Msg = "请登录"
  3286. br.ErrMsg = "请登录,SysUser Is Empty"
  3287. br.Ret = 408
  3288. return
  3289. }
  3290. chartType := utils.CHART_TYPE_SEASON
  3291. if len(req.ChartEdbInfoList) <= 0 {
  3292. br.Msg = "请选择指标"
  3293. return
  3294. }
  3295. edbInfoIdArr := make([]int, 0)
  3296. edbInfoNameMap := make(map[int]string)
  3297. for _, v := range req.ChartEdbInfoList {
  3298. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  3299. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  3300. }
  3301. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3302. for _, v := range mappingList {
  3303. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  3304. v.EdbAliasName = name
  3305. }
  3306. }
  3307. var seasonExtraConfig string
  3308. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  3309. if tErr != nil {
  3310. br.Msg = "季节性图表配置信息异常"
  3311. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  3312. return
  3313. }
  3314. seasonExtraConfig = string(seasonExtra)
  3315. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, "", seasonExtraConfig)
  3316. if err != nil {
  3317. br.Msg = "获取失败"
  3318. if errMsg != `` {
  3319. br.Msg = errMsg
  3320. }
  3321. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3322. return
  3323. }
  3324. warnEdbList := make([]string, 0)
  3325. for _, v := range edbList {
  3326. if v.IsNullData {
  3327. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3328. }
  3329. }
  3330. if len(warnEdbList) > 0 {
  3331. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3332. }
  3333. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3334. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3335. chartInfo.Button = data_manage.ChartViewButton{
  3336. IsEdit: chartInfo.IsEdit,
  3337. IsEnChart: chartInfo.IsEnChart,
  3338. IsAdd: chartInfo.IsAdd,
  3339. IsCopy: true,
  3340. IsSetName: chartInfo.IsSetName,
  3341. }
  3342. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3343. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3344. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3345. resp := new(data_manage.ChartInfoDetailResp)
  3346. resp.ChartInfo = chartInfo
  3347. resp.EdbInfoList = edbList
  3348. resp.XEdbIdValue = xEdbIdValue
  3349. resp.YDataList = yDataList
  3350. resp.DataResp = dataResp
  3351. br.Ret = 200
  3352. br.Success = true
  3353. br.Msg = "获取成功"
  3354. br.Data = resp
  3355. }
  3356. // @router /chart_info/image/set_by_svg [post]
  3357. func (this *ChartInfoController) ChartInfoImgSetBySvg() {
  3358. br := new(models.BaseResponse).Init()
  3359. defer func() {
  3360. this.Data["json"] = br
  3361. this.ServeJSON()
  3362. }()
  3363. imgData := this.GetString("Img")
  3364. if imgData == "" {
  3365. br.Msg = "图片参数错误"
  3366. br.ErrMsg = "图片参数错误,Img Is Empty"
  3367. return
  3368. }
  3369. chartInfoId, _ := this.GetInt("ChartInfoId", 0)
  3370. if chartInfoId <= 0 {
  3371. br.Msg = "图片参数错误"
  3372. br.ErrMsg = "图片参数错误,ChartInfoId Is Empty"
  3373. return
  3374. }
  3375. resp := new(models.ResourceResp)
  3376. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  3377. if err != nil {
  3378. br.Msg = errMsg
  3379. br.ErrMsg = err.Error()
  3380. return
  3381. }
  3382. if chartInfoId > 0 && resourceUrl != "" {
  3383. err = data_manage.EditChartInfoImageV2(chartInfoId, resourceUrl)
  3384. if err != nil {
  3385. br.Msg = "保存失败"
  3386. br.ErrMsg = "保存失败,Err:" + err.Error()
  3387. return
  3388. }
  3389. go data.EsAddOrEditChartInfo(chartInfoId)
  3390. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfoId)
  3391. }
  3392. resp.ResourceUrl = resourceUrl
  3393. resp.Source = "convert"
  3394. br.Msg = "上传成功"
  3395. br.Ret = 200
  3396. br.Success = true
  3397. br.Data = resp
  3398. return
  3399. }