package biapprove import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/bi_approve/request" "eta_gn/eta_api/models/bi_approve/response" biapprove "eta_gn/eta_api/services/bi_approve" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" ) type BiApproveController struct { controllers.BaseAuthController } // List // @Title 审批列表 // @Description 审批列表 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码" // @Param ListType query int true "列表类型:1-待处理;2-已处理;3-我发起的" // @Param ClassifyId query int false "分类ID" // @Param Keyword query string false "搜索关键词" // @Param ApproveState query int false "审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" // @Param TimeType query int false "时间类型:1-提交时间;2-处理时间;3-审批时间" // @Param StartTime query string false "开始时间" // @Param EndTime query string false "结束时间" // @Param SortField query int false "排序字段:1-提交时间;2-处理时间;3-审批时间" // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)" // @Success 200 {object} report_approve.BiApproveListResp // @router /list [get] func (this *BiApproveController) List() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") listType, _ := this.GetInt("ListType") approveState, _ := this.GetInt("ApproveState") timeType, _ := this.GetInt("TimeType") startTime := this.GetString("StartTime") endTime := this.GetString("EndTime") sortField, _ := this.GetInt("SortField") sortRule, _ := this.GetInt("SortRule") classifyId, _ := this.GetInt("ClassifyId") keyword := this.GetString("Keyword") if pageSize <= 0 { pageSize = utils.PageSize10 } if currentIndex <= 0 { currentIndex = 1 } startSize := paging.StartIndex(currentIndex, pageSize) var list []*response.BiApproveItemOrmResp var total int var msg string var err error classifyList, msg, err := biapprove.GetBiClassifyAll() if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批列表成功" } br.ErrMsg = "获取分类列表失败, Err: " + err.Error() return } classifyMap := make(map[int]string) for _, v := range classifyList { classifyMap[v.BiDashboardClassifyId] = v.BiDashboardClassifyName } switch listType { case 1: list, total, msg, err = biapprove.ProcessingBiApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword) case 2: list, total, msg, err = biapprove.SolvedBiApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword) case 3: list, total, msg, err = biapprove.MyApplyBiApproves(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword) default: br.Msg = "列表类型错误" return } if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批列表失败" } br.ErrMsg = "获取审批列表失败, Err: " + err.Error() return } for _, v := range list { v.ClassifyName = classifyMap[v.ClassifyId] } resp := new(response.BiApproveListResp) page := paging.GetPaging(currentIndex, pageSize, total) resp.List = list resp.Paging = page br.Msg = "获取审批列表成功" br.Data = resp br.Ret = 200 br.Success = true } // list // @Title 公共看板分类列表 // @Description 公共看板分类列表 // @Success 200 {object} report_approve.BiApproveFlowDetailItem // @router /classify/list [get] func (this *BiApproveController) ClassifyList() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() res, msg, err := biapprove.GetPulicBiClassifyList() if err != nil { if msg == "" { br.Msg = "获取分类列表失败" } else { br.Msg = msg } br.ErrMsg = err.Error() return } br.Data = res br.Msg = "获取分类列表成功" br.Ret = 200 br.Success = true } // Approve // @Title 通过审批 // @Description 通过审批 // @Param request body report_approve.BiApprovePassReq true "type json string" // @Success 200 string "操作成功" // @router /approve [post] func (this *BiApproveController) Approve() { 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 request.BiApprovePassReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.BiApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId) return } // 通过审批 msg, err := biapprove.PassBiApprove(req.BiApproveId, sysUser.AdminId) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "操作失败" } br.ErrMsg = "通过审批失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" } // Detail // @Title 审批详情 // @Description 审批详情 // @Param BiApproveId query int true "审批ID" // @Success 200 {object} report_approve.BiApproveDetail // @router /detail [get] func (this *BiApproveController) Detail() { 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 } approveId, _ := this.GetInt("BiApproveId") if approveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", approveId) return } resp, msg, err := biapprove.GetApproveDetail(approveId) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批详情失败" } br.ErrMsg = "获取审批详情失败, Err: " + err.Error() return } br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // Refuse // @Title 驳回审批 // @Description 驳回审批 // @Param request body request.BiApproveRefuseReq true "type json string" // @Success 200 string "操作成功" // @router /refuse [post] func (this *BiApproveController) Refuse() { 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 request.BiApproveRefuseReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.BiApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId) return } maxStrLen := 500 approvelen := len([]rune(req.ApproveRemark)) if approvelen > maxStrLen { br.Msg = fmt.Sprintf("审批驳回原因不能超过%d字", maxStrLen) return } msg, err := biapprove.BiApproveRefuse(req.BiApproveId, sysUser.AdminId, req.ApproveRemark) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "操作失败" } br.ErrMsg = "驳回审批失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" } // Cancel // @Title 撤销审批 // @Description 撤销审批 // @Param request body report_approve.BiApproveCancelReq true "type json string" // @Success 200 string "操作成功" // @router /cancel [post] func (this *BiApproveController) Cancel() { 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 request.BiApproveCancelReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.BiApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, BiApproveId: %d", req.BiApproveId) return } // 撤销审批 msg, e := biapprove.BiApproveCancel(req.BiApproveId, sysUser.AdminId, sysUser.RealName) if e != nil { if msg != "" { br.Msg = msg } else { br.Msg = "操作失败" } br.ErrMsg = "撤销审批失败, Err: " + e.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" } // MessageList // @Title 审批消息列表 // @Description 审批消息列表 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码" // @Success 200 {object} report_approve.BiApproveMessageListResp // @router /message/list [get] func (this *BiApproveController) MessageList() { 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 } currentIndex, _ := this.GetInt("currentIndex") pageSize, _ := this.GetInt("pageSize") // 分页 var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) resp := new(response.BiApproveMessageListResp) resp.List = make([]*response.BiApproveMessageItem, 0) list, total, unRead, msg, err := biapprove.GetBiApproveMessage(sysUser.AdminId, startSize, pageSize) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批消息失败" } br.ErrMsg = "获取审批消息失败, Err: " + err.Error() return } resp.List = list resp.UnreadTotal = unRead page := paging.GetPaging(currentIndex, pageSize, total) resp.Paging = page br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // MessageRead // @Title 消息已读 // @Description 消息已读 // @Param request body report_approve.BiApproveMessageReadReq true "type json string" // @Success 200 string "操作成功" // @router /message/read [post] func (this *BiApproveController) MessageRead() { 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 request.BiApproveMessageReadReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.MessageId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId) return } msg, err := biapprove.ReadBiMessage(req.MessageId, sysUser.AdminId) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "操作失败" } br.ErrMsg = "消息已读失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" } // CheckApproveOpen // @Title 校验分类是否开启审批 // @Description 校验分类是否开启审批 // @Param request body report_approve.BiApproveCheckApproveOpenReq true "type json string" // @Success 200 string "操作成功" // @router /classify/check_open [post] func (this *BiApproveController) CheckApproveOpen() { 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 request.BiApproveCheckApproveOpenReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } // 校验是否开启了审批流 opening, e := biapprove.CheckBiOpenApprove(req.ClassifyId) if e != nil { br.Msg = "操作失败" br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error() return } br.Data = opening br.Ret = 200 br.Success = true br.Msg = "操作成功" }