From 371702c8971b4157badfe637db8c0ba92ab6cc1f Mon Sep 17 00:00:00 2001 From: HenryYee Date: Mon, 3 Jul 2023 18:34:51 +0800 Subject: [PATCH] v3.1.5 --- src/handler/fetch/fetch.go | 29 ++++++++++++++++++++--------- src/handler/manage/db/impl.go | 1 + src/handler/manage/tpl/impl.go | 20 ++++++++++++++++++++ src/handler/order/query/query.go | 10 +++++++--- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/handler/fetch/fetch.go b/src/handler/fetch/fetch.go index ced93870..c63fdeb7 100644 --- a/src/handler/fetch/fetch.go +++ b/src/handler/fetch/fetch.go @@ -16,7 +16,7 @@ package fetch import ( "Yearning-go/src/engine" "Yearning-go/src/handler/common" - tpl2 "Yearning-go/src/handler/manage/tpl" + "Yearning-go/src/handler/manage/tpl" "Yearning-go/src/lib" "Yearning-go/src/model" "encoding/json" @@ -103,19 +103,30 @@ func FetchSource(c yee.Context) (err error) { return c.JSON(http.StatusOK, common.SuccessPayload(source)) } +type StepInfo struct { + tpl.Tpl + model.CoreWorkflowDetail +} + func FetchAuditSteps(c yee.Context) (err error) { u := c.QueryParam("source_id") unescape, _ := url.QueryUnescape(u) - var s model.CoreDataSource - var tpl model.CoreWorkflowTpl - var whoIsAuditor []tpl2.Tpl - model.DB().Model(model.CoreDataSource{}).Where("source_id = ?", unescape).First(&s) - if err := model.DB().Model(model.CoreWorkflowTpl{}).Where("id =?", s.FlowID).First(&tpl).Error; errors.Is(err, gorm.ErrRecordNotFound) { - return c.JSON(http.StatusOK, common.ERR_COMMON_MESSAGE(errors.New("数据源没有添加流程!无法提交工单"))) + whoIsAuditor, err := tpl.OrderRelation(unescape) + if err != nil { + return c.JSON(http.StatusOK, common.ERR_COMMON_MESSAGE(err)) + } + workId := c.QueryParam("work_id") + var s []model.CoreWorkflowDetail + model.DB().Where("work_id = ?", workId).Find(&s) + var steps []StepInfo + for _, v := range whoIsAuditor { + steps = append(steps, StepInfo{Tpl: v}) + } + for i, v := range s { + steps[i].CoreWorkflowDetail = v } - _ = json.Unmarshal(tpl.Steps, &whoIsAuditor) - return c.JSON(http.StatusOK, common.SuccessPayload(whoIsAuditor)) + return c.JSON(http.StatusOK, common.SuccessPayload(steps)) } diff --git a/src/handler/manage/db/impl.go b/src/handler/manage/db/impl.go index 93ff282a..657ce9c6 100644 --- a/src/handler/manage/db/impl.go +++ b/src/handler/manage/db/impl.go @@ -71,6 +71,7 @@ func SuperEditSource(source *model.CoreDataSource) common.Resp { "cert": source.Cert, "key_file": source.KeyFile, }) + model.DB().Model(model.CoreQueryOrder{}).Where("status =? and source_id =?", 1, source.SourceId).Updates(&model.CoreQueryOrder{Assigned: source.Principal}) var k []model.CoreRoleGroup model.DB().Find(&k) for i := range k { diff --git a/src/handler/manage/tpl/impl.go b/src/handler/manage/tpl/impl.go index f05cf0eb..cb41cd77 100644 --- a/src/handler/manage/tpl/impl.go +++ b/src/handler/manage/tpl/impl.go @@ -1,5 +1,12 @@ package tpl +import ( + "Yearning-go/src/model" + "encoding/json" + "errors" + "gorm.io/gorm" +) + type Tpl struct { Desc string `json:"desc"` Auditor []string `json:"auditor"` @@ -17,3 +24,16 @@ type ReqTpl struct { Source string `json:"source"` Page int ` json:"page"` } + +func OrderRelation(source_id string) ([]Tpl, error) { + var s model.CoreDataSource + var tpl model.CoreWorkflowTpl + var whoIsAuditor []Tpl + model.DB().Model(model.CoreDataSource{}).Where("source_id = ?", source_id).First(&s) + if err := model.DB().Model(model.CoreWorkflowTpl{}).Where("id =?", s.FlowID).First(&tpl).Error; errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errors.New("数据源没有添加流程!无法提交工单") + } + _ = json.Unmarshal(tpl.Steps, &whoIsAuditor) + + return whoIsAuditor, nil +} diff --git a/src/handler/order/query/query.go b/src/handler/order/query/query.go index d35f2b01..0baa07e8 100644 --- a/src/handler/order/query/query.go +++ b/src/handler/order/query/query.go @@ -96,20 +96,24 @@ func QueryHandlerSets(c yee.Context) (err error) { c.Logger().Error(err.Error()) return c.JSON(http.StatusOK, common.ERR_REQ_BIND) } - found := model.DB().Where("work_id=? AND status=?", u.WorkId, 1).Error + token := new(lib.Token).JwtParse(c) + empty := new(model.CoreQueryOrder) + found := model.DB().Where("work_id=? AND status=? AND assigned = ?", u.WorkId, 1, token.Username).Find(empty).Error switch c.Params("tp") { case "agreed": if !errors.Is(found, gorm.ErrRecordNotFound) { model.DB().Model(model.CoreQueryOrder{}).Where("work_id =?", u.WorkId).Updates(&model.CoreQueryOrder{Status: 2, ApprovalTime: time.Now().Format("2006-01-02 15:04")}) lib.MessagePush(u.WorkId, 8, "") + return c.JSON(http.StatusOK, common.SuccessPayLoadToMessage(common.ORDER_IS_AGREE)) } - return c.JSON(http.StatusOK, common.SuccessPayLoadToMessage(common.ORDER_IS_AGREE)) + return c.JSON(http.StatusOK, common.ERR_REQ_FAKE) case "reject": if !errors.Is(found, gorm.ErrRecordNotFound) { model.DB().Model(model.CoreQueryOrder{}).Where("work_id =?", u.WorkId).Updates(&model.CoreQueryOrder{Status: 4}) lib.MessagePush(u.WorkId, 9, "") + return c.JSON(http.StatusOK, common.SuccessPayLoadToMessage(common.ORDER_IS_REJECT)) } - return c.JSON(http.StatusOK, common.SuccessPayLoadToMessage(common.ORDER_IS_REJECT)) + return c.JSON(http.StatusOK, common.ERR_REQ_FAKE) case "undo": t := new(lib.Token) t.JwtParse(c)