From 585cbbed230c995643f6b395db9a9dc7263c1168 Mon Sep 17 00:00:00 2001
From: "meilin.huang" <954537473@qq.com>
Date: Wed, 16 Apr 2025 12:09:55 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20i18n=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +--
frontend/src/i18n/en/msg.ts | 2 +-
frontend/src/i18n/en/system.ts | 2 +-
frontend/src/i18n/zh-cn/msg.ts | 2 +-
frontend/src/i18n/zh-cn/system.ts | 2 +-
.../internal/db/application/db_data_sync.go | 8 ++++--
server/internal/db/application/db_sql_exec.go | 2 ++
server/internal/db/application/db_transfer.go | 8 ++++--
.../machine/application/machine_cronjob.go | 6 ++--
server/migration/migrations/init.go | 9 ------
server/pkg/base/app.go | 2 ++
server/pkg/base/repo.go | 2 ++
server/pkg/biz/assert.go | 17 ++++++-----
server/pkg/scheduler/scheduler.go | 28 ++++++++++---------
server/resources/script/sql/mayfly-go.sql | 1 -
15 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/README.md b/README.md
index 2ec26059..501a8491 100644
--- a/README.md
+++ b/README.md
@@ -108,9 +108,9 @@ http://go.mayfly.run
如果觉得项目不错,或者已经在使用了,希望你可以去 Github 或者 Gitee 帮我点个 ⭐ Star,这将是对我极大的鼓励与支持。
-> 喝杯咖啡 ☕️ 或者来杯奶茶 🧋,让作者更有精神,写出更棒的代码!这将是对作者最大的鼓励和支持!
+> 喝杯咖啡 ☕️ 或者来杯奶茶 🧋,让作者更有精神,写出更棒的代码!
> **特别感谢:**
-> 赞助金额达 199 元以上,加微信(wx-error),我将邀请您进入付费交流群,享受更快、更优先的技术支持!
+> 赞助金额达 199 元以上,加微信(wx-error),可受邀进入付费交流群,享受更快、更优先的技术支持与交流服务!
diff --git a/frontend/src/i18n/en/msg.ts b/frontend/src/i18n/en/msg.ts
index 334e66af..21bac309 100644
--- a/frontend/src/i18n/en/msg.ts
+++ b/frontend/src/i18n/en/msg.ts
@@ -16,6 +16,6 @@ export default {
sendMsg: 'Send Message',
selectTmplPlaceholder: 'Select message template, support fuzzy search by number',
msgTmplTooltip:
- 'Message template supports variable replacement, the variable format is {{.variable}}, the following are common built-in variables
{{.receiver}}: used to @ specify the recipient',
+ "Message template supports variable replacement, the variable format is {'{{.variable}}'} the following are common built-in variables
{'{{.receiver}}'}: used to {'@'} specify the recipient",
},
};
diff --git a/frontend/src/i18n/en/system.ts b/frontend/src/i18n/en/system.ts
index ba0bc726..6d234efb 100644
--- a/frontend/src/i18n/en/system.ts
+++ b/frontend/src/i18n/en/system.ts
@@ -48,7 +48,7 @@ export default {
lastLoginTime: 'Last Login Time',
usernamePlacholder: '5-16 uppercase letters, numbers, -.: characters',
random: 'Random',
- usernamePatternErrMsg: 'Only 5-16 uppercase letters, numbers, and -@.: characters are allowed',
+ usernamePatternErrMsg: "Only 5-16 uppercase letters, numbers, and -.:{'@'} characters are allowed",
accountSearchPlaceholder: 'Enter account fuzzy search and select',
accountInfo: 'Account Information',
allocateRoleTitle: 'Allocate the `{name}` role',
diff --git a/frontend/src/i18n/zh-cn/msg.ts b/frontend/src/i18n/zh-cn/msg.ts
index fa5c5000..932a4484 100644
--- a/frontend/src/i18n/zh-cn/msg.ts
+++ b/frontend/src/i18n/zh-cn/msg.ts
@@ -15,6 +15,6 @@ export default {
send: '发送',
sendMsg: '发送消息',
selectTmplPlaceholder: '选择消息模板,支持编号模糊搜索',
- msgTmplTooltip: '消息模板支持变量替换,变量格式为{{.变量名}},以下为通用内置变量
{{.receiver}}:用于@指定接收人',
+ msgTmplTooltip: "消息模板支持变量替换,变量格式为{'{{.变量名}}'},以下为通用内置变量
{'{{.receiver}}'}:用于{'@'}指定接收人",
},
};
diff --git a/frontend/src/i18n/zh-cn/system.ts b/frontend/src/i18n/zh-cn/system.ts
index bcd3b399..94a45b8b 100644
--- a/frontend/src/i18n/zh-cn/system.ts
+++ b/frontend/src/i18n/zh-cn/system.ts
@@ -47,7 +47,7 @@ export default {
deleteAccountConfirm: '确定删除【{name}】的账号?',
usernamePlacholder: '5-16位大小写字母、数字、_-.:',
random: '随机',
- usernamePatternErrMsg: '只允许输入5-16位大小写字母、数字、_-@.:',
+ usernamePatternErrMsg: "只允许输入5-16位大小写字母、数字、_-.:{'@'}",
accountSearchPlaceholder: '输入账号模糊搜索并选择',
accountInfo: '账号信息',
allocateRoleTitle: '分配 `{name}` 的角色',
diff --git a/server/internal/db/application/db_data_sync.go b/server/internal/db/application/db_data_sync.go
index 6264e830..ff014398 100644
--- a/server/internal/db/application/db_data_sync.go
+++ b/server/internal/db/application/db_data_sync.go
@@ -47,6 +47,8 @@ type DataSyncTask interface {
GetTaskLogList(condition *entity.DataSyncLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
}
+var _ (DataSyncTask) = (*dataSyncAppImpl)(nil)
+
type dataSyncAppImpl struct {
base.AppImpl[*entity.DataSyncTask, repository.DataSyncTask]
@@ -105,12 +107,14 @@ func (app *dataSyncAppImpl) AddCronJob(ctx context.Context, taskEntity *entity.D
// 根据状态添加新的任务
if taskEntity.Status == entity.DataSyncTaskStatusEnable {
taskId := taskEntity.Id
- scheduler.AddFunByKey(key, taskEntity.TaskCron, func() {
+ if err := scheduler.AddFunByKey(key, taskEntity.TaskCron, func() {
logx.Infof("start the data synchronization task: %d", taskId)
if err := app.RunCronJob(ctx, taskId); err != nil {
logx.Errorf("the data synchronization task failed to execute at a scheduled time: %s", err.Error())
}
- })
+ }); err != nil {
+ logx.ErrorTrace("add db data sync cron job failed", err)
+ }
}
}
diff --git a/server/internal/db/application/db_sql_exec.go b/server/internal/db/application/db_sql_exec.go
index dbc4855c..cb27d16e 100644
--- a/server/internal/db/application/db_sql_exec.go
+++ b/server/internal/db/application/db_sql_exec.go
@@ -64,6 +64,8 @@ type DbSqlExec interface {
GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
}
+var _ (DbSqlExec) = (*dbSqlExecAppImpl)(nil)
+
type dbSqlExecAppImpl struct {
dbApp Db `inject:"T"`
dbSqlExecRepo repository.DbSqlExec `inject:"T"`
diff --git a/server/internal/db/application/db_transfer.go b/server/internal/db/application/db_transfer.go
index 9af648d2..ab9e119a 100644
--- a/server/internal/db/application/db_transfer.go
+++ b/server/internal/db/application/db_transfer.go
@@ -58,6 +58,8 @@ type DbTransferTask interface {
TimerDeleteTransferFile()
}
+var _ (DbTransferTask) = (*dbTransferAppImpl)(nil)
+
type dbTransferAppImpl struct {
base.AppImpl[*entity.DbTransferTask, repository.DbTransferTask]
@@ -114,11 +116,13 @@ func (app *dbTransferAppImpl) AddCronJob(ctx context.Context, taskEntity *entity
}
taskId := taskEntity.Id
- scheduler.AddFunByKey(key, taskEntity.Cron, func() {
+ if err := scheduler.AddFunByKey(key, taskEntity.Cron, func() {
logx.Infof("start the synchronization task: %d", taskId)
logId, _ := app.CreateLog(ctx, taskId)
app.Run(ctx, taskId, logId)
- })
+ }); err != nil {
+ logx.ErrorTrace("add db transfer cron job failed", err)
+ }
}
}
diff --git a/server/internal/machine/application/machine_cronjob.go b/server/internal/machine/application/machine_cronjob.go
index e5737a8e..89ca2300 100644
--- a/server/internal/machine/application/machine_cronjob.go
+++ b/server/internal/machine/application/machine_cronjob.go
@@ -165,9 +165,11 @@ func (m *machineCronJobAppImpl) addCronJob(mcj *entity.MachineCronJob) {
return
}
- scheduler.AddFunByKey(key, mcj.Cron, func() {
+ if err := scheduler.AddFunByKey(key, mcj.Cron, func() {
m.RunCronJob(key)
- })
+ }); err != nil {
+ logx.ErrorTrace("add machine cron job failed", err)
+ }
}
func (m *machineCronJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineCronJob) {
diff --git a/server/migration/migrations/init.go b/server/migration/migrations/init.go
index fd36f782..7eb1f2dc 100644
--- a/server/migration/migrations/init.go
+++ b/server/migration/migrations/init.go
@@ -562,15 +562,6 @@ func initResource(tx *gorm.DB) error {
Type: 2,
Weight: 19999999,
},
- {
- Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 30}}}},
- Pid: 14,
- UiPath: "Xlqig32x/sfslfel/32xax2xA/",
- Name: "menu.accountEdit",
- Code: "account:update",
- Type: 2,
- Weight: 19999999,
- },
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 31}}}},
Pid: 14,
diff --git a/server/pkg/base/app.go b/server/pkg/base/app.go
index cbcf3bb3..d25ab467 100644
--- a/server/pkg/base/app.go
+++ b/server/pkg/base/app.go
@@ -70,6 +70,8 @@ type App[T model.ModelI] interface {
Tx(ctx context.Context, funcs ...func(context.Context) error) (err error)
}
+var _ (App[*model.Model]) = (*AppImpl[*model.Model, *RepoImpl[*model.Model]])(nil)
+
// 基础application接口实现
type AppImpl[T model.ModelI, R Repo[T]] struct {
Repo R `inject:"T"` // repo接口, 根据类型进行注入
diff --git a/server/pkg/base/repo.go b/server/pkg/base/repo.go
index 85130027..331aa8cf 100644
--- a/server/pkg/base/repo.go
+++ b/server/pkg/base/repo.go
@@ -93,6 +93,8 @@ type Repo[T model.ModelI] interface {
CountByCond(cond any) int64
}
+var _ (Repo[*model.Model]) = (*RepoImpl[*model.Model])(nil)
+
// 基础repo接口
type RepoImpl[T model.ModelI] struct {
model any // 模型实例
diff --git a/server/pkg/biz/assert.go b/server/pkg/biz/assert.go
index 1e641c38..d690a47d 100644
--- a/server/pkg/biz/assert.go
+++ b/server/pkg/biz/assert.go
@@ -2,7 +2,6 @@ package biz
import (
"context"
- "fmt"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/i18n"
"mayfly-go/pkg/utils/anyx"
@@ -22,7 +21,7 @@ func ErrIsNil(err error, msgAndParams ...any) {
panic(errorx.NewBiz(err.Error()))
}
- panic(errorx.NewBiz(fmt.Sprintf(msgAndParams[0].(string), msgAndParams[1:]...)))
+ panic(errorx.NewBiz(msgAndParams[0].(string), msgAndParams[1:]...))
}
}
@@ -44,7 +43,7 @@ func ErrIsNilI(ctx context.Context, err error, msgId i18n.MsgId, attrs ...any) {
func ErrNotNil(err error, msg string, params ...any) {
if err == nil {
- panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
+ panic(errorx.NewBiz(msg, params...))
}
}
@@ -54,7 +53,7 @@ func ErrNotNil(err error, msg string, params ...any) {
// biz.ErrIsNilAppendErr(err, "xxxx: %s")
func ErrIsNilAppendErr(err error, msg string) {
if err != nil {
- panic(errorx.NewBiz(fmt.Sprintf(msg, err.Error())))
+ panic(errorx.NewBiz(msg, err.Error()))
}
}
@@ -64,13 +63,13 @@ func ErrIsNilAppendErr(err error, msg string) {
// biz.ErrIsNilAppendErr(err, "xxxx: %s")
func ErrIsNilAppendErrI(ctx context.Context, err error, msgId i18n.MsgId) {
if err != nil {
- panic(errorx.NewBiz(fmt.Sprintf(i18n.TC(ctx, msgId), err.Error())))
+ panic(errorx.NewBiz(i18n.TC(ctx, msgId), err.Error()))
}
}
func IsTrue(exp bool, msg string, params ...any) {
if !exp {
- panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
+ panic(errorx.NewBiz(msg, params...))
}
}
@@ -88,19 +87,19 @@ func IsTrueBy(exp bool, err *errorx.BizError) {
func NotEmpty(str string, msg string, params ...any) {
if str == "" {
- panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
+ panic(errorx.NewBiz(msg, params...))
}
}
func NotNil(data any, msg string, params ...any) {
if reflect.ValueOf(data).IsNil() {
- panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
+ panic(errorx.NewBiz(msg, params...))
}
}
func NotBlank(data any, msg string, params ...any) {
if anyx.IsBlank(data) {
- panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
+ panic(errorx.NewBiz(msg, params...))
}
}
diff --git a/server/pkg/scheduler/scheduler.go b/server/pkg/scheduler/scheduler.go
index 5d4915c9..f749fa66 100644
--- a/server/pkg/scheduler/scheduler.go
+++ b/server/pkg/scheduler/scheduler.go
@@ -1,7 +1,6 @@
package scheduler
import (
- "mayfly-go/pkg/biz"
"mayfly-go/pkg/logx"
"sync"
@@ -25,14 +24,14 @@ func Stop() {
cronService.Stop()
}
-// 根据任务id移除
+// Remove 根据任务id移除
func Remove(id cron.EntryID) {
cronService.Remove(id)
}
-// 根据任务key移除
+// RemoveByKey 根据任务key移除
func RemoveByKey(key string) {
- logx.Debugf("移除cron任务 => [key = %s]", key)
+ logx.Debugf("remove cron func => [key = %s]", key)
id, ok := key2IdMap.Load(key)
if ok {
Remove(id.(cron.EntryID))
@@ -44,18 +43,21 @@ func GetCron() *cron.Cron {
return cronService
}
-// 添加任务
-func AddFun(spec string, cmd func()) cron.EntryID {
- id, err := cronService.AddFunc(spec, cmd)
- biz.ErrIsNilAppendErr(err, "添加任务失败: %s")
- return id
+// AddFun 添加任务
+func AddFun(spec string, cmd func()) (cron.EntryID, error) {
+ return cronService.AddFunc(spec, cmd)
}
-// 根据key添加定时任务
-func AddFunByKey(key, spec string, cmd func()) {
- logx.Debugf("添加cron任务 => [key = %s]", key)
+// AddFunByKey 根据key添加定时任务
+func AddFunByKey(key, spec string, cmd func()) error {
+ logx.Debugf("add cron func => [key = %s]", key)
RemoveByKey(key)
- key2IdMap.Store(key, AddFun(spec, cmd))
+ id, err := AddFun(spec, cmd)
+ if err != nil {
+ return err
+ }
+ key2IdMap.Store(key, id)
+ return nil
}
func ExistKey(key string) bool {
diff --git a/server/resources/script/sql/mayfly-go.sql b/server/resources/script/sql/mayfly-go.sql
index 6a17184d..4f86ff97 100644
--- a/server/resources/script/sql/mayfly-go.sql
+++ b/server/resources/script/sql/mayfly-go.sql
@@ -764,7 +764,6 @@ INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`,
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(27, 5, 'Xlqig32x/UGxla231/JExq23XK/', 2, 1, 'menu.menuPermissionEdit', 'resource:update', 30000000, 'null', 1, 'admin', 1, 'admin', '2021-05-31 18:04:03', '2024-11-07 14:04:10', 0, NULL);
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(28, 5, 'Xlqig32x/UGxla231/Elex13XK/', 2, 1, 'menu.menuPermissionEnableDisable', 'resource:changeStatus', 40000000, 'null', 1, 'admin', 1, 'admin', '2021-05-31 18:04:33', '2024-11-07 14:04:53', 0, NULL);
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(29, 14, 'Xlqig32x/sfslfel/xlawx2xA/', 2, 1, 'menu.accountAdd', 'account:add', 19999999, 'null', 1, 'admin', 1, 'admin', '2021-05-31 19:23:42', '2024-11-07 14:11:46', 0, NULL);
-INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(30, 14, 'Xlqig32x/sfslfel/32xax2xA/', 2, 1, 'menu.accountEdit', 'account:update', 19999999, 'null', 1, 'admin', 1, 'admin', '2021-05-31 19:23:58', '2024-11-07 14:11:56', 0, NULL);
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(31, 14, 'Xlqig32x/sfslfel/eubale13/', 2, 1, 'menu.accountBase', 'account', 9999999, 'null', 1, 'admin', 1, 'admin', '2021-05-31 21:25:06', '2024-11-07 14:11:27', 0, NULL);
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(32, 5, 'Xlqig32x/UGxla231/321q23XK/', 2, 1, 'menu.menuPermissionBase', 'resource', 9999999, 'null', 1, 'admin', 1, 'admin', '2021-05-31 21:25:25', '2024-11-07 14:03:59', 0, NULL);
INSERT INTO `t_sys_resource` (`id`, `pid`, `ui_path`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`, `is_deleted`, `delete_time`) values(33, 11, 'Xlqig32x/lxqSiae1/908xKxq3/', 2, 1, 'menu.roleBase', 'role', 9999999, 'null', 1, 'admin', 1, 'admin', '2021-05-31 21:25:40', '2024-11-07 14:13:03', 0, NULL);