bi_dashboard.go 36 KB

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