package approval import ( "context" "errors" "fmt" api "github.com/fonchain_enterprise/fonchain-main/api/approval" artShow "github.com/fonchain_enterprise/fonchain-main/api/artShow" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/fonchain_enterprise/fonchain-main/pkg/model/oa_model" "github.com/fonchain_enterprise/fonchain-main/pkg/service" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" ) // RevokeLeaveApply // 撤销审批 // 2024.03.27 添加 画展包审批撤销 func RevokeAllApproval(c *gin.Context) { /* 1、待审批 直接取消 2、未通过 撤销审批 审批人 根据 撤销的审批中的 审批人是否已审批 设置 3、通过 撤销审批 审批人 为 撤销的审批中的审批人 */ revokeReq := new(api.RevokeApprovalReq) if err := c.ShouldBindBodyWith(&revokeReq, binding.JSON); err != nil { service.Error(c, e.Error, err) return } beforeApproval := QueryApprovalSetStatusBefore(revokeReq.ID) // 校验 审批中的 画展包 状态 if beforeApproval.Type == TypeExhibition { artShowRevokeReq := new(artShow.RevokeReq) artShowRevokeReq.ShowUid = make([]string, 0) for i := 0; i < len(beforeApproval.Exhibition.ApprovalExhibitions); i++ { artShowRevokeReq.ShowUid = append(artShowRevokeReq.ShowUid, beforeApproval.Exhibition.ApprovalExhibitions[i].PackageID) } artShowRevokeReq.ApplyUid = beforeApproval.Exhibition.ApplyID checkArtShowRes, err := service.GrpcArtShowImpl.CheckArtShow(context.Background(), artShowRevokeReq) if err != nil { service.Error(c, e.Error, errors.New(e.FailedQueryArtShowInfo)) return } if !checkArtShowRes.CanRevoke { service.Error(c, e.Error, errors.New(e.ErrorNotAllowedRevokeArtShowApply)) return } } if beforeApproval.Type == oa_model.TypeNursingLeaveApply || beforeApproval.Type == oa_model.TypeParentalLeaveApply { err := CheckLeaveApplyIsUse(beforeApproval) if err != nil { service.Error(c, e.Error, err) return } } // 审批 撤销 _, err := service.ApprovalProvider.RevokeMyApproval(context.Background(), revokeReq) if err != nil { service.Error(c, e.Error, err) return } detailReq := new(api.DetailRequest) detailReq.ID = revokeReq.ID detailRes, err := service.ApprovalProvider.Detail(context.Background(), detailReq) if err != nil { service.Error(c, e.Error, err) return } //撤销后推送给下一个审批人 err = service.SendAppMessage("审批通知", "您有一条"+detailRes.TypeName+"审批待处理,点击查看详情 >", detailRes.NowUserId, detailRes.ID, "approval") if err != nil { fmt.Println("==============APP推送失败=====================") fmt.Println(err) } if detailRes.Status != e.ApprovalWorkStatusRevoking { service.Error(c, e.Error, errors.New("撤销失败")) return } // oa 撤销 if oa_model.TypeZhCN[detailRes.Type] != "" { _, err = RevokeOaApproval(detailRes) if err != nil { service.Error(c, e.Error, err) return } } // 画展包审批撤销 if detailRes.Type == TypeExhibition { err = RevokeArtShowApproval(detailRes) if err != nil { service.Error(c, e.Error, err) return } } // 画展包润格审批撤销 if detailRes.Type == TypeArtExhibitionReward { err = RevokeRewordApproval(detailRes) if err != nil { service.Error(c, e.Error, err) return } } service.Success(c) }