package knowledge_approve import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "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" "strings" "github.com/rdlucklib/rdluck_tools/paging" ) type KnowledgeApproveFlowController struct { controllers.BaseAuthController } // List // @Title 审批流列表 // @Description 审批流列表 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码" // @Param ClassifyId query int false "分类ID" // @Param Keyword query string false "搜索关键词" // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)" // @Success 200 {object} report_approve.ReportApproveListResp // @router /flow/list [get] func (c *KnowledgeApproveFlowController) List() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") keyword := c.GetString("Keyword") classifyId, _ := c.GetInt("ClassifyId", 0) sortRule, _ := c.GetInt("SortRule", 2) if pageSize <= 0 { pageSize = utils.PageSize10 } if currentIndex <= 0 { currentIndex = 1 } var condition string var pars []interface{} if keyword != "" { condition = ` AND flow_name LIKE ?` pars = utils.GetLikeKeywordPars(pars, keyword, 1) } if classifyId > 0 { condition += ` AND classify_id = ?` pars = append(pars, classifyId) } startSize := paging.StartIndex(currentIndex, pageSize) orderMap := map[int]string{1: "ASC", 2: "DESC"} if sortRule == 0 { sortRule = 2 } condition += " ORDER BY create_time " + orderMap[sortRule] res, total, msg, err := knowledge_approve.GetKnowledgeResourceApproveFlowList(condition, pars, startSize, pageSize) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批流列表失败" } br.ErrMsg = "获取审批流列表失败, err:" + err.Error() return } page := paging.GetPaging(currentIndex, pageSize, total) resp := new(response.KnowledgeResourceApproveFlowListResp) resp.List = res resp.Paging = page br.Data = resp br.Msg = "获取审批流列表成功" br.Success = true br.Ret = 200 } // Add // @Title 新增审批流 // @Description 新增审批流 // @Param request body request.KnowledgeResourceApproveFlowSaveReq true "type json string" // @Success 200 // @router /flow/add [post] func (c *KnowledgeApproveFlowController) Add() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.KnowledgeResourceApproveFlowSaveReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = "参数解析失败, err:" + err.Error() return } req.FlowName = strings.TrimSpace(req.FlowName) if req.FlowName == "" { br.Msg = "审批流名称不能为空" return } if len([]rune(req.FlowName)) > 20 { br.Msg = "审批流名称最多输入20个字符" return } if req.ClassifyId <= 0 { br.Msg = "请选择审批分类" return } if len(req.Nodes) == 0 { br.Msg = "请添加审批流程" return } if req.KnowledgeResourceApproveFlowId > 0 { br.Msg = "审批流已存在" return } _, msg, err := knowledge_approve.SaveKnowledgeResourceApproveFlow(req) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "新增审批流失败" } br.ErrMsg = "新增审批流失败, err:" + err.Error() return } br.Msg = "新增审批流成功" br.Success = true br.Ret = 200 } // edit // @Title 新增审批流 // @Description 新增审批流 // @Param request body request.KnowledgeResourceApproveFlowSaveReq true "type json string" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/edit [post] func (c *KnowledgeApproveFlowController) Edit() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.KnowledgeResourceApproveFlowSaveReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = "参数解析失败, err:" + err.Error() return } req.FlowName = strings.TrimSpace(req.FlowName) if req.FlowName == "" { br.Msg = "审批流名称不能为空" return } if len([]rune(req.FlowName)) > 20 { br.Msg = "审批流名称最多输入20个字符" return } if req.ClassifyId <= 0 { br.Msg = "请选择审批分类" return } if len(req.Nodes) == 0 { br.Msg = "请添加审批流程" return } if req.KnowledgeResourceApproveFlowId == 0 { br.Msg = "审批流不存在, 请刷新重试" return } ok, msg, err := knowledge_approve.SaveKnowledgeResourceApproveFlow(req) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "编辑审批流失败" } br.ErrMsg = "编辑审批流失败, err:" + err.Error() return } if !ok { br.Msg = msg return } br.Msg = "编辑审批流成功" br.Success = true br.Ret = 200 } // delete // @Title 新增审批流 // @Description 新增审批流 // @Param request body request.KnowledgeResourceApproveFlowRemoveReq true "type json string" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/remove [post] func (c *KnowledgeApproveFlowController) Remove() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.KnowledgeResourceApproveFlowRemoveReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = "参数解析失败, err:" + err.Error() return } if req.KnowledgeResourceApproveFlowId <= 0 { br.Msg = "审批流不存在, 请刷新重试" return } ok, msg, err := knowledge_approve.DeleteKnowledgeResourceApproveFlow(req.KnowledgeResourceApproveFlowId) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "删除审批流失败" } br.ErrMsg = "删除审批流失败, err:" + err.Error() return } if !ok { br.Msg = msg return } br.Msg = "删除审批流成功" br.Success = true br.Ret = 200 } // Detail // @Title 审批流详情 // @Description 审批流详情 // @Param KnowledgeResourceApproveFlowId query int true "看板审批流ID" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/detail [get] func (c *KnowledgeApproveFlowController) Detail() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } flowId, _ := c.GetInt("KnowledgeResourceApproveFlowId") if flowId <= 0 { br.Msg = "审批流不存在" return } detail, msg, err := knowledge_approve.GetKnowledgeResourceApproveFlowDetail(flowId) if err != nil { if msg != "" { br.Msg = msg } else { br.Msg = "获取审批流详情失败" } br.ErrMsg = "获取审批流详情失败, err:" + err.Error() return } if detail == nil { br.Msg = "审批流不存在" return } br.Data = detail br.Ret = 200 br.Success = true br.Msg = "获取审批流详情成功" }