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" "strings" "github.com/rdlucklib/rdluck_tools/paging" ) type BiApproveFlowController 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 *BiApproveFlowController) 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 := biapprove.GetBiApproveFlowList(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.BiApproveFlowListResp) resp.List = res resp.Paging = page br.Data = resp br.Msg = "获取审批流列表成功" br.Success = true br.Ret = 200 } // Add // @Title 新增审批流 // @Description 新增审批流 // @Param request body request.BiApproveFlowSaveReq true "type json string" // @Success 200 // @router /flow/add [post] func (c *BiApproveFlowController) Add() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.BiApproveFlowSaveReq 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.BiApproveFlowId > 0 { br.Msg = "审批流已存在" return } _, msg, err := biapprove.SaveBiApproveFlow(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.BiApproveFlowSaveReq true "type json string" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/edit [post] func (c *BiApproveFlowController) Edit() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.BiApproveFlowSaveReq 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.BiApproveFlowId == 0 { br.Msg = "审批流不存在, 请刷新重试" return } ok, msg, err := biapprove.SaveBiApproveFlow(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.BiApproveFlowRemoveResp true "type json string" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/remove [post] func (c *BiApproveFlowController) Remove() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() var req *request.BiApproveFlowRemoveResp if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = "参数解析失败, err:" + err.Error() return } if req.BiApproveFlowId <= 0 { br.Msg = "审批流不存在, 请刷新重试" return } ok, msg, err := biapprove.DeleteBiApproveFlow(req.BiApproveFlowId) 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 request body request.BiApproveFlowRemoveResp true "type json string" // @Success 200 {object} report_approve.ReportApproveFlowDetailItem // @router /flow/detail [get] func (c *BiApproveFlowController) 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("BiApproveFlowId") if flowId <= 0 { br.Msg = "审批流不存在" return } detail, msg, err := biapprove.GetBiApproveFlowDetail(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 = "获取审批流详情成功" }