feat: adjust id format
This commit is contained in:
+3
-4
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"log"
|
||||
@@ -19,16 +18,16 @@ type IDModel struct {
|
||||
CreatedBy string `json:"created_by" gorm:"type:varchar(100) comment '创建人';default:'';"`
|
||||
ModifiedBy string `json:"modified_by" gorm:"type:varchar(100) comment '修改人';default:'';"`
|
||||
CreatedOn util.Time `json:"created_on" gorm:"type:timestamp comment '创建时间';default:current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';default:current_timestamp on update current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';"`
|
||||
}
|
||||
|
||||
type UUIDModel struct {
|
||||
ID uuid.UUID `gorm:"type:varchar(36) comment 'id';primary_key" json:"id"`
|
||||
ID string `gorm:"type:varchar(12) comment 'id';primary_key" json:"id"`
|
||||
|
||||
CreatedBy string `json:"created_by" gorm:"type:varchar(100) comment '创建人';default:'';"`
|
||||
ModifiedBy string `json:"modified_by" gorm:"type:varchar(100) comment '修改人';default:'';"`
|
||||
CreatedOn util.Time `json:"created_on" gorm:"type:timestamp comment '创建时间';default:current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';default:current_timestamp on update current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';"`
|
||||
}
|
||||
|
||||
// Setup initializes the database instance
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package models
|
||||
type SendTasksIns struct {
|
||||
UUIDModel
|
||||
|
||||
TaskID string `json:"task_id" gorm:"type:varchar(36) comment '任务id';default:'';index:task_id"`
|
||||
WayID string `json:"way_id" gorm:"type:varchar(36) comment '渠道id';default:'';index:way_id"`
|
||||
TaskID string `json:"task_id" gorm:"type:varchar(12) comment '任务id';default:'';index:task_id"`
|
||||
WayID string `json:"way_id" gorm:"type:varchar(12) comment '渠道id';default:'';index:way_id"`
|
||||
WayType string `json:"way_type" gorm:"type:varchar(100) comment '渠道类型';default:'';index:way_type"`
|
||||
ContentType string `json:"content_type" gorm:"type:varchar(100) comment '实例类型';default:'';index:content_type"`
|
||||
Config string `json:"config" gorm:"type:text comment '实例配置';"`
|
||||
|
||||
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/gorm"
|
||||
"message-nest/pkg/util"
|
||||
)
|
||||
|
||||
type SendTasks struct {
|
||||
@@ -13,16 +13,20 @@ type SendTasks struct {
|
||||
Name string `json:"name" gorm:"type:varchar(100) comment '任务名称';default:'';"`
|
||||
}
|
||||
|
||||
func GenerateTaskUniqueID() string {
|
||||
newUUID := util.GenerateUniqueID()
|
||||
return fmt.Sprintf("T-%s", newUUID)
|
||||
}
|
||||
|
||||
// AddSendTaskWithID 添加实例的时候添加任务
|
||||
func AddSendTaskWithID(name string, id string, createdBy string) error {
|
||||
err := db.Where("id = ?", id).Find(&SendTasks{}).Error
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
uuidObj, _ := uuid.Parse(id)
|
||||
task := SendTasks{
|
||||
UUIDModel: UUIDModel{
|
||||
ID: uuidObj,
|
||||
ID: id,
|
||||
CreatedBy: createdBy,
|
||||
ModifiedBy: createdBy,
|
||||
},
|
||||
@@ -36,7 +40,7 @@ func AddSendTaskWithID(name string, id string, createdBy string) error {
|
||||
|
||||
// AddSendTask 添加任务
|
||||
func AddSendTask(name string, createdBy string) error {
|
||||
newUUID := uuid.New()
|
||||
newUUID := GenerateTaskUniqueID()
|
||||
task := SendTasks{
|
||||
UUIDModel: UUIDModel{
|
||||
ID: newUUID,
|
||||
@@ -97,7 +101,7 @@ type SendTasksInsRes struct {
|
||||
}
|
||||
|
||||
type TaskIns struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
InsData []SendTasksInsRes `json:"ins_data"`
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
type SendTasksLogs struct {
|
||||
ID int `gorm:"primary_key" json:"id" `
|
||||
TaskID string `json:"task_id" gorm:"type:varchar(36) comment '任务id';default:'';index:task_id"`
|
||||
TaskID string `json:"task_id" gorm:"type:varchar(12) comment '任务id';default:'';index:task_id"`
|
||||
Log string `json:"log" gorm:"type:text comment '日志';"`
|
||||
Status int `json:"status" gorm:"type:int comment '状态';default:0;"`
|
||||
|
||||
CreatedOn util.Time `json:"created_on" gorm:"type:timestamp comment '创建时间';default:current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';default:current_timestamp on update current_timestamp;"`
|
||||
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';"`
|
||||
}
|
||||
|
||||
// Add 添加日志记录
|
||||
|
||||
+7
-2
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/gorm"
|
||||
"message-nest/pkg/util"
|
||||
)
|
||||
|
||||
type SendWays struct {
|
||||
@@ -15,8 +15,13 @@ type SendWays struct {
|
||||
Auth string `json:"auth" gorm:"type:varchar(2048) comment '认证信息';default:'';"`
|
||||
}
|
||||
|
||||
func GenerateWayUniqueID() string {
|
||||
newUUID := util.GenerateUniqueID()
|
||||
return fmt.Sprintf("W-%s", newUUID)
|
||||
}
|
||||
|
||||
func AddSendWay(name string, auth string, wayType string, createdBy string, modifiedBy string) error {
|
||||
newUUID := uuid.New()
|
||||
newUUID := GenerateWayUniqueID()
|
||||
way := SendWays{
|
||||
UUIDModel: UUIDModel{
|
||||
ID: newUUID,
|
||||
|
||||
Reference in New Issue
Block a user