bi_dashboard.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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. _, ok := publicDashboardClassifyIdMap[c.BiDashboardClassifyId]
  615. if !ok {
  616. continue
  617. }
  618. tmpRespGroupIndexMap := make(map[int]int)
  619. child := make([]*bi_dashboard.RespPublicGroupListItem, 0)
  620. for _, v := range adminIdList {
  621. systemAdmin, ok := systemAdminMap[v]
  622. if !ok {
  623. continue
  624. }
  625. // 看板 列表信息
  626. respGroupNameListItemList, ok := publicDashboardListMap[v]
  627. if !ok {
  628. respGroupNameListItemList = make([]*bi_dashboard.BiDashboard, 0)
  629. }
  630. for _, vv := range respGroupNameListItemList {
  631. if vv.BiDashboardClassifyId == c.BiDashboardClassifyId {
  632. tmpIndex, ok := tmpRespGroupIndexMap[systemAdmin.AdminId]
  633. if !ok {
  634. // 用户的分组信息
  635. tmpRespGroupListItem := &bi_dashboard.RespPublicGroupListItem{
  636. GroupId: int64(systemAdmin.AdminId),
  637. GroupName: systemAdmin.RealName,
  638. AdminId: systemAdmin.AdminId,
  639. DashboardList: make([]*bi_dashboard.BiDashboard, 0),
  640. }
  641. tmpIndex = len(child)
  642. child = append(child, tmpRespGroupListItem)
  643. tmpRespGroupIndexMap[systemAdmin.AdminId] = tmpIndex
  644. }
  645. tmpRespGroupListItem := child[tmpIndex]
  646. child[tmpIndex].DashboardList = append(tmpRespGroupListItem.DashboardList, vv)
  647. //tmpItem.Children = append(tmpItem.Children, tmpRespGroupListItem)
  648. }
  649. tmpItem.Children = child
  650. }
  651. }
  652. resp = append(resp, tmpItem)
  653. }
  654. br.Ret = 200
  655. br.Success = true
  656. br.Msg = "查询成功"
  657. br.Data = resp
  658. return
  659. }
  660. // AddDashboardClassify
  661. // @Title 新增看板分类
  662. // @Description 新增看板分类接口
  663. // @Param request body bi_dashboard.AddDashboardClassifyReq true "type json string"
  664. // @Success 200 Ret=200 新增成功
  665. // @router /classify/add [post]
  666. func (this *BIDaShboardController) AddDashboardClassify() {
  667. br := new(models.BaseResponse).Init()
  668. defer func() {
  669. this.Data["json"] = br
  670. this.ServeJSON()
  671. }()
  672. var req bi_dashboard.AddDashboardClassifyReq
  673. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  674. if err != nil {
  675. br.Msg = "参数解析异常!"
  676. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  677. return
  678. }
  679. if req.ClassifyName == "" {
  680. br.Msg = "名称不能为空"
  681. return
  682. }
  683. maxSort, err := bi_dashboard.GetBiDashboardClassifyMaxSort()
  684. if err != nil {
  685. br.Msg = "获取最大排序值失败"
  686. br.ErrMsg = "获取最大排序值失败,Err:" + err.Error()
  687. return
  688. }
  689. count, err := bi_dashboard.GetBiDashboardClassifyByName(req.ClassifyName)
  690. if err != nil {
  691. br.Msg = "获取分类名称失败"
  692. br.ErrMsg = "获取分类名称失败,Err:" + err.Error()
  693. return
  694. }
  695. if count > 0 {
  696. br.Msg = "分类名称已存在"
  697. return
  698. }
  699. item := &bi_dashboard.BiDashboardClassify{
  700. BiDashboardClassifyName: req.ClassifyName,
  701. Sort: maxSort + 1,
  702. CreateTime: time.Now(),
  703. ModifyTime: time.Now(),
  704. }
  705. _, e := bi_dashboard.AddBiDashboardClassify(item)
  706. if e != nil {
  707. err = e
  708. br.Msg = "新增失败"
  709. br.ErrMsg = "新增失败,Err:" + e.Error()
  710. return
  711. }
  712. br.Ret = 200
  713. br.Success = true
  714. br.Msg = "新增成功"
  715. //br.Data =
  716. }
  717. // EditDashboardClassify
  718. // @Title 编辑看板分类
  719. // @Description 编辑看板分类接口
  720. // @Param request body bi_dashboard.EditDashboardReq true "type json string"
  721. // @Success 200 Ret=200 编辑成功
  722. // @router /classify/edit [post]
  723. func (this *BIDaShboardController) EditDashboardClassify() {
  724. br := new(models.BaseResponse).Init()
  725. defer func() {
  726. this.Data["json"] = br
  727. this.ServeJSON()
  728. }()
  729. var req bi_dashboard.EditDashboardClassifyReq
  730. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  731. if err != nil {
  732. br.Msg = "参数解析异常!"
  733. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  734. return
  735. }
  736. if req.ClassifyName == "" {
  737. br.Msg = "标题不能为空"
  738. return
  739. }
  740. if req.BiDashboardClassifyId <= 0 {
  741. br.Msg = "参数有误"
  742. br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
  743. return
  744. }
  745. item, err := bi_dashboard.GetBiDashboardClassifyById(req.BiDashboardClassifyId)
  746. if err != nil && !utils.IsErrNoRow(err) {
  747. br.Msg = "获取数据异常!"
  748. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  749. return
  750. }
  751. // 修改
  752. item.BiDashboardClassifyName = req.ClassifyName
  753. item.ModifyTime = time.Now()
  754. err = bi_dashboard.EditDashboardClassify(item)
  755. if err != nil {
  756. br.Msg = "编辑失败"
  757. br.ErrMsg = "编辑失败,Err:" + err.Error()
  758. return
  759. }
  760. err = biapproveSerice.ModifyBiApproveFlowClassify(req.BiDashboardClassifyId, req.ClassifyName)
  761. if err != nil {
  762. br.Msg = "编辑失败"
  763. br.ErrMsg = "编辑失败,Err:" + err.Error()
  764. return
  765. }
  766. br.Ret = 200
  767. br.Success = true
  768. br.Msg = "编辑成功"
  769. br.IsAddLog = true
  770. }
  771. // EditDashboardClassify
  772. // @Title 删除看板分类
  773. // @Description 删除看板分类接口
  774. // @Param request body bi_dashboard.DelDashboardClassifyReq true "type json string"
  775. // @Success 200 Ret=200 编辑成功
  776. // @router /classify/del [post]
  777. func (this *BIDaShboardController) DelDashboardClassify() {
  778. br := new(models.BaseResponse).Init()
  779. defer func() {
  780. this.Data["json"] = br
  781. this.ServeJSON()
  782. }()
  783. var req bi_dashboard.DelDashboardClassifyReq
  784. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  785. if err != nil {
  786. br.Msg = "参数解析异常!"
  787. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  788. return
  789. }
  790. if req.BiDashboardClassifyId <= 0 {
  791. br.Msg = "参数有误"
  792. br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
  793. return
  794. }
  795. publicCond := ` AND state = 6 AND bi_dashboard_classify_id = ? `
  796. publicPars := make([]interface{}, 0)
  797. publicPars = append(publicPars, req.BiDashboardClassifyId)
  798. publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
  799. if err != nil {
  800. err = errors.New("我的看板列表查询出错:" + err.Error())
  801. return
  802. }
  803. if len(publicList) > 0 {
  804. br.Msg = "该分类已关联看板,暂不支持删除!"
  805. return
  806. }
  807. // 查询是否关联审批流
  808. tmp, er := biapprove.GetBiApproveFlowByClassifyId(req.BiDashboardClassifyId)
  809. if er != nil && !utils.IsErrNoRow(er) {
  810. err = er
  811. br.Msg = "查询审批流出错"
  812. br.ErrMsg = "查询审批流出错:" + er.Error()
  813. return
  814. }
  815. if tmp.BiApproveFlowId > 0 {
  816. br.Msg = "该分类已关联审批流,暂不支持删除!"
  817. return
  818. }
  819. err = bi_dashboard.DelBiDashboardClassify(req.BiDashboardClassifyId)
  820. if err != nil {
  821. br.Msg = "编辑失败"
  822. br.ErrMsg = "编辑失败,Err:" + err.Error()
  823. return
  824. }
  825. br.Ret = 200
  826. br.Success = true
  827. br.Msg = "删除成功"
  828. br.IsAddLog = true
  829. }
  830. // Grant
  831. // @Title 分配看板权限
  832. // @Description 分配看板权限接口
  833. // @Param request body models.GrantPptReq true "type json string"
  834. // @Success 200 Ret=200 分配成功
  835. // @router /grant [post]
  836. func (this *BIDaShboardController) Grant() {
  837. br := new(models.BaseResponse).Init()
  838. defer func() {
  839. this.Data["json"] = br
  840. this.ServeJSON()
  841. }()
  842. var req bi_dashboard.GrantDashboardReq
  843. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  844. if err != nil {
  845. br.Msg = "参数解析异常!"
  846. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  847. return
  848. }
  849. if req.AdminIdStr == "" {
  850. br.Msg = "参数错误"
  851. return
  852. }
  853. if req.BiDashboardId <= 0 {
  854. br.Msg = "参数错误"
  855. return
  856. }
  857. dashboardItem, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  858. if err != nil {
  859. err = errors.New("我的看板列表查询出错:" + err.Error())
  860. br.Msg = "我的看板列表查询出错"
  861. br.ErrMsg = err.Error()
  862. return
  863. }
  864. if dashboardItem.SysAdminId != this.SysUser.AdminId {
  865. br.Msg = "无权配置"
  866. return
  867. }
  868. list := make([]*bi_dashboard.BiDashboardGrant, 0)
  869. grantAdminIdStrList := strings.Split(req.AdminIdStr, ",")
  870. lenGrantAdminIdStrList := len(grantAdminIdStrList) //指定用户的人数
  871. for _, v := range grantAdminIdStrList {
  872. grantAdminId, tmpErr := strconv.Atoi(v)
  873. if tmpErr != nil {
  874. br.Msg = "参数有误"
  875. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
  876. return
  877. }
  878. //如果只选择了自己作为指定的人,那么就提示他报错。如果多人,那么就过滤自己
  879. if grantAdminId == this.SysUser.AdminId {
  880. if lenGrantAdminIdStrList == 1 {
  881. br.Msg = "不能指定自己为权限用户"
  882. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
  883. return
  884. }
  885. continue
  886. }
  887. tmpV := &bi_dashboard.BiDashboardGrant{
  888. BiDashboardId: req.BiDashboardId,
  889. GrantAdminId: grantAdminId,
  890. CreateTime: time.Now(),
  891. }
  892. list = append(list, tmpV)
  893. }
  894. if len(list) <= 0 {
  895. br.Msg = "参数有误"
  896. br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", "指定用户为空")
  897. return
  898. }
  899. err = bi_dashboard.MultiAddDashboardGrant(req.BiDashboardId, list)
  900. if err != nil {
  901. br.Msg = "分配失败"
  902. br.ErrMsg = fmt.Sprintf("分配失败,Err:%s", err.Error())
  903. return
  904. }
  905. br.Ret = 200
  906. br.Success = true
  907. br.IsAddLog = true
  908. br.Msg = "分配成功"
  909. }
  910. // Public
  911. // @Title
  912. // @Description 设置公共看板
  913. // @Param request body models.GrantPptReq true "type json string"
  914. // @Success 200 Ret=200 分配成功
  915. // @router /public [post]
  916. func (this *BIDaShboardController) Public() {
  917. br := new(models.BaseResponse).Init()
  918. defer func() {
  919. this.Data["json"] = br
  920. this.ServeJSON()
  921. }()
  922. var req bi_dashboard.PublicDashboardReq
  923. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  924. if err != nil {
  925. br.Msg = "参数解析异常!"
  926. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  927. return
  928. }
  929. // 校验是否开启了审批流
  930. opening, e := biapproveSerice.CheckBiOpenApprove(req.ClassifyId)
  931. if e != nil {
  932. if !utils.IsErrNoRow(e) {
  933. br.Msg = "该分类未配置审批流,请先配置审批流"
  934. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  935. return
  936. }
  937. br.Msg = "操作失败"
  938. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  939. return
  940. }
  941. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  942. if err != nil && !utils.IsErrNoRow(err) {
  943. br.Msg = "获取数据异常!"
  944. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  945. return
  946. }
  947. if opening {
  948. _, err = biapproveSerice.SubmitBiApprove(req.BiDashboardId, item.BiDashboardName, req.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName)
  949. if err != nil {
  950. br.Msg = "提交审批失败"
  951. br.ErrMsg = "提交审批失败, Err: " + err.Error()
  952. return
  953. }
  954. item.State = 4
  955. } else {
  956. item.State = 6
  957. }
  958. item.BiDashboardClassifyId = req.ClassifyId
  959. err = bi_dashboard.EditDashboard(item)
  960. if err != nil {
  961. br.Msg = "编辑失败"
  962. br.ErrMsg = "编辑失败,Err:" + err.Error()
  963. return
  964. }
  965. br.Ret = 200
  966. br.Success = true
  967. br.IsAddLog = true
  968. br.Msg = "分配成功"
  969. }
  970. // GroupList
  971. // @Title 获取分类列表
  972. // @Description 获取分类列表接口
  973. // @Success 200 {object} models.RespGroupList
  974. // @router /classify/list [get]
  975. func (this *BIDaShboardController) ClassifyList() {
  976. br := new(models.BaseResponse).Init()
  977. defer func() {
  978. this.Data["json"] = br
  979. this.ServeJSON()
  980. }()
  981. classifyList, err := bi_dashboard.GetBiDashboardClassifyAllList()
  982. if err != nil {
  983. br.Msg = "查询失败"
  984. br.ErrMsg = "查询失败,Err:" + err.Error()
  985. return
  986. }
  987. br.Ret = 200
  988. br.Success = true
  989. br.Msg = "查询成功"
  990. br.Data = classifyList
  991. return
  992. }
  993. // CancelGrant
  994. // @Title 取消分配看板权限
  995. // @Description 取消分配看板权限
  996. // @Param request body bi_dashboard.DelDashboardReq true "type json string"
  997. // @Success 200 Ret=200 分配成功
  998. // @router /grant/cancel [post]
  999. func (this *BIDaShboardController) CancelGrant() {
  1000. br := new(models.BaseResponse).Init()
  1001. defer func() {
  1002. this.Data["json"] = br
  1003. this.ServeJSON()
  1004. }()
  1005. var req bi_dashboard.DelDashboardReq
  1006. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1007. if err != nil {
  1008. br.Msg = "参数解析异常!"
  1009. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1010. return
  1011. }
  1012. if req.BiDashboardId <= 0 {
  1013. br.Msg = "参数错误"
  1014. return
  1015. }
  1016. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  1017. if err != nil {
  1018. br.Msg = "数据不存在"
  1019. br.ErrMsg = "数据不存在,Err:" + err.Error()
  1020. return
  1021. }
  1022. if item.SysAdminId != this.SysUser.AdminId {
  1023. br.Msg = "无权配置"
  1024. return
  1025. }
  1026. // 分配
  1027. err = bi_dashboard.DeleteDashboardGrant(req.BiDashboardId)
  1028. if err != nil {
  1029. br.Msg = "取消失败"
  1030. br.ErrMsg = "取消失败,Err:" + err.Error()
  1031. return
  1032. }
  1033. br.Ret = 200
  1034. br.Success = true
  1035. br.IsAddLog = true
  1036. br.Msg = "取消成功"
  1037. }
  1038. // GrantInfo
  1039. // @Title 获取分配ppt权限详情
  1040. // @Description 获取分配ppt权限详情接口
  1041. // @Param BiDashboardId query int true "看板的id"
  1042. // @Success 200 {object} models.GrantInfoResp
  1043. // @router /grant/info [get]
  1044. func (this *BIDaShboardController) GrantInfo() {
  1045. br := new(models.BaseResponse).Init()
  1046. defer func() {
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. biDashboardId, _ := this.GetInt("BiDashboardId")
  1051. if biDashboardId <= 0 {
  1052. br.Msg = "参数错误"
  1053. return
  1054. }
  1055. item, err := bi_dashboard.GetDashboardById(biDashboardId)
  1056. if err != nil {
  1057. br.Msg = "数据不存在"
  1058. br.ErrMsg = "数据不存在,Err:" + err.Error()
  1059. return
  1060. }
  1061. if item.SysAdminId != this.SysUser.AdminId {
  1062. br.Msg = "无权配置"
  1063. return
  1064. }
  1065. grantInfoList, err := bi_dashboard.GetDashboardGrantInfo(biDashboardId)
  1066. if err != nil {
  1067. br.Msg = "信息获取失败"
  1068. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. if len(grantInfoList) <= 0 {
  1072. br.Msg = "未配置"
  1073. br.IsSendEmail = false
  1074. br.Success = true
  1075. br.Ret = 200
  1076. return
  1077. }
  1078. var adminIdStr string
  1079. adminIdsList := make([]string, 0)
  1080. for _, v := range grantInfoList {
  1081. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  1082. }
  1083. adminIdStr = strings.Join(adminIdsList, ",")
  1084. br.Ret = 200
  1085. br.Success = true
  1086. br.Data = adminIdStr
  1087. br.Msg = "查询成功"
  1088. }
  1089. // Public
  1090. // @Title
  1091. // @Description 撤销公共看板
  1092. // @Param request body models.GrantPptReq true "type json string"
  1093. // @Success 200 Ret=200 分配成功
  1094. // @router /public/cancel [post]
  1095. func (this *BIDaShboardController) PublicCancel() {
  1096. br := new(models.BaseResponse).Init()
  1097. defer func() {
  1098. this.Data["json"] = br
  1099. this.ServeJSON()
  1100. }()
  1101. var req bi_dashboard.DelDashboardReq
  1102. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1103. if err != nil {
  1104. br.Msg = "参数解析异常!"
  1105. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1106. return
  1107. }
  1108. item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
  1109. if err != nil && !utils.IsErrNoRow(err) {
  1110. br.Msg = "获取数据异常!"
  1111. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1112. return
  1113. }
  1114. // 校验是否开启了审批流
  1115. opening, e := biapproveSerice.CheckBiOpenApprove(item.BiDashboardClassifyId)
  1116. if e != nil {
  1117. br.Msg = "操作失败"
  1118. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1119. return
  1120. }
  1121. if opening {
  1122. approvalItem, err := biapprove.GetBiApproveByBoardId(req.BiDashboardId)
  1123. if err != nil && !utils.IsErrNoRow(err) {
  1124. br.Msg = "获取数据异常!"
  1125. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1126. return
  1127. }
  1128. // 撤销审批
  1129. msg, e := biapproveSerice.BiApproveCancel(approvalItem.BiApproveId, this.SysUser.AdminId, this.SysUser.RealName)
  1130. if e != nil {
  1131. if msg != "" {
  1132. br.Msg = msg
  1133. } else {
  1134. br.Msg = "操作失败"
  1135. }
  1136. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1137. return
  1138. }
  1139. }
  1140. item.BiDashboardClassifyId = 0
  1141. item.State = 1
  1142. err = bi_dashboard.SaveDashboard(item)
  1143. if err != nil {
  1144. br.Msg = "编辑失败"
  1145. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1146. return
  1147. }
  1148. br.Ret = 200
  1149. br.Success = true
  1150. br.IsAddLog = true
  1151. br.Msg = "撤销成功"
  1152. }
  1153. // GroupList
  1154. // @Title 获取我的首页看板
  1155. // @Description 获取我的首页看板接口
  1156. // @Success 200 {object} models.RespGroupList
  1157. // @router /home_page [get]
  1158. func (this *BIDaShboardController) HomePage() {
  1159. br := new(models.BaseResponse).Init()
  1160. defer func() {
  1161. this.Data["json"] = br
  1162. this.ServeJSON()
  1163. }()
  1164. item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
  1165. if err != nil && !utils.IsErrNoRow(err) {
  1166. br.Msg = "数据不存在"
  1167. br.ErrMsg = "数据不存在,Err:" + err.Error()
  1168. return
  1169. }
  1170. publicCond := ` AND state = 6 AND bi_dashboard_classify_id > 0 `
  1171. publicPars := []interface{}{this.SysUser.AdminId}
  1172. publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
  1173. if err != nil {
  1174. err = errors.New("我的看板列表查询出错:" + err.Error())
  1175. return
  1176. }
  1177. if item.BiDashboardHomePageId == 0 && len(publicList) > 0 {
  1178. item = &bi_dashboard.BiDashboardHomePage{
  1179. AdminId: publicList[0].SysAdminId,
  1180. BiDashboardId: publicList[0].BiDashboardId,
  1181. FromType: 3,
  1182. }
  1183. }
  1184. if item.BiDashboardId == 0 {
  1185. item = nil
  1186. }
  1187. br.Ret = 200
  1188. br.Success = true
  1189. br.Msg = "查询成功"
  1190. br.Data = item
  1191. return
  1192. }
  1193. // GroupList
  1194. // @Title 保存我的看板首页
  1195. // @Description保存我的看板首页接口
  1196. // @Success 200 {object} models.RespGroupList
  1197. // @router /home_page/save [post]
  1198. func (this *BIDaShboardController) HomePageSave() {
  1199. br := new(models.BaseResponse).Init()
  1200. defer func() {
  1201. this.Data["json"] = br
  1202. this.ServeJSON()
  1203. }()
  1204. var req bi_dashboard.SaveHomePageReq
  1205. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1206. if err != nil {
  1207. br.Msg = "参数解析异常!"
  1208. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. if req.BiDashboardId <= 0 {
  1212. br.Msg = "参数错误"
  1213. return
  1214. }
  1215. item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
  1216. if err != nil && !utils.IsErrNoRow(err) {
  1217. br.Msg = "数据不存在"
  1218. br.ErrMsg = "数据不存在,Err:" + err.Error()
  1219. return
  1220. }
  1221. homePageItem := &bi_dashboard.BiDashboardHomePage{
  1222. BiDashboardId: req.BiDashboardId,
  1223. AdminId: this.SysUser.AdminId,
  1224. CreateTime: time.Now(),
  1225. ModifyTime: time.Now(),
  1226. FromType: req.FromType,
  1227. }
  1228. if item.BiDashboardHomePageId > 0 {
  1229. homePageItem.BiDashboardHomePageId = item.BiDashboardHomePageId
  1230. }
  1231. err = bi_dashboard.SaveBiDashboardHomePage(homePageItem)
  1232. if err != nil {
  1233. br.Msg = "保存失败"
  1234. br.ErrMsg = "保存失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. br.Ret = 200
  1238. br.Success = true
  1239. br.Msg = "保存成功"
  1240. return
  1241. }
  1242. // Editing
  1243. // @Title 标记/查询编辑状态
  1244. // @Description 标记/查询编辑状态
  1245. // @Param request body models.PPTEditingReq true "type json string"
  1246. // @Success 200 Ret=200 操作成功
  1247. // @router /editing [post]
  1248. func (this *BIDaShboardController) Editing() {
  1249. br := new(models.BaseResponse).Init()
  1250. defer func() {
  1251. if br.ErrMsg == "" {
  1252. br.IsSendEmail = false
  1253. }
  1254. this.Data["json"] = br
  1255. this.ServeJSON()
  1256. }()
  1257. sysUser := this.SysUser
  1258. if sysUser == nil {
  1259. br.Msg = "请登录"
  1260. br.ErrMsg = "请登录,SysUser Is Empty"
  1261. br.Ret = 408
  1262. return
  1263. }
  1264. var req bi_dashboard.BiDashboardEditingReq
  1265. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1266. if err != nil {
  1267. br.Msg = "参数解析异常!"
  1268. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. if req.BiDashboardId <= 0 {
  1272. br.Msg = "参数有误"
  1273. return
  1274. }
  1275. if req.Status < 0 {
  1276. br.Msg = "标记状态异常"
  1277. return
  1278. }
  1279. editor, e := services.UpdateBiDashboardEditing(req.BiDashboardId, req.Status, sysUser.AdminId, sysUser.RealName)
  1280. if e != nil {
  1281. br.Msg = "操作失败"
  1282. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  1283. return
  1284. }
  1285. br.Data = editor
  1286. br.Ret = 200
  1287. br.Success = true
  1288. br.Msg = "操作成功"
  1289. }