This commit is contained in:
2026-05-01 15:35:48 +08:00
parent 354856360b
commit 27f0e47162
4 changed files with 102 additions and 23 deletions

View File

@@ -14,6 +14,7 @@ import (
type ContractAggregateService interface {
// 聚合根生命周期管理
CreateContract(ctx context.Context, enterpriseInfoID, userID, contractName string, contractType entities.ContractType, contractFileID, contractFileURL string) (*entities.ContractInfo, error)
CreateContractWithCode(ctx context.Context, enterpriseInfoID, userID, contractName string, contractType entities.ContractType, contractFileID, contractFileURL, contractCode string) (*entities.ContractInfo, error)
LoadContract(ctx context.Context, contractID string) (*entities.ContractInfo, error)
SaveContract(ctx context.Context, contract *entities.ContractInfo) error
DeleteContract(ctx context.Context, contractID string) error
@@ -94,6 +95,48 @@ func (s *ContractAggregateServiceImpl) CreateContract(
return contract, nil
}
// CreateContractWithCode 使用指定编号创建合同信息
func (s *ContractAggregateServiceImpl) CreateContractWithCode(
ctx context.Context,
enterpriseInfoID, userID, contractName string,
contractType entities.ContractType,
contractFileID, contractFileURL, contractCode string,
) (*entities.ContractInfo, error) {
s.logger.Debug("使用指定编号创建合同信息",
zap.String("enterprise_info_id", enterpriseInfoID),
zap.String("user_id", userID),
zap.String("contract_code", contractCode))
exists, err := s.ExistsByContractFileID(ctx, contractFileID)
if err != nil {
return nil, fmt.Errorf("检查合同文件ID失败: %w", err)
}
if exists {
return nil, fmt.Errorf("合同文件ID已存在")
}
contract, err := entities.NewContractInfoWithCode(enterpriseInfoID, userID, contractName, contractType, contractFileID, contractFileURL, contractCode)
if err != nil {
return nil, fmt.Errorf("创建合同信息失败: %w", err)
}
if err := s.ValidateBusinessRules(ctx, contract); err != nil {
return nil, fmt.Errorf("业务规则验证失败: %w", err)
}
err = s.SaveContract(ctx, contract)
if err != nil {
return nil, fmt.Errorf("保存合同信息失败: %w", err)
}
s.logger.Info("合同信息创建成功(指定编号)",
zap.String("contract_id", contract.ID),
zap.String("contract_code", contractCode),
zap.String("enterprise_info_id", enterpriseInfoID))
return contract, nil
}
// LoadContract 加载合同信息
func (s *ContractAggregateServiceImpl) LoadContract(ctx context.Context, contractID string) (*entities.ContractInfo, error) {
s.logger.Debug("加载合同信息", zap.String("contract_id", contractID))