my_chart.go 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  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. keyword := this.GetString("Keyword")
  1131. var total int
  1132. page := paging.GetPaging(currentIndex, pageSize, total)
  1133. var startSize int
  1134. if pageSize <= 0 {
  1135. pageSize = utils.PageSize20
  1136. }
  1137. if currentIndex <= 0 {
  1138. currentIndex = 1
  1139. }
  1140. startSize = paging.StartIndex(currentIndex, pageSize)
  1141. var condition string
  1142. var pars []interface{}
  1143. chartAdminId := sysUser.AdminId
  1144. if myChartClassifyId > 0 {
  1145. condition += " AND c.my_chart_classify_id=? "
  1146. pars = append(pars, myChartClassifyId)
  1147. // 可共享
  1148. if isShared {
  1149. myClassify, e := data_manage.GetMyChartClassifyByClassifyId(myChartClassifyId)
  1150. if e != nil {
  1151. if e.Error() == utils.ErrNoRow() {
  1152. br.Msg = "分类已被删除, 请刷新页面"
  1153. return
  1154. }
  1155. br.Msg = "获取失败"
  1156. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  1157. return
  1158. }
  1159. chartAdminId = myClassify.AdminId
  1160. }
  1161. }
  1162. if keyword != "" {
  1163. if this.Lang == utils.LANG_EN {
  1164. condition += " AND (b.chart_name_en like ?) "
  1165. } else {
  1166. condition += " AND (b.chart_name like ?) "
  1167. }
  1168. pars = append(pars, "%"+keyword+"%")
  1169. }
  1170. condition += " AND (a.admin_id = ? OR d.is_public = 1)"
  1171. pars = append(pars, chartAdminId)
  1172. if myChartId > 0 {
  1173. condition += " AND a.my_chart_id=? "
  1174. pars = append(pars, myChartId)
  1175. }
  1176. // 获取当前账号的不可见指标
  1177. noPermissionChartIdList := make([]int, 0)
  1178. {
  1179. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1180. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1181. if err != nil && err.Error() != utils.ErrNoRow() {
  1182. br.Msg = "获取失败"
  1183. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1184. return
  1185. }
  1186. for _, v := range confList {
  1187. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1188. }
  1189. }
  1190. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1191. if lenNoPermissionChartIdList > 0 {
  1192. condition += ` AND b.chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1193. pars = append(pars, noPermissionChartIdList)
  1194. }
  1195. //获取图表信息
  1196. list, err := data_manage.GetMyChartListByCondition(condition, pars, startSize, pageSize)
  1197. if err != nil && err.Error() != utils.ErrNoRow() {
  1198. br.Success = true
  1199. br.Msg = "获取图表信息失败"
  1200. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1201. return
  1202. }
  1203. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1204. if err != nil && err.Error() != utils.ErrNoRow() {
  1205. br.Msg = "获取图表信息失败"
  1206. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1207. return
  1208. }
  1209. myChartMap := make(map[int]int)
  1210. chartInfoIds := ""
  1211. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1212. for _, v := range myChartList {
  1213. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1214. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1215. }
  1216. if chartInfoIds != "" {
  1217. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1218. //判断是否需要展示英文标识
  1219. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1220. if e != nil {
  1221. br.Msg = "获取失败"
  1222. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1223. return
  1224. }
  1225. for _, v := range edbList {
  1226. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1227. }
  1228. }
  1229. listLen := len(list)
  1230. if listLen > 0 {
  1231. // 分类id
  1232. classifyIdList := make([]int, 0)
  1233. // 当前列表中的分类map
  1234. classifyMap := make(map[int]*data_manage.ChartClassify)
  1235. for _, v := range list {
  1236. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1237. }
  1238. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1239. if err != nil {
  1240. br.Msg = "获取失败"
  1241. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1242. return
  1243. }
  1244. for _, v := range classifyList {
  1245. classifyMap[v.ChartClassifyId] = v
  1246. }
  1247. // 已授权分类id
  1248. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1249. if err != nil {
  1250. br.Msg = "获取失败"
  1251. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1252. return
  1253. }
  1254. // 权限
  1255. for i, chartViewInfo := range list {
  1256. //判断是否需要展示英文标识
  1257. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1258. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  1259. }
  1260. if _, ok := myChartMap[list[i].ChartInfoId]; ok {
  1261. list[i].IsAdd = true
  1262. }
  1263. // 数据权限
  1264. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1265. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1266. } else if chartViewInfo.ChartClassifyId == 0 {
  1267. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, 0, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1268. }
  1269. }
  1270. }
  1271. resp := new(data_manage.MyChartListResp)
  1272. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1273. items := make([]*data_manage.MyChartList, 0)
  1274. resp.Paging = page
  1275. resp.List = items
  1276. br.Ret = 200
  1277. br.Success = true
  1278. br.Msg = "获取成功"
  1279. return
  1280. }
  1281. total, err = data_manage.GetMyChartListCountByCondition(condition, pars)
  1282. if err != nil && err.Error() != utils.ErrNoRow() {
  1283. br.Msg = "获取信息失败"
  1284. br.ErrMsg = "获取我的图表数据总数失败,Err:" + err.Error()
  1285. return
  1286. }
  1287. page = paging.GetPaging(currentIndex, pageSize, total)
  1288. resp.Paging = page
  1289. resp.List = list
  1290. br.Ret = 200
  1291. br.Success = true
  1292. br.Msg = "获取成功"
  1293. br.Data = resp
  1294. }
  1295. // @Title 移动我的图表接口
  1296. // @Description 移动我的图表接口
  1297. // @Success 200 {object} data_manage.MoveMyChartReq
  1298. // @router /move [post]
  1299. func (this *MyChartController) MyChartMove() {
  1300. br := new(models.BaseResponse).Init()
  1301. defer func() {
  1302. this.Data["json"] = br
  1303. this.ServeJSON()
  1304. }()
  1305. sysUser := this.SysUser
  1306. if sysUser == nil {
  1307. br.Msg = "请登录"
  1308. br.ErrMsg = "请登录,SysUser Is Empty"
  1309. br.Ret = 408
  1310. return
  1311. }
  1312. adminId := sysUser.AdminId
  1313. var req data_manage.MoveMyChartReq
  1314. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1315. if err != nil {
  1316. br.Msg = "参数解析异常!"
  1317. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1318. return
  1319. }
  1320. //step := float64(65536)
  1321. var newSort float64
  1322. if req.PrevMyChartId <= 0 {
  1323. firstMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
  1324. if err != nil {
  1325. br.Msg = "获取数据失败!"
  1326. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1327. return
  1328. }
  1329. //if firstMapItem.Sort <= 0 {
  1330. // firstSort := step / float64(2)
  1331. // err = data_manage.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
  1332. // if err != nil {
  1333. // br.Msg = "移动失败!"
  1334. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1335. // return
  1336. // }
  1337. // newSort = step / float64(4)
  1338. //} else {
  1339. // newSort = firstMapItem.Sort / float64(2)
  1340. //}
  1341. newSort = firstMapItem.Sort - 1
  1342. } else if req.NextMyChartId <= 0 {
  1343. latestMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
  1344. if err != nil {
  1345. br.Msg = "获取数据失败!"
  1346. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1347. return
  1348. }
  1349. //if latestMapItem.Sort <= 0 {
  1350. // latestSort := step / float64(2)
  1351. // err = data_manage.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
  1352. // if err != nil {
  1353. // br.Msg = "移动失败!"
  1354. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1355. // return
  1356. // }
  1357. // newSort = step / float64(4)
  1358. //} else {
  1359. // newSort = latestMapItem.Sort + (step / float64(2)) - 1
  1360. //}
  1361. newSort = latestMapItem.Sort + 1
  1362. } else {
  1363. preMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
  1364. if err != nil {
  1365. br.Msg = "获取数据失败!"
  1366. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1367. return
  1368. }
  1369. nextMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
  1370. if err != nil {
  1371. br.Msg = "获取数据失败!"
  1372. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1373. return
  1374. }
  1375. newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
  1376. newSort = preMapItem.Sort + 1
  1377. var updateSortStr string
  1378. if preMapItem.Sort == nextMapItem.Sort {
  1379. //变更兄弟节点的排序(sort同级)
  1380. updateSortStr = `sort + 2`
  1381. } else if nextMapItem.Sort-preMapItem.Sort == 1 {
  1382. //变更兄弟节点的排序(sort只相差一级)
  1383. updateSortStr = `sort + 1`
  1384. }
  1385. if updateSortStr != `` {
  1386. _ = data_manage.UpdateMyChartSortByClassifyId(req.MyChartClassifyId, int(preMapItem.Sort), preMapItem.MyChartClassifyMappingId, updateSortStr)
  1387. }
  1388. }
  1389. //if newSort >= 0 {
  1390. //
  1391. //} else {
  1392. // utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
  1393. //}
  1394. err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
  1395. if err != nil {
  1396. br.Msg = "移动失败!"
  1397. br.ErrMsg = "移动失败,Err:" + err.Error()
  1398. return
  1399. }
  1400. //新增操作日志
  1401. {
  1402. edbLog := new(data_manage.MyChartLog)
  1403. edbLog.MyChartId = 0
  1404. edbLog.ChartInfoId = 0
  1405. edbLog.SysUserId = sysUser.AdminId
  1406. edbLog.SysUserRealName = sysUser.RealName
  1407. edbLog.CreateTime = time.Now()
  1408. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1409. edbLog.Status = "移动我的图表"
  1410. edbLog.Method = this.Ctx.Input.URI()
  1411. go data_manage.AddMyChartLog(edbLog)
  1412. }
  1413. //更新es
  1414. if req.MyChartId > 0 {
  1415. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1416. }
  1417. br.Ret = 200
  1418. br.Success = true
  1419. br.Msg = "移动成功"
  1420. br.IsAddLog = true
  1421. }
  1422. // @Title ETA图表-推荐列表接口
  1423. // @Description ETA图表-推荐列表接口
  1424. // @Param ChartClassifyId query int true "分类id"
  1425. // @Success 200 {object} data_manage.ChartRecommendListResp
  1426. // @router /chart/recommend/list [get]
  1427. func (this *MyChartController) ChartRecommendList() {
  1428. br := new(models.BaseResponse).Init()
  1429. defer func() {
  1430. this.Data["json"] = br
  1431. this.ServeJSON()
  1432. }()
  1433. sysUser := this.SysUser
  1434. if sysUser == nil {
  1435. br.Msg = "请登录"
  1436. br.ErrMsg = "请登录,SysUser Is Empty"
  1437. br.Ret = 408
  1438. return
  1439. }
  1440. pageSize := 6
  1441. currentIndex := 1
  1442. var startSize int
  1443. startSize = paging.StartIndex(currentIndex, pageSize)
  1444. var condition string
  1445. var pars []interface{}
  1446. if sysUser.AdminId > 0 {
  1447. condition += " AND a.admin_id=? "
  1448. pars = append(pars, sysUser.AdminId)
  1449. }
  1450. //获取图表信息
  1451. list, err := data_manage.GetRecommendChartListByCondition(condition, pars, startSize, pageSize)
  1452. if err != nil && err.Error() != utils.ErrNoRow() {
  1453. br.Success = true
  1454. br.Msg = "获取图表信息失败"
  1455. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1456. return
  1457. }
  1458. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1459. if err != nil && err.Error() != utils.ErrNoRow() {
  1460. br.Msg = "获取图表信息失败"
  1461. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1462. return
  1463. }
  1464. myChartMap := make(map[int]int)
  1465. for _, v := range myChartList {
  1466. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1467. }
  1468. listLen := len(list)
  1469. if listLen > 0 {
  1470. // 分类id
  1471. classifyIdList := make([]int, 0)
  1472. // 当前列表中的分类map
  1473. classifyMap := make(map[int]*data_manage.ChartClassify)
  1474. for _, v := range list {
  1475. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1476. }
  1477. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1478. if err != nil {
  1479. br.Msg = "获取失败"
  1480. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1481. return
  1482. }
  1483. for _, v := range classifyList {
  1484. classifyMap[v.ChartClassifyId] = v
  1485. }
  1486. // 已授权分类id
  1487. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1488. if err != nil {
  1489. br.Msg = "获取失败"
  1490. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. // 权限
  1494. for k, chartViewInfo := range list {
  1495. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1496. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1497. }
  1498. if _, ok := myChartMap[list[k].ChartInfoId]; ok {
  1499. list[k].IsAdd = true
  1500. }
  1501. }
  1502. }
  1503. resp := new(data_manage.ChartRecommendListResp)
  1504. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1505. items := make([]*data_manage.ChartInfoView, 0)
  1506. resp.List = items
  1507. br.Ret = 200
  1508. br.Success = true
  1509. br.Msg = "获取成功"
  1510. return
  1511. }
  1512. resp.List = list
  1513. br.Ret = 200
  1514. br.Success = true
  1515. br.Msg = "获取成功"
  1516. br.Data = resp
  1517. }
  1518. // @Title 我的图表-列表接口
  1519. // @Description 我的图表-列表接口
  1520. // @Param KeyWord query string true "搜索关键词"
  1521. // @Success 200 {object} data_manage.MyChartListResp
  1522. // @router /search [get]
  1523. func (this *MyChartController) MyChartSearch() {
  1524. br := new(models.BaseResponse).Init()
  1525. defer func() {
  1526. this.Data["json"] = br
  1527. this.ServeJSON()
  1528. }()
  1529. sysUser := this.SysUser
  1530. if sysUser == nil {
  1531. br.Msg = "请登录"
  1532. br.ErrMsg = "请登录,SysUser Is Empty"
  1533. br.Ret = 408
  1534. return
  1535. }
  1536. var condition string
  1537. var pars []interface{}
  1538. condition += " AND a.admin_id=? "
  1539. pars = append(pars, sysUser.AdminId)
  1540. keyWord := this.GetString("KeyWord")
  1541. if keyWord != "" {
  1542. condition += ` AND chart_name LIKE '%` + keyWord + `%' `
  1543. }
  1544. //获取图表信息
  1545. list, err := data_manage.GetMyChartSearchByCondition(condition, pars)
  1546. if err != nil && err.Error() != utils.ErrNoRow() {
  1547. br.Success = true
  1548. br.Msg = "获取图表信息失败"
  1549. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1550. return
  1551. }
  1552. listLen := len(list)
  1553. if listLen > 0 {
  1554. // 分类id
  1555. classifyIdList := make([]int, 0)
  1556. // 当前列表中的分类map
  1557. classifyMap := make(map[int]*data_manage.ChartClassify)
  1558. for _, v := range list {
  1559. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1560. }
  1561. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1562. if err != nil {
  1563. br.Msg = "获取失败"
  1564. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1565. return
  1566. }
  1567. for _, v := range classifyList {
  1568. classifyMap[v.ChartClassifyId] = v
  1569. }
  1570. // 已授权分类id
  1571. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1572. if err != nil {
  1573. br.Msg = "获取失败"
  1574. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1575. return
  1576. }
  1577. // 权限
  1578. for k, chartViewInfo := range list {
  1579. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1580. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1581. }
  1582. list[k].IsAdd = true
  1583. }
  1584. }
  1585. resp := new(data_manage.MyChartSearchListResp)
  1586. if list == nil {
  1587. list = make([]*data_manage.MyChartList, 0)
  1588. }
  1589. resp.List = list
  1590. br.Ret = 200
  1591. br.Success = true
  1592. br.Msg = "获取成功"
  1593. br.Data = resp
  1594. }
  1595. // MyChartSearchByEs
  1596. // @Title 我的图表-列表接口
  1597. // @Description 我的图表-列表接口
  1598. // @Param Keyword query string true "搜索关键词"
  1599. // @Success 200 {object} data_manage.MyChartListResp
  1600. // @router /search_by_es [get]
  1601. func (this *MyChartController) MyChartSearchByEs() {
  1602. br := new(models.BaseResponse).Init()
  1603. defer func() {
  1604. this.Data["json"] = br
  1605. this.ServeJSON()
  1606. }()
  1607. sysUser := this.SysUser
  1608. if sysUser == nil {
  1609. br.Msg = "请登录"
  1610. br.ErrMsg = "请登录,SysUser Is Empty"
  1611. br.Ret = 408
  1612. return
  1613. }
  1614. pageSize, _ := this.GetInt("PageSize")
  1615. currentIndex, _ := this.GetInt("CurrentIndex")
  1616. var startSize int
  1617. if pageSize <= 0 {
  1618. pageSize = utils.PageSize20
  1619. }
  1620. if currentIndex <= 0 {
  1621. currentIndex = 1
  1622. }
  1623. startSize = paging.StartIndex(currentIndex, pageSize)
  1624. keyword := this.GetString("Keyword")
  1625. // 获取当前账号的不可见指标
  1626. noPermissionChartIdList := make([]int, 0)
  1627. {
  1628. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1629. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1630. if err != nil && err.Error() != utils.ErrNoRow() {
  1631. br.Msg = "获取失败"
  1632. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1633. return
  1634. }
  1635. for _, v := range confList {
  1636. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1637. }
  1638. }
  1639. //获取图表信息
  1640. list, total, err := data.EsSearchMyChartInfo(keyword, sysUser.AdminId, noPermissionChartIdList, startSize, pageSize)
  1641. if err != nil {
  1642. br.Msg = "获取失败"
  1643. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1644. return
  1645. }
  1646. lenList := len(list)
  1647. if lenList <= 0 {
  1648. list = make([]*data_manage.MyChartList, 0)
  1649. } else {
  1650. // 分类id
  1651. classifyIdList := make([]int, 0)
  1652. // 图表id
  1653. chartInfoIdList := make([]int, 0)
  1654. // 当前列表中的分类map
  1655. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1656. // 当前列表中的图表map
  1657. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  1658. for _, v := range list {
  1659. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1660. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1661. }
  1662. // 分类
  1663. {
  1664. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1665. if err != nil {
  1666. if err != nil {
  1667. br.Msg = "获取失败"
  1668. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1669. return
  1670. }
  1671. }
  1672. for _, tmpClassifyInfo := range classifyList {
  1673. chartClassifyMap[tmpClassifyInfo.ChartClassifyId] = tmpClassifyInfo
  1674. }
  1675. }
  1676. // 图表
  1677. {
  1678. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1679. if err != nil {
  1680. br.Msg = "获取失败"
  1681. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  1682. return
  1683. }
  1684. for _, tmpChartInfo := range tmpChartList {
  1685. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  1686. }
  1687. }
  1688. // 已授权分类id
  1689. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1690. if err != nil {
  1691. br.Msg = "获取失败"
  1692. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1693. return
  1694. }
  1695. // 权限
  1696. for k, tmpChartViewInfo := range list {
  1697. list[k].IsAdd = true
  1698. chartViewInfo, ok := chartInfoMap[tmpChartViewInfo.ChartInfoId]
  1699. if !ok {
  1700. continue
  1701. }
  1702. if currClassify, ok := chartClassifyMap[chartViewInfo.ChartClassifyId]; ok {
  1703. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1704. }
  1705. }
  1706. }
  1707. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1708. resp := data_manage.MyChartSearchListResp{
  1709. List: list,
  1710. Paging: page,
  1711. }
  1712. br.Ret = 200
  1713. br.Success = true
  1714. br.Msg = "获取成功"
  1715. br.Data = resp
  1716. }
  1717. // PublicClassifyList
  1718. // @Title 我的图表-公共分类列表接口
  1719. // @Description 我的图表-公共分类列表接口
  1720. // @Success 200 {object} data_manage.MyChartClassifyResp
  1721. // @router /classify/public_list [get]
  1722. func (this *MyChartController) PublicClassifyList() {
  1723. br := new(models.BaseResponse).Init()
  1724. defer func() {
  1725. this.Data["json"] = br
  1726. this.ServeJSON()
  1727. }()
  1728. sysUser := this.SysUser
  1729. if sysUser == nil {
  1730. br.Msg = "请登录"
  1731. br.ErrMsg = "请登录,SysUser Is Empty"
  1732. br.Ret = 408
  1733. return
  1734. }
  1735. //获取图表信息
  1736. list, err := data_manage.GetPublicChartClassifyAllExceptMy(sysUser.AdminId)
  1737. if err != nil && err.Error() != utils.ErrNoRow() {
  1738. br.Success = true
  1739. br.Msg = "获取公共分类信息失败"
  1740. br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
  1741. return
  1742. }
  1743. resp := new(data_manage.PublicChartClassifyResp)
  1744. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1745. resp.List = make([]data_manage.PublicChartClassifyList, 0)
  1746. br.Ret = 200
  1747. br.Success = true
  1748. br.Msg = "获取成功"
  1749. return
  1750. }
  1751. // 创建人姓名
  1752. adminIdStr := make([]string, 0)
  1753. for _, v := range list {
  1754. adminIdStr = append(adminIdStr, fmt.Sprint(v.AdminId))
  1755. }
  1756. adminMap := make(map[int]string)
  1757. adminList, _ := system.GetSysAdminByIdSlice(adminIdStr)
  1758. if len(adminList) > 0 {
  1759. for _, adminInfo := range adminList {
  1760. adminMap[adminInfo.AdminId] = adminInfo.RealName
  1761. }
  1762. }
  1763. respList := make([]data_manage.PublicChartClassifyList, 0)
  1764. existMap := make(map[int]bool, 0)
  1765. itemsMap := make(map[int][]data_manage.PublicChartClassifyItem, 0)
  1766. for _, v := range list {
  1767. realName := adminMap[v.AdminId]
  1768. if realName == "" {
  1769. // 忽略掉被删掉的用户
  1770. continue
  1771. }
  1772. if itemsMap[v.AdminId] == nil {
  1773. itemsMap[v.AdminId] = make([]data_manage.PublicChartClassifyItem, 0)
  1774. }
  1775. itemsMap[v.AdminId] = append(itemsMap[v.AdminId], data_manage.PublicChartClassifyItem{
  1776. MyChartClassifyId: v.MyChartClassifyId,
  1777. MyChartClassifyName: v.MyChartClassifyName,
  1778. AdminId: v.AdminId,
  1779. RealName: realName,
  1780. IsPublic: v.IsPublic,
  1781. IsCompanyPublic: v.IsCompanyPublic,
  1782. })
  1783. var menu data_manage.PublicChartClassifyList
  1784. if existMap[v.AdminId] {
  1785. continue
  1786. }
  1787. existMap[v.AdminId] = true
  1788. menu.MenuAdminId = v.AdminId
  1789. menu.MenuName = fmt.Sprintf("%s的图库", realName)
  1790. respList = append(respList, menu)
  1791. }
  1792. for k, v := range respList {
  1793. respList[k].Items = itemsMap[v.MenuAdminId]
  1794. }
  1795. resp.List = respList
  1796. language := `CN`
  1797. // 指标显示的语言
  1798. {
  1799. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  1800. if configDetail != nil {
  1801. language = configDetail.ConfigValue
  1802. } else {
  1803. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  1804. if configDetail != nil {
  1805. language = configDetail.ConfigValue
  1806. }
  1807. }
  1808. }
  1809. resp.Language = language
  1810. br.Ret = 200
  1811. br.Success = true
  1812. br.Msg = "获取成功"
  1813. br.Data = resp
  1814. }
  1815. // ModifyClassifyPublicStatus
  1816. // @Title 修改我的图表分类的是否可见
  1817. // @Description 修改我的图表分类的是否可见接口
  1818. // @Param request body data_manage.ModifyChartClassifyPublicReq true "type json string"
  1819. // @Success 200 Ret=200 修改成功
  1820. // @router /classify/modify_public [post]
  1821. func (this *MyChartController) ModifyClassifyPublicStatus() {
  1822. br := new(models.BaseResponse).Init()
  1823. defer func() {
  1824. this.Data["json"] = br
  1825. this.ServeJSON()
  1826. }()
  1827. sysUser := this.SysUser
  1828. if sysUser == nil {
  1829. br.Msg = "请登录"
  1830. br.ErrMsg = "请登录,SysUser Is Empty"
  1831. br.Ret = 408
  1832. return
  1833. }
  1834. var req data_manage.ModifyChartClassifyPublicReq
  1835. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1836. if err != nil {
  1837. br.Msg = "参数解析异常!"
  1838. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1839. return
  1840. }
  1841. //查询该分类存不存在
  1842. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  1843. if err != nil && err.Error() != utils.ErrNoRow() {
  1844. br.Msg = "修改失败,找不到该分类"
  1845. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1846. return
  1847. }
  1848. if item == nil {
  1849. br.Msg = "分类不存在"
  1850. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1851. return
  1852. }
  1853. item.IsPublic = req.IsPublic
  1854. item.PublicTime = time.Now()
  1855. if req.IsPublic == 0 {
  1856. // 取消公开同时取消客户公开
  1857. item.IsCompanyPublic = 0
  1858. }
  1859. err = item.Update([]string{"IsPublic", "PublicTime", "IsCompanyPublic"})
  1860. if err != nil {
  1861. br.Msg = "修改失败"
  1862. br.ErrMsg = "修改是否公开失败,Err:" + err.Error()
  1863. return
  1864. }
  1865. //新增操作日志
  1866. {
  1867. edbLog := new(data_manage.MyChartLog)
  1868. edbLog.MyChartId = 0
  1869. edbLog.ChartInfoId = 0
  1870. edbLog.SysUserId = sysUser.AdminId
  1871. edbLog.SysUserRealName = sysUser.RealName
  1872. edbLog.CreateTime = time.Now()
  1873. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1874. edbLog.Status = "修改分类是否公开"
  1875. edbLog.Method = this.Ctx.Input.URI()
  1876. go data_manage.AddMyChartLog(edbLog)
  1877. }
  1878. br.Ret = 200
  1879. br.Msg = "修改成功"
  1880. br.Success = true
  1881. br.IsAddLog = true
  1882. }
  1883. // CopyClassifyAndChart
  1884. // @Title 复制我的图表分类
  1885. // @Description 复制我的图表分类接口
  1886. // @Param request body data_manage.CopyChartClassifyReq true "type json string"
  1887. // @Success 200 Ret=200 复制成功
  1888. // @router /classify/copy [post]
  1889. func (this *MyChartController) CopyClassifyAndChart() {
  1890. br := new(models.BaseResponse).Init()
  1891. defer func() {
  1892. this.Data["json"] = br
  1893. this.ServeJSON()
  1894. }()
  1895. sysUser := this.SysUser
  1896. if sysUser == nil {
  1897. br.Msg = "请登录"
  1898. br.ErrMsg = "请登录,SysUser Is Empty"
  1899. br.Ret = 408
  1900. return
  1901. }
  1902. var req data_manage.CopyChartClassifyReq
  1903. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1904. if err != nil {
  1905. br.Msg = "参数解析异常!"
  1906. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1907. return
  1908. }
  1909. //查询该公共分类存不存在
  1910. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1911. if err != nil && err.Error() != utils.ErrNoRow() {
  1912. br.Msg = "复制失败,找不到该分类"
  1913. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1914. return
  1915. }
  1916. if item == nil {
  1917. br.Msg = "分类不存在"
  1918. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1919. return
  1920. }
  1921. //获取所有的分类名称
  1922. chartClassifyList, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  1923. //生成新的分类名称
  1924. newChartClassifyName := generateMyChartClassifyName(item.MyChartClassifyName, 1, chartClassifyList)
  1925. //复制分类
  1926. newMyChartClassify, err := data_manage.CopyPublicMyChartClassifyById(item.MyChartClassifyId, sysUser.AdminId, newChartClassifyName)
  1927. if err != nil {
  1928. br.Msg = "复制失败"
  1929. br.ErrMsg = "复制失败,Err:" + err.Error()
  1930. return
  1931. }
  1932. //新增操作日志
  1933. {
  1934. edbLog := new(data_manage.MyChartLog)
  1935. edbLog.MyChartId = 0
  1936. edbLog.ChartInfoId = 0
  1937. edbLog.SysUserId = sysUser.AdminId
  1938. edbLog.SysUserRealName = sysUser.RealName
  1939. edbLog.CreateTime = time.Now()
  1940. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1941. edbLog.Status = "复制分类"
  1942. edbLog.Method = this.Ctx.Input.URI()
  1943. go data_manage.AddMyChartLog(edbLog)
  1944. }
  1945. br.Data = newMyChartClassify
  1946. br.Ret = 200
  1947. br.Msg = "复制成功"
  1948. br.Success = true
  1949. br.IsAddLog = true
  1950. }
  1951. // generateMyChartClassifyName 生成我的图库分类名称
  1952. func generateMyChartClassifyName(myChartClassifyName string, count int, chartClassifyList []*data_manage.MyChartClassify) (newChartClassifyName string) {
  1953. newChartClassifyName = fmt.Sprint(myChartClassifyName, count)
  1954. for _, v := range chartClassifyList {
  1955. if v.MyChartClassifyName == newChartClassifyName {
  1956. count++
  1957. newChartClassifyName = generateMyChartClassifyName(fmt.Sprint(myChartClassifyName), count, chartClassifyList)
  1958. return
  1959. }
  1960. }
  1961. return
  1962. }
  1963. // ModifyClassifyPublicStatus
  1964. // @Title 修改公共分类是否用户可见
  1965. // @Description 修改公共分类是否用户可见接口
  1966. // @Param request body data_manage.ModifyChartClassifyCompanyPublicReq true "type json string"
  1967. // @Success 200 Ret=200 修改成功
  1968. // @router /classify/modify_company_public [post]
  1969. func (this *MyChartController) ModifyClassifyCompanyPublicStatus() {
  1970. br := new(models.BaseResponse).Init()
  1971. defer func() {
  1972. this.Data["json"] = br
  1973. this.ServeJSON()
  1974. }()
  1975. sysUser := this.SysUser
  1976. if sysUser == nil {
  1977. br.Msg = "请登录"
  1978. br.ErrMsg = "请登录,SysUser Is Empty"
  1979. br.Ret = 408
  1980. return
  1981. }
  1982. var req data_manage.ModifyChartClassifyCompanyPublicReq
  1983. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1984. if err != nil {
  1985. br.Msg = "参数解析异常!"
  1986. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1987. return
  1988. }
  1989. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1990. if err != nil {
  1991. br.Msg = "找不到该分类"
  1992. br.ErrMsg = "获取分类信息失败, Err:" + err.Error()
  1993. return
  1994. }
  1995. if item.IsPublic != 1 {
  1996. br.Msg = "该分类未公开,不可设置为用户可见"
  1997. br.ErrMsg = "该分类未公开,不可设置为用户可见"
  1998. return
  1999. }
  2000. item.IsCompanyPublic = req.IsCompanyPublic
  2001. item.CompanyPublicTime = time.Now()
  2002. err = item.Update([]string{"IsCompanyPublic", "CompanyPublicTime"})
  2003. if err != nil {
  2004. br.Msg = "修改失败"
  2005. br.ErrMsg = "修改是否用户可见失败, Err:" + err.Error()
  2006. return
  2007. }
  2008. {
  2009. edbLog := new(data_manage.MyChartLog)
  2010. edbLog.MyChartId = 0
  2011. edbLog.ChartInfoId = 0
  2012. edbLog.SysUserId = sysUser.AdminId
  2013. edbLog.SysUserRealName = sysUser.RealName
  2014. edbLog.CreateTime = time.Now()
  2015. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2016. edbLog.Status = "修改用户是否可见"
  2017. edbLog.Method = this.Ctx.Input.URI()
  2018. go data_manage.AddMyChartLog(edbLog)
  2019. }
  2020. br.Ret = 200
  2021. br.Msg = "修改成功"
  2022. br.Success = true
  2023. br.IsAddLog = true
  2024. }
  2025. // CompanyPublicClassifyList
  2026. // @Title 我的图表-用户可见分类列表
  2027. // @Description 我的图表-用户可见分类列表接口
  2028. // @Param Keyword query string false "分类名称关键词"
  2029. // @Success 200 {object} data_manage.MyChartClassifyResp
  2030. // @router /classify/company_public_list [get]
  2031. func (this *MyChartController) CompanyPublicClassifyList() {
  2032. br := new(models.BaseResponse).Init()
  2033. defer func() {
  2034. this.Data["json"] = br
  2035. this.ServeJSON()
  2036. }()
  2037. sysUser := this.SysUser
  2038. if sysUser == nil {
  2039. br.Msg = "请登录"
  2040. br.ErrMsg = "请登录,SysUser Is Empty"
  2041. br.Ret = 408
  2042. return
  2043. }
  2044. var condition string
  2045. var pars []interface{}
  2046. keyword := this.GetString("Keyword")
  2047. if keyword != "" {
  2048. keyword = "%" + keyword + "%"
  2049. condition += ` AND my_chart_classify_name LIKE ? `
  2050. pars = append(pars, keyword)
  2051. }
  2052. list, err := data_manage.GetCompanyPublicClassifyList(condition, pars)
  2053. if err != nil && err.Error() != utils.ErrNoRow() {
  2054. br.Success = true
  2055. br.Msg = "获取用户可见分类列表失败"
  2056. br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
  2057. return
  2058. }
  2059. resp := new(data_manage.MyChartClassifyResp)
  2060. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  2061. items := make([]*data_manage.MyChartClassifyItem, 0)
  2062. resp.List = items
  2063. br.Ret = 200
  2064. br.Success = true
  2065. br.Msg = "获取成功"
  2066. return
  2067. }
  2068. results := make([]*data_manage.MyChartClassifyItem, 0)
  2069. for _, v := range list {
  2070. results = append(results, data_manage.FormatMyChartClassify2Item(v, 0))
  2071. }
  2072. resp.List = results
  2073. //resp.List = list
  2074. br.Ret = 200
  2075. br.Success = true
  2076. br.Msg = "获取成功"
  2077. br.Data = resp
  2078. }
  2079. //func init() {
  2080. // data.AddAllMyChartInfo()
  2081. //}
  2082. // ClassifyFrameworkNodeList
  2083. // @Title 我的图表分类-关联的框架节点列表
  2084. // @Description 我的图表分类-关联的框架节点列表
  2085. // @Param MyChartClassifyId query int false "图表分类ID"
  2086. // @Success 200 Ret=200 获取成功
  2087. // @router /classify/framework_node_list [get]
  2088. func (this *MyChartController) ClassifyFrameworkNodeList() {
  2089. br := new(models.BaseResponse).Init()
  2090. defer func() {
  2091. if br.ErrMsg == "" {
  2092. br.IsSendEmail = true
  2093. }
  2094. this.Data["json"] = br
  2095. this.ServeJSON()
  2096. }()
  2097. sysUser := this.SysUser
  2098. if sysUser == nil {
  2099. br.Msg = "请登录"
  2100. br.ErrMsg = "请登录,SysUser Is Empty"
  2101. br.Ret = 408
  2102. return
  2103. }
  2104. classifyId, _ := this.GetInt("MyChartClassifyId")
  2105. if classifyId <= 0 {
  2106. br.Msg = "参数有误"
  2107. br.ErrMsg = fmt.Sprintf("参数有误, MyChartClassifyId: %d", classifyId)
  2108. return
  2109. }
  2110. _, e := data_manage.GetMyChartClassifyById(sysUser.AdminId, classifyId)
  2111. if e != nil {
  2112. if e.Error() == utils.ErrNoRow() {
  2113. br.Msg = "分类不存在, 请刷新页面"
  2114. return
  2115. }
  2116. br.Msg = "获取失败"
  2117. br.ErrMsg = "获取分类信息失败, Err:" + e.Error()
  2118. return
  2119. }
  2120. nodeOb := new(data_manage.ChartFrameworkNode)
  2121. cond := ` AND my_chart_classify_id = ?`
  2122. pars := make([]interface{}, 0)
  2123. pars = append(pars, classifyId)
  2124. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  2125. if e != nil {
  2126. br.Msg = "获取失败"
  2127. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  2128. return
  2129. }
  2130. resp := make([]*data_manage.ChartFrameworkNodeItem, 0)
  2131. for _, v := range nodes {
  2132. resp = append(resp, data_manage.FormatChartFrameworkNode2Item(v, 0))
  2133. }
  2134. br.Data = resp
  2135. br.Ret = 200
  2136. br.Msg = "获取成功"
  2137. br.Success = true
  2138. }