edb_classify.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  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. 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), this.SysUser.AdminId)
  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, this.SysUser.AdminId)
  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.RealName, 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), this.SysUser.AdminId)
  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, this.SysUser.AdminId)
  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), this.SysUser.AdminId)
  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. // 如果选择了只看我的,那么只查询归属于我的账号
  1013. sysUserId := this.SysUser.AdminId
  1014. // 如果是数据查看,那么就看所有的指标和分类
  1015. if classifyType == utils.EdbClassifyTypeBase {
  1016. sysUserId = 0
  1017. }
  1018. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, int8(classifyType), sysUserId)
  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. sysUserId := this.SysUser.AdminId
  1169. // 基础指标(数据查看)默认是所有分类
  1170. if classifyType == utils.EdbClassifyTypeBase {
  1171. sysUserId = 0
  1172. }
  1173. allList := make([]*data_manage.EdbClassifyItems, 0)
  1174. if classifyType == utils.EdbClassifyTypeOrigin {
  1175. // 基础指标+计算指标
  1176. list, e := data_manage.GetEdbClassifyByClassifyTypes([]int{utils.EdbClassifyTypeBase, utils.EdbClassifyTypeCalculate}, sysUserId)
  1177. if e != nil && !utils.IsErrNoRow(e) {
  1178. br.Msg = "获取失败"
  1179. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  1180. return
  1181. }
  1182. allList = list
  1183. } else {
  1184. // 单一类型
  1185. list, err := data_manage.GetAllEdbClassifyByType(classifyType, sysUserId)
  1186. if err != nil && !utils.IsErrNoRow(err) {
  1187. br.Msg = "获取失败"
  1188. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1189. return
  1190. }
  1191. allList = list
  1192. }
  1193. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1194. var sortList data_manage.EdbClassifyItemList
  1195. if len(allList) > 0 {
  1196. // 已授权分类id
  1197. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1198. if err != nil {
  1199. br.Msg = "获取失败"
  1200. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1201. return
  1202. }
  1203. //for k, v := range allList {
  1204. // // 数据权限
  1205. // v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1206. // // 按钮权限
  1207. // button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1208. // allList[k].Button = button
  1209. //}
  1210. //nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  1211. newNodes := make([]*data_manage.EdbClassifyItems, 0)
  1212. for _, v := range allList {
  1213. // 分类设定了权限且无权限, 那么忽略掉该节点
  1214. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  1215. continue
  1216. }
  1217. newNodes = append(newNodes, v)
  1218. }
  1219. for k, v := range newNodes {
  1220. // 数据权限
  1221. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1222. // 按钮权限
  1223. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1224. newNodes[k].Button = button
  1225. }
  1226. nodeAll = data.GetClassifyTreeRecursive(newNodes, 0)
  1227. //根据sort值排序
  1228. sortList = nodeAll
  1229. sort.Sort(sortList)
  1230. }
  1231. language := `CN`
  1232. // 指标显示的语言
  1233. {
  1234. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1235. if configDetail != nil {
  1236. language = configDetail.ConfigValue
  1237. } else {
  1238. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1239. if configDetail != nil {
  1240. language = configDetail.ConfigValue
  1241. }
  1242. }
  1243. }
  1244. // 是否允许添加一级分类
  1245. canOpClassify := true
  1246. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1247. if !button.AddButton {
  1248. canOpClassify = false
  1249. }
  1250. resp := new(data_manage.EdbClassifyListResp)
  1251. resp.AllNodes = sortList
  1252. resp.Language = language
  1253. resp.CanOpClassify = canOpClassify
  1254. br.Ret = 200
  1255. br.Success = true
  1256. br.Msg = "获取成功"
  1257. br.Data = resp
  1258. }
  1259. // EdbClassifyMoveV2
  1260. // @Title 分类移动接口v2
  1261. // @Description 分类移动接口v2
  1262. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  1263. // @router /edb_classify/move/v2 [post]
  1264. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  1265. // br := new(models.BaseResponse).Init()
  1266. // defer func() {
  1267. // this.Data["json"] = br
  1268. // this.ServeJSON()
  1269. // }()
  1270. //
  1271. // sysUser := this.SysUser
  1272. // if sysUser == nil {
  1273. // br.Msg = "请登录"
  1274. // br.ErrMsg = "请登录,SysUser Is Empty"
  1275. // br.Ret = 408
  1276. // return
  1277. // }
  1278. //
  1279. // var req data_manage.MoveEdbClassifyReq
  1280. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1281. // if err != nil {
  1282. // br.Msg = "参数解析异常!"
  1283. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1284. // return
  1285. // }
  1286. //
  1287. // if req.ClassifyId <= 0 {
  1288. // br.Msg = "参数错误"
  1289. // br.ErrMsg = "分类id小于等于0"
  1290. // return
  1291. // }
  1292. //
  1293. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  1294. // if errMsg != `` {
  1295. // br.Msg = errMsg
  1296. // br.ErrMsg = errMsg
  1297. // if err != nil {
  1298. // br.ErrMsg = err.Error()
  1299. // } else {
  1300. // br.IsSendEmail = false
  1301. // }
  1302. // return
  1303. // }
  1304. //
  1305. // br.Ret = 200
  1306. // br.Success = true
  1307. // br.Msg = "移动成功"
  1308. //}