新增部分接口合同授权码

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

@@ -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)
}