my_chart.go 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/services/data/data_manage_permission"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 我的图库
  19. type MyChartController struct {
  20. controllers.BaseAuthController
  21. }
  22. // @Title ETA图表列表接口
  23. // @Description ETA图表列表接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param ChartClassifyId query int true "分类id"
  27. // @Param KeyWord query string true "搜索关键词"
  28. // @Param IsShowMe query bool true "是否只看我的,true、false"
  29. // @Success 200 {object} data_manage.ChartListResp
  30. // @router /chart/list [get]
  31. func (this *MyChartController) ChartList() {
  32. br := new(models.BaseResponse).Init()
  33. defer func() {
  34. this.Data["json"] = br
  35. this.ServeJSON()
  36. }()
  37. sysUser := this.SysUser
  38. if sysUser == nil {
  39. br.Msg = "请登录"
  40. br.ErrMsg = "请登录,SysUser Is Empty"
  41. br.Ret = 408
  42. return
  43. }
  44. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  45. pageSize, _ := this.GetInt("PageSize")
  46. currentIndex, _ := this.GetInt("CurrentIndex")
  47. keyWord := this.GetString("KeyWord")
  48. var total int
  49. page := paging.GetPaging(currentIndex, pageSize, total)
  50. var startSize int
  51. if pageSize <= 0 {
  52. pageSize = utils.PageSize20
  53. }
  54. if currentIndex <= 0 {
  55. currentIndex = 1
  56. }
  57. startSize = paging.StartIndex(currentIndex, pageSize)
  58. var condition string
  59. var pars []interface{}
  60. // 普通图表
  61. condition += ` AND source = ? `
  62. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  63. chartClassifyIds := make([]int, 0)
  64. if chartClassifyId > 0 {
  65. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  66. if e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  69. return
  70. }
  71. parents := data.GetChartClassifyChildrenRecursive(list, chartClassifyId)
  72. sort.Slice(parents, func(i, j int) bool {
  73. return parents[i].Level < parents[i].Level
  74. })
  75. for _, v := range parents {
  76. chartClassifyIds = append(chartClassifyIds, v.ChartClassifyId)
  77. }
  78. //chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  79. //if err != nil && err.Error() != utils.ErrNoRow() {
  80. // br.Msg = "获取图表信息失败"
  81. // br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  82. // return
  83. //}
  84. condition += " AND chart_classify_id IN(" + utils.GetOrmInReplace(len(chartClassifyIds)) + ") "
  85. pars = append(pars, chartClassifyIds)
  86. }
  87. if keyWord != "" {
  88. condition += ` AND ( chart_name LIKE '%` + keyWord + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
  89. }
  90. //只看我的
  91. isShowMe, _ := this.GetBool("IsShowMe")
  92. if isShowMe {
  93. condition += ` AND sys_user_id = ? `
  94. pars = append(pars, sysUser.AdminId)
  95. }
  96. // 获取当前账号的不可见指标
  97. noPermissionChartIdList := make([]int, 0)
  98. {
  99. obj := data_manage.EdbInfoNoPermissionAdmin{}
  100. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  101. if err != nil && err.Error() != utils.ErrNoRow() {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  104. return
  105. }
  106. for _, v := range confList {
  107. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  108. }
  109. }
  110. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  111. if lenNoPermissionChartIdList > 0 {
  112. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  113. pars = append(pars, noPermissionChartIdList)
  114. }
  115. //获取图表信息
  116. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  117. if err != nil && err.Error() != utils.ErrNoRow() {
  118. br.Success = true
  119. br.Msg = "获取图表信息失败"
  120. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  121. return
  122. }
  123. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  124. if err != nil && err.Error() != utils.ErrNoRow() {
  125. br.Msg = "获取图表信息失败"
  126. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  127. return
  128. }
  129. myChartMap := make(map[int]*data_manage.MyChartView)
  130. for _, v := range myChartList {
  131. myChartMap[v.ChartInfoId] = v
  132. }
  133. listLen := len(list)
  134. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  135. if listLen > 0 {
  136. // 分类id
  137. classifyIdList := make([]int, 0)
  138. // 当前列表中的分类map
  139. classifyMap := make(map[int]*data_manage.ChartClassify)
  140. for _, v := range list {
  141. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  142. }
  143. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  144. if err != nil {
  145. br.Msg = "获取失败"
  146. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  147. return
  148. }
  149. for _, v := range classifyList {
  150. classifyMap[v.ChartClassifyId] = v
  151. }
  152. // 已授权分类id
  153. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  154. if err != nil {
  155. br.Msg = "获取失败"
  156. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  157. return
  158. }
  159. // 权限
  160. for k, chartViewInfo := range list {
  161. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  162. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  163. }
  164. }
  165. chartInfoIds := ""
  166. for _, v := range list {
  167. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  168. }
  169. if chartInfoIds != "" {
  170. chartInfoIds = strings.Trim(chartInfoIds, ",")
  171. //判断是否需要展示英文标识
  172. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  173. if e != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  176. return
  177. }
  178. for _, v := range edbList {
  179. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  180. }
  181. }
  182. }
  183. for i := 0; i < listLen; i++ {
  184. //判断是否需要展示英文标识
  185. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  186. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  187. }
  188. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  189. list[i].IsAdd = true
  190. list[i].MyChartId = existItem.MyChartId
  191. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  192. }
  193. }
  194. resp := new(data_manage.ChartListResp)
  195. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  196. items := make([]*data_manage.ChartInfoView, 0)
  197. resp.Paging = page
  198. resp.List = items
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "获取成功"
  202. return
  203. }
  204. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  205. if err != nil && err.Error() != utils.ErrNoRow() {
  206. br.Msg = "获取指标信息失败"
  207. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  208. return
  209. }
  210. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  211. resp.Paging = page
  212. resp.List = list
  213. br.Ret = 200
  214. br.Success = true
  215. br.Msg = "获取成功"
  216. br.Data = resp
  217. }
  218. // ClassifyList
  219. // @Title 我的图表-分类列表接口
  220. // @Description 我的图表-分类列表接口
  221. // @Success 200 {object} data_manage.MyChartClassifyResp
  222. // @router /classify/list [get]
  223. func (this *MyChartController) ClassifyList() {
  224. br := new(models.BaseResponse).Init()
  225. defer func() {
  226. this.Data["json"] = br
  227. this.ServeJSON()
  228. }()
  229. sysUser := this.SysUser
  230. if sysUser == nil {
  231. br.Msg = "请登录"
  232. br.ErrMsg = "请登录,SysUser Is Empty"
  233. br.Ret = 408
  234. return
  235. }
  236. //获取图表信息
  237. list, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  238. if err != nil && err.Error() != utils.ErrNoRow() {
  239. br.Success = true
  240. br.Msg = "获取分类信息失败"
  241. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  242. return
  243. }
  244. resp := new(data_manage.MyChartClassifyResp)
  245. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  246. items := make([]*data_manage.MyChartClassifyItem, 0)
  247. resp.List = items
  248. br.Ret = 200
  249. br.Success = true
  250. br.Msg = "获取成功"
  251. return
  252. }
  253. //resp.List = list
  254. // 获取图表分类下各自的图表数
  255. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  256. if e != nil {
  257. br.Msg = "获取失败"
  258. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  259. return
  260. }
  261. results := make([]*data_manage.MyChartClassifyItem, 0)
  262. for _, v := range list {
  263. results = append(results, data_manage.FormatMyChartClassify2Item(v, chartsNumMap[v.MyChartClassifyId]))
  264. }
  265. resp.List = results
  266. language := `CN`
  267. // 指标显示的语言
  268. {
  269. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  270. if configDetail != nil {
  271. language = configDetail.ConfigValue
  272. } else {
  273. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  274. if configDetail != nil {
  275. language = configDetail.ConfigValue
  276. }
  277. }
  278. }
  279. resp.Language = language
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "获取成功"
  283. br.Data = resp
  284. }
  285. // @Title 新增我的图表分类
  286. // @Description 新增我的图表接口
  287. // @Param request body data_manage.MyChartClassifyAddReq true "type json string"
  288. // @Success 200 Ret=200 保存成功
  289. // @router /classify/add [post]
  290. func (this *MyChartController) ClassifyAdd() {
  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.MyChartClassifyAddReq
  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. if req.MyChartClassifyName == "" {
  311. br.Msg = "请输入分类名称"
  312. br.IsSendEmail = false
  313. return
  314. }
  315. var condition string
  316. var pars []interface{}
  317. condition += " AND admin_id=? "
  318. pars = append(pars, sysUser.AdminId)
  319. condition += " AND my_chart_classify_name=? "
  320. pars = append(pars, req.MyChartClassifyName)
  321. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  322. if err != nil {
  323. br.Msg = "保存失败"
  324. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  325. return
  326. }
  327. if count > 0 {
  328. br.Msg = "分类已存在,请重新输入"
  329. br.IsSendEmail = false
  330. return
  331. }
  332. // 获取我的图库分类的最大排序值
  333. sort, err := data_manage.GetMyChartClassifyMinSort(sysUser.AdminId)
  334. if err != nil {
  335. br.Msg = "保存失败"
  336. br.ErrMsg = "保存失败,获取最大排序失败,Err:" + err.Error()
  337. return
  338. }
  339. item := new(data_manage.MyChartClassify)
  340. item.AdminId = sysUser.AdminId
  341. item.MyChartClassifyName = req.MyChartClassifyName
  342. item.Sort = sort - 1
  343. item.ModifyTime = time.Now()
  344. item.CreateTime = time.Now()
  345. err = data_manage.AddMyChartClassify(item)
  346. if err != nil {
  347. br.Msg = "保存失败"
  348. br.ErrMsg = "保存失败,Err:" + err.Error()
  349. return
  350. }
  351. //新增操作日志
  352. {
  353. edbLog := new(data_manage.MyChartLog)
  354. edbLog.MyChartId = 0
  355. edbLog.ChartInfoId = 0
  356. edbLog.SysUserId = sysUser.AdminId
  357. edbLog.SysUserRealName = sysUser.RealName
  358. edbLog.CreateTime = time.Now()
  359. edbLog.Content = string(this.Ctx.Input.RequestBody)
  360. edbLog.Status = "新增分类"
  361. edbLog.Method = this.Ctx.Input.URI()
  362. go data_manage.AddMyChartLog(edbLog)
  363. }
  364. br.Ret = 200
  365. br.Msg = "保存成功"
  366. br.Success = true
  367. br.IsAddLog = true
  368. }
  369. // @Title 编辑我的图表分类
  370. // @Description 编辑我的图表接口
  371. // @Param request body data_manage.MyChartClassifyEditReq true "type json string"
  372. // @Success 200 Ret=200 保存成功
  373. // @router /classify/edit [post]
  374. func (this *MyChartController) ClassifyEdit() {
  375. br := new(models.BaseResponse).Init()
  376. defer func() {
  377. this.Data["json"] = br
  378. this.ServeJSON()
  379. }()
  380. sysUser := this.SysUser
  381. if sysUser == nil {
  382. br.Msg = "请登录"
  383. br.ErrMsg = "请登录,SysUser Is Empty"
  384. br.Ret = 408
  385. return
  386. }
  387. var req data_manage.MyChartClassifyEditReq
  388. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  389. if err != nil {
  390. br.Msg = "参数解析异常!"
  391. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  392. return
  393. }
  394. if req.MyChartClassifyName == "" {
  395. br.Msg = "请输入分类名称"
  396. br.IsSendEmail = false
  397. return
  398. }
  399. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  400. if err != nil && err.Error() != utils.ErrNoRow() {
  401. br.Msg = "保存失败"
  402. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  403. return
  404. }
  405. if item == nil {
  406. br.Msg = "分类不存在"
  407. br.ErrMsg = "分类不存在,Err:" + err.Error()
  408. return
  409. }
  410. var condition string
  411. var pars []interface{}
  412. condition += " AND admin_id=? "
  413. pars = append(pars, sysUser.AdminId)
  414. condition += " AND my_chart_classify_name=? "
  415. pars = append(pars, req.MyChartClassifyName)
  416. condition += " AND my_chart_classify_id<>? "
  417. pars = append(pars, req.MyChartClassifyId)
  418. //判断名称是否已经存在
  419. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  420. if err != nil {
  421. br.Msg = "保存失败"
  422. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  423. return
  424. }
  425. if count > 0 {
  426. br.Msg = "分类已存在,请重新输入"
  427. br.IsSendEmail = false
  428. return
  429. }
  430. err = data_manage.ModifyMyChartClassify(req.MyChartClassifyId, req.MyChartClassifyName)
  431. if err != nil {
  432. br.Msg = "保存失败"
  433. br.ErrMsg = "保存失败,Err:" + err.Error()
  434. return
  435. }
  436. //新增操作日志
  437. {
  438. edbLog := new(data_manage.MyChartLog)
  439. edbLog.MyChartId = 0
  440. edbLog.ChartInfoId = 0
  441. edbLog.SysUserId = sysUser.AdminId
  442. edbLog.SysUserRealName = sysUser.RealName
  443. edbLog.CreateTime = time.Now()
  444. edbLog.Content = string(this.Ctx.Input.RequestBody)
  445. edbLog.Status = "编辑分类"
  446. edbLog.Method = this.Ctx.Input.URI()
  447. go data_manage.AddMyChartLog(edbLog)
  448. }
  449. br.Ret = 200
  450. br.Msg = "保存成功"
  451. br.Success = true
  452. br.IsAddLog = true
  453. }
  454. // ClassifyMove
  455. // @Title 移动我的图表分类
  456. // @Description 移动我的图表分类接口
  457. // @Param request body data_manage.MyChartClassifyMoveReq true "type json string"
  458. // @Success 200 Ret=200 移动成功
  459. // @router /classify/move [post]
  460. func (this *MyChartController) ClassifyMove() {
  461. br := new(models.BaseResponse).Init()
  462. defer func() {
  463. this.Data["json"] = br
  464. this.ServeJSON()
  465. }()
  466. sysUser := this.SysUser
  467. if sysUser == nil {
  468. br.Msg = "请登录"
  469. br.ErrMsg = "请登录,SysUser Is Empty"
  470. br.Ret = 408
  471. return
  472. }
  473. var req data_manage.MyChartClassifyMoveReq
  474. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  475. if err != nil {
  476. br.Msg = "参数解析异常!"
  477. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  478. return
  479. }
  480. //查询该分类存不存在
  481. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  482. if err != nil && err.Error() != utils.ErrNoRow() {
  483. br.Msg = "移动失败,找不到该分类"
  484. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  485. return
  486. }
  487. if item == nil {
  488. br.Msg = "分类不存在"
  489. br.ErrMsg = "分类不存在,Err:" + err.Error()
  490. return
  491. }
  492. updateCol := make([]string, 0)
  493. //如果有传入 上一个兄弟节点分类id
  494. if req.PrevClassifyId > 0 {
  495. prevClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.PrevClassifyId)
  496. if err != nil {
  497. br.Msg = "移动失败"
  498. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  499. return
  500. }
  501. //如果是移动在两个兄弟节点之间
  502. if req.NextClassifyId > 0 {
  503. //下一个兄弟节点
  504. nextClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.NextClassifyId)
  505. if err != nil {
  506. br.Msg = "移动失败"
  507. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  508. return
  509. }
  510. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  511. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == item.Sort {
  512. //变更兄弟节点的排序
  513. updateSortStr := `sort + 2`
  514. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, prevClassify.MyChartClassifyId, prevClassify.Sort, updateSortStr)
  515. } else {
  516. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  517. if nextClassify.Sort-prevClassify.Sort == 1 {
  518. //变更兄弟节点的排序
  519. updateSortStr := `sort + 1`
  520. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, 0, prevClassify.Sort, updateSortStr)
  521. }
  522. }
  523. }
  524. item.Sort = prevClassify.Sort + 1
  525. item.ModifyTime = time.Now()
  526. updateCol = append(updateCol, "Sort", "ModifyTime")
  527. } else {
  528. firstClassify, err := data_manage.GetFirstMyChartClassifyByAdminId(sysUser.AdminId)
  529. if err != nil && err.Error() != utils.ErrNoRow() {
  530. br.Msg = "移动失败"
  531. br.ErrMsg = "获取获取当前账号下的排序第一条的分类信息失败,Err:" + err.Error()
  532. return
  533. }
  534. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  535. if firstClassify != nil && firstClassify.Sort == 0 {
  536. updateSortStr := ` sort + 1 `
  537. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, firstClassify.MyChartClassifyId-1, 0, updateSortStr)
  538. }
  539. item.Sort = 0 //那就是排在第一位
  540. item.ModifyTime = time.Now()
  541. updateCol = append(updateCol, "Sort", "ModifyTime")
  542. }
  543. //更新
  544. if len(updateCol) > 0 {
  545. err = item.Update(updateCol)
  546. if err != nil {
  547. br.Msg = "移动失败"
  548. br.ErrMsg = "修改失败,Err:" + err.Error()
  549. return
  550. }
  551. }
  552. //新增操作日志
  553. {
  554. edbLog := new(data_manage.MyChartLog)
  555. edbLog.MyChartId = 0
  556. edbLog.ChartInfoId = 0
  557. edbLog.SysUserId = sysUser.AdminId
  558. edbLog.SysUserRealName = sysUser.RealName
  559. edbLog.CreateTime = time.Now()
  560. edbLog.Content = string(this.Ctx.Input.RequestBody)
  561. edbLog.Status = "移动分类"
  562. edbLog.Method = this.Ctx.Input.URI()
  563. go data_manage.AddMyChartLog(edbLog)
  564. }
  565. br.Ret = 200
  566. br.Msg = "保存成功"
  567. br.Success = true
  568. br.IsAddLog = true
  569. }
  570. // @Title 删除我的图表分类
  571. // @Description 删除我的图表接口
  572. // @Param request body data_manage.MyChartClassifyDeleteReq true "type json string"
  573. // @Success 200 Ret=200 保存成功
  574. // @router /classify/delete [post]
  575. func (this *MyChartController) ClassifyDelete() {
  576. br := new(models.BaseResponse).Init()
  577. defer func() {
  578. this.Data["json"] = br
  579. this.ServeJSON()
  580. }()
  581. sysUser := this.SysUser
  582. if sysUser == nil {
  583. br.Msg = "请登录"
  584. br.ErrMsg = "请登录,SysUser Is Empty"
  585. br.Ret = 408
  586. return
  587. }
  588. var req data_manage.MyChartClassifyDeleteReq
  589. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  590. if err != nil {
  591. br.Msg = "参数解析异常!"
  592. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  593. return
  594. }
  595. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  596. if err != nil && err.Error() != utils.ErrNoRow() {
  597. br.Msg = "保存失败"
  598. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  599. return
  600. }
  601. if item == nil {
  602. br.Msg = "分类已被删除"
  603. br.ErrMsg = "分类已被删除,Err:" + err.Error()
  604. return
  605. }
  606. nodeOb := new(data_manage.ChartFrameworkNode)
  607. cond := ` AND my_chart_classify_id = ?`
  608. pars := make([]interface{}, 0)
  609. pars = append(pars, req.MyChartClassifyId)
  610. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  611. if e != nil {
  612. br.Msg = "获取失败"
  613. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  614. return
  615. }
  616. if len(nodes) > 0 {
  617. br.Msg = "该图分类已添加节点链接, 不允许删除"
  618. return
  619. }
  620. //var condition string
  621. //var pars []interface{}
  622. //
  623. //condition += " AND admin_id=? "
  624. //pars = append(pars, sysUser.AdminId)
  625. //
  626. //condition += " AND my_chart_classify_id=? "
  627. //pars = append(pars, req.MyChartClassifyId)
  628. ////判断是否包含图表
  629. //count, err := data_manage.GetMyChartClassifyMappingCountByCondition(condition, pars)
  630. //if err != nil {
  631. // br.Msg = "保存失败"
  632. // br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  633. // return
  634. //}
  635. //if count > 0 {
  636. // br.Msg = "此分类下含有图表,不可删除"
  637. // br.IsSendEmail = false
  638. // return
  639. //}
  640. err = data_manage.DeleteMyChartClassify(req.MyChartClassifyId)
  641. if err != nil {
  642. br.Msg = "删除失败"
  643. br.ErrMsg = "删除失败,Err:" + err.Error()
  644. return
  645. }
  646. //新增操作日志
  647. {
  648. edbLog := new(data_manage.MyChartLog)
  649. edbLog.MyChartId = 0
  650. edbLog.ChartInfoId = 0
  651. edbLog.SysUserId = sysUser.AdminId
  652. edbLog.SysUserRealName = sysUser.RealName
  653. edbLog.CreateTime = time.Now()
  654. edbLog.Content = string(this.Ctx.Input.RequestBody)
  655. edbLog.Status = "删除分类"
  656. edbLog.Method = this.Ctx.Input.URI()
  657. go data_manage.AddMyChartLog(edbLog)
  658. }
  659. br.Ret = 200
  660. br.Msg = "删除成功"
  661. br.Success = true
  662. br.IsAddLog = true
  663. }
  664. // @Title 新增我的图表
  665. // @Description 新增我的图表接口
  666. // @Param request body data_manage.MyChartAddReq true "type json string"
  667. // @Success 200 Ret=200 保存成功
  668. // @router /add [post]
  669. func (this *MyChartController) MyChartAdd() {
  670. br := new(models.BaseResponse).Init()
  671. defer func() {
  672. this.Data["json"] = br
  673. this.ServeJSON()
  674. }()
  675. sysUser := this.SysUser
  676. if sysUser == nil {
  677. br.Msg = "请登录"
  678. br.ErrMsg = "请登录,SysUser Is Empty"
  679. br.Ret = 408
  680. return
  681. }
  682. var req data_manage.MyChartAddReq
  683. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  684. if err != nil {
  685. br.Msg = "参数解析异常!"
  686. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  687. return
  688. }
  689. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  690. if err != nil && err.Error() != utils.ErrNoRow() {
  691. br.Msg = "获取图表信息失败!"
  692. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  693. return
  694. }
  695. if chartItem == nil {
  696. br.Msg = "此图表已被删除!"
  697. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  698. return
  699. }
  700. var condition string
  701. var pars []interface{}
  702. condition += " AND admin_id=? "
  703. pars = append(pars, sysUser.AdminId)
  704. condition += " AND chart_info_id=? "
  705. pars = append(pars, req.ChartInfoId)
  706. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  707. if err != nil && err.Error() != utils.ErrNoRow() {
  708. br.Msg = "保存失败"
  709. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  710. return
  711. }
  712. resp := new(data_manage.MyChartAddResp)
  713. var myChartClassifyId string
  714. if existItem != nil { //修改
  715. fmt.Println("modify")
  716. for _, v := range req.MyChartClassifyId {
  717. myChartClassifyId += strconv.Itoa(v) + ","
  718. }
  719. resp.MyChartInfoId = existItem.MyChartId
  720. err = data_manage.MoveMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  721. if err != nil {
  722. br.Msg = "保存失败"
  723. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  724. return
  725. }
  726. } else {
  727. myChart := &data_manage.MyChart{
  728. //MyChartId: 0,
  729. ChartInfoId: chartItem.ChartInfoId,
  730. Source: chartItem.Source,
  731. AdminId: sysUser.AdminId,
  732. CreateTime: time.Now(),
  733. ModifyTime: time.Now(),
  734. }
  735. newMyChartId, err := data_manage.AddMyChart(myChart)
  736. if err != nil {
  737. br.Msg = "保存失败"
  738. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  739. return
  740. }
  741. //step := float64(65536)
  742. for _, v := range req.MyChartClassifyId {
  743. var sort float64
  744. // 查找最小排序值
  745. firstMapItem, _ := data_manage.GetMyChartSort(sysUser.AdminId, v, 0)
  746. if firstMapItem != nil {
  747. sort = firstMapItem.Sort
  748. }
  749. //获取最大的排序字段
  750. //count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  751. mappingItem := new(data_manage.MyChartClassifyMapping)
  752. mappingItem.AdminId = sysUser.AdminId
  753. mappingItem.MyChartId = int(newMyChartId)
  754. mappingItem.MyChartClassifyId = v
  755. mappingItem.CreateTime = time.Now()
  756. mappingItem.ModifyTime = time.Now()
  757. //mappingItem.Sort = (float64(count) + 1) * step
  758. mappingItem.Sort = sort
  759. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  760. if err != nil {
  761. br.Msg = "保存失败"
  762. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  763. return
  764. }
  765. myChartClassifyId += strconv.Itoa(v) + ","
  766. }
  767. //新增操作日志
  768. {
  769. edbLog := new(data_manage.MyChartLog)
  770. edbLog.MyChartId = myChart.MyChartId
  771. edbLog.ChartInfoId = myChart.ChartInfoId
  772. edbLog.SysUserId = sysUser.AdminId
  773. edbLog.SysUserRealName = sysUser.RealName
  774. edbLog.CreateTime = time.Now()
  775. edbLog.Content = string(this.Ctx.Input.RequestBody)
  776. edbLog.Status = "新增我的图表"
  777. edbLog.Method = this.Ctx.Input.URI()
  778. go data_manage.AddMyChartLog(edbLog)
  779. }
  780. resp.MyChartInfoId = int(newMyChartId)
  781. }
  782. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  783. //更新es
  784. if resp.MyChartInfoId > 0 {
  785. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  786. }
  787. br.Ret = 200
  788. br.Msg = "保存成功"
  789. br.Success = true
  790. br.Data = resp
  791. br.IsAddLog = true
  792. }
  793. // MyChartAddToClassify
  794. // @Title 将图表加入到我的图表分类
  795. // @Description 新增我的图表接口
  796. // @Param request body data_manage.MyChartAddReq true "type json string"
  797. // @Success 200 Ret=200 保存成功
  798. // @router /add_to_classify [post]
  799. func (this *MyChartController) MyChartAddToClassify() {
  800. br := new(models.BaseResponse).Init()
  801. defer func() {
  802. this.Data["json"] = br
  803. this.ServeJSON()
  804. }()
  805. sysUser := this.SysUser
  806. if sysUser == nil {
  807. br.Msg = "请登录"
  808. br.ErrMsg = "请登录,SysUser Is Empty"
  809. br.Ret = 408
  810. return
  811. }
  812. var req data_manage.MyChartAddReq
  813. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  814. if err != nil {
  815. br.Msg = "参数解析异常!"
  816. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  817. return
  818. }
  819. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  820. if err != nil && err.Error() != utils.ErrNoRow() {
  821. br.Msg = "获取图表信息失败!"
  822. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  823. return
  824. }
  825. if chartItem == nil {
  826. br.Msg = "此图表已被删除!"
  827. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  828. return
  829. }
  830. var condition string
  831. var pars []interface{}
  832. condition += " AND admin_id=? "
  833. pars = append(pars, sysUser.AdminId)
  834. condition += " AND chart_info_id=? "
  835. pars = append(pars, req.ChartInfoId)
  836. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  837. if err != nil && err.Error() != utils.ErrNoRow() {
  838. br.Msg = "保存失败"
  839. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  840. return
  841. }
  842. resp := new(data_manage.MyChartAddResp)
  843. var myChartClassifyId string
  844. if existItem != nil { //修改
  845. fmt.Println("modify")
  846. for _, v := range req.MyChartClassifyId {
  847. myChartClassifyId += strconv.Itoa(v) + ","
  848. }
  849. resp.MyChartInfoId = existItem.MyChartId
  850. err = data_manage.AddMyChartToMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  851. if err != nil {
  852. br.Msg = "保存失败"
  853. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  854. return
  855. }
  856. } else {
  857. myChart := &data_manage.MyChart{
  858. //MyChartId: 0,
  859. ChartInfoId: chartItem.ChartInfoId,
  860. Source: chartItem.Source,
  861. AdminId: sysUser.AdminId,
  862. CreateTime: time.Now(),
  863. ModifyTime: time.Now(),
  864. }
  865. newMyChartId, err := data_manage.AddMyChart(myChart)
  866. if err != nil {
  867. br.Msg = "保存失败"
  868. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  869. return
  870. }
  871. step := float64(65536)
  872. for _, v := range req.MyChartClassifyId {
  873. //获取最大的排序字段
  874. count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  875. mappingItem := new(data_manage.MyChartClassifyMapping)
  876. mappingItem.AdminId = sysUser.AdminId
  877. mappingItem.MyChartId = int(newMyChartId)
  878. mappingItem.MyChartClassifyId = v
  879. mappingItem.CreateTime = time.Now()
  880. mappingItem.ModifyTime = time.Now()
  881. mappingItem.Sort = (float64(count) + 1) * step
  882. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  883. if err != nil {
  884. br.Msg = "保存失败"
  885. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  886. return
  887. }
  888. myChartClassifyId += strconv.Itoa(v) + ","
  889. }
  890. //新增操作日志
  891. {
  892. edbLog := new(data_manage.MyChartLog)
  893. edbLog.MyChartId = myChart.MyChartId
  894. edbLog.ChartInfoId = myChart.ChartInfoId
  895. edbLog.SysUserId = sysUser.AdminId
  896. edbLog.SysUserRealName = sysUser.RealName
  897. edbLog.CreateTime = time.Now()
  898. edbLog.Content = string(this.Ctx.Input.RequestBody)
  899. edbLog.Status = "新增我的图表"
  900. edbLog.Method = this.Ctx.Input.URI()
  901. go data_manage.AddMyChartLog(edbLog)
  902. }
  903. resp.MyChartInfoId = int(newMyChartId)
  904. }
  905. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  906. //更新es
  907. if resp.MyChartInfoId > 0 {
  908. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  909. }
  910. br.Ret = 200
  911. br.Msg = "保存成功"
  912. br.Success = true
  913. br.Data = resp
  914. br.IsAddLog = true
  915. }
  916. // GetMyChartClassifyIdList
  917. // @Title 根据我的图表id获取所属分类列表
  918. // @Description 根据我的图表id获取所属分类列表接口
  919. // @Param query ChartInfoId int `description:"图表id"`
  920. // @Success 200 {object} []int
  921. // @router /get_mychart_classify_id_list [get]
  922. func (this *MyChartController) GetMyChartClassifyIdList() {
  923. br := new(models.BaseResponse).Init()
  924. defer func() {
  925. this.Data["json"] = br
  926. this.ServeJSON()
  927. }()
  928. sysUser := this.SysUser
  929. if sysUser == nil {
  930. br.Msg = "请登录"
  931. br.ErrMsg = "请登录,SysUser Is Empty"
  932. br.Ret = 408
  933. return
  934. }
  935. chartInfoId, _ := this.GetInt("ChartInfoId")
  936. if chartInfoId <= 0 {
  937. br.Msg = "请传入图表id"
  938. br.IsSendEmail = false
  939. return
  940. }
  941. //图表分类id列表
  942. chartClassifyIdList := make([]int, 0)
  943. var condition string
  944. var pars []interface{}
  945. condition += " AND admin_id=? AND chart_info_id=? "
  946. pars = append(pars, sysUser.AdminId, chartInfoId)
  947. existItem, _ := data_manage.GetMyChartDetailByCondition(condition, pars)
  948. if existItem != nil {
  949. myChartClassifyList, err := data_manage.GetMyChartClassifyList(existItem.MyChartId)
  950. if err != nil && err.Error() != utils.ErrNoRow() {
  951. br.Msg = "获取图表信息失败!"
  952. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  953. return
  954. }
  955. for _, v := range myChartClassifyList {
  956. chartClassifyIdList = append(chartClassifyIdList, v.MyChartClassifyId)
  957. }
  958. }
  959. br.Ret = 200
  960. br.Msg = "获取成功"
  961. br.Success = true
  962. br.Data = chartClassifyIdList
  963. }
  964. // @Title 删除-我的图表-中的图表
  965. // @Description 删除-我的图表-中的图表接口
  966. // @Param request body data_manage.MyChartDeleteReq true "type json string"
  967. // @Success 200 Ret=200 保存成功
  968. // @router /delete [post]
  969. func (this *MyChartController) MyChartDelete() {
  970. setNxKey := "MyChartDelete_"
  971. deleteCache := true
  972. br := new(models.BaseResponse).Init()
  973. defer func() {
  974. if deleteCache {
  975. utils.Rc.Delete(setNxKey)
  976. }
  977. this.Data["json"] = br
  978. this.ServeJSON()
  979. }()
  980. sysUser := this.SysUser
  981. if sysUser == nil {
  982. br.Msg = "请登录"
  983. br.ErrMsg = "请登录,SysUser Is Empty"
  984. br.Ret = 408
  985. return
  986. }
  987. var req data_manage.MyChartDeleteReq
  988. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  989. if err != nil {
  990. br.Msg = "参数解析异常!"
  991. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  992. return
  993. }
  994. setNxKey += strconv.Itoa(req.MyChartId) + strconv.Itoa(req.MyChartClassifyId)
  995. if !utils.Rc.SetNX(setNxKey, 1, 3*time.Second) {
  996. deleteCache = false
  997. br.Msg = "系统处理中,请稍后重试!"
  998. br.IsSendEmail = false
  999. return
  1000. }
  1001. if req.MyChartId <= 0 {
  1002. br.Msg = "参数错误!"
  1003. br.ErrMsg = "参数错误,Err:" + string(this.Ctx.Input.RequestBody)
  1004. return
  1005. }
  1006. isDelMyChart, err := data_manage.DeleteMyChart(req.MyChartId, req.MyChartClassifyId)
  1007. if err != nil {
  1008. br.Msg = "移除失败!"
  1009. br.ErrMsg = "移除失败,Err:" + err.Error()
  1010. return
  1011. }
  1012. //新增操作日志
  1013. {
  1014. edbLog := new(data_manage.MyChartLog)
  1015. edbLog.MyChartId = 0
  1016. edbLog.ChartInfoId = 0
  1017. edbLog.SysUserId = sysUser.AdminId
  1018. edbLog.SysUserRealName = sysUser.RealName
  1019. edbLog.CreateTime = time.Now()
  1020. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1021. edbLog.Status = "删除-我的图表-中的图表"
  1022. edbLog.Method = this.Ctx.Input.URI()
  1023. go data_manage.AddMyChartLog(edbLog)
  1024. }
  1025. if isDelMyChart {
  1026. //如果确实删除了,那么就去ES同步删除
  1027. go data.EsDeleteMyChartInfoByMyChartId(req.MyChartId)
  1028. } else {
  1029. //如果只是删除了关系,那么就去ES同步更新数据
  1030. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1031. }
  1032. br.Ret = 200
  1033. br.Msg = "移除成功"
  1034. br.Success = true
  1035. br.IsAddLog = true
  1036. }
  1037. // @Title 编辑我的图表
  1038. // @Description 编辑我的图表接口
  1039. // @Param request body data_manage.MyChartEditReq true "type json string"
  1040. // @Success 200 Ret=200 保存成功
  1041. // @router /edit [post]
  1042. func (this *MyChartController) MyChartEdit() {
  1043. br := new(models.BaseResponse).Init()
  1044. defer func() {
  1045. this.Data["json"] = br
  1046. this.ServeJSON()
  1047. }()
  1048. sysUser := this.SysUser
  1049. if sysUser == nil {
  1050. br.Msg = "请登录"
  1051. br.ErrMsg = "请登录,SysUser Is Empty"
  1052. br.Ret = 408
  1053. return
  1054. }
  1055. var req data_manage.MyChartEditReq
  1056. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1057. if err != nil {
  1058. br.Msg = "参数解析异常!"
  1059. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1060. return
  1061. }
  1062. for _, v := range req.MyChartClassifyId {
  1063. myChartClassifyId := v
  1064. count, _ := data_manage.GetMyChartClassifyMappingCount(sysUser.AdminId, req.MyChartId, myChartClassifyId)
  1065. if count <= 0 {
  1066. mappingItem := new(data_manage.MyChartClassifyMapping)
  1067. mappingItem.AdminId = sysUser.AdminId
  1068. mappingItem.MyChartId = req.MyChartId
  1069. mappingItem.MyChartClassifyId = myChartClassifyId
  1070. mappingItem.CreateTime = time.Now()
  1071. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  1072. }
  1073. }
  1074. err = data_manage.DeleteMyChartClassifyMapping(sysUser.AdminId, req.MyChartId, req.CurrentMyChartClassifyId)
  1075. if err != nil {
  1076. br.Msg = "保存失败!"
  1077. br.ErrMsg = "保存失败,移除分类失败,Err:" + err.Error()
  1078. return
  1079. }
  1080. //新增操作日志
  1081. {
  1082. edbLog := new(data_manage.MyChartLog)
  1083. edbLog.MyChartId = 0
  1084. edbLog.ChartInfoId = 0
  1085. edbLog.SysUserId = sysUser.AdminId
  1086. edbLog.SysUserRealName = sysUser.RealName
  1087. edbLog.CreateTime = time.Now()
  1088. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1089. edbLog.Status = "编辑我的图表"
  1090. edbLog.Method = this.Ctx.Input.URI()
  1091. go data_manage.AddMyChartLog(edbLog)
  1092. }
  1093. //更新es
  1094. if req.MyChartId > 0 {
  1095. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1096. }
  1097. br.Ret = 200
  1098. br.Msg = "保存成功"
  1099. br.Success = true
  1100. br.IsAddLog = true
  1101. }
  1102. // MyChartList
  1103. // @Title 我的图表-列表接口
  1104. // @Description 我的图表-列表接口
  1105. // @Param PageSize query int true "每页数据条数"
  1106. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1107. // @Param MyChartClassifyId query int true "我的图表分类id"
  1108. // @Param MyChartId query int true "我的图表id"
  1109. // @Param IsShared query bool false "是否可分享(如从图库框架请求的属于可分享的)"
  1110. // @Success 200 {object} data_manage.MyChartListResp
  1111. // @router /list [get]
  1112. func (this *MyChartController) MyChartList() {
  1113. br := new(models.BaseResponse).Init()
  1114. defer func() {
  1115. this.Data["json"] = br
  1116. this.ServeJSON()
  1117. }()
  1118. sysUser := this.SysUser
  1119. if sysUser == nil {
  1120. br.Msg = "请登录"
  1121. br.ErrMsg = "请登录,SysUser Is Empty"
  1122. br.Ret = 408
  1123. return
  1124. }
  1125. myChartClassifyId, _ := this.GetInt("MyChartClassifyId")
  1126. pageSize, _ := this.GetInt("PageSize")
  1127. currentIndex, _ := this.GetInt("CurrentIndex")
  1128. myChartId, _ := this.GetInt("MyChartId")
  1129. isShared, _ := this.GetBool("IsShared")
  1130. var total int
  1131. page := paging.GetPaging(currentIndex, pageSize, total)
  1132. var startSize int
  1133. if pageSize <= 0 {
  1134. pageSize = utils.PageSize20
  1135. }
  1136. if currentIndex <= 0 {
  1137. currentIndex = 1
  1138. }
  1139. startSize = paging.StartIndex(currentIndex, pageSize)
  1140. var condition string
  1141. var pars []interface{}
  1142. chartAdminId := sysUser.AdminId
  1143. if myChartClassifyId > 0 {
  1144. condition += " AND c.my_chart_classify_id=? "
  1145. pars = append(pars, myChartClassifyId)
  1146. // 可共享
  1147. if isShared {
  1148. myClassify, e := data_manage.GetMyChartClassifyByClassifyId(myChartClassifyId)
  1149. if e != nil {
  1150. if e.Error() == utils.ErrNoRow() {
  1151. br.Msg = "分类已被删除, 请刷新页面"
  1152. return
  1153. }
  1154. br.Msg = "获取失败"
  1155. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  1156. return
  1157. }
  1158. chartAdminId = myClassify.AdminId
  1159. }
  1160. }
  1161. condition += " AND (a.admin_id = ? OR d.is_public = 1)"
  1162. pars = append(pars, chartAdminId)
  1163. if myChartId > 0 {
  1164. condition += " AND a.my_chart_id=? "
  1165. pars = append(pars, myChartId)
  1166. }
  1167. // 获取当前账号的不可见指标
  1168. noPermissionChartIdList := make([]int, 0)
  1169. {
  1170. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1171. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1172. if err != nil && err.Error() != utils.ErrNoRow() {
  1173. br.Msg = "获取失败"
  1174. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. for _, v := range confList {
  1178. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1179. }
  1180. }
  1181. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1182. if lenNoPermissionChartIdList > 0 {
  1183. condition += ` AND b.chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1184. pars = append(pars, noPermissionChartIdList)
  1185. }
  1186. //获取图表信息
  1187. list, err := data_manage.GetMyChartListByCondition(condition, pars, startSize, pageSize)
  1188. if err != nil && err.Error() != utils.ErrNoRow() {
  1189. br.Success = true
  1190. br.Msg = "获取图表信息失败"
  1191. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1192. return
  1193. }
  1194. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1195. if err != nil && err.Error() != utils.ErrNoRow() {
  1196. br.Msg = "获取图表信息失败"
  1197. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1198. return
  1199. }
  1200. myChartMap := make(map[int]int)
  1201. chartInfoIds := ""
  1202. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1203. for _, v := range myChartList {
  1204. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1205. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1206. }
  1207. if chartInfoIds != "" {
  1208. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1209. //判断是否需要展示英文标识
  1210. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1211. if e != nil {
  1212. br.Msg = "获取失败"
  1213. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1214. return
  1215. }
  1216. for _, v := range edbList {
  1217. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1218. }
  1219. }
  1220. listLen := len(list)
  1221. if listLen > 0 {
  1222. // 分类id
  1223. classifyIdList := make([]int, 0)
  1224. // 当前列表中的分类map
  1225. classifyMap := make(map[int]*data_manage.ChartClassify)
  1226. for _, v := range list {
  1227. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1228. }
  1229. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1230. if err != nil {
  1231. br.Msg = "获取失败"
  1232. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1233. return
  1234. }
  1235. for _, v := range classifyList {
  1236. classifyMap[v.ChartClassifyId] = v
  1237. }
  1238. // 已授权分类id
  1239. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1240. if err != nil {
  1241. br.Msg = "获取失败"
  1242. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1243. return
  1244. }
  1245. // 权限
  1246. for i, chartViewInfo := range list {
  1247. //判断是否需要展示英文标识
  1248. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1249. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  1250. }
  1251. if _, ok := myChartMap[list[i].ChartInfoId]; ok {
  1252. list[i].IsAdd = true
  1253. }
  1254. // 数据权限
  1255. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1256. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1257. } else if chartViewInfo.ChartClassifyId == 0 {
  1258. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, 0, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1259. }
  1260. }
  1261. }
  1262. resp := new(data_manage.MyChartListResp)
  1263. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1264. items := make([]*data_manage.MyChartList, 0)
  1265. resp.Paging = page
  1266. resp.List = items
  1267. br.Ret = 200
  1268. br.Success = true
  1269. br.Msg = "获取成功"
  1270. return
  1271. }
  1272. total, err = data_manage.GetMyChartListCountByCondition(condition, pars)
  1273. if err != nil && err.Error() != utils.ErrNoRow() {
  1274. br.Msg = "获取信息失败"
  1275. br.ErrMsg = "获取我的图表数据总数失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. page = paging.GetPaging(currentIndex, pageSize, total)
  1279. resp.Paging = page
  1280. resp.List = list
  1281. br.Ret = 200
  1282. br.Success = true
  1283. br.Msg = "获取成功"
  1284. br.Data = resp
  1285. }
  1286. // @Title 移动我的图表接口
  1287. // @Description 移动我的图表接口
  1288. // @Success 200 {object} data_manage.MoveMyChartReq
  1289. // @router /move [post]
  1290. func (this *MyChartController) MyChartMove() {
  1291. br := new(models.BaseResponse).Init()
  1292. defer func() {
  1293. this.Data["json"] = br
  1294. this.ServeJSON()
  1295. }()
  1296. sysUser := this.SysUser
  1297. if sysUser == nil {
  1298. br.Msg = "请登录"
  1299. br.ErrMsg = "请登录,SysUser Is Empty"
  1300. br.Ret = 408
  1301. return
  1302. }
  1303. adminId := sysUser.AdminId
  1304. var req data_manage.MoveMyChartReq
  1305. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1306. if err != nil {
  1307. br.Msg = "参数解析异常!"
  1308. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1309. return
  1310. }
  1311. //step := float64(65536)
  1312. var newSort float64
  1313. if req.PrevMyChartId <= 0 {
  1314. firstMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
  1315. if err != nil {
  1316. br.Msg = "获取数据失败!"
  1317. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1318. return
  1319. }
  1320. //if firstMapItem.Sort <= 0 {
  1321. // firstSort := step / float64(2)
  1322. // err = data_manage.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
  1323. // if err != nil {
  1324. // br.Msg = "移动失败!"
  1325. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1326. // return
  1327. // }
  1328. // newSort = step / float64(4)
  1329. //} else {
  1330. // newSort = firstMapItem.Sort / float64(2)
  1331. //}
  1332. newSort = firstMapItem.Sort - 1
  1333. } else if req.NextMyChartId <= 0 {
  1334. latestMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
  1335. if err != nil {
  1336. br.Msg = "获取数据失败!"
  1337. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1338. return
  1339. }
  1340. //if latestMapItem.Sort <= 0 {
  1341. // latestSort := step / float64(2)
  1342. // err = data_manage.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
  1343. // if err != nil {
  1344. // br.Msg = "移动失败!"
  1345. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1346. // return
  1347. // }
  1348. // newSort = step / float64(4)
  1349. //} else {
  1350. // newSort = latestMapItem.Sort + (step / float64(2)) - 1
  1351. //}
  1352. newSort = latestMapItem.Sort + 1
  1353. } else {
  1354. preMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
  1355. if err != nil {
  1356. br.Msg = "获取数据失败!"
  1357. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1358. return
  1359. }
  1360. nextMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
  1361. if err != nil {
  1362. br.Msg = "获取数据失败!"
  1363. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1364. return
  1365. }
  1366. newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
  1367. newSort = preMapItem.Sort + 1
  1368. var updateSortStr string
  1369. if preMapItem.Sort == nextMapItem.Sort {
  1370. //变更兄弟节点的排序(sort同级)
  1371. updateSortStr = `sort + 2`
  1372. } else if nextMapItem.Sort-preMapItem.Sort == 1 {
  1373. //变更兄弟节点的排序(sort只相差一级)
  1374. updateSortStr = `sort + 1`
  1375. }
  1376. if updateSortStr != `` {
  1377. _ = data_manage.UpdateMyChartSortByClassifyId(req.MyChartClassifyId, int(preMapItem.Sort), preMapItem.MyChartClassifyMappingId, updateSortStr)
  1378. }
  1379. }
  1380. //if newSort >= 0 {
  1381. //
  1382. //} else {
  1383. // utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
  1384. //}
  1385. err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
  1386. if err != nil {
  1387. br.Msg = "移动失败!"
  1388. br.ErrMsg = "移动失败,Err:" + err.Error()
  1389. return
  1390. }
  1391. //新增操作日志
  1392. {
  1393. edbLog := new(data_manage.MyChartLog)
  1394. edbLog.MyChartId = 0
  1395. edbLog.ChartInfoId = 0
  1396. edbLog.SysUserId = sysUser.AdminId
  1397. edbLog.SysUserRealName = sysUser.RealName
  1398. edbLog.CreateTime = time.Now()
  1399. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1400. edbLog.Status = "移动我的图表"
  1401. edbLog.Method = this.Ctx.Input.URI()
  1402. go data_manage.AddMyChartLog(edbLog)
  1403. }
  1404. //更新es
  1405. if req.MyChartId > 0 {
  1406. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1407. }
  1408. br.Ret = 200
  1409. br.Success = true
  1410. br.Msg = "移动成功"
  1411. br.IsAddLog = true
  1412. }
  1413. // @Title ETA图表-推荐列表接口
  1414. // @Description ETA图表-推荐列表接口
  1415. // @Param ChartClassifyId query int true "分类id"
  1416. // @Success 200 {object} data_manage.ChartRecommendListResp
  1417. // @router /chart/recommend/list [get]
  1418. func (this *MyChartController) ChartRecommendList() {
  1419. br := new(models.BaseResponse).Init()
  1420. defer func() {
  1421. this.Data["json"] = br
  1422. this.ServeJSON()
  1423. }()
  1424. sysUser := this.SysUser
  1425. if sysUser == nil {
  1426. br.Msg = "请登录"
  1427. br.ErrMsg = "请登录,SysUser Is Empty"
  1428. br.Ret = 408
  1429. return
  1430. }
  1431. pageSize := 6
  1432. currentIndex := 1
  1433. var startSize int
  1434. startSize = paging.StartIndex(currentIndex, pageSize)
  1435. var condition string
  1436. var pars []interface{}
  1437. if sysUser.AdminId > 0 {
  1438. condition += " AND a.admin_id=? "
  1439. pars = append(pars, sysUser.AdminId)
  1440. }
  1441. //获取图表信息
  1442. list, err := data_manage.GetRecommendChartListByCondition(condition, pars, startSize, pageSize)
  1443. if err != nil && err.Error() != utils.ErrNoRow() {
  1444. br.Success = true
  1445. br.Msg = "获取图表信息失败"
  1446. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1447. return
  1448. }
  1449. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1450. if err != nil && err.Error() != utils.ErrNoRow() {
  1451. br.Msg = "获取图表信息失败"
  1452. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1453. return
  1454. }
  1455. myChartMap := make(map[int]int)
  1456. for _, v := range myChartList {
  1457. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1458. }
  1459. listLen := len(list)
  1460. if listLen > 0 {
  1461. // 分类id
  1462. classifyIdList := make([]int, 0)
  1463. // 当前列表中的分类map
  1464. classifyMap := make(map[int]*data_manage.ChartClassify)
  1465. for _, v := range list {
  1466. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1467. }
  1468. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1469. if err != nil {
  1470. br.Msg = "获取失败"
  1471. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1472. return
  1473. }
  1474. for _, v := range classifyList {
  1475. classifyMap[v.ChartClassifyId] = v
  1476. }
  1477. // 已授权分类id
  1478. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1479. if err != nil {
  1480. br.Msg = "获取失败"
  1481. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1482. return
  1483. }
  1484. // 权限
  1485. for k, chartViewInfo := range list {
  1486. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1487. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1488. }
  1489. if _, ok := myChartMap[list[k].ChartInfoId]; ok {
  1490. list[k].IsAdd = true
  1491. }
  1492. }
  1493. }
  1494. resp := new(data_manage.ChartRecommendListResp)
  1495. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1496. items := make([]*data_manage.ChartInfoView, 0)
  1497. resp.List = items
  1498. br.Ret = 200
  1499. br.Success = true
  1500. br.Msg = "获取成功"
  1501. return
  1502. }
  1503. resp.List = list
  1504. br.Ret = 200
  1505. br.Success = true
  1506. br.Msg = "获取成功"
  1507. br.Data = resp
  1508. }
  1509. // @Title 我的图表-列表接口
  1510. // @Description 我的图表-列表接口
  1511. // @Param KeyWord query string true "搜索关键词"
  1512. // @Success 200 {object} data_manage.MyChartListResp
  1513. // @router /search [get]
  1514. func (this *MyChartController) MyChartSearch() {
  1515. br := new(models.BaseResponse).Init()
  1516. defer func() {
  1517. this.Data["json"] = br
  1518. this.ServeJSON()
  1519. }()
  1520. sysUser := this.SysUser
  1521. if sysUser == nil {
  1522. br.Msg = "请登录"
  1523. br.ErrMsg = "请登录,SysUser Is Empty"
  1524. br.Ret = 408
  1525. return
  1526. }
  1527. var condition string
  1528. var pars []interface{}
  1529. condition += " AND a.admin_id=? "
  1530. pars = append(pars, sysUser.AdminId)
  1531. keyWord := this.GetString("KeyWord")
  1532. if keyWord != "" {
  1533. condition += ` AND chart_name LIKE '%` + keyWord + `%' `
  1534. }
  1535. //获取图表信息
  1536. list, err := data_manage.GetMyChartSearchByCondition(condition, pars)
  1537. if err != nil && err.Error() != utils.ErrNoRow() {
  1538. br.Success = true
  1539. br.Msg = "获取图表信息失败"
  1540. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1541. return
  1542. }
  1543. listLen := len(list)
  1544. if listLen > 0 {
  1545. // 分类id
  1546. classifyIdList := make([]int, 0)
  1547. // 当前列表中的分类map
  1548. classifyMap := make(map[int]*data_manage.ChartClassify)
  1549. for _, v := range list {
  1550. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1551. }
  1552. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1553. if err != nil {
  1554. br.Msg = "获取失败"
  1555. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1556. return
  1557. }
  1558. for _, v := range classifyList {
  1559. classifyMap[v.ChartClassifyId] = v
  1560. }
  1561. // 已授权分类id
  1562. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1563. if err != nil {
  1564. br.Msg = "获取失败"
  1565. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1566. return
  1567. }
  1568. // 权限
  1569. for k, chartViewInfo := range list {
  1570. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1571. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1572. }
  1573. list[k].IsAdd = true
  1574. }
  1575. }
  1576. resp := new(data_manage.MyChartSearchListResp)
  1577. if list == nil {
  1578. list = make([]*data_manage.MyChartList, 0)
  1579. }
  1580. resp.List = list
  1581. br.Ret = 200
  1582. br.Success = true
  1583. br.Msg = "获取成功"
  1584. br.Data = resp
  1585. }
  1586. // MyChartSearchByEs
  1587. // @Title 我的图表-列表接口
  1588. // @Description 我的图表-列表接口
  1589. // @Param Keyword query string true "搜索关键词"
  1590. // @Success 200 {object} data_manage.MyChartListResp
  1591. // @router /search_by_es [get]
  1592. func (this *MyChartController) MyChartSearchByEs() {
  1593. br := new(models.BaseResponse).Init()
  1594. defer func() {
  1595. this.Data["json"] = br
  1596. this.ServeJSON()
  1597. }()
  1598. sysUser := this.SysUser
  1599. if sysUser == nil {
  1600. br.Msg = "请登录"
  1601. br.ErrMsg = "请登录,SysUser Is Empty"
  1602. br.Ret = 408
  1603. return
  1604. }
  1605. pageSize, _ := this.GetInt("PageSize")
  1606. currentIndex, _ := this.GetInt("CurrentIndex")
  1607. var startSize int
  1608. if pageSize <= 0 {
  1609. pageSize = utils.PageSize20
  1610. }
  1611. if currentIndex <= 0 {
  1612. currentIndex = 1
  1613. }
  1614. startSize = paging.StartIndex(currentIndex, pageSize)
  1615. keyword := this.GetString("Keyword")
  1616. // 获取当前账号的不可见指标
  1617. noPermissionChartIdList := make([]int, 0)
  1618. {
  1619. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1620. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1621. if err != nil && err.Error() != utils.ErrNoRow() {
  1622. br.Msg = "获取失败"
  1623. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1624. return
  1625. }
  1626. for _, v := range confList {
  1627. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1628. }
  1629. }
  1630. //获取图表信息
  1631. list, total, err := data.EsSearchMyChartInfo(keyword, sysUser.AdminId, noPermissionChartIdList, startSize, pageSize)
  1632. if err != nil {
  1633. br.Msg = "获取失败"
  1634. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1635. return
  1636. }
  1637. lenList := len(list)
  1638. if lenList <= 0 {
  1639. list = make([]*data_manage.MyChartList, 0)
  1640. } else {
  1641. // 分类id
  1642. classifyIdList := make([]int, 0)
  1643. // 图表id
  1644. chartInfoIdList := make([]int, 0)
  1645. // 当前列表中的分类map
  1646. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1647. // 当前列表中的图表map
  1648. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  1649. for _, v := range list {
  1650. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1651. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1652. }
  1653. // 分类
  1654. {
  1655. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1656. if err != nil {
  1657. if err != nil {
  1658. br.Msg = "获取失败"
  1659. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1660. return
  1661. }
  1662. }
  1663. for _, tmpClassifyInfo := range classifyList {
  1664. chartClassifyMap[tmpClassifyInfo.ChartClassifyId] = tmpClassifyInfo
  1665. }
  1666. }
  1667. // 图表
  1668. {
  1669. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1670. if err != nil {
  1671. br.Msg = "获取失败"
  1672. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  1673. return
  1674. }
  1675. for _, tmpChartInfo := range tmpChartList {
  1676. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  1677. }
  1678. }
  1679. // 已授权分类id
  1680. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1681. if err != nil {
  1682. br.Msg = "获取失败"
  1683. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1684. return
  1685. }
  1686. // 权限
  1687. for k, tmpChartViewInfo := range list {
  1688. list[k].IsAdd = true
  1689. chartViewInfo, ok := chartInfoMap[tmpChartViewInfo.ChartInfoId]
  1690. if !ok {
  1691. continue
  1692. }
  1693. if currClassify, ok := chartClassifyMap[chartViewInfo.ChartClassifyId]; ok {
  1694. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1695. }
  1696. }
  1697. }
  1698. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1699. resp := data_manage.MyChartSearchListResp{
  1700. List: list,
  1701. Paging: page,
  1702. }
  1703. br.Ret = 200
  1704. br.Success = true
  1705. br.Msg = "获取成功"
  1706. br.Data = resp
  1707. }
  1708. // PublicClassifyList
  1709. // @Title 我的图表-公共分类列表接口
  1710. // @Description 我的图表-公共分类列表接口
  1711. // @Success 200 {object} data_manage.MyChartClassifyResp
  1712. // @router /classify/public_list [get]
  1713. func (this *MyChartController) PublicClassifyList() {
  1714. br := new(models.BaseResponse).Init()
  1715. defer func() {
  1716. this.Data["json"] = br
  1717. this.ServeJSON()
  1718. }()
  1719. sysUser := this.SysUser
  1720. if sysUser == nil {
  1721. br.Msg = "请登录"
  1722. br.ErrMsg = "请登录,SysUser Is Empty"
  1723. br.Ret = 408
  1724. return
  1725. }
  1726. //获取图表信息
  1727. list, err := data_manage.GetPublicChartClassifyAllExceptMy(sysUser.AdminId)
  1728. if err != nil && err.Error() != utils.ErrNoRow() {
  1729. br.Success = true
  1730. br.Msg = "获取公共分类信息失败"
  1731. br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
  1732. return
  1733. }
  1734. resp := new(data_manage.PublicChartClassifyResp)
  1735. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1736. resp.List = make([]data_manage.PublicChartClassifyList, 0)
  1737. br.Ret = 200
  1738. br.Success = true
  1739. br.Msg = "获取成功"
  1740. return
  1741. }
  1742. // 创建人姓名
  1743. adminIdStr := make([]string, 0)
  1744. for _, v := range list {
  1745. adminIdStr = append(adminIdStr, fmt.Sprint(v.AdminId))
  1746. }
  1747. adminMap := make(map[int]string)
  1748. adminList, _ := system.GetSysAdminByIdSlice(adminIdStr)
  1749. if len(adminList) > 0 {
  1750. for _, adminInfo := range adminList {
  1751. adminMap[adminInfo.AdminId] = adminInfo.RealName
  1752. }
  1753. }
  1754. respList := make([]data_manage.PublicChartClassifyList, 0)
  1755. existMap := make(map[int]bool, 0)
  1756. itemsMap := make(map[int][]data_manage.PublicChartClassifyItem, 0)
  1757. for _, v := range list {
  1758. realName := adminMap[v.AdminId]
  1759. if realName == "" {
  1760. // 忽略掉被删掉的用户
  1761. continue
  1762. }
  1763. if itemsMap[v.AdminId] == nil {
  1764. itemsMap[v.AdminId] = make([]data_manage.PublicChartClassifyItem, 0)
  1765. }
  1766. itemsMap[v.AdminId] = append(itemsMap[v.AdminId], data_manage.PublicChartClassifyItem{
  1767. MyChartClassifyId: v.MyChartClassifyId,
  1768. MyChartClassifyName: v.MyChartClassifyName,
  1769. AdminId: v.AdminId,
  1770. RealName: realName,
  1771. IsPublic: v.IsPublic,
  1772. IsCompanyPublic: v.IsCompanyPublic,
  1773. })
  1774. var menu data_manage.PublicChartClassifyList
  1775. if existMap[v.AdminId] {
  1776. continue
  1777. }
  1778. existMap[v.AdminId] = true
  1779. menu.MenuAdminId = v.AdminId
  1780. menu.MenuName = fmt.Sprintf("%s的图库", realName)
  1781. respList = append(respList, menu)
  1782. }
  1783. for k, v := range respList {
  1784. respList[k].Items = itemsMap[v.MenuAdminId]
  1785. }
  1786. resp.List = respList
  1787. language := `CN`
  1788. // 指标显示的语言
  1789. {
  1790. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  1791. if configDetail != nil {
  1792. language = configDetail.ConfigValue
  1793. } else {
  1794. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  1795. if configDetail != nil {
  1796. language = configDetail.ConfigValue
  1797. }
  1798. }
  1799. }
  1800. resp.Language = language
  1801. br.Ret = 200
  1802. br.Success = true
  1803. br.Msg = "获取成功"
  1804. br.Data = resp
  1805. }
  1806. // ModifyClassifyPublicStatus
  1807. // @Title 修改我的图表分类的是否可见
  1808. // @Description 修改我的图表分类的是否可见接口
  1809. // @Param request body data_manage.ModifyChartClassifyPublicReq true "type json string"
  1810. // @Success 200 Ret=200 修改成功
  1811. // @router /classify/modify_public [post]
  1812. func (this *MyChartController) ModifyClassifyPublicStatus() {
  1813. br := new(models.BaseResponse).Init()
  1814. defer func() {
  1815. this.Data["json"] = br
  1816. this.ServeJSON()
  1817. }()
  1818. sysUser := this.SysUser
  1819. if sysUser == nil {
  1820. br.Msg = "请登录"
  1821. br.ErrMsg = "请登录,SysUser Is Empty"
  1822. br.Ret = 408
  1823. return
  1824. }
  1825. var req data_manage.ModifyChartClassifyPublicReq
  1826. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1827. if err != nil {
  1828. br.Msg = "参数解析异常!"
  1829. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1830. return
  1831. }
  1832. //查询该分类存不存在
  1833. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  1834. if err != nil && err.Error() != utils.ErrNoRow() {
  1835. br.Msg = "修改失败,找不到该分类"
  1836. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1837. return
  1838. }
  1839. if item == nil {
  1840. br.Msg = "分类不存在"
  1841. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1842. return
  1843. }
  1844. item.IsPublic = req.IsPublic
  1845. item.PublicTime = time.Now()
  1846. if req.IsPublic == 0 {
  1847. // 取消公开同时取消客户公开
  1848. item.IsCompanyPublic = 0
  1849. }
  1850. err = item.Update([]string{"IsPublic", "PublicTime", "IsCompanyPublic"})
  1851. if err != nil {
  1852. br.Msg = "修改失败"
  1853. br.ErrMsg = "修改是否公开失败,Err:" + err.Error()
  1854. return
  1855. }
  1856. //新增操作日志
  1857. {
  1858. edbLog := new(data_manage.MyChartLog)
  1859. edbLog.MyChartId = 0
  1860. edbLog.ChartInfoId = 0
  1861. edbLog.SysUserId = sysUser.AdminId
  1862. edbLog.SysUserRealName = sysUser.RealName
  1863. edbLog.CreateTime = time.Now()
  1864. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1865. edbLog.Status = "修改分类是否公开"
  1866. edbLog.Method = this.Ctx.Input.URI()
  1867. go data_manage.AddMyChartLog(edbLog)
  1868. }
  1869. br.Ret = 200
  1870. br.Msg = "修改成功"
  1871. br.Success = true
  1872. br.IsAddLog = true
  1873. }
  1874. // CopyClassifyAndChart
  1875. // @Title 复制我的图表分类
  1876. // @Description 复制我的图表分类接口
  1877. // @Param request body data_manage.CopyChartClassifyReq true "type json string"
  1878. // @Success 200 Ret=200 复制成功
  1879. // @router /classify/copy [post]
  1880. func (this *MyChartController) CopyClassifyAndChart() {
  1881. br := new(models.BaseResponse).Init()
  1882. defer func() {
  1883. this.Data["json"] = br
  1884. this.ServeJSON()
  1885. }()
  1886. sysUser := this.SysUser
  1887. if sysUser == nil {
  1888. br.Msg = "请登录"
  1889. br.ErrMsg = "请登录,SysUser Is Empty"
  1890. br.Ret = 408
  1891. return
  1892. }
  1893. var req data_manage.CopyChartClassifyReq
  1894. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1895. if err != nil {
  1896. br.Msg = "参数解析异常!"
  1897. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1898. return
  1899. }
  1900. //查询该公共分类存不存在
  1901. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1902. if err != nil && err.Error() != utils.ErrNoRow() {
  1903. br.Msg = "复制失败,找不到该分类"
  1904. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1905. return
  1906. }
  1907. if item == nil {
  1908. br.Msg = "分类不存在"
  1909. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1910. return
  1911. }
  1912. //获取所有的分类名称
  1913. chartClassifyList, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  1914. //生成新的分类名称
  1915. newChartClassifyName := generateMyChartClassifyName(item.MyChartClassifyName, 1, chartClassifyList)
  1916. //复制分类
  1917. newMyChartClassify, err := data_manage.CopyPublicMyChartClassifyById(item.MyChartClassifyId, sysUser.AdminId, newChartClassifyName)
  1918. if err != nil {
  1919. br.Msg = "复制失败"
  1920. br.ErrMsg = "复制失败,Err:" + err.Error()
  1921. return
  1922. }
  1923. //新增操作日志
  1924. {
  1925. edbLog := new(data_manage.MyChartLog)
  1926. edbLog.MyChartId = 0
  1927. edbLog.ChartInfoId = 0
  1928. edbLog.SysUserId = sysUser.AdminId
  1929. edbLog.SysUserRealName = sysUser.RealName
  1930. edbLog.CreateTime = time.Now()
  1931. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1932. edbLog.Status = "复制分类"
  1933. edbLog.Method = this.Ctx.Input.URI()
  1934. go data_manage.AddMyChartLog(edbLog)
  1935. }
  1936. br.Data = newMyChartClassify
  1937. br.Ret = 200
  1938. br.Msg = "复制成功"
  1939. br.Success = true
  1940. br.IsAddLog = true
  1941. }
  1942. // generateMyChartClassifyName 生成我的图库分类名称
  1943. func generateMyChartClassifyName(myChartClassifyName string, count int, chartClassifyList []*data_manage.MyChartClassify) (newChartClassifyName string) {
  1944. newChartClassifyName = fmt.Sprint(myChartClassifyName, count)
  1945. for _, v := range chartClassifyList {
  1946. if v.MyChartClassifyName == newChartClassifyName {
  1947. count++
  1948. newChartClassifyName = generateMyChartClassifyName(fmt.Sprint(myChartClassifyName), count, chartClassifyList)
  1949. return
  1950. }
  1951. }
  1952. return
  1953. }
  1954. // ModifyClassifyPublicStatus
  1955. // @Title 修改公共分类是否用户可见
  1956. // @Description 修改公共分类是否用户可见接口
  1957. // @Param request body data_manage.ModifyChartClassifyCompanyPublicReq true "type json string"
  1958. // @Success 200 Ret=200 修改成功
  1959. // @router /classify/modify_company_public [post]
  1960. func (this *MyChartController) ModifyClassifyCompanyPublicStatus() {
  1961. br := new(models.BaseResponse).Init()
  1962. defer func() {
  1963. this.Data["json"] = br
  1964. this.ServeJSON()
  1965. }()
  1966. sysUser := this.SysUser
  1967. if sysUser == nil {
  1968. br.Msg = "请登录"
  1969. br.ErrMsg = "请登录,SysUser Is Empty"
  1970. br.Ret = 408
  1971. return
  1972. }
  1973. var req data_manage.ModifyChartClassifyCompanyPublicReq
  1974. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1975. if err != nil {
  1976. br.Msg = "参数解析异常!"
  1977. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1978. return
  1979. }
  1980. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1981. if err != nil {
  1982. br.Msg = "找不到该分类"
  1983. br.ErrMsg = "获取分类信息失败, Err:" + err.Error()
  1984. return
  1985. }
  1986. if item.IsPublic != 1 {
  1987. br.Msg = "该分类未公开,不可设置为用户可见"
  1988. br.ErrMsg = "该分类未公开,不可设置为用户可见"
  1989. return
  1990. }
  1991. item.IsCompanyPublic = req.IsCompanyPublic
  1992. item.CompanyPublicTime = time.Now()
  1993. err = item.Update([]string{"IsCompanyPublic", "CompanyPublicTime"})
  1994. if err != nil {
  1995. br.Msg = "修改失败"
  1996. br.ErrMsg = "修改是否用户可见失败, Err:" + err.Error()
  1997. return
  1998. }
  1999. {
  2000. edbLog := new(data_manage.MyChartLog)
  2001. edbLog.MyChartId = 0
  2002. edbLog.ChartInfoId = 0
  2003. edbLog.SysUserId = sysUser.AdminId
  2004. edbLog.SysUserRealName = sysUser.RealName
  2005. edbLog.CreateTime = time.Now()
  2006. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2007. edbLog.Status = "修改用户是否可见"
  2008. edbLog.Method = this.Ctx.Input.URI()
  2009. go data_manage.AddMyChartLog(edbLog)
  2010. }
  2011. br.Ret = 200
  2012. br.Msg = "修改成功"
  2013. br.Success = true
  2014. br.IsAddLog = true
  2015. }
  2016. // CompanyPublicClassifyList
  2017. // @Title 我的图表-用户可见分类列表
  2018. // @Description 我的图表-用户可见分类列表接口
  2019. // @Param Keyword query string false "分类名称关键词"
  2020. // @Success 200 {object} data_manage.MyChartClassifyResp
  2021. // @router /classify/company_public_list [get]
  2022. func (this *MyChartController) CompanyPublicClassifyList() {
  2023. br := new(models.BaseResponse).Init()
  2024. defer func() {
  2025. this.Data["json"] = br
  2026. this.ServeJSON()
  2027. }()
  2028. sysUser := this.SysUser
  2029. if sysUser == nil {
  2030. br.Msg = "请登录"
  2031. br.ErrMsg = "请登录,SysUser Is Empty"
  2032. br.Ret = 408
  2033. return
  2034. }
  2035. var condition string
  2036. var pars []interface{}
  2037. keyword := this.GetString("Keyword")
  2038. if keyword != "" {
  2039. keyword = "%" + keyword + "%"
  2040. condition += ` AND my_chart_classify_name LIKE ? `
  2041. pars = append(pars, keyword)
  2042. }
  2043. list, err := data_manage.GetCompanyPublicClassifyList(condition, pars)
  2044. if err != nil && err.Error() != utils.ErrNoRow() {
  2045. br.Success = true
  2046. br.Msg = "获取用户可见分类列表失败"
  2047. br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
  2048. return
  2049. }
  2050. resp := new(data_manage.MyChartClassifyResp)
  2051. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  2052. items := make([]*data_manage.MyChartClassifyItem, 0)
  2053. resp.List = items
  2054. br.Ret = 200
  2055. br.Success = true
  2056. br.Msg = "获取成功"
  2057. return
  2058. }
  2059. results := make([]*data_manage.MyChartClassifyItem, 0)
  2060. for _, v := range list {
  2061. results = append(results, data_manage.FormatMyChartClassify2Item(v, 0))
  2062. }
  2063. resp.List = results
  2064. //resp.List = list
  2065. br.Ret = 200
  2066. br.Success = true
  2067. br.Msg = "获取成功"
  2068. br.Data = resp
  2069. }
  2070. //func init() {
  2071. // data.AddAllMyChartInfo()
  2072. //}
  2073. // ClassifyFrameworkNodeList
  2074. // @Title 我的图表分类-关联的框架节点列表
  2075. // @Description 我的图表分类-关联的框架节点列表
  2076. // @Param MyChartClassifyId query int false "图表分类ID"
  2077. // @Success 200 Ret=200 获取成功
  2078. // @router /classify/framework_node_list [get]
  2079. func (this *MyChartController) ClassifyFrameworkNodeList() {
  2080. br := new(models.BaseResponse).Init()
  2081. defer func() {
  2082. if br.ErrMsg == "" {
  2083. br.IsSendEmail = true
  2084. }
  2085. this.Data["json"] = br
  2086. this.ServeJSON()
  2087. }()
  2088. sysUser := this.SysUser
  2089. if sysUser == nil {
  2090. br.Msg = "请登录"
  2091. br.ErrMsg = "请登录,SysUser Is Empty"
  2092. br.Ret = 408
  2093. return
  2094. }
  2095. classifyId, _ := this.GetInt("MyChartClassifyId")
  2096. if classifyId <= 0 {
  2097. br.Msg = "参数有误"
  2098. br.ErrMsg = fmt.Sprintf("参数有误, MyChartClassifyId: %d", classifyId)
  2099. return
  2100. }
  2101. _, e := data_manage.GetMyChartClassifyById(sysUser.AdminId, classifyId)
  2102. if e != nil {
  2103. if e.Error() == utils.ErrNoRow() {
  2104. br.Msg = "分类不存在, 请刷新页面"
  2105. return
  2106. }
  2107. br.Msg = "获取失败"
  2108. br.ErrMsg = "获取分类信息失败, Err:" + e.Error()
  2109. return
  2110. }
  2111. nodeOb := new(data_manage.ChartFrameworkNode)
  2112. cond := ` AND my_chart_classify_id = ?`
  2113. pars := make([]interface{}, 0)
  2114. pars = append(pars, classifyId)
  2115. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  2116. if e != nil {
  2117. br.Msg = "获取失败"
  2118. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  2119. return
  2120. }
  2121. resp := make([]*data_manage.ChartFrameworkNodeItem, 0)
  2122. for _, v := range nodes {
  2123. resp = append(resp, data_manage.FormatChartFrameworkNode2Item(v, 0))
  2124. }
  2125. br.Data = resp
  2126. br.Ret = 200
  2127. br.Msg = "获取成功"
  2128. br.Success = true
  2129. }