bi_dashboard.go 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/models"
  6. biapprove "eta_gn/eta_api/models/bi_approve"
  7. "eta_gn/eta_api/models/bi_dashboard"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services"
  10. biapproveSerice "eta_gn/eta_api/services/bi_approve"
  11. "eta_gn/eta_api/utils"
  12. "fmt"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type BIDaShboardController struct {
  18. BaseAuthController
  19. }
  20. // @router /my_list [get]
  21. func (this *BIDaShboardController) MyList() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. privateCond := ` AND sys_admin_id = ? `
  28. privatePars := []interface{}{this.SysUser.AdminId}
  29. privateList, err := bi_dashboard.GetBiDashboardList(privateCond, privatePars)
  30. if err != nil {
  31. err = errors.New("我的看板列表查询出错:" + err.Error())
  32. return
  33. }
  34. br.Ret = 200
  35. br.Success = true
  36. br.Msg = "查询成功"
  37. br.Data = privateList
  38. return
  39. }
  40. // @router /add [post]
  41. func (this *BIDaShboardController) AddDashboard() {
  42. br := new(models.BaseResponse).Init()
  43. defer func() {
  44. this.Data["json"] = br
  45. this.ServeJSON()
  46. }()
  47. var req bi_dashboard.AddDashboardReq
  48. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  49. if err != nil {
  50. br.Msg = "参数解析异常!"
  51. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  52. return
  53. }
  54. if req.BiDashboardName == "" {
  55. br.Msg = "名称不能为空"
  56. return
  57. }
  58. nameItem, err := bi_dashboard.GetDashboardByName(req.BiDashboardName)
  59. if err != nil && !utils.IsErrNoRow(err) {
  60. br.Msg = "查询失败"
  61. br.ErrMsg = "查询失败,Err:" + err.Error()
  62. return
  63. }
  64. if nameItem != nil && nameItem.BiDashboardId > 0 {
  65. br.Msg = "名称重复"
  66. return
  67. }
  68. item := &bi_dashboard.BiDashboard{
  69. BiDashboardName: req.BiDashboardName,
  70. SysAdminId: this.SysUser.AdminId,
  71. SysAdminName: this.SysUser.RealName,
  72. CreateTime: time.Now(),
  73. ModifyTime: time.Now(),
  74. State: 1,
  75. }
  76. id, e := bi_dashboard.AddBiDashboard(item)
  77. if e != nil {
  78. err = e
  79. br.Msg = "新增失败"
  80. br.ErrMsg = "新增失败,Err:" + e.Error()
  81. return
  82. }
  83. detailList := make([]*bi_dashboard.BiDashboardDetail, 0)
  84. for i, v := range req.List {
  85. item := &bi_dashboard.BiDashboardDetail{
  86. BiDashboardId: int(id),
  87. Type: v.Type,
  88. UniqueCode: v.UniqueCode,
  89. Sort: i + 1,
  90. CreateTime: time.Now(),
  91. ModifyTime: time.Now(),
  92. }
  93. detailList = append(detailList, item)
  94. }
  95. err = bi_dashboard.AddBiDashboardDetailMulti(detailList)
  96. if err != nil {
  97. br.Msg = "新增详情失败"
  98. br.ErrMsg = "新增详情失败,Err:" + err.Error()
  99. return
  100. }
  101. br.Ret = 200
  102. br.Success = true
  103. br.Msg = "新增成功"
  104. }
  105. // @router /edit [post]
  106. func (this *BIDaShboardController) EditDashboard() {
  107. br := new(models.BaseResponse).Init()
  108. defer func() {
  109. this.Data["json"] = br
  110. this.ServeJSON()
  111. }()
  112. var req bi_dashboard.EditDashboardReq
  113. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  114. if err != nil {
  115. br.Msg = "参数解析异常!"
  116. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  117. return
  118. }
  119. if req.BiDashboardName == "" {
  120. br.Msg = "标题不能为空"
  121. return
  122. }
  123. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  124. if err != nil && !utils.IsErrNoRow(err) {
  125. br.Msg = "获取数据异常!"
  126. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  127. return
  128. }
  129. if item.SysAdminId != this.SysUser.AdminId {
  130. br.Msg = `无权编辑`
  131. return
  132. }
  133. item.BiDashboardName = req.BiDashboardName
  134. item.ModifyTime = time.Now()
  135. err = bi_dashboard.EditDashboard(item)
  136. if err != nil {
  137. br.Msg = "编辑失败"
  138. br.ErrMsg = "编辑失败,Err:" + err.Error()
  139. return
  140. }
  141. err = bi_dashboard.DeleteBiDashboardDetail(req.BiDashboardId)
  142. if err != nil {
  143. br.Msg = "删除详情失败"
  144. br.ErrMsg = "删除详情失败,Err:" + err.Error()
  145. return
  146. }
  147. detailList := make([]*bi_dashboard.BiDashboardDetail, 0)
  148. for _, v := range req.List {
  149. item := &bi_dashboard.BiDashboardDetail{
  150. BiDashboardId: req.BiDashboardId,
  151. Type: v.Type,
  152. UniqueCode: v.UniqueCode,
  153. Sort: v.Sort,
  154. CreateTime: time.Now(),
  155. ModifyTime: time.Now(),
  156. }
  157. detailList = append(detailList, item)
  158. }
  159. err = bi_dashboard.AddBiDashboardDetailMulti(detailList)
  160. if err != nil {
  161. br.Msg = "新增详情失败"
  162. br.ErrMsg = "新增详情失败,Err:" + err.Error()
  163. return
  164. }
  165. br.Ret = 200
  166. br.Success = true
  167. br.Msg = "编辑成功"
  168. br.IsAddLog = true
  169. }
  170. // @router /delete [post]
  171. func (this *BIDaShboardController) DeleteDashboard() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. var req bi_dashboard.DelDashboardReq
  178. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  179. if err != nil {
  180. br.Msg = "参数解析异常!"
  181. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  182. return
  183. }
  184. if req.BiDashboardId <= 0 {
  185. br.Msg = "参数错误"
  186. return
  187. }
  188. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  189. if err != nil && !utils.IsErrNoRow(err) {
  190. br.Msg = "获取数据异常!"
  191. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  192. return
  193. }
  194. if item.SysAdminId != this.SysUser.AdminId {
  195. br.Msg = "无权删除"
  196. return
  197. }
  198. err = bi_dashboard.DelDashboard(req.BiDashboardId)
  199. if err != nil {
  200. br.Msg = "删除失败"
  201. br.ErrMsg = "删除失败,Err:" + err.Error()
  202. return
  203. }
  204. err = bi_dashboard.DeleteDashboardGrant(req.BiDashboardId)
  205. if err != nil {
  206. br.Msg = "删除失败"
  207. br.ErrMsg = "删除失败,Err:" + err.Error()
  208. return
  209. }
  210. br.Ret = 200
  211. br.Success = true
  212. br.IsAddLog = true
  213. br.Msg = "删除成功"
  214. }
  215. // @router /detail/delete [post]
  216. func (this *BIDaShboardController) DeleteDashboardDetail() {
  217. br := new(models.BaseResponse).Init()
  218. defer func() {
  219. this.Data["json"] = br
  220. this.ServeJSON()
  221. }()
  222. var req bi_dashboard.DelDashboardDetailReq
  223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  224. if err != nil {
  225. br.Msg = "参数解析异常!"
  226. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  227. return
  228. }
  229. if req.BiDashboardDetailId <= 0 {
  230. br.Msg = "参数错误"
  231. return
  232. }
  233. err = bi_dashboard.DeleteBiDashboardDetailByDetailId(req.BiDashboardDetailId)
  234. if err != nil {
  235. br.Msg = "删除失败"
  236. br.ErrMsg = "删除失败,Err:" + err.Error()
  237. return
  238. }
  239. br.Ret = 200
  240. br.Success = true
  241. br.IsAddLog = true
  242. br.Msg = "删除成功"
  243. }
  244. // @router /detail [get]
  245. func (this *BIDaShboardController) DetailDashboard() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. if br.ErrMsg == "" {
  249. br.IsSendEmail = false
  250. }
  251. this.Data["json"] = br
  252. this.ServeJSON()
  253. }()
  254. sysUser := this.SysUser
  255. if sysUser == nil {
  256. br.Msg = "请登录"
  257. br.ErrMsg = "请登录,SysUser Is Empty"
  258. br.Ret = 408
  259. return
  260. }
  261. dashboardId, _ := this.GetInt("DashboardId")
  262. resp := new(bi_dashboard.DashboardDetailResp)
  263. dashboardItem, err := bi_dashboard.GetDashboardById(dashboardId)
  264. if err != nil {
  265. err = errors.New("我的看板列表查询出错:" + err.Error())
  266. br.Msg = "我的看板列表查询出错"
  267. br.ErrMsg = err.Error()
  268. return
  269. }
  270. grantInfoList, err := bi_dashboard.GetDashboardGrantInfo(dashboardId)
  271. if err != nil {
  272. br.Msg = "信息获取失败"
  273. br.ErrMsg = "共享信息获取失败,Err:" + err.Error()
  274. return
  275. }
  276. if len(grantInfoList) > 0 {
  277. resp.IsGrant = 1
  278. }
  279. detailList, err := bi_dashboard.GetBiDashboardDetailById(dashboardId)
  280. if err != nil {
  281. br.Msg = "详情获取失败"
  282. br.ErrMsg = "详情获取失败,Err:" + err.Error()
  283. return
  284. }
  285. editor, e := services.UpdateBiDashboardEditing(dashboardId, 0, sysUser.AdminId, sysUser.RealName)
  286. if e != nil {
  287. br.Msg = "编辑状态更新失败"
  288. br.ErrMsg = "编辑状态更新失败,Err:" + e.Error()
  289. return
  290. }
  291. resp.Editor = editor
  292. resp.BiDashboard = dashboardItem
  293. resp.List = detailList
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = "获取成功"
  297. br.Data = resp
  298. }
  299. // @router /detail/move [post]
  300. func (this *BIDaShboardController) MoveDashboard() {
  301. br := new(models.BaseResponse).Init()
  302. defer func() {
  303. this.Data["json"] = br
  304. this.ServeJSON()
  305. }()
  306. var req bi_dashboard.MoveDashboardDetailReq
  307. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  308. if err != nil {
  309. br.Msg = "参数解析异常!"
  310. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  311. return
  312. }
  313. if req.BiDashboardId <= 0 {
  314. br.Msg = "参数错误"
  315. return
  316. }
  317. if req.BiDashboardDetailId == req.OtherDetailId || req.BiDashboardDetailId <= 0 || req.OtherDetailId <= 0 {
  318. br.Msg = "看板Id有误"
  319. return
  320. }
  321. if req.Sort < 0 || req.OtherSort < 0 || req.Sort == req.OtherSort {
  322. br.Msg = "排序有误"
  323. return
  324. }
  325. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  326. if err != nil && !utils.IsErrNoRow(err) {
  327. br.Msg = "获取数据异常!"
  328. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  329. return
  330. }
  331. if item.SysAdminId != this.SysUser.AdminId {
  332. br.Msg = `无权移动`
  333. return
  334. }
  335. detailItem := &bi_dashboard.BiDashboardDetail{
  336. BiDashboardDetailId: req.BiDashboardDetailId,
  337. Sort: req.OtherSort,
  338. ModifyTime: time.Now(),
  339. }
  340. err = bi_dashboard.EditBiDashboardDetail(detailItem)
  341. if err != nil {
  342. br.Msg = "编辑详情失败"
  343. br.ErrMsg = "编辑详情失败,Err:" + err.Error()
  344. return
  345. }
  346. otherItem := &bi_dashboard.BiDashboardDetail{
  347. BiDashboardDetailId: req.OtherDetailId,
  348. Sort: req.Sort,
  349. ModifyTime: time.Now(),
  350. }
  351. err = bi_dashboard.EditBiDashboardDetail(otherItem)
  352. if err != nil {
  353. br.Msg = "编辑详情失败"
  354. br.ErrMsg = "编辑详情失败,Err:" + err.Error()
  355. return
  356. }
  357. br.Ret = 200
  358. br.Success = true
  359. br.Msg = "编辑成功"
  360. br.IsAddLog = true
  361. }
  362. // @router /share_list [get]
  363. func (this *BIDaShboardController) ShareList() {
  364. br := new(models.BaseResponse).Init()
  365. defer func() {
  366. this.Data["json"] = br
  367. this.ServeJSON()
  368. }()
  369. grantList := bi_dashboard.RespGroupList{}
  370. ShareList, err := bi_dashboard.GetAllMyShareList(this.SysUser.AdminId)
  371. if err != nil {
  372. err = errors.New("我的看板列表查询出错:" + err.Error())
  373. br.ErrMsg = err.Error()
  374. br.Msg = "查询失败"
  375. return
  376. }
  377. grantList.MyList = ShareList
  378. adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
  379. adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
  380. grantDashboardList, err := bi_dashboard.GetAllGrantList(this.SysUser.AdminId)
  381. if err != nil {
  382. err = errors.New("我的看板列表查询出错:" + err.Error())
  383. br.ErrMsg = err.Error()
  384. br.Msg = "查询失败"
  385. return
  386. }
  387. publicAdminIdList := make([]int, 0)
  388. publicDashboardListMap := make(map[int][]*bi_dashboard.BiDashboard)
  389. for _, v := range grantDashboardList {
  390. publicDashboardList, ok := publicDashboardListMap[v.SysAdminId]
  391. if !ok {
  392. publicDashboardList = make([]*bi_dashboard.BiDashboard, 0)
  393. publicAdminIdList = append(publicAdminIdList, v.SysAdminId)
  394. if _, ok := adminIdMap[v.SysAdminId]; !ok {
  395. adminIdList = append(adminIdList, v.SysAdminId) //需要查询的创建人admin_id列表集合
  396. adminIdMap[v.SysAdminId] = v.SysAdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  397. }
  398. }
  399. tmp := &bi_dashboard.BiDashboard{
  400. BiDashboardId: v.BiDashboardId,
  401. BiDashboardName: v.BiDashboardName,
  402. CreateTime: v.CreateTime,
  403. ModifyTime: v.ModifyTime,
  404. Sort: v.Sort,
  405. State: v.State,
  406. SysAdminId: v.SysAdminId,
  407. SysAdminName: v.SysAdminName,
  408. }
  409. publicDashboardList = append(publicDashboardList, tmp)
  410. publicDashboardListMap[v.SysAdminId] = publicDashboardList
  411. }
  412. systemAdminMap := make(map[int]*system.Admin)
  413. systemAdminList, err := system.GetAdminListByIdList(adminIdList)
  414. if err != nil {
  415. return
  416. }
  417. for _, v := range systemAdminList {
  418. systemAdminMap[v.AdminId] = v
  419. }
  420. for _, v := range publicAdminIdList {
  421. systemAdmin, ok := systemAdminMap[v]
  422. if !ok {
  423. continue
  424. }
  425. respGroupNameListItemList, ok := publicDashboardListMap[v]
  426. if !ok {
  427. respGroupNameListItemList = make([]*bi_dashboard.BiDashboard, 0)
  428. }
  429. tmpRespGroupListItem := &bi_dashboard.RespOtherGroupListItem{
  430. GroupId: int64(systemAdmin.AdminId),
  431. GroupName: systemAdmin.RealName,
  432. AdminId: systemAdmin.AdminId,
  433. DashboardList: respGroupNameListItemList,
  434. }
  435. grantList.OtherList = append(grantList.OtherList, tmpRespGroupListItem)
  436. }
  437. br.Ret = 200
  438. br.Success = true
  439. br.Msg = "查询成功"
  440. br.Data = grantList
  441. return
  442. }
  443. // @router /public_list [get]
  444. func (this *BIDaShboardController) PublicList() {
  445. br := new(models.BaseResponse).Init()
  446. defer func() {
  447. this.Data["json"] = br
  448. this.ServeJSON()
  449. }()
  450. resp := make([]*bi_dashboard.RespPublicGroupListItem, 0)
  451. publicCond := ` AND state = 6 AND bi_dashboard_classify_id > 0 `
  452. publicPars := make([]interface{}, 0)
  453. publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
  454. if err != nil {
  455. err = errors.New("我的看板列表查询出错:" + err.Error())
  456. return
  457. }
  458. adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
  459. adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
  460. publicAdminIdList := make([]int, 0)
  461. publicDashboardListMap := make(map[int][]*bi_dashboard.BiDashboard)
  462. publicDashboardClassifyIdMap := make(map[int]int)
  463. for _, v := range publicList {
  464. publicDashboardList, ok := publicDashboardListMap[v.SysAdminId]
  465. if !ok {
  466. publicDashboardList = make([]*bi_dashboard.BiDashboard, 0)
  467. publicAdminIdList = append(publicAdminIdList, v.SysAdminId)
  468. if _, ok := adminIdMap[v.SysAdminId]; !ok {
  469. adminIdList = append(adminIdList, v.SysAdminId) //需要查询的创建人admin_id列表集合
  470. adminIdMap[v.SysAdminId] = v.SysAdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  471. }
  472. }
  473. tmp := &bi_dashboard.BiDashboard{
  474. BiDashboardId: v.BiDashboardId,
  475. BiDashboardClassifyId: v.BiDashboardClassifyId,
  476. BiDashboardName: v.BiDashboardName,
  477. CreateTime: v.CreateTime,
  478. ModifyTime: v.ModifyTime,
  479. Sort: v.Sort,
  480. State: v.State,
  481. SysAdminId: v.SysAdminId,
  482. SysAdminName: v.SysAdminName,
  483. }
  484. publicDashboardList = append(publicDashboardList, tmp)
  485. publicDashboardListMap[v.SysAdminId] = publicDashboardList
  486. publicDashboardClassifyIdMap[v.BiDashboardClassifyId] = v.BiDashboardClassifyId
  487. }
  488. systemAdminMap := make(map[int]*system.Admin)
  489. systemAdminList, err := system.GetAdminListByIdList(adminIdList)
  490. if err != nil {
  491. return
  492. }
  493. for _, v := range systemAdminList {
  494. systemAdminMap[v.AdminId] = v
  495. }
  496. classifyList, err := bi_dashboard.GetBiDashboardClassifyAllList()
  497. if err != nil {
  498. br.Msg = "查询失败"
  499. br.ErrMsg = "查询失败,Err:" + err.Error()
  500. return
  501. }
  502. for _, c := range classifyList {
  503. tmpItem := &bi_dashboard.RespPublicGroupListItem{
  504. GroupId: int64(c.BiDashboardClassifyId),
  505. GroupName: c.BiDashboardClassifyName,
  506. Children: make([]*bi_dashboard.RespPublicGroupListItem, 0),
  507. }
  508. if _, ok := publicDashboardClassifyIdMap[c.BiDashboardClassifyId]; ok {
  509. for _, v := range adminIdList {
  510. systemAdmin, ok := systemAdminMap[v]
  511. if !ok {
  512. continue
  513. }
  514. respGroupNameListItemList, ok := publicDashboardListMap[v]
  515. if !ok {
  516. respGroupNameListItemList = make([]*bi_dashboard.BiDashboard, 0)
  517. }
  518. tmpRespGroupListItem := &bi_dashboard.RespPublicGroupListItem{
  519. GroupId: int64(systemAdmin.AdminId),
  520. GroupName: systemAdmin.RealName,
  521. AdminId: systemAdmin.AdminId,
  522. DashboardList: make([]*bi_dashboard.BiDashboard, 0),
  523. }
  524. for _, vv := range respGroupNameListItemList {
  525. if vv.BiDashboardClassifyId == c.BiDashboardClassifyId {
  526. tmpRespGroupListItem.DashboardList = append(tmpRespGroupListItem.DashboardList, vv)
  527. tmpItem.Children = append(tmpItem.Children, tmpRespGroupListItem)
  528. }
  529. }
  530. }
  531. resp = append(resp, tmpItem)
  532. }
  533. }
  534. br.Ret = 200
  535. br.Success = true
  536. br.Msg = "查询成功"
  537. br.Data = resp
  538. return
  539. }
  540. // @router /classify/add [post]
  541. func (this *BIDaShboardController) AddDashboardClassify() {
  542. br := new(models.BaseResponse).Init()
  543. defer func() {
  544. this.Data["json"] = br
  545. this.ServeJSON()
  546. }()
  547. var req bi_dashboard.AddDashboardClassifyReq
  548. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  549. if err != nil {
  550. br.Msg = "参数解析异常!"
  551. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  552. return
  553. }
  554. if req.ClassifyName == "" {
  555. br.Msg = "名称不能为空"
  556. return
  557. }
  558. maxSort, err := bi_dashboard.GetBiDashboardClassifyMaxSort()
  559. if err != nil {
  560. br.Msg = "获取最大排序值失败"
  561. br.ErrMsg = "获取最大排序值失败,Err:" + err.Error()
  562. return
  563. }
  564. count, err := bi_dashboard.GetBiDashboardClassifyByName(req.ClassifyName)
  565. if err != nil {
  566. br.Msg = "获取分类名称失败"
  567. br.ErrMsg = "获取分类名称失败,Err:" + err.Error()
  568. return
  569. }
  570. if count > 0 {
  571. br.Msg = "分类名称已存在"
  572. return
  573. }
  574. item := &bi_dashboard.BiDashboardClassify{
  575. BiDashboardClassifyName: req.ClassifyName,
  576. Sort: maxSort + 1,
  577. CreateTime: time.Now(),
  578. ModifyTime: time.Now(),
  579. }
  580. _, e := bi_dashboard.AddBiDashboardClassify(item)
  581. if e != nil {
  582. err = e
  583. br.Msg = "新增失败"
  584. br.ErrMsg = "新增失败,Err:" + e.Error()
  585. return
  586. }
  587. br.Ret = 200
  588. br.Success = true
  589. br.Msg = "新增成功"
  590. }
  591. // @router /classify/edit [post]
  592. func (this *BIDaShboardController) EditDashboardClassify() {
  593. br := new(models.BaseResponse).Init()
  594. defer func() {
  595. this.Data["json"] = br
  596. this.ServeJSON()
  597. }()
  598. var req bi_dashboard.EditDashboardClassifyReq
  599. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  600. if err != nil {
  601. br.Msg = "参数解析异常!"
  602. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  603. return
  604. }
  605. if req.ClassifyName == "" {
  606. br.Msg = "标题不能为空"
  607. return
  608. }
  609. if req.BiDashboardClassifyId <= 0 {
  610. br.Msg = "参数有误"
  611. br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
  612. return
  613. }
  614. item, err := bi_dashboard.GetBiDashboardClassifyById(req.BiDashboardClassifyId)
  615. if err != nil && !utils.IsErrNoRow(err) {
  616. br.Msg = "获取数据异常!"
  617. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  618. return
  619. }
  620. item.BiDashboardClassifyName = req.ClassifyName
  621. item.ModifyTime = time.Now()
  622. err = bi_dashboard.EditDashboardClassify(item)
  623. if err != nil {
  624. br.Msg = "编辑失败"
  625. br.ErrMsg = "编辑失败,Err:" + err.Error()
  626. return
  627. }
  628. err = biapproveSerice.ModifyBiApproveFlowClassify(req.BiDashboardClassifyId, req.ClassifyName)
  629. if err != nil {
  630. br.Msg = "编辑失败"
  631. br.ErrMsg = "编辑失败,Err:" + err.Error()
  632. return
  633. }
  634. br.Ret = 200
  635. br.Success = true
  636. br.Msg = "编辑成功"
  637. br.IsAddLog = true
  638. }
  639. // @router /classify/del [post]
  640. func (this *BIDaShboardController) DelDashboardClassify() {
  641. br := new(models.BaseResponse).Init()
  642. defer func() {
  643. this.Data["json"] = br
  644. this.ServeJSON()
  645. }()
  646. var req bi_dashboard.DelDashboardClassifyReq
  647. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  648. if err != nil {
  649. br.Msg = "参数解析异常!"
  650. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  651. return
  652. }
  653. if req.BiDashboardClassifyId <= 0 {
  654. br.Msg = "参数有误"
  655. br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
  656. return
  657. }
  658. publicCond := ` AND state = 6 AND bi_dashboard_classify_id = ? `
  659. publicPars := make([]interface{}, 0)
  660. publicPars = append(publicPars, req.BiDashboardClassifyId)
  661. publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
  662. if err != nil {
  663. err = errors.New("我的看板列表查询出错:" + err.Error())
  664. return
  665. }
  666. if len(publicList) > 0 {
  667. br.Msg = "该分类已关联看板,暂不支持删除!"
  668. return
  669. }
  670. tmp, er := biapprove.GetBiApproveFlowByClassifyId(req.BiDashboardClassifyId)
  671. if er != nil && !utils.IsErrNoRow(er) {
  672. err = er
  673. br.Msg = "查询审批流出错"
  674. br.ErrMsg = "查询审批流出错:" + er.Error()
  675. return
  676. }
  677. if tmp.BiApproveFlowId > 0 {
  678. br.Msg = "该分类已关联审批流,暂不支持删除!"
  679. return
  680. }
  681. err = bi_dashboard.DelBiDashboardClassify(req.BiDashboardClassifyId)
  682. if err != nil {
  683. br.Msg = "编辑失败"
  684. br.ErrMsg = "编辑失败,Err:" + err.Error()
  685. return
  686. }
  687. br.Ret = 200
  688. br.Success = true
  689. br.Msg = "删除成功"
  690. br.IsAddLog = true
  691. }
  692. // @router /grant [post]
  693. func (this *BIDaShboardController) Grant() {
  694. br := new(models.BaseResponse).Init()
  695. defer func() {
  696. this.Data["json"] = br
  697. this.ServeJSON()
  698. }()
  699. var req bi_dashboard.GrantDashboardReq
  700. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  701. if err != nil {
  702. br.Msg = "参数解析异常!"
  703. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  704. return
  705. }
  706. if req.AdminIdStr == "" {
  707. br.Msg = "参数错误"
  708. return
  709. }
  710. if req.BiDashboardId <= 0 {
  711. br.Msg = "参数错误"
  712. return
  713. }
  714. dashboardItem, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  715. if err != nil {
  716. err = errors.New("我的看板列表查询出错:" + err.Error())
  717. br.Msg = "我的看板列表查询出错"
  718. br.ErrMsg = err.Error()
  719. return
  720. }
  721. if dashboardItem.SysAdminId != this.SysUser.AdminId {
  722. br.Msg = "无权配置"
  723. return
  724. }
  725. list := make([]*bi_dashboard.BiDashboardGrant, 0)
  726. grantAdminIdStrList := strings.Split(req.AdminIdStr, ",")
  727. lenGrantAdminIdStrList := len(grantAdminIdStrList) //指定用户的人数
  728. for _, v := range grantAdminIdStrList {
  729. grantAdminId, tmpErr := strconv.Atoi(v)
  730. if tmpErr != nil {
  731. br.Msg = "参数有误"
  732. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
  733. return
  734. }
  735. if grantAdminId == this.SysUser.AdminId {
  736. if lenGrantAdminIdStrList == 1 {
  737. br.Msg = "不能指定自己为权限用户"
  738. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
  739. return
  740. }
  741. continue
  742. }
  743. tmpV := &bi_dashboard.BiDashboardGrant{
  744. BiDashboardId: req.BiDashboardId,
  745. GrantAdminId: grantAdminId,
  746. CreateTime: time.Now(),
  747. }
  748. list = append(list, tmpV)
  749. }
  750. if len(list) <= 0 {
  751. br.Msg = "参数有误"
  752. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", "指定用户为空")
  753. return
  754. }
  755. err = bi_dashboard.MultiAddDashboardGrant(req.BiDashboardId, list)
  756. if err != nil {
  757. br.Msg = "分配失败"
  758. br.ErrMsg = fmt.Sprintf("分配失败,Err:%s", err.Error())
  759. return
  760. }
  761. br.Ret = 200
  762. br.Success = true
  763. br.IsAddLog = true
  764. br.Msg = "分配成功"
  765. }
  766. // @router /public [post]
  767. func (this *BIDaShboardController) Public() {
  768. br := new(models.BaseResponse).Init()
  769. defer func() {
  770. this.Data["json"] = br
  771. this.ServeJSON()
  772. }()
  773. var req bi_dashboard.PublicDashboardReq
  774. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  775. if err != nil {
  776. br.Msg = "参数解析异常!"
  777. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  778. return
  779. }
  780. opening, e := biapproveSerice.CheckBiOpenApprove(req.ClassifyId)
  781. if e != nil {
  782. if !utils.IsErrNoRow(e) {
  783. br.Msg = "该分类未配置审批流,请先配置审批流"
  784. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  785. return
  786. }
  787. br.Msg = "操作失败"
  788. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  789. return
  790. }
  791. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  792. if err != nil && !utils.IsErrNoRow(err) {
  793. br.Msg = "获取数据异常!"
  794. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  795. return
  796. }
  797. if opening {
  798. _, err = biapproveSerice.SubmitBiApprove(req.BiDashboardId, item.BiDashboardName, req.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName)
  799. if err != nil {
  800. br.Msg = "提交审批失败"
  801. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  802. return
  803. }
  804. item.State = 4
  805. } else {
  806. item.State = 6
  807. }
  808. item.BiDashboardClassifyId = req.ClassifyId
  809. err = bi_dashboard.EditDashboard(item)
  810. if err != nil {
  811. br.Msg = "编辑失败"
  812. br.ErrMsg = "编辑失败,Err:" + err.Error()
  813. return
  814. }
  815. br.Ret = 200
  816. br.Success = true
  817. br.IsAddLog = true
  818. br.Msg = "分配成功"
  819. }
  820. // @router /classify/list [get]
  821. func (this *BIDaShboardController) ClassifyList() {
  822. br := new(models.BaseResponse).Init()
  823. defer func() {
  824. this.Data["json"] = br
  825. this.ServeJSON()
  826. }()
  827. classifyList, err := bi_dashboard.GetBiDashboardClassifyAllList()
  828. if err != nil {
  829. br.Msg = "查询失败"
  830. br.ErrMsg = "查询失败,Err:" + err.Error()
  831. return
  832. }
  833. br.Ret = 200
  834. br.Success = true
  835. br.Msg = "查询成功"
  836. br.Data = classifyList
  837. return
  838. }
  839. // @router /grant/cancel [post]
  840. func (this *BIDaShboardController) CancelGrant() {
  841. br := new(models.BaseResponse).Init()
  842. defer func() {
  843. this.Data["json"] = br
  844. this.ServeJSON()
  845. }()
  846. var req bi_dashboard.DelDashboardReq
  847. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  848. if err != nil {
  849. br.Msg = "参数解析异常!"
  850. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  851. return
  852. }
  853. if req.BiDashboardId <= 0 {
  854. br.Msg = "参数错误"
  855. return
  856. }
  857. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  858. if err != nil {
  859. br.Msg = "数据不存在"
  860. br.ErrMsg = "数据不存在,Err:" + err.Error()
  861. return
  862. }
  863. if item.SysAdminId != this.SysUser.AdminId {
  864. br.Msg = "无权配置"
  865. return
  866. }
  867. err = bi_dashboard.DeleteDashboardGrant(req.BiDashboardId)
  868. if err != nil {
  869. br.Msg = "取消失败"
  870. br.ErrMsg = "取消失败,Err:" + err.Error()
  871. return
  872. }
  873. br.Ret = 200
  874. br.Success = true
  875. br.IsAddLog = true
  876. br.Msg = "取消成功"
  877. }
  878. // @router /grant/info [get]
  879. func (this *BIDaShboardController) GrantInfo() {
  880. br := new(models.BaseResponse).Init()
  881. defer func() {
  882. this.Data["json"] = br
  883. this.ServeJSON()
  884. }()
  885. biDashboardId, _ := this.GetInt("BiDashboardId")
  886. if biDashboardId <= 0 {
  887. br.Msg = "参数错误"
  888. return
  889. }
  890. item, err := bi_dashboard.GetDashboardById(biDashboardId)
  891. if err != nil {
  892. br.Msg = "数据不存在"
  893. br.ErrMsg = "数据不存在,Err:" + err.Error()
  894. return
  895. }
  896. if item.SysAdminId != this.SysUser.AdminId {
  897. br.Msg = "无权配置"
  898. return
  899. }
  900. grantInfoList, err := bi_dashboard.GetDashboardGrantInfo(biDashboardId)
  901. if err != nil {
  902. br.Msg = "信息获取失败"
  903. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  904. return
  905. }
  906. if len(grantInfoList) <= 0 {
  907. br.Msg = "未配置"
  908. br.IsSendEmail = false
  909. br.Success = true
  910. br.Ret = 200
  911. return
  912. }
  913. var adminIdStr string
  914. adminIdsList := make([]string, 0)
  915. for _, v := range grantInfoList {
  916. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  917. }
  918. adminIdStr = strings.Join(adminIdsList, ",")
  919. br.Ret = 200
  920. br.Success = true
  921. br.Data = adminIdStr
  922. br.Msg = "查询成功"
  923. }
  924. // @router /public/cancel [post]
  925. func (this *BIDaShboardController) PublicCancel() {
  926. br := new(models.BaseResponse).Init()
  927. defer func() {
  928. this.Data["json"] = br
  929. this.ServeJSON()
  930. }()
  931. var req bi_dashboard.DelDashboardReq
  932. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  933. if err != nil {
  934. br.Msg = "参数解析异常!"
  935. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  936. return
  937. }
  938. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  939. if err != nil && !utils.IsErrNoRow(err) {
  940. br.Msg = "获取数据异常!"
  941. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  942. return
  943. }
  944. opening, e := biapproveSerice.CheckBiOpenApprove(item.BiDashboardClassifyId)
  945. if e != nil {
  946. br.Msg = "操作失败"
  947. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  948. return
  949. }
  950. if opening {
  951. approvalItem, err := biapprove.GetBiApproveByBoardId(req.BiDashboardId)
  952. if err != nil && !utils.IsErrNoRow(err) {
  953. br.Msg = "获取数据异常!"
  954. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  955. return
  956. }
  957. msg, e := biapproveSerice.BiApproveCancel(approvalItem.BiApproveId, this.SysUser.AdminId, this.SysUser.RealName)
  958. if e != nil {
  959. if msg != "" {
  960. br.Msg = msg
  961. } else {
  962. br.Msg = "操作失败"
  963. }
  964. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  965. return
  966. }
  967. }
  968. item.BiDashboardClassifyId = 0
  969. item.State = 1
  970. err = bi_dashboard.SaveDashboard(item)
  971. if err != nil {
  972. br.Msg = "编辑失败"
  973. br.ErrMsg = "编辑失败,Err:" + err.Error()
  974. return
  975. }
  976. br.Ret = 200
  977. br.Success = true
  978. br.IsAddLog = true
  979. br.Msg = "撤销成功"
  980. }
  981. // @router /home_page [get]
  982. func (this *BIDaShboardController) HomePage() {
  983. br := new(models.BaseResponse).Init()
  984. defer func() {
  985. this.Data["json"] = br
  986. this.ServeJSON()
  987. }()
  988. item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
  989. if err != nil && !utils.IsErrNoRow(err) {
  990. br.Msg = "数据不存在"
  991. br.ErrMsg = "数据不存在,Err:" + err.Error()
  992. return
  993. }
  994. publicCond := ` AND state = 6 AND bi_dashboard_classify_id > 0 `
  995. publicPars := []interface{}{this.SysUser.AdminId}
  996. publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
  997. if err != nil {
  998. err = errors.New("我的看板列表查询出错:" + err.Error())
  999. return
  1000. }
  1001. if item.BiDashboardHomePageId == 0 && len(publicList) > 0 {
  1002. item = &bi_dashboard.BiDashboardHomePage{
  1003. AdminId: publicList[0].SysAdminId,
  1004. BiDashboardId: publicList[0].BiDashboardId,
  1005. FromType: 3,
  1006. }
  1007. }
  1008. if item.BiDashboardId == 0 {
  1009. item = nil
  1010. }
  1011. br.Ret = 200
  1012. br.Success = true
  1013. br.Msg = "查询成功"
  1014. br.Data = item
  1015. return
  1016. }
  1017. // @router /home_page/save [post]
  1018. func (this *BIDaShboardController) HomePageSave() {
  1019. br := new(models.BaseResponse).Init()
  1020. defer func() {
  1021. this.Data["json"] = br
  1022. this.ServeJSON()
  1023. }()
  1024. var req bi_dashboard.SaveHomePageReq
  1025. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1026. if err != nil {
  1027. br.Msg = "参数解析异常!"
  1028. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1029. return
  1030. }
  1031. if req.BiDashboardId <= 0 {
  1032. br.Msg = "参数错误"
  1033. return
  1034. }
  1035. item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
  1036. if err != nil && !utils.IsErrNoRow(err) {
  1037. br.Msg = "数据不存在"
  1038. br.ErrMsg = "数据不存在,Err:" + err.Error()
  1039. return
  1040. }
  1041. homePageItem := &bi_dashboard.BiDashboardHomePage{
  1042. BiDashboardId: req.BiDashboardId,
  1043. AdminId: this.SysUser.AdminId,
  1044. CreateTime: time.Now(),
  1045. ModifyTime: time.Now(),
  1046. FromType: req.FromType,
  1047. }
  1048. if item.BiDashboardHomePageId > 0 {
  1049. homePageItem.BiDashboardHomePageId = item.BiDashboardHomePageId
  1050. }
  1051. err = bi_dashboard.SaveBiDashboardHomePage(homePageItem)
  1052. if err != nil {
  1053. br.Msg = "保存失败"
  1054. br.ErrMsg = "保存失败,Err:" + err.Error()
  1055. return
  1056. }
  1057. br.Ret = 200
  1058. br.Success = true
  1059. br.Msg = "保存成功"
  1060. return
  1061. }
  1062. // @router /editing [post]
  1063. func (this *BIDaShboardController) Editing() {
  1064. br := new(models.BaseResponse).Init()
  1065. defer func() {
  1066. if br.ErrMsg == "" {
  1067. br.IsSendEmail = false
  1068. }
  1069. this.Data["json"] = br
  1070. this.ServeJSON()
  1071. }()
  1072. sysUser := this.SysUser
  1073. if sysUser == nil {
  1074. br.Msg = "请登录"
  1075. br.ErrMsg = "请登录,SysUser Is Empty"
  1076. br.Ret = 408
  1077. return
  1078. }
  1079. var req bi_dashboard.BiDashboardEditingReq
  1080. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1081. if err != nil {
  1082. br.Msg = "参数解析异常!"
  1083. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1084. return
  1085. }
  1086. if req.BiDashboardId <= 0 {
  1087. br.Msg = "参数有误"
  1088. return
  1089. }
  1090. if req.Status < 0 {
  1091. br.Msg = "标记状态异常"
  1092. return
  1093. }
  1094. editor, e := services.UpdateBiDashboardEditing(req.BiDashboardId, req.Status, sysUser.AdminId, sysUser.RealName)
  1095. if e != nil {
  1096. br.Msg = "操作失败"
  1097. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  1098. return
  1099. }
  1100. br.Data = editor
  1101. br.Ret = 200
  1102. br.Success = true
  1103. br.Msg = "操作成功"
  1104. }