chart_classify.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. if req.ChartClassifyId == 0 && req.ChartInfoId > 0 {
  488. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  489. if err != nil {
  490. if utils.IsErrNoRow(err) {
  491. br.Msg = "图表已删除,请刷新页面"
  492. br.ErrMsg = "指标不存在,Err:" + err.Error()
  493. return
  494. }
  495. br.Msg = "删除失败"
  496. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  497. return
  498. }
  499. if chartInfo.ForumChartInfoId > 0 {
  500. deleteStatus = 3
  501. tipsMsg = "删除后,该图表将从ETA投研资源库同步删除,影响客户的查看权限,是否确认删除?"
  502. }
  503. }
  504. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  505. resp.DeleteStatus = deleteStatus
  506. resp.TipsMsg = tipsMsg
  507. br.Ret = 200
  508. br.Msg = "检测成功"
  509. br.Success = true
  510. br.Data = resp
  511. }
  512. // @Title 删除图表分类/图表
  513. // @Description 删除图表分类/图表接口
  514. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  515. // @Success 200 Ret=200 删除成功
  516. // @router /chart_classify/delete [post]
  517. func (this *ChartClassifyController) DeleteChartClassify() {
  518. br := new(models.BaseResponse).Init()
  519. defer func() {
  520. this.Data["json"] = br
  521. this.ServeJSON()
  522. }()
  523. sysUser := this.SysUser
  524. if sysUser == nil {
  525. br.Msg = "请登录"
  526. br.ErrMsg = "请登录,SysUser Is Empty"
  527. br.Ret = 408
  528. return
  529. }
  530. var req data_manage.DeleteChartClassifyReq
  531. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  532. if err != nil {
  533. br.Msg = "参数解析异常!"
  534. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  535. return
  536. }
  537. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  538. br.Msg = "参数错误"
  539. br.IsSendEmail = false
  540. return
  541. }
  542. //删除分类
  543. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  544. // 查找分类
  545. item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  546. if err != nil {
  547. br.Msg = "保存失败"
  548. br.Msg = "获取分类信息失败,Err:" + err.Error()
  549. return
  550. }
  551. // 已授权分类id
  552. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  553. if err != nil {
  554. br.Msg = "获取失败"
  555. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  556. return
  557. }
  558. // 权限校验
  559. {
  560. haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  561. button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  562. if !button.OpButton {
  563. br.Msg = "无操作权限"
  564. br.IsSendEmail = false
  565. return
  566. }
  567. }
  568. //判断是否含有指标
  569. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  570. if err != nil && !utils.IsErrNoRow(err) {
  571. br.Msg = "删除失败"
  572. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  573. return
  574. }
  575. if count > 0 {
  576. br.Msg = "该目录下存在关联指标,不可删除"
  577. br.IsSendEmail = false
  578. return
  579. }
  580. err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  581. if err != nil {
  582. br.Msg = "删除失败"
  583. br.ErrMsg = "删除失败,Err:" + err.Error()
  584. return
  585. }
  586. }
  587. resp := new(data_manage.AddChartInfoResp)
  588. //删除图表
  589. if req.ChartInfoId > 0 {
  590. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  591. if err != nil {
  592. if utils.IsErrNoRow(err) {
  593. br.Msg = "图表已删除,请刷新页面"
  594. br.ErrMsg = "指标不存在,Err:" + err.Error()
  595. return
  596. } else {
  597. br.Msg = "删除失败"
  598. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  599. return
  600. }
  601. }
  602. if chartInfo == nil {
  603. br.Msg = "图表已删除,请刷新页面"
  604. return
  605. }
  606. chartClassifyItem, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  607. if err != nil {
  608. br.Msg = "获取失败"
  609. br.ErrMsg = "获取图表分类详情数据失败,Err:" + err.Error()
  610. return
  611. }
  612. // 已授权图表、分类id
  613. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  614. if err != nil {
  615. br.Msg = "获取失败"
  616. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  617. return
  618. }
  619. // 权限校验
  620. {
  621. haveOperaAuth := data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassifyItem.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  622. //图表操作权限
  623. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, haveOperaAuth)
  624. if !ok {
  625. br.Msg = "没有该图表的操作权限"
  626. br.ErrMsg = "没有该图表的操作权限"
  627. return
  628. }
  629. }
  630. // 获取引用该图表的MyCharts, 用于ES删除
  631. var myCond string
  632. var myPars []interface{}
  633. myCond += ` AND a.chart_info_id = ? `
  634. myPars = append(myPars, req.ChartInfoId)
  635. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  636. if e != nil {
  637. br.Msg = "删除失败"
  638. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  639. return
  640. }
  641. myIds := make([]int, 0)
  642. for _, m := range myCharts {
  643. myIds = append(myIds, m.MyChartId)
  644. }
  645. //删除图表及关联指标
  646. err = data_manage.DeleteChartInfoAndData(req.ChartInfoId)
  647. if err != nil {
  648. br.Msg = "删除失败"
  649. br.ErrMsg = "删除失败,Err:" + err.Error()
  650. return
  651. }
  652. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  653. err = data_manage.DeleteChartSeriesAndEdbMapping(req.ChartInfoId)
  654. if err != nil {
  655. br.Msg = "删除失败"
  656. br.ErrMsg = "删除失败,Err:" + err.Error()
  657. return
  658. }
  659. }
  660. //删除ES
  661. {
  662. go data.EsDeleteChartInfo(req.ChartInfoId)
  663. // 删除MY ETA 图表 es数据
  664. //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId)
  665. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  666. if chartInfo.ForumChartInfoId > 0 {
  667. go eta_forum.DeleteChartByForumChartInfoId(chartInfo.ForumChartInfoId)
  668. }
  669. }
  670. var condition string
  671. var pars []interface{}
  672. condition += " AND chart_classify_id=? AND source = ? "
  673. pars = append(pars, chartInfo.ChartClassifyId, utils.CHART_SOURCE_DEFAULT)
  674. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  675. pars = append(pars, req.ChartInfoId)
  676. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  677. if err != nil && !utils.IsErrNoRow(err) {
  678. br.Msg = "删除失败"
  679. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  680. return
  681. }
  682. if nextItem != nil {
  683. resp.UniqueCode = nextItem.UniqueCode
  684. resp.ChartInfoId = nextItem.ChartInfoId
  685. } else {
  686. var condition string
  687. var pars []interface{}
  688. condition += " AND level=3 "
  689. //pars = append(pars, chartInfo.ChartClassifyId)
  690. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  691. pars = append(pars, chartInfo.ChartClassifyId)
  692. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  693. if err != nil && !utils.IsErrNoRow(err) {
  694. br.Msg = "删除失败"
  695. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  696. return
  697. }
  698. if classifyItem != nil {
  699. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  700. if err != nil && !utils.IsErrNoRow(err) {
  701. br.Msg = "删除失败"
  702. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  703. return
  704. }
  705. if nextItem != nil {
  706. resp.UniqueCode = nextItem.UniqueCode
  707. resp.ChartInfoId = nextItem.ChartInfoId
  708. }
  709. }
  710. }
  711. // 删除图表中的指标引用
  712. _ = data_manage.DeleteEdbRelationByObjectId(req.ChartInfoId, utils.EDB_RELATION_CHART)
  713. //新增操作日志
  714. {
  715. chartLog := new(data_manage.ChartInfoLog)
  716. chartLog.ChartName = chartInfo.ChartName
  717. chartLog.ChartInfoId = req.ChartInfoId
  718. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  719. chartLog.SysUserId = sysUser.AdminId
  720. chartLog.SysUserRealName = sysUser.RealName
  721. chartLog.UniqueCode = chartInfo.UniqueCode
  722. chartLog.CreateTime = time.Now()
  723. chartLog.Content = string(this.Ctx.Input.RequestBody)
  724. chartLog.Status = "删除图表"
  725. chartLog.Method = this.Ctx.Input.URI()
  726. go data_manage.AddChartInfoLog(chartLog)
  727. }
  728. }
  729. br.Ret = 200
  730. br.Msg = "删除成功"
  731. br.Success = true
  732. br.Data = resp
  733. br.IsAddLog = true
  734. }
  735. // ChartClassifyMove
  736. // @Title 图表分类移动接口
  737. // @Description 图表分类移动接口
  738. // @Success 200 {object} data_manage.MoveChartClassifyReq
  739. // @router /chart_classify/move [post]
  740. func (this *ChartClassifyController) ChartClassifyMove() {
  741. br := new(models.BaseResponse).Init()
  742. defer func() {
  743. if br.ErrMsg == "" {
  744. br.IsSendEmail = false
  745. }
  746. this.Data["json"] = br
  747. this.ServeJSON()
  748. }()
  749. sysUser := this.SysUser
  750. if sysUser == nil {
  751. br.Msg = "请登录"
  752. br.ErrMsg = "请登录,SysUser Is Empty"
  753. br.Ret = 408
  754. return
  755. }
  756. var req data_manage.MoveChartClassifyReq
  757. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  758. if err != nil {
  759. br.Msg = "参数解析异常!"
  760. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  761. return
  762. }
  763. if req.ClassifyId <= 0 {
  764. br.Msg = "参数错误"
  765. br.ErrMsg = "分类id小于等于0"
  766. return
  767. }
  768. //判断分类是否存在
  769. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  770. if err != nil {
  771. if utils.IsErrNoRow(err) {
  772. br.Msg = "分类不存在,请刷新页面"
  773. return
  774. }
  775. br.Msg = "移动失败"
  776. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  777. return
  778. }
  779. // 校验移动的父级目录下是否有重名分类
  780. exists, e := data_manage.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  781. if e != nil && !utils.IsErrNoRow(e) {
  782. br.Msg = "移动失败"
  783. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  784. return
  785. }
  786. if exists != nil && exists.ChartClassifyId > 0 {
  787. br.Msg = "移动失败,分类名称已存在"
  788. return
  789. }
  790. // 已授权分类id
  791. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, chartClassifyInfo.ChartClassifyId)
  792. if err != nil {
  793. br.Msg = "获取失败"
  794. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  795. return
  796. }
  797. // 权限校验
  798. {
  799. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
  800. button := data.GetChartClassifyOpButton(this.SysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
  801. if !button.OpButton {
  802. br.Msg = "无操作权限"
  803. br.IsSendEmail = false
  804. return
  805. }
  806. }
  807. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  808. br.Msg = "分类异常"
  809. br.ErrMsg = "分类异常,不是ETA图库的分类"
  810. return
  811. }
  812. updateCol := make([]string, 0)
  813. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  814. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  815. parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  816. if err != nil {
  817. br.Msg = "移动失败"
  818. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  819. return
  820. }
  821. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  822. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  823. chartClassifyInfo.ModifyTime = time.Now()
  824. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  825. }
  826. //如果有传入 上一个兄弟节点分类id
  827. if req.PrevClassifyId > 0 {
  828. //上一个兄弟节点
  829. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  830. if err != nil {
  831. br.Msg = "移动失败"
  832. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  833. return
  834. }
  835. //如果是移动在两个兄弟节点之间
  836. if req.NextClassifyId > 0 {
  837. //下一个兄弟节点
  838. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  839. if err != nil {
  840. br.Msg = "移动失败"
  841. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  842. return
  843. }
  844. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  845. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  846. //变更兄弟节点的排序
  847. updateSortStr := `sort + 2`
  848. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  849. } else {
  850. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  851. if nextClassify.Sort-prevClassify.Sort == 1 {
  852. //变更兄弟节点的排序
  853. updateSortStr := `sort + 1`
  854. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  855. }
  856. }
  857. }
  858. chartClassifyInfo.Sort = prevClassify.Sort + 1
  859. chartClassifyInfo.ModifyTime = time.Now()
  860. updateCol = append(updateCol, "Sort", "ModifyTime")
  861. } else {
  862. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  863. if err != nil && !utils.IsErrNoRow(err) {
  864. br.Msg = "移动失败"
  865. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  866. return
  867. }
  868. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  869. if firstClassify != nil && firstClassify.Sort == 0 {
  870. updateSortStr := ` sort + 1 `
  871. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  872. }
  873. chartClassifyInfo.Sort = 0 //那就是排在第一位
  874. chartClassifyInfo.ModifyTime = time.Now()
  875. updateCol = append(updateCol, "Sort", "ModifyTime")
  876. }
  877. //更新
  878. if len(updateCol) > 0 {
  879. err = chartClassifyInfo.Update(updateCol)
  880. if err != nil {
  881. br.Msg = "移动失败"
  882. br.ErrMsg = "修改失败,Err:" + err.Error()
  883. return
  884. }
  885. }
  886. br.Ret = 200
  887. br.Success = true
  888. br.Msg = "移动成功"
  889. }
  890. // getChartClassifyListForMe 获取我创建的图表分类
  891. func getChartClassifyListForMeV2(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  892. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  893. if err != nil && !utils.IsErrNoRow(err) {
  894. errMsg = "获取失败"
  895. return
  896. }
  897. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  898. if err != nil && !utils.IsErrNoRow(err) {
  899. errMsg = "获取失败"
  900. return
  901. }
  902. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  903. for _, v := range classifyAll {
  904. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  905. }
  906. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  907. for _, v := range rootList {
  908. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  909. v.Children = existItems
  910. } else {
  911. items := make([]*data_manage.ChartClassifyItems, 0)
  912. v.Children = items
  913. }
  914. nodeAll = append(nodeAll, v)
  915. }
  916. resp.AllNodes = nodeAll
  917. return
  918. }
  919. // ChartClassifyChartListV2
  920. // @Title 根据图表分类获取图表列表
  921. // @Description 根据图表分类获取图表列表接口
  922. // @Param IsShowMe query bool true "是否只看我的,true、false"
  923. // @Param ChartClassifyId query bool true "图片分类id"
  924. // @Success 200 {object} data_manage.ChartClassifyListResp
  925. // @router /chart_classify/chart/list [get]
  926. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  927. br := new(models.BaseResponse).Init()
  928. defer func() {
  929. this.Data["json"] = br
  930. this.ServeJSON()
  931. }()
  932. sysUser := this.SysUser
  933. if sysUser == nil {
  934. br.Msg = "请登录"
  935. br.ErrMsg = "请登录,SysUser Is Empty"
  936. br.Ret = 408
  937. return
  938. }
  939. resp := new(data_manage.ChartClassifyListResp)
  940. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  941. if chartClassifyId <= 0 {
  942. br.Msg = "参数错误"
  943. return
  944. }
  945. // 获取当前账号的不可见指标
  946. noPermissionChartIdMap := make(map[int]bool)
  947. {
  948. obj := data_manage.EdbInfoNoPermissionAdmin{}
  949. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  950. if err != nil && !utils.IsErrNoRow(err) {
  951. br.Msg = "获取失败"
  952. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  953. return
  954. }
  955. for _, v := range confList {
  956. noPermissionChartIdMap[v.ChartInfoId] = true
  957. }
  958. }
  959. isShowMe, _ := this.GetBool("IsShowMe")
  960. if isShowMe {
  961. allChartInfo, err := data_manage.GetChartInfoByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, sysUser.AdminId, chartClassifyId)
  962. if err != nil && !utils.IsErrNoRow(err) {
  963. br.Msg = "获取失败"
  964. br.ErrMsg = "获取全部数据失败,Err:" + err.Error()
  965. return
  966. }
  967. // 移除没有权限的图表
  968. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  969. resp.AllNodes = allNodes
  970. br.Ret = 200
  971. br.Success = true
  972. br.Msg = "获取成功"
  973. br.Data = resp
  974. fmt.Println("source my classify")
  975. return
  976. }
  977. allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  978. if err != nil && !utils.IsErrNoRow(err) {
  979. br.Msg = "获取失败"
  980. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  981. return
  982. }
  983. // 移除没有权限的图表
  984. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  985. for k, item := range allNodes {
  986. item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  987. item.Button.AddButton = false
  988. item.Button.OpButton = false
  989. item.Button.DeleteButton = false
  990. allNodes[k] = item
  991. }
  992. resp.AllNodes = allNodes
  993. br.Ret = 200
  994. br.Success = true
  995. br.Msg = "获取成功"
  996. br.Data = resp
  997. }
  998. // ChartClassifyChartListV3
  999. // @Title 根据图表分类获取图表列表-包含分类和图表
  1000. // @Description 根据图表分类获取图表列表接口-包含分类和图表
  1001. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1002. // @Param ChartClassifyId query bool true "图片分类id"
  1003. // @Success 200 {object} data_manage.ChartClassifyListResp
  1004. // @router /chart_classify/chart/listV2 [get]
  1005. func (this *ChartClassifyController) ChartClassifyChartListV3() {
  1006. br := new(models.BaseResponse).Init()
  1007. defer func() {
  1008. this.Data["json"] = br
  1009. this.ServeJSON()
  1010. }()
  1011. sysUser := this.SysUser
  1012. if sysUser == nil {
  1013. br.Msg = "请登录"
  1014. br.ErrMsg = "请登录,SysUser Is Empty"
  1015. br.Ret = 408
  1016. return
  1017. }
  1018. resp := new(data_manage.ChartClassifyListResp)
  1019. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1020. if chartClassifyId < 0 {
  1021. br.Msg = "参数错误"
  1022. return
  1023. }
  1024. // 获取当前账号的不可见指标
  1025. noPermissionChartIdMap := make(map[int]bool)
  1026. {
  1027. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1028. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1029. if err != nil && !utils.IsErrNoRow(err) {
  1030. br.Msg = "获取失败"
  1031. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. for _, v := range confList {
  1035. noPermissionChartIdMap[v.ChartInfoId] = true
  1036. }
  1037. }
  1038. var allNodes []*data_manage.ChartClassifyItems
  1039. // 获取是否精选资源标识
  1040. isSelected, _ := this.GetInt("IsSelected")
  1041. if chartClassifyId > 0 {
  1042. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1043. if err != nil {
  1044. br.Msg = "获取失败"
  1045. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1046. return
  1047. }
  1048. isSelected = chartClassifyInfo.IsSelected
  1049. }
  1050. isShowMe, _ := this.GetBool("IsShowMe")
  1051. if isShowMe {
  1052. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentIdForMe(chartClassifyId, sysUser.AdminId, isSelected)
  1053. if err != nil && !utils.IsErrNoRow(err) {
  1054. br.Msg = "获取失败"
  1055. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. // 移除没有权限的图表
  1059. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1060. allNodes, err = data.GetChartClassifyByIsMe(sysUser.AdminId, chartClassifyId, utils.CHART_SOURCE_DEFAULT, allNodes)
  1061. if err != nil {
  1062. br.Msg = "获取失败"
  1063. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. //resp.AllNodes = allNodes
  1067. //
  1068. //br.Ret = 200
  1069. //br.Success = true
  1070. //br.Msg = "获取成功"
  1071. //br.Data = resp
  1072. //fmt.Println("source my classify")
  1073. //return
  1074. } else {
  1075. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentId(chartClassifyId, isSelected)
  1076. if err != nil && err.Error() != utils.ErrNoRow() {
  1077. br.Msg = "获取失败"
  1078. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1079. return
  1080. }
  1081. //allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  1082. //if err != nil && err.Error() != utils.ErrNoRow() {
  1083. // br.Msg = "获取失败"
  1084. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1085. // return
  1086. //}
  1087. // 移除没有权限的图表
  1088. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1089. }
  1090. menulist, e := system.GetMenuButtonsByRoleId(this.SysUser.RoleId)
  1091. if e != nil {
  1092. br.Msg = "获取失败"
  1093. br.ErrMsg = "获取角色按钮权限失败, Err: " + e.Error()
  1094. return
  1095. }
  1096. buttonList := make(map[string]int, 0)
  1097. for _, item := range menulist {
  1098. if item.MenuType == 1 {
  1099. buttonList[item.ButtonCode] = 1
  1100. }
  1101. }
  1102. var addOrEditRight, deleteRight, moveRight bool
  1103. if _, ok := buttonList[CHART_CLASSIFY_ADD_OR_EDIT]; ok {
  1104. addOrEditRight = true
  1105. }
  1106. if _, ok := buttonList[CHART_CLASSIFY_DELETE]; ok {
  1107. deleteRight = true
  1108. }
  1109. if _, ok := buttonList[CHART_CLASSIFY_MOVE]; ok {
  1110. moveRight = true
  1111. }
  1112. for k, item := range allNodes {
  1113. //item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  1114. item.Button = data.GetChartOpButtonV2(item.HaveOperaAuth, addOrEditRight, deleteRight, moveRight)
  1115. if item.ChartInfoId > 0 {
  1116. item.Button.AddButton = false
  1117. item.Button.OpButton = false
  1118. item.Button.DeleteButton = false
  1119. item.Button.MoveButton = true
  1120. } else if item.Level == 6 {
  1121. item.Button.AddButton = false
  1122. }
  1123. allNodes[k] = item
  1124. }
  1125. resp.AllNodes = allNodes
  1126. br.Ret = 200
  1127. br.Success = true
  1128. br.Msg = "获取成功"
  1129. br.Data = resp
  1130. }
  1131. // SetChartClassifyResourceStatus
  1132. // @Title 一键从资源库上架/下架
  1133. // @Description 一键从资源库上架/下架
  1134. // @Param ChartClassifyId query bool true "图片分类id"
  1135. // @Param ResourceStatus query bool true "资源状态"
  1136. // @Success 200 {object} models.BaseResponse
  1137. // @router /chart_classify/resource_status [post]
  1138. func (this *ChartClassifyController) SetChartClassifyResourceStatus() {
  1139. br := new(models.BaseResponse).Init()
  1140. defer func() {
  1141. this.Data["json"] = br
  1142. this.ServeJSON()
  1143. }()
  1144. var req data_manage.SetChartClassifyResourceStatusReq
  1145. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1146. if err != nil {
  1147. br.Msg = "参数解析异常!"
  1148. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. chartClassifyId := req.ChartClassifyId
  1152. if chartClassifyId <= 0 {
  1153. br.Msg = "参数错误"
  1154. return
  1155. }
  1156. resourceStatus := req.ResourceStatus
  1157. if resourceStatus <= 0 {
  1158. br.Msg = "参数错误"
  1159. return
  1160. }
  1161. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1162. if err != nil {
  1163. br.Msg = "获取失败"
  1164. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1165. return
  1166. }
  1167. if resourceStatus == utils.ChartClassifyResourceStatusDown {
  1168. errMsg, err := eta_forum.SetChartClassifyResourceStatusDown(chartClassifyInfo, this.SysUser)
  1169. if err != nil {
  1170. if errMsg != "" {
  1171. br.Msg = errMsg
  1172. br.ErrMsg = err.Error()
  1173. return
  1174. }
  1175. br.Msg = "操作失败"
  1176. br.ErrMsg = err.Error()
  1177. return
  1178. }
  1179. } else if resourceStatus == utils.ChartClassifyResourceStatusUp {
  1180. errMsg, err := eta_forum.SetChartClassifyResourceStatusUp(chartClassifyInfo, this.SysUser)
  1181. if err != nil {
  1182. if errMsg != "" {
  1183. br.Msg = errMsg
  1184. br.ErrMsg = err.Error()
  1185. return
  1186. }
  1187. br.Msg = "操作失败"
  1188. br.ErrMsg = err.Error()
  1189. return
  1190. }
  1191. }
  1192. br.Ret = 200
  1193. br.Success = true
  1194. br.Msg = "操作成功"
  1195. }
  1196. // 一键更新至资源库
  1197. // @Title 一键更新至资源库
  1198. // @Description 一键更新至资源库
  1199. // @Param ChartClassifyId query bool true "图片分类id"
  1200. // @Success 200 {object} models.BaseResponse
  1201. // @router /chart_classify/forum_chart/update [post]
  1202. func (this *ChartClassifyController) UpdateChartClassifyResource() {
  1203. br := new(models.BaseResponse).Init()
  1204. defer func() {
  1205. this.Data["json"] = br
  1206. this.ServeJSON()
  1207. }()
  1208. var req data_manage.ChartClassifyResourceUpdate
  1209. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1210. if err != nil {
  1211. br.Msg = "参数解析异常!"
  1212. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1213. return
  1214. }
  1215. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  1216. if err != nil {
  1217. br.Msg = "获取失败"
  1218. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1219. return
  1220. }
  1221. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  1222. br.Msg = "分类来源错误"
  1223. return
  1224. }
  1225. if chartClassifyInfo.IsSelected != utils.ChartClassifyIsSelected {
  1226. br.Msg = "该分类不是精选分类"
  1227. return
  1228. }
  1229. err = eta_forum.ChartBatchUpdateAndUpload(chartClassifyInfo, this.SysUser)
  1230. if err != nil {
  1231. br.Msg = "操作失败"
  1232. br.ErrMsg = err.Error()
  1233. return
  1234. }
  1235. br.Ret = 200
  1236. br.Success = true
  1237. br.Msg = "操作成功"
  1238. }