bi_dashboard.go 37 KB

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