2022-07-28 09:18:01 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-08-18 05:26:14 +00:00
|
|
|
"fmt"
|
2022-07-28 09:18:01 +00:00
|
|
|
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
2022-08-12 05:24:33 +00:00
|
|
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/common/page"
|
2022-08-16 10:45:28 +00:00
|
|
|
msg "github.com/fonchain_enterprise/fonchain-approval/pkg/m"
|
2022-07-28 09:18:01 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/plugin/soft_delete"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Approval 审批
|
|
|
|
type Approval struct {
|
2022-08-16 10:45:28 +00:00
|
|
|
ID uint64 `gorm:"primaryKey;column:id" json:"id"`
|
|
|
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"`
|
|
|
|
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
|
|
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
|
|
|
|
SubmitterID uint64 `gorm:"column:submitter_id" json:"submitterId"`
|
|
|
|
Status int8 `gorm:"column:status" json:"status"`
|
|
|
|
SubmitterName string `gorm:"column:submitter_name" json:"submitterName"`
|
|
|
|
CopyUsers CopyUsers `gorm:"column:copy_users" json:"copyUsers"`
|
|
|
|
ApprovalUsers ApprovalUsers `gorm:"column:approval_users" json:"approvalUsers"`
|
|
|
|
Type string `gorm:"column:type" json:"type"`
|
|
|
|
Level uint8 `gorm:"column:level" json:"level"`
|
|
|
|
NowLevel uint8 `gorm:"column:now_level" json:"nowLevel"`
|
|
|
|
NowUserId uint64 `gorm:"column:now_user_id" json:"nowUserId"`
|
|
|
|
NowUserName string `gorm:"column:now_user_name" json:"nowUserName"`
|
|
|
|
Content string `gorm:"column:content" json:"content"`
|
|
|
|
Reply string `gorm:"column:reply" json:"reply"`
|
|
|
|
Domain *string `gorm:"column:domain" json:"domain"`
|
|
|
|
Show *Show `gorm:"foreignKey:ApprovalID" json:"Show"`
|
|
|
|
Work *Work `gorm:"foreignKey:ApprovalID" json:"Work"`
|
|
|
|
Bundle *Bundle `gorm:"foreignKey:ApprovalID" json:"Bundle"`
|
|
|
|
Exhibition *Exhibition `gorm:"foreignKey:ApprovalID" json:"Exhibition"`
|
|
|
|
ApprovalWorkFlows []*ApprovalWorkFlow `gorm:"foreignKey:ApprovalID" json:"ApprovalWorkFlows"`
|
2022-07-28 09:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
TypeContent = "content"
|
|
|
|
TypeWork = "work"
|
|
|
|
TypeExhibition = "exhibition"
|
|
|
|
TypeShow = "show"
|
|
|
|
TypeBundle = "bundle"
|
|
|
|
)
|
2022-07-29 07:40:30 +00:00
|
|
|
const (
|
2022-08-18 05:26:14 +00:00
|
|
|
StatusDoing = 1
|
|
|
|
StatusOk = 2
|
|
|
|
StatusFail = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
StatusNeedViewed = 4
|
|
|
|
StatusViewed = 5
|
2022-07-29 07:40:30 +00:00
|
|
|
)
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
type ApprovalContentInterface interface {
|
2022-07-29 09:08:00 +00:00
|
|
|
SaveApprovalContent(in *approval.CreateRequest, a *Approval) error
|
|
|
|
UpdateApprovalContent(in *approval.CreateRequest, a *Approval) error
|
|
|
|
BuildResContent(a *Approval, request *approval.CreateRequest)
|
2022-07-28 09:18:01 +00:00
|
|
|
DeleteApproval(p *Approval) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// TableName get sql table name.获取数据库表名
|
|
|
|
func (m *Approval) TableName() string {
|
|
|
|
return "approval"
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
func preValidateExhibition(in *approval.CreateRequest) error {
|
|
|
|
var entity *Bundle
|
|
|
|
|
|
|
|
if in.Type != TypeExhibition {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if in.Exhibition == nil || in.Exhibition.PidApprovalID == 0 {
|
|
|
|
return errors.New(msg.ErrorApprovalType)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := DB.Where(Bundle{ApprovalID: in.Exhibition.PidApprovalID}).First(&entity).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(in.Exhibition.ApprovalExhibitions) != int(entity.ApplicationsNum) {
|
|
|
|
return errors.New(msg.ErrorWrongNum)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func StoreApproval(in *approval.CreateRequest) (*Approval, error) {
|
2022-07-28 09:18:01 +00:00
|
|
|
var entity *Approval
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
if err1 := preValidateExhibition(in); err1 != nil {
|
|
|
|
return entity, err1
|
|
|
|
}
|
|
|
|
|
2022-07-28 09:18:01 +00:00
|
|
|
err := DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
setting, terr := GetApprovalSettingFromKeyWord(in.Domain, in.Type)
|
|
|
|
if terr != nil {
|
|
|
|
return terr
|
|
|
|
}
|
|
|
|
|
2022-07-28 09:18:01 +00:00
|
|
|
// 保存基本信息
|
|
|
|
entity = &Approval{
|
2022-07-29 07:40:30 +00:00
|
|
|
Domain: &in.Domain,
|
|
|
|
SubmitterID: in.SubmitterID,
|
2022-07-28 09:18:01 +00:00
|
|
|
SubmitterName: in.SubmitterName,
|
2022-08-16 10:45:28 +00:00
|
|
|
CopyUsers: setting.CopyUsers,
|
|
|
|
ApprovalUsers: setting.ApprovalUsers,
|
2022-07-28 09:18:01 +00:00
|
|
|
Type: in.Type,
|
|
|
|
Content: in.Content,
|
2022-08-18 05:26:14 +00:00
|
|
|
Status: StatusDoing,
|
2022-08-16 10:45:28 +00:00
|
|
|
Level: uint8(len(setting.ApprovalUsers)),
|
|
|
|
NowLevel: 1,
|
|
|
|
NowUserId: setting.ApprovalUsers[0].ID,
|
|
|
|
NowUserName: setting.ApprovalUsers[0].Name,
|
2022-07-28 09:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := DB.Create(&entity).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 不同类型保存不同的结构体
|
|
|
|
err := entity.SaveContent(in)
|
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return BatchSave(setting.ApprovalUsers, entity.ID)
|
2022-07-28 09:18:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return entity, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
func Viewed(in *approval.ViewedRequest) error {
|
|
|
|
|
|
|
|
var entity *Approval
|
|
|
|
var err error
|
2022-08-18 05:26:14 +00:00
|
|
|
var isView = false
|
2022-07-29 07:40:30 +00:00
|
|
|
|
|
|
|
if err = DB.First(&entity, in.ID).Error; err != nil {
|
2022-08-16 10:45:28 +00:00
|
|
|
return errors.New(msg.ErrorNotFound)
|
2022-07-29 07:40:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
if entity.Status != StatusOk {
|
|
|
|
return errors.New(msg.ErrorDoingNotView)
|
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
copyUsers := entity.CopyUsers
|
|
|
|
|
|
|
|
for i, temp := range copyUsers {
|
|
|
|
if temp.ID == in.UserID {
|
2022-08-18 05:26:14 +00:00
|
|
|
if temp.IsViewed == true {
|
|
|
|
return errors.New(msg.ErrorAlreadySettingView)
|
|
|
|
}
|
|
|
|
|
|
|
|
isView = true
|
|
|
|
temp.IsViewed = isView
|
2022-07-29 07:40:30 +00:00
|
|
|
copyUsers[i] = temp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
if isView == false {
|
|
|
|
return errors.New(msg.ErrorSettingView)
|
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
return DB.Model(&Approval{}).Where(&Approval{ID: in.ID}).Updates(&Approval{CopyUsers: copyUsers}).Error
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func UpdateApproval(in *approval.CreateRequest) (*Approval, error) {
|
2022-07-29 07:40:30 +00:00
|
|
|
var entity *Approval
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
if err1 := preValidateExhibition(in); err1 != nil {
|
|
|
|
return entity, err1
|
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
err := DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
|
|
|
if departErr := DB.First(&entity, in.ID).Error; departErr != nil {
|
2022-08-16 10:45:28 +00:00
|
|
|
return errors.New(msg.ErrorNotFound)
|
2022-07-29 07:40:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 03:41:22 +00:00
|
|
|
if entity.Type != in.Type {
|
2022-08-16 10:45:28 +00:00
|
|
|
return errors.New(msg.ErrorChangeType)
|
2022-07-30 03:41:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
// 保存基本信息
|
2022-08-25 07:53:38 +00:00
|
|
|
upEntity := &Approval{
|
2022-07-29 07:40:30 +00:00
|
|
|
Content: in.Content,
|
|
|
|
}
|
|
|
|
|
2022-08-25 07:53:38 +00:00
|
|
|
if err := DB.Where(&Approval{ID: in.ID}).Updates(&upEntity).Error; err != nil {
|
2022-07-29 07:40:30 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 不同类型保存不同的结构体
|
|
|
|
err := entity.UpdateContent(in)
|
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return entity, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func approvalCalc(filter *Approval) *approval.Information {
|
|
|
|
|
|
|
|
var num int64
|
|
|
|
|
2022-07-30 05:11:18 +00:00
|
|
|
info := &approval.Information{
|
|
|
|
Total: 0,
|
|
|
|
DoingTotal: 0,
|
|
|
|
SuccessTotal: 0,
|
|
|
|
FailTotal: 0,
|
|
|
|
}
|
2022-07-29 07:40:30 +00:00
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(&filter).Count(&num)
|
|
|
|
info.Total = uint64(num)
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusDoing}).Count(&num)
|
2022-07-29 07:40:30 +00:00
|
|
|
info.DoingTotal = uint64(num)
|
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusOk}).Count(&num)
|
|
|
|
info.SuccessTotal = uint64(num)
|
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(&filter).Where(&Approval{Status: StatusFail}).Count(&num)
|
|
|
|
info.FailTotal = uint64(num)
|
|
|
|
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
func approvalCalcJson(domain string, userId uint64) *approval.Information {
|
|
|
|
|
|
|
|
var num int64
|
2022-08-18 05:26:14 +00:00
|
|
|
var jsonStr = "JSON_CONTAINS(approval_users,JSON_OBJECT('ID', ?))"
|
2022-08-16 10:45:28 +00:00
|
|
|
|
|
|
|
info := &approval.Information{
|
|
|
|
Total: 0,
|
|
|
|
DoingTotal: 0,
|
|
|
|
SuccessTotal: 0,
|
|
|
|
FailTotal: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(jsonStr, userId).Count(&num)
|
|
|
|
info.Total = uint64(num)
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusDoing, Domain: &domain}).Count(&num)
|
2022-08-16 10:45:28 +00:00
|
|
|
info.DoingTotal = uint64(num)
|
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusOk, Domain: &domain}).Count(&num)
|
|
|
|
info.SuccessTotal = uint64(num)
|
|
|
|
|
|
|
|
DB.Model(&Approval{}).Where(jsonStr, userId).Where(&Approval{Status: StatusFail, Domain: &domain}).Count(&num)
|
|
|
|
info.FailTotal = uint64(num)
|
|
|
|
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2022-07-29 07:40:30 +00:00
|
|
|
// ApprovalInfo 统计
|
|
|
|
func ApprovalInfo(in *approval.InformationRequest) (*approval.InformationResponse, error) {
|
|
|
|
|
|
|
|
response := &approval.InformationResponse{
|
|
|
|
MySubmitInfo: approvalCalc(&Approval{Domain: &in.Domain, SubmitterID: in.UserID}),
|
2022-08-16 10:45:28 +00:00
|
|
|
SubmitMeInfo: approvalCalcJson(in.Domain, in.UserID),
|
2022-07-29 07:40:30 +00:00
|
|
|
DomainInfo: approvalCalc(&Approval{Domain: &in.Domain}),
|
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) SaveApprovalContent(in *approval.CreateRequest, a *Approval) error {
|
2022-07-28 09:18:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) UpdateApprovalContent(in *approval.CreateRequest, a *Approval) error {
|
2022-07-29 07:40:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-28 09:18:01 +00:00
|
|
|
func (m *Approval) DeleteApproval(p *Approval) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Approval) DeleteContent() error {
|
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
factory, err := getApprovalContentFactory(m.Type)
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return factory.DeleteApproval(m)
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) BuildResContent(a *Approval, request *approval.CreateRequest) {
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) SetResContent(request *approval.CreateRequest) error {
|
2022-07-28 09:18:01 +00:00
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
factory, err := getApprovalContentFactory(m.Type)
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
factory.BuildResContent(m, request)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) SaveContent(in *approval.CreateRequest) error {
|
2022-07-28 09:18:01 +00:00
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
factory, err := getApprovalContentFactory(in.Type)
|
2022-07-28 09:18:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = factory.SaveApprovalContent(in, m)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:08:00 +00:00
|
|
|
func (m *Approval) UpdateContent(in *approval.CreateRequest) error {
|
2022-07-29 07:40:30 +00:00
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
factory, err := getApprovalContentFactory(in.Type)
|
2022-07-29 07:40:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = factory.UpdateApprovalContent(in, m)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
func MyWorkApprovals(in *approval.ListRequest) ([]*Approval, int64) {
|
2022-07-28 09:18:01 +00:00
|
|
|
var list []*Approval
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
//list
|
2022-07-30 03:41:22 +00:00
|
|
|
modelObj := DB.Model(&Approval{}).
|
|
|
|
Preload("Show").
|
|
|
|
Preload("Work.ApprovalWorks").
|
|
|
|
Preload("Bundle").
|
2022-08-16 10:45:28 +00:00
|
|
|
Preload("ApprovalWorkFlows").
|
2022-07-30 03:41:22 +00:00
|
|
|
Preload("Exhibition.ApprovalExhibitions")
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
if in.Type != "" {
|
|
|
|
modelObj = modelObj.Where(&Approval{Type: in.Type})
|
|
|
|
}
|
|
|
|
|
2022-08-04 03:07:55 +00:00
|
|
|
if in.UserID != 0 {
|
2022-08-18 05:26:14 +00:00
|
|
|
modelObj = modelObj.Where(DB.Where("JSON_CONTAINS(approval_users,JSON_OBJECT('ID', ?))", in.UserID).
|
|
|
|
Or(DB.Where("JSON_CONTAINS(copy_users,JSON_OBJECT('ID', ?))", in.UserID)).Where("status != ?", StatusDoing))
|
2022-07-30 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 09:18:01 +00:00
|
|
|
if in.Status != 0 {
|
|
|
|
modelObj = modelObj.Where(&Approval{Status: int8(in.Status)})
|
|
|
|
}
|
|
|
|
|
|
|
|
modelObj.Count(&count)
|
|
|
|
|
2022-08-12 05:24:33 +00:00
|
|
|
modelObj.Limit(int(in.PageSize)).Offset(page.GetOffset(in.Page, in.PageSize)).Order("id desc").Find(&list)
|
2022-07-28 09:18:01 +00:00
|
|
|
|
|
|
|
return list, count
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
func MySubmitApprovals(in *approval.ListRequest) ([]*Approval, int64) {
|
|
|
|
var list []*Approval
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
//list
|
|
|
|
modelObj := DB.Model(&Approval{}).
|
|
|
|
Preload("Show").
|
|
|
|
Preload("Work.ApprovalWorks").
|
|
|
|
Preload("Bundle").
|
|
|
|
Preload("ApprovalWorkFlows").
|
|
|
|
Preload("Exhibition.ApprovalExhibitions")
|
|
|
|
|
|
|
|
if in.Status != 0 {
|
|
|
|
modelObj = modelObj.Where(&Approval{Status: int8(in.Status)})
|
|
|
|
}
|
|
|
|
|
|
|
|
if in.Type != "" {
|
|
|
|
modelObj = modelObj.Where(&Approval{Type: in.Type})
|
|
|
|
}
|
|
|
|
|
|
|
|
modelObj = modelObj.Where(&Approval{SubmitterID: in.UserID})
|
|
|
|
|
|
|
|
modelObj.Count(&count)
|
|
|
|
|
|
|
|
modelObj.Limit(int(in.PageSize)).Offset(page.GetOffset(in.Page, in.PageSize)).Order("id desc").Find(&list)
|
|
|
|
|
|
|
|
return list, count
|
|
|
|
}
|
|
|
|
|
2022-08-16 10:45:28 +00:00
|
|
|
func (m *Approval) Pass(reply string, workFlowId uint64) error {
|
|
|
|
return m.operateStatus(StatusOk, reply, workFlowId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Approval) Refuse(reply string, workFlowId uint64) error {
|
|
|
|
return m.operateStatus(StatusFail, reply, workFlowId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Approval) operateStatus(status uint8, reply string, workFlowId uint64) error {
|
|
|
|
|
|
|
|
var workFlow ApprovalWorkFlow
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
m.Reply = reply
|
2022-08-16 10:45:28 +00:00
|
|
|
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: m.ID, Status: StatusDoing}).First(&workFlow, workFlowId).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.NowLevel != workFlow.Level {
|
|
|
|
return errors.New(msg.ErrorOperate)
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
// 拒绝通过
|
|
|
|
if status == StatusFail {
|
2022-08-16 10:45:28 +00:00
|
|
|
m.Status = StatusFail
|
|
|
|
|
|
|
|
if err := DB.Save(m).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return workFlow.Refuse(reply)
|
|
|
|
}
|
|
|
|
|
2022-08-18 05:26:14 +00:00
|
|
|
/*--------层级审批通过---------*/
|
|
|
|
// 整个审批通过
|
|
|
|
if m.Level == m.NowLevel {
|
2022-08-16 10:45:28 +00:00
|
|
|
m.Status = StatusOk
|
2022-08-18 05:26:14 +00:00
|
|
|
|
|
|
|
//审批层级通过
|
|
|
|
} else {
|
2022-08-16 10:45:28 +00:00
|
|
|
m.NowLevel = workFlow.Level + 1
|
|
|
|
nextFlow, err := GetWorkFlowByLevel(m.ID, m.NowLevel)
|
2022-08-18 05:26:14 +00:00
|
|
|
fmt.Println(nextFlow)
|
2022-08-16 10:45:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.NowUserId = nextFlow.UserId
|
|
|
|
m.NowUserName = nextFlow.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := DB.Save(m).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return workFlow.Pass(reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getApprovalContentFactory(typeFiled string) (ApprovalContentInterface, error) {
|
2022-07-28 09:18:01 +00:00
|
|
|
switch typeFiled {
|
|
|
|
case TypeContent:
|
|
|
|
return &Approval{}, nil
|
|
|
|
case TypeShow:
|
|
|
|
return &Show{}, nil
|
|
|
|
case TypeWork:
|
|
|
|
return &Work{}, nil
|
|
|
|
case TypeBundle:
|
|
|
|
return &Bundle{}, nil
|
|
|
|
case TypeExhibition:
|
|
|
|
return &Exhibition{}, nil
|
|
|
|
default:
|
2022-08-16 10:45:28 +00:00
|
|
|
return &Approval{}, nil
|
2022-07-28 09:18:01 +00:00
|
|
|
}
|
|
|
|
}
|