59 lines
2.6 KiB
Go
59 lines
2.6 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/allocaterequest"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/batchmetadata"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model/entity"
|
|
)
|
|
|
|
func (s *sAppCard) submitAppAllocateRequest(ctx context.Context, user *entity.SysUser, param *model.AppCardAllocateBatchSubmitParam) (*model.AppCardAllocateBatchModel, error) {
|
|
_, err := allocaterequest.Key(user.TenantId, user.UserId, param.RequestId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
values := appNormalizeAllocateCardValues(param.CardValues)
|
|
if len(values) == 0 || len(values) > 100 || param.TargetDeptId <= 0 {
|
|
return nil, gerror.New("请选择1至100张卡及目标客户")
|
|
}
|
|
mode := appAllocateExecutionMode(param.ExecutionMode)
|
|
if mode == batchmetadata.Single && len(values) != 1 {
|
|
return nil, gerror.New("单卡划拨只能选择一张卡")
|
|
}
|
|
hash := allocaterequest.Fingerprint(values, user.DeptId, param.TargetDeptId, mode, param.Remark)
|
|
existing, err := allocaterequest.Find(ctx, user.TenantId, user.UserId, param.RequestId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if existing != nil {
|
|
return s.resumeAppAllocateRequest(ctx, user, existing, hash)
|
|
}
|
|
return nil, gerror.New("请先创建划拨批次,再按批次号提交;旧请求未受理,不能直接重试创建")
|
|
}
|
|
|
|
func appValidateAllocateRequest(batch *entity.BatchMain, user *entity.SysUser, hash string) error {
|
|
if batch.BatchType != consts.BatchTypeAllocate || batch.SourceBatchNo != "" || batch.BatchInfo == nil || batch.BatchInfo.Get("jobRole").String() != "allocate_parent" {
|
|
return gerror.New("请求标识对应的批次不可重试")
|
|
}
|
|
if batch.CreatedDept != user.DeptId || batch.BatchInfo.Get("requestHash").String() != hash {
|
|
return gerror.New("同一请求标识不能更改卡片、目标客户、规模或备注")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *sAppCard) resumeAppAllocateRequest(ctx context.Context, user *entity.SysUser, batch *entity.BatchMain, hash string) (*model.AppCardAllocateBatchModel, error) {
|
|
if err := appValidateAllocateRequest(batch, user, hash); err != nil {
|
|
return nil, err
|
|
}
|
|
response := appAllocateQueuedResponse(batch)
|
|
if response.Status == "pending" || response.Status == "processing" {
|
|
if !appWorkerBatchAsyncEnabled(ctx) || s.publishAppAllocateBatch(ctx, user, batch.BatchNo) != nil {
|
|
response.FailReason = "任务已受理,投递尚未确认,请保留批次号并稍后刷新"
|
|
}
|
|
}
|
|
return response, nil
|
|
}
|