更新2.1.2版本,优化部门、角色权限,增加上下级关系;增加登录、系统、短信日志;优化省市区编码

This commit is contained in:
孟帅
2023-01-25 11:49:21 +08:00
parent 11fad0132d
commit 93e0fe7250
190 changed files with 35896 additions and 7208 deletions

View File

@@ -20,21 +20,17 @@ import (
"sync"
)
var (
// 添加新的任务时只需实现cronStrategy接口并加入到cronList即可
cronList = []cronStrategy{
Test, // 测试无参任务
Test2, // 测试有参任务
Monitor, // 监控
}
inst = new(tasks)
)
type cronStrategy interface {
GetName() string
Execute(ctx context.Context)
}
var (
// 添加新的任务时只需实现cronStrategy接口并加入到cronList即可
cronList []cronStrategy
inst = new(tasks)
)
type tasks struct {
list []*TaskItem
sync.RWMutex
@@ -49,7 +45,7 @@ type TaskItem struct {
Count int // 执行次数仅Policy=4时有效
}
func init() {
func LoadCronList() {
for _, cron := range cronList {
inst.Add(&TaskItem{
Name: cron.GetName(),
@@ -66,6 +62,10 @@ func StopALL() {
// StartALL 启动任务
func StartALL(sysCron []*entity.SysCron) error {
if len(inst.list) == 0 {
LoadCronList()
}
var (
err error
ct = gctx.New()
@@ -86,7 +86,7 @@ func StartALL(sysCron []*entity.SysCron) error {
if gcron.Search(cron.Name) == nil {
var (
t *gcron.Entry
ctx = context.WithValue(gctx.New(), consts.CronArgsKey, strings.Split(cron.Params, consts.CronSplitStr))
ctx = context.WithValue(gctx.New(), consts.ContextKeyCronArgs, strings.Split(cron.Params, consts.CronSplitStr))
)
switch cron.Policy {
case consts.CronPolicySame:
@@ -130,7 +130,7 @@ func StartALL(sysCron []*entity.SysCron) error {
}
}
g.Log().Debug(ct, "load scheduled task complete..")
g.Log().Debug(ct, "load cron success..")
return nil
}
@@ -140,8 +140,15 @@ func Stop(sysCron *entity.SysCron) error {
}
// Once 立即执行一次某个任务
func Once(sysCron *entity.SysCron) error {
return nil
func Once(ctx context.Context, sysCron *entity.SysCron) error {
for _, v := range cronList {
if v.GetName() == sysCron.Name {
go v.Execute(ctx)
return nil
}
}
return gerror.Newf("定时任务不存在:%+v", sysCron.Name)
}
// Delete 删除任务

View File

@@ -18,6 +18,10 @@ import (
"sync"
)
func init() {
cronList = append(cronList, Monitor)
}
// Monitor 监控
var Monitor = &cMonitor{name: "monitor"}

View File

@@ -12,6 +12,10 @@ import (
"time"
)
func init() {
cronList = append(cronList, Test)
}
// Test 测试任务
var Test = &cTest{name: "test"}

View File

@@ -13,6 +13,10 @@ import (
"time"
)
func init() {
cronList = append(cronList, Test2)
}
// Test2 测试2任务
var Test2 = &cTest2{name: "test2"}
@@ -26,7 +30,7 @@ func (c *cTest2) GetName() string {
// Execute 执行任务
func (c *cTest2) Execute(ctx context.Context) {
args, ok := ctx.Value(consts.CronArgsKey).([]string)
args, ok := ctx.Value(consts.ContextKeyCronArgs).([]string)
if !ok {
g.Log().Warning(ctx, "参数解析失败!")
return