chart_classify.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_admin/models"
  5. "eta/eta_forum_admin/models/system"
  6. "eta/eta_forum_admin/services"
  7. "eta/eta_forum_admin/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 数据管理-分类模块
  16. type ChartClassifyController struct {
  17. BaseAuthController
  18. }
  19. // ChartClassifyListV2
  20. // @Title 图表分类列表
  21. // @Description 图表分类列表接口
  22. // @Param IsShowMe query bool true "是否只看我的,true、false"
  23. // @Success 200 {object} models.ChartClassifyListResp
  24. // @router /chart_classify/list [get]
  25. func (this *ChartClassifyController) ChartClassifyListV2() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. resp := new(models.ChartClassifyListResp)
  32. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  33. key := utils.CACHE_CHART_CLASSIFY
  34. if utils.Re == nil {
  35. if utils.Re == nil && utils.Rc.IsExist(key) {
  36. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  37. err := json.Unmarshal(redisData, &resp)
  38. if err == nil && resp != nil {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. fmt.Println("source redis")
  44. return
  45. }
  46. }
  47. }
  48. }
  49. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  50. if err != nil && err.Error() != utils.ErrNoRow() {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  53. return
  54. }
  55. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  56. if err != nil && err.Error() != utils.ErrNoRow() {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  59. return
  60. }
  61. allChartInfo, err := models.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT})
  62. if err != nil && err.Error() != utils.ErrNoRow() {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  65. return
  66. }
  67. chartInfoMap := make(map[int][]*models.ChartClassifyItems)
  68. for _, v := range allChartInfo {
  69. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  70. }
  71. rootChildMap := make(map[int][]*models.ChartClassifyItems)
  72. for _, v := range classifyAll {
  73. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  74. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  75. v.Children = existItems
  76. } else {
  77. items := make([]*models.ChartClassifyItems, 0)
  78. v.Children = items
  79. }
  80. }
  81. nodeAll := make([]*models.ChartClassifyItems, 0)
  82. for _, v := range rootList {
  83. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  84. v.Children = existItems
  85. } else {
  86. items := make([]*models.ChartClassifyItems, 0)
  87. v.Children = items
  88. }
  89. nodeAll = append(nodeAll, v)
  90. }
  91. //
  92. //
  93. //nodeAll := make([]*models.ChartClassifyItems, 0)
  94. //for k := range rootList {
  95. // rootNode := rootList[k]
  96. // services.ChartClassifyListMakeTree(classifyAll, rootNode)
  97. // nodeAll = append(nodeAll, rootNode)
  98. //}
  99. resp.AllNodes = nodeAll
  100. // 将数据加入缓存
  101. if utils.Re == nil {
  102. redisData, _ := json.Marshal(resp)
  103. utils.Rc.Put(key, redisData, 2*time.Hour)
  104. }
  105. br.Ret = 200
  106. br.Success = true
  107. br.Msg = "获取成功"
  108. br.Data = resp
  109. }
  110. // SimpleList
  111. // @Title 单层分类列表
  112. // @Description 单层分类列表
  113. // @Success 200 {object} data_manage.EdbClassifyListResp
  114. // @router /classify/simple [get]
  115. func (this *ChartClassifyController) SimpleList() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. // 默认查一级分类和一级分类下的指标信息,
  122. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  123. // 增加标识判断是文件夹还是指标列表
  124. reqParentId, _ := this.GetInt("ParentId")
  125. sysUserIds := this.GetString("SysUserIds")
  126. adminIdsSlice := make([]int, 0)
  127. if sysUserIds != "" {
  128. adminIds := strings.Split(sysUserIds, ",")
  129. if len(adminIds) == 0 {
  130. br.Msg = "请选择正确的创建人"
  131. return
  132. }
  133. for _, adminId := range adminIds {
  134. adminIdInt, e := strconv.Atoi(adminId)
  135. if e != nil {
  136. br.Msg = "请选择正确的创建人"
  137. return
  138. }
  139. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  140. }
  141. }
  142. parentId := 0
  143. nodeAll := make([]*models.ChartClassifyItems, 0)
  144. // 处理未分类
  145. //查询未分类的指标列表
  146. if reqParentId == -1 {
  147. initClassify := &models.ChartClassifyItems{
  148. ChartClassifyId: 0,
  149. ChartInfoId: 0,
  150. ChartClassifyName: "未分类",
  151. ChartClassifyNameEn: "",
  152. ParentId: 0,
  153. Level: 1,
  154. Sort: 0,
  155. }
  156. nodeAll = append(nodeAll, initClassify)
  157. } else {
  158. parentId = reqParentId
  159. }
  160. rootList := make([]*models.ChartClassifyItems, 0)
  161. rootListTmp := make([]*models.ChartClassifyItems, 0)
  162. var err error
  163. if reqParentId == -1 || reqParentId > 0 {
  164. rootListTmp, err = models.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_DEFAULT)
  165. if err != nil && err.Error() != utils.ErrNoRow() {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  168. return
  169. }
  170. if len(adminIdsSlice) > 0 {
  171. // 判断是否存在某个创建人的图表,如果不存在某个创建人的图表则过滤
  172. hasClassifyMap, e, _ := services.GetChartClassifyListByAdmins(adminIdsSlice)
  173. if e != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取创建人图表失败,Err:" + e.Error()
  176. return
  177. }
  178. for _, v := range rootListTmp {
  179. if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
  180. rootList = append(rootList, v)
  181. }
  182. }
  183. } else {
  184. rootList = rootListTmp
  185. }
  186. }
  187. var sortList models.ChartClassifyItemList
  188. if reqParentId >= 0 {
  189. // 查询挂在当前分类上的图表列表
  190. var e error
  191. allChartInfo := make([]*models.ChartClassifyItems, 0)
  192. if len(adminIdsSlice) > 0 {
  193. allChartInfo, e = models.GetChartInfoAllByClassifyIdAndAdmin(utils.CHART_SOURCE_DEFAULT, parentId, adminIdsSlice)
  194. } else {
  195. allChartInfo, e = models.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, parentId)
  196. }
  197. if e != nil && e.Error() != utils.ErrNoRow() {
  198. br.Msg = "获取失败"
  199. br.ErrMsg = "获取图表信息失败,Err:" + e.Error()
  200. return
  201. }
  202. if len(allChartInfo) > 0 {
  203. // 查询机构名称
  204. /*adminIds := make([]int, 0)
  205. for _, v := range allChartInfo {
  206. adminIds = append(adminIds, v.SysUserId)
  207. }
  208. adminCompanyMap, er := services.GetCompanyNameByAdmins(adminIds)
  209. if er != nil {
  210. br.Msg = "获取失败"
  211. br.ErrMsg = "获取机构失败,Err:" + er.Error()
  212. return
  213. }*/
  214. for _, v := range allChartInfo {
  215. v.Children = make([]*models.ChartClassifyItems, 0)
  216. //if n, ok := adminCompanyMap[v.SysUserId]; ok {
  217. v.Company = utils.HzCompanyName
  218. //}
  219. nodeAll = append(nodeAll, v)
  220. }
  221. }
  222. }
  223. if len(rootList) > 0 {
  224. for _, v := range rootList {
  225. v.Children = make([]*models.ChartClassifyItems, 0)
  226. nodeAll = append(nodeAll, v)
  227. }
  228. }
  229. if len(nodeAll) > 0 {
  230. //根据sort值排序
  231. sortList = nodeAll
  232. sort.Sort(sortList)
  233. }
  234. language := `CN`
  235. // 指标显示的语言
  236. {
  237. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  238. if configDetail != nil {
  239. language = configDetail.ConfigValue
  240. } else {
  241. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  242. if configDetail != nil {
  243. language = configDetail.ConfigValue
  244. }
  245. }
  246. }
  247. resp := new(models.ChartClassifyListResp)
  248. if len(nodeAll) > 0 {
  249. resp.AllNodes = sortList
  250. } else {
  251. resp.AllNodes = nodeAll
  252. }
  253. resp.Language = language
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "获取成功"
  257. br.Data = resp
  258. }
  259. // ChartClassifyItems
  260. // @Title 获取所有图表分类接口-不包含图表
  261. // @Description 获取所有图表分类接口-不包含图表
  262. // @Success 200 {object} models.ChartClassifyListResp
  263. // @router /chart_classify/items [get]
  264. func (this *ChartClassifyController) ChartClassifyItems() {
  265. br := new(models.BaseResponse).Init()
  266. defer func() {
  267. this.Data["json"] = br
  268. this.ServeJSON()
  269. }()
  270. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  271. if err != nil {
  272. br.Msg = "获取失败"
  273. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  274. return
  275. }
  276. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  277. if err != nil {
  278. br.Msg = "获取失败"
  279. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  280. return
  281. }
  282. nodeAll := make([]*models.ChartClassifyItems, 0)
  283. for k := range rootList {
  284. rootNode := rootList[k]
  285. services.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
  286. nodeAll = append(nodeAll, rootNode)
  287. }
  288. language := `CN`
  289. // 指标显示的语言
  290. {
  291. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  292. if configDetail != nil {
  293. language = configDetail.ConfigValue
  294. } else {
  295. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  296. if configDetail != nil {
  297. language = configDetail.ConfigValue
  298. }
  299. }
  300. }
  301. // 是否允许添加分类
  302. canOpClassify := true
  303. // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
  304. //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) {
  305. // canOpClassify = false
  306. //}
  307. resp := models.ChartClassifyListResp{
  308. AllNodes: nodeAll,
  309. Language: language,
  310. CanOpClassify: canOpClassify,
  311. }
  312. br.Ret = 200
  313. br.Success = true
  314. br.Msg = "获取成功"
  315. br.Data = resp
  316. }
  317. // @Title 新增图表分类
  318. // @Description 新增图表分类接口
  319. // @Param request body models.AddChartClassifyReq true "type json string"
  320. // @Success 200 Ret=200 保存成功
  321. // @router /classify/add [post]
  322. func (this *ChartClassifyController) AddChartClassify() {
  323. br := new(models.BaseResponse).Init()
  324. defer func() {
  325. this.Data["json"] = br
  326. this.ServeJSON()
  327. }()
  328. var req models.AddChartClassifyReq
  329. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  330. if err != nil {
  331. br.Msg = "参数解析异常!"
  332. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  333. return
  334. }
  335. if req.ChartClassifyName == "" {
  336. br.Msg = "请输入分类名称"
  337. br.IsSendEmail = false
  338. return
  339. }
  340. if req.ParentId < 0 {
  341. br.Msg = "参数错误"
  342. br.IsSendEmail = false
  343. return
  344. }
  345. // 新增图表分类
  346. _, err, errMsg, isSendEmail := services.AddChartClassify(req.ChartClassifyName, req.ParentId, utils.CHART_SOURCE_DEFAULT, this.Lang, this.SysUser)
  347. if err != nil {
  348. br.Msg = errMsg
  349. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  350. br.IsSendEmail = isSendEmail
  351. return
  352. }
  353. br.Ret = 200
  354. br.Msg = "保存成功"
  355. br.Success = true
  356. }
  357. // EditChartClassify
  358. // @Title 修改图表分类
  359. // @Description 修改图表分类接口
  360. // @Param request body models.EditChartClassifyReq true "type json string"
  361. // @Success 200 Ret=200 修改成功
  362. // @router /classify/edit [post]
  363. func (this *ChartClassifyController) EditChartClassify() {
  364. br := new(models.BaseResponse).Init()
  365. defer func() {
  366. this.Data["json"] = br
  367. this.ServeJSON()
  368. }()
  369. var req models.EditChartClassifyReq
  370. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  371. if err != nil {
  372. br.Msg = "参数解析异常!"
  373. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  374. return
  375. }
  376. if req.ChartClassifyName == "" {
  377. br.Msg = "请输入分类名称"
  378. br.IsSendEmail = false
  379. return
  380. }
  381. if req.ChartClassifyId <= 0 {
  382. br.Msg = "参数错误"
  383. br.IsSendEmail = false
  384. return
  385. }
  386. // 编辑图表分类
  387. _, err, errMsg, isSendEmail := services.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_DEFAULT, req.ChartClassifyName, this.Lang, this.SysUser)
  388. if err != nil {
  389. br.Msg = errMsg
  390. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  391. br.IsSendEmail = isSendEmail
  392. return
  393. }
  394. br.Ret = 200
  395. br.Msg = "保存成功"
  396. br.Success = true
  397. br.IsAddLog = true
  398. }
  399. // @Title 删除图表检测接口
  400. // @Description 删除图表检测接口
  401. // @Param request body models.ChartClassifyDeleteCheckResp true "type json string"
  402. // @Success 200 Ret=200 检测成功
  403. // @router /chart_classify/delete/check [post]
  404. func (this *ChartClassifyController) DeleteChartClassifyCheck() {
  405. br := new(models.BaseResponse).Init()
  406. defer func() {
  407. this.Data["json"] = br
  408. this.ServeJSON()
  409. }()
  410. var req models.ChartClassifyDeleteCheckReq
  411. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  412. if err != nil {
  413. br.Msg = "参数解析异常!"
  414. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  415. return
  416. }
  417. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  418. br.Msg = "参数错误"
  419. br.IsSendEmail = false
  420. return
  421. }
  422. var deleteStatus int
  423. var tipsMsg string
  424. //删除分类
  425. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  426. // 查找分类
  427. /*item, err := models.GetChartClassifyById(req.ChartClassifyId)
  428. if err != nil {
  429. br.Msg = "保存失败"
  430. br.Msg = "获取分类信息失败,Err:" + err.Error()
  431. return
  432. }
  433. // 已授权分类id
  434. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  435. if err != nil {
  436. br.Msg = "获取失败"
  437. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  438. return
  439. }
  440. // todo 删除是否需要加权限校验
  441. {
  442. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  443. button := services.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  444. if !button.OpButton {
  445. br.Msg = "无操作权限"
  446. br.IsSendEmail = false
  447. return
  448. }
  449. }*/
  450. //判断图表分类下,是否含有图表
  451. count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  452. if err != nil {
  453. br.Msg = "删除失败"
  454. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  455. return
  456. }
  457. if count > 0 {
  458. deleteStatus = 1
  459. tipsMsg = "该分类下关联图表不可删除"
  460. }
  461. }
  462. if deleteStatus != 1 && req.ChartInfoId == 0 {
  463. classifyCount, err := models.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  464. if err != nil && err.Error() != utils.ErrNoRow() {
  465. br.Msg = "删除失败"
  466. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  467. return
  468. }
  469. if classifyCount > 0 {
  470. deleteStatus = 2
  471. tipsMsg = "确认删除当前目录及包含的子目录吗"
  472. }
  473. }
  474. if deleteStatus == 0 {
  475. tipsMsg = "可删除,进行删除操作"
  476. }
  477. resp := new(models.ChartClassifyDeleteCheckResp)
  478. resp.DeleteStatus = deleteStatus
  479. resp.TipsMsg = tipsMsg
  480. br.Ret = 200
  481. br.Msg = "检测成功"
  482. br.Success = true
  483. br.Data = resp
  484. }
  485. // @Title 删除图表分类/图表
  486. // @Description 删除图表分类/图表接口
  487. // @Param request body models.DeleteChartClassifyReq true "type json string"
  488. // @Success 200 Ret=200 删除成功
  489. // @router /classify/delete [post]
  490. func (this *ChartClassifyController) DeleteChartClassify() {
  491. br := new(models.BaseResponse).Init()
  492. defer func() {
  493. this.Data["json"] = br
  494. this.ServeJSON()
  495. }()
  496. sysUser := this.SysUser
  497. if sysUser == nil {
  498. br.Msg = "请登录"
  499. br.ErrMsg = "请登录,SysUser Is Empty"
  500. br.Ret = 408
  501. return
  502. }
  503. var req models.DeleteChartClassifyReq
  504. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  505. if err != nil {
  506. br.Msg = "参数解析异常!"
  507. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  508. return
  509. }
  510. if req.ChartClassifyId < 0 {
  511. br.Msg = "参数错误"
  512. br.IsSendEmail = false
  513. return
  514. }
  515. //删除分类
  516. _, err = models.GetChartClassifyById(req.ChartClassifyId)
  517. if err != nil {
  518. if err.Error() == utils.ErrNoRow() {
  519. br.Msg = "分类不存在,请刷新"
  520. return
  521. }
  522. br.Msg = "操作失败"
  523. br.Msg = "获取分类信息失败,Err:" + err.Error()
  524. return
  525. }
  526. //判断是否含有指标
  527. count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  528. if err != nil && err.Error() != utils.ErrNoRow() {
  529. br.Msg = "删除失败"
  530. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  531. return
  532. }
  533. if count > 0 {
  534. br.Msg = "该目录下存在关联指标,不可删除"
  535. br.IsSendEmail = false
  536. return
  537. }
  538. err = models.DeleteChartClassify(req.ChartClassifyId)
  539. if err != nil {
  540. br.Msg = "删除失败"
  541. br.ErrMsg = "删除失败,Err:" + err.Error()
  542. return
  543. }
  544. resp := new(models.AddChartInfoResp)
  545. br.Ret = 200
  546. br.Msg = "删除成功"
  547. br.Success = true
  548. br.Data = resp
  549. br.IsAddLog = true
  550. }
  551. // ChartClassifyMove
  552. // @Title 图表分类移动接口
  553. // @Description 图表分类移动接口
  554. // @Success 200 {object} models.MoveChartClassifyReq
  555. // @router /classify/move [post]
  556. func (this *ChartClassifyController) ChartClassifyMove() {
  557. br := new(models.BaseResponse).Init()
  558. defer func() {
  559. if br.ErrMsg == "" {
  560. br.IsSendEmail = false
  561. }
  562. this.Data["json"] = br
  563. this.ServeJSON()
  564. }()
  565. sysUser := this.SysUser
  566. if sysUser == nil {
  567. br.Msg = "请登录"
  568. br.ErrMsg = "请登录,SysUser Is Empty"
  569. br.Ret = 408
  570. return
  571. }
  572. var req models.MoveChartClassifyReq
  573. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  574. if err != nil {
  575. br.Msg = "参数解析异常!"
  576. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  577. return
  578. }
  579. if req.ClassifyId <= 0 && req.ChartInfoId <= 0 {
  580. br.Msg = "参数错误"
  581. br.ErrMsg = "请选择分类或者图表"
  582. return
  583. }
  584. //判断分类是否存在
  585. /*chartClassifyInfo, err := models.GetChartClassifyById(req.ClassifyId)
  586. if err != nil {
  587. if err.Error() == utils.ErrNoRow() {
  588. br.Msg = "分类不存在,请刷新页面"
  589. return
  590. }
  591. br.Msg = "移动失败"
  592. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  593. return
  594. }
  595. // 校验移动的父级目录下是否有重名分类
  596. exists, e := models.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  597. if e != nil && e.Error() != utils.ErrNoRow() {
  598. br.Msg = "移动失败"
  599. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  600. return
  601. }
  602. if exists != nil {
  603. br.Msg = "移动失败,分类名称已存在"
  604. return
  605. }
  606. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  607. br.Msg = "分类异常"
  608. br.ErrMsg = "分类异常,不是ETA图库的分类"
  609. return
  610. }
  611. updateCol := make([]string, 0)
  612. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  613. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  614. parentChartClassifyInfo, err := models.GetChartClassifyById(req.ParentClassifyId)
  615. if err != nil {
  616. br.Msg = "移动失败"
  617. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  618. return
  619. }
  620. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  621. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  622. chartClassifyInfo.ModifyTime = time.Now()
  623. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  624. }
  625. //如果有传入 上一个兄弟节点分类id
  626. if req.PrevClassifyId > 0 {
  627. //上一个兄弟节点
  628. prevClassify, err := models.GetChartClassifyById(req.PrevClassifyId)
  629. if err != nil {
  630. br.Msg = "移动失败"
  631. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  632. return
  633. }
  634. //如果是移动在两个兄弟节点之间
  635. if req.NextClassifyId > 0 {
  636. //下一个兄弟节点
  637. nextClassify, err := models.GetChartClassifyById(req.NextClassifyId)
  638. if err != nil {
  639. br.Msg = "移动失败"
  640. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  641. return
  642. }
  643. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  644. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  645. //变更兄弟节点的排序
  646. updateSortStr := `sort + 2`
  647. _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  648. } else {
  649. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  650. if nextClassify.Sort-prevClassify.Sort == 1 {
  651. //变更兄弟节点的排序
  652. updateSortStr := `sort + 1`
  653. _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  654. }
  655. }
  656. }
  657. chartClassifyInfo.Sort = prevClassify.Sort + 1
  658. chartClassifyInfo.ModifyTime = time.Now()
  659. updateCol = append(updateCol, "Sort", "ModifyTime")
  660. } else {
  661. firstClassify, err := models.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  662. if err != nil && err.Error() != utils.ErrNoRow() {
  663. br.Msg = "移动失败"
  664. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  665. return
  666. }
  667. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  668. if firstClassify != nil && firstClassify.Sort == 0 {
  669. updateSortStr := ` sort + 1 `
  670. _ = models.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  671. }
  672. chartClassifyInfo.Sort = 0 //那就是排在第一位
  673. chartClassifyInfo.ModifyTime = time.Now()
  674. updateCol = append(updateCol, "Sort", "ModifyTime")
  675. }
  676. //更新
  677. if len(updateCol) > 0 {
  678. err = chartClassifyInfo.Update(updateCol)
  679. if err != nil {
  680. br.Msg = "移动失败"
  681. br.ErrMsg = "修改失败,Err:" + err.Error()
  682. return
  683. }
  684. }*/
  685. err, errMsg := services.MoveChartClassify(req, sysUser, 0)
  686. if errMsg != `` {
  687. br.Msg = errMsg
  688. br.ErrMsg = errMsg
  689. if err != nil {
  690. br.ErrMsg = err.Error()
  691. } else {
  692. br.IsSendEmail = false
  693. }
  694. return
  695. }
  696. br.Ret = 200
  697. br.Success = true
  698. br.Msg = "移动成功"
  699. }
  700. // getChartClassifyListForMe 获取我创建的图表分类
  701. func getChartClassifyListForMeV2(adminInfo system.Admin, resp *models.ChartClassifyListResp) (errMsg string, err error) {
  702. rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  703. if err != nil && err.Error() != utils.ErrNoRow() {
  704. errMsg = "获取失败"
  705. return
  706. }
  707. classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  708. if err != nil && err.Error() != utils.ErrNoRow() {
  709. errMsg = "获取失败"
  710. return
  711. }
  712. rootChildMap := make(map[int][]*models.ChartClassifyItems)
  713. for _, v := range classifyAll {
  714. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  715. }
  716. nodeAll := make([]*models.ChartClassifyItems, 0)
  717. for _, v := range rootList {
  718. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  719. v.Children = existItems
  720. } else {
  721. items := make([]*models.ChartClassifyItems, 0)
  722. v.Children = items
  723. }
  724. nodeAll = append(nodeAll, v)
  725. }
  726. resp.AllNodes = nodeAll
  727. return
  728. }
  729. // ChartClassifyChartListV2
  730. // @Title 根据图表分类获取图表列表
  731. // @Description 根据图表分类获取图表列表接口
  732. // @Param SysUserIds query string true "根据创建人查询"
  733. // @Param ChartClassifyId query bool true "图片分类id"
  734. // @Success 200 {object} models.ChartClassifyListResp
  735. // @router /classify/chart_list [get]
  736. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  737. br := new(models.BaseResponse).Init()
  738. defer func() {
  739. this.Data["json"] = br
  740. this.ServeJSON()
  741. }()
  742. sysUser := this.SysUser
  743. if sysUser == nil {
  744. br.Msg = "请登录"
  745. br.ErrMsg = "请登录,SysUser Is Empty"
  746. br.Ret = 408
  747. return
  748. }
  749. resp := new(models.ChartClassifyListResp)
  750. pageSize, _ := this.GetInt("PageSize")
  751. currentIndex, _ := this.GetInt("CurrentIndex")
  752. sysUserIds := this.GetString("SysUserIds")
  753. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  754. if chartClassifyId < 0 && chartClassifyId != -1 {
  755. br.Msg = "参数错误"
  756. return
  757. }
  758. var startSize int
  759. if pageSize <= 0 {
  760. pageSize = utils.PageSize20
  761. }
  762. if currentIndex <= 0 {
  763. currentIndex = 1
  764. }
  765. startSize = utils.StartIndex(currentIndex, pageSize)
  766. condition := ""
  767. pars := make([]interface{}, 0)
  768. if sysUserIds != "" {
  769. adminIds := strings.Split(sysUserIds, ",")
  770. if len(adminIds) == 0 {
  771. br.Msg = "请选择正确的创建人"
  772. return
  773. }
  774. adminIdsSlice := make([]int, 0)
  775. for _, adminId := range adminIds {
  776. adminIdInt, e := strconv.Atoi(adminId)
  777. if e != nil {
  778. br.Msg = "请选择正确的创建人"
  779. return
  780. }
  781. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  782. }
  783. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  784. pars = append(pars, adminIdsSlice)
  785. }
  786. if chartClassifyId > 0 {
  787. // 查询所有子分类
  788. childClassify, e, _ := services.GetChildClassifyByClassifyId(chartClassifyId)
  789. if e != nil && e.Error() != utils.ErrNoRow() {
  790. br.Msg = "获取失败"
  791. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  792. return
  793. }
  794. var classifyIds []int
  795. for _, v := range childClassify {
  796. classifyIds = append(classifyIds, v.ChartClassifyId)
  797. }
  798. condition += fmt.Sprintf(` AND chart_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  799. pars = append(pars, classifyIds)
  800. } else if chartClassifyId == 0 {
  801. condition += " AND chart_classify_id = ?"
  802. pars = append(pars, chartClassifyId)
  803. }
  804. allChartInfo, err := models.GetChartInfoByConditionPage(utils.CHART_SOURCE_DEFAULT, condition, pars, startSize, pageSize)
  805. if err != nil && err.Error() != utils.ErrNoRow() {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  808. return
  809. }
  810. total, err := models.GetChartInfoTotalByCondition(utils.CHART_SOURCE_DEFAULT, condition, pars)
  811. if err != nil {
  812. br.Msg = "获取失败"
  813. br.ErrMsg = "获取图表总数失败,Err:" + err.Error()
  814. return
  815. }
  816. if len(allChartInfo) > 0 {
  817. /*adminIds := make([]int, 0)
  818. for _, v := range allChartInfo {
  819. adminIds = append(adminIds, v.SysUserId)
  820. }
  821. adminCompanyMap, er := services.GetCompanyNameByAdmins(adminIds)
  822. if er != nil {
  823. br.Msg = "获取失败"
  824. br.ErrMsg = "获取机构失败,Err:" + er.Error()
  825. return
  826. }*/
  827. for k, v := range allChartInfo {
  828. v.Children = make([]*models.ChartClassifyItems, 0)
  829. //if n, ok := adminCompanyMap[v.SysUserId]; ok {
  830. allChartInfo[k].Company = utils.HzCompanyName
  831. //}
  832. }
  833. }
  834. page := paging.GetPaging(currentIndex, pageSize, int(total))
  835. resp.AllNodes = allChartInfo
  836. resp.Paging = page
  837. br.Ret = 200
  838. br.Success = true
  839. br.Msg = "获取成功"
  840. br.Data = resp
  841. }
  842. // ModifyChartClassify
  843. // @Title 批量修改图表分类
  844. // @Description 批量修改图表分类
  845. // @Param SysUserIds query string true "根据创建人查询"
  846. // @Param ChartClassifyIds query string true "图片分类id"
  847. // @Success 200 {object} models.ChartClassifyListResp
  848. // @router /modify_chart_classify [post]
  849. func (this *ChartClassifyController) ModifyChartClassify() {
  850. br := new(models.BaseResponse).Init()
  851. defer func() {
  852. this.Data["json"] = br
  853. this.ServeJSON()
  854. }()
  855. sysUser := this.SysUser
  856. if sysUser == nil {
  857. br.Msg = "请登录"
  858. br.ErrMsg = "请登录,SysUser Is Empty"
  859. br.Ret = 408
  860. return
  861. }
  862. var req models.ModifyChartClassifyReq
  863. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  864. if err != nil {
  865. br.Msg = "参数解析异常!"
  866. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  867. return
  868. }
  869. if !req.SelectAll && req.ChartInfoIds == "" {
  870. br.Msg = "请选择图表"
  871. return
  872. }
  873. if req.ChartClassifyId < 0 {
  874. br.Msg = "请选择新分类"
  875. return
  876. }
  877. var chartIds []int
  878. if req.SelectAll {
  879. //根据查询条件筛选
  880. chartClassifyIds := req.ChartClassifyIds
  881. sysUserIds := req.SysUserIds
  882. chartName := req.ChartName
  883. condition := " AND source = ? "
  884. pars := make([]interface{}, 0)
  885. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  886. if chartClassifyIds != "" {
  887. classifyIds := strings.Split(chartClassifyIds, ",")
  888. if len(classifyIds) == 0 {
  889. br.Msg = "请选择正确的分类"
  890. return
  891. }
  892. classifyIdSlice := make([]int, 0)
  893. for _, id := range classifyIds {
  894. tmp, e := strconv.Atoi(id)
  895. if e != nil {
  896. br.Msg = "请选择正确的分类"
  897. return
  898. }
  899. classifyIdSlice = append(classifyIdSlice, tmp)
  900. }
  901. condition += " AND chart_classify_id in (" + utils.GetOrmInReplace(len(classifyIdSlice)) + ") "
  902. pars = append(pars, classifyIdSlice)
  903. }
  904. if sysUserIds != "" {
  905. adminIds := strings.Split(sysUserIds, ",")
  906. if len(adminIds) == 0 {
  907. br.Msg = "请选择正确的创建人"
  908. return
  909. }
  910. adminIdsSlice := make([]int, 0)
  911. for _, adminId := range adminIds {
  912. adminIdInt, e := strconv.Atoi(adminId)
  913. if e != nil {
  914. br.Msg = "请选择正确的创建人"
  915. return
  916. }
  917. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  918. }
  919. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  920. pars = append(pars, adminIdsSlice)
  921. }
  922. if chartName != "" {
  923. condition = " AND chart_name LIKE ? "
  924. pars = append(pars, utils.GetLikeKeyword(chartName))
  925. }
  926. allChartInfo, err := models.GetChartInfoItemsByCondition(condition, pars)
  927. if err != nil {
  928. br.Msg = "获取失败"
  929. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  930. return
  931. }
  932. // 判断是否超过100 个
  933. if len(allChartInfo) > 100 {
  934. br.Msg = "最多只能选择100个图表"
  935. return
  936. }
  937. for _, v := range allChartInfo {
  938. chartIds = append(chartIds, v.ChartInfoId)
  939. }
  940. } else {
  941. chartIdStr := strings.Split(req.ChartInfoIds, ",")
  942. if len(chartIdStr) == 0 {
  943. br.Msg = "请选择正确的图表"
  944. return
  945. }
  946. for _, id := range chartIdStr {
  947. tmp, e := strconv.Atoi(id)
  948. if e != nil {
  949. br.Msg = "请选择正确的分类"
  950. return
  951. }
  952. chartIds = append(chartIds, tmp)
  953. }
  954. // 判断是否超过100 个
  955. if len(chartIds) > 100 {
  956. br.Msg = "最多只能选择100个图表"
  957. return
  958. }
  959. }
  960. if len(chartIds) == 0 {
  961. br.Msg = "请选择正确的图表"
  962. return
  963. }
  964. err = models.UpdateChartClassifyIdByChartInfoId(chartIds, req.ChartClassifyId)
  965. if err != nil {
  966. br.Msg = "更新失败"
  967. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  968. return
  969. }
  970. br.Ret = 200
  971. br.Success = true
  972. br.Msg = "操作成功"
  973. }
  974. // ClassifyTree
  975. // @Title 多层分类列表树
  976. // @Description 多层分类列表树
  977. // @Success 200 {object} data_manage.EdbClassifyListResp
  978. // @router /classify/tree [get]
  979. func (this *ChartClassifyController) ClassifyTree() {
  980. br := new(models.BaseResponse).Init()
  981. defer func() {
  982. this.Data["json"] = br
  983. this.ServeJSON()
  984. }()
  985. allList, err := models.GetChartClassify()
  986. if err != nil && err.Error() != utils.ErrNoRow() {
  987. br.Msg = "获取失败"
  988. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  989. return
  990. }
  991. nodeAll := make([]*models.ChartClassifyItems, 0)
  992. list := make([]*models.ChartClassifyItems, 0)
  993. var sortList models.ChartClassifyItemList
  994. if len(allList) > 0 {
  995. nodeAll = services.GetClassifyTreeRecursive(allList, 0)
  996. //根据sort值排序
  997. sortList = nodeAll
  998. sort.Sort(sortList)
  999. }
  1000. language := `CN`
  1001. // 指标显示的语言
  1002. {
  1003. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1004. if configDetail != nil {
  1005. language = configDetail.ConfigValue
  1006. } else {
  1007. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1008. if configDetail != nil {
  1009. language = configDetail.ConfigValue
  1010. }
  1011. }
  1012. }
  1013. initClassify := &models.ChartClassifyItems{
  1014. ChartClassifyId: 0,
  1015. ChartInfoId: 0,
  1016. ChartClassifyName: "未分类",
  1017. ChartClassifyNameEn: "",
  1018. ParentId: 0,
  1019. Level: 1,
  1020. Sort: 0,
  1021. }
  1022. list = append(list, initClassify)
  1023. list = append(list, sortList...)
  1024. resp := new(models.ChartClassifyListResp)
  1025. resp.AllNodes = list
  1026. resp.Language = language
  1027. br.Ret = 200
  1028. br.Success = true
  1029. br.Msg = "获取成功"
  1030. br.Data = resp
  1031. }
  1032. // ClassifyRealTree
  1033. // @Title 多层分类列表树
  1034. // @Description 多层分类列表树
  1035. // @Success 200 {object} data_manage.EdbClassifyListResp
  1036. // @router /classify/real_tree [get]
  1037. func (this *ChartClassifyController) ClassifyRealTree() {
  1038. br := new(models.BaseResponse).Init()
  1039. defer func() {
  1040. this.Data["json"] = br
  1041. this.ServeJSON()
  1042. }()
  1043. allList, err := models.GetChartClassify()
  1044. if err != nil && err.Error() != utils.ErrNoRow() {
  1045. br.Msg = "获取失败"
  1046. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1047. return
  1048. }
  1049. nodeAll := make([]*models.ChartClassifyItems, 0)
  1050. list := make([]*models.ChartClassifyItems, 0)
  1051. var sortList models.ChartClassifyItemList
  1052. if len(allList) > 0 {
  1053. nodeAll = services.GetClassifyTreeRecursive(allList, 0)
  1054. //根据sort值排序
  1055. sortList = nodeAll
  1056. sort.Sort(sortList)
  1057. }
  1058. language := `CN`
  1059. // 指标显示的语言
  1060. {
  1061. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1062. if configDetail != nil {
  1063. language = configDetail.ConfigValue
  1064. } else {
  1065. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1066. if configDetail != nil {
  1067. language = configDetail.ConfigValue
  1068. }
  1069. }
  1070. }
  1071. list = append(list, sortList...)
  1072. resp := new(models.ChartClassifyListResp)
  1073. resp.AllNodes = list
  1074. resp.Language = language
  1075. br.Ret = 200
  1076. br.Success = true
  1077. br.Msg = "获取成功"
  1078. br.Data = resp
  1079. }