chart_classify.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  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. oldParentId := chartClassifyInfo.ParentId
  780. oldLevelPath := chartClassifyInfo.LevelPath
  781. oldSelected := chartClassifyInfo.IsSelected
  782. // 校验移动的父级目录下是否有重名分类
  783. exists, e := data_manage.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  784. if e != nil && !utils.IsErrNoRow(e) {
  785. br.Msg = "移动失败"
  786. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  787. return
  788. }
  789. if exists != nil && exists.ChartClassifyId > 0 {
  790. br.Msg = "移动失败,分类名称已存在"
  791. return
  792. }
  793. // 已授权分类id
  794. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, chartClassifyInfo.ChartClassifyId)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  798. return
  799. }
  800. // 权限校验
  801. {
  802. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
  803. button := data.GetChartClassifyOpButton(this.SysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
  804. if !button.OpButton {
  805. br.Msg = "无操作权限"
  806. br.IsSendEmail = false
  807. return
  808. }
  809. }
  810. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  811. br.Msg = "分类异常"
  812. br.ErrMsg = "分类异常,不是ETA图库的分类"
  813. return
  814. }
  815. updateCol := make([]string, 0)
  816. var parentChartClassifyInfo *data_manage.ChartClassify
  817. if req.ParentClassifyId > 0 {
  818. parentChartClassifyInfo, err = data_manage.GetChartClassifyById(req.ParentClassifyId)
  819. if err != nil {
  820. br.Msg = "移动失败"
  821. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  822. return
  823. }
  824. }
  825. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  826. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  827. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  828. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  829. chartClassifyInfo.ModifyTime = time.Now()
  830. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  831. }
  832. //如果有传入 上一个兄弟节点分类id
  833. if req.PrevClassifyId > 0 {
  834. //上一个兄弟节点
  835. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  836. if err != nil {
  837. br.Msg = "移动失败"
  838. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  839. return
  840. }
  841. //如果是移动在两个兄弟节点之间
  842. if req.NextClassifyId > 0 {
  843. //下一个兄弟节点
  844. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  845. if err != nil {
  846. br.Msg = "移动失败"
  847. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  848. return
  849. }
  850. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  851. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  852. //变更兄弟节点的排序
  853. updateSortStr := `sort + 2`
  854. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  855. } else {
  856. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  857. if nextClassify.Sort-prevClassify.Sort == 1 {
  858. //变更兄弟节点的排序
  859. updateSortStr := `sort + 1`
  860. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  861. }
  862. }
  863. }
  864. chartClassifyInfo.Sort = prevClassify.Sort + 1
  865. chartClassifyInfo.ModifyTime = time.Now()
  866. updateCol = append(updateCol, "Sort", "ModifyTime")
  867. } else {
  868. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  869. if err != nil && !utils.IsErrNoRow(err) {
  870. br.Msg = "移动失败"
  871. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  872. return
  873. }
  874. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  875. if firstClassify != nil && firstClassify.Sort == 0 {
  876. updateSortStr := ` sort + 1 `
  877. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  878. }
  879. chartClassifyInfo.Sort = 0 //那就是排在第一位
  880. chartClassifyInfo.ModifyTime = time.Now()
  881. updateCol = append(updateCol, "Sort", "ModifyTime")
  882. }
  883. //更新
  884. if len(updateCol) > 0 {
  885. err = chartClassifyInfo.Update(updateCol)
  886. if err != nil {
  887. br.Msg = "移动失败"
  888. br.ErrMsg = "修改失败,Err:" + err.Error()
  889. return
  890. }
  891. }
  892. if oldParentId != req.ParentClassifyId {
  893. if err = data.UpdateChartClassifyLevelPathWithChildren(chartClassifyInfo, parentChartClassifyInfo, oldParentId, oldLevelPath); err != nil {
  894. br.Msg = "修改分类失败"
  895. br.ErrMsg = "更新分类level_path失败,Err:" + err.Error()
  896. return
  897. }
  898. }
  899. // 如果是精选目录,则需要同步到ETA资源库
  900. if chartClassifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
  901. // 如果当前目录的精选标识发生变化,需要同步更新子目录的精选标识
  902. if err = data.UpdateChildClassifySelection(chartClassifyInfo, parentChartClassifyInfo, oldSelected); err != nil {
  903. br.Msg = "修改分类失败"
  904. br.ErrMsg = "更新子目录精选标识失败,Err:" + err.Error()
  905. return
  906. }
  907. go eta_forum.ChartClassifySaveBatch(chartClassifyInfo.Source)
  908. }
  909. br.Ret = 200
  910. br.Success = true
  911. br.Msg = "移动成功"
  912. }
  913. // getChartClassifyListForMe 获取我创建的图表分类
  914. func getChartClassifyListForMeV2(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  915. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  916. if err != nil && !utils.IsErrNoRow(err) {
  917. errMsg = "获取失败"
  918. return
  919. }
  920. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  921. if err != nil && !utils.IsErrNoRow(err) {
  922. errMsg = "获取失败"
  923. return
  924. }
  925. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  926. for _, v := range classifyAll {
  927. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  928. }
  929. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  930. for _, v := range rootList {
  931. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  932. v.Children = existItems
  933. } else {
  934. items := make([]*data_manage.ChartClassifyItems, 0)
  935. v.Children = items
  936. }
  937. nodeAll = append(nodeAll, v)
  938. }
  939. resp.AllNodes = nodeAll
  940. return
  941. }
  942. // ChartClassifyChartListV2
  943. // @Title 根据图表分类获取图表列表
  944. // @Description 根据图表分类获取图表列表接口
  945. // @Param IsShowMe query bool true "是否只看我的,true、false"
  946. // @Param ChartClassifyId query bool true "图片分类id"
  947. // @Success 200 {object} data_manage.ChartClassifyListResp
  948. // @router /chart_classify/chart/list [get]
  949. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  950. br := new(models.BaseResponse).Init()
  951. defer func() {
  952. this.Data["json"] = br
  953. this.ServeJSON()
  954. }()
  955. sysUser := this.SysUser
  956. if sysUser == nil {
  957. br.Msg = "请登录"
  958. br.ErrMsg = "请登录,SysUser Is Empty"
  959. br.Ret = 408
  960. return
  961. }
  962. resp := new(data_manage.ChartClassifyListResp)
  963. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  964. if chartClassifyId <= 0 {
  965. br.Msg = "参数错误"
  966. return
  967. }
  968. // 获取当前账号的不可见指标
  969. noPermissionChartIdMap := make(map[int]bool)
  970. {
  971. obj := data_manage.EdbInfoNoPermissionAdmin{}
  972. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  973. if err != nil && !utils.IsErrNoRow(err) {
  974. br.Msg = "获取失败"
  975. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  976. return
  977. }
  978. for _, v := range confList {
  979. noPermissionChartIdMap[v.ChartInfoId] = true
  980. }
  981. }
  982. isShowMe, _ := this.GetBool("IsShowMe")
  983. if isShowMe {
  984. allChartInfo, err := data_manage.GetChartInfoByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, sysUser.AdminId, chartClassifyId)
  985. if err != nil && !utils.IsErrNoRow(err) {
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取全部数据失败,Err:" + err.Error()
  988. return
  989. }
  990. // 移除没有权限的图表
  991. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  992. resp.AllNodes = allNodes
  993. br.Ret = 200
  994. br.Success = true
  995. br.Msg = "获取成功"
  996. br.Data = resp
  997. fmt.Println("source my classify")
  998. return
  999. }
  1000. allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  1001. if err != nil && !utils.IsErrNoRow(err) {
  1002. br.Msg = "获取失败"
  1003. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1004. return
  1005. }
  1006. // 移除没有权限的图表
  1007. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1008. for k, item := range allNodes {
  1009. item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  1010. item.Button.AddButton = false
  1011. item.Button.OpButton = false
  1012. item.Button.DeleteButton = false
  1013. allNodes[k] = item
  1014. }
  1015. resp.AllNodes = allNodes
  1016. br.Ret = 200
  1017. br.Success = true
  1018. br.Msg = "获取成功"
  1019. br.Data = resp
  1020. }
  1021. // ChartClassifyChartListV3
  1022. // @Title 根据图表分类获取图表列表-包含分类和图表
  1023. // @Description 根据图表分类获取图表列表接口-包含分类和图表
  1024. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1025. // @Param ChartClassifyId query bool true "图片分类id"
  1026. // @Success 200 {object} data_manage.ChartClassifyListResp
  1027. // @router /chart_classify/chart/listV2 [get]
  1028. func (this *ChartClassifyController) ChartClassifyChartListV3() {
  1029. br := new(models.BaseResponse).Init()
  1030. defer func() {
  1031. this.Data["json"] = br
  1032. this.ServeJSON()
  1033. }()
  1034. sysUser := this.SysUser
  1035. if sysUser == nil {
  1036. br.Msg = "请登录"
  1037. br.ErrMsg = "请登录,SysUser Is Empty"
  1038. br.Ret = 408
  1039. return
  1040. }
  1041. resp := new(data_manage.ChartClassifyListResp)
  1042. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1043. if chartClassifyId < 0 {
  1044. br.Msg = "参数错误"
  1045. return
  1046. }
  1047. // 获取当前账号的不可见指标
  1048. noPermissionChartIdMap := make(map[int]bool)
  1049. {
  1050. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1051. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1052. if err != nil && !utils.IsErrNoRow(err) {
  1053. br.Msg = "获取失败"
  1054. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1055. return
  1056. }
  1057. for _, v := range confList {
  1058. noPermissionChartIdMap[v.ChartInfoId] = true
  1059. }
  1060. }
  1061. var allNodes []*data_manage.ChartClassifyItems
  1062. // 获取是否精选资源标识
  1063. isSelected, _ := this.GetInt("IsSelected")
  1064. if chartClassifyId > 0 {
  1065. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1066. if err != nil {
  1067. br.Msg = "获取失败"
  1068. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. isSelected = chartClassifyInfo.IsSelected
  1072. }
  1073. isShowMe, _ := this.GetBool("IsShowMe")
  1074. if isShowMe {
  1075. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentIdForMe(chartClassifyId, sysUser.AdminId, isSelected)
  1076. if err != nil && !utils.IsErrNoRow(err) {
  1077. br.Msg = "获取失败"
  1078. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1079. return
  1080. }
  1081. // 移除没有权限的图表
  1082. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1083. allNodes, err = data.GetChartClassifyByIsMe(sysUser.AdminId, chartClassifyId, utils.CHART_SOURCE_DEFAULT, allNodes)
  1084. if err != nil {
  1085. br.Msg = "获取失败"
  1086. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1087. return
  1088. }
  1089. //resp.AllNodes = allNodes
  1090. //
  1091. //br.Ret = 200
  1092. //br.Success = true
  1093. //br.Msg = "获取成功"
  1094. //br.Data = resp
  1095. //fmt.Println("source my classify")
  1096. //return
  1097. } else {
  1098. allChartInfo, err := data_manage.GetChartClassifyAndInfoByParentId(chartClassifyId, isSelected)
  1099. if err != nil && err.Error() != utils.ErrNoRow() {
  1100. br.Msg = "获取失败"
  1101. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1102. return
  1103. }
  1104. //allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  1105. //if err != nil && err.Error() != utils.ErrNoRow() {
  1106. // br.Msg = "获取失败"
  1107. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1108. // return
  1109. //}
  1110. // 移除没有权限的图表
  1111. allNodes = data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  1112. }
  1113. menulist, e := system.GetMenuButtonsByRoleId(this.SysUser.RoleId)
  1114. if e != nil {
  1115. br.Msg = "获取失败"
  1116. br.ErrMsg = "获取角色按钮权限失败, Err: " + e.Error()
  1117. return
  1118. }
  1119. buttonList := make(map[string]int, 0)
  1120. for _, item := range menulist {
  1121. if item.MenuType == 1 {
  1122. buttonList[item.ButtonCode] = 1
  1123. }
  1124. }
  1125. var addOrEditRight, deleteRight, moveRight bool
  1126. if _, ok := buttonList[CHART_CLASSIFY_ADD_OR_EDIT]; ok {
  1127. addOrEditRight = true
  1128. }
  1129. if _, ok := buttonList[CHART_CLASSIFY_DELETE]; ok {
  1130. deleteRight = true
  1131. }
  1132. if _, ok := buttonList[CHART_CLASSIFY_MOVE]; ok {
  1133. moveRight = true
  1134. }
  1135. for k, item := range allNodes {
  1136. //item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  1137. item.Button = data.GetChartOpButtonV2(item.HaveOperaAuth, addOrEditRight, deleteRight, moveRight)
  1138. if item.ChartInfoId > 0 {
  1139. item.Button.AddButton = false
  1140. item.Button.OpButton = false
  1141. item.Button.DeleteButton = false
  1142. item.Button.MoveButton = true
  1143. } else if item.Level == 6 {
  1144. item.Button.AddButton = false
  1145. }
  1146. allNodes[k] = item
  1147. }
  1148. resp.AllNodes = allNodes
  1149. br.Ret = 200
  1150. br.Success = true
  1151. br.Msg = "获取成功"
  1152. br.Data = resp
  1153. }
  1154. // SetChartClassifyResourceStatus
  1155. // @Title 一键从资源库上架/下架
  1156. // @Description 一键从资源库上架/下架
  1157. // @Param ChartClassifyId query bool true "图片分类id"
  1158. // @Param ResourceStatus query bool true "资源状态"
  1159. // @Success 200 {object} models.BaseResponse
  1160. // @router /chart_classify/resource_status [post]
  1161. func (this *ChartClassifyController) SetChartClassifyResourceStatus() {
  1162. br := new(models.BaseResponse).Init()
  1163. defer func() {
  1164. this.Data["json"] = br
  1165. this.ServeJSON()
  1166. }()
  1167. var req data_manage.SetChartClassifyResourceStatusReq
  1168. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1169. if err != nil {
  1170. br.Msg = "参数解析异常!"
  1171. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1172. return
  1173. }
  1174. chartClassifyId := req.ChartClassifyId
  1175. if chartClassifyId <= 0 {
  1176. br.Msg = "参数错误"
  1177. return
  1178. }
  1179. resourceStatus := req.ResourceStatus
  1180. if resourceStatus <= 0 {
  1181. br.Msg = "参数错误"
  1182. return
  1183. }
  1184. chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
  1185. if err != nil {
  1186. br.Msg = "获取失败"
  1187. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1188. return
  1189. }
  1190. if resourceStatus == utils.ChartClassifyResourceStatusDown {
  1191. errMsg, err := eta_forum.SetChartClassifyResourceStatusDown(chartClassifyInfo, this.SysUser)
  1192. if err != nil {
  1193. if errMsg != "" {
  1194. br.Msg = errMsg
  1195. br.ErrMsg = err.Error()
  1196. return
  1197. }
  1198. br.Msg = "操作失败"
  1199. br.ErrMsg = err.Error()
  1200. return
  1201. }
  1202. } else if resourceStatus == utils.ChartClassifyResourceStatusUp {
  1203. errMsg, err := eta_forum.SetChartClassifyResourceStatusUp(chartClassifyInfo, this.SysUser)
  1204. if err != nil {
  1205. if errMsg != "" {
  1206. br.Msg = errMsg
  1207. br.ErrMsg = err.Error()
  1208. return
  1209. }
  1210. br.Msg = "操作失败"
  1211. br.ErrMsg = err.Error()
  1212. return
  1213. }
  1214. }
  1215. br.Ret = 200
  1216. br.Success = true
  1217. br.Msg = "操作成功"
  1218. }
  1219. // 一键更新至资源库
  1220. // @Title 一键更新至资源库
  1221. // @Description 一键更新至资源库
  1222. // @Param ChartClassifyId query bool true "图片分类id"
  1223. // @Success 200 {object} models.BaseResponse
  1224. // @router /chart_classify/forum_chart/update [post]
  1225. func (this *ChartClassifyController) UpdateChartClassifyResource() {
  1226. br := new(models.BaseResponse).Init()
  1227. defer func() {
  1228. this.Data["json"] = br
  1229. this.ServeJSON()
  1230. }()
  1231. var req data_manage.ChartClassifyResourceUpdate
  1232. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1233. if err != nil {
  1234. br.Msg = "参数解析异常!"
  1235. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1236. return
  1237. }
  1238. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  1239. if err != nil {
  1240. br.Msg = "获取失败"
  1241. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1242. return
  1243. }
  1244. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  1245. br.Msg = "分类来源错误"
  1246. return
  1247. }
  1248. if chartClassifyInfo.IsSelected != utils.ChartClassifyIsSelected {
  1249. br.Msg = "该分类不是精选分类"
  1250. return
  1251. }
  1252. err = eta_forum.ChartBatchUpdateAndUpload(chartClassifyInfo, this.SysUser)
  1253. if err != nil {
  1254. br.Msg = "操作失败"
  1255. br.ErrMsg = err.Error()
  1256. return
  1257. }
  1258. br.Ret = 200
  1259. br.Success = true
  1260. br.Msg = "操作成功"
  1261. }