feat: adjust id format

This commit is contained in:
engigu
2024-01-20 13:21:38 +08:00
parent f16002573e
commit 1e0e745fea
19 changed files with 100 additions and 62 deletions
+3 -4
View File
@@ -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
View File
@@ -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 '实例配置';"`
+9 -5
View File
@@ -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"`
}
+2 -2
View File
@@ -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
View File
@@ -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,
+1 -1
View File
@@ -1,6 +1,6 @@
package constant
const CleanLogsTaskId = "00000000-0000-0000-0000-000000000001"
const CleanLogsTaskId = "T-IM1GBswSRY"
const SiteSettingSectionName = "site_config"
//const SiteSettingTitleKeyName = "title"
-19
View File
@@ -1,19 +0,0 @@
package util
import (
"time"
)
func TimeStampToYmdMHD(stamp int) string {
timestamp := int64(stamp)
timeObj := time.Unix(timestamp, 0)
formattedTime := timeObj.Format("2006-01-02 15:04:05")
return formattedTime
}
func GetNowTimeStampToYmdMHD() string {
now := time.Now().Unix()
timeObj := time.Unix(now, 0)
formattedTime := timeObj.Format("2006-01-02 15:04:05")
return formattedTime
}
+27
View File
@@ -0,0 +1,27 @@
package util
import (
"math/rand"
"time"
)
func GenerateRandomString(length int) string {
source := rand.NewSource(time.Now().UnixNano())
random := rand.New(source)
charSet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var result string
var charSetLen = len(charSet)
for i := 0; i < length; i++ {
randomIndex := random.Intn(charSetLen)
result += string(charSet[randomIndex])
}
return result
}
func GenerateUniqueID() string {
randomString := GenerateRandomString(10)
return randomString
}
+8 -11
View File
@@ -3,7 +3,6 @@ package v1
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"message-nest/models"
"message-nest/pkg/app"
"message-nest/pkg/e"
@@ -13,7 +12,7 @@ import (
)
type DeleteMsgTaskInsReq struct {
ID string `json:"id" validate:"required,len=36" label:"实例id"`
ID string `json:"id" validate:"required,len=12" label:"实例id"`
}
// DeleteMsgSendWay 删除消息渠道
@@ -65,9 +64,9 @@ func GetMsgSendWayIns(c *gin.Context) {
}
type SendTasksInsReq struct {
ID string `json:"id" validate:"required,len=36" label:"实例id"`
TaskId string `json:"task_id" validate:"required,len=36" label:"ins任务id"`
WayID string `json:"way_id" validate:"required,len=36" label:"渠道id"`
ID string `json:"id" validate:"required,len=12" label:"实例id"`
TaskId string `json:"task_id" validate:"required,len=12" label:"ins任务id"`
WayID string `json:"way_id" validate:"required,len=12" label:"渠道id"`
ContentType string `json:"content_type" validate:"required,max=100" label:"实例内容类型"`
Config string `json:"config" validate:"" label:"任务配置"`
Extra string `json:"extra" validate:"" label:"任务额外信息"`
@@ -76,7 +75,7 @@ type SendTasksInsReq struct {
}
type AddManyTasksInsReq struct {
TaskId string `json:"id" validate:"required,len=36" label:"任务id"`
TaskId string `json:"id" validate:"required,len=12" label:"任务id"`
TaskName string `json:"name" validate:"required,max=100" label:"任务名"`
InsData []SendTasksInsReq `json:"ins_data"`
}
@@ -104,10 +103,9 @@ func AddManyTasksIns(c *gin.Context) {
appG.CResponse(code, dataErrStr, nil)
return
}
uuidObj, _ := uuid.Parse(data.ID)
taskIns = append(taskIns, models.SendTasksIns{
UUIDModel: models.UUIDModel{
ID: uuidObj,
ID: data.ID,
CreatedBy: currentUser,
ModifiedBy: currentUser,
},
@@ -158,9 +156,8 @@ func AddTasksIns(c *gin.Context) {
}
sendTaskInsService := send_ins_service.SendTaskInsService{}
uuidObj, _ := uuid.Parse(req.ID)
err := sendTaskInsService.AddOne(models.SendTasksIns{
UUIDModel: models.UUIDModel{ID: uuidObj},
UUIDModel: models.UUIDModel{ID: req.ID},
TaskID: req.TaskId,
WayID: req.WayID,
WayType: req.WayType,
@@ -179,7 +176,7 @@ func AddTasksIns(c *gin.Context) {
}
type UpdateMsgTaskInsEnableReq struct {
ID string `json:"ins_id" validate:"required,len=36" label:"实例id"`
ID string `json:"ins_id" validate:"required,len=12" label:"实例id"`
Enable int `json:"status" validate:"" label:"实例开启状态"`
}
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
type SendMessageReq struct {
TaskID string `json:"task_id" validate:"required,len=36" label:"任务id"`
TaskID string `json:"task_id" validate:"required,len=12" label:"任务id"`
Text string `json:"text" validate:"required" label:"文本内容"`
Title string `json:"title" label:"消息标题"`
HTML string `json:"html" label:"html内容"`
+2 -2
View File
@@ -11,7 +11,7 @@ import (
)
type DeleteMsgSendTaskReq struct {
ID string `json:"id" validate:"required,len=36" label:"任务id"`
ID string `json:"id" validate:"required,len=12" label:"任务id"`
}
// DeleteMsgSendTask 删除消息任务
@@ -103,7 +103,7 @@ func AddMsgSendTask(c *gin.Context) {
}
type EditMsgSendTaskReq struct {
ID string `json:"id" validate:"required,len=36" label:"任务id"`
ID string `json:"id" validate:"required,len=12" label:"任务id"`
TaskName string `json:"name" validate:"required,max=100,min=1" label:"任务任务名"`
}
+2 -2
View File
@@ -12,7 +12,7 @@ import (
)
type DeleteMsgSendWayReq struct {
ID string `json:"id" validate:"required,len=36" label:"渠道id"`
ID string `json:"id" validate:"required,len=12" label:"渠道id"`
}
// DeleteMsgSendWay 删除消息渠道
@@ -138,7 +138,7 @@ func AddMsgSendWay(c *gin.Context) {
}
type EditSendWayReq struct {
ID string `json:"id" validate:"required,len=36" label:"渠道id"`
ID string `json:"id" validate:"required,len=12" label:"渠道id"`
Name string `json:"name" validate:"required,max=100,min=1" label:"渠道名"`
Type string `json:"type" validate:"required,max=100,min=1" label:"渠道类型"`
Auth string `json:"auth" validate:"required" label:"渠道认证信息"`
+1 -1
View File
@@ -7,7 +7,7 @@ const CONSTANT = {
// PAGE_SIZE: 8,
TOTAL: 0,
DEFALUT_SITE_CONFIG: JSON.stringify({ "logo": "<svg t=\"1702547210136\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"1861\" width=\"200\" height=\"200\"><path d=\"M970.091313 224.033616a14.201535 14.201535 0 0 0-14.100687-3.631838c-88.419556-13.429657-142.919111-12.953859-248.242424 23.762747-69.454869 24.217859-109.056 79.873293-135.267556 116.712728-6.692202 9.403475-18.949172 26.625293-23.77309 29.509818-5.70699-1.303273-21.929374-16.036202-31.762101-24.965172-28.626747-25.994343-64.252121-58.353778-106.767516-58.757172-0.312889-0.005172-0.627071-0.005172-0.939959-0.005171-29.62101 0-54.798222 13.434828-72.857859 38.89907-13.222788 18.651798-17.914828 37.388929-18.106182 38.176323a14.31402 14.31402 0 0 0 2.893576 12.515556 14.336 14.336 0 0 0 11.782465 5.095434l0.409858-0.024565c19.192242-1.152 59.141172-3.545212 65.807516 81.857939 4.288646 54.899071 29.742545 108.631919 69.833697 147.419798 45.499475 44.025535 106.237414 67.298263 175.650909 67.298263 98.97503 0 166.222869-24.480323 205.207272-45.015919 43.172202-22.742626 62.621737-45.918384 63.429819-46.898425a14.170505 14.170505 0 0 0 1.529535-15.874586 14.191192 14.191192 0 0 0-14.166626-7.337373c-37.924202 4.443798-92.767677 6.09099-138.666667-11.298909-7.580444-2.872889-13.878303-5.893172-18.959515-8.691071 20.273131-9.964606 51.000889-28.383677 83.621495-59.93503 34.186343-33.065374 37.722505-69.908687 40.838464-102.423273 2.297535-23.919192 4.666182-48.651636 18.500526-73.091879 28.807758-50.883232 66.645333-74.489535 74.560646-79.035475a14.201535 14.201535 0 0 0 12.135434-7.776969 14.193778 14.193778 0 0 0-2.59103-16.484849z\" fill=\"\" p-id=\"1862\"></path><path d=\"M674.834101 716.481939c-33.422222 4.90796-74.989899 16.884364-117.22602-8.102787-34.843152-20.613172-53.056646-20.993293-77.783919-18.49794-0.156444 0.015515-0.312889 0.015515-0.469334 0.034909-0.274101 0.033616-0.548202 0.060768-0.822303 0.094384-4.697212 0.487434-9.65301 1.065374-14.995394 1.62004-6.702545 0.649051-13.414141 1.19596-20.133495 1.634263-75.333818 4.102465-136.860444-5.381172-163.012525-10.404202-49.488162-9.872808-86.57196-23.921778-108.946101-33.970424-59.832889-26.868364-87.080081-56.671677-87.080081-72.989738 0-1.873455 0.384-2.222545 0.787394-2.585858 2.196687-1.974303 10.616242-6.520242 41.302626-6.004364 24.793212 0.418909 56.970343 3.858101 94.308849 7.853253 40.722101 4.348121 86.873212 9.283232 136.348444 11.686788 6.913293 0.333576 13.959758 0.625778 20.93899 0.858505 9.510788 0.307717 17.545051-7.182222 17.868283-16.707233 0.319354-9.535354-7.175758-17.550222-16.705939-17.868282a1386.24 1386.24 0 0 1-20.419233-0.839112c-48.521051-2.358303-94.161455-7.236525-134.434909-11.544565-90.868364-9.712485-139.353212-13.818828-162.333737 6.833131-8.02004 7.21196-12.262141 17.004606-12.262141 28.317737 0 0.672323 0.029737 1.348525 0.065939 2.026021l0.005172 0.100848c-0.045253 0.524929-0.071111 1.039515-0.071111 1.539879 0 41.464242 9.561212 81.661414 28.414707 119.484768 17.493333 35.088808 42.251636 66.663434 73.583192 93.927434 9.169455-6.551273 20.155475-13.604202 32.524929-20.050748 49.737697-25.921939 97.838545-29.339152 139.099798-9.884444 101.590626 47.906909 142.060606 47.837091 206.198949-0.364606 5.70699-4.287354 13.814949-3.140525 18.103596 2.567758 4.289939 5.708283 3.140525 13.813657-2.567757 18.103595-38.425859 28.877576-69.968162 41.279354-105.143596 41.280647-0.484848 0-0.969697-0.002586-1.457132-0.007758-32.760242-0.316768-69.311354-11.381657-126.16404-38.190545-51.905939-24.47903-106.215434 1.008485-139.548444 23.465374 64.611556 47.922424 146.341495 74.101657 232.704 74.101656 117.55701 0 226.204444-48.934788 292.761858-131.362909l0.002586-0.002586c18.79402-14.959192 12.028121-41.362101-23.442101-36.152889z\" fill=\"\" p-id=\"1863\"></path></svg>", "pagesize": "8", "slogan": "A Message Way Hosted Site", "title": "Message Nest" }),
LOG_TASK_ID: "00000000-0000-0000-0000-000000000001",
LOG_TASK_ID: "T-IM1GBswSRY",
STORE_TOKEN_NAME: '__message_nest_token__',
STORE_CUSTOM_NAME: '__message_nest_custom_site__',
NO_AUTH_URL: [
+24
View File
@@ -0,0 +1,24 @@
function generateRandomString(length) {
const charSet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charSet.length);
result += charSet.charAt(randomIndex);
}
return result;
}
function generateUniqueID() {
const randomString = generateRandomString(10);
return randomString;
}
function generateBizUniqueID(flag) {
const randomString = generateRandomString(10);
return `${flag}-${randomString}`;
}
export { generateUniqueID, generateBizUniqueID };
@@ -14,7 +14,7 @@
<div ref="refContainer">
<el-table :data="tableData" stripe empty-text="发信任务为空" :row-style="rowStyle()">
<el-table-column label="ID" prop="id" width="320px" />
<el-table-column label="ID" prop="id" />
<el-table-column label="任务名" prop="name" />
<el-table-column label="创建时间" prop="created_on" />
<el-table-column fixed="right" label="操作" width="190px">
@@ -96,11 +96,11 @@
import { defineComponent, onMounted, watch, reactive, toRefs } from 'vue';
import { _ } from 'lodash';
import { QuestionFilled } from '@element-plus/icons-vue'
import { v4 as uuidv4 } from 'uuid';
import { usePageState } from '@/store/page_sate.js';
import { request } from '@/api/api'
import { CONSTANT } from '@/constant'
import { CommonUtils } from "@/util/commonUtils.js";
import { generateBizUniqueID } from "@/util/uuid.js";
export default defineComponent({
@@ -122,7 +122,7 @@ export default defineComponent({
currInsInputContentType: 'text',
currTaskInput: {
taskName: '',
taskId: uuidv4(),
taskId: generateBizUniqueID('T'),
},
});
@@ -149,7 +149,7 @@ export default defineComponent({
state.isShowAddBox = false;
state.currTaskInput = {
taskName: '',
taskId: uuidv4(),
taskId: generateBizUniqueID('T'),
}
}
@@ -162,7 +162,7 @@ export default defineComponent({
// 点击暂存实例
const clickStore = () => {
let insData = {
id: uuidv4(),
id: generateBizUniqueID('I'),
task_id: state.currTaskInput.taskId,
way_id: state.currWayTmp.id,
way_type: state.currWayTmp.type,
@@ -102,13 +102,13 @@
import { defineComponent, onMounted, watch, reactive, toRefs } from 'vue';
import { _ } from 'lodash';
import { QuestionFilled } from '@element-plus/icons-vue'
import { v4 as uuidv4 } from 'uuid';
import { usePageState } from '@/store/page_sate.js';
import { request } from '@/api/api'
import tableDeleteButton from '@/views/common/tableDeleteButton.vue'
import { ElMessage } from 'element-plus'
import { CONSTANT } from '@/constant'
import { CommonUtils } from "@/util/commonUtils.js";
import { generateBizUniqueID } from "@/util/uuid.js";
export default defineComponent({
@@ -203,7 +203,7 @@ export default defineComponent({
const getFinalData = () => {
let postData = {
id: uuidv4(),
id: generateBizUniqueID('I'),
enable: 1,
task_id: state.currTaskInput.taskId,
way_id: state.currWayTmp.id,
@@ -19,7 +19,7 @@
<hr />
<div ref="refContainer">
<el-table :data="tableData" stripe empty-text="发信渠道为空" :row-style="rowStyle()">
<el-table-column label="ID" width="320px">
<el-table-column label="ID" >
<template #default="scope">
{{ scope.row.id }}
<el-icon>
@@ -116,7 +116,7 @@ export default {
await queryListData(pageNum, state.pageSize);
}
const rowStyle = () => {
return {
'font-size': '13px',
@@ -62,7 +62,8 @@ export default defineComponent({
if (newValue[props.componentName].rowData) {
const row = pageState.ShowDialogData[props.componentName].rowData;
let nowData = [];
_.cloneDeep(CONSTANT.WAYS_DATA).forEach(element => {
let copyData = _.cloneDeep(CONSTANT.WAYS_DATA);
copyData.forEach(element => {
if (element.type == row.type) {
// 填充输入框的值
state.editData = row;