bi_dashboard.go 35 KB

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