chart_classify.go 43 KB

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