chart_info.go 81 KB

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