bi_dashboard.go 30 KB

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