chart_classify.go 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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 = n
  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. condition += " AND chart_classify_id = ?"
  788. pars = append(pars, chartClassifyId)
  789. }
  790. allChartInfo, err := models.GetChartInfoByConditionPage(utils.CHART_SOURCE_DEFAULT, condition, pars, startSize, pageSize)
  791. if err != nil && err.Error() != utils.ErrNoRow() {
  792. br.Msg = "获取失败"
  793. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  794. return
  795. }
  796. total, err := models.GetChartInfoTotalByCondition(utils.CHART_SOURCE_DEFAULT, condition, pars)
  797. if err != nil {
  798. br.Msg = "获取失败"
  799. br.ErrMsg = "获取图表总数失败,Err:" + err.Error()
  800. return
  801. }
  802. if len(allChartInfo) > 0 {
  803. adminIds := make([]int, 0)
  804. for _, v := range allChartInfo {
  805. adminIds = append(adminIds, v.SysUserId)
  806. }
  807. adminCompanyMap, er := services.GetCompanyNameByAdmins(adminIds)
  808. if er != nil {
  809. br.Msg = "获取失败"
  810. br.ErrMsg = "获取机构失败,Err:" + er.Error()
  811. return
  812. }
  813. for k, v := range allChartInfo {
  814. v.Children = make([]*models.ChartClassifyItems, 0)
  815. if n, ok := adminCompanyMap[v.SysUserId]; ok {
  816. allChartInfo[k].Company = n
  817. }
  818. }
  819. }
  820. page := paging.GetPaging(currentIndex, pageSize, int(total))
  821. resp.AllNodes = allChartInfo
  822. resp.Paging = page
  823. br.Ret = 200
  824. br.Success = true
  825. br.Msg = "获取成功"
  826. br.Data = resp
  827. }
  828. // ModifyChartClassify
  829. // @Title 批量修改图表分类
  830. // @Description 批量修改图表分类
  831. // @Param SysUserIds query string true "根据创建人查询"
  832. // @Param ChartClassifyIds query string true "图片分类id"
  833. // @Success 200 {object} models.ChartClassifyListResp
  834. // @router /modify_chart_classify [post]
  835. func (this *ChartClassifyController) ModifyChartClassify() {
  836. br := new(models.BaseResponse).Init()
  837. defer func() {
  838. this.Data["json"] = br
  839. this.ServeJSON()
  840. }()
  841. sysUser := this.SysUser
  842. if sysUser == nil {
  843. br.Msg = "请登录"
  844. br.ErrMsg = "请登录,SysUser Is Empty"
  845. br.Ret = 408
  846. return
  847. }
  848. var req models.ModifyChartClassifyReq
  849. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  850. if err != nil {
  851. br.Msg = "参数解析异常!"
  852. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  853. return
  854. }
  855. if !req.SelectAll && req.ChartInfoIds == "" {
  856. br.Msg = "请选择图表"
  857. return
  858. }
  859. if req.ChartClassifyId < 0 {
  860. br.Msg = "请选择新分类"
  861. return
  862. }
  863. var chartIds []int
  864. if req.SelectAll {
  865. //根据查询条件筛选
  866. chartClassifyIds := req.ChartClassifyIds
  867. sysUserIds := req.SysUserIds
  868. chartName := req.ChartName
  869. condition := " AND source = ? "
  870. pars := make([]interface{}, 0)
  871. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  872. if chartClassifyIds != "" {
  873. classifyIds := strings.Split(chartClassifyIds, ",")
  874. if len(classifyIds) == 0 {
  875. br.Msg = "请选择正确的分类"
  876. return
  877. }
  878. classifyIdSlice := make([]int, 0)
  879. for _, id := range classifyIds {
  880. tmp, e := strconv.Atoi(id)
  881. if e != nil {
  882. br.Msg = "请选择正确的分类"
  883. return
  884. }
  885. classifyIdSlice = append(classifyIdSlice, tmp)
  886. }
  887. condition += " AND chart_classify_id in (" + utils.GetOrmInReplace(len(classifyIdSlice)) + ") "
  888. pars = append(pars, classifyIdSlice)
  889. }
  890. if sysUserIds != "" {
  891. adminIds := strings.Split(sysUserIds, ",")
  892. if len(adminIds) == 0 {
  893. br.Msg = "请选择正确的创建人"
  894. return
  895. }
  896. adminIdsSlice := make([]int, 0)
  897. for _, adminId := range adminIds {
  898. adminIdInt, e := strconv.Atoi(adminId)
  899. if e != nil {
  900. br.Msg = "请选择正确的创建人"
  901. return
  902. }
  903. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  904. }
  905. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  906. pars = append(pars, adminIdsSlice)
  907. }
  908. if chartName != "" {
  909. condition = " AND chart_name LIKE ? "
  910. pars = append(pars, utils.GetLikeKeyword(chartName))
  911. }
  912. allChartInfo, err := models.GetChartInfoItemsByCondition(condition, pars)
  913. if err != nil {
  914. br.Msg = "获取失败"
  915. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  916. return
  917. }
  918. // 判断是否超过100 个
  919. if len(allChartInfo) > 100 {
  920. br.Msg = "最多只能选择100个图表"
  921. return
  922. }
  923. for _, v := range allChartInfo {
  924. chartIds = append(chartIds, v.ChartInfoId)
  925. }
  926. } else {
  927. chartIdStr := strings.Split(req.ChartInfoIds, ",")
  928. if len(chartIdStr) == 0 {
  929. br.Msg = "请选择正确的图表"
  930. return
  931. }
  932. for _, id := range chartIdStr {
  933. tmp, e := strconv.Atoi(id)
  934. if e != nil {
  935. br.Msg = "请选择正确的分类"
  936. return
  937. }
  938. chartIds = append(chartIds, tmp)
  939. }
  940. // 判断是否超过100 个
  941. if len(chartIds) > 100 {
  942. br.Msg = "最多只能选择100个图表"
  943. return
  944. }
  945. }
  946. if len(chartIds) == 0 {
  947. br.Msg = "请选择正确的图表"
  948. return
  949. }
  950. err = models.UpdateChartClassifyIdByChartInfoId(chartIds, req.ChartClassifyId)
  951. if err != nil {
  952. br.Msg = "更新失败"
  953. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  954. return
  955. }
  956. br.Ret = 200
  957. br.Success = true
  958. br.Msg = "操作成功"
  959. }