edb_classify.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/system"
  8. "eta_gn/eta_api/services/data"
  9. "eta_gn/eta_api/services/data/data_manage_permission"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "sort"
  13. )
  14. // EdbClassifyController 数据管理-分类模块
  15. type EdbClassifyController struct {
  16. controllers.BaseAuthController
  17. }
  18. // ListV2
  19. // @Title 分类列表
  20. // @Description 分类列表接口
  21. // @Success 200 {object} data_manage.EdbClassifyListResp
  22. // @router /classify/list [get]
  23. func (this *EdbClassifyController) ListV2() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. // 分类来源筛选
  30. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  31. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  32. br.Msg = "参数有误"
  33. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  34. return
  35. }
  36. edbType := utils.EdbTypeBase
  37. if classifyType == utils.EdbClassifyTypeCalculate {
  38. edbType = utils.EdbTypeCalculate
  39. }
  40. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  41. if err != nil && !utils.IsErrNoRow(err) {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  44. return
  45. }
  46. //classifyAll, err := data_manage.GetEdbClassifyAll()
  47. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  48. if err != nil && !utils.IsErrNoRow(err) {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  51. return
  52. }
  53. // 分类map
  54. classifyMap := make(map[int]*data_manage.EdbClassifyItems)
  55. for _, v := range classifyAll {
  56. classifyMap[v.ClassifyId] = v
  57. }
  58. // 已授权分类id
  59. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  60. if err != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  63. return
  64. }
  65. // 获取当前账号的不可见指标
  66. obj := data_manage.EdbInfoNoPermissionAdmin{}
  67. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  68. if err != nil && !utils.IsErrNoRow(err) {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  71. return
  72. }
  73. noPermissionEdbInfoIdMap := make(map[int]bool)
  74. for _, v := range confList {
  75. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  76. }
  77. //allEdbInfo, err := data_manage.GetEdbInfoAll(utils.EDB_INFO_TYPE)
  78. allEdbInfo, err := data_manage.GetEdbInfoByTypes(utils.EDB_INFO_TYPE, edbType)
  79. if err != nil && !utils.IsErrNoRow(err) {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  82. return
  83. }
  84. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  85. if len(allEdbInfo) > 0 {
  86. // 获取所有有权限的指标和分类
  87. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  91. return
  92. }
  93. for _, v := range allEdbInfo {
  94. // 如果指标不可见,那么就不返回该指标
  95. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  96. continue
  97. }
  98. // 数据权限
  99. if classifyInfo, ok := classifyMap[v.ClassifyId]; ok {
  100. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  101. }
  102. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  103. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  104. v.Button = button
  105. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  106. }
  107. }
  108. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  109. for _, v := range classifyAll {
  110. // 数据权限
  111. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  112. // 按钮权限
  113. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  114. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  115. v.Button = button
  116. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  117. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  118. v.Children = existItems
  119. } else {
  120. items := make([]*data_manage.EdbClassifyItems, 0)
  121. v.Children = items
  122. }
  123. }
  124. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  125. for _, v := range rootList {
  126. // 数据权限
  127. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  128. // 按钮权限
  129. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  130. v.Button = button
  131. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  132. v.Children = existItems
  133. } else {
  134. items := make([]*data_manage.EdbClassifyItems, 0)
  135. v.Children = items
  136. }
  137. nodeAll = append(nodeAll, v)
  138. }
  139. resp := new(data_manage.EdbClassifyListResp)
  140. resp.AllNodes = nodeAll
  141. resp.CanOpClassify = true
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // Items
  148. // @Title 获取所有分类接口-不包含指标
  149. // @Description 获取所有分类接口-不包含指标
  150. // @Success 200 {object} data_manage.EdbClassifyListResp
  151. // @router /classify/items [get]
  152. func (this *EdbClassifyController) Items() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. // 分类来源筛选
  159. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  160. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  161. br.Msg = "参数有误"
  162. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  163. return
  164. }
  165. //edbType := utils.EdbTypeBase
  166. //if classifyType == utils.EdbClassifyTypeCalculate {
  167. // edbType = utils.EdbTypeCalculate
  168. //}
  169. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  170. if err != nil {
  171. br.Msg = "获取失败"
  172. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  173. return
  174. }
  175. //classifyAll, err := data_manage.GetEdbClassifyAll()
  176. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  177. if err != nil {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  180. return
  181. }
  182. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  183. for k := range rootList {
  184. rootNode := rootList[k]
  185. data.EdbClassifyItemsMakeTree(classifyAll, rootNode)
  186. nodeAll = append(nodeAll, rootNode)
  187. }
  188. resp := new(data_manage.EdbClassifyListResp)
  189. resp.AllNodes = nodeAll
  190. br.Ret = 200
  191. br.Success = true
  192. br.Msg = "获取成功"
  193. br.Data = resp
  194. }
  195. // AddEdbClassify
  196. // @Title 新增分类
  197. // @Description 新增分类接口
  198. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  199. // @Success 200 Ret=200 保存成功
  200. // @router /classify/add [post]
  201. func (this *EdbClassifyController) AddEdbClassify() {
  202. br := new(models.BaseResponse).Init()
  203. defer func() {
  204. this.Data["json"] = br
  205. this.ServeJSON()
  206. }()
  207. var req data_manage.AddEdbClassifyReq
  208. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  209. if err != nil {
  210. br.Msg = "参数解析异常!"
  211. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  212. return
  213. }
  214. if req.ClassifyName == "" {
  215. br.Msg = "请输入分类名称"
  216. br.IsSendEmail = false
  217. return
  218. }
  219. if req.ParentId < 0 {
  220. br.Msg = "参数错误"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. // 分类来源筛选
  225. classifyType := req.ClassifyType
  226. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  227. br.Msg = "参数有误"
  228. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  229. return
  230. }
  231. //添加指标
  232. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, classifyType, this.SysUser.AdminId, this.SysUser.AdminName, this.Lang)
  233. if errMsg != `` {
  234. br.Msg = errMsg
  235. br.ErrMsg = errMsg
  236. if err != nil {
  237. br.ErrMsg = errMsg + ";Err:" + err.Error()
  238. } else {
  239. br.IsSendEmail = false
  240. }
  241. return
  242. }
  243. //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
  244. //if err != nil {
  245. // br.Msg = "判断名称是否已存在失败"
  246. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  247. // return
  248. //}
  249. //if count > 0 {
  250. // br.Msg = "分类名称已存在,请重新输入"
  251. // br.IsSendEmail = false
  252. // return
  253. //}
  254. ////获取该层级下最大的排序数
  255. //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
  256. //
  257. //classify := new(data_manage.EdbClassify)
  258. //classify.ClassifyType = req.ClassifyType
  259. //classify.ParentId = req.ParentId
  260. //classify.ClassifyName = req.ClassifyName
  261. //classify.HasData = 0
  262. //classify.CreateTime = time.Now()
  263. //classify.ModifyTime = time.Now()
  264. //classify.SysUserId = this.SysUser.AdminId
  265. //classify.SysUserRealName = this.SysUser.RealName
  266. //classify.Level = req.Level + 1
  267. //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  268. //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  269. //classify.Sort = maxSort
  270. //
  271. //_, err = data_manage.AddEdbClassify(classify)
  272. //if err != nil {
  273. // br.Msg = "保存分类失败"
  274. // br.ErrMsg = "保存分类失败,Err:" + err.Error()
  275. // return
  276. //}
  277. br.Ret = 200
  278. br.Msg = "保存成功"
  279. br.Success = true
  280. br.IsAddLog = true
  281. }
  282. // EditEdbClassify
  283. // @Title 修改分类
  284. // @Description 修改分类接口
  285. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  286. // @Success 200 Ret=200 修改成功
  287. // @router /classify/edit [post]
  288. func (this *EdbClassifyController) EditEdbClassify() {
  289. br := new(models.BaseResponse).Init()
  290. defer func() {
  291. this.Data["json"] = br
  292. this.ServeJSON()
  293. }()
  294. var req data_manage.EditEdbClassifyReq
  295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  296. if err != nil {
  297. br.Msg = "参数解析异常!"
  298. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  299. return
  300. }
  301. if req.ClassifyName == "" {
  302. br.Msg = "请输入分类名称"
  303. br.IsSendEmail = false
  304. return
  305. }
  306. if req.ClassifyId < 0 {
  307. br.Msg = "参数错误"
  308. br.IsSendEmail = false
  309. return
  310. }
  311. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  312. if errMsg != `` {
  313. br.Msg = errMsg
  314. br.ErrMsg = errMsg
  315. if err != nil {
  316. br.ErrMsg = errMsg + ";Err:" + err.Error()
  317. } else {
  318. br.IsSendEmail = false
  319. }
  320. return
  321. }
  322. //item, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  323. //if err != nil {
  324. // br.Msg = "保存失败"
  325. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  326. // return
  327. //}
  328. //
  329. //if item.ClassifyName != req.ClassifyName {
  330. // count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, item.ParentId)
  331. // if err != nil {
  332. // br.Msg = "判断名称是否已存在失败"
  333. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  334. // return
  335. // }
  336. // if count > 0 {
  337. // br.Msg = "分类名称已存在,请重新输入"
  338. // br.IsSendEmail = false
  339. // return
  340. // }
  341. //
  342. // err = data_manage.EditEdbClassify(req.ClassifyId, req.ClassifyName)
  343. // if err != nil {
  344. // br.Msg = "保存失败"
  345. // br.ErrMsg = "保存失败,Err:" + err.Error()
  346. // return
  347. // }
  348. //}
  349. br.Ret = 200
  350. br.Msg = "保存成功"
  351. br.Success = true
  352. br.IsAddLog = true
  353. }
  354. // DeleteEdbClassifyCheck
  355. // @Title 删除检测接口
  356. // @Description 删除检测接口
  357. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  358. // @Success 200 Ret=200 检测成功
  359. // @router /classify/delete/check [post]
  360. func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
  361. br := new(models.BaseResponse).Init()
  362. defer func() {
  363. this.Data["json"] = br
  364. this.ServeJSON()
  365. }()
  366. var req data_manage.ClassifyDeleteCheckReq
  367. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  368. if err != nil {
  369. br.Msg = "参数解析异常!"
  370. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  371. return
  372. }
  373. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  374. br.Msg = "参数错误"
  375. br.IsSendEmail = false
  376. return
  377. }
  378. deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  379. if errMsg != `` {
  380. br.Msg = errMsg
  381. br.ErrMsg = errMsg
  382. if err != nil {
  383. br.ErrMsg = err.Error()
  384. } else {
  385. br.IsSendEmail = false
  386. }
  387. return
  388. }
  389. if this.Lang == "en" {
  390. if utils.ViperConfig.InConfig(tipsMsg) {
  391. tipsMsg = utils.ViperConfig.GetString(tipsMsg)
  392. }
  393. }
  394. //var deleteStatus int
  395. //var tipsMsg string
  396. ////删除分类
  397. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  398. // //判断分类下,是否含有指标
  399. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  400. // if err != nil {
  401. // br.Msg = "删除失败"
  402. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  403. // return
  404. // }
  405. //
  406. // if count > 0 {
  407. // deleteStatus = 1
  408. // tipsMsg = "若目录关联指标不可删除"
  409. // }
  410. //}
  411. //
  412. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  413. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  414. // if err != nil && !utils.IsErrNoRow(err) {
  415. // br.Msg = "删除失败"
  416. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  417. // return
  418. // }
  419. // if classifyCount > 0 {
  420. // deleteStatus = 2
  421. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  422. // }
  423. //}
  424. //
  425. ////删除指标
  426. //if req.EdbInfoId > 0 {
  427. // //判断指标是否用于作图,如果用于作图,则不可删除
  428. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  429. // if err != nil && !utils.IsErrNoRow(err) {
  430. // br.Msg = "删除失败"
  431. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  432. // return
  433. // }
  434. // if chartCount > 0 {
  435. // deleteStatus = 3
  436. // tipsMsg = "当前指标已用作画图,不可删除"
  437. // }
  438. // //判断指标是否用于计算
  439. // {
  440. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  441. // if err != nil && !utils.IsErrNoRow(err) {
  442. // br.Msg = "删除失败"
  443. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  444. // return
  445. // }
  446. // if calculateCount > 0 {
  447. // deleteStatus = 4
  448. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  449. // }
  450. // }
  451. //}
  452. resp := new(data_manage.ClassifyDeleteCheckResp)
  453. resp.DeleteStatus = deleteStatus
  454. resp.TipsMsg = tipsMsg
  455. resp.TableList = tableList
  456. br.Ret = 200
  457. br.Msg = "检测成功"
  458. br.Success = true
  459. br.Data = resp
  460. }
  461. // DeleteEdbClassify
  462. // @Title 删除分类/指标
  463. // @Description 删除分类/指标接口
  464. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  465. // @Success 200 Ret=200 新增成功
  466. // @router /classify/delete [post]
  467. func (this *EdbClassifyController) DeleteEdbClassify() {
  468. br := new(models.BaseResponse).Init()
  469. defer func() {
  470. this.Data["json"] = br
  471. this.ServeJSON()
  472. }()
  473. sysUser := this.SysUser
  474. if sysUser == nil {
  475. br.Msg = "请登录"
  476. br.ErrMsg = "请登录,SysUser Is Empty"
  477. br.Ret = 408
  478. return
  479. }
  480. var req data_manage.DeleteEdbClassifyReq
  481. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  482. if err != nil {
  483. br.Msg = "参数解析异常!"
  484. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  485. return
  486. }
  487. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  488. br.Msg = "参数错误"
  489. br.IsSendEmail = false
  490. return
  491. }
  492. nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  493. if errMsg != `` {
  494. br.Msg = errMsg
  495. br.ErrMsg = errMsg
  496. if err != nil {
  497. br.ErrMsg = err.Error()
  498. } else {
  499. br.IsSendEmail = false
  500. }
  501. return
  502. }
  503. resp := data_manage.AddEdbInfoResp{}
  504. if nextItem != nil {
  505. resp = data_manage.AddEdbInfoResp{
  506. EdbInfoId: nextItem.EdbInfoId,
  507. UniqueCode: nextItem.UniqueCode,
  508. }
  509. }
  510. br.Ret = 200
  511. br.Msg = "删除成功"
  512. br.Success = true
  513. br.IsAddLog = true
  514. br.Data = resp
  515. }
  516. // EdbClassifyMove
  517. // @Title 分类移动接口
  518. // @Description 分类移动接口
  519. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  520. // @router /edb_classify/move [post]
  521. func (this *EdbClassifyController) EdbClassifyMove() {
  522. br := new(models.BaseResponse).Init()
  523. defer func() {
  524. this.Data["json"] = br
  525. this.ServeJSON()
  526. }()
  527. sysUser := this.SysUser
  528. if sysUser == nil {
  529. br.Msg = "请登录"
  530. br.ErrMsg = "请登录,SysUser Is Empty"
  531. br.Ret = 408
  532. return
  533. }
  534. var req data_manage.MoveEdbClassifyReq
  535. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  536. if err != nil {
  537. br.Msg = "参数解析异常!"
  538. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  539. return
  540. }
  541. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  542. br.Msg = "参数错误"
  543. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  544. return
  545. }
  546. // 分类来源筛选
  547. classifyType := req.ClassifyType // 默认指标库的
  548. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  549. br.Msg = "参数有误"
  550. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  551. return
  552. }
  553. err, errMsg := data.MoveEdbClassify(req, sysUser, uint8(classifyType))
  554. if errMsg != `` {
  555. br.Msg = errMsg
  556. br.ErrMsg = errMsg
  557. if err != nil {
  558. br.ErrMsg = err.Error()
  559. } else {
  560. br.IsSendEmail = false
  561. }
  562. return
  563. }
  564. ////判断分类是否存在
  565. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  566. //if err != nil {
  567. // br.Msg = "移动失败"
  568. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  569. // return
  570. //}
  571. //updateCol := make([]string, 0)
  572. //
  573. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  574. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  575. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  576. // if err != nil {
  577. // br.Msg = "移动失败"
  578. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  579. // return
  580. // }
  581. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  582. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  583. // edbClassifyInfo.ModifyTime = time.Now()
  584. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  585. //}
  586. //
  587. ////如果有传入 上一个兄弟节点分类id
  588. //if req.PrevClassifyId > 0 {
  589. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  590. // if err != nil {
  591. // br.Msg = "移动失败"
  592. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  593. // return
  594. // }
  595. //
  596. // //如果是移动在两个兄弟节点之间
  597. // if req.NextClassifyId > 0 {
  598. // //下一个兄弟节点
  599. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  600. // if err != nil {
  601. // br.Msg = "移动失败"
  602. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  603. // return
  604. // }
  605. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  606. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  607. // //变更兄弟节点的排序
  608. // updateSortStr := `sort + 2`
  609. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  610. // } else {
  611. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  612. // if nextClassify.Sort-prevClassify.Sort == 1 {
  613. // //变更兄弟节点的排序
  614. // updateSortStr := `sort + 1`
  615. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  616. // }
  617. // }
  618. // }
  619. //
  620. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  621. // edbClassifyInfo.ModifyTime = time.Now()
  622. // updateCol = append(updateCol, "Sort", "ModifyTime")
  623. //} else {
  624. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  625. // if err != nil && !utils.IsErrNoRow(err) {
  626. // br.Msg = "移动失败"
  627. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  628. // return
  629. // }
  630. //
  631. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  632. // if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  633. // updateSortStr := ` sort + 1 `
  634. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  635. // }
  636. //
  637. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  638. // edbClassifyInfo.ModifyTime = time.Now()
  639. // updateCol = append(updateCol, "Sort", "ModifyTime")
  640. //}
  641. //
  642. ////更新
  643. //if len(updateCol) > 0 {
  644. // err = edbClassifyInfo.Update(updateCol)
  645. // if err != nil {
  646. // br.Msg = "移动失败"
  647. // br.ErrMsg = "修改失败,Err:" + err.Error()
  648. // return
  649. // }
  650. //}
  651. br.Ret = 200
  652. br.Success = true
  653. br.Msg = "移动成功"
  654. }
  655. // ItemsV2
  656. // @Title 分类列表
  657. // @Description 分类列表接口
  658. // @Success 200 {object} data_manage.EdbClassifyListResp
  659. // @router /classify/items/v2 [get]
  660. func (this *EdbClassifyController) ItemsV2() {
  661. br := new(models.BaseResponse).Init()
  662. defer func() {
  663. this.Data["json"] = br
  664. this.ServeJSON()
  665. }()
  666. // 分类来源筛选
  667. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  668. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  669. br.Msg = "参数有误"
  670. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  671. return
  672. }
  673. //edbType := utils.EdbTypeBase
  674. //if classifyType == utils.EdbClassifyTypeCalculate {
  675. // edbType = utils.EdbTypeCalculate
  676. //}
  677. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  678. if err != nil && !utils.IsErrNoRow(err) {
  679. br.Msg = "获取失败"
  680. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  681. return
  682. }
  683. //classifyAll, err := data_manage.GetEdbClassifyAll()
  684. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  685. if err != nil && !utils.IsErrNoRow(err) {
  686. br.Msg = "获取失败"
  687. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  688. return
  689. }
  690. // 已授权分类id
  691. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  692. if err != nil {
  693. br.Msg = "获取失败"
  694. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  695. return
  696. }
  697. //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
  698. //if err != nil && !utils.IsErrNoRow(err) {
  699. // br.Msg = "获取失败"
  700. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  701. // return
  702. //}
  703. //edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  704. //for _, v := range allEdbInfo {
  705. // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
  706. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  707. // v.Button = button
  708. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  709. //}
  710. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  711. for _, v := range classifyAll {
  712. // 数据权限
  713. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  714. // 按钮权限
  715. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  716. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  717. v.Button = button
  718. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  719. //if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  720. // v.Children = existItems
  721. //} else {
  722. // items := make([]*data_manage.EdbClassifyItems, 0)
  723. // v.Children = items
  724. //}
  725. }
  726. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  727. for _, v := range rootList {
  728. // 数据权限
  729. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  730. // 按钮权限
  731. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  732. v.Button = button
  733. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  734. v.Children = existItems
  735. } else {
  736. items := make([]*data_manage.EdbClassifyItems, 0)
  737. v.Children = items
  738. }
  739. nodeAll = append(nodeAll, v)
  740. }
  741. language := `CN`
  742. // 指标显示的语言
  743. {
  744. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  745. if configDetail != nil {
  746. language = configDetail.ConfigValue
  747. } else {
  748. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  749. if configDetail != nil {
  750. language = configDetail.ConfigValue
  751. }
  752. }
  753. }
  754. // 是否允许添加一级分类
  755. canOpClassify := true
  756. //button := data.GetEdbClassifyOpButton(this.SysUser, 0)
  757. //if !button.AddButton {
  758. // canOpClassify = false
  759. //}
  760. resp := data_manage.EdbClassifyListResp{
  761. AllNodes: nodeAll,
  762. CanOpClassify: canOpClassify,
  763. Language: language,
  764. }
  765. br.Ret = 200
  766. br.Success = true
  767. br.Msg = "获取成功"
  768. br.Data = resp
  769. }
  770. // ClassifyEdbInfoList
  771. // @Title 获取分类下指标接口
  772. // @Description 获取分类下指标接口
  773. // @Param ClassifyId query int true "分类id"
  774. // @Success 200 {object} data_manage.EdbClassifyListResp
  775. // @router /classify/edb_info/list [get]
  776. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  777. br := new(models.BaseResponse).Init()
  778. defer func() {
  779. this.Data["json"] = br
  780. this.ServeJSON()
  781. }()
  782. classifyId, _ := this.GetInt("ClassifyId")
  783. if classifyId <= 0 {
  784. br.Msg = "参数错误,请刷新页面"
  785. return
  786. }
  787. classifyInfo, err := data_manage.GetEdbClassifyById(classifyId)
  788. if err != nil {
  789. br.Msg = "获取失败"
  790. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  791. return
  792. }
  793. // 获取当前账号的不可见指标
  794. obj := data_manage.EdbInfoNoPermissionAdmin{}
  795. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  796. if err != nil && !utils.IsErrNoRow(err) {
  797. br.Msg = "获取失败"
  798. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  799. return
  800. }
  801. noPermissionEdbInfoIdMap := make(map[int]bool)
  802. for _, v := range confList {
  803. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  804. }
  805. // 指标类型(基础指标,预测指标)
  806. edbType := 0
  807. switch classifyInfo.ClassifyType {
  808. case utils.EdbClassifyTypeBase:
  809. edbType = 1
  810. case utils.EdbClassifyTypeCalculate:
  811. edbType = 2
  812. }
  813. // 无权限指标 和 无权限指标分类id
  814. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType)
  815. if err != nil {
  816. br.Msg = "获取失败"
  817. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  818. return
  819. }
  820. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, utils.EDB_INFO_TYPE, edbType, 0, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
  821. if err != nil && !utils.IsErrNoRow(err) {
  822. br.Msg = "获取失败"
  823. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  824. return
  825. }
  826. list := make([]*data_manage.EdbClassifyItems, 0)
  827. if len(allEdbInfo) > 0 {
  828. // 获取所有有权限的指标和分类
  829. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  830. if err != nil {
  831. br.Msg = "获取失败"
  832. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  833. return
  834. }
  835. for _, v := range allEdbInfo {
  836. // 如果指标不可见,那么就不返回该指标
  837. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  838. continue
  839. }
  840. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  841. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  842. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  843. v.Button = button
  844. list = append(list, v)
  845. }
  846. }
  847. resp := new(data_manage.ClassifyEdbInfoListResp)
  848. resp.EdbInfoList = list
  849. br.Ret = 200
  850. br.Success = true
  851. br.Msg = "获取成功"
  852. br.Data = resp
  853. }
  854. // ItemsV3
  855. // @Title 分类列表
  856. // @Description 分类列表接口
  857. // @Success 200 {object} data_manage.EdbClassifyListResp
  858. // @router /classify/items/v3 [get]
  859. func (this *EdbClassifyController) ItemsV3() {
  860. br := new(models.BaseResponse).Init()
  861. defer func() {
  862. this.Data["json"] = br
  863. this.ServeJSON()
  864. }()
  865. // 分类来源筛选
  866. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  867. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  868. br.Msg = "参数有误"
  869. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  870. return
  871. }
  872. //edbType := utils.EdbTypeBase
  873. //if classifyType == utils.EdbClassifyTypeCalculate {
  874. // edbType = utils.EdbTypeCalculate
  875. //}
  876. // TODO:9级改造
  877. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  878. if err != nil && !utils.IsErrNoRow(err) {
  879. br.Msg = "获取失败"
  880. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  881. return
  882. }
  883. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(int8(classifyType))
  884. if err != nil && !utils.IsErrNoRow(err) {
  885. br.Msg = "获取失败"
  886. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  887. return
  888. }
  889. classifyAll, err := data_manage.GetEdbClassifyAllV2(int8(classifyType))
  890. if err != nil && !utils.IsErrNoRow(err) {
  891. br.Msg = "获取失败"
  892. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  893. return
  894. }
  895. // 已授权分类id
  896. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  897. if err != nil {
  898. br.Msg = "获取失败"
  899. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  900. return
  901. }
  902. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  903. for _, v := range rootTwoList {
  904. // 数据权限
  905. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  906. // 按钮权限
  907. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  908. v.Button = button
  909. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  910. }
  911. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  912. for _, v := range classifyAll {
  913. // 数据权限
  914. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  915. // 按钮权限
  916. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  917. v.Button = button
  918. if v.Level == 3 {
  919. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  920. }
  921. }
  922. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  923. for _, v := range rootList {
  924. // 数据权限
  925. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  926. // 按钮权限
  927. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  928. v.Button = button
  929. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  930. v.Children = existItems
  931. for _, item := range existItems {
  932. // 数据权限
  933. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  934. // 按钮权限
  935. button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId, v.HaveOperaAuth)
  936. item.Button = button
  937. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  938. for _, existItem := range existItems {
  939. // 数据权限
  940. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  941. // 按钮权限
  942. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  943. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  944. existItem.Button = button
  945. }
  946. item.Children = existItems
  947. } else {
  948. items := make([]*data_manage.EdbClassifyItems, 0)
  949. item.Children = items
  950. }
  951. }
  952. } else {
  953. items := make([]*data_manage.EdbClassifyItems, 0)
  954. v.Children = items
  955. }
  956. nodeAll = append(nodeAll, v)
  957. }
  958. language := `CN`
  959. // 指标显示的语言
  960. {
  961. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  962. if configDetail != nil {
  963. language = configDetail.ConfigValue
  964. } else {
  965. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  966. if configDetail != nil {
  967. language = configDetail.ConfigValue
  968. }
  969. }
  970. }
  971. // 是否允许添加一级分类
  972. canOpClassify := true
  973. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  974. if !button.AddButton {
  975. canOpClassify = false
  976. }
  977. resp := new(data_manage.EdbClassifyListResp)
  978. resp.AllNodes = nodeAll
  979. resp.Language = language
  980. resp.CanOpClassify = canOpClassify
  981. br.Ret = 200
  982. br.Success = true
  983. br.Msg = "获取成功"
  984. br.Data = resp
  985. }
  986. // SimpleList
  987. // @Title 单层分类列表
  988. // @Description 单层分类列表
  989. // @Success 200 {object} data_manage.EdbClassifyListResp
  990. // @router /classify/simple [get]
  991. func (this *EdbClassifyController) SimpleList() {
  992. br := new(models.BaseResponse).Init()
  993. defer func() {
  994. this.Data["json"] = br
  995. this.ServeJSON()
  996. }()
  997. // 分类来源筛选
  998. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  999. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  1000. br.Msg = "参数有误"
  1001. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  1002. return
  1003. }
  1004. //edbType := utils.EdbTypeBase
  1005. //if classifyType == utils.EdbClassifyTypeCalculate {
  1006. // edbType = utils.EdbTypeCalculate
  1007. //}
  1008. // 默认查一级分类和一级分类下的指标信息,
  1009. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  1010. // 增加标识判断是文件夹还是指标列表
  1011. parentId, _ := this.GetInt("ParentId")
  1012. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  1013. // 如果选择了只看我的,那么只查询归属于我的账号
  1014. sysUserId := 0
  1015. if isOnlyMe {
  1016. sysUserId = this.SysUser.AdminId
  1017. }
  1018. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, int8(classifyType))
  1019. if err != nil && !utils.IsErrNoRow(err) {
  1020. br.Msg = "获取失败"
  1021. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1025. var sortList data_manage.EdbClassifyItemList
  1026. if parentId > 0 {
  1027. // 查询挂在当前分类上的指标列表
  1028. // 获取当前账号的不可见指标
  1029. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1030. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  1031. if err != nil && !utils.IsErrNoRow(err) {
  1032. br.Msg = "获取失败"
  1033. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1034. return
  1035. }
  1036. noPermissionEdbInfoIdMap := make(map[int]bool)
  1037. for _, v := range confList {
  1038. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  1039. }
  1040. // 指标类型(基础指标,预测指标)
  1041. edbType := 0
  1042. switch classifyType {
  1043. case utils.EdbClassifyTypeBase:
  1044. edbType = 1
  1045. case utils.EdbClassifyTypeCalculate:
  1046. edbType = 2
  1047. }
  1048. // 无权限指标 和 无权限指标分类id
  1049. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType)
  1050. if err != nil {
  1051. br.Msg = "获取失败"
  1052. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1053. return
  1054. }
  1055. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 0, edbType, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
  1056. if err != nil {
  1057. br.Msg = "获取指标数据失败"
  1058. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  1059. return
  1060. }
  1061. if len(allEdbInfo) > 0 {
  1062. // 查询当前分类信息
  1063. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  1064. if err != nil {
  1065. br.Msg = "获取失败"
  1066. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  1067. return
  1068. }
  1069. // 获取所有有权限的指标和分类
  1070. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1071. if err != nil {
  1072. br.Msg = "获取失败"
  1073. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. for _, v := range allEdbInfo {
  1077. // 如果指标不可见,那么就不返回该指标
  1078. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  1079. continue
  1080. }
  1081. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1082. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  1083. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  1084. v.Button = button
  1085. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  1086. v.ParentId = parentId
  1087. nodeAll = append(nodeAll, v)
  1088. }
  1089. }
  1090. }
  1091. if len(rootList) > 0 {
  1092. // 已授权分类id
  1093. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1094. if err != nil {
  1095. br.Msg = "获取失败"
  1096. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1097. return
  1098. }
  1099. for _, v := range rootList {
  1100. // 分类设定了权限且无权限, 那么忽略掉该节点
  1101. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  1102. continue
  1103. }
  1104. // 数据权限
  1105. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1106. // 按钮权限
  1107. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1108. v.Button = button
  1109. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  1110. nodeAll = append(nodeAll, v)
  1111. }
  1112. }
  1113. if len(nodeAll) > 0 {
  1114. //根据sort值排序
  1115. sortList = nodeAll
  1116. sort.Sort(sortList)
  1117. }
  1118. language := `CN`
  1119. // 指标显示的语言
  1120. {
  1121. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1122. if configDetail != nil {
  1123. language = configDetail.ConfigValue
  1124. } else {
  1125. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1126. if configDetail != nil {
  1127. language = configDetail.ConfigValue
  1128. }
  1129. }
  1130. }
  1131. // 是否允许添加一级分类
  1132. canOpClassify := true
  1133. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1134. if !button.AddButton {
  1135. canOpClassify = false
  1136. }
  1137. resp := new(data_manage.EdbClassifyListResp)
  1138. resp.AllNodes = sortList
  1139. resp.Language = language
  1140. resp.CanOpClassify = canOpClassify
  1141. br.Ret = 200
  1142. br.Success = true
  1143. br.Msg = "获取成功"
  1144. br.Data = resp
  1145. }
  1146. // ClassifyTree
  1147. // @Title 多层分类列表树
  1148. // @Description 多层分类列表树
  1149. // @Success 200 {object} data_manage.EdbClassifyListResp
  1150. // @router /classify/tree [get]
  1151. func (this *EdbClassifyController) ClassifyTree() {
  1152. br := new(models.BaseResponse).Init()
  1153. defer func() {
  1154. this.Data["json"] = br
  1155. this.ServeJSON()
  1156. }()
  1157. // 分类来源筛选
  1158. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  1159. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate && classifyType != utils.EdbClassifyTypeOrigin {
  1160. br.Msg = "参数有误"
  1161. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  1162. return
  1163. }
  1164. //edbType := utils.EdbTypeBase
  1165. //if classifyType == utils.EdbClassifyTypeCalculate {
  1166. // edbType = utils.EdbTypeCalculate
  1167. //}
  1168. allList := make([]*data_manage.EdbClassifyItems, 0)
  1169. if classifyType == utils.EdbClassifyTypeOrigin {
  1170. // 基础指标+计算指标
  1171. list, e := data_manage.GetEdbClassifyByClassifyTypes([]int{utils.EdbClassifyTypeBase, utils.EdbClassifyTypeCalculate})
  1172. if e != nil && !utils.IsErrNoRow(e) {
  1173. br.Msg = "获取失败"
  1174. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  1175. return
  1176. }
  1177. allList = list
  1178. } else {
  1179. // 单一类型
  1180. list, err := data_manage.GetAllEdbClassifyByType(classifyType)
  1181. if err != nil && !utils.IsErrNoRow(err) {
  1182. br.Msg = "获取失败"
  1183. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1184. return
  1185. }
  1186. allList = list
  1187. }
  1188. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1189. var sortList data_manage.EdbClassifyItemList
  1190. if len(allList) > 0 {
  1191. // 已授权分类id
  1192. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1193. if err != nil {
  1194. br.Msg = "获取失败"
  1195. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1196. return
  1197. }
  1198. //for k, v := range allList {
  1199. // // 数据权限
  1200. // v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1201. // // 按钮权限
  1202. // button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1203. // allList[k].Button = button
  1204. //}
  1205. //nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  1206. newNodes := make([]*data_manage.EdbClassifyItems, 0)
  1207. for _, v := range allList {
  1208. // 分类设定了权限且无权限, 那么忽略掉该节点
  1209. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  1210. continue
  1211. }
  1212. newNodes = append(newNodes, v)
  1213. }
  1214. for k, v := range newNodes {
  1215. // 数据权限
  1216. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1217. // 按钮权限
  1218. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1219. newNodes[k].Button = button
  1220. }
  1221. nodeAll = data.GetClassifyTreeRecursive(newNodes, 0)
  1222. //根据sort值排序
  1223. sortList = nodeAll
  1224. sort.Sort(sortList)
  1225. }
  1226. language := `CN`
  1227. // 指标显示的语言
  1228. {
  1229. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1230. if configDetail != nil {
  1231. language = configDetail.ConfigValue
  1232. } else {
  1233. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1234. if configDetail != nil {
  1235. language = configDetail.ConfigValue
  1236. }
  1237. }
  1238. }
  1239. // 是否允许添加一级分类
  1240. canOpClassify := true
  1241. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1242. if !button.AddButton {
  1243. canOpClassify = false
  1244. }
  1245. resp := new(data_manage.EdbClassifyListResp)
  1246. resp.AllNodes = sortList
  1247. resp.Language = language
  1248. resp.CanOpClassify = canOpClassify
  1249. br.Ret = 200
  1250. br.Success = true
  1251. br.Msg = "获取成功"
  1252. br.Data = resp
  1253. }
  1254. // EdbClassifyMoveV2
  1255. // @Title 分类移动接口v2
  1256. // @Description 分类移动接口v2
  1257. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  1258. // @router /edb_classify/move/v2 [post]
  1259. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  1260. // br := new(models.BaseResponse).Init()
  1261. // defer func() {
  1262. // this.Data["json"] = br
  1263. // this.ServeJSON()
  1264. // }()
  1265. //
  1266. // sysUser := this.SysUser
  1267. // if sysUser == nil {
  1268. // br.Msg = "请登录"
  1269. // br.ErrMsg = "请登录,SysUser Is Empty"
  1270. // br.Ret = 408
  1271. // return
  1272. // }
  1273. //
  1274. // var req data_manage.MoveEdbClassifyReq
  1275. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1276. // if err != nil {
  1277. // br.Msg = "参数解析异常!"
  1278. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1279. // return
  1280. // }
  1281. //
  1282. // if req.ClassifyId <= 0 {
  1283. // br.Msg = "参数错误"
  1284. // br.ErrMsg = "分类id小于等于0"
  1285. // return
  1286. // }
  1287. //
  1288. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  1289. // if errMsg != `` {
  1290. // br.Msg = errMsg
  1291. // br.ErrMsg = errMsg
  1292. // if err != nil {
  1293. // br.ErrMsg = err.Error()
  1294. // } else {
  1295. // br.IsSendEmail = false
  1296. // }
  1297. // return
  1298. // }
  1299. //
  1300. // br.Ret = 200
  1301. // br.Success = true
  1302. // br.Msg = "移动成功"
  1303. //}