edb_classify.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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/utils"
  10. )
  11. // EdbClassifyController 数据管理-分类模块
  12. type EdbClassifyController struct {
  13. controllers.BaseAuthController
  14. }
  15. //
  16. //// @Title 分类列表
  17. //// @Description 分类列表接口
  18. //// @Success 200 {object} data_manage.EdbClassifyListResp
  19. //// @router /classify/list [get]
  20. //func (this *EdbClassifyController) List() {
  21. // br := new(models.BaseResponse).Init()
  22. // defer func() {
  23. // this.Data["json"] = br
  24. // this.ServeJSON()
  25. // }()
  26. // rootList, err := data_manage.GetEdbClassifyByParentId(0)
  27. // if err != nil {
  28. // br.Msg = "获取失败"
  29. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  30. // return
  31. // }
  32. //
  33. // classifyAll, err := data_manage.GetEdbClassifyAll()
  34. // if err != nil {
  35. // br.Msg = "获取失败"
  36. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  37. // return
  38. // }
  39. //
  40. // fmt.Println("start:", time.Now())
  41. // nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  42. // for k := range rootList {
  43. // rootNode := rootList[k]
  44. // data.EdbClassifyListMakeTree(classifyAll, rootNode)
  45. // nodeAll = append(nodeAll, rootNode)
  46. // }
  47. // fmt.Println("end:", time.Now())
  48. // resp := new(data_manage.EdbClassifyListResp)
  49. // resp.AllNodes = nodeAll
  50. // br.Ret = 200
  51. // br.Success = true
  52. // br.Msg = "获取成功"
  53. // br.Data = resp
  54. //}
  55. // ListV2
  56. // @Title 分类列表
  57. // @Description 分类列表接口
  58. // @Success 200 {object} data_manage.EdbClassifyListResp
  59. // @router /classify/list [get]
  60. func (this *EdbClassifyController) ListV2() {
  61. br := new(models.BaseResponse).Init()
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  67. if err != nil && err.Error() != utils.ErrNoRow() {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  70. return
  71. }
  72. classifyAll, err := data_manage.GetEdbClassifyAll()
  73. if err != nil && err.Error() != utils.ErrNoRow() {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  76. return
  77. }
  78. // 获取当前账号的不可见指标
  79. obj := data_manage.EdbInfoNoPermissionAdmin{}
  80. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  81. if err != nil && err.Error() != utils.ErrNoRow() {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  84. return
  85. }
  86. noPermissionEdbInfoIdMap := make(map[int]bool)
  87. for _, v := range confList {
  88. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  89. }
  90. allEdbInfo, err := data_manage.GetEdbInfoAll(utils.EDB_INFO_TYPE)
  91. if err != nil && err.Error() != utils.ErrNoRow() {
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  94. return
  95. }
  96. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  97. for _, v := range allEdbInfo {
  98. // 如果指标不可见,那么就不返回该指标
  99. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  100. continue
  101. }
  102. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
  103. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  104. v.Button = button
  105. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  106. }
  107. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  108. for _, v := range classifyAll {
  109. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  110. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  111. v.Button = button
  112. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  113. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  114. v.Children = existItems
  115. } else {
  116. items := make([]*data_manage.EdbClassifyItems, 0)
  117. v.Children = items
  118. }
  119. }
  120. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  121. for _, v := range rootList {
  122. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  123. v.Button = button
  124. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  125. v.Children = existItems
  126. } else {
  127. items := make([]*data_manage.EdbClassifyItems, 0)
  128. v.Children = items
  129. }
  130. nodeAll = append(nodeAll, v)
  131. }
  132. resp := new(data_manage.EdbClassifyListResp)
  133. resp.AllNodes = nodeAll
  134. resp.CanOpClassify = true
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = resp
  139. }
  140. // @Title 获取所有分类接口-不包含指标
  141. // @Description 获取所有分类接口-不包含指标
  142. // @Success 200 {object} data_manage.EdbClassifyListResp
  143. // @router /classify/items [get]
  144. func (this *EdbClassifyController) Items() {
  145. br := new(models.BaseResponse).Init()
  146. defer func() {
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  151. if err != nil {
  152. br.Msg = "获取失败"
  153. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  154. return
  155. }
  156. classifyAll, err := data_manage.GetEdbClassifyAll()
  157. if err != nil {
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  160. return
  161. }
  162. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  163. for k := range rootList {
  164. rootNode := rootList[k]
  165. data.EdbClassifyItemsMakeTree(classifyAll, rootNode)
  166. nodeAll = append(nodeAll, rootNode)
  167. }
  168. resp := new(data_manage.EdbClassifyListResp)
  169. resp.AllNodes = nodeAll
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "获取成功"
  173. br.Data = resp
  174. }
  175. // @Title 新增分类
  176. // @Description 新增分类接口
  177. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  178. // @Success 200 Ret=200 保存成功
  179. // @router /classify/add [post]
  180. func (this *EdbClassifyController) AddEdbClassify() {
  181. br := new(models.BaseResponse).Init()
  182. defer func() {
  183. this.Data["json"] = br
  184. this.ServeJSON()
  185. }()
  186. var req data_manage.AddEdbClassifyReq
  187. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  188. if err != nil {
  189. br.Msg = "参数解析异常!"
  190. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  191. return
  192. }
  193. if req.ClassifyName == "" {
  194. br.Msg = "请输入分类名称"
  195. br.IsSendEmail = false
  196. return
  197. }
  198. if req.ParentId < 0 {
  199. br.Msg = "参数错误"
  200. br.IsSendEmail = false
  201. return
  202. }
  203. //添加指标
  204. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 0, this.SysUser.AdminId, this.SysUser.AdminName)
  205. if errMsg != `` {
  206. br.Msg = errMsg
  207. br.ErrMsg = errMsg
  208. if err != nil {
  209. br.ErrMsg = errMsg + ";Err:" + err.Error()
  210. } else {
  211. br.IsSendEmail = false
  212. }
  213. return
  214. }
  215. //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
  216. //if err != nil {
  217. // br.Msg = "判断名称是否已存在失败"
  218. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  219. // return
  220. //}
  221. //if count > 0 {
  222. // br.Msg = "分类名称已存在,请重新输入"
  223. // br.IsSendEmail = false
  224. // return
  225. //}
  226. ////获取该层级下最大的排序数
  227. //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
  228. //
  229. //classify := new(data_manage.EdbClassify)
  230. //classify.ClassifyType = req.ClassifyType
  231. //classify.ParentId = req.ParentId
  232. //classify.ClassifyName = req.ClassifyName
  233. //classify.HasData = 0
  234. //classify.CreateTime = time.Now()
  235. //classify.ModifyTime = time.Now()
  236. //classify.SysUserId = this.SysUser.AdminId
  237. //classify.SysUserRealName = this.SysUser.RealName
  238. //classify.Level = req.Level + 1
  239. //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  240. //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  241. //classify.Sort = maxSort
  242. //
  243. //_, err = data_manage.AddEdbClassify(classify)
  244. //if err != nil {
  245. // br.Msg = "保存分类失败"
  246. // br.ErrMsg = "保存分类失败,Err:" + err.Error()
  247. // return
  248. //}
  249. br.Ret = 200
  250. br.Msg = "保存成功"
  251. br.Success = true
  252. br.IsAddLog = true
  253. }
  254. // @Title 修改分类
  255. // @Description 修改分类接口
  256. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  257. // @Success 200 Ret=200 修改成功
  258. // @router /classify/edit [post]
  259. func (this *EdbClassifyController) EditEdbClassify() {
  260. br := new(models.BaseResponse).Init()
  261. defer func() {
  262. this.Data["json"] = br
  263. this.ServeJSON()
  264. }()
  265. var req data_manage.EditEdbClassifyReq
  266. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  267. if err != nil {
  268. br.Msg = "参数解析异常!"
  269. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  270. return
  271. }
  272. if req.ClassifyName == "" {
  273. br.Msg = "请输入分类名称"
  274. br.IsSendEmail = false
  275. return
  276. }
  277. if req.ClassifyId < 0 {
  278. br.Msg = "参数错误"
  279. br.IsSendEmail = false
  280. return
  281. }
  282. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.SysUser)
  283. if errMsg != `` {
  284. br.Msg = errMsg
  285. br.ErrMsg = errMsg
  286. if err != nil {
  287. br.ErrMsg = errMsg + ";Err:" + err.Error()
  288. } else {
  289. br.IsSendEmail = false
  290. }
  291. return
  292. }
  293. //item, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  294. //if err != nil {
  295. // br.Msg = "保存失败"
  296. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  297. // return
  298. //}
  299. //
  300. //if item.ClassifyName != req.ClassifyName {
  301. // count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, item.ParentId)
  302. // if err != nil {
  303. // br.Msg = "判断名称是否已存在失败"
  304. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  305. // return
  306. // }
  307. // if count > 0 {
  308. // br.Msg = "分类名称已存在,请重新输入"
  309. // br.IsSendEmail = false
  310. // return
  311. // }
  312. //
  313. // err = data_manage.EditEdbClassify(req.ClassifyId, req.ClassifyName)
  314. // if err != nil {
  315. // br.Msg = "保存失败"
  316. // br.ErrMsg = "保存失败,Err:" + err.Error()
  317. // return
  318. // }
  319. //}
  320. br.Ret = 200
  321. br.Msg = "保存成功"
  322. br.Success = true
  323. }
  324. // @Title 删除检测接口
  325. // @Description 删除检测接口
  326. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  327. // @Success 200 Ret=200 检测成功
  328. // @router /classify/delete/check [post]
  329. func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
  330. br := new(models.BaseResponse).Init()
  331. defer func() {
  332. this.Data["json"] = br
  333. this.ServeJSON()
  334. }()
  335. var req data_manage.ClassifyDeleteCheckReq
  336. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  337. if err != nil {
  338. br.Msg = "参数解析异常!"
  339. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  340. return
  341. }
  342. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  343. br.Msg = "参数错误"
  344. br.IsSendEmail = false
  345. return
  346. }
  347. deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  348. if errMsg != `` {
  349. br.Msg = errMsg
  350. br.ErrMsg = errMsg
  351. if err != nil {
  352. br.ErrMsg = err.Error()
  353. } else {
  354. br.IsSendEmail = false
  355. }
  356. return
  357. }
  358. //var deleteStatus int
  359. //var tipsMsg string
  360. ////删除分类
  361. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  362. // //判断分类下,是否含有指标
  363. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  364. // if err != nil {
  365. // br.Msg = "删除失败"
  366. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  367. // return
  368. // }
  369. //
  370. // if count > 0 {
  371. // deleteStatus = 1
  372. // tipsMsg = "若目录关联指标不可删除"
  373. // }
  374. //}
  375. //
  376. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  377. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  378. // if err != nil && err.Error() != utils.ErrNoRow() {
  379. // br.Msg = "删除失败"
  380. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  381. // return
  382. // }
  383. // if classifyCount > 0 {
  384. // deleteStatus = 2
  385. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  386. // }
  387. //}
  388. //
  389. ////删除指标
  390. //if req.EdbInfoId > 0 {
  391. // //判断指标是否用于作图,如果用于作图,则不可删除
  392. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  393. // if err != nil && err.Error() != utils.ErrNoRow() {
  394. // br.Msg = "删除失败"
  395. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  396. // return
  397. // }
  398. // if chartCount > 0 {
  399. // deleteStatus = 3
  400. // tipsMsg = "当前指标已用作画图,不可删除"
  401. // }
  402. // //判断指标是否用于计算
  403. // {
  404. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  405. // if err != nil && err.Error() != utils.ErrNoRow() {
  406. // br.Msg = "删除失败"
  407. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  408. // return
  409. // }
  410. // if calculateCount > 0 {
  411. // deleteStatus = 4
  412. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  413. // }
  414. // }
  415. //}
  416. resp := new(data_manage.ClassifyDeleteCheckResp)
  417. resp.DeleteStatus = deleteStatus
  418. resp.TipsMsg = tipsMsg
  419. br.Ret = 200
  420. br.Msg = "检测成功"
  421. br.Success = true
  422. br.Data = resp
  423. }
  424. // @Title 删除分类/指标
  425. // @Description 删除分类/指标接口
  426. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  427. // @Success 200 Ret=200 新增成功
  428. // @router /classify/delete [post]
  429. func (this *EdbClassifyController) DeleteEdbClassify() {
  430. br := new(models.BaseResponse).Init()
  431. defer func() {
  432. this.Data["json"] = br
  433. this.ServeJSON()
  434. }()
  435. sysUser := this.SysUser
  436. if sysUser == nil {
  437. br.Msg = "请登录"
  438. br.ErrMsg = "请登录,SysUser Is Empty"
  439. br.Ret = 408
  440. return
  441. }
  442. var req data_manage.DeleteEdbClassifyReq
  443. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  444. if err != nil {
  445. br.Msg = "参数解析异常!"
  446. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  447. return
  448. }
  449. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  450. br.Msg = "参数错误"
  451. br.IsSendEmail = false
  452. return
  453. }
  454. nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  455. if errMsg != `` {
  456. br.Msg = errMsg
  457. br.ErrMsg = errMsg
  458. if err != nil {
  459. br.ErrMsg = err.Error()
  460. } else {
  461. br.IsSendEmail = false
  462. }
  463. return
  464. }
  465. resp := data_manage.AddEdbInfoResp{}
  466. if nextItem != nil {
  467. resp = data_manage.AddEdbInfoResp{
  468. EdbInfoId: nextItem.EdbInfoId,
  469. UniqueCode: nextItem.UniqueCode,
  470. }
  471. }
  472. br.Ret = 200
  473. br.Msg = "删除成功"
  474. br.Success = true
  475. br.IsAddLog = true
  476. br.Data = resp
  477. }
  478. // EdbClassifyMove
  479. // @Title 分类移动接口
  480. // @Description 分类移动接口
  481. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  482. // @router /edb_classify/move [post]
  483. func (this *EdbClassifyController) EdbClassifyMove() {
  484. br := new(models.BaseResponse).Init()
  485. defer func() {
  486. this.Data["json"] = br
  487. this.ServeJSON()
  488. }()
  489. sysUser := this.SysUser
  490. if sysUser == nil {
  491. br.Msg = "请登录"
  492. br.ErrMsg = "请登录,SysUser Is Empty"
  493. br.Ret = 408
  494. return
  495. }
  496. var req data_manage.MoveEdbClassifyReq
  497. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  498. if err != nil {
  499. br.Msg = "参数解析异常!"
  500. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  501. return
  502. }
  503. if req.ClassifyId <= 0 {
  504. br.Msg = "参数错误"
  505. br.ErrMsg = "分类id小于等于0"
  506. return
  507. }
  508. err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId, sysUser)
  509. if errMsg != `` {
  510. br.Msg = errMsg
  511. br.ErrMsg = errMsg
  512. if err != nil {
  513. br.ErrMsg = err.Error()
  514. } else {
  515. br.IsSendEmail = false
  516. }
  517. return
  518. }
  519. ////判断分类是否存在
  520. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  521. //if err != nil {
  522. // br.Msg = "移动失败"
  523. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  524. // return
  525. //}
  526. //updateCol := make([]string, 0)
  527. //
  528. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  529. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  530. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  531. // if err != nil {
  532. // br.Msg = "移动失败"
  533. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  534. // return
  535. // }
  536. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  537. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  538. // edbClassifyInfo.ModifyTime = time.Now()
  539. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  540. //}
  541. //
  542. ////如果有传入 上一个兄弟节点分类id
  543. //if req.PrevClassifyId > 0 {
  544. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  545. // if err != nil {
  546. // br.Msg = "移动失败"
  547. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  548. // return
  549. // }
  550. //
  551. // //如果是移动在两个兄弟节点之间
  552. // if req.NextClassifyId > 0 {
  553. // //下一个兄弟节点
  554. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  555. // if err != nil {
  556. // br.Msg = "移动失败"
  557. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  558. // return
  559. // }
  560. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  561. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  562. // //变更兄弟节点的排序
  563. // updateSortStr := `sort + 2`
  564. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  565. // } else {
  566. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  567. // if nextClassify.Sort-prevClassify.Sort == 1 {
  568. // //变更兄弟节点的排序
  569. // updateSortStr := `sort + 1`
  570. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  571. // }
  572. // }
  573. // }
  574. //
  575. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  576. // edbClassifyInfo.ModifyTime = time.Now()
  577. // updateCol = append(updateCol, "Sort", "ModifyTime")
  578. //} else {
  579. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  580. // if err != nil && err.Error() != utils.ErrNoRow() {
  581. // br.Msg = "移动失败"
  582. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  583. // return
  584. // }
  585. //
  586. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  587. // if firstClassify != nil && firstClassify.Sort == 0 {
  588. // updateSortStr := ` sort + 1 `
  589. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  590. // }
  591. //
  592. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  593. // edbClassifyInfo.ModifyTime = time.Now()
  594. // updateCol = append(updateCol, "Sort", "ModifyTime")
  595. //}
  596. //
  597. ////更新
  598. //if len(updateCol) > 0 {
  599. // err = edbClassifyInfo.Update(updateCol)
  600. // if err != nil {
  601. // br.Msg = "移动失败"
  602. // br.ErrMsg = "修改失败,Err:" + err.Error()
  603. // return
  604. // }
  605. //}
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "移动成功"
  609. }
  610. // ItemsV2
  611. // @Title 分类列表
  612. // @Description 分类列表接口
  613. // @Success 200 {object} data_manage.EdbClassifyListResp
  614. // @router /classify/items/v2 [get]
  615. func (this *EdbClassifyController) ItemsV2() {
  616. br := new(models.BaseResponse).Init()
  617. defer func() {
  618. this.Data["json"] = br
  619. this.ServeJSON()
  620. }()
  621. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  622. if err != nil && err.Error() != utils.ErrNoRow() {
  623. br.Msg = "获取失败"
  624. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  625. return
  626. }
  627. classifyAll, err := data_manage.GetEdbClassifyAll()
  628. if err != nil && err.Error() != utils.ErrNoRow() {
  629. br.Msg = "获取失败"
  630. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  631. return
  632. }
  633. //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
  634. //if err != nil && err.Error() != utils.ErrNoRow() {
  635. // br.Msg = "获取失败"
  636. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  637. // return
  638. //}
  639. //edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  640. //for _, v := range allEdbInfo {
  641. // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
  642. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  643. // v.Button = button
  644. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  645. //}
  646. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  647. for _, v := range classifyAll {
  648. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  649. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  650. v.Button = button
  651. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  652. //if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  653. // v.Children = existItems
  654. //} else {
  655. // items := make([]*data_manage.EdbClassifyItems, 0)
  656. // v.Children = items
  657. //}
  658. }
  659. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  660. for _, v := range rootList {
  661. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  662. v.Button = button
  663. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  664. v.Children = existItems
  665. } else {
  666. items := make([]*data_manage.EdbClassifyItems, 0)
  667. v.Children = items
  668. }
  669. nodeAll = append(nodeAll, v)
  670. }
  671. language := `CN`
  672. // 指标显示的语言
  673. {
  674. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  675. if configDetail != nil {
  676. language = configDetail.ConfigValue
  677. } else {
  678. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  679. if configDetail != nil {
  680. language = configDetail.ConfigValue
  681. }
  682. }
  683. }
  684. // 是否允许添加一级分类
  685. canOpClassify := true
  686. //button := data.GetEdbClassifyOpButton(this.SysUser, 0)
  687. //if !button.AddButton {
  688. // canOpClassify = false
  689. //}
  690. resp := data_manage.EdbClassifyListResp{
  691. AllNodes: nodeAll,
  692. CanOpClassify: canOpClassify,
  693. Language: language,
  694. }
  695. br.Ret = 200
  696. br.Success = true
  697. br.Msg = "获取成功"
  698. br.Data = resp
  699. }
  700. // @Title 获取分类下指标接口
  701. // @Description 获取分类下指标接口
  702. // @Param ClassifyId query int true "分类id"
  703. // @Success 200 {object} data_manage.EdbClassifyListResp
  704. // @router /classify/edb_info/list [get]
  705. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  706. br := new(models.BaseResponse).Init()
  707. defer func() {
  708. this.Data["json"] = br
  709. this.ServeJSON()
  710. }()
  711. classifyId, _ := this.GetInt("ClassifyId")
  712. if classifyId <= 0 {
  713. br.Msg = "参数错误,请刷新页面"
  714. return
  715. }
  716. // 获取当前账号的不可见指标
  717. obj := data_manage.EdbInfoNoPermissionAdmin{}
  718. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  719. if err != nil && err.Error() != utils.ErrNoRow() {
  720. br.Msg = "获取失败"
  721. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  722. return
  723. }
  724. noPermissionEdbInfoIdMap := make(map[int]bool)
  725. for _, v := range confList {
  726. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  727. }
  728. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, 0)
  729. if err != nil && err.Error() != utils.ErrNoRow() {
  730. br.Msg = "获取失败"
  731. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  732. return
  733. }
  734. list := make([]*data_manage.EdbClassifyItems, 0)
  735. for _, v := range allEdbInfo {
  736. // 如果指标不可见,那么就不返回该指标
  737. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  738. continue
  739. }
  740. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
  741. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  742. v.Button = button
  743. list = append(list, v)
  744. }
  745. resp := new(data_manage.ClassifyEdbInfoListResp)
  746. resp.EdbInfoList = list
  747. br.Ret = 200
  748. br.Success = true
  749. br.Msg = "获取成功"
  750. br.Data = resp
  751. }
  752. // ItemsV3
  753. // @Title 分类列表
  754. // @Description 分类列表接口
  755. // @Success 200 {object} data_manage.EdbClassifyListResp
  756. // @router /classify/items/v3 [get]
  757. func (this *EdbClassifyController) ItemsV3() {
  758. br := new(models.BaseResponse).Init()
  759. defer func() {
  760. this.Data["json"] = br
  761. this.ServeJSON()
  762. }()
  763. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  764. if err != nil && err.Error() != utils.ErrNoRow() {
  765. br.Msg = "获取失败"
  766. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  767. return
  768. }
  769. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(0)
  770. if err != nil && err.Error() != utils.ErrNoRow() {
  771. br.Msg = "获取失败"
  772. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  773. return
  774. }
  775. classifyAll, err := data_manage.GetEdbClassifyAllV2(0)
  776. if err != nil && err.Error() != utils.ErrNoRow() {
  777. br.Msg = "获取失败"
  778. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  779. return
  780. }
  781. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  782. for _, v := range rootTwoList {
  783. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  784. v.Button = button
  785. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  786. }
  787. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  788. for _, v := range classifyAll {
  789. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  790. v.Button = button
  791. if v.Level == 3 {
  792. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  793. }
  794. }
  795. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  796. for _, v := range rootList {
  797. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  798. v.Button = button
  799. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  800. v.Children = existItems
  801. for _, item := range existItems {
  802. button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId)
  803. item.Button = button
  804. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  805. for _, existItem := range existItems {
  806. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  807. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  808. existItem.Button = button
  809. }
  810. item.Children = existItems
  811. } else {
  812. items := make([]*data_manage.EdbClassifyItems, 0)
  813. item.Children = items
  814. }
  815. }
  816. } else {
  817. items := make([]*data_manage.EdbClassifyItems, 0)
  818. v.Children = items
  819. }
  820. nodeAll = append(nodeAll, v)
  821. }
  822. language := `CN`
  823. // 指标显示的语言
  824. {
  825. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  826. if configDetail != nil {
  827. language = configDetail.ConfigValue
  828. } else {
  829. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  830. if configDetail != nil {
  831. language = configDetail.ConfigValue
  832. }
  833. }
  834. }
  835. // 是否允许添加一级分类
  836. // 是否允许添加一级分类
  837. canOpClassify := true
  838. button := data.GetEdbClassifyOpButton(this.SysUser, 0)
  839. if !button.AddButton {
  840. canOpClassify = false
  841. }
  842. resp := new(data_manage.EdbClassifyListResp)
  843. resp.AllNodes = nodeAll
  844. resp.Language = language
  845. resp.CanOpClassify = canOpClassify
  846. br.Ret = 200
  847. br.Success = true
  848. br.Msg = "获取成功"
  849. br.Data = resp
  850. }
  851. // EdbClassifyMoveV2
  852. // @Title 分类移动接口v2
  853. // @Description 分类移动接口v2
  854. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  855. // @router /edb_classify/move/v2 [post]
  856. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  857. // br := new(models.BaseResponse).Init()
  858. // defer func() {
  859. // this.Data["json"] = br
  860. // this.ServeJSON()
  861. // }()
  862. //
  863. // sysUser := this.SysUser
  864. // if sysUser == nil {
  865. // br.Msg = "请登录"
  866. // br.ErrMsg = "请登录,SysUser Is Empty"
  867. // br.Ret = 408
  868. // return
  869. // }
  870. //
  871. // var req data_manage.MoveEdbClassifyReq
  872. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  873. // if err != nil {
  874. // br.Msg = "参数解析异常!"
  875. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  876. // return
  877. // }
  878. //
  879. // if req.ClassifyId <= 0 {
  880. // br.Msg = "参数错误"
  881. // br.ErrMsg = "分类id小于等于0"
  882. // return
  883. // }
  884. //
  885. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  886. // if errMsg != `` {
  887. // br.Msg = errMsg
  888. // br.ErrMsg = errMsg
  889. // if err != nil {
  890. // br.ErrMsg = err.Error()
  891. // } else {
  892. // br.IsSendEmail = false
  893. // }
  894. // return
  895. // }
  896. //
  897. // br.Ret = 200
  898. // br.Success = true
  899. // br.Msg = "移动成功"
  900. //}