获取任务输出文件

This commit is contained in:
Mr.Li 2023-04-21 14:41:11 +08:00
parent e43f4cb3fa
commit 1b82eee4cd
1 changed files with 19 additions and 3 deletions

View File

@ -56,6 +56,22 @@ func (s System) GetJob(name string) (Job, error) {
return Job{}, errors.New("没有找到相关配置:" + name) return Job{}, errors.New("没有找到相关配置:" + name)
} }
func (j Job) GetFileName(params map[string]interface{}) string {
m := regexp.MustCompile("({[a-zA-Z0-9]+})")
name := m.ReplaceAllFunc([]byte(j.File), func(b []byte) []byte {
field := string(b[1 : len(b)-1])
if val, ok := params[field]; ok {
return []byte(toString(val, false))
}
return b
})
return string(name)
}
func (t Task) GetSql(params map[string]interface{}) string { func (t Task) GetSql(params map[string]interface{}) string {
sql := t.Sql sql := t.Sql
@ -65,7 +81,7 @@ func (t Task) GetSql(params map[string]interface{}) string {
field := string(b[1 : len(b)-1]) field := string(b[1 : len(b)-1])
if val, ok := params[field]; ok { if val, ok := params[field]; ok {
return []byte(t.getParam(val)) return []byte(toString(val, t.Timestamp))
} }
return b return b
}) })
@ -80,10 +96,10 @@ func (t Task) GetSql(params map[string]interface{}) string {
return sql return sql
} }
func (t Task) getParam(parm interface{}) string { func toString(parm interface{}, timestamp bool) string {
switch p := parm.(type) { switch p := parm.(type) {
case time.Time: case time.Time:
if t.Timestamp { if timestamp {
return strconv.FormatInt(p.Unix(), 10) return strconv.FormatInt(p.Unix(), 10)
} else { } else {
return p.Format("2006-01-02 15:04:05") return p.Format("2006-01-02 15:04:05")