f
This commit is contained in:
@@ -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,51 @@ 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_name", contractName),
|
||||
zap.String("contract_code", contractCode),
|
||||
zap.String("contract_type", string(contractType)))
|
||||
|
||||
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.NewContractInfoWithContractCode(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("enterprise_info_id", enterpriseInfoID),
|
||||
zap.String("contract_code", contractCode),
|
||||
zap.String("contract_name", contractName))
|
||||
|
||||
return contract, nil
|
||||
}
|
||||
|
||||
// LoadContract 加载合同信息
|
||||
func (s *ContractAggregateServiceImpl) LoadContract(ctx context.Context, contractID string) (*entities.ContractInfo, error) {
|
||||
s.logger.Debug("加载合同信息", zap.String("contract_id", contractID))
|
||||
|
||||
Reference in New Issue
Block a user