chart_classify.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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/services/eta_forum"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "time"
  14. )
  15. const (
  16. CHART_CLASSIFY_ADD_OR_EDIT = "chartLib:classifyOpt:add"
  17. CHART_CLASSIFY_DELETE = "chartLib:classifyOpt:delete"
  18. CHART_CLASSIFY_MOVE = "chartLib:classifyOpt:move"
  19. )
  20. // 数据管理-分类模块
  21. type ChartClassifyController struct {
  22. controllers.BaseAuthController
  23. }
  24. //
  25. //// @Title 图表分类列表
  26. //// @Description 图表分类列表接口
  27. //// @Success 200 {object} data_manage.ChartClassifyListResp
  28. //// @router /chart_classify/list [get]
  29. //func (this *ChartClassifyController) ChartClassifyList() {
  30. // br := new(models.BaseResponse).Init()
  31. // defer func() {
  32. // this.Data["json"] = br
  33. // this.ServeJSON()
  34. // }()
  35. // rootList, err := data_manage.GetChartClassifyByParentId(0)
  36. // if err != nil {
  37. // br.Msg = "获取失败"
  38. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  39. // return
  40. // }
  41. //
  42. // classifyAll, err := data_manage.GetChartClassifyAll()
  43. // if err != nil {
  44. // br.Msg = "获取失败"
  45. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. // return
  47. // }
  48. //
  49. // nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  50. // for k := range rootList {
  51. // rootNode := rootList[k]
  52. // data.ChartClassifyListMakeTree(classifyAll, rootNode)
  53. // nodeAll = append(nodeAll, rootNode)
  54. // }
  55. // resp := new(data_manage.ChartClassifyListResp)
  56. // resp.AllNodes = nodeAll
  57. // br.Ret = 200
  58. // br.Success = true
  59. // br.Msg = "获取成功"
  60. // br.Data = resp
  61. //}
  62. // ChartClassifyListV2
  63. // @Title 图表分类列表
  64. // @Description 图表分类列表接口
  65. // @Param IsShowMe query bool true "是否只看我的,true、false"
  66. // @Success 200 {object} data_manage.ChartClassifyListResp
  67. // @router /chart_classify/list [get]
  68. func (this *ChartClassifyController) ChartClassifyListV2() {
  69. br := new(models.BaseResponse).Init()
  70. defer func() {
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. resp := new(data_manage.ChartClassifyListResp)
  75. // 获取当前账号的不可见指标
  76. noPermissionChartIdMap := make(map[int]bool)
  77. {
  78. obj := data_manage.EdbInfoNoPermissionAdmin{}
  79. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  80. if err != nil && !utils.IsErrNoRow(err) {
  81. br.Msg = "获取失败"
  82. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  83. return
  84. }
  85. for _, v := range confList {
  86. noPermissionChartIdMap[v.ChartInfoId] = true
  87. }
  88. }
  89. isShowMe, _ := this.GetBool("IsShowMe")
  90. if isShowMe {
  91. errMsg, err := getChartClassifyListForMe(*this.SysUser, resp)
  92. if err != nil {
  93. br.Msg = errMsg
  94. br.ErrMsg = err.Error()
  95. return
  96. }
  97. // 移除没有权限的图表
  98. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  99. resp.AllNodes = allNodes
  100. br.Ret = 200
  101. br.Success = true
  102. br.Msg = "获取成功"
  103. br.Data = resp
  104. fmt.Println("source my classify")
  105. return
  106. }
  107. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  108. key := utils.CACHE_CHART_CLASSIFY
  109. if utils.Re == nil {
  110. if utils.Re == nil && utils.Rc.IsExist(key) {
  111. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  112. err := json.Unmarshal(redisData, &resp)
  113. if err == nil && resp != nil {
  114. // 移除没有权限的图表
  115. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  116. resp.AllNodes = allNodes
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. fmt.Println("source redis")
  122. return
  123. }
  124. }
  125. }
  126. }
  127. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  128. if err != nil && !utils.IsErrNoRow(err) {
  129. br.Msg = "获取失败"
  130. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  131. return
  132. }
  133. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  134. if err != nil && !utils.IsErrNoRow(err) {
  135. br.Msg = "获取失败"
  136. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  137. return
  138. }
  139. allChartInfo, err := data_manage.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT})
  140. if err != nil && !utils.IsErrNoRow(err) {
  141. br.Msg = "获取失败"
  142. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  143. return
  144. }
  145. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  146. for _, v := range allChartInfo {
  147. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  148. }
  149. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  150. for _, v := range classifyAll {
  151. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  152. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  153. v.Children = existItems
  154. } else {
  155. items := make([]*data_manage.ChartClassifyItems, 0)
  156. v.Children = items
  157. }
  158. }
  159. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  160. for _, v := range rootList {
  161. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  162. v.Children = existItems
  163. } else {
  164. items := make([]*data_manage.ChartClassifyItems, 0)
  165. v.Children = items
  166. }
  167. nodeAll = append(nodeAll, v)
  168. }
  169. //
  170. //
  171. //nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  172. //for k := range rootList {
  173. // rootNode := rootList[k]
  174. // data.ChartClassifyListMakeTree(classifyAll, rootNode)
  175. // nodeAll = append(nodeAll, rootNode)
  176. //}
  177. resp.AllNodes = nodeAll
  178. // 将数据加入缓存
  179. if utils.Re == nil {
  180. redisData, _ := json.Marshal(resp)
  181. utils.Rc.Put(key, redisData, 2*time.Hour)
  182. }
  183. // 移除没有权限的图表
  184. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  185. resp.AllNodes = allNodes
  186. br.Ret = 200
  187. br.Success = true
  188. br.Msg = "获取成功"
  189. br.Data = resp
  190. }
  191. // getChartClassifyListForMe 获取我创建的图表
  192. func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  193. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  194. if err != nil && !utils.IsErrNoRow(err) {
  195. errMsg = "获取失败"
  196. return
  197. }
  198. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  199. if err != nil && !utils.IsErrNoRow(err) {
  200. errMsg = "获取失败"
  201. return
  202. }
  203. allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_DEFAULT}, adminInfo.AdminId)
  204. if err != nil && !utils.IsErrNoRow(err) {
  205. errMsg = "获取失败"
  206. return
  207. }
  208. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  209. for _, v := range allChartInfo {
  210. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  211. }
  212. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  213. for _, v := range classifyAll {
  214. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  215. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  216. v.Children = existItems
  217. } else {
  218. items := make([]*data_manage.ChartClassifyItems, 0)
  219. v.Children = items
  220. }
  221. }
  222. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  223. for _, v := range rootList {
  224. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  225. v.Children = existItems
  226. } else {
  227. items := make([]*data_manage.ChartClassifyItems, 0)
  228. v.Children = items
  229. }
  230. nodeAll = append(nodeAll, v)
  231. }
  232. resp.AllNodes = nodeAll
  233. return
  234. }
  235. // ChartClassifyItems
  236. // @Title 获取所有图表分类接口-不包含图表
  237. // @Description 获取所有图表分类接口-不包含图表
  238. // @Param IsShowMe query bool true "是否只看我的,true、false"
  239. // @Success 200 {object} data_manage.ChartClassifyListResp
  240. // @router /chart_classify/items [get]
  241. func (this *ChartClassifyController) ChartClassifyItems() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. isShowMe, _ := this.GetBool("IsShowMe")
  248. level, _ := this.GetInt(`Level`)
  249. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  250. if err != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  253. return
  254. }
  255. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  256. if err != nil {
  257. br.Msg = "获取失败"
  258. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  259. return
  260. }
  261. // 已授权分类id
  262. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  263. if err != nil {
  264. br.Msg = "获取失败"
  265. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  266. return
  267. }
  268. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  269. for k := range rootList {
  270. rootNode := rootList[k]
  271. data.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode, permissionClassifyIdList, level)
  272. nodeAll = append(nodeAll, rootNode)
  273. }
  274. if isShowMe {
  275. // 自己拥有的分类id列表
  276. chartClassifyIdList, err := data_manage.GetChartClassifyIdListByAdminId(this.SysUser.AdminId, utils.CHART_SOURCE_DEFAULT)
  277. if err != nil {
  278. br.Msg = "获取失败"
  279. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  280. return
  281. }
  282. tmpNodeAll := nodeAll
  283. nodeAll = make([]*data_manage.ChartClassifyItems, 0)
  284. for _, node := range tmpNodeAll {
  285. if node.Children == nil || len(node.Children) <= 0 {
  286. continue
  287. }
  288. isSelf := data.RemoveNotChartClassifyItemsMakeTree(node, chartClassifyIdList)
  289. if isSelf {
  290. nodeAll = append(nodeAll, node)
  291. }
  292. }
  293. }
  294. language := `CN`
  295. // 指标显示的语言
  296. {
  297. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  298. if configDetail != nil {
  299. language = configDetail.ConfigValue
  300. } else {
  301. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  302. if configDetail != nil {
  303. language = configDetail.ConfigValue
  304. }
  305. }
  306. }
  307. // 是否允许添加分类
  308. canOpClassify := true
  309. // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
  310. //if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, this.SysUser.RoleTypeCode) {
  311. // canOpClassify = false
  312. //}
  313. resp := data_manage.ChartClassifyListResp{
  314. AllNodes: nodeAll,
  315. Language: language,
  316. CanOpClassify: canOpClassify,
  317. }
  318. br.Ret = 200
  319. br.Success = true
  320. br.Msg = "获取成功"
  321. br.Data = resp
  322. }
  323. // @Title 新增图表分类
  324. // @Description 新增图表分类接口
  325. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  326. // @Success 200 Ret=200 保存成功
  327. // @router /chart_classify/add [post]
  328. func (this *ChartClassifyController) AddChartClassify() {
  329. br := new(models.BaseResponse).Init()
  330. defer func() {
  331. this.Data["json"] = br
  332. this.ServeJSON()
  333. }()
  334. var req data_manage.AddChartClassifyReq
  335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  336. if err != nil {
  337. br.Msg = "参数解析异常!"
  338. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  339. return
  340. }
  341. if req.ChartClassifyName == "" {
  342. br.Msg = "请输入分类名称"
  343. br.IsSendEmail = false
  344. return
  345. }
  346. if req.ParentId < 0 {
  347. br.Msg = "参数错误"
  348. br.IsSendEmail = false
  349. return
  350. }
  351. // 新增图表分类
  352. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_DEFAULT, req.IsSelected, this.Lang, this.SysUser)
  353. if err != nil {
  354. br.Msg = errMsg
  355. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  356. br.IsSendEmail = isSendEmail
  357. return
  358. }
  359. br.Ret = 200
  360. br.Msg = "保存成功"
  361. br.Success = true
  362. }
  363. // EditChartClassify
  364. // @Title 修改图表分类
  365. // @Description 修改图表分类接口
  366. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  367. // @Success 200 Ret=200 修改成功
  368. // @router /chart_classify/edit [post]
  369. func (this *ChartClassifyController) EditChartClassify() {
  370. br := new(models.BaseResponse).Init()
  371. defer func() {
  372. this.Data["json"] = br
  373. this.ServeJSON()
  374. }()
  375. var req data_manage.EditChartClassifyReq
  376. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  377. if err != nil {
  378. br.Msg = "参数解析异常!"
  379. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  380. return
  381. }
  382. if req.ChartClassifyName == "" {
  383. br.Msg = "请输入分类名称"
  384. br.IsSendEmail = false
  385. return
  386. }
  387. if req.ChartClassifyId <= 0 {
  388. br.Msg = "参数错误"
  389. br.IsSendEmail = false
  390. return
  391. }
  392. // 编辑图表分类
  393. classifyInfo, isDeleteForumChart, err, errMsg, isSendEmail := data.EditChartClassifyV2(req.ChartClassifyId, req.ParentId, utils.CHART_SOURCE_DEFAULT, req.ChartClassifyName, req.IsSelected, this.Lang)
  394. if err != nil {
  395. br.Msg = errMsg
  396. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  397. br.IsSendEmail = isSendEmail
  398. return
  399. }
  400. // 移除精选后,删除所有的图表
  401. if isDeleteForumChart {
  402. go eta_forum.ChartInfoDeleteBatch(classifyInfo, this.SysUser)
  403. }
  404. br.Ret = 200
  405. br.Msg = "保存成功"
  406. br.Success = true
  407. br.IsAddLog = true
  408. }
  409. // @Title 删除图表检测接口
  410. // @Description 删除图表检测接口
  411. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  412. // @Success 200 Ret=200 检测成功
  413. // @router /chart_classify/delete/check [post]
  414. func (this *ChartClassifyController) DeleteChartClassifyCheck() {
  415. br := new(models.BaseResponse).Init()
  416. defer func() {
  417. this.Data["json"] = br
  418. this.ServeJSON()
  419. }()
  420. var req data_manage.ChartClassifyDeleteCheckReq
  421. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  422. if err != nil {
  423. br.Msg = "参数解析异常!"
  424. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  425. return
  426. }
  427. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  428. br.Msg = "参数错误"
  429. br.IsSendEmail = false
  430. return
  431. }
  432. var deleteStatus int
  433. var tipsMsg string
  434. //删除分类
  435. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  436. // 查找分类
  437. item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  438. if err != nil {
  439. br.Msg = "保存失败"
  440. br.Msg = "获取分类信息失败,Err:" + err.Error()
  441. return
  442. }
  443. // 已授权分类id
  444. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  445. if err != nil {
  446. br.Msg = "获取失败"
  447. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  448. return
  449. }
  450. // 权限校验
  451. {
  452. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  453. button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  454. if !button.OpButton {
  455. br.Msg = "无操作权限"
  456. br.IsSendEmail = false
  457. return
  458. }
  459. }
  460. //判断图表分类下,是否含有图表
  461. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  462. if err != nil {
  463. br.Msg = "删除失败"
  464. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  465. return
  466. }
  467. if count > 0 {
  468. deleteStatus = 1
  469. tipsMsg = "该分类下关联图表不可删除"
  470. }
  471. }
  472. if deleteStatus != 1 && req.ChartInfoId == 0 {
  473. classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  474. if err != nil && !utils.IsErrNoRow(err) {
  475. br.Msg = "删除失败"
  476. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  477. return
  478. }
  479. if classifyCount > 0 {
  480. deleteStatus = 2
  481. tipsMsg = "确认删除当前目录及包含的子目录吗"
  482. }
  483. }
  484. if deleteStatus == 0 {
  485. tipsMsg = "可删除,进行删除操作"
  486. }
  487. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  488. resp.DeleteStatus = deleteStatus
  489. resp.TipsMsg = tipsMsg
  490. br.Ret = 200
  491. br.Msg = "检测成功"
  492. br.Success = true
  493. br.Data = resp
  494. }
  495. // @Title 删除图表分类/图表
  496. // @Description 删除图表分类/图表接口
  497. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  498. // @Success 200 Ret=200 删除成功
  499. // @router /chart_classify/delete [post]
  500. func (this *ChartClassifyController) DeleteChartClassify() {
  501. br := new(models.BaseResponse).Init()
  502. defer func() {
  503. this.Data["json"] = br
  504. this.ServeJSON()
  505. }()
  506. sysUser := this.SysUser
  507. if sysUser == nil {
  508. br.Msg = "请登录"
  509. br.ErrMsg = "请登录,SysUser Is Empty"
  510. br.Ret = 408
  511. return
  512. }
  513. var req data_manage.DeleteChartClassifyReq
  514. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  515. if err != nil {
  516. br.Msg = "参数解析异常!"
  517. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  518. return
  519. }
  520. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  521. br.Msg = "参数错误"
  522. br.IsSendEmail = false
  523. return
  524. }
  525. //删除分类
  526. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  527. // 查找分类
  528. item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  529. if err != nil {
  530. br.Msg = "保存失败"
  531. br.Msg = "获取分类信息失败,Err:" + err.Error()
  532. return
  533. }
  534. // 已授权分类id
  535. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  536. if err != nil {
  537. br.Msg = "获取失败"
  538. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  539. return
  540. }
  541. // 权限校验
  542. {
  543. haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  544. button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  545. if !button.OpButton {
  546. br.Msg = "无操作权限"
  547. br.IsSendEmail = false
  548. return
  549. }
  550. }
  551. //判断是否含有指标
  552. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  553. if err != nil && !utils.IsErrNoRow(err) {
  554. br.Msg = "删除失败"
  555. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  556. return
  557. }
  558. if count > 0 {
  559. br.Msg = "该目录下存在关联指标,不可删除"
  560. br.IsSendEmail = false
  561. return
  562. }
  563. err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  564. if err != nil {
  565. br.Msg = "删除失败"
  566. br.ErrMsg = "删除失败,Err:" + err.Error()
  567. return
  568. }
  569. }
  570. resp := new(data_manage.AddChartInfoResp)
  571. //删除图表
  572. if req.ChartInfoId > 0 {
  573. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  574. if err != nil {
  575. if utils.IsErrNoRow(err) {
  576. br.Msg = "图表已删除,请刷新页面"
  577. br.ErrMsg = "指标不存在,Err:" + err.Error()
  578. return
  579. } else {
  580. br.Msg = "删除失败"
  581. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  582. return
  583. }
  584. }
  585. if chartInfo == nil {
  586. br.Msg = "图表已删除,请刷新页面"
  587. return
  588. }
  589. chartClassifyItem, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  590. if err != nil {
  591. br.Msg = "获取失败"
  592. br.ErrMsg = "获取图表分类详情数据失败,Err:" + err.Error()
  593. return
  594. }
  595. // 已授权图表、分类id
  596. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  597. if err != nil {
  598. br.Msg = "获取失败"
  599. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  600. return
  601. }
  602. // 权限校验
  603. {
  604. haveOperaAuth := data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassifyItem.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  605. //图表操作权限
  606. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, haveOperaAuth)
  607. if !ok {
  608. br.Msg = "没有该图表的操作权限"
  609. br.ErrMsg = "没有该图表的操作权限"
  610. return
  611. }
  612. }
  613. // 获取引用该图表的MyCharts, 用于ES删除
  614. var myCond string
  615. var myPars []interface{}
  616. myCond += ` AND a.chart_info_id = ? `
  617. myPars = append(myPars, req.ChartInfoId)
  618. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  619. if e != nil {
  620. br.Msg = "删除失败"
  621. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  622. return
  623. }
  624. myIds := make([]int, 0)
  625. for _, m := range myCharts {
  626. myIds = append(myIds, m.MyChartId)
  627. }
  628. //删除图表及关联指标
  629. err = data_manage.DeleteChartInfoAndData(req.ChartInfoId)
  630. if err != nil {
  631. br.Msg = "删除失败"
  632. br.ErrMsg = "删除失败,Err:" + err.Error()
  633. return
  634. }
  635. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  636. err = data_manage.DeleteChartSeriesAndEdbMapping(req.ChartInfoId)
  637. if err != nil {
  638. br.Msg = "删除失败"
  639. br.ErrMsg = "删除失败,Err:" + err.Error()
  640. return
  641. }
  642. }
  643. //删除ES
  644. {
  645. go data.EsDeleteChartInfo(req.ChartInfoId)
  646. // 删除MY ETA 图表 es数据
  647. //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId)
  648. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  649. }
  650. var condition string
  651. var pars []interface{}
  652. condition += " AND chart_classify_id=? AND source = ? "
  653. pars = append(pars, chartInfo.ChartClassifyId, utils.CHART_SOURCE_DEFAULT)
  654. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  655. pars = append(pars, req.ChartInfoId)
  656. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  657. if err != nil && !utils.IsErrNoRow(err) {
  658. br.Msg = "删除失败"
  659. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  660. return
  661. }
  662. if nextItem != nil {
  663. resp.UniqueCode = nextItem.UniqueCode
  664. resp.ChartInfoId = nextItem.ChartInfoId
  665. } else {
  666. var condition string
  667. var pars []interface{}
  668. condition += " AND level=3 "
  669. //pars = append(pars, chartInfo.ChartClassifyId)
  670. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  671. pars = append(pars, chartInfo.ChartClassifyId)
  672. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  673. if err != nil && !utils.IsErrNoRow(err) {
  674. br.Msg = "删除失败"
  675. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  676. return
  677. }
  678. if classifyItem != nil {
  679. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  680. if err != nil && !utils.IsErrNoRow(err) {
  681. br.Msg = "删除失败"
  682. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  683. return
  684. }
  685. if nextItem != nil {
  686. resp.UniqueCode = nextItem.UniqueCode
  687. resp.ChartInfoId = nextItem.ChartInfoId
  688. }
  689. }
  690. }
  691. // 删除图表中的指标引用
  692. _ = data_manage.DeleteEdbRelationByObjectId(req.ChartInfoId, utils.EDB_RELATION_CHART)
  693. //新增操作日志
  694. {
  695. chartLog := new(data_manage.ChartInfoLog)
  696. chartLog.ChartName = chartInfo.ChartName
  697. chartLog.ChartInfoId = req.ChartInfoId
  698. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  699. chartLog.SysUserId = sysUser.AdminId
  700. chartLog.SysUserRealName = sysUser.RealName
  701. chartLog.UniqueCode = chartInfo.UniqueCode
  702. chartLog.CreateTime = time.Now()
  703. chartLog.Content = string(this.Ctx.Input.RequestBody)
  704. chartLog.Status = "删除图表"
  705. chartLog.Method = this.Ctx.Input.URI()
  706. go data_manage.AddChartInfoLog(chartLog)
  707. }
  708. }
  709. br.Ret = 200
  710. br.Msg = "删除成功"
  711. br.Success = true
  712. br.Data = resp
  713. br.IsAddLog = true
  714. }
  715. // ChartClassifyMove
  716. // @Title 图表分类移动接口
  717. // @Description 图表分类移动接口
  718. // @Success 200 {object} data_manage.MoveChartClassifyReq
  719. // @router /chart_classify/move [post]
  720. func (this *ChartClassifyController) ChartClassifyMove() {
  721. br := new(models.BaseResponse).Init()
  722. defer func() {
  723. if br.ErrMsg == "" {
  724. br.IsSendEmail = false
  725. }
  726. this.Data["json"] = br
  727. this.ServeJSON()
  728. }()
  729. sysUser := this.SysUser
  730. if sysUser == nil {
  731. br.Msg = "请登录"
  732. br.ErrMsg = "请登录,SysUser Is Empty"
  733. br.Ret = 408
  734. return
  735. }
  736. var req data_manage.MoveChartClassifyReq
  737. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  738. if err != nil {
  739. br.Msg = "参数解析异常!"
  740. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  741. return
  742. }
  743. if req.ClassifyId <= 0 {
  744. br.Msg = "参数错误"
  745. br.ErrMsg = "分类id小于等于0"
  746. return
  747. }
  748. //判断分类是否存在
  749. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  750. if err != nil {
  751. if utils.IsErrNoRow(err) {
  752. br.Msg = "分类不存在,请刷新页面"
  753. return
  754. }
  755. br.Msg = "移动失败"
  756. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  757. return
  758. }
  759. // 校验移动的父级目录下是否有重名分类
  760. exists, e := data_manage.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  761. if e != nil && !utils.IsErrNoRow(e) {
  762. br.Msg = "移动失败"
  763. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  764. return
  765. }
  766. if exists != nil && exists.ChartClassifyId > 0 {
  767. br.Msg = "移动失败,分类名称已存在"
  768. return
  769. }
  770. // 已授权分类id
  771. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, chartClassifyInfo.ChartClassifyId)
  772. if err != nil {
  773. br.Msg = "获取失败"
  774. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  775. return
  776. }
  777. // 权限校验
  778. {
  779. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
  780. button := data.GetChartClassifyOpButton(this.SysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
  781. if !button.OpButton {
  782. br.Msg = "无操作权限"
  783. br.IsSendEmail = false
  784. return
  785. }
  786. }
  787. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  788. br.Msg = "分类异常"
  789. br.ErrMsg = "分类异常,不是ETA图库的分类"
  790. return
  791. }
  792. updateCol := make([]string, 0)
  793. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  794. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  795. parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  796. if err != nil {
  797. br.Msg = "移动失败"
  798. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  799. return
  800. }
  801. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  802. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  803. chartClassifyInfo.ModifyTime = time.Now()
  804. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  805. }
  806. //如果有传入 上一个兄弟节点分类id
  807. if req.PrevClassifyId > 0 {
  808. //上一个兄弟节点
  809. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  810. if err != nil {
  811. br.Msg = "移动失败"
  812. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  813. return
  814. }
  815. //如果是移动在两个兄弟节点之间
  816. if req.NextClassifyId > 0 {
  817. //下一个兄弟节点
  818. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  819. if err != nil {
  820. br.Msg = "移动失败"
  821. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  822. return
  823. }
  824. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  825. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  826. //变更兄弟节点的排序
  827. updateSortStr := `sort + 2`
  828. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  829. } else {
  830. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  831. if nextClassify.Sort-prevClassify.Sort == 1 {
  832. //变更兄弟节点的排序
  833. updateSortStr := `sort + 1`
  834. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  835. }
  836. }
  837. }
  838. chartClassifyInfo.Sort = prevClassify.Sort + 1
  839. chartClassifyInfo.ModifyTime = time.Now()
  840. updateCol = append(updateCol, "Sort", "ModifyTime")
  841. } else {
  842. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  843. if err != nil && !utils.IsErrNoRow(err) {
  844. br.Msg = "移动失败"
  845. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  846. return
  847. }
  848. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  849. if firstClassify != nil && firstClassify.Sort == 0 {
  850. updateSortStr := ` sort + 1 `
  851. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  852. }
  853. chartClassifyInfo.Sort = 0 //那就是排在第一位
  854. chartClassifyInfo.ModifyTime = time.Now()
  855. updateCol = append(updateCol, "Sort", "ModifyTime")
  856. }
  857. //更新
  858. if len(updateCol) > 0 {
  859. err = chartClassifyInfo.Update(updateCol)
  860. if err != nil {
  861. br.Msg = "移动失败"
  862. br.ErrMsg = "修改失败,Err:" + err.Error()
  863. return
  864. }
  865. }
  866. br.Ret = 200
  867. br.Success = true
  868. br.Msg = "移动成功"
  869. }
  870. // getChartClassifyListForMe 获取我创建的图表分类
  871. func getChartClassifyListForMeV2(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  872. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  873. if err != nil && !utils.IsErrNoRow(err) {
  874. errMsg = "获取失败"
  875. return
  876. }
  877. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  878. if err != nil && !utils.IsErrNoRow(err) {
  879. errMsg = "获取失败"
  880. return
  881. }
  882. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  883. for _, v := range classifyAll {
  884. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  885. }
  886. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  887. for _, v := range rootList {
  888. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  889. v.Children = existItems
  890. } else {
  891. items := make([]*data_manage.ChartClassifyItems, 0)
  892. v.Children = items
  893. }
  894. nodeAll = append(nodeAll, v)
  895. }
  896. resp.AllNodes = nodeAll
  897. return
  898. }
  899. // ChartClassifyChartListV2
  900. // @Title 根据图表分类获取图表列表
  901. // @Description 根据图表分类获取图表列表接口
  902. // @Param IsShowMe query bool true "是否只看我的,true、false"
  903. // @Param ChartClassifyId query bool true "图片分类id"
  904. // @Success 200 {object} data_manage.ChartClassifyListResp
  905. // @router /chart_classify/chart/list [get]
  906. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  907. br := new(models.BaseResponse).Init()
  908. defer func() {
  909. this.Data["json"] = br
  910. this.ServeJSON()
  911. }()
  912. sysUser := this.SysUser
  913. if sysUser == nil {
  914. br.Msg = "请登录"
  915. br.ErrMsg = "请登录,SysUser Is Empty"
  916. br.Ret = 408
  917. return
  918. }
  919. resp := new(data_manage.ChartClassifyListResp)
  920. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  921. if chartClassifyId <= 0 {
  922. br.Msg = "参数错误"
  923. return
  924. }
  925. // 获取当前账号的不可见指标
  926. noPermissionChartIdMap := make(map[int]bool)
  927. {
  928. obj := data_manage.EdbInfoNoPermissionAdmin{}
  929. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  930. if err != nil && !utils.IsErrNoRow(err) {
  931. br.Msg = "获取失败"
  932. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  933. return
  934. }
  935. for _, v := range confList {
  936. noPermissionChartIdMap[v.ChartInfoId] = true
  937. }
  938. }
  939. isShowMe, _ := this.GetBool("IsShowMe")
  940. if isShowMe {
  941. allChartInfo, err := data_manage.GetChartInfoByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, sysUser.AdminId, chartClassifyId)
  942. if err != nil && !utils.IsErrNoRow(err) {
  943. br.Msg = "获取失败"
  944. br.ErrMsg = "获取全部数据失败,Err:" + err.Error()
  945. return
  946. }
  947. // 移除没有权限的图表
  948. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  949. resp.AllNodes = allNodes
  950. br.Ret = 200
  951. br.Success = true
  952. br.Msg = "获取成功"
  953. br.Data = resp
  954. fmt.Println("source my classify")
  955. return
  956. }
  957. allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  958. if err != nil && !utils.IsErrNoRow(err) {
  959. br.Msg = "获取失败"
  960. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  961. return
  962. }
  963. // 移除没有权限的图表
  964. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  965. for k, item := range allNodes {
  966. item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  967. item.Button.AddButton = false
  968. item.Button.OpButton = false
  969. item.Button.DeleteButton = false
  970. allNodes[k] = item
  971. }
  972. resp.AllNodes = allNodes
  973. br.Ret = 200
  974. br.Success = true
  975. br.Msg = "获取成功"
  976. br.Data = resp
  977. }
  978. // ChartClassifyChartListV3
  979. // @Title 根据图表分类获取图表列表-包含分类和图表
  980. // @Description 根据图表分类获取图表列表接口-包含分类和图表
  981. // @Param IsShowMe query bool true "是否只看我的,true、false"
  982. // @Param ChartClassifyId query bool true "图片分类id"
  983. // @Success 200 {object} data_manage.ChartClassifyListResp
  984. // @router /chart_classify/chart/listV2 [get]
  985. func (this *ChartClassifyController) ChartClassifyChartListV3() {
  986. br := new(models.BaseResponse).Init()
  987. defer func() {
  988. this.Data["json"] = br
  989. this.ServeJSON()
  990. }()
  991. sysUser := this.SysUser
  992. if sysUser == nil {
  993. br.Msg = "请登录"
  994. br.ErrMsg = "请登录,SysUser Is Empty"
  995. br.Ret = 408
  996. return
  997. }
  998. resp := new(data_manage.ChartClassifyListResp)
  999. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1000. if chartClassifyId < 0 {
  1001. br.Msg = "参数错误"
  1002. return
  1003. }
  1004. // 获取当前账号的不可见指标
  1005. noPermissionChartIdMap := make(map[int]bool)
  1006. {
  1007. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1008. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1009. if err != nil && !utils.IsErrNoRow(err) {
  1010. br.Msg = "获取失败"
  1011. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. for _, v := range confList {
  1015. noPermissionChartIdMap[v.ChartInfoId] = true
  1016. }
  1017. }
  1018. var allNodes []*data_manage.ChartClassifyItems
  1019. // 获取是否精选资源标识
  1020. isSelected, _ := this.GetInt("IsSelected")
  1021. isShowMe, _ := this.GetBool("IsShowMe")
  1022. if isShowMe {
  1023. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentIdForMe(chartClassifyId, sysUser.AdminId, isSelected)
  1024. if err != nil && !utils.IsErrNoRow(err) {
  1025. br.Msg = "获取失败"
  1026. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. // 移除没有权限的图表
  1030. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1031. allNodes, err = data.GetChartClassifyByIsMe(sysUser.AdminId, chartClassifyId, utils.CHART_SOURCE_DEFAULT, allNodes)
  1032. if err != nil {
  1033. br.Msg = "获取失败"
  1034. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1035. return
  1036. }
  1037. //resp.AllNodes = allNodes
  1038. //
  1039. //br.Ret = 200
  1040. //br.Success = true
  1041. //br.Msg = "获取成功"
  1042. //br.Data = resp
  1043. //fmt.Println("source my classify")
  1044. //return
  1045. } else {
  1046. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentId(chartClassifyId, isSelected)
  1047. if err != nil && err.Error() != utils.ErrNoRow() {
  1048. br.Msg = "获取失败"
  1049. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1050. return
  1051. }
  1052. //allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  1053. //if err != nil && err.Error() != utils.ErrNoRow() {
  1054. // br.Msg = "获取失败"
  1055. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1056. // return
  1057. //}
  1058. // 移除没有权限的图表
  1059. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1060. }
  1061. menulist, e := system.GetMenuButtonsByRoleId(this.SysUser.RoleId)
  1062. if e != nil {
  1063. br.Msg = "获取失败"
  1064. br.ErrMsg = "获取角色按钮权限失败, Err: " + e.Error()
  1065. return
  1066. }
  1067. buttonList := make(map[string]int, 0)
  1068. for _, item := range menulist {
  1069. if item.MenuType == 1 {
  1070. buttonList[item.ButtonCode] = 1
  1071. }
  1072. }
  1073. var addOrEditRight, deleteRight, moveRight bool
  1074. if _, ok := buttonList[CHART_CLASSIFY_ADD_OR_EDIT]; ok {
  1075. addOrEditRight = true
  1076. }
  1077. if _, ok := buttonList[CHART_CLASSIFY_DELETE]; ok {
  1078. deleteRight = true
  1079. }
  1080. if _, ok := buttonList[CHART_CLASSIFY_MOVE]; ok {
  1081. moveRight = true
  1082. }
  1083. for k, item := range allNodes {
  1084. //item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  1085. item.Button = data.GetChartOpButtonV2(item.HaveOperaAuth, addOrEditRight, deleteRight, moveRight)
  1086. if item.ChartInfoId > 0 {
  1087. item.Button.AddButton = false
  1088. item.Button.OpButton = false
  1089. item.Button.DeleteButton = false
  1090. item.Button.MoveButton = true
  1091. } else if item.Level == 6 {
  1092. item.Button.AddButton = false
  1093. }
  1094. allNodes[k] = item
  1095. }
  1096. resp.AllNodes = allNodes
  1097. br.Ret = 200
  1098. br.Success = true
  1099. br.Msg = "获取成功"
  1100. br.Data = resp
  1101. }
  1102. // SetChartClassifyResourceStatus
  1103. // @Title 一键从资源库上架/下架
  1104. // @Description 一键从资源库上架/下架
  1105. // @Param ChartClassifyId query bool true "图片分类id"
  1106. // @Param ResourceStatus query bool true "资源状态"
  1107. // @Success 200 {object} models.BaseResponse
  1108. // @router /chart_classify/resource_status [post]
  1109. func (this *ChartClassifyController) SetChartClassifyResourceStatus() {
  1110. br := new(models.BaseResponse).Init()
  1111. defer func() {
  1112. this.Data["json"] = br
  1113. this.ServeJSON()
  1114. }()
  1115. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1116. if chartClassifyId <= 0 {
  1117. br.Msg = "参数错误"
  1118. return
  1119. }
  1120. resourceStatus, _ := this.GetInt("ResourceStatus")
  1121. if resourceStatus <= 0 {
  1122. br.Msg = "参数错误"
  1123. return
  1124. }
  1125. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1126. if err != nil {
  1127. br.Msg = "获取失败"
  1128. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1129. return
  1130. }
  1131. if resourceStatus == utils.ChartClassifyResourceStatusDown {
  1132. errMsg, err := eta_forum.SetChartClassifyResourceStatusDown(chartClassifyInfo, this.SysUser)
  1133. if err != nil {
  1134. if errMsg != "" {
  1135. br.Msg = errMsg
  1136. br.ErrMsg = err.Error()
  1137. return
  1138. }
  1139. br.Msg = "操作失败"
  1140. br.ErrMsg = err.Error()
  1141. return
  1142. }
  1143. } else if resourceStatus == utils.ChartClassifyResourceStatusUp {
  1144. errMsg, err := eta_forum.SetChartClassifyResourceStatusUp(chartClassifyInfo, this.SysUser)
  1145. if err != nil {
  1146. if errMsg != "" {
  1147. br.Msg = errMsg
  1148. br.ErrMsg = err.Error()
  1149. return
  1150. }
  1151. br.Msg = "操作失败"
  1152. br.ErrMsg = err.Error()
  1153. return
  1154. }
  1155. }
  1156. br.Ret = 200
  1157. br.Success = true
  1158. br.Msg = "操作成功"
  1159. }
  1160. // 一键更新至资源库
  1161. // @Title 一键更新至资源库
  1162. // @Description 一键更新至资源库
  1163. // @Param ChartClassifyId query bool true "图片分类id"
  1164. // @Success 200 {object} models.BaseResponse
  1165. // @router /chart_classify/forum_chart/update [post]
  1166. func (this *ChartClassifyController) UpdateChartClassifyResource() {
  1167. br := new(models.BaseResponse).Init()
  1168. defer func() {
  1169. this.Data["json"] = br
  1170. this.ServeJSON()
  1171. }()
  1172. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1173. if chartClassifyId <= 0 {
  1174. br.Msg = "参数错误"
  1175. return
  1176. }
  1177. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1178. if err != nil {
  1179. br.Msg = "获取失败"
  1180. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  1184. br.Msg = "分类来源错误"
  1185. return
  1186. }
  1187. if chartClassifyInfo.IsSelected != utils.ChartClassifyIsSelected {
  1188. br.Msg = "该分类不是精选分类"
  1189. return
  1190. }
  1191. err = eta_forum.ChartInfoSaveBatch(chartClassifyInfo, this.SysUser)
  1192. if err != nil {
  1193. br.Msg = "操作失败"
  1194. br.ErrMsg = err.Error()
  1195. return
  1196. }
  1197. br.Ret = 200
  1198. br.Success = true
  1199. br.Msg = "操作成功"
  1200. }