package knowledge_approve import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/knowledge" "eta_gn/eta_api/models/knowledge_approve/request" "eta_gn/eta_api/models/knowledge_approve/response" "eta_gn/eta_api/services/knowledge_approve" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" ) type KnowledgeApproveController 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.KnowledgeResourceApproveListResp // @router /list [get] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveItemOrmResp var total int var msg string var err error classifyList, msg, err := knowledge_approve.GetKnowledgeClassifyAll() 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.ClassifyId] = v.ClassifyName } switch listType { case 1: list, total, msg, err = knowledge_approve.ProcessingKnowledgeResourceApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword) case 2: list, total, msg, err = knowledge_approve.SolvedKnowledgeResourceApprove(sysUser.AdminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize, sysUser.RealName, startTime, endTime, keyword) case 3: list, total, msg, err = knowledge_approve.MyApplyKnowledgeResourceApproves(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.KnowledgeResourceApproveListResp) 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} []*knowledge.KnowledgeClassifyItem // @router /classify/list [get] func (this *KnowledgeApproveController) ClassifyList() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() res, msg, err := knowledge_approve.GetPulicKnowledgeClassifyList(knowledge.KnowledgeResourceTypeOpinion) 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 request.KnowledgeResourceApprovePassReq true "type json string" // @Success 200 string "操作成功" // @router /approve [post] func (this *KnowledgeApproveController) 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.KnowledgeResourceApprovePassReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.KnowledgeResourceApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId) return } // 通过审批 msg, err := knowledge_approve.PassKnowledgeResourceApprove(req.KnowledgeResourceApproveId, 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 KnowledgeResourceApproveId query int true "审批ID" // @Success 200 {object} report_approve.KnowledgeResourceApproveDetail // @router /detail [get] func (this *KnowledgeApproveController) 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("KnowledgeResourceApproveId") if approveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", approveId) return } resp, msg, err := knowledge_approve.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.KnowledgeResourceApproveRefuseReq true "type json string" // @Success 200 string "操作成功" // @router /refuse [post] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveRefuseReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.KnowledgeResourceApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId) return } maxStrLen := 500 approvelen := len([]rune(req.ApproveRemark)) if approvelen > maxStrLen { br.Msg = fmt.Sprintf("审批驳回原因不能超过%d字", maxStrLen) return } msg, err := knowledge_approve.KnowledgeResourceApproveRefuse(req.KnowledgeResourceApproveId, 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.KnowledgeResourceApproveCancelReq true "type json string" // @Success 200 string "操作成功" // @router /cancel [post] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveCancelReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } if req.KnowledgeResourceApproveId <= 0 { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("参数有误, KnowledgeResourceApproveId: %d", req.KnowledgeResourceApproveId) return } // 撤销审批 msg, e := knowledge_approve.KnowledgeResourceApproveCancel(req.KnowledgeResourceApproveId, 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.KnowledgeResourceApproveMessageListResp // @router /message/list [get] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveMessageListResp) list, total, unRead, msg, err := knowledge_approve.GetKnowledgeResourceApproveMessage(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.KnowledgeResourceApproveMessageReadReq true "type json string" // @Success 200 string "操作成功" // @router /message/read [post] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveMessageReadReq 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 := knowledge_approve.ReadKnowledgeMessage(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.KnowledgeResourceApproveCheckApproveOpenReq true "type json string" // @Success 200 string "操作成功" // @router /classify/check_open [post] func (this *KnowledgeApproveController) 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.KnowledgeResourceApproveCheckApproveOpenReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数有误" br.ErrMsg = "参数解析失败, Err: " + e.Error() return } // 校验是否开启了审批流 opening, e := knowledge_approve.CheckKnowledgeOpenApprove(req.ClassifyId) if e != nil { br.Msg = "操作失败" br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error() return } br.Data = opening br.Ret = 200 br.Success = true br.Msg = "操作成功" }