新增部分接口合同授权码

This commit is contained in:
2025-08-04 22:02:09 +08:00
parent f482f0a6e8
commit 3f4c3086f3
6 changed files with 57 additions and 21 deletions

View File

@@ -147,10 +147,10 @@ func registerAllProcessors(combService *comb.CombService) {
var RequestProcessors map[string]processors.ProcessorFunc
// PreprocessRequestApi 调用指定的请求处理函数
func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, apiCode string, params []byte, options *commands.ApiCallOptions) ([]byte, error) {
func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, apiCode string, params []byte, options *commands.ApiCallOptions, callContext *processors.CallContext) ([]byte, error) {
if processor, exists := RequestProcessors[apiCode]; exists {
// 设置Options到依赖容器
deps := a.processorDeps.WithOptions(options)
// 设置Options和CallContext到依赖容器
deps := a.processorDeps.WithOptions(options).WithCallContext(callContext)
return processor(ctx, params, deps)
}
return nil, fmt.Errorf("%s: 未找到处理器: %s", ErrSystem, apiCode)

View File

@@ -15,6 +15,11 @@ type CombServiceInterface interface {
ProcessCombRequest(ctx context.Context, params []byte, deps *ProcessorDependencies, packageCode string) (*CombinedResult, error)
}
// CallContext CallApi调用上下文包含调用相关的数据
type CallContext struct {
ContractCode string // 合同编号
}
// ProcessorDependencies 处理器依赖容器
type ProcessorDependencies struct {
WestDexService *westdex.WestDexService
@@ -24,6 +29,7 @@ type ProcessorDependencies struct {
Validator interfaces.RequestValidator
CombService CombServiceInterface // Changed to interface to break import cycle
Options *commands.ApiCallOptions // 添加Options支持
CallContext *CallContext // 添加CallApi调用上下文
}
// NewProcessorDependencies 创建处理器依赖容器
@@ -43,6 +49,7 @@ func NewProcessorDependencies(
Validator: validator,
CombService: combService,
Options: nil, // 初始化为nil在调用时设置
CallContext: nil, // 初始化为nil在调用时设置
}
}
@@ -52,6 +59,12 @@ func (deps *ProcessorDependencies) WithOptions(options *commands.ApiCallOptions)
return deps
}
// WithCallContext 设置CallContext的便捷方法
func (deps *ProcessorDependencies) WithCallContext(callContext *CallContext) *ProcessorDependencies {
deps.CallContext = callContext
return deps
}
// ProcessorFunc 处理器函数类型定义
type ProcessorFunc func(ctx context.Context, params []byte, deps *ProcessorDependencies) ([]byte, error)

View File

@@ -33,13 +33,16 @@ func ProcessFLXG0V4BRequest(ctx context.Context, params []byte, deps *processors
if err != nil {
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
}
encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode)
if err != nil {
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"data": map[string]interface{}{
"name": encryptedName,
"idcard": encryptedIDCard,
"auth_authorizeFileCode": encryptedAuthAuthorizeFileCode,
"inquired_auth": paramsDto.AuthDate,
// "auth_authorizeFileCode": paramsDto.AuthAuthorizeFileCode,
},
}
respBytes, err := deps.WestDexService.CallAPI("G22SC01", reqData)

View File

@@ -31,11 +31,15 @@ func ProcessQYGL8271Request(ctx context.Context, params []byte, deps *processors
if err != nil {
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
}
encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode)
if err != nil {
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"data": map[string]interface{}{
"org_name": encryptedEntName,
"uscc": encryptedEntCode,
"auth_authorizeFileCode": encryptedAuthAuthorizeFileCode,
"inquired_auth": paramsDto.AuthDate, // AuthDate 有 encrypt:"false" 标签,不加密
},
}

View File

@@ -31,7 +31,7 @@ type ContractInfo struct {
UserID string `gorm:"type:varchar(36);not null;index" json:"user_id" comment:"关联用户ID"`
// 合同基本信息
// ContractCode string `gorm:"type:varchar(255);not null" json:"contract_code" comment:"合同编号"`
ContractCode string `gorm:"type:varchar(255);not null;uniqueIndex" json:"contract_code" comment:"合同编号"`
ContractName string `gorm:"type:varchar(255);not null" json:"contract_name" comment:"合同名称"`
ContractType ContractType `gorm:"type:varchar(50);not null;index" json:"contract_type" comment:"合同类型"`
ContractFileID string `gorm:"type:varchar(100);not null" json:"contract_file_id" comment:"合同文件ID"`
@@ -91,13 +91,13 @@ func NewContractInfo(enterpriseInfoID, userID, contractName string, contractType
}
// 生成合同编码
// contractCode := GenerateContractCode(contractType)
contractCode := GenerateContractCode(contractType)
contractInfo := &ContractInfo{
ID: uuid.New().String(),
EnterpriseInfoID: enterpriseInfoID,
UserID: userID,
// ContractCode: contractCode,
ContractCode: contractCode,
ContractName: contractName,
ContractType: contractType,
ContractFileID: contractFileID,
@@ -110,7 +110,7 @@ func NewContractInfo(enterpriseInfoID, userID, contractName string, contractType
ContractInfoID: contractInfo.ID,
EnterpriseInfoID: enterpriseInfoID,
UserID: userID,
// ContractCode: contractCode,
ContractCode: contractCode,
ContractName: contractName,
ContractType: string(contractType),
CreatedAt: time.Now(),
@@ -198,9 +198,9 @@ func (c *ContractInfo) validateBasicFields() error {
if c.UserID == "" {
return fmt.Errorf("用户ID不能为空")
}
// if c.ContractCode == "" {
// return fmt.Errorf("合同编码不能为空")
// }
if c.ContractCode == "" {
return fmt.Errorf("合同编码不能为空")
}
if c.ContractName == "" {
return fmt.Errorf("合同名称不能为空")
}
@@ -309,7 +309,7 @@ type ContractInfoCreatedEvent struct {
ContractInfoID string `json:"contract_info_id"`
EnterpriseInfoID string `json:"enterprise_info_id"`
UserID string `json:"user_id"`
// ContractCode string `json:"contract_code"`
ContractCode string `json:"contract_code"`
ContractName string `json:"contract_name"`
ContractType string `json:"contract_type"`
CreatedAt time.Time `json:"created_at"`
@@ -347,13 +347,13 @@ func GenerateContractCode(contractType ContractType) string {
prefix += "02"
}
// 获取当前日期格式为YYMMDD
// 获取当前日期,格式为YYYYMMDD
now := time.Now()
dateStr := now.Format("060102") // YYMMDD格式
dateStr := now.Format("20060102") // YYYYMMDD格式
// 生成一个随机的6位数字
randNum := fmt.Sprintf("%06d", rand.Intn(1000000))
// 格式CON + 类型标识 + YYMMDD + 6位随机数
// 格式CON + 类型标识 + YYYYMMDD + 6位随机数
return fmt.Sprintf("%s%s%s", prefix, dateStr, randNum)
}