65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package oa
|
|
|
|
import (
|
|
"WiiCITMS/models/oa"
|
|
"WiiGenerates/WiiCITMS/generates/v1/go/types"
|
|
"WiiGoLibrary/apply/middle/process/v1"
|
|
"WiiGoLibrary/framework/db/v1/utils/mssql/unique"
|
|
"WiiGoLibrary/framework/hub/v1/dblib"
|
|
"errors"
|
|
)
|
|
|
|
// GetInstanceGuidByApprovalRecord 根据审批记录ID获取工作流实例ID
|
|
func GetInstanceGuidByApprovalRecord(recordGuid string) (string, error) {
|
|
// 验证审批记录ID格式
|
|
guid, err := unique.FromString(recordGuid)
|
|
if err != nil {
|
|
return "", errors.New("无效的审批记录ID格式")
|
|
}
|
|
|
|
// 查询审批记录
|
|
record := &oa.ApprovalRecordModel{}
|
|
r := dblib.DBIns.DB.Where("RecordGuid = ? AND (RecordStatus & 524288) = 0", guid).First(record)
|
|
if r.Error != nil {
|
|
return "", errors.New("审批记录不存在")
|
|
}
|
|
|
|
// 返回工作流实例ID
|
|
return record.InstanceGuid.String(), nil
|
|
}
|
|
|
|
// GetRecordApprover 根据审批记录ID获取审批人ID
|
|
func GetRecordApprover(recordGuid string) (string, error) {
|
|
// 验证审批记录ID格式
|
|
guid, err := unique.FromString(recordGuid)
|
|
if err != nil {
|
|
return "", errors.New("无效的审批记录ID格式")
|
|
}
|
|
|
|
// 查询审批记录
|
|
record := &oa.ApprovalRecordModel{}
|
|
r := dblib.DBIns.DB.Where("RecordGuid = ? AND (RecordStatus & 524288) = 0", guid).First(record)
|
|
if r.Error != nil {
|
|
return "", errors.New("审批记录不存在")
|
|
}
|
|
|
|
// 返回审批人ID
|
|
return record.ApproverGuid.String(), nil
|
|
}
|
|
|
|
// VerifyApproverForRecord 验证指定用户是否是审批记录的审批人
|
|
func VerifyApproverForRecord(recordGuid string, approverGuid string) *process.Process {
|
|
// 获取审批记录的审批人
|
|
recordApproverGuid, err := GetRecordApprover(recordGuid)
|
|
if err != nil {
|
|
return process.FailError(types.ApprovalRecordNotFoundError, err)
|
|
}
|
|
|
|
// 验证是否是指定的审批人
|
|
if recordApproverGuid != approverGuid {
|
|
return process.FailError(types.NoPermissionError, errors.New("非指定审批人,无权操作"))
|
|
}
|
|
|
|
return process.Success(200)
|
|
}
|