123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- 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 = "获取审批流详情成功"
- }
|