12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- package controllers
- import (
- "encoding/json"
- "errors"
- "eta_gn/eta_api/models"
- biapprove "eta_gn/eta_api/models/bi_approve"
- "eta_gn/eta_api/models/bi_dashboard"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services"
- biapproveSerice "eta_gn/eta_api/services/bi_approve"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- type BIDaShboardController struct {
- BaseAuthController
- }
- // GroupList
- // @Title 获取我的列表
- // @Description 获取我的列表接口
- // @Success 200 {object} models.RespGroupList
- // @router /my_list [get]
- func (this *BIDaShboardController) MyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 获取我的看板列表
- privateCond := ` AND sys_admin_id = ? `
- privatePars := []interface{}{this.SysUser.AdminId}
- privateList, err := bi_dashboard.GetBiDashboardList(privateCond, privatePars)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "查询成功"
- br.Data = privateList
- return
- }
- // AddDashboard
- // @Title 新增看板
- // @Description 新增看板接口
- // @Param request body models.AddDashboardReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /add [post]
- func (this *BIDaShboardController) AddDashboard() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.AddDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardName == "" {
- br.Msg = "名称不能为空"
- return
- }
- nameItem, err := bi_dashboard.GetDashboardByName(req.BiDashboardName)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "查询失败"
- br.ErrMsg = "查询失败,Err:" + err.Error()
- return
- }
- if nameItem != nil && nameItem.BiDashboardId > 0 {
- br.Msg = "名称重复"
- return
- }
- item := &bi_dashboard.BiDashboard{
- //BiDashboardClassifyId: req.ClassifyId,
- BiDashboardName: req.BiDashboardName,
- SysAdminId: this.SysUser.AdminId,
- SysAdminName: this.SysUser.RealName,
- //Sort: 0,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- State: 1,
- }
- id, e := bi_dashboard.AddBiDashboard(item)
- if e != nil {
- err = e
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + e.Error()
- return
- }
- detailList := make([]*bi_dashboard.BiDashboardDetail, 0)
- var isAddResource bool
- for i, v := range req.List {
- item := &bi_dashboard.BiDashboardDetail{
- BiDashboardId: int(id),
- Type: v.Type,
- UniqueCode: v.UniqueCode,
- Conf: v.Conf,
- Sort: i + 1,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- detailList = append(detailList, item)
- if v.Type == 3 {
- isAddResource = true
- }
- }
- err = bi_dashboard.AddBiDashboardDetailMulti(detailList)
- if err != nil {
- br.Msg = "新增详情失败"
- br.ErrMsg = "新增详情失败,Err:" + err.Error()
- return
- }
- if isAddResource {
- msg, err := services.SaveBiDashboardKnowledgeResource(item.BiDashboardId, this.SysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "新增知识资源失败"
- }
- br.Msg = msg
- br.ErrMsg = "新增知识资源失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // EditPpt
- // @Title 编辑看板
- // @Description 编辑看板接口
- // @Param request body bi_dashboard.EditDashboardReq true "type json string"
- // @Success 200 Ret=200 编辑成功
- // @router /edit [post]
- func (this *BIDaShboardController) EditDashboard() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.EditDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardName == "" {
- br.Msg = "标题不能为空"
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- // 判断权限
- if item.SysAdminId != this.SysUser.AdminId {
- br.Msg = `无权编辑`
- return
- }
- // 修改
- item.BiDashboardName = req.BiDashboardName
- item.ModifyTime = time.Now()
- err = bi_dashboard.EditDashboard(item)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- err = bi_dashboard.DeleteBiDashboardDetail(req.BiDashboardId)
- if err != nil {
- br.Msg = "删除详情失败"
- br.ErrMsg = "删除详情失败,Err:" + err.Error()
- return
- }
- detailList := make([]*bi_dashboard.BiDashboardDetail, 0)
- isEditResource := false
- for _, v := range req.List {
- item := &bi_dashboard.BiDashboardDetail{
- BiDashboardId: req.BiDashboardId,
- Type: v.Type,
- UniqueCode: v.UniqueCode,
- Conf: v.Conf,
- Sort: v.Sort,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- if v.Type == 3 {
- isEditResource = true
- }
- detailList = append(detailList, item)
- }
- err = bi_dashboard.AddBiDashboardDetailMulti(detailList)
- if err != nil {
- br.Msg = "新增详情失败"
- br.ErrMsg = "新增详情失败,Err:" + err.Error()
- return
- }
- if isEditResource {
- // 添加知识资源引用
- msg, err := services.SaveBiDashboardKnowledgeResource(item.BiDashboardId, this.SysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "编辑知识资源失败"
- }
- br.Msg = msg
- br.ErrMsg = "编辑知识资源失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- br.IsAddLog = true
- }
- // DeleteDashboard
- // @Title 删除看板
- // @Description 删除看板接口
- // @Param request body bi_dashboard.DelDashboardReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /delete [post]
- func (this *BIDaShboardController) DeleteDashboard() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.DelDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if item.SysAdminId != this.SysUser.AdminId {
- br.Msg = "无权删除"
- return
- }
- err = bi_dashboard.DelDashboard(req.BiDashboardId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- //如果该看板存在共享记录,则删除共享
- err = bi_dashboard.DeleteDashboardGrant(req.BiDashboardId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "删除成功"
- }
- // DeleteDashboard
- // @Title 删除看板详情
- // @Description 删除看板详情接口
- // @Param request body bi_dashboard.DelDashboardDetailReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /detail/delete [post]
- func (this *BIDaShboardController) DeleteDashboardDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.DelDashboardDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardDetailId <= 0 {
- br.Msg = "参数错误"
- return
- }
- err = bi_dashboard.DeleteBiDashboardDetailByDetailId(req.BiDashboardDetailId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "删除成功"
- }
- // DetailDashboard
- // @Title 获取看板详情
- // @Description 获取看板详情接口
- // @Param PptId query int true "PptId"
- // @Success 200 {object} models.PptV2
- // @router /detail [get]
- func (this *BIDaShboardController) DetailDashboard() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dashboardId, _ := this.GetInt("DashboardId")
- resp := new(bi_dashboard.DashboardDetailResp)
- dashboardItem, err := bi_dashboard.GetDashboardById(dashboardId)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- br.Msg = "我的看板列表查询出错"
- br.ErrMsg = err.Error()
- return
- }
- grantInfoList, err := bi_dashboard.GetDashboardGrantInfo(dashboardId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "共享信息获取失败,Err:" + err.Error()
- return
- }
- if len(grantInfoList) > 0 {
- resp.IsGrant = 1
- }
- detailList, err := bi_dashboard.GetBiDashboardDetailById(dashboardId)
- if err != nil {
- br.Msg = "详情获取失败"
- br.ErrMsg = "详情获取失败,Err:" + err.Error()
- return
- }
- editor, e := services.UpdateBiDashboardEditing(dashboardId, 0, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "编辑状态更新失败"
- br.ErrMsg = "编辑状态更新失败,Err:" + e.Error()
- return
- }
- resp.Editor = editor
- resp.BiDashboard = dashboardItem
- resp.List = detailList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MoveDashboard
- // @Title 移动看板详情
- // @Description 移动看板详情接口
- // @Param request body bi_dashboard.MoveDashboardDetailReq true "type json string"
- // @Success 200 Ret=200 移动成功
- // @router /detail/move [post]
- func (this *BIDaShboardController) MoveDashboard() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.MoveDashboardDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- if req.BiDashboardDetailId == req.OtherDetailId || req.BiDashboardDetailId <= 0 || req.OtherDetailId <= 0 {
- br.Msg = "看板Id有误"
- return
- }
- if req.Sort < 0 || req.OtherSort < 0 || req.Sort == req.OtherSort {
- br.Msg = "排序有误"
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- // 判断权限
- if item.SysAdminId != this.SysUser.AdminId {
- br.Msg = `无权移动`
- return
- }
- // 修改
- detailItem := &bi_dashboard.BiDashboardDetail{
- BiDashboardDetailId: req.BiDashboardDetailId,
- Sort: req.OtherSort,
- ModifyTime: time.Now(),
- }
- err = bi_dashboard.EditBiDashboardDetail(detailItem)
- if err != nil {
- br.Msg = "编辑详情失败"
- br.ErrMsg = "编辑详情失败,Err:" + err.Error()
- return
- }
- otherItem := &bi_dashboard.BiDashboardDetail{
- BiDashboardDetailId: req.OtherDetailId,
- Sort: req.Sort,
- ModifyTime: time.Now(),
- }
- err = bi_dashboard.EditBiDashboardDetail(otherItem)
- if err != nil {
- br.Msg = "编辑详情失败"
- br.ErrMsg = "编辑详情失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- br.IsAddLog = true
- }
- // ShareList
- // @Title 获取共享列表
- // @Description 获取共享列表接口
- // @Success 200 {object} models.RespGroupList
- // @router /share_list [get]
- func (this *BIDaShboardController) ShareList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //myPptList := make([]*bi_dashboard.BiDashboard, 0)
- //otherPptList := make([]*bi_dashboard.BiDashboard, 0)
- grantList := bi_dashboard.RespGroupList{}
- // 获取我的看板列表
- ShareList, err := bi_dashboard.GetAllMyShareList(this.SysUser.AdminId)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- br.ErrMsg = err.Error()
- br.Msg = "查询失败"
- return
- }
- grantList.MyList = ShareList
- //dashboardMap := make(map[int]*bi_dashboard.BiDashboard)
- adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
- adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
- grantDashboardList, err := bi_dashboard.GetAllGrantList(this.SysUser.AdminId)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- br.ErrMsg = err.Error()
- br.Msg = "查询失败"
- return
- }
- publicAdminIdList := make([]int, 0)
- publicDashboardListMap := make(map[int][]*bi_dashboard.BiDashboard)
- for _, v := range grantDashboardList {
- publicDashboardList, ok := publicDashboardListMap[v.SysAdminId]
- if !ok {
- publicDashboardList = make([]*bi_dashboard.BiDashboard, 0)
- publicAdminIdList = append(publicAdminIdList, v.SysAdminId)
- if _, ok := adminIdMap[v.SysAdminId]; !ok {
- adminIdList = append(adminIdList, v.SysAdminId) //需要查询的创建人admin_id列表集合
- adminIdMap[v.SysAdminId] = v.SysAdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
- }
- }
- tmp := &bi_dashboard.BiDashboard{
- BiDashboardId: v.BiDashboardId,
- BiDashboardName: v.BiDashboardName,
- CreateTime: v.CreateTime,
- ModifyTime: v.ModifyTime,
- Sort: v.Sort,
- State: v.State,
- SysAdminId: v.SysAdminId,
- SysAdminName: v.SysAdminName,
- }
- publicDashboardList = append(publicDashboardList, tmp)
- publicDashboardListMap[v.SysAdminId] = publicDashboardList
- }
- // 创建人信息
- systemAdminMap := make(map[int]*system.Admin)
- systemAdminList, err := system.GetAdminListByIdList(adminIdList)
- if err != nil {
- return
- }
- for _, v := range systemAdminList {
- systemAdminMap[v.AdminId] = v
- }
- for _, v := range publicAdminIdList {
- systemAdmin, ok := systemAdminMap[v]
- if !ok {
- continue
- }
- // 看板 列表信息
- respGroupNameListItemList, ok := publicDashboardListMap[v]
- if !ok {
- respGroupNameListItemList = make([]*bi_dashboard.BiDashboard, 0)
- }
- // ppt 分组信息
- tmpRespGroupListItem := &bi_dashboard.RespOtherGroupListItem{
- GroupId: int64(systemAdmin.AdminId),
- GroupName: systemAdmin.RealName,
- AdminId: systemAdmin.AdminId,
- DashboardList: respGroupNameListItemList,
- }
- grantList.OtherList = append(grantList.OtherList, tmpRespGroupListItem)
- }
- //if len(dashboradIds) > 0 {
- // // 通过dashboradIds列表字段获取所有的看板信息
- // dashboradList, tmpErr := bi_dashboard.GetDashboradByIds(dashboradIds)
- // if tmpErr != nil {
- // err = errors.New("查询dashborad详情出错:" + err.Error())
- // br.Msg = "查询dashborad详情出错"
- // br.ErrMsg = err.Error()
- // return
- // }
- // for _, v := range dashboradList {
- // dashboardMap[v.BiDashboardId] = v
- // }
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "查询成功"
- br.Data = grantList
- return
- }
- // PublicList
- // @Title 获取公共列表
- // @Description 获取公共列表接口
- // @Success 200 {object} models.RespGroupList
- // @router /public_list [get]
- func (this *BIDaShboardController) PublicList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := make([]*bi_dashboard.RespPublicGroupListItem, 0)
- // 获取公共看板列表
- publicCond := ` AND state = 6 AND bi_dashboard_classify_id > 0 `
- publicPars := make([]interface{}, 0)
- publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- return
- }
- //dashboardMap := make(map[int]*bi_dashboard.BiDashboard)
- adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
- adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
- publicAdminIdList := make([]int, 0)
- publicDashboardListMap := make(map[int][]*bi_dashboard.BiDashboard)
- publicDashboardClassifyIdMap := make(map[int]int)
- for _, v := range publicList {
- publicDashboardList, ok := publicDashboardListMap[v.SysAdminId]
- if !ok {
- publicDashboardList = make([]*bi_dashboard.BiDashboard, 0)
- publicAdminIdList = append(publicAdminIdList, v.SysAdminId)
- if _, ok := adminIdMap[v.SysAdminId]; !ok {
- adminIdList = append(adminIdList, v.SysAdminId) //需要查询的创建人admin_id列表集合
- adminIdMap[v.SysAdminId] = v.SysAdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
- }
- }
- tmp := &bi_dashboard.BiDashboard{
- BiDashboardId: v.BiDashboardId,
- BiDashboardClassifyId: v.BiDashboardClassifyId,
- BiDashboardName: v.BiDashboardName,
- CreateTime: v.CreateTime,
- ModifyTime: v.ModifyTime,
- Sort: v.Sort,
- State: v.State,
- SysAdminId: v.SysAdminId,
- SysAdminName: v.SysAdminName,
- }
- publicDashboardList = append(publicDashboardList, tmp)
- publicDashboardListMap[v.SysAdminId] = publicDashboardList
- publicDashboardClassifyIdMap[v.BiDashboardClassifyId] = v.BiDashboardClassifyId
- }
- // 创建人信息
- systemAdminMap := make(map[int]*system.Admin)
- systemAdminList, err := system.GetAdminListByIdList(adminIdList)
- if err != nil {
- return
- }
- for _, v := range systemAdminList {
- systemAdminMap[v.AdminId] = v
- }
- classifyList, err := bi_dashboard.GetBiDashboardClassifyAllList()
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "查询失败,Err:" + err.Error()
- return
- }
- for _, c := range classifyList {
- tmpItem := &bi_dashboard.RespPublicGroupListItem{
- GroupId: int64(c.BiDashboardClassifyId),
- GroupName: c.BiDashboardClassifyName,
- Children: make([]*bi_dashboard.RespPublicGroupListItem, 0),
- }
- _, ok := publicDashboardClassifyIdMap[c.BiDashboardClassifyId]
- if !ok {
- continue
- }
- tmpRespGroupIndexMap := make(map[int]int)
- child := make([]*bi_dashboard.RespPublicGroupListItem, 0)
- for _, v := range adminIdList {
- systemAdmin, ok := systemAdminMap[v]
- if !ok {
- continue
- }
- // 看板 列表信息
- respGroupNameListItemList, ok := publicDashboardListMap[v]
- if !ok {
- respGroupNameListItemList = make([]*bi_dashboard.BiDashboard, 0)
- }
- for _, vv := range respGroupNameListItemList {
- if vv.BiDashboardClassifyId == c.BiDashboardClassifyId {
- tmpIndex, ok := tmpRespGroupIndexMap[systemAdmin.AdminId]
- if !ok {
- // 用户的分组信息
- tmpRespGroupListItem := &bi_dashboard.RespPublicGroupListItem{
- GroupId: int64(systemAdmin.AdminId),
- GroupName: systemAdmin.RealName,
- AdminId: systemAdmin.AdminId,
- DashboardList: make([]*bi_dashboard.BiDashboard, 0),
- }
- tmpIndex = len(child)
- child = append(child, tmpRespGroupListItem)
- tmpRespGroupIndexMap[systemAdmin.AdminId] = tmpIndex
- }
- tmpRespGroupListItem := child[tmpIndex]
- child[tmpIndex].DashboardList = append(tmpRespGroupListItem.DashboardList, vv)
- //tmpItem.Children = append(tmpItem.Children, tmpRespGroupListItem)
- }
- tmpItem.Children = child
- }
- }
- resp = append(resp, tmpItem)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "查询成功"
- br.Data = resp
- return
- }
- // AddDashboardClassify
- // @Title 新增看板分类
- // @Description 新增看板分类接口
- // @Param request body bi_dashboard.AddDashboardClassifyReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /classify/add [post]
- func (this *BIDaShboardController) AddDashboardClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.AddDashboardClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "名称不能为空"
- return
- }
- maxSort, err := bi_dashboard.GetBiDashboardClassifyMaxSort()
- if err != nil {
- br.Msg = "获取最大排序值失败"
- br.ErrMsg = "获取最大排序值失败,Err:" + err.Error()
- return
- }
- count, err := bi_dashboard.GetBiDashboardClassifyByName(req.ClassifyName)
- if err != nil {
- br.Msg = "获取分类名称失败"
- br.ErrMsg = "获取分类名称失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类名称已存在"
- return
- }
- item := &bi_dashboard.BiDashboardClassify{
- BiDashboardClassifyName: req.ClassifyName,
- Sort: maxSort + 1,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- _, e := bi_dashboard.AddBiDashboardClassify(item)
- if e != nil {
- err = e
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- //br.Data =
- }
- // EditDashboardClassify
- // @Title 编辑看板分类
- // @Description 编辑看板分类接口
- // @Param request body bi_dashboard.EditDashboardReq true "type json string"
- // @Success 200 Ret=200 编辑成功
- // @router /classify/edit [post]
- func (this *BIDaShboardController) EditDashboardClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.EditDashboardClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "标题不能为空"
- return
- }
- if req.BiDashboardClassifyId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
- return
- }
- item, err := bi_dashboard.GetBiDashboardClassifyById(req.BiDashboardClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- // 修改
- item.BiDashboardClassifyName = req.ClassifyName
- item.ModifyTime = time.Now()
- err = bi_dashboard.EditDashboardClassify(item)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- err = biapproveSerice.ModifyBiApproveFlowClassify(req.BiDashboardClassifyId, req.ClassifyName)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- br.IsAddLog = true
- }
- // EditDashboardClassify
- // @Title 删除看板分类
- // @Description 删除看板分类接口
- // @Param request body bi_dashboard.DelDashboardClassifyReq true "type json string"
- // @Success 200 Ret=200 编辑成功
- // @router /classify/del [post]
- func (this *BIDaShboardController) DelDashboardClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.DelDashboardClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardClassifyId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, BiDashboardClassifyId: %d", req.BiDashboardClassifyId)
- return
- }
- publicCond := ` AND state = 6 AND bi_dashboard_classify_id = ? `
- publicPars := make([]interface{}, 0)
- publicPars = append(publicPars, req.BiDashboardClassifyId)
- publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- return
- }
- if len(publicList) > 0 {
- br.Msg = "该分类已关联看板,暂不支持删除!"
- return
- }
- // 查询是否关联审批流
- tmp, er := biapprove.GetBiApproveFlowByClassifyId(req.BiDashboardClassifyId)
- if er != nil && !utils.IsErrNoRow(er) {
- err = er
- br.Msg = "查询审批流出错"
- br.ErrMsg = "查询审批流出错:" + er.Error()
- return
- }
- if tmp.BiApproveFlowId > 0 {
- br.Msg = "该分类已关联审批流,暂不支持删除!"
- return
- }
- err = bi_dashboard.DelBiDashboardClassify(req.BiDashboardClassifyId)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- br.IsAddLog = true
- }
- // Grant
- // @Title 分配看板权限
- // @Description 分配看板权限接口
- // @Param request body models.GrantPptReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant [post]
- func (this *BIDaShboardController) Grant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.GrantDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.AdminIdStr == "" {
- br.Msg = "参数错误"
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dashboardItem, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- br.Msg = "我的看板列表查询出错"
- br.ErrMsg = err.Error()
- return
- }
- if dashboardItem.SysAdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- list := make([]*bi_dashboard.BiDashboardGrant, 0)
- grantAdminIdStrList := strings.Split(req.AdminIdStr, ",")
- lenGrantAdminIdStrList := len(grantAdminIdStrList) //指定用户的人数
- for _, v := range grantAdminIdStrList {
- grantAdminId, tmpErr := strconv.Atoi(v)
- if tmpErr != nil {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
- return
- }
- //如果只选择了自己作为指定的人,那么就提示他报错。如果多人,那么就过滤自己
- if grantAdminId == this.SysUser.AdminId {
- if lenGrantAdminIdStrList == 1 {
- br.Msg = "不能指定自己为权限用户"
- br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", tmpErr.Error())
- return
- }
- continue
- }
- tmpV := &bi_dashboard.BiDashboardGrant{
- BiDashboardId: req.BiDashboardId,
- GrantAdminId: grantAdminId,
- CreateTime: time.Now(),
- }
- list = append(list, tmpV)
- }
- if len(list) <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误,Err:%s", "指定用户为空")
- return
- }
- err = bi_dashboard.MultiAddDashboardGrant(req.BiDashboardId, list)
- if err != nil {
- br.Msg = "分配失败"
- br.ErrMsg = fmt.Sprintf("分配失败,Err:%s", err.Error())
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "分配成功"
- }
- // Public
- // @Title
- // @Description 设置公共看板
- // @Param request body models.GrantPptReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /public [post]
- func (this *BIDaShboardController) Public() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.PublicDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 校验是否开启了审批流
- opening, e := biapproveSerice.CheckBiOpenApprove(req.ClassifyId)
- if e != nil {
- if !utils.IsErrNoRow(e) {
- br.Msg = "该分类未配置审批流,请先配置审批流"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- if opening {
- _, err = biapproveSerice.SubmitBiApprove(req.BiDashboardId, item.BiDashboardName, req.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName)
- if err != nil {
- br.Msg = "提交审批失败"
- br.ErrMsg = "提交审批失败, Err: " + err.Error()
- return
- }
- item.State = 4
- } else {
- item.State = 6
- }
- item.BiDashboardClassifyId = req.ClassifyId
- err = bi_dashboard.EditDashboard(item)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "分配成功"
- }
- // GroupList
- // @Title 获取分类列表
- // @Description 获取分类列表接口
- // @Success 200 {object} models.RespGroupList
- // @router /classify/list [get]
- func (this *BIDaShboardController) ClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := bi_dashboard.GetBiDashboardClassifyAllList()
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "查询失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "查询成功"
- br.Data = classifyList
- return
- }
- // CancelGrant
- // @Title 取消分配看板权限
- // @Description 取消分配看板权限
- // @Param request body bi_dashboard.DelDashboardReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /grant/cancel [post]
- func (this *BIDaShboardController) CancelGrant() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.DelDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil {
- br.Msg = "数据不存在"
- br.ErrMsg = "数据不存在,Err:" + err.Error()
- return
- }
- if item.SysAdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- // 分配
- err = bi_dashboard.DeleteDashboardGrant(req.BiDashboardId)
- if err != nil {
- br.Msg = "取消失败"
- br.ErrMsg = "取消失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "取消成功"
- }
- // GrantInfo
- // @Title 获取分配ppt权限详情
- // @Description 获取分配ppt权限详情接口
- // @Param BiDashboardId query int true "看板的id"
- // @Success 200 {object} models.GrantInfoResp
- // @router /grant/info [get]
- func (this *BIDaShboardController) GrantInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- biDashboardId, _ := this.GetInt("BiDashboardId")
- if biDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := bi_dashboard.GetDashboardById(biDashboardId)
- if err != nil {
- br.Msg = "数据不存在"
- br.ErrMsg = "数据不存在,Err:" + err.Error()
- return
- }
- if item.SysAdminId != this.SysUser.AdminId {
- br.Msg = "无权配置"
- return
- }
- grantInfoList, err := bi_dashboard.GetDashboardGrantInfo(biDashboardId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- if len(grantInfoList) <= 0 {
- br.Msg = "未配置"
- br.IsSendEmail = false
- br.Success = true
- br.Ret = 200
- return
- }
- var adminIdStr string
- adminIdsList := make([]string, 0)
- for _, v := range grantInfoList {
- adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
- }
- adminIdStr = strings.Join(adminIdsList, ",")
- br.Ret = 200
- br.Success = true
- br.Data = adminIdStr
- br.Msg = "查询成功"
- }
- // Public
- // @Title
- // @Description 撤销公共看板
- // @Param request body models.GrantPptReq true "type json string"
- // @Success 200 Ret=200 分配成功
- // @router /public/cancel [post]
- func (this *BIDaShboardController) PublicCancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.DelDashboardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- item, err := bi_dashboard.GetDashboardById(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- // 校验是否开启了审批流
- opening, e := biapproveSerice.CheckBiOpenApprove(item.BiDashboardClassifyId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- if opening {
- approvalItem, err := biapprove.GetBiApproveByBoardId(req.BiDashboardId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据异常!"
- br.ErrMsg = "获取数据异常,Err:" + err.Error()
- return
- }
- // 撤销审批
- msg, e := biapproveSerice.BiApproveCancel(approvalItem.BiApproveId, this.SysUser.AdminId, this.SysUser.RealName)
- if e != nil {
- if msg != "" {
- br.Msg = msg
- } else {
- br.Msg = "操作失败"
- }
- br.ErrMsg = "撤销审批失败, Err: " + e.Error()
- return
- }
- }
- item.BiDashboardClassifyId = 0
- item.State = 1
- err = bi_dashboard.SaveDashboard(item)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "撤销成功"
- }
- // GroupList
- // @Title 获取我的首页看板
- // @Description 获取我的首页看板接口
- // @Success 200 {object} models.RespGroupList
- // @router /home_page [get]
- func (this *BIDaShboardController) HomePage() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "数据不存在"
- br.ErrMsg = "数据不存在,Err:" + err.Error()
- return
- }
- publicCond := ` AND state = 6 AND bi_dashboard_classify_id > 0 `
- publicPars := []interface{}{this.SysUser.AdminId}
- publicList, err := bi_dashboard.GetBiDashboardList(publicCond, publicPars)
- if err != nil {
- err = errors.New("我的看板列表查询出错:" + err.Error())
- return
- }
- if item.BiDashboardHomePageId == 0 && len(publicList) > 0 {
- item = &bi_dashboard.BiDashboardHomePage{
- AdminId: publicList[0].SysAdminId,
- BiDashboardId: publicList[0].BiDashboardId,
- FromType: 3,
- }
- }
- if item.BiDashboardId == 0 {
- item = nil
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "查询成功"
- br.Data = item
- return
- }
- // GroupList
- // @Title 保存我的看板首页
- // @Description保存我的看板首页接口
- // @Success 200 {object} models.RespGroupList
- // @router /home_page/save [post]
- func (this *BIDaShboardController) HomePageSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req bi_dashboard.SaveHomePageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := bi_dashboard.GetBiDashboardHomePageById(this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "数据不存在"
- br.ErrMsg = "数据不存在,Err:" + err.Error()
- return
- }
- homePageItem := &bi_dashboard.BiDashboardHomePage{
- BiDashboardId: req.BiDashboardId,
- AdminId: this.SysUser.AdminId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- FromType: req.FromType,
- }
- if item.BiDashboardHomePageId > 0 {
- homePageItem.BiDashboardHomePageId = item.BiDashboardHomePageId
- }
- err = bi_dashboard.SaveBiDashboardHomePage(homePageItem)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- // Editing
- // @Title 标记/查询编辑状态
- // @Description 标记/查询编辑状态
- // @Param request body models.PPTEditingReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /editing [post]
- func (this *BIDaShboardController) Editing() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req bi_dashboard.BiDashboardEditingReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BiDashboardId <= 0 {
- br.Msg = "参数有误"
- return
- }
- if req.Status < 0 {
- br.Msg = "标记状态异常"
- return
- }
- editor, e := services.UpdateBiDashboardEditing(req.BiDashboardId, req.Status, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
- return
- }
- br.Data = editor
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|