接入阿里云二要素
This commit is contained in:
@@ -2,12 +2,18 @@ package entities
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 初始化随机数种子
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// ContractType 合同类型枚举
|
||||
type ContractType string
|
||||
|
||||
@@ -20,15 +26,16 @@ const (
|
||||
// 存储企业签署的合同信息,一个企业可以有多个合同
|
||||
type ContractInfo struct {
|
||||
// 基础标识
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"合同信息唯一标识"`
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"合同信息唯一标识"`
|
||||
EnterpriseInfoID string `gorm:"type:varchar(36);not null;index" json:"enterprise_info_id" comment:"关联企业信息ID"`
|
||||
UserID string `gorm:"type:varchar(36);not null;index" json:"user_id" comment:"关联用户ID"`
|
||||
UserID string `gorm:"type:varchar(36);not null;index" json:"user_id" comment:"关联用户ID"`
|
||||
|
||||
// 合同基本信息
|
||||
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"`
|
||||
ContractFileURL string `gorm:"type:varchar(500);not null" json:"contract_file_url" comment:"合同文件下载链接"`
|
||||
// ContractCode string `gorm:"type:varchar(255);not null" 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"`
|
||||
ContractFileURL string `gorm:"type:varchar(500);not null" json:"contract_file_url" comment:"合同文件下载链接"`
|
||||
|
||||
// 时间戳字段
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
|
||||
@@ -83,15 +90,19 @@ func NewContractInfo(enterpriseInfoID, userID, contractName string, contractType
|
||||
return nil, fmt.Errorf("无效的合同类型: %s", contractType)
|
||||
}
|
||||
|
||||
// 生成合同编码
|
||||
// contractCode := GenerateContractCode(contractType)
|
||||
|
||||
contractInfo := &ContractInfo{
|
||||
ID: uuid.New().String(),
|
||||
EnterpriseInfoID: enterpriseInfoID,
|
||||
UserID: userID,
|
||||
ContractName: contractName,
|
||||
ContractType: contractType,
|
||||
ContractFileID: contractFileID,
|
||||
ContractFileURL: contractFileURL,
|
||||
domainEvents: make([]interface{}, 0),
|
||||
// ContractCode: contractCode,
|
||||
ContractName: contractName,
|
||||
ContractType: contractType,
|
||||
ContractFileID: contractFileID,
|
||||
ContractFileURL: contractFileURL,
|
||||
domainEvents: make([]interface{}, 0),
|
||||
}
|
||||
|
||||
// 添加领域事件
|
||||
@@ -99,9 +110,10 @@ func NewContractInfo(enterpriseInfoID, userID, contractName string, contractType
|
||||
ContractInfoID: contractInfo.ID,
|
||||
EnterpriseInfoID: enterpriseInfoID,
|
||||
UserID: userID,
|
||||
ContractName: contractName,
|
||||
ContractType: string(contractType),
|
||||
CreatedAt: time.Now(),
|
||||
// ContractCode: contractCode,
|
||||
ContractName: contractName,
|
||||
ContractType: string(contractType),
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
|
||||
return contractInfo, nil
|
||||
@@ -133,14 +145,14 @@ func (c *ContractInfo) UpdateContractInfo(contractName, contractFileID, contract
|
||||
|
||||
// 添加领域事件
|
||||
c.addDomainEvent(&ContractInfoUpdatedEvent{
|
||||
ContractInfoID: c.ID,
|
||||
EnterpriseInfoID: c.EnterpriseInfoID,
|
||||
UserID: c.UserID,
|
||||
OldContractName: oldContractName,
|
||||
NewContractName: contractName,
|
||||
ContractInfoID: c.ID,
|
||||
EnterpriseInfoID: c.EnterpriseInfoID,
|
||||
UserID: c.UserID,
|
||||
OldContractName: oldContractName,
|
||||
NewContractName: contractName,
|
||||
OldContractFileID: oldContractFileID,
|
||||
NewContractFileID: contractFileID,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
})
|
||||
|
||||
return nil
|
||||
@@ -186,6 +198,9 @@ func (c *ContractInfo) validateBasicFields() error {
|
||||
if c.UserID == "" {
|
||||
return fmt.Errorf("用户ID不能为空")
|
||||
}
|
||||
// if c.ContractCode == "" {
|
||||
// return fmt.Errorf("合同编码不能为空")
|
||||
// }
|
||||
if c.ContractName == "" {
|
||||
return fmt.Errorf("合同名称不能为空")
|
||||
}
|
||||
@@ -291,12 +306,13 @@ func isValidURL(url string) bool {
|
||||
|
||||
// ContractInfoCreatedEvent 合同信息创建事件
|
||||
type ContractInfoCreatedEvent struct {
|
||||
ContractInfoID string `json:"contract_info_id"`
|
||||
EnterpriseInfoID string `json:"enterprise_info_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ContractName string `json:"contract_name"`
|
||||
ContractType string `json:"contract_type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ContractInfoID string `json:"contract_info_id"`
|
||||
EnterpriseInfoID string `json:"enterprise_info_id"`
|
||||
UserID string `json:"user_id"`
|
||||
// ContractCode string `json:"contract_code"`
|
||||
ContractName string `json:"contract_name"`
|
||||
ContractType string `json:"contract_type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// ContractInfoUpdatedEvent 合同信息更新事件
|
||||
@@ -319,4 +335,25 @@ type ContractInfoDeletedEvent struct {
|
||||
ContractName string `json:"contract_name"`
|
||||
ContractType string `json:"contract_type"`
|
||||
DeletedAt time.Time `json:"deleted_at"`
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateContractCode 生成合同编码
|
||||
func GenerateContractCode(contractType ContractType) string {
|
||||
prefix := "CON"
|
||||
switch contractType {
|
||||
case ContractTypeCooperation:
|
||||
prefix += "01"
|
||||
case ContractTypeReSign:
|
||||
prefix += "02"
|
||||
}
|
||||
|
||||
// 获取当前日期,格式为YYMMDD
|
||||
now := time.Now()
|
||||
dateStr := now.Format("060102") // YYMMDD格式
|
||||
|
||||
// 生成一个随机的6位数字
|
||||
randNum := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
|
||||
// 格式:CON + 类型标识 + YYMMDD + 6位随机数
|
||||
return fmt.Sprintf("%s%s%s", prefix, dateStr, randNum)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user