mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
fix: i18n特殊字符调整
This commit is contained in:
@@ -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接口, 根据类型进行注入
|
||||
|
||||
@@ -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 // 模型实例
|
||||
|
||||
@@ -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...))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user