edb_classify.go 45 KB

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