chart_info.go 86 KB

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