提交 1e052455 authored 作者: mooncake's avatar mooncake

rename package

上级 55ac0e28
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos" "gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
goutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/goutils" goutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/goutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
...@@ -54,7 +54,7 @@ func init() { ...@@ -54,7 +54,7 @@ func init() {
} }
func parseInit() { func parseInit() {
if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceUtils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok { if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceutils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok {
return return
} }
if err := config.ParseConf(); err != nil { if err := config.ParseConf(); err != nil {
......
...@@ -3,14 +3,15 @@ package config ...@@ -3,14 +3,15 @@ package config
import ( import (
"bytes" "bytes"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/hashUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/hashutils"
) )
type ConsulConfFetcher struct { type ConsulConfFetcher struct {
...@@ -52,7 +53,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher { ...@@ -52,7 +53,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher {
x.err = xerror.New("[consul]请先配置consul") x.err = xerror.New("[consul]请先配置consul")
return x return x
} }
if hashUtils.Md5(kv.Value) != hashUtils.Md5(x.cfg.GetContent()) { if hashutils.Md5(kv.Value) != hashutils.Md5(x.cfg.GetContent()) {
x.count++ x.count++
x.isNew = true x.isNew = true
x.cfg.SetContent(kv.Value) x.cfg.SetContent(kv.Value)
......
...@@ -3,7 +3,7 @@ package database ...@@ -3,7 +3,7 @@ package database
import ( import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
...@@ -25,7 +25,7 @@ func InitMysql(dbConfig *config.Database) (*sgorm.DB, error) { ...@@ -25,7 +25,7 @@ func InitMysql(dbConfig *config.Database) (*sgorm.DB, error) {
if dbConfig.Mysql.EnableLog { if dbConfig.Mysql.EnableLog {
opts = append(opts, opts = append(opts,
mysql.WithLogging(logger.Get()), mysql.WithLogging(logger.Get()),
mysql.WithLogRequestIDKey(ctxUtils.ContextTraceIDKey), mysql.WithLogRequestIDKey(ctxutils.ContextTraceIDKey),
) )
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
) )
...@@ -102,8 +102,8 @@ func Auth(opts ...JwtOption) gin.HandlerFunc { ...@@ -102,8 +102,8 @@ func Auth(opts ...JwtOption) gin.HandlerFunc {
} }
} else { } else {
xsfID, _ := xsf.ParseString(claims.UID) xsfID, _ := xsf.ParseString(claims.UID)
c.Set(ctxUtils.KeyUID, xsfID) c.Set(ctxutils.KeyUID, xsfID)
c.Set(ctxUtils.KeyUName, claims.Name) c.Set(ctxutils.KeyUName, claims.Name)
} }
c.Next() c.Next()
...@@ -130,7 +130,7 @@ func HeaderFields(keys []string) gin.HandlerFunc { ...@@ -130,7 +130,7 @@ func HeaderFields(keys []string) gin.HandlerFunc {
c.Set(key, c.Request.Header.Get(key)) c.Set(key, c.Request.Header.Get(key))
kv[key] = c.Request.Header.Get(key) kv[key] = c.Request.Header.Get(key)
} }
logger.Info("[middleware][headerFields]header kvs", logger.Any("kv", kv), ctxUtils.GinTraceIDField(c)) logger.Info("[middleware][headerFields]header kvs", logger.Any("kv", kv), ctxutils.GinTraceIDField(c))
} }
} }
......
...@@ -8,9 +8,9 @@ import ( ...@@ -8,9 +8,9 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -206,19 +206,19 @@ func Logging(opts ...Option) gin.HandlerFunc { ...@@ -206,19 +206,19 @@ func Logging(opts ...Option) gin.HandlerFunc {
entity.SetCopyReq(c, buf) entity.SetCopyReq(c, buf)
c.Set(ctxUtils.KeyAppName, o.appName) c.Set(ctxutils.KeyAppName, o.appName)
reqID := "" reqID := ""
if o.traceIDFrom == 1 { if o.traceIDFrom == 1 {
if v, isExist := c.Get(ctxUtils.ContextTraceIDKey); isExist { if v, isExist := c.Get(ctxutils.ContextTraceIDKey); isExist {
if requestID, ok := v.(string); ok { if requestID, ok := v.(string); ok {
reqID = requestID reqID = requestID
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID)) fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
} }
} }
} else if o.traceIDFrom == 2 { } else if o.traceIDFrom == 2 {
reqID = c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey) reqID = c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID)) fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
} }
o.log.Info("[middleware][logging]<<<<<<<<<req", fields...) o.log.Info("[middleware][logging]<<<<<<<<<req", fields...)
...@@ -229,12 +229,12 @@ func Logging(opts ...Option) gin.HandlerFunc { ...@@ -229,12 +229,12 @@ func Logging(opts ...Option) gin.HandlerFunc {
c.Writer = newWriter c.Writer = newWriter
ip := ips.GetClientIP(c) ip := ips.GetClientIP(c)
c.Set(ctxUtils.KeyClientIP, ip) c.Set(ctxutils.KeyClientIP, ip)
// processing requests // processing requests
c.Next() c.Next()
rspBodyMax := c.GetInt(ctxUtils.KeyRspBodyMax) rspBodyMax := c.GetInt(ctxutils.KeyRspBodyMax)
contentType := c.Writer.Header().Get("Content-Type") contentType := c.Writer.Header().Get("Content-Type")
isMedia := false isMedia := false
if strings.Contains(contentType, "image") { if strings.Contains(contentType, "image") {
...@@ -260,7 +260,7 @@ func Logging(opts ...Option) gin.HandlerFunc { ...@@ -260,7 +260,7 @@ func Logging(opts ...Option) gin.HandlerFunc {
} }
} }
if reqID != "" { if reqID != "" {
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID)) fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
} }
o.log.Info("[middleware][logging]>>>>>>>>>rsp", fields...) o.log.Info("[middleware][logging]>>>>>>>>>rsp", fields...)
...@@ -285,13 +285,13 @@ func SimpleLog(opts ...Option) gin.HandlerFunc { ...@@ -285,13 +285,13 @@ func SimpleLog(opts ...Option) gin.HandlerFunc {
reqID := "" reqID := ""
switch o.traceIDFrom { switch o.traceIDFrom {
case 1: case 1:
if v, isExist := c.Get(ctxUtils.ContextTraceIDKey); isExist { if v, isExist := c.Get(ctxutils.ContextTraceIDKey); isExist {
if requestID, ok := v.(string); ok { if requestID, ok := v.(string); ok {
reqID = requestID reqID = requestID
} }
} }
case 2: case 2:
reqID = c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey) reqID = c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
} }
// processing requests // processing requests
...@@ -306,7 +306,7 @@ func SimpleLog(opts ...Option) gin.HandlerFunc { ...@@ -306,7 +306,7 @@ func SimpleLog(opts ...Option) gin.HandlerFunc {
zap.Int("size", c.Writer.Size()), zap.Int("size", c.Writer.Size()),
} }
if reqID != "" { if reqID != "" {
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID)) fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
} }
o.log.Info("[middleware][logging]]>>>>>>>>>rsp", fields...) o.log.Info("[middleware][logging]]>>>>>>>>>rsp", fields...)
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
func init() { func init() {
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
var ( var (
...@@ -48,7 +48,7 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli ...@@ -48,7 +48,7 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli
}) })
return func(c *gin.Context) { return func(c *gin.Context) {
clientIP := ips.GetClientIP(c) clientIP := ips.GetClientIP(c)
ctx := ctxUtils.WrapCtx(c) ctx := ctxutils.WrapCtx(c)
if redisIPRateLimiter.Allow(ctx, clientIP) { if redisIPRateLimiter.Allow(ctx, clientIP) {
c.Next() c.Next()
} else { } else {
...@@ -58,5 +58,5 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli ...@@ -58,5 +58,5 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli
} }
func Fail(c *gin.Context, code int, msg string, data ...any) { func Fail(c *gin.Context, code int, msg string, data ...any) {
c.AbortWithStatusJSON(http.StatusOK, response.Result{Code: code, Msg: msg, Data: nil, TimeStamp: time.Now().Unix(), TraceID: ctxUtils.GetGinCtxTid(c)}) c.AbortWithStatusJSON(http.StatusOK, response.Result{Code: code, Msg: msg, Data: nil, TimeStamp: time.Now().Unix(), TraceID: ctxutils.GetGinCtxTid(c)})
} }
...@@ -3,7 +3,7 @@ package middleware ...@@ -3,7 +3,7 @@ package middleware
import ( import (
"net/http" "net/http"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
......
...@@ -2,11 +2,12 @@ package middleware ...@@ -2,11 +2,12 @@ package middleware
import ( import (
"context" "context"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"go.uber.org/zap"
"net/http" "net/http"
"time" "time"
"github.com/gin-gonic/gin"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"go.uber.org/zap"
) )
// RequestIDOption set the request id options. // RequestIDOption set the request id options.
...@@ -20,8 +21,8 @@ type requestIDOptions struct { ...@@ -20,8 +21,8 @@ type requestIDOptions struct {
func defaultRequestIDOptions() *requestIDOptions { func defaultRequestIDOptions() *requestIDOptions {
return &requestIDOptions{ return &requestIDOptions{
contextRequestIDKey: ctxUtils.ContextTraceIDKey, contextRequestIDKey: ctxutils.ContextTraceIDKey,
headerXRequestIDKey: ctxUtils.HeaderXRequestIDKey, headerXRequestIDKey: ctxutils.HeaderXRequestIDKey,
} }
} }
...@@ -32,11 +33,11 @@ func (o *requestIDOptions) apply(opts ...RequestIDOption) { ...@@ -32,11 +33,11 @@ func (o *requestIDOptions) apply(opts ...RequestIDOption) {
} }
func (o *requestIDOptions) setRequestIDKey() { func (o *requestIDOptions) setRequestIDKey() {
if o.contextRequestIDKey != ctxUtils.ContextTraceIDKey { if o.contextRequestIDKey != ctxutils.ContextTraceIDKey {
ctxUtils.ContextTraceIDKey = o.contextRequestIDKey ctxutils.ContextTraceIDKey = o.contextRequestIDKey
} }
if o.headerXRequestIDKey != ctxUtils.HeaderXRequestIDKey { if o.headerXRequestIDKey != ctxutils.HeaderXRequestIDKey {
ctxUtils.HeaderXRequestIDKey = o.headerXRequestIDKey ctxutils.HeaderXRequestIDKey = o.headerXRequestIDKey
} }
} }
...@@ -64,7 +65,7 @@ func WithHeaderRequestIDKey(key string) RequestIDOption { ...@@ -64,7 +65,7 @@ func WithHeaderRequestIDKey(key string) RequestIDOption {
type CtxKeyString string type CtxKeyString string
// RequestIDKey request_id // RequestIDKey request_id
var RequestIDKey = CtxKeyString(ctxUtils.ContextTraceIDKey) var RequestIDKey = CtxKeyString(ctxutils.ContextTraceIDKey)
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
...@@ -76,21 +77,21 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc { ...@@ -76,21 +77,21 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc {
o.setRequestIDKey() o.setRequestIDKey()
return func(c *gin.Context) { return func(c *gin.Context) {
requestID := c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey) requestID := c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
// Create request id // Create request id
if requestID == "" { if requestID == "" {
requestID = ctxUtils.GenerateTid() requestID = ctxutils.GenerateTid()
c.Request.Header.Set(ctxUtils.HeaderXRequestIDKey, requestID) c.Request.Header.Set(ctxutils.HeaderXRequestIDKey, requestID)
} }
st := time.Now() st := time.Now()
// Expose it for use in the application // Expose it for use in the application
c.Set(ctxUtils.ContextTraceIDKey, requestID) c.Set(ctxutils.ContextTraceIDKey, requestID)
c.Set(ctxUtils.KeyApiStartTime, st) c.Set(ctxutils.KeyApiStartTime, st)
// Set X-Request-Id header // Set X-Request-Id header
c.Writer.Header().Set(ctxUtils.HeaderXRequestIDKey, requestID) c.Writer.Header().Set(ctxutils.HeaderXRequestIDKey, requestID)
c.Next() c.Next()
} }
...@@ -98,12 +99,12 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc { ...@@ -98,12 +99,12 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc {
// HeaderRequestID get request id from the header // HeaderRequestID get request id from the header
func HeaderRequestID(c *gin.Context) string { func HeaderRequestID(c *gin.Context) string {
return c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey) return c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
} }
// HeaderRequestIDField get request id field from header // HeaderRequestIDField get request id field from header
func HeaderRequestIDField(c *gin.Context) zap.Field { func HeaderRequestIDField(c *gin.Context) zap.Field {
return zap.String(ctxUtils.HeaderXRequestIDKey, HeaderRequestID(c)) return zap.String(ctxutils.HeaderXRequestIDKey, HeaderRequestID(c))
} }
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
...@@ -115,7 +116,7 @@ var RequestHeaderKey = "request_header_key" ...@@ -115,7 +116,7 @@ var RequestHeaderKey = "request_header_key"
func AdaptCtx(ctx context.Context) (*gin.Context, context.Context) { func AdaptCtx(ctx context.Context) (*gin.Context, context.Context) {
c, ok := ctx.(*gin.Context) c, ok := ctx.(*gin.Context)
if ok { if ok {
ctx = ctxUtils.WrapCtx(c) ctx = ctxutils.WrapCtx(c)
} }
return c, ctx return c, ctx
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"go.uber.org/zap" "go.uber.org/zap"
) )
...@@ -29,13 +29,13 @@ func (d *RedisDatastore) Add(ctx context.Context, key string, start, value int64 ...@@ -29,13 +29,13 @@ func (d *RedisDatastore) Add(ctx context.Context, key string, start, value int64
c, err := d.client.IncrBy(ctx, k, value).Result() c, err := d.client.IncrBy(ctx, k, value).Result()
if err != nil { if err != nil {
if d.logger != nil { if d.logger != nil {
d.logger.Error(fmt.Sprintf("[SlideWindow] add fail,[k:%s add:%d]", k, value), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx)) d.logger.Error(fmt.Sprintf("[SlideWindow] add fail,[k:%s add:%d]", k, value), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
} }
return 0, err return 0, err
} }
_, _ = d.client.Expire(ctx, k, d.ttl).Result() _, _ = d.client.Expire(ctx, k, d.ttl).Result()
if d.logger != nil { if d.logger != nil {
d.logger.Info(fmt.Sprintf("[SlideWindow] add success,[k:%s add:%d -> %d]", k, value, c), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx)) d.logger.Info(fmt.Sprintf("[SlideWindow] add success,[k:%s add:%d -> %d]", k, value, c), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
} }
return c, err return c, err
} }
...@@ -49,12 +49,12 @@ func (d *RedisDatastore) Get(ctx context.Context, key string, start int64) (int6 ...@@ -49,12 +49,12 @@ func (d *RedisDatastore) Get(ctx context.Context, key string, start int64) (int6
err = nil err = nil
} }
if d.logger != nil { if d.logger != nil {
d.logger.Error(fmt.Sprintf("[SlideWindow] get fail [k:%s]", k), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx)) d.logger.Error(fmt.Sprintf("[SlideWindow] get fail [k:%s]", k), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
} }
return 0, err return 0, err
} }
if d.logger != nil { if d.logger != nil {
d.logger.Info(fmt.Sprintf("[SlideWindow] get success [k:%s v:%s]", k, value), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx)) d.logger.Info(fmt.Sprintf("[SlideWindow] get success [k:%s v:%s]", k, value), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
} }
return strconv.ParseInt(value, 10, 64) return strconv.ParseInt(value, 10, 64)
} }
......
...@@ -10,13 +10,13 @@ import ( ...@@ -10,13 +10,13 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
) )
const CustomErrorCode = 0 const CustomErrorCode = 0
...@@ -63,7 +63,7 @@ func newResp(c *gin.Context, code int, msg string, data interface{}) *Result { ...@@ -63,7 +63,7 @@ func newResp(c *gin.Context, code int, msg string, data interface{}) *Result {
Code: code, Code: code,
Msg: msg, Msg: msg,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
TraceID: ctxUtils.GetGinCtxTid(c), TraceID: ctxutils.GetGinCtxTid(c),
} }
// ensure that the data field is not nil on return, note that it is not nil when resp.data=[]interface {}, it is serialized to null // ensure that the data field is not nil on return, note that it is not nil when resp.data=[]interface {}, it is serialized to null
...@@ -173,10 +173,10 @@ func Out(c *gin.Context, err *errcode.Error, data ...interface{}) { ...@@ -173,10 +173,10 @@ func Out(c *gin.Context, err *errcode.Error, data ...interface{}) {
// status code flat 200, custom error codes in data.code // status code flat 200, custom error codes in data.code
func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{}) { func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{}) {
c.Writer.Header().Set(ctxUtils.HeaderXTimestampKey, strconv.FormatInt(time.Now().Unix(), 10)) c.Writer.Header().Set(ctxutils.HeaderXTimestampKey, strconv.FormatInt(time.Now().Unix(), 10))
appName := c.GetString(ctxUtils.KeyAppName) appName := c.GetString(ctxutils.KeyAppName)
stTime := c.GetTime(ctxUtils.KeyApiStartTime) stTime := c.GetTime(ctxutils.KeyApiStartTime)
ctxUtils.AddApiCost(c, appName, stTime) ctxutils.AddApiCost(c, appName, stTime)
if len(data) > 0 { if len(data) > 0 {
writeJSON(c, http.StatusOK, newResp(c, code, msg, data[0])) writeJSON(c, http.StatusOK, newResp(c, code, msg, data[0]))
...@@ -188,7 +188,7 @@ func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{}) ...@@ -188,7 +188,7 @@ func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{})
// Success return success // Success return success
func Success(c *gin.Context, data ...interface{}) { func Success(c *gin.Context, data ...interface{}) {
c.Set(ctxUtils.KeyRspCode, 1) c.Set(ctxutils.KeyRspCode, 1)
respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), data...) respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), data...)
} }
...@@ -207,7 +207,7 @@ func Success(c *gin.Context, data ...interface{}) { ...@@ -207,7 +207,7 @@ func Success(c *gin.Context, data ...interface{}) {
// if total%int64(pageSize) > 0 { // if total%int64(pageSize) > 0 {
// totalPage = totalPage + 1 // totalPage = totalPage + 1
// } // }
// c.Set(ctxUtils.KeyRspCode, 1) // c.Set(ctxutils.KeyRspCode, 1)
// if list == nil { // if list == nil {
// list = []*T{} // list = []*T{}
// } // }
...@@ -221,7 +221,7 @@ func Success(c *gin.Context, data ...interface{}) { ...@@ -221,7 +221,7 @@ func Success(c *gin.Context, data ...interface{}) {
func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) { func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
pageIndex := 1 pageIndex := 1
pageSize := 10 pageSize := 10
if req, ok := c.Get(ctxUtils.KeyPagination); ok { if req, ok := c.Get(ctxutils.KeyPagination); ok {
if pagination, ok := req.(query.Pagination); ok { if pagination, ok := req.(query.Pagination); ok {
pageIndex = pagination.PageIndex pageIndex = pagination.PageIndex
if pagination.PageSize > 0 { if pagination.PageSize > 0 {
...@@ -233,7 +233,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) { ...@@ -233,7 +233,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
if total%int64(pageSize) > 0 { if total%int64(pageSize) > 0 {
pageTotal = pageTotal + 1 pageTotal = pageTotal + 1
} }
c.Set(ctxUtils.KeyRspCode, 1) c.Set(ctxutils.KeyRspCode, 1)
if list == nil { if list == nil {
list = []*T{} list = []*T{}
} }
...@@ -244,7 +244,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) { ...@@ -244,7 +244,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
// SuccessWithList return success // SuccessWithList return success
func SuccessWithList[T any](c *gin.Context, list []*T) { func SuccessWithList[T any](c *gin.Context, list []*T) {
c.Set(ctxUtils.KeyRspCode, 1) c.Set(ctxutils.KeyRspCode, 1)
if list == nil { if list == nil {
list = []*T{} list = []*T{}
} }
...@@ -253,24 +253,24 @@ func SuccessWithList[T any](c *gin.Context, list []*T) { ...@@ -253,24 +253,24 @@ func SuccessWithList[T any](c *gin.Context, list []*T) {
// ErrorE return error // ErrorE return error
func ErrorE(c *gin.Context, err *errcode.Error, data ...interface{}) { func ErrorE(c *gin.Context, err *errcode.Error, data ...interface{}) {
c.Set(ctxUtils.KeyRspCode, 0) c.Set(ctxutils.KeyRspCode, 0)
respJSONWith200(c, err.Code(), err.Msg(), data...) respJSONWith200(c, err.Code(), err.Msg(), data...)
} }
func Error(c *gin.Context, err error) { func Error(c *gin.Context, err error) {
c.Set(ctxUtils.KeyRspCode, 0) c.Set(ctxutils.KeyRspCode, 0)
msg := "" msg := ""
if err != nil { if err != nil {
msg = err.Error() msg = err.Error()
if e, ok := err.(*xerror.Error); ok { if e, ok := err.(*xerror.Error); ok {
//if !errcode.IsSysDefinedError(xerr.Code()) { //if !errcode.IsSysDefinedError(xerr.Code()) {
// logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c)) // logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
//} //}
if e.Code() != errcode.InvalidParams.Code() { if e.Code() != errcode.InvalidParams.Code() {
logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c)) logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
} }
} else { } else {
logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c)) logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
} }
} }
respJSONWith200(c, CustomErrorCode, msg) respJSONWith200(c, CustomErrorCode, msg)
......
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/text" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/text"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/webLogUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/weblogutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron" "gitlab.wanzhuangkj.com/tush/xpkg/xcron"
) )
...@@ -122,7 +122,7 @@ func New() *gin.Engine { ...@@ -122,7 +122,7 @@ func New() *gin.Engine {
binding.Validator = validator.Init() binding.Validator = validator.Init()
// r.Use(xvalidator.Translation()) // r.Use(xvalidator.Translation())
webLogUtils.Init() weblogutils.Init()
if config.IsNotProd() { if config.IsNotProd() {
r.GET(consts.RootRoute+"/config", gin.WrapF(errcode.ShowConfig([]byte(config.Show())))) r.GET(consts.RootRoute+"/config", gin.WrapF(errcode.ShowConfig([]byte(config.Show()))))
......
...@@ -58,7 +58,6 @@ require ( ...@@ -58,7 +58,6 @@ require (
require ( require (
github.com/bwmarrin/snowflake v0.3.0 github.com/bwmarrin/snowflake v0.3.0
github.com/bytedance/go-tagexpr/v2 v2.9.11 github.com/bytedance/go-tagexpr/v2 v2.9.11
github.com/duke-git/lancet/v2 v2.3.4
github.com/go-redsync/redsync/v4 v4.13.0 github.com/go-redsync/redsync/v4 v4.13.0
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/hashicorp/consul/api v1.12.0 github.com/hashicorp/consul/api v1.12.0
......
...@@ -122,8 +122,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC ...@@ -122,8 +122,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/duke-git/lancet/v2 v2.3.4 h1:8XGI7P9w+/GqmEBEXYaH/XuNiM0f4/90Ioti0IvYJls=
github.com/duke-git/lancet/v2 v2.3.4/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
......
...@@ -13,8 +13,8 @@ import ( ...@@ -13,8 +13,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
) )
type memoryCache struct { type memoryCache struct {
......
...@@ -2,8 +2,8 @@ package biz ...@@ -2,8 +2,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -16,10 +16,10 @@ type Email struct { ...@@ -16,10 +16,10 @@ type Email struct {
var EmailTool = &Email{} var EmailTool = &Email{}
func (*Email) GetIDs(rs []*Email) []xsf.ID { func (*Email) GetIDs(rs []*Email) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (x *Email) GetTplIDs(rs []*Email) []xsf.ID { func (x *Email) GetTplIDs(rs []*Email) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetTplID()) set.Add(r.GetTplID())
} }
......
...@@ -2,8 +2,8 @@ package biz ...@@ -2,8 +2,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -16,10 +16,10 @@ type EmailReceiver struct { ...@@ -16,10 +16,10 @@ type EmailReceiver struct {
var EmailReceiverTool = &EmailReceiver{} var EmailReceiverTool = &EmailReceiver{}
func (*EmailReceiver) GetIDs(rs []*EmailReceiver) []xsf.ID { func (*EmailReceiver) GetIDs(rs []*EmailReceiver) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID { func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailID()) set.Add(r.GetEmailID())
} }
......
...@@ -2,8 +2,8 @@ package biz ...@@ -2,8 +2,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -16,10 +16,10 @@ type EmailSend struct { ...@@ -16,10 +16,10 @@ type EmailSend struct {
var EmailSendTool = &EmailSend{} var EmailSendTool = &EmailSend{}
func (*EmailSend) GetIDs(rs []*EmailSend) []xsf.ID { func (*EmailSend) GetIDs(rs []*EmailSend) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID { func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailID()) set.Add(r.GetEmailID())
} }
......
...@@ -2,8 +2,8 @@ package biz ...@@ -2,8 +2,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -16,10 +16,10 @@ type EmailSendLog struct { ...@@ -16,10 +16,10 @@ type EmailSendLog struct {
var EmailSendLogTool = &EmailSendLog{} var EmailSendLogTool = &EmailSendLog{}
func (*EmailSendLog) GetIDs(rs []*EmailSendLog) []xsf.ID { func (*EmailSendLog) GetIDs(rs []*EmailSendLog) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID { func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailSendID()) set.Add(r.GetEmailSendID())
} }
......
...@@ -2,7 +2,7 @@ package biz ...@@ -2,7 +2,7 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -15,7 +15,7 @@ type EmailTpl struct { ...@@ -15,7 +15,7 @@ type EmailTpl struct {
var EmailTplTool = &EmailTpl{} var EmailTplTool = &EmailTpl{}
func (*EmailTpl) GetIDs(rs []*EmailTpl) []xsf.ID { func (*EmailTpl) GetIDs(rs []*EmailTpl) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (EmailTpl) NewFromModel(m *models.EmailTpl) *EmailTpl { func (EmailTpl) NewFromModel(m *models.EmailTpl) *EmailTpl {
......
...@@ -2,8 +2,8 @@ package biz ...@@ -2,8 +2,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -16,10 +16,10 @@ type EmailTplReceiver struct { ...@@ -16,10 +16,10 @@ type EmailTplReceiver struct {
var EmailTplReceiverTool = &EmailTplReceiver{} var EmailTplReceiverTool = &EmailTplReceiver{}
func (*EmailTplReceiver) GetIDs(rs []*EmailTplReceiver) []xsf.ID { func (*EmailTplReceiver) GetIDs(rs []*EmailTplReceiver) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs) return sliceutils.GetIDs[xsf.ID](rs)
} }
func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID { func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetTplID()) set.Add(r.GetTplID())
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -52,7 +52,7 @@ func (x *emailController) UpdateByID(c *gin.Context) { ...@@ -52,7 +52,7 @@ func (x *emailController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -75,7 +75,7 @@ func (x *emailController) GetByID(c *gin.Context) { ...@@ -75,7 +75,7 @@ func (x *emailController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
email, err := service.EmailService.GetByID(ctxUtils.WrapCtx(c), in.ID) email, err := service.EmailService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -89,7 +89,7 @@ func (x *emailController) GetByIDs(c *gin.Context) { ...@@ -89,7 +89,7 @@ func (x *emailController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emails, err := service.EmailService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emails, err := service.EmailService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -115,7 +115,7 @@ func (x *emailController) Page(c *gin.Context) { ...@@ -115,7 +115,7 @@ func (x *emailController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emails, total, err := service.EmailService.Page(ctxUtils.WrapCtx(c), in) emails, total, err := service.EmailService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -141,7 +141,7 @@ func (x *emailController) ExportCSV(c *gin.Context) { ...@@ -141,7 +141,7 @@ func (x *emailController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailReceiverController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailReceiverController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailReceiverService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailReceiverService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailReceiverController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailReceiverController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailReceiverService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailReceiverService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -52,7 +52,7 @@ func (x *emailReceiverController) UpdateByID(c *gin.Context) { ...@@ -52,7 +52,7 @@ func (x *emailReceiverController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailReceiverService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailReceiverService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -75,7 +75,7 @@ func (x *emailReceiverController) GetByID(c *gin.Context) { ...@@ -75,7 +75,7 @@ func (x *emailReceiverController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailReceiver, err := service.EmailReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID) emailReceiver, err := service.EmailReceiverService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -89,7 +89,7 @@ func (x *emailReceiverController) GetByIDs(c *gin.Context) { ...@@ -89,7 +89,7 @@ func (x *emailReceiverController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailReceivers, err := service.EmailReceiverService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emailReceivers, err := service.EmailReceiverService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -115,7 +115,7 @@ func (x *emailReceiverController) Page(c *gin.Context) { ...@@ -115,7 +115,7 @@ func (x *emailReceiverController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailReceivers, total, err := service.EmailReceiverService.Page(ctxUtils.WrapCtx(c), in) emailReceivers, total, err := service.EmailReceiverService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -141,7 +141,7 @@ func (x *emailReceiverController) ExportCSV(c *gin.Context) { ...@@ -141,7 +141,7 @@ func (x *emailReceiverController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailReceiverService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailReceiverService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailSendController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailSendController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailSendService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailSendService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailSendController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailSendController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailSendService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailSendService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -53,7 +53,7 @@ func (x *emailSendController) UpdateByID(c *gin.Context) { ...@@ -53,7 +53,7 @@ func (x *emailSendController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailSendService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailSendService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -76,7 +76,7 @@ func (x *emailSendController) GetByID(c *gin.Context) { ...@@ -76,7 +76,7 @@ func (x *emailSendController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSend, err := service.EmailSendService.GetByID(ctxUtils.WrapCtx(c), in.ID) emailSend, err := service.EmailSendService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -90,7 +90,7 @@ func (x *emailSendController) GetByIDs(c *gin.Context) { ...@@ -90,7 +90,7 @@ func (x *emailSendController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSends, err := service.EmailSendService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emailSends, err := service.EmailSendService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -116,7 +116,7 @@ func (x *emailSendController) Page(c *gin.Context) { ...@@ -116,7 +116,7 @@ func (x *emailSendController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSends, total, err := service.EmailSendService.Page(ctxUtils.WrapCtx(c), in) emailSends, total, err := service.EmailSendService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -142,7 +142,7 @@ func (x *emailSendController) ExportCSV(c *gin.Context) { ...@@ -142,7 +142,7 @@ func (x *emailSendController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailSendService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailSendService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailSendLogController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailSendLogController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailSendLogService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailSendLogService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailSendLogController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailSendLogController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailSendLogService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailSendLogService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -52,7 +52,7 @@ func (x *emailSendLogController) UpdateByID(c *gin.Context) { ...@@ -52,7 +52,7 @@ func (x *emailSendLogController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailSendLogService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailSendLogService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -75,7 +75,7 @@ func (x *emailSendLogController) GetByID(c *gin.Context) { ...@@ -75,7 +75,7 @@ func (x *emailSendLogController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSendLog, err := service.EmailSendLogService.GetByID(ctxUtils.WrapCtx(c), in.ID) emailSendLog, err := service.EmailSendLogService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -89,7 +89,7 @@ func (x *emailSendLogController) GetByIDs(c *gin.Context) { ...@@ -89,7 +89,7 @@ func (x *emailSendLogController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSendLogs, err := service.EmailSendLogService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emailSendLogs, err := service.EmailSendLogService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -115,7 +115,7 @@ func (x *emailSendLogController) Page(c *gin.Context) { ...@@ -115,7 +115,7 @@ func (x *emailSendLogController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailSendLogs, total, err := service.EmailSendLogService.Page(ctxUtils.WrapCtx(c), in) emailSendLogs, total, err := service.EmailSendLogService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -141,7 +141,7 @@ func (x *emailSendLogController) ExportCSV(c *gin.Context) { ...@@ -141,7 +141,7 @@ func (x *emailSendLogController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailSendLogService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailSendLogService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailTplController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailTplController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailTplService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailTplService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailTplController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailTplController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailTplService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailTplService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -52,7 +52,7 @@ func (x *emailTplController) UpdateByID(c *gin.Context) { ...@@ -52,7 +52,7 @@ func (x *emailTplController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailTplService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailTplService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -75,7 +75,7 @@ func (x *emailTplController) GetByID(c *gin.Context) { ...@@ -75,7 +75,7 @@ func (x *emailTplController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTpl, err := service.EmailTplService.GetByID(ctxUtils.WrapCtx(c), in.ID) emailTpl, err := service.EmailTplService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -89,7 +89,7 @@ func (x *emailTplController) GetByIDs(c *gin.Context) { ...@@ -89,7 +89,7 @@ func (x *emailTplController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTpls, err := service.EmailTplService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emailTpls, err := service.EmailTplService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -115,7 +115,7 @@ func (x *emailTplController) Page(c *gin.Context) { ...@@ -115,7 +115,7 @@ func (x *emailTplController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTpls, total, err := service.EmailTplService.Page(ctxUtils.WrapCtx(c), in) emailTpls, total, err := service.EmailTplService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -141,7 +141,7 @@ func (x *emailTplController) ExportCSV(c *gin.Context) { ...@@ -141,7 +141,7 @@ func (x *emailTplController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailTplService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailTplService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -27,7 +27,7 @@ func (x *emailTplReceiverController) Create(c *gin.Context) { ...@@ -27,7 +27,7 @@ func (x *emailTplReceiverController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.EmailTplReceiverService.Create(ctxUtils.WrapCtx(c), in) id, err := service.EmailTplReceiverService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -40,7 +40,7 @@ func (x *emailTplReceiverController) DeleteByID(c *gin.Context) { ...@@ -40,7 +40,7 @@ func (x *emailTplReceiverController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailTplReceiverService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil { if err := service.EmailTplReceiverService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -52,7 +52,7 @@ func (x *emailTplReceiverController) UpdateByID(c *gin.Context) { ...@@ -52,7 +52,7 @@ func (x *emailTplReceiverController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.EmailTplReceiverService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil { if err := service.EmailTplReceiverService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -75,7 +75,7 @@ func (x *emailTplReceiverController) GetByID(c *gin.Context) { ...@@ -75,7 +75,7 @@ func (x *emailTplReceiverController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTplReceiver, err := service.EmailTplReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID) emailTplReceiver, err := service.EmailTplReceiverService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -89,7 +89,7 @@ func (x *emailTplReceiverController) GetByIDs(c *gin.Context) { ...@@ -89,7 +89,7 @@ func (x *emailTplReceiverController) GetByIDs(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTplReceivers, err := service.EmailTplReceiverService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs) emailTplReceivers, err := service.EmailTplReceiverService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -115,7 +115,7 @@ func (x *emailTplReceiverController) Page(c *gin.Context) { ...@@ -115,7 +115,7 @@ func (x *emailTplReceiverController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
emailTplReceivers, total, err := service.EmailTplReceiverService.Page(ctxUtils.WrapCtx(c), in) emailTplReceivers, total, err := service.EmailTplReceiverService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -141,7 +141,7 @@ func (x *emailTplReceiverController) ExportCSV(c *gin.Context) { ...@@ -141,7 +141,7 @@ func (x *emailTplReceiverController) ExportCSV(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
url, err := service.EmailTplReceiverService.ExportCSV(ctxUtils.WrapCtx(c), in) url, err := service.EmailTplReceiverService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
...@@ -166,7 +166,7 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) { ...@@ -166,7 +166,7 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
from := fmt.Sprintf("%s<%s>", config.Cfg.Alias, config.Cfg.Addr) from := fmt.Sprintf("%s<%s>", config.Cfg.Alias, config.Cfg.Addr)
email := models.Email{} email := models.Email{}
email.ID = xsfUtils.EmailID(ctx) email.ID = xsfutils.EmailID(ctx)
email.TplID = et.ID email.TplID = et.ID
email.UType = in.UType email.UType = in.UType
email.UID = in.UID email.UID = in.UID
...@@ -199,12 +199,12 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) { ...@@ -199,12 +199,12 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
} }
emailSend := models.EmailSend{} emailSend := models.EmailSend{}
emailSend.ID = xsfUtils.EmailSendID(ctx) emailSend.ID = xsfutils.EmailSendID(ctx)
emailSend.EmailID = email.ID emailSend.EmailID = email.ID
emailSend.State = enums.EmailSend_State_Wait emailSend.State = enums.EmailSend_State_Wait
emailSendLog := models.EmailSendLog{} emailSendLog := models.EmailSendLog{}
emailSendLog.ID = xsfUtils.EmailSendLogID(ctx) emailSendLog.ID = xsfutils.EmailSendLogID(ctx)
emailSendLog.EmailSendID = emailSend.ID emailSendLog.EmailSendID = emailSend.ID
emailSendLog.State = emailSend.State emailSendLog.State = emailSend.State
......
package models package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -33,7 +33,7 @@ func (x *Email) GetTplID() xsf.ID { ...@@ -33,7 +33,7 @@ func (x *Email) GetTplID() xsf.ID {
return x.TplID return x.TplID
} }
func (x *Email) GetTplIDs(rs []*Email) []xsf.ID { func (x *Email) GetTplIDs(rs []*Email) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetTplID()) set.Add(r.GetTplID())
} }
......
package models package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -29,7 +29,7 @@ func (x *EmailReceiver) GetEmailID() xsf.ID { ...@@ -29,7 +29,7 @@ func (x *EmailReceiver) GetEmailID() xsf.ID {
return x.EmailID return x.EmailID
} }
func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID { func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailID()) set.Add(r.GetEmailID())
} }
......
...@@ -2,7 +2,7 @@ package models ...@@ -2,7 +2,7 @@ package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -30,7 +30,7 @@ func (x *EmailSend) GetEmailID() xsf.ID { ...@@ -30,7 +30,7 @@ func (x *EmailSend) GetEmailID() xsf.ID {
return x.EmailID return x.EmailID
} }
func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID { func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailID()) set.Add(r.GetEmailID())
} }
......
...@@ -2,7 +2,7 @@ package models ...@@ -2,7 +2,7 @@ package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -30,7 +30,7 @@ func (x *EmailSendLog) GetEmailSendID() xsf.ID { ...@@ -30,7 +30,7 @@ func (x *EmailSendLog) GetEmailSendID() xsf.ID {
return x.EmailSendID return x.EmailSendID
} }
func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID { func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetEmailSendID()) set.Add(r.GetEmailSendID())
} }
......
package models package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -29,7 +29,7 @@ func (x *EmailTplReceiver) GetTplID() xsf.ID { ...@@ -29,7 +29,7 @@ func (x *EmailTplReceiver) GetTplID() xsf.ID {
return x.TplID return x.TplID
} }
func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID { func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetTplID()) set.Add(r.GetTplID())
} }
......
...@@ -2,9 +2,10 @@ package service ...@@ -2,9 +2,10 @@ package service
import ( import (
"context" "context"
"github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"time" "time"
"github.com/spf13/cast"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
type commonService struct{} type commonService struct{}
...@@ -18,8 +19,8 @@ const ( ...@@ -18,8 +19,8 @@ const (
) )
func csvName(ctx context.Context, tableName string) string { func csvName(ctx context.Context, tableName string) string {
if ctxUtils.GetCtxUID(ctx) > 0 { if ctxutils.GetCtxUID(ctx) > 0 {
return "csv/" + tableName + "" + cast.ToString(ctxUtils.GetCtxUID(ctx)) + "_" + time.Now().Format("20060102150405") + ".csv" return "csv/" + tableName + "" + cast.ToString(ctxutils.GetCtxUID(ctx)) + "_" + time.Now().Format("20060102150405") + ".csv"
} }
return "csv/" + tableName + "_" + time.Now().Format("20060102150405") + ".csv" return "csv/" + tableName + "_" + time.Now().Format("20060102150405") + ".csv"
} }
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -32,7 +32,7 @@ func newEmailService() *emailService { ...@@ -32,7 +32,7 @@ func newEmailService() *emailService {
func (x *emailService) Create(ctx context.Context, in *types.EmailCreateReq) (id xsf.ID, err error) { func (x *emailService) Create(ctx context.Context, in *types.EmailCreateReq) (id xsf.ID, err error) {
email := &models.Email{} email := &models.Email{}
_ = copier.Copy(email, in) _ = copier.Copy(email, in)
email.ID = xsfUtils.EmailID(ctx) email.ID = xsfutils.EmailID(ctx)
if err = dao.EmailDao.Create(ctx, email); err != nil { if err = dao.EmailDao.Create(ctx, email); err != nil {
return 0, err return 0, err
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -32,7 +32,7 @@ func newEmailReceiverService() *emailReceiverService { ...@@ -32,7 +32,7 @@ func newEmailReceiverService() *emailReceiverService {
func (x *emailReceiverService) Create(ctx context.Context, in *types.EmailReceiverCreateReq) (id xsf.ID, err error) { func (x *emailReceiverService) Create(ctx context.Context, in *types.EmailReceiverCreateReq) (id xsf.ID, err error) {
emailReceiver := &models.EmailReceiver{} emailReceiver := &models.EmailReceiver{}
_ = copier.Copy(emailReceiver, in) _ = copier.Copy(emailReceiver, in)
emailReceiver.ID = xsfUtils.EmailReceiverID(ctx) emailReceiver.ID = xsfutils.EmailReceiverID(ctx)
if err = dao.EmailReceiverDao.Create(ctx, emailReceiver); err != nil { if err = dao.EmailReceiverDao.Create(ctx, emailReceiver); err != nil {
return 0, err return 0, err
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -33,7 +33,7 @@ func newEmailSendService() *emailSendService { ...@@ -33,7 +33,7 @@ func newEmailSendService() *emailSendService {
func (x *emailSendService) Create(ctx context.Context, in *types.EmailSendCreateReq) (id xsf.ID, err error) { func (x *emailSendService) Create(ctx context.Context, in *types.EmailSendCreateReq) (id xsf.ID, err error) {
emailSend := &models.EmailSend{} emailSend := &models.EmailSend{}
_ = copier.Copy(emailSend, in) _ = copier.Copy(emailSend, in)
emailSend.ID = xsfUtils.EmailSendID(ctx) emailSend.ID = xsfutils.EmailSendID(ctx)
if err = dao.EmailSendDao.Create(ctx, emailSend); err != nil { if err = dao.EmailSendDao.Create(ctx, emailSend); err != nil {
return 0, err return 0, err
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -32,7 +32,7 @@ func newEmailSendLogService() *emailSendLogService { ...@@ -32,7 +32,7 @@ func newEmailSendLogService() *emailSendLogService {
func (x *emailSendLogService) Create(ctx context.Context, in *types.EmailSendLogCreateReq) (id xsf.ID, err error) { func (x *emailSendLogService) Create(ctx context.Context, in *types.EmailSendLogCreateReq) (id xsf.ID, err error) {
emailSendLog := &models.EmailSendLog{} emailSendLog := &models.EmailSendLog{}
_ = copier.Copy(emailSendLog, in) _ = copier.Copy(emailSendLog, in)
emailSendLog.ID = xsfUtils.EmailSendLogID(ctx) emailSendLog.ID = xsfutils.EmailSendLogID(ctx)
if err = dao.EmailSendLogDao.Create(ctx, emailSendLog); err != nil { if err = dao.EmailSendLogDao.Create(ctx, emailSendLog); err != nil {
return 0, err return 0, err
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -32,7 +32,7 @@ func newEmailTplService() *emailTplService { ...@@ -32,7 +32,7 @@ func newEmailTplService() *emailTplService {
func (x *emailTplService) Create(ctx context.Context, in *types.EmailTplCreateReq) (id xsf.ID, err error) { func (x *emailTplService) Create(ctx context.Context, in *types.EmailTplCreateReq) (id xsf.ID, err error) {
emailTpl := &models.EmailTpl{} emailTpl := &models.EmailTpl{}
_ = copier.Copy(emailTpl, in) _ = copier.Copy(emailTpl, in)
emailTpl.ID = xsfUtils.EmailTplID(ctx) emailTpl.ID = xsfutils.EmailTplID(ctx)
if err = dao.EmailTplDao.Create(ctx, emailTpl); err != nil { if err = dao.EmailTplDao.Create(ctx, emailTpl); err != nil {
return 0, err return 0, err
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils" xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter" csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -32,7 +32,7 @@ func newEmailTplReceiverService() *emailTplReceiverService { ...@@ -32,7 +32,7 @@ func newEmailTplReceiverService() *emailTplReceiverService {
func (x *emailTplReceiverService) Create(ctx context.Context, in *types.EmailTplReceiverCreateReq) (id xsf.ID, err error) { func (x *emailTplReceiverService) Create(ctx context.Context, in *types.EmailTplReceiverCreateReq) (id xsf.ID, err error) {
emailTplReceiver := &models.EmailTplReceiver{} emailTplReceiver := &models.EmailTplReceiver{}
_ = copier.Copy(emailTplReceiver, in) _ = copier.Copy(emailTplReceiver, in)
emailTplReceiver.ID = xsfUtils.EmailTplReceiverID(ctx) emailTplReceiver.ID = xsfutils.EmailTplReceiverID(ctx)
if err = dao.EmailTplReceiverDao.Create(ctx, emailTplReceiver); err != nil { if err = dao.EmailTplReceiverDao.Create(ctx, emailTplReceiver); err != nil {
return 0, err return 0, err
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
...@@ -24,7 +24,7 @@ func (x *EmailSendCreateReq) Valid() error { ...@@ -24,7 +24,7 @@ func (x *EmailSendCreateReq) Valid() error {
if x.EmailID <= 0 { if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -48,7 +48,7 @@ type EmailSendGetByStateReq struct { ...@@ -48,7 +48,7 @@ type EmailSendGetByStateReq struct {
} }
func (x *EmailSendGetByStateReq) Valid() error { func (x *EmailSendGetByStateReq) Valid() error {
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -68,7 +68,7 @@ func (x *EmailSendUpdateByIDReq) Valid() error { ...@@ -68,7 +68,7 @@ func (x *EmailSendUpdateByIDReq) Valid() error {
if x.EmailID <= 0 { if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -88,7 +88,7 @@ func (x *EmailSendUpdateByIDsReq) Valid() error { ...@@ -88,7 +88,7 @@ func (x *EmailSendUpdateByIDsReq) Valid() error {
if x.EmailID <= 0 { if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
...@@ -24,7 +24,7 @@ func (x *EmailSendLogCreateReq) Valid() error { ...@@ -24,7 +24,7 @@ func (x *EmailSendLogCreateReq) Valid() error {
if x.EmailSendID <= 0 { if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -48,7 +48,7 @@ type EmailSendLogGetByStateReq struct { ...@@ -48,7 +48,7 @@ type EmailSendLogGetByStateReq struct {
} }
func (x *EmailSendLogGetByStateReq) Valid() error { func (x *EmailSendLogGetByStateReq) Valid() error {
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -68,7 +68,7 @@ func (x *EmailSendLogUpdateByIDReq) Valid() error { ...@@ -68,7 +68,7 @@ func (x *EmailSendLogUpdateByIDReq) Valid() error {
if x.EmailSendID <= 0 { if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
...@@ -88,7 +88,7 @@ func (x *EmailSendLogUpdateByIDsReq) Valid() error { ...@@ -88,7 +88,7 @@ func (x *EmailSendLogUpdateByIDsReq) Valid() error {
if x.EmailSendID <= 0 { if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
} }
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) { if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
} }
return nil return nil
......
package xsfUtils package xsfutils
import ( import (
"context" "context"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
) )
...@@ -121,7 +121,7 @@ func WithdrawID(ctx context.Context) xsf.ID { ...@@ -121,7 +121,7 @@ func WithdrawID(ctx context.Context) xsf.ID {
func generateID(ctx context.Context, bizTag string) xsf.ID { func generateID(ctx context.Context, bizTag string) xsf.ID {
xsf, err := dxsf.GenerateID(ctx, bizTag) xsf, err := dxsf.GenerateID(ctx, bizTag)
if err != nil { if err != nil {
logger.Error(fmt.Sprintf("GenerateID[%s] failed", bizTag), logger.Err(err), ctxUtils.CtxTraceIDField(ctx)) logger.Error(fmt.Sprintf("GenerateID[%s] failed", bizTag), logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return xsf return xsf
} }
return xsf return xsf
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"go.uber.org/zap" "go.uber.org/zap"
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
type CopyHttpReq struct { type CopyHttpReq struct {
...@@ -26,11 +26,11 @@ func SetCopyReq(c *gin.Context, buf *bytes.Buffer) { ...@@ -26,11 +26,11 @@ func SetCopyReq(c *gin.Context, buf *bytes.Buffer) {
copyHttpReq.URL = c.Request.URL.String() copyHttpReq.URL = c.Request.URL.String()
copyHttpReq.Headers = c.Request.Header copyHttpReq.Headers = c.Request.Header
copyHttpReq.Body = buf.String() copyHttpReq.Body = buf.String()
c.Set(ctxUtils.KeyReqBody, copyHttpReq) c.Set(ctxutils.KeyReqBody, copyHttpReq)
} }
func GetCopyReq(c *gin.Context) *CopyHttpReq { func GetCopyReq(c *gin.Context) *CopyHttpReq {
if val, isExist := c.Get(ctxUtils.KeyReqBody); isExist { if val, isExist := c.Get(ctxutils.KeyReqBody); isExist {
if req, ok := val.(*CopyHttpReq); ok { if req, ok := val.(*CopyHttpReq); ok {
return req return req
} }
...@@ -42,11 +42,11 @@ func SetCopyRsp(c *gin.Context, buf *bytes.Buffer) { ...@@ -42,11 +42,11 @@ func SetCopyRsp(c *gin.Context, buf *bytes.Buffer) {
copyHttpRsp := &CopyHttpRsp{} copyHttpRsp := &CopyHttpRsp{}
copyHttpRsp.Headers = c.Writer.Header() copyHttpRsp.Headers = c.Writer.Header()
copyHttpRsp.Body = buf.String() copyHttpRsp.Body = buf.String()
c.Set(ctxUtils.KeyRspBody, copyHttpRsp) c.Set(ctxutils.KeyRspBody, copyHttpRsp)
} }
func GetCopyRsp(c *gin.Context) *CopyHttpRsp { func GetCopyRsp(c *gin.Context) *CopyHttpRsp {
if val, isExist := c.Get(ctxUtils.KeyRspBody); isExist { if val, isExist := c.Get(ctxutils.KeyRspBody); isExist {
if rsp, ok := val.(*CopyHttpRsp); ok { if rsp, ok := val.(*CopyHttpRsp); ok {
return rsp return rsp
} }
...@@ -60,11 +60,11 @@ func SetCopyApiReq(c *gin.Context, buf *bytes.Buffer) { ...@@ -60,11 +60,11 @@ func SetCopyApiReq(c *gin.Context, buf *bytes.Buffer) {
copyHttpReq.URL = c.Request.URL.String() copyHttpReq.URL = c.Request.URL.String()
copyHttpReq.Headers = c.Request.Header copyHttpReq.Headers = c.Request.Header
copyHttpReq.Body = buf.String() copyHttpReq.Body = buf.String()
c.Set(fmt.Sprintf(ctxUtils.KeyOApiReqBody, ctxUtils.GetGinCtxTraceID(c)), copyHttpReq) c.Set(fmt.Sprintf(ctxutils.KeyOApiReqBody, ctxutils.GetGinCtxTraceID(c)), copyHttpReq)
} }
func GetCopyApiReq(c *gin.Context) *CopyHttpReq { func GetCopyApiReq(c *gin.Context) *CopyHttpReq {
if val, isExist := c.Get(fmt.Sprintf(ctxUtils.KeyOApiReqBody, ctxUtils.GetGinCtxTraceID(c))); isExist { if val, isExist := c.Get(fmt.Sprintf(ctxutils.KeyOApiReqBody, ctxutils.GetGinCtxTraceID(c))); isExist {
if req, ok := val.(*CopyHttpReq); ok { if req, ok := val.(*CopyHttpReq); ok {
return req return req
} }
...@@ -76,11 +76,11 @@ func SetCopyApiRsp(c *gin.Context, buf *bytes.Buffer) { ...@@ -76,11 +76,11 @@ func SetCopyApiRsp(c *gin.Context, buf *bytes.Buffer) {
copyHttpRsp := &CopyHttpRsp{} copyHttpRsp := &CopyHttpRsp{}
copyHttpRsp.Headers = c.Writer.Header() copyHttpRsp.Headers = c.Writer.Header()
copyHttpRsp.Body = buf.String() copyHttpRsp.Body = buf.String()
c.Set(fmt.Sprintf(ctxUtils.KeyOApiRspBody, ctxUtils.GetGinCtxTraceID(c)), copyHttpRsp) c.Set(fmt.Sprintf(ctxutils.KeyOApiRspBody, ctxutils.GetGinCtxTraceID(c)), copyHttpRsp)
} }
func GetCopyApiRsp(c *gin.Context) *CopyHttpRsp { func GetCopyApiRsp(c *gin.Context) *CopyHttpRsp {
if val, isExist := c.Get(fmt.Sprintf(ctxUtils.KeyOApiRspBody, ctxUtils.GetGinCtxTraceID(c))); isExist { if val, isExist := c.Get(fmt.Sprintf(ctxutils.KeyOApiRspBody, ctxutils.GetGinCtxTraceID(c))); isExist {
if rsp, ok := val.(*CopyHttpRsp); ok { if rsp, ok := val.(*CopyHttpRsp); ok {
return rsp return rsp
} }
......
...@@ -17,9 +17,9 @@ import ( ...@@ -17,9 +17,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/httpContentType" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/httpContentType"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/duke-git/lancet/v2/retry"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
retryutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/retryutils"
) )
const defaultTimeout = 30 * time.Second const defaultTimeout = 30 * time.Second
...@@ -296,7 +296,7 @@ func (x *Request) send(ctx context.Context) { ...@@ -296,7 +296,7 @@ func (x *Request) send(ctx context.Context) {
return return
} }
if x.reqBody != nil { if x.reqBody != nil {
if c, _ := ctxUtils.GetGinCtx(ctx); c != nil { if c, _ := ctxutils.GetGinCtx(ctx); c != nil {
entity.SetCopyApiReq(c, bodyBuf) entity.SetCopyApiReq(c, bodyBuf)
} }
} }
...@@ -305,7 +305,7 @@ func (x *Request) send(ctx context.Context) { ...@@ -305,7 +305,7 @@ func (x *Request) send(ctx context.Context) {
x.request.Header.Add(k, v) x.request.Header.Add(k, v)
} }
} }
x.request.Header.Add(ctxUtils.HeaderXRequestIDKey, ctxUtils.CtxRequestID(ctx)) x.request.Header.Add(ctxutils.HeaderXRequestIDKey, ctxutils.CtxRequestID(ctx))
if x.timeout < 1 { if x.timeout < 1 {
x.timeout = defaultTimeout x.timeout = defaultTimeout
} }
...@@ -319,18 +319,18 @@ func (x *Request) send(ctx context.Context) { ...@@ -319,18 +319,18 @@ func (x *Request) send(ctx context.Context) {
logger.String("url", x.url), logger.String("url", x.url),
logger.Any("header", x.request.Header), logger.Any("header", x.request.Header),
logger.String("body", bodyBuf.String()), logger.String("body", bodyBuf.String()),
ctxUtils.CtxTraceIDField(ctx)) ctxutils.CtxTraceIDField(ctx))
} }
st := time.Now() st := time.Now()
if x.retryCount > 0 { if x.retryCount > 0 {
x.err = retry.Retry(func() error { x.err = retryutils.Retry(func() error {
x.pushDo(ctx) x.pushDo(ctx)
return x.err return x.err
}, },
retry.RetryTimes(uint(x.retryCount)), retryutils.RetryTimes(uint(x.retryCount)),
retry.RetryWithLinearBackoff(8*time.Second), retryutils.RetryWithLinearBackoff(8*time.Second),
retry.Context(ctx), retryutils.Context(ctx),
) )
} else { } else {
x.pushDo(ctx) x.pushDo(ctx)
...@@ -347,7 +347,7 @@ func (x *Request) send(ctx context.Context) { ...@@ -347,7 +347,7 @@ func (x *Request) send(ctx context.Context) {
logger.String("status", x.response.Status), logger.String("status", x.response.Status),
logger.Any("header", x.Response().Header), logger.Any("header", x.Response().Header),
logger.String("body", body), logger.String("body", body),
ctxUtils.CtxTraceIDField(ctx)) ctxutils.CtxTraceIDField(ctx))
} }
} }
...@@ -400,7 +400,7 @@ func (x *Request) pushDo(ctx context.Context) { ...@@ -400,7 +400,7 @@ func (x *Request) pushDo(ctx context.Context) {
x.response.Status = rsp.Status x.response.Status = rsp.Status
x.response.Header = rsp.Header x.response.Header = rsp.Header
x.response.StatusCode = rsp.StatusCode x.response.StatusCode = rsp.StatusCode
ctxUtils.SetApiCost(ctx, x.response.Header) ctxutils.SetApiCost(ctx, x.response.Header)
if rsp.Body != nil { if rsp.Body != nil {
defer rsp.Body.Close() defer rsp.Body.Close()
x.response.body, x.err = io.ReadAll(rsp.Body) x.response.body, x.err = io.ReadAll(rsp.Body)
...@@ -409,13 +409,13 @@ func (x *Request) pushDo(ctx context.Context) { ...@@ -409,13 +409,13 @@ func (x *Request) pushDo(ctx context.Context) {
return return
} }
if len(x.response.body) > 0 { if len(x.response.body) > 0 {
if c, _ := ctxUtils.GetGinCtx(ctx); c != nil { if c, _ := ctxutils.GetGinCtx(ctx); c != nil {
entity.SetCopyApiRsp(c, x.response.BodyBuf()) entity.SetCopyApiRsp(c, x.response.BodyBuf())
} }
} }
} }
if rsp.StatusCode != http.StatusOK { if rsp.StatusCode != http.StatusOK {
x.err = xerror.Newf("http %d, %s ", rsp.StatusCode, rsp.Status) x.err = errors.New(rsp.Status)
return return
} }
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUtils(t *testing.T) { func Testutils(t *testing.T) {
_, err := readFile("notfound") _, err := readFile("notfound")
assert.Error(t, err) assert.Error(t, err)
_, err = readFile("utils.go") _, err = readFile("utils.go")
......
package convert_utils package convertutils
import "strconv" import "strconv"
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
) )
...@@ -126,7 +126,7 @@ func (x *CSVExporter[T]) WriteToReply(ctx context.Context) *CSVExporter[T] { ...@@ -126,7 +126,7 @@ func (x *CSVExporter[T]) WriteToReply(ctx context.Context) *CSVExporter[T] {
if x.err != nil { if x.err != nil {
return x return x
} }
c, err := ctxUtils.GetGinCtx(ctx) c, err := ctxutils.GetGinCtx(ctx)
if err != nil { if err != nil {
x.err = err x.err = err
return x return x
......
package ctxUtils package ctxutils
import ( import (
"context" "context"
......
package ctxUtils_test package ctxutils_test
import ( import (
"fmt" "fmt"
......
package fileUtils package fileutils
import ( import (
"os" "os"
......
package fileUtils package fileutils
const ( const (
prefix = "prefix" prefix = "prefix"
......
package hashUtils package hashutils
import ( import (
"crypto/md5" "crypto/md5"
......
package map_utils package maputils
import ( import (
"encoding/json" "encoding/json"
......
package redSyncUtils package redsyncutils
import ( import (
"context" "context"
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
var ( var (
...@@ -33,12 +33,12 @@ func Sync(ctx context.Context, key string, fn func(), options ...redsync.Option) ...@@ -33,12 +33,12 @@ func Sync(ctx context.Context, key string, fn func(), options ...redsync.Option)
} }
mutex := redSync.NewMutex(key, options...) mutex := redSync.NewMutex(key, options...)
if err := mutex.LockContext(ctx); err != nil { if err := mutex.LockContext(ctx); err != nil {
logger.Error("[redSync]try get lock fail", logger.Any("err", err), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[redSync]try get lock fail", logger.Any("err", err), ctxutils.CtxTraceIDField(ctx))
return xerror.Wrap(err, fmt.Sprintf("[redSync][%s]get lock fail", key)) return xerror.Wrap(err, fmt.Sprintf("[redSync][%s]get lock fail", key))
} }
defer func() { defer func() {
if _, err := mutex.UnlockContext(ctx); err != nil { if _, err := mutex.UnlockContext(ctx); err != nil {
logger.Error("[redSync]release lock fail", logger.Any("err", err), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[redSync]release lock fail", logger.Any("err", err), ctxutils.CtxTraceIDField(ctx))
} }
}() }()
fn() fn()
......
package retryUtils package retryutils
import ( import (
"context" "context"
...@@ -6,9 +6,6 @@ import ( ...@@ -6,9 +6,6 @@ import (
"fmt" "fmt"
"math" "math"
"math/rand" "math/rand"
"reflect"
"runtime"
"strings"
"time" "time"
) )
...@@ -105,9 +102,12 @@ func Retry(retryFunc RetryFunc, opts ...Option) error { ...@@ -105,9 +102,12 @@ func Retry(retryFunc RetryFunc, opts ...Option) error {
} }
} }
var i uint var (
i uint
err error
)
for i < config.retryTimes { for i < config.retryTimes {
err := retryFunc() err = retryFunc()
if err != nil { if err != nil {
after := time.After(config.backoffStrategy.CalculateInterval()) after := time.After(config.backoffStrategy.CalculateInterval())
select { select {
...@@ -121,11 +121,11 @@ func Retry(retryFunc RetryFunc, opts ...Option) error { ...@@ -121,11 +121,11 @@ func Retry(retryFunc RetryFunc, opts ...Option) error {
i++ i++
} }
funcPath := runtime.FuncForPC(reflect.ValueOf(retryFunc).Pointer()).Name() // funcPath := runtime.FuncForPC(reflect.ValueOf(retryFunc).Pointer()).Name()
lastSlash := strings.LastIndex(funcPath, "/") // lastSlash := strings.LastIndex(funcPath, "/")
funcName := funcPath[lastSlash+1:] // funcName := funcPath[lastSlash+1:]
return fmt.Errorf("function %s run failed after %d times retry", funcName, i) return fmt.Errorf("retry[3] faild, %s", err.Error())
} }
type BackoffStrategy interface { type BackoffStrategy interface {
......
package setUtils package setutils
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
......
package sliceUtils package sliceutils
import ( import (
"fmt" "fmt"
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/spf13/cast" "github.com/spf13/cast"
...@@ -67,7 +67,7 @@ func GetIDs[ID xtype.Key, T IID[ID]](rs []*T) []ID { ...@@ -67,7 +67,7 @@ func GetIDs[ID xtype.Key, T IID[ID]](rs []*T) []ID {
if len(rs) == 0 { if len(rs) == 0 {
return nil return nil
} }
set := setUtils.NewSet[ID]() set := setutils.NewSet[ID]()
for _, r := range rs { for _, r := range rs {
set.Add((*r).GetID()) set.Add((*r).GetID())
} }
...@@ -173,7 +173,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T { ...@@ -173,7 +173,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T {
} }
func GetStrMapIDs[ID xtype.Key, T IID[ID]](m map[string]*T) []ID { func GetStrMapIDs[ID xtype.Key, T IID[ID]](m map[string]*T) []ID {
st := setUtils.NewSet[ID]() st := setutils.NewSet[ID]()
for _, v := range m { for _, v := range m {
st.Add((*v).GetID()) st.Add((*v).GetID())
} }
...@@ -189,7 +189,7 @@ func IDMapToSlice[ID xtype.Key, T any](m map[ID]*T) []*T { ...@@ -189,7 +189,7 @@ func IDMapToSlice[ID xtype.Key, T any](m map[ID]*T) []*T {
} }
func GetIDMapIDs[ID xtype.Key, T IID[ID]](m map[ID]*T) []ID { func GetIDMapIDs[ID xtype.Key, T IID[ID]](m map[ID]*T) []ID {
st := setUtils.NewSet[ID]() st := setutils.NewSet[ID]()
for _, v := range m { for _, v := range m {
st.Add((*v).GetID()) st.Add((*v).GetID())
} }
...@@ -205,7 +205,7 @@ func StrMapSliceToSlice[T any](m map[string][]*T) []*T { ...@@ -205,7 +205,7 @@ func StrMapSliceToSlice[T any](m map[string][]*T) []*T {
} }
func GetStrMapSliceIDs[ID xtype.Key, T IID[ID]](m map[string][]*T) []ID { func GetStrMapSliceIDs[ID xtype.Key, T IID[ID]](m map[string][]*T) []ID {
st := setUtils.NewSet[ID]() st := setutils.NewSet[ID]()
for _, rs := range m { for _, rs := range m {
for _, r := range rs { for _, r := range rs {
st.Add((*r).GetID()) st.Add((*r).GetID())
...@@ -223,7 +223,7 @@ func IDMapSliceToSlice[ID xtype.Key, T any](m map[ID][]*T) []*T { ...@@ -223,7 +223,7 @@ func IDMapSliceToSlice[ID xtype.Key, T any](m map[ID][]*T) []*T {
} }
func GetIDMapSliceIDs[ID xtype.Key, T IID[ID]](m map[ID][]*T) []ID { func GetIDMapSliceIDs[ID xtype.Key, T IID[ID]](m map[ID][]*T) []ID {
st := setUtils.NewSet[ID]() st := setutils.NewSet[ID]()
for _, rs := range m { for _, rs := range m {
for _, r := range rs { for _, r := range rs {
st.Add((*r).GetID()) st.Add((*r).GetID())
...@@ -281,7 +281,7 @@ func ArrayUnique[T comparable](array []T) []T { ...@@ -281,7 +281,7 @@ func ArrayUnique[T comparable](array []T) []T {
// if len(rs) == 0 { // if len(rs) == 0 {
// return nil // return nil
// } // }
// set := setUtils.NewSet[id]() // set := setutils.NewSet[id]()
// for _, r := range rs { // for _, r := range rs {
// set.Add((*r).GetID()) // set.Add((*r).GetID())
// } // }
......
package stackUtils package stackutils
import "runtime" import "runtime"
......
package stringUtils package stringutils
import ( import (
"strings" "strings"
......
package uriUtils package uriutils
import ( import (
"net/url" "net/url"
......
package uuidUtils package uuidutils
import ( import (
"strings" "strings"
......
package webLogUtils package weblogutils
import ( import (
"container/list" "container/list"
...@@ -15,9 +15,9 @@ import ( ...@@ -15,9 +15,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
merge "gitlab.wanzhuangkj.com/tush/xpkg/pkg/merger" merge "gitlab.wanzhuangkj.com/tush/xpkg/pkg/merger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/jsonutils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/jsonutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/retryutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -51,10 +51,10 @@ func WebLogInterceptor() func(c *gin.Context) { ...@@ -51,10 +51,10 @@ func WebLogInterceptor() func(c *gin.Context) {
rsp *entity.CopyHttpRsp rsp *entity.CopyHttpRsp
// respCode int // respCode int
) )
ctx := ctxUtils.WrapCtx(c) ctx := ctxutils.WrapCtx(c)
xApi, ok := api.XApi.M[URL] xApi, ok := api.XApi.M[URL]
if ok { if ok {
uid := ctxUtils.GetGinUID(c) uid := ctxutils.GetGinUID(c)
req = entity.GetCopyReq(c) req = entity.GetCopyReq(c)
if uid > 0 { if uid > 0 {
defer func() { defer func() {
...@@ -101,7 +101,7 @@ func Init() { ...@@ -101,7 +101,7 @@ func Init() {
if l.Len() == 0 { if l.Len() == 0 {
return nil return nil
} }
ctx := context.WithValue(context.Background(), ctxUtils.ContextTraceIDKey, xsf.GenerateID().String()) ctx := context.WithValue(context.Background(), ctxutils.ContextTraceIDKey, xsf.GenerateID().String())
ors := make([]*WebLog, 0, l.Len()) ors := make([]*WebLog, 0, l.Len())
for e := l.Front(); e != nil; e = e.Next() { for e := l.Front(); e != nil; e = e.Next() {
le, ok := e.Value.(*WebLog) le, ok := e.Value.(*WebLog)
...@@ -115,12 +115,12 @@ func Init() { ...@@ -115,12 +115,12 @@ func Init() {
insertFn := func() error { insertFn := func() error {
if debug { if debug {
if err := webLogDaoInstance.CreateSlice(ctx, ors); err != nil { if err := webLogDaoInstance.CreateSlice(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail detail", logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return err return err
} }
} else { } else {
if err := webLogDaoInstance.CreateSliceSilent(ctx, ors); err != nil { if err := webLogDaoInstance.CreateSliceSilent(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail detail", logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return err return err
} }
} }
...@@ -130,10 +130,10 @@ func Init() { ...@@ -130,10 +130,10 @@ func Init() {
if debug { if debug {
logger.Info("[webLog]batch insert start") logger.Info("[webLog]batch insert start")
} }
if err := retryUtils.Retry(insertFn, retryUtils.RetryTimes(10), retryUtils.RetryWithLinearBackoff(32*time.Minute)); err != nil { if err := retryutils.Retry(insertFn, retryutils.RetryTimes(10), retryutils.RetryWithLinearBackoff(32*time.Minute)); err != nil {
logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxutils.CtxTraceIDField(ctx))
for _, or := range ors { for _, or := range ors {
logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UID.String()), logger.String("operate", or.Operate), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UID.String()), logger.String("operate", or.Operate), ctxutils.CtxTraceIDField(ctx))
} }
} }
if debug { if debug {
...@@ -151,11 +151,11 @@ func Init() { ...@@ -151,11 +151,11 @@ func Init() {
func AddAsync(ctx context.Context, operate string, req *entity.CopyHttpReq, rsp *entity.CopyHttpRsp) { func AddAsync(ctx context.Context, operate string, req *entity.CopyHttpReq, rsp *entity.CopyHttpRsp) {
wl := &WebLog{} wl := &WebLog{}
wl.ID = xsf.GenerateID() wl.ID = xsf.GenerateID()
wl.CompanyName = ctxUtils.GetCtxCompanyName(ctx) wl.CompanyName = ctxutils.GetCtxCompanyName(ctx)
wl.CompanyID = ctxUtils.GetCtxCompanyID(ctx) wl.CompanyID = ctxutils.GetCtxCompanyID(ctx)
wl.UID = ctxUtils.GetCtxUID(ctx) wl.UID = ctxutils.GetCtxUID(ctx)
wl.UName = ctxUtils.GetCtxUName(ctx) wl.UName = ctxutils.GetCtxUName(ctx)
wl.TraceID = ctxUtils.GetCtxTid(ctx) wl.TraceID = ctxutils.GetCtxTid(ctx)
wl.Operate = operate wl.Operate = operate
wl.CreatedAt = xtime.Now() wl.CreatedAt = xtime.Now()
if req != nil { if req != nil {
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
) )
func Go(ctx context.Context, n int, fn func() error) error { func Go(ctx context.Context, n int, fn func() error) error {
......
...@@ -13,8 +13,8 @@ import ( ...@@ -13,8 +13,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" setutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
...@@ -125,7 +125,7 @@ func (x *ODao[T]) CreateSliceTx(ctx context.Context, tx *gorm.DB, tbs []*T) erro ...@@ -125,7 +125,7 @@ func (x *ODao[T]) CreateSliceTx(ctx context.Context, tx *gorm.DB, tbs []*T) erro
} }
func (x *ODao[T]) getIDs(tbs []*T) []xsf.ID { func (x *ODao[T]) getIDs(tbs []*T) []xsf.ID {
idsSet := setUtils.NewSet[xsf.ID]() idsSet := setutils.NewSet[xsf.ID]()
for _, r := range tbs { for _, r := range tbs {
if id := (*r).GetID(); id > 0 { if id := (*r).GetID(); id > 0 {
idsSet.Add(id) idsSet.Add(id)
...@@ -303,13 +303,13 @@ type IListParams interface { ...@@ -303,13 +303,13 @@ type IListParams interface {
} }
func (x *ODao[T]) Page(ctx context.Context, where IPageParams) (rs []*T, total int64, err error) { func (x *ODao[T]) Page(ctx context.Context, where IPageParams) (rs []*T, total int64, err error) {
if ginCtx, err := ctxUtils.GetGinCtx(ctx); err == nil && ginCtx != nil { if ginCtx, err := ctxutils.GetGinCtx(ctx); err == nil && ginCtx != nil {
ginCtx.Set(ctxUtils.KeyApiType, "page") ginCtx.Set(ctxutils.KeyApiType, "page")
pagination := query.Pagination{ pagination := query.Pagination{
PageIndex: where.GetPageIndex(), PageIndex: where.GetPageIndex(),
PageSize: where.GetPageSize(), PageSize: where.GetPageSize(),
} }
ginCtx.Set(ctxUtils.KeyPagination, pagination) ginCtx.Set(ctxutils.KeyPagination, pagination)
} }
condition := x.DB().WithContext(ctx).Model(new(T)).Scopes(x.MakeCondition(where)) condition := x.DB().WithContext(ctx).Model(new(T)).Scopes(x.MakeCondition(where))
if where.Unscoped() { if where.Unscoped() {
...@@ -479,14 +479,14 @@ func (x *ODao[T]) GetByID(ctx context.Context, id xsf.ID) (record *T, err error) ...@@ -479,14 +479,14 @@ func (x *ODao[T]) GetByID(ctx context.Context, id xsf.ID) (record *T, err error)
if err = x.DB().WithContext(ctx).Where("id = ?", id).First(&record).Error; err != nil { if err = x.DB().WithContext(ctx).Where("id = ?", id).First(&record).Error; err != nil {
if xerror.Is(err, ErrRecordNotFound) { if xerror.Is(err, ErrRecordNotFound) {
if err = x.Cache.SetPlaceholder(ctx, id); err != nil { if err = x.Cache.SetPlaceholder(ctx, id); err != nil {
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx)) logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
} }
return nil, nil return nil, nil
} }
return nil, xerror.New(err.Error()) return nil, xerror.New(err.Error())
} }
if err = x.Cache.Set(ctx, id, record, x.Cache.ExpireTime); err != nil { if err = x.Cache.Set(ctx, id, record, x.Cache.ExpireTime); err != nil {
logger.Warn("cache.Set error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx)) logger.Warn("cache.Set error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
} }
return record, nil return record, nil
}) })
...@@ -542,7 +542,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs ...@@ -542,7 +542,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs
recordIDMap[(*record).GetID()] = struct{}{} recordIDMap[(*record).GetID()] = struct{}{}
} }
if err = x.Cache.MultiSet(ctx, records, x.Cache.ExpireTime); err != nil { if err = x.Cache.MultiSet(ctx, records, x.Cache.ExpireTime); err != nil {
logger.Warn("cache.MultiSet error", logger.Err(err), logger.Any("ids", records), ctxUtils.CtxTraceIDField(ctx)) logger.Warn("cache.MultiSet error", logger.Err(err), logger.Any("ids", records), ctxutils.CtxTraceIDField(ctx))
} }
if len(records) == len(missedIDs) { if len(records) == len(missedIDs) {
return itemMap, nil return itemMap, nil
...@@ -551,7 +551,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs ...@@ -551,7 +551,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs
for _, id := range missedIDs { for _, id := range missedIDs {
if _, ok := recordIDMap[id]; !ok { if _, ok := recordIDMap[id]; !ok {
if err = x.Cache.SetPlaceholder(ctx, id); err != nil { if err = x.Cache.SetPlaceholder(ctx, id); err != nil {
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx)) logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
} }
} }
} }
......
package xmodels package xmodels
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" setutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gorm.io/gorm" "gorm.io/gorm"
) )
func GetUid(tx *gorm.DB) xsf.ID { func GetUid(tx *gorm.DB) xsf.ID {
ctx := tx.Statement.Context ctx := tx.Statement.Context
return ctxUtils.GetCtxUID(ctx) return ctxutils.GetCtxUID(ctx)
} }
type IModel interface { type IModel interface {
...@@ -17,7 +17,7 @@ type IModel interface { ...@@ -17,7 +17,7 @@ type IModel interface {
} }
func GetIDs[T IModel](rs []*T) []xsf.ID { func GetIDs[T IModel](rs []*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]() st := setutils.NewSet[xsf.ID]()
for _, v := range rs { for _, v := range rs {
st.Add((*v).GetID()) st.Add((*v).GetID())
} }
...@@ -33,7 +33,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T { ...@@ -33,7 +33,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T {
} }
func GetStrMapIDs[T IModel](m map[string]*T) []xsf.ID { func GetStrMapIDs[T IModel](m map[string]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]() st := setutils.NewSet[xsf.ID]()
for _, v := range m { for _, v := range m {
st.Add((*v).GetID()) st.Add((*v).GetID())
} }
...@@ -49,7 +49,7 @@ func IDMapToSlice[T any](m map[xsf.ID]*T) []*T { ...@@ -49,7 +49,7 @@ func IDMapToSlice[T any](m map[xsf.ID]*T) []*T {
} }
func GetIDMapIDs[T IModel](m map[xsf.ID]*T) []xsf.ID { func GetIDMapIDs[T IModel](m map[xsf.ID]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]() st := setutils.NewSet[xsf.ID]()
for _, v := range m { for _, v := range m {
st.Add((*v).GetID()) st.Add((*v).GetID())
} }
...@@ -73,7 +73,7 @@ func IDMapSliceToSlice[T any](m map[xsf.ID][]*T) []*T { ...@@ -73,7 +73,7 @@ func IDMapSliceToSlice[T any](m map[xsf.ID][]*T) []*T {
} }
func GetIDMapSliceIDs[T IModel](m map[xsf.ID][]*T) []xsf.ID { func GetIDMapSliceIDs[T IModel](m map[xsf.ID][]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]() st := setutils.NewSet[xsf.ID]()
for _, rs := range m { for _, rs := range m {
for _, r := range rs { for _, r := range rs {
st.Add((*r).GetID()) st.Add((*r).GetID())
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
...@@ -36,7 +36,7 @@ func (x *CronJob) ParseJobInfo() { ...@@ -36,7 +36,7 @@ func (x *CronJob) ParseJobInfo() {
var CronJobTool = &CronJob{} var CronJobTool = &CronJob{}
func (*CronJob) GetIDs(rs []*CronJob) []xsf.ID { func (*CronJob) GetIDs(rs []*CronJob) []xsf.ID {
return sliceUtils.GetIDs(rs) return sliceutils.GetIDs(rs)
} }
func (CronJob) NewFromModel(m *models.CronJob) *CronJob { func (CronJob) NewFromModel(m *models.CronJob) *CronJob {
......
package biz package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
...@@ -16,10 +16,10 @@ type CronJobLog struct { ...@@ -16,10 +16,10 @@ type CronJobLog struct {
var CronJobLogTool = &CronJobLog{} var CronJobLogTool = &CronJobLog{}
func (*CronJobLog) GetIDs(rs []*CronJobLog) []xsf.ID { func (*CronJobLog) GetIDs(rs []*CronJobLog) []xsf.ID {
return sliceUtils.GetIDs(rs) return sliceutils.GetIDs(rs)
} }
func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID { func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetJobID()) set.Add(r.GetJobID())
} }
......
...@@ -3,8 +3,8 @@ package biz ...@@ -3,8 +3,8 @@ package biz
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
...@@ -17,10 +17,10 @@ type CronJobRecord struct { ...@@ -17,10 +17,10 @@ type CronJobRecord struct {
var CronJobRecordTool = &CronJobRecord{} var CronJobRecordTool = &CronJobRecord{}
func (*CronJobRecord) GetIDs(rs []*CronJobRecord) []xsf.ID { func (*CronJobRecord) GetIDs(rs []*CronJobRecord) []xsf.ID {
return sliceUtils.GetIDs(rs) return sliceutils.GetIDs(rs)
} }
func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID { func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetJobID()) set.Add(r.GetJobID())
} }
......
...@@ -12,8 +12,8 @@ import ( ...@@ -12,8 +12,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/redSyncUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/redsyncutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
...@@ -44,13 +44,13 @@ func (x *cronJobController) StartByCode(c *gin.Context) { ...@@ -44,13 +44,13 @@ func (x *cronJobController) StartByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err")) response.Error(c, errors.New("pwd err"))
return return
} }
ctx := ctxUtils.WrapCtx(c) ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.CronJobService.StartByID(ctx, job.ID, nil); err != nil { if err := service.CronJobService.StartByID(ctx, job.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -74,13 +74,13 @@ func (x *cronJobController) StopByCode(c *gin.Context) { ...@@ -74,13 +74,13 @@ func (x *cronJobController) StopByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err")) response.Error(c, errors.New("pwd err"))
return return
} }
ctx := ctxUtils.WrapCtx(c) ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.CronJobService.StopByID(ctx, job.ID, nil); err != nil { if err := service.CronJobService.StopByID(ctx, job.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -98,12 +98,12 @@ func (x *cronJobController) CallOnceByCode(c *gin.Context) { ...@@ -98,12 +98,12 @@ func (x *cronJobController) CallOnceByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err")) response.Error(c, errors.New("pwd err"))
return return
} }
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), req.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), req.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
err = ExecJob(ctxUtils.WrapCtx(c), job) err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -117,7 +117,7 @@ func (x *cronJobController) Create(c *gin.Context) { ...@@ -117,7 +117,7 @@ func (x *cronJobController) Create(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
id, err := service.CronJobService.Create(ctxUtils.WrapCtx(c), in, nil) id, err := service.CronJobService.Create(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -131,7 +131,7 @@ func (x *cronJobController) DeleteByID(c *gin.Context) { ...@@ -131,7 +131,7 @@ func (x *cronJobController) DeleteByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.CronJobService.DeleteByID(ctxUtils.WrapCtx(c), in.ID, nil); err != nil { if err := service.CronJobService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -144,7 +144,7 @@ func (x *cronJobController) UpdateByID(c *gin.Context) { ...@@ -144,7 +144,7 @@ func (x *cronJobController) UpdateByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.CronJobService.UpdateByID(ctxUtils.WrapCtx(c), in, nil); err != nil { if err := service.CronJobService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -157,7 +157,7 @@ func (x *cronJobController) GetByID(c *gin.Context) { ...@@ -157,7 +157,7 @@ func (x *cronJobController) GetByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil) cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -172,18 +172,18 @@ func (x *cronJobController) StartByID(c *gin.Context) { ...@@ -172,18 +172,18 @@ func (x *cronJobController) StartByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil) cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
ctx := ctxUtils.WrapCtx(c) ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, cj.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctx, cj.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
if err := service.CronJobService.StartByID(ctx, job.ID, nil); err != nil { if err := service.CronJobService.StartByID(ctx, job.ID); err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
...@@ -203,17 +203,17 @@ func (x *cronJobController) StopByID(c *gin.Context) { ...@@ -203,17 +203,17 @@ func (x *cronJobController) StopByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil) cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), cj.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), cj.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
err = ExecJob(ctxUtils.WrapCtx(c), job) err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -226,17 +226,17 @@ func (x *cronJobController) RunByID(c *gin.Context) { ...@@ -226,17 +226,17 @@ func (x *cronJobController) RunByID(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil) cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), cj.JobCode, &biz.CronJobOpts{}) job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), cj.JobCode)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
} }
err = ExecJob(ctxUtils.WrapCtx(c), job) err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -250,7 +250,7 @@ func (x *cronJobController) Page(c *gin.Context) { ...@@ -250,7 +250,7 @@ func (x *cronJobController) Page(c *gin.Context) {
response.Error(c, err) response.Error(c, err)
return return
} }
cjs, total, err := service.CronJobService.Page(ctxUtils.WrapCtx(c), in, nil) cjs, total, err := service.CronJobService.Page(ctxutils.WrapCtx(c), in)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -267,9 +267,9 @@ func ExecJob(ctx context.Context, j *biz.CronJob) error { ...@@ -267,9 +267,9 @@ func ExecJob(ctx context.Context, j *biz.CronJob) error {
if !ok { if !ok {
return errors.New("handler not found") return errors.New("handler not found")
} }
return redSyncUtils.Sync(ctx, j.JobCode, func() { return redsyncutils.Sync(ctx, j.JobCode, func() {
if err := execTask(ctx, j); err != nil { if err := execTask(ctx, j); err != nil {
logger.Error(fmt.Sprintf("[cronJob][%s] exec err: %s", j.JobName, err.Error()), ctxUtils.CtxTraceIDField(ctx)) logger.Error(fmt.Sprintf("[cronJob][%s] exec err: %s", j.JobName, err.Error()), ctxutils.CtxTraceIDField(ctx))
} }
}, },
redsync.WithExpiry(5*time.Minute), redsync.WithExpiry(5*time.Minute),
...@@ -297,13 +297,13 @@ func execTask(ctx context.Context, j *biz.CronJob) error { ...@@ -297,13 +297,13 @@ func execTask(ctx context.Context, j *biz.CronJob) error {
if job == nil { if job == nil {
return nil return nil
} }
logger.Info(fmt.Sprintf("[cronJob][%s] start", j.JobName), ctxUtils.CtxTraceIDField(ctx)) logger.Info(fmt.Sprintf("[cronJob][%s] start", j.JobName), ctxutils.CtxTraceIDField(ctx))
cronJobRecord := &models.CronJobRecord{JobID: job.ID, BeginTime: xtime.Now()} cronJobRecord := &models.CronJobRecord{JobID: job.ID, BeginTime: xtime.Now()}
_ = dao.CronJobRecordDao.CreateSilent(ctx, cronJobRecord) _ = dao.CronJobRecordDao.CreateSilent(ctx, cronJobRecord)
_ = dao.CronJobLogDao.CreateSilent(ctx, &models.CronJobLog{JobID: job.ID, Info: "job started."}) _ = dao.CronJobLogDao.CreateSilent(ctx, &models.CronJobLog{JobID: job.ID, Info: "job started."})
defer func() { defer func() {
logger.Info(fmt.Sprintf("[cronJob][%s] end", j.JobName), logger.Any("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx)) logger.Info(fmt.Sprintf("[cronJob][%s] end", j.JobName), logger.Any("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
_ = dao.CronJobDao.UpdateByIDSilent(ctx, job.ID, &models.CronJob{State: enums.CronJob_State_NOT_RUNNING}) _ = dao.CronJobDao.UpdateByIDSilent(ctx, job.ID, &models.CronJob{State: enums.CronJob_State_NOT_RUNNING})
}() }()
......
...@@ -7,9 +7,8 @@ import ( ...@@ -7,9 +7,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/controller" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/controller"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/service" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/service"
...@@ -32,15 +31,15 @@ func initCron() error { ...@@ -32,15 +31,15 @@ func initCron() error {
return nil return nil
} }
ctx := context.TODO() ctx := context.TODO()
cronJobs, err := service.CronJobService.GetSliceByEnable(ctx, enums.CronJob_Enable_OPEN, &biz.CronJobOpts{}) cronJobs, err := service.CronJobService.GetSliceByEnable(ctx, enums.CronJob_Enable_OPEN)
if err != nil { if err != nil {
return err return err
} }
if len(cronJobs) == 0 { if len(cronJobs) == 0 {
return nil return nil
} }
cronJobIDs := sliceUtils.GetIDs(cronJobs) cronJobIDs := sliceutils.GetIDs(cronJobs)
_ = service.CronJobService.UpdateByIDs(ctx, &types.CronJobUpdateByIDsReq{IDs: cronJobIDs, State: enums.CronJob_State_NOT_RUNNING}, nil) _ = service.CronJobService.UpdateByIDs(ctx, &types.CronJobUpdateByIDsReq{IDs: cronJobIDs, State: enums.CronJob_State_NOT_RUNNING})
var tasks []*gocron.Task var tasks []*gocron.Task
for _, job := range cronJobs { for _, job := range cronJobs {
job.ParseJobInfo() job.ParseJobInfo()
...@@ -50,13 +49,13 @@ func initCron() error { ...@@ -50,13 +49,13 @@ func initCron() error {
TimeSpec: job.TimeSpec, TimeSpec: job.TimeSpec,
Name: job.JobCode, Name: job.JobCode,
Fn: func() { Fn: func() {
ctx := context.WithValue(ctx, ctxUtils.HeaderXRequestIDKey, ctxUtils.GenerateTid()) ctx := context.WithValue(ctx, ctxutils.HeaderXRequestIDKey, ctxutils.GenerateTid())
if err := controller.ExecJob(ctx, job); err != nil { if err := controller.ExecJob(ctx, job); err != nil {
logger.Error(fmt.Sprintf("[cron]exec err: %s", err.Error()), logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxUtils.CtxTraceIDField(ctx)) logger.Error(fmt.Sprintf("[cron]exec err: %s", err.Error()), logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxutils.CtxTraceIDField(ctx))
} }
}, },
} }
logger.Info("[cron]add cron job", logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxUtils.CtxTraceIDField(ctx)) logger.Info("[cron]add cron job", logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxutils.CtxTraceIDField(ctx))
tasks = append(tasks, &tsk) tasks = append(tasks, &tsk)
} }
} }
...@@ -69,6 +68,6 @@ func initCron() error { ...@@ -69,6 +68,6 @@ func initCron() error {
if err = gocron.Add(tasks...); err != nil { if err = gocron.Add(tasks...); err != nil {
return err return err
} }
logger.Info("[cron] initialized", ctxUtils.CtxTraceIDField(ctx)) logger.Info("[cron] initialized", ctxutils.CtxTraceIDField(ctx))
return nil return nil
} }
package models package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -34,7 +34,7 @@ func (x *CronJobLog) GetJobID() xsf.ID { ...@@ -34,7 +34,7 @@ func (x *CronJobLog) GetJobID() xsf.ID {
return x.JobID return x.JobID
} }
func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID { func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetJobID()) set.Add(r.GetJobID())
} }
......
package models package models
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -37,7 +37,7 @@ func (x *CronJobRecord) GetJobID() xsf.ID { ...@@ -37,7 +37,7 @@ func (x *CronJobRecord) GetJobID() xsf.ID {
return x.JobID return x.JobID
} }
func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID { func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
set := setUtils.NewSet[xsf.ID]() set := setutils.NewSet[xsf.ID]()
for _, r := range rs { for _, r := range rs {
set.Add(r.GetJobID()) set.Add(r.GetJobID())
} }
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
) )
type cronJobService struct { type cronJobService struct {
...@@ -75,7 +75,7 @@ func (x *cronJobService) DeleteByIDs(ctx context.Context, ids []xsf.ID) error { ...@@ -75,7 +75,7 @@ func (x *cronJobService) DeleteByIDs(ctx context.Context, ids []xsf.ID) error {
if err != nil { if err != nil {
return err return err
} }
err = sliceUtils.CompareSlice(ids, cronJobs, ecode.ErrCronJobNotFound) err = sliceutils.CompareSlice(ids, cronJobs, ecode.ErrCronJobNotFound)
if err != nil { if err != nil {
return err return err
} }
...@@ -122,7 +122,7 @@ func (x *cronJobService) UpdateByIDs(ctx context.Context, req *types.CronJobUpda ...@@ -122,7 +122,7 @@ func (x *cronJobService) UpdateByIDs(ctx context.Context, req *types.CronJobUpda
if err != nil { if err != nil {
return err return err
} }
err = sliceUtils.CompareSlice(req.IDs, cronJobs, ecode.ErrCronJobNotFound) err = sliceutils.CompareSlice(req.IDs, cronJobs, ecode.ErrCronJobNotFound)
if err != nil { if err != nil {
return err return err
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论