提交 a4765858 authored 作者: mooncake's avatar mooncake

email

上级 4c2a0b25
...@@ -68,6 +68,7 @@ func parseInit() { ...@@ -68,6 +68,7 @@ func parseInit() {
if err := dxsf.Init(); err != nil { if err := dxsf.Init(); err != nil {
logger.Fatal(err.Error()) logger.Fatal(err.Error())
} }
logger.Info("[dxsf] initialized.")
} }
type Application struct { type Application struct {
......
package email package main
func main() {
}
package config package config
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"strings" "strings"
"sync" "sync"
"time" "time"
...@@ -120,6 +121,7 @@ type Config struct { ...@@ -120,6 +121,7 @@ type Config struct {
Redis Redis `yaml:"redis" json:"redis" mapstructure:"redis"` Redis Redis `yaml:"redis" json:"redis" mapstructure:"redis"`
Cron Cron `yaml:"cron" json:"cron" mapstructure:"cron"` Cron Cron `yaml:"cron" json:"cron" mapstructure:"cron"`
Oss oss.AliOssConfig `yaml:"oss" json:"oss" mapstructure:"oss"` Oss oss.AliOssConfig `yaml:"oss" json:"oss" mapstructure:"oss"`
Email config.Config `yaml:"email" json:"email" mapstructure:"email"`
Content []byte `yaml:"-" json:"-"` Content []byte `yaml:"-" json:"-"`
} }
......
...@@ -3,6 +3,7 @@ package config ...@@ -3,6 +3,7 @@ package config
import ( import (
"bytes" "bytes"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"time" "time"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
...@@ -13,6 +14,7 @@ import ( ...@@ -13,6 +14,7 @@ import (
) )
type ConsulConfFetcher struct { type ConsulConfFetcher struct {
count int
isNew bool isNew bool
confKey string confKey string
err error err error
...@@ -51,6 +53,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher { ...@@ -51,6 +53,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher {
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.isNew = true x.isNew = true
x.cfg.SetContent(kv.Value) x.cfg.SetContent(kv.Value)
} }
...@@ -78,6 +81,9 @@ func (x *ConsulConfFetcher) parse() *ConsulConfFetcher { ...@@ -78,6 +81,9 @@ func (x *ConsulConfFetcher) parse() *ConsulConfFetcher {
for _, load := range x.loads { for _, load := range x.loads {
load(x.cfg.GetContent()) load(x.cfg.GetContent())
} }
if x.count > 1 {
eventbus.Eb.Publish(context.Background(), eventbus.TopicConfChange)
}
logger.Debug("[consul] conf updated") logger.Debug("[consul] conf updated")
return x return x
} }
......
...@@ -29,7 +29,8 @@ func ParseConf() (err error) { ...@@ -29,7 +29,8 @@ func ParseConf() (err error) {
if confType == "local" { if confType == "local" {
localConf() localConf()
logger.Infof("[conf]conf:%s", Cfg.ConfCenter.Local.Conf) logger.Infof("[conf]conf:%s", Cfg.ConfCenter.Local.Conf)
if err := parseLocal(Cfg.ConfCenter.Local.Conf, Cfg, func() { lp := &localParser{}
if err := lp.parseLocal(Cfg.ConfCenter.Local.Conf, Cfg, func() {
ParseExtend() ParseExtend()
}); err != nil { }); err != nil {
return err return err
...@@ -48,6 +49,9 @@ func ParseConf() (err error) { ...@@ -48,6 +49,9 @@ func ParseConf() (err error) {
if confType == "nacos" { if confType == "nacos" {
nacosConf() nacosConf()
nc := NewNacos(&Cfg.ConfCenter.Nacos, func(content []byte) (err error) { nc := NewNacos(&Cfg.ConfCenter.Nacos, func(content []byte) (err error) {
if bytes.Compare(content, Cfg.GetContent()) == 0 {
return nil
}
Cfg.SetContent(content) Cfg.SetContent(content)
v := viper.New() v := viper.New()
v.SetConfigType("yaml") v.SetConfigType("yaml")
...@@ -57,7 +61,10 @@ func ParseConf() (err error) { ...@@ -57,7 +61,10 @@ func ParseConf() (err error) {
if err := v.Unmarshal(&Cfg); err != nil { if err := v.Unmarshal(&Cfg); err != nil {
return err return err
} }
return ParseExtend() if err := ParseExtend(); err != nil {
return err
}
return nil
}, logger.Get()) }, logger.Get())
if err := nc.Connect().Watch().Fetch().Parse().Err(); err != nil { if err := nc.Connect().Watch().Fetch().Parse().Err(); err != nil {
return err return err
......
...@@ -4,8 +4,10 @@ package config ...@@ -4,8 +4,10 @@ package config
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
...@@ -17,8 +19,11 @@ import ( ...@@ -17,8 +19,11 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
// parseLocal configuration files to struct, including yaml, toml, json, etc., and turn on listening for configuration file changes if fs is not empty type localParser struct {
func parseLocal(configFile string, obj ICfg, reloads ...func()) error { count int
}
func (x *localParser) parseLocal(configFile string, obj ICfg, reloads ...func()) error {
confFileAbs, err := filepath.Abs(configFile) confFileAbs, err := filepath.Abs(configFile)
if err != nil { if err != nil {
return err return err
...@@ -50,13 +55,13 @@ func parseLocal(configFile string, obj ICfg, reloads ...func()) error { ...@@ -50,13 +55,13 @@ func parseLocal(configFile string, obj ICfg, reloads ...func()) error {
for _, reload := range reloads { for _, reload := range reloads {
reload() reload()
} }
watchConfig(configFile, obj, reloads...) x.watchConfig(configFile, obj, reloads...)
} }
return nil return nil
} }
func watchConfig(confFile string, obj ICfg, reloads ...func()) { func (x *localParser) watchConfig(confFile string, obj ICfg, reloads ...func()) {
viper.WatchConfig() viper.WatchConfig()
// Note: OnConfigChange is called twice on Windows // Note: OnConfigChange is called twice on Windows
...@@ -78,6 +83,10 @@ func watchConfig(confFile string, obj ICfg, reloads ...func()) { ...@@ -78,6 +83,10 @@ func watchConfig(confFile string, obj ICfg, reloads ...func()) {
reload() reload()
} }
} }
x.count++
if x.count > 1 {
eventbus.Eb.Publish(context.Background(), eventbus.TopicConfChange)
}
}) })
} }
......
package config package config
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/config_client" "github.com/nacos-group/nacos-sdk-go/clients/config_client"
...@@ -21,6 +23,7 @@ type NacosClient struct { ...@@ -21,6 +23,7 @@ type NacosClient struct {
parseFn func(content []byte) (err error) parseFn func(content []byte) (err error)
e error e error
l *zap.Logger l *zap.Logger
count int
} }
type Parser func(content []byte) (err error) type Parser func(content []byte) (err error)
...@@ -98,7 +101,11 @@ func (x *NacosClient) Parse() *NacosClient { ...@@ -98,7 +101,11 @@ func (x *NacosClient) Parse() *NacosClient {
if x.e != nil { if x.e != nil {
return x return x
} }
x.e = x.parseFn([]byte(x.content)) x.e = x.parseFn(x.content)
x.count++
if x.count > 1 {
eventbus.Eb.Publish(context.Background(), eventbus.TopicConfChange)
}
return x return x
} }
......
...@@ -90,6 +90,7 @@ require ( ...@@ -90,6 +90,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/nyaruka/phonenumbers v1.0.55 // indirect
go.uber.org/goleak v1.3.0 // indirect go.uber.org/goleak v1.3.0 // indirect
golang.org/x/image v0.23.0 // indirect golang.org/x/image v0.23.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
......
...@@ -459,6 +459,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW ...@@ -459,6 +459,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
github.com/nacos-group/nacos-sdk-go v1.1.6 h1:zjn7CIoz0RxPHCalWc9kXOQx94oUFQl5J1rctbq2mYU= github.com/nacos-group/nacos-sdk-go v1.1.6 h1:zjn7CIoz0RxPHCalWc9kXOQx94oUFQl5J1rctbq2mYU=
github.com/nacos-group/nacos-sdk-go v1.1.6/go.mod h1:cBv9wy5iObs7khOqov1ERFQrCuTR4ILpgaiaVMxEmGI= github.com/nacos-group/nacos-sdk-go v1.1.6/go.mod h1:cBv9wy5iObs7khOqov1ERFQrCuTR4ILpgaiaVMxEmGI=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg=
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U= github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"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"
) )
type Email struct { type Email struct {
models.Email models.Email
xcommon.CommonBiz[xsf.ID,models.Email, Email] xcommon.CommonBiz[xsf.ID, models.Email, Email]
} }
var EmailTool = &Email{} var EmailTool = &Email{}
...@@ -22,7 +19,7 @@ var EmailTool = &Email{} ...@@ -22,7 +19,7 @@ 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())
...@@ -33,7 +30,6 @@ func (x *Email) GetTplIDs(rs []*Email) []xsf.ID{ ...@@ -33,7 +30,6 @@ func (x *Email) GetTplIDs(rs []*Email) []xsf.ID{
type EmailOpts struct { type EmailOpts struct {
} }
func (Email) NewFromModel(m *models.Email) *Email { func (Email) NewFromModel(m *models.Email) *Email {
if m == nil { if m == nil {
return nil return nil
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"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"
) )
type EmailReceiver struct { type EmailReceiver struct {
models.EmailReceiver models.EmailReceiver
xcommon.CommonBiz[xsf.ID,models.EmailReceiver, EmailReceiver] xcommon.CommonBiz[xsf.ID, models.EmailReceiver, EmailReceiver]
} }
var EmailReceiverTool = &EmailReceiver{} var EmailReceiverTool = &EmailReceiver{}
...@@ -22,7 +19,7 @@ var EmailReceiverTool = &EmailReceiver{} ...@@ -22,7 +19,7 @@ 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())
...@@ -33,7 +30,6 @@ func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID{ ...@@ -33,7 +30,6 @@ func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID{
type EmailReceiverOpts struct { type EmailReceiverOpts struct {
} }
func (EmailReceiver) NewFromModel(m *models.EmailReceiver) *EmailReceiver { func (EmailReceiver) NewFromModel(m *models.EmailReceiver) *EmailReceiver {
if m == nil { if m == nil {
return nil return nil
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"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"
) )
type EmailSend struct { type EmailSend struct {
models.EmailSend models.EmailSend
xcommon.CommonBiz[xsf.ID,models.EmailSend, EmailSend] xcommon.CommonBiz[xsf.ID, models.EmailSend, EmailSend]
} }
var EmailSendTool = &EmailSend{} var EmailSendTool = &EmailSend{}
...@@ -22,7 +19,7 @@ var EmailSendTool = &EmailSend{} ...@@ -22,7 +19,7 @@ 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())
...@@ -33,7 +30,6 @@ func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID{ ...@@ -33,7 +30,6 @@ func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID{
type EmailSendOpts struct { type EmailSendOpts struct {
} }
func (EmailSend) NewFromModel(m *models.EmailSend) *EmailSend { func (EmailSend) NewFromModel(m *models.EmailSend) *EmailSend {
if m == nil { if m == nil {
return nil return nil
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"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"
) )
type EmailSendLog struct { type EmailSendLog struct {
models.EmailSendLog models.EmailSendLog
xcommon.CommonBiz[xsf.ID,models.EmailSendLog, EmailSendLog] xcommon.CommonBiz[xsf.ID, models.EmailSendLog, EmailSendLog]
} }
var EmailSendLogTool = &EmailSendLog{} var EmailSendLogTool = &EmailSendLog{}
...@@ -22,7 +19,7 @@ var EmailSendLogTool = &EmailSendLog{} ...@@ -22,7 +19,7 @@ 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())
...@@ -33,7 +30,6 @@ func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID{ ...@@ -33,7 +30,6 @@ func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID{
type EmailSendLogOpts struct { type EmailSendLogOpts struct {
} }
func (EmailSendLog) NewFromModel(m *models.EmailSendLog) *EmailSendLog { func (EmailSendLog) NewFromModel(m *models.EmailSendLog) *EmailSendLog {
if m == nil { if m == nil {
return nil return nil
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"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"
) )
type EmailTpl struct { type EmailTpl struct {
models.EmailTpl models.EmailTpl
xcommon.CommonBiz[xsf.ID,models.EmailTpl, EmailTpl] xcommon.CommonBiz[xsf.ID, models.EmailTpl, EmailTpl]
} }
var EmailTplTool = &EmailTpl{} var EmailTplTool = &EmailTpl{}
...@@ -25,7 +22,6 @@ func (*EmailTpl) GetIDs(rs []*EmailTpl) []xsf.ID { ...@@ -25,7 +22,6 @@ func (*EmailTpl) GetIDs(rs []*EmailTpl) []xsf.ID {
type EmailTplOpts struct { type EmailTplOpts struct {
} }
func (EmailTpl) NewFromModel(m *models.EmailTpl) *EmailTpl { func (EmailTpl) NewFromModel(m *models.EmailTpl) *EmailTpl {
if m == nil { if m == nil {
return nil return nil
......
package biz package biz
import ( import (
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"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"
) )
type EmailTplReceiver struct { type EmailTplReceiver struct {
models.EmailTplReceiver models.EmailTplReceiver
xcommon.CommonBiz[xsf.ID,models.EmailTplReceiver, EmailTplReceiver] xcommon.CommonBiz[xsf.ID, models.EmailTplReceiver, EmailTplReceiver]
} }
var EmailTplReceiverTool = &EmailTplReceiver{} var EmailTplReceiverTool = &EmailTplReceiver{}
...@@ -22,7 +19,7 @@ var EmailTplReceiverTool = &EmailTplReceiver{} ...@@ -22,7 +19,7 @@ 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())
...@@ -33,7 +30,6 @@ func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID{ ...@@ -33,7 +30,6 @@ func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID{
type EmailTplReceiverOpts struct { type EmailTplReceiverOpts struct {
} }
func (EmailTplReceiver) NewFromModel(m *models.EmailTplReceiver) *EmailTplReceiver { func (EmailTplReceiver) NewFromModel(m *models.EmailTplReceiver) *EmailTplReceiver {
if m == nil { if m == nil {
return nil return nil
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailCachePrefixKey = prefix + "email:" emailCachePrefixKey = "email:"
) )
type EmailCache ocache.OCache[models.Email] type EmailCache ocache.OCache[models.Email]
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailReceiverCachePrefixKey = prefix + "emailReceiver:" emailReceiverCachePrefixKey = "emailReceiver:"
) )
type EmailReceiverCache ocache.OCache[models.EmailReceiver] type EmailReceiverCache ocache.OCache[models.EmailReceiver]
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailSendCachePrefixKey = prefix + "emailSend:" emailSendCachePrefixKey = "emailSend:"
) )
type EmailSendCache ocache.OCache[models.EmailSend] type EmailSendCache ocache.OCache[models.EmailSend]
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailSendLogCachePrefixKey = prefix + "emailSendLog:" emailSendLogCachePrefixKey = "emailSendLog:"
) )
type EmailSendLogCache ocache.OCache[models.EmailSendLog] type EmailSendLogCache ocache.OCache[models.EmailSendLog]
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailTplCachePrefixKey = prefix + "emailTpl:" emailTplCachePrefixKey = "emailTpl:"
) )
type EmailTplCache ocache.OCache[models.EmailTpl] type EmailTplCache ocache.OCache[models.EmailTpl]
......
package cache package cache
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"operator-qt/internal/modules/operator/models"
) )
const ( var (
emailTplReceiverCachePrefixKey = prefix + "emailTplReceiver:" emailTplReceiverCachePrefixKey = "emailTplReceiver:"
) )
type EmailTplReceiverCache ocache.OCache[models.EmailTplReceiver] type EmailTplReceiverCache ocache.OCache[models.EmailTplReceiver]
......
package consts package config
var ( var (
Schema string = "" Cfg = &Config{}
Prefix string = ""
) )
// Config 配置结构体 (建议从环境变量或配置文件中读取)
type Config struct {
SMTPServer string `yaml:"smtpServer" json:"smtpServer" mapstructure:"smtpServer"`
SMTPPort int `yaml:"smtpPort" json:"smtpPort" mapstructure:"smtpPort"`
Email string `yaml:"emailAddr" json:"emailAddr" mapstructure:"emailAddr"`
Token string `yaml:"emailToken" json:"emailToken" mapstructure:"emailToken"`
Name string `yaml:"emailAlias" json:"emailAlias" mapstructure:"emailAlias"`
Schema string `yaml:"schema" json:"schema" mapstructure:"schema"`
}
type Email struct {
From string
To []Receiver
Subject string
Body string
Attachments []*Attachment
InlineImages map[string]string // CID -> 图片文件路径
}
type Receiver struct {
Email string
DisplayName string
}
type Attachment struct {
Filename string // 显示的文件名
FilePath string // 文件路径(二选一)
Data []byte // 文件数据(二选一)
ContentType string // 可选:指定内容类型
}
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailController struct { type emailController struct {
...@@ -37,7 +35,7 @@ func (x *emailController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailController) DeleteByID(c *gin.Context) { func (x *emailController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,6 @@ func (x *emailController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,6 @@ func (x *emailController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailController) UpdateByID(c *gin.Context) { func (x *emailController) UpdateByID(c *gin.Context) {
in := &types.EmailUpdateByIDReq{} in := &types.EmailUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +58,7 @@ func (x *emailController) UpdateByID(c *gin.Context) { ...@@ -72,18 +58,7 @@ func (x *emailController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailController) UpdateByIDs(c *gin.Context) {
in := &types.EmailUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件详情 // @Summary 查询邮件详情
// @Description 通过id查询邮件详情,参数id必填 // @Description 通过id查询邮件详情,参数id必填
...@@ -100,7 +75,7 @@ func (x *emailController) GetByID(c *gin.Context) { ...@@ -100,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, nil) email, err := service.EmailService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +97,7 @@ func (x *emailController) GetByIDs(c *gin.Context) { ...@@ -122,6 +97,7 @@ func (x *emailController) GetByIDs(c *gin.Context) {
data := types.EmailObjDetailTool.NewSliceFromBizSlice(emails) data := types.EmailObjDetailTool.NewSliceFromBizSlice(emails)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件 // @Summary 分页查询邮件
// @Description 分页查询邮件 // @Description 分页查询邮件
...@@ -147,6 +123,7 @@ func (x *emailController) Page(c *gin.Context) { ...@@ -147,6 +123,7 @@ func (x *emailController) Page(c *gin.Context) {
data := types.EmailObjDetailTool.NewSliceFromBizSlice(emails) data := types.EmailObjDetailTool.NewSliceFromBizSlice(emails)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailReceiverController struct { type emailReceiverController struct {
...@@ -37,7 +35,7 @@ func (x *emailReceiverController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailReceiverController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailReceiverController) DeleteByID(c *gin.Context) { func (x *emailReceiverController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,6 @@ func (x *emailReceiverController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,6 @@ func (x *emailReceiverController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailReceiverController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailReceiverService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailReceiverController) UpdateByID(c *gin.Context) { func (x *emailReceiverController) UpdateByID(c *gin.Context) {
in := &types.EmailReceiverUpdateByIDReq{} in := &types.EmailReceiverUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +58,7 @@ func (x *emailReceiverController) UpdateByID(c *gin.Context) { ...@@ -72,18 +58,7 @@ func (x *emailReceiverController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailReceiverController) UpdateByIDs(c *gin.Context) {
in := &types.EmailReceiverUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailReceiverService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件收件人详情 // @Summary 查询邮件收件人详情
// @Description 通过id查询邮件收件人详情,参数id必填 // @Description 通过id查询邮件收件人详情,参数id必填
...@@ -100,7 +75,7 @@ func (x *emailReceiverController) GetByID(c *gin.Context) { ...@@ -100,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, nil) emailReceiver, err := service.EmailReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +97,7 @@ func (x *emailReceiverController) GetByIDs(c *gin.Context) { ...@@ -122,6 +97,7 @@ func (x *emailReceiverController) GetByIDs(c *gin.Context) {
data := types.EmailReceiverObjDetailTool.NewSliceFromBizSlice(emailReceivers) data := types.EmailReceiverObjDetailTool.NewSliceFromBizSlice(emailReceivers)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件收件人 // @Summary 分页查询邮件收件人
// @Description 分页查询邮件收件人 // @Description 分页查询邮件收件人
...@@ -147,6 +123,7 @@ func (x *emailReceiverController) Page(c *gin.Context) { ...@@ -147,6 +123,7 @@ func (x *emailReceiverController) Page(c *gin.Context) {
data := types.EmailReceiverObjDetailTool.NewSliceFromBizSlice(emailReceivers) data := types.EmailReceiverObjDetailTool.NewSliceFromBizSlice(emailReceivers)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailSendController struct { type emailSendController struct {
...@@ -37,7 +35,7 @@ func (x *emailSendController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailSendController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailSendController) DeleteByID(c *gin.Context) { func (x *emailSendController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,7 @@ func (x *emailSendController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,7 @@ func (x *emailSendController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailSendController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailSendService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailSendController) UpdateByID(c *gin.Context) { func (x *emailSendController) UpdateByID(c *gin.Context) {
in := &types.EmailSendUpdateByIDReq{} in := &types.EmailSendUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +59,7 @@ func (x *emailSendController) UpdateByID(c *gin.Context) { ...@@ -72,18 +59,7 @@ func (x *emailSendController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailSendController) UpdateByIDs(c *gin.Context) {
in := &types.EmailSendUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailSendService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件发送详情 // @Summary 查询邮件发送详情
// @Description 通过id查询邮件发送详情,参数id必填 // @Description 通过id查询邮件发送详情,参数id必填
...@@ -100,7 +76,7 @@ func (x *emailSendController) GetByID(c *gin.Context) { ...@@ -100,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, nil) emailSend, err := service.EmailSendService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +98,7 @@ func (x *emailSendController) GetByIDs(c *gin.Context) { ...@@ -122,6 +98,7 @@ func (x *emailSendController) GetByIDs(c *gin.Context) {
data := types.EmailSendObjDetailTool.NewSliceFromBizSlice(emailSends) data := types.EmailSendObjDetailTool.NewSliceFromBizSlice(emailSends)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件发送 // @Summary 分页查询邮件发送
// @Description 分页查询邮件发送 // @Description 分页查询邮件发送
...@@ -147,6 +124,7 @@ func (x *emailSendController) Page(c *gin.Context) { ...@@ -147,6 +124,7 @@ func (x *emailSendController) Page(c *gin.Context) {
data := types.EmailSendObjDetailTool.NewSliceFromBizSlice(emailSends) data := types.EmailSendObjDetailTool.NewSliceFromBizSlice(emailSends)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailSendLogController struct { type emailSendLogController struct {
...@@ -37,7 +35,7 @@ func (x *emailSendLogController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailSendLogController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailSendLogController) DeleteByID(c *gin.Context) { func (x *emailSendLogController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,6 @@ func (x *emailSendLogController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,6 @@ func (x *emailSendLogController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailSendLogController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailSendLogService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailSendLogController) UpdateByID(c *gin.Context) { func (x *emailSendLogController) UpdateByID(c *gin.Context) {
in := &types.EmailSendLogUpdateByIDReq{} in := &types.EmailSendLogUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +58,7 @@ func (x *emailSendLogController) UpdateByID(c *gin.Context) { ...@@ -72,18 +58,7 @@ func (x *emailSendLogController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailSendLogController) UpdateByIDs(c *gin.Context) {
in := &types.EmailSendLogUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailSendLogService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件发送记录详情 // @Summary 查询邮件发送记录详情
// @Description 通过id查询邮件发送记录详情,参数id必填 // @Description 通过id查询邮件发送记录详情,参数id必填
...@@ -100,7 +75,7 @@ func (x *emailSendLogController) GetByID(c *gin.Context) { ...@@ -100,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, nil) emailSendLog, err := service.EmailSendLogService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +97,7 @@ func (x *emailSendLogController) GetByIDs(c *gin.Context) { ...@@ -122,6 +97,7 @@ func (x *emailSendLogController) GetByIDs(c *gin.Context) {
data := types.EmailSendLogObjDetailTool.NewSliceFromBizSlice(emailSendLogs) data := types.EmailSendLogObjDetailTool.NewSliceFromBizSlice(emailSendLogs)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件发送记录 // @Summary 分页查询邮件发送记录
// @Description 分页查询邮件发送记录 // @Description 分页查询邮件发送记录
...@@ -147,6 +123,7 @@ func (x *emailSendLogController) Page(c *gin.Context) { ...@@ -147,6 +123,7 @@ func (x *emailSendLogController) Page(c *gin.Context) {
data := types.EmailSendLogObjDetailTool.NewSliceFromBizSlice(emailSendLogs) data := types.EmailSendLogObjDetailTool.NewSliceFromBizSlice(emailSendLogs)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailTplController struct { type emailTplController struct {
...@@ -37,7 +35,7 @@ func (x *emailTplController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailTplController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailTplController) DeleteByID(c *gin.Context) { func (x *emailTplController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,6 @@ func (x *emailTplController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,6 @@ func (x *emailTplController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailTplController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailTplService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailTplController) UpdateByID(c *gin.Context) { func (x *emailTplController) UpdateByID(c *gin.Context) {
in := &types.EmailTplUpdateByIDReq{} in := &types.EmailTplUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +58,7 @@ func (x *emailTplController) UpdateByID(c *gin.Context) { ...@@ -72,18 +58,7 @@ func (x *emailTplController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailTplController) UpdateByIDs(c *gin.Context) {
in := &types.EmailTplUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailTplService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件模板详情 // @Summary 查询邮件模板详情
// @Description 通过id查询邮件模板详情,参数id必填 // @Description 通过id查询邮件模板详情,参数id必填
...@@ -100,7 +75,7 @@ func (x *emailTplController) GetByID(c *gin.Context) { ...@@ -100,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, nil) emailTpl, err := service.EmailTplService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +97,7 @@ func (x *emailTplController) GetByIDs(c *gin.Context) { ...@@ -122,6 +97,7 @@ func (x *emailTplController) GetByIDs(c *gin.Context) {
data := types.EmailTplObjDetailTool.NewSliceFromBizSlice(emailTpls) data := types.EmailTplObjDetailTool.NewSliceFromBizSlice(emailTpls)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件模板 // @Summary 分页查询邮件模板
// @Description 分页查询邮件模板 // @Description 分页查询邮件模板
...@@ -147,6 +123,7 @@ func (x *emailTplController) Page(c *gin.Context) { ...@@ -147,6 +123,7 @@ func (x *emailTplController) Page(c *gin.Context) {
data := types.EmailTplObjDetailTool.NewSliceFromBizSlice(emailTpls) data := types.EmailTplObjDetailTool.NewSliceFromBizSlice(emailTpls)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package controller package controller
import ( import (
"operator-qt/internal/modules/operator/service"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
) )
type emailTplReceiverController struct { type emailTplReceiverController struct {
...@@ -37,7 +35,7 @@ func (x *emailTplReceiverController) Create(c *gin.Context) { ...@@ -37,7 +35,7 @@ func (x *emailTplReceiverController) Create(c *gin.Context) {
response.Success(c, id) response.Success(c, id)
} }
func (x *emailTplReceiverController) DeleteByID(c *gin.Context) { func (x *emailTplReceiverController) DeleteByID(c *gin.Context) {
in:= &request.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -48,18 +46,6 @@ func (x *emailTplReceiverController) DeleteByID(c *gin.Context) { ...@@ -48,18 +46,6 @@ func (x *emailTplReceiverController) DeleteByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailTplReceiverController) DeleteByIDs(c *gin.Context) {
in := &request.BaseIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailTplReceiverService.DeleteByIDs(ctxUtils.WrapCtx(c), in.IDs, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
func (x *emailTplReceiverController) UpdateByID(c *gin.Context) { func (x *emailTplReceiverController) UpdateByID(c *gin.Context) {
in := &types.EmailTplReceiverUpdateByIDReq{} in := &types.EmailTplReceiverUpdateByIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
...@@ -72,18 +58,7 @@ func (x *emailTplReceiverController) UpdateByID(c *gin.Context) { ...@@ -72,18 +58,7 @@ func (x *emailTplReceiverController) UpdateByID(c *gin.Context) {
} }
response.Success(c) response.Success(c)
} }
func (x *emailTplReceiverController) UpdateByIDs(c *gin.Context) {
in := &types.EmailTplReceiverUpdateByIDsReq{}
if err := x.Bind(c, in); err != nil {
response.Error(c, err)
return
}
if err := service.EmailTplReceiverService.UpdateByIDs(ctxUtils.WrapCtx(c), in, nil); err != nil {
response.Error(c, err)
return
}
response.Success(c)
}
// GetByID // GetByID
// @Summary 查询邮件模板收件人详情 // @Summary 查询邮件模板收件人详情
// @Description 通过id查询邮件模板收件人详情,参数id必填 // @Description 通过id查询邮件模板收件人详情,参数id必填
...@@ -100,7 +75,7 @@ func (x *emailTplReceiverController) GetByID(c *gin.Context) { ...@@ -100,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, nil) emailTplReceiver, err := service.EmailTplReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
if err != nil { if err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -122,6 +97,7 @@ func (x *emailTplReceiverController) GetByIDs(c *gin.Context) { ...@@ -122,6 +97,7 @@ func (x *emailTplReceiverController) GetByIDs(c *gin.Context) {
data := types.EmailTplReceiverObjDetailTool.NewSliceFromBizSlice(emailTplReceivers) data := types.EmailTplReceiverObjDetailTool.NewSliceFromBizSlice(emailTplReceivers)
response.SuccessWithList(c, data) response.SuccessWithList(c, data)
} }
// Page // Page
// @Summary 分页查询邮件模板收件人 // @Summary 分页查询邮件模板收件人
// @Description 分页查询邮件模板收件人 // @Description 分页查询邮件模板收件人
...@@ -147,6 +123,7 @@ func (x *emailTplReceiverController) Page(c *gin.Context) { ...@@ -147,6 +123,7 @@ func (x *emailTplReceiverController) Page(c *gin.Context) {
data := types.EmailTplReceiverObjDetailTool.NewSliceFromBizSlice(emailTplReceivers) data := types.EmailTplReceiverObjDetailTool.NewSliceFromBizSlice(emailTplReceivers)
response.SuccessWithPage(c, data, total) response.SuccessWithPage(c, data, total)
} }
// ExportCSV // ExportCSV
// @Summary 导出csv // @Summary 导出csv
// @Description 导出csv // @Description 导出csv
......
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailDao struct { type emailDao struct {
*odao.ODao[models.Email] *odao.ODao[models.Email]
} }
var EmailDao = &emailDao{ var EmailDao = &emailDao{}
ODao: odao.NewDao[models.Email](consts.Schema_operator),
}
func init() {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
EmailDao.ODao.Cache = cache.NewEmailCache(database.GetCacheType())
})
}
func (x *emailDao) GetSliceByTplID(ctx context.Context, order string, tplID xsf.ID) ([]*models.Email, error) { func (x *emailDao) GetSliceByTplID(ctx context.Context, order string, tplID xsf.ID) ([]*models.Email, error) {
if tplID <= 0 { if tplID <= 0 {
return nil, nil return nil, nil
...@@ -35,24 +24,24 @@ func (x *emailDao) GetSliceByTplIDs(ctx context.Context, order string, tplIDs [] ...@@ -35,24 +24,24 @@ func (x *emailDao) GetSliceByTplIDs(ctx context.Context, order string, tplIDs []
if len(tplIDs) == 0 { if len(tplIDs) == 0 {
return nil, nil return nil, nil
} }
emails,err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs) emails, err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return emails, nil return emails, nil
} }
func (x *emailDao) GetMapSliceByTplIDs(ctx context.Context,order string, tplIDs []xsf.ID) (map[xsf.ID][]*models.Email,int, error) { func (x *emailDao) GetMapSliceByTplIDs(ctx context.Context, order string, tplIDs []xsf.ID) (map[xsf.ID][]*models.Email, int, error) {
if len(tplIDs) == 0 { if len(tplIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emails,err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs) emails, err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
itemMap := make(map[xsf.ID][]*models.Email) itemMap := make(map[xsf.ID][]*models.Email)
for _, record := range emails { for _, record := range emails {
itemMap[record.TplID] = append(itemMap[record.TplID], record) itemMap[record.TplID] = append(itemMap[record.TplID], record)
} }
return itemMap,len(emails), nil return itemMap, len(emails), nil
} }
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailReceiverDao struct { type emailReceiverDao struct {
*odao.ODao[models.EmailReceiver] *odao.ODao[models.EmailReceiver]
} }
var EmailReceiverDao = &emailReceiverDao{ var EmailReceiverDao = &emailReceiverDao{}
ODao: odao.NewDao[models.EmailReceiver](consts.Schema_operator),
}
func init() {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
EmailReceiverDao.ODao.Cache = cache.NewEmailReceiverCache(database.GetCacheType())
})
}
func (x *emailReceiverDao) GetSliceByEmailID(ctx context.Context, order string, emailID xsf.ID) ([]*models.EmailReceiver, error) { func (x *emailReceiverDao) GetSliceByEmailID(ctx context.Context, order string, emailID xsf.ID) ([]*models.EmailReceiver, error) {
if emailID <= 0 { if emailID <= 0 {
return nil, nil return nil, nil
...@@ -35,24 +24,24 @@ func (x *emailReceiverDao) GetSliceByEmailIDs(ctx context.Context, order string, ...@@ -35,24 +24,24 @@ func (x *emailReceiverDao) GetSliceByEmailIDs(ctx context.Context, order string,
if len(emailIDs) == 0 { if len(emailIDs) == 0 {
return nil, nil return nil, nil
} }
emailReceivers,err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs) emailReceivers, err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return emailReceivers, nil return emailReceivers, nil
} }
func (x *emailReceiverDao) GetMapSliceByEmailIDs(ctx context.Context,order string, emailIDs []xsf.ID) (map[xsf.ID][]*models.EmailReceiver,int, error) { func (x *emailReceiverDao) GetMapSliceByEmailIDs(ctx context.Context, order string, emailIDs []xsf.ID) (map[xsf.ID][]*models.EmailReceiver, int, error) {
if len(emailIDs) == 0 { if len(emailIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emailReceivers,err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs) emailReceivers, err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
itemMap := make(map[xsf.ID][]*models.EmailReceiver) itemMap := make(map[xsf.ID][]*models.EmailReceiver)
for _, record := range emailReceivers { for _, record := range emailReceivers {
itemMap[record.EmailID] = append(itemMap[record.EmailID], record) itemMap[record.EmailID] = append(itemMap[record.EmailID], record)
} }
return itemMap,len(emailReceivers), nil return itemMap, len(emailReceivers), nil
} }
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailSendDao struct { type emailSendDao struct {
*odao.ODao[models.EmailSend] *odao.ODao[models.EmailSend]
} }
var EmailSendDao = &emailSendDao{ var EmailSendDao = &emailSendDao{}
ODao: odao.NewDao[models.EmailSend](consts.Schema_operator),
}
func init() {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
EmailSendDao.ODao.Cache = cache.NewEmailSendCache(database.GetCacheType())
})
}
func (x *emailSendDao) GetSliceByState(ctx context.Context, order string, state enums.EmailSend_State_Enum) ([]*models.EmailSend, error) { func (x *emailSendDao) GetSliceByState(ctx context.Context, order string, state enums.EmailSend_State_Enum) ([]*models.EmailSend, error) {
return x.GetOrderSliceByWhere(ctx, order, "state = ?", state) return x.GetOrderSliceByWhere(ctx, order, "state = ?", state)
} }
func (x *emailSendDao) GetSliceByStates(ctx context.Context, order string, states []enums.EmailSend_State_Enum) ([]*models.EmailSend, error) { func (x *emailSendDao) GetSliceByStates(ctx context.Context, order string, states []enums.EmailSend_State_Enum) ([]*models.EmailSend, error) {
if len(states) == 0{ if len(states) == 0 {
return nil,nil return nil, nil
} }
return x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states) return x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states)
} }
func (x *emailSendDao) GetMapSliceByStates(ctx context.Context, order string, states []enums.EmailSend_State_Enum) (map[enums.EmailSend_State_Enum][]*models.EmailSend,int, error) { func (x *emailSendDao) GetMapSliceByStates(ctx context.Context, order string, states []enums.EmailSend_State_Enum) (map[enums.EmailSend_State_Enum][]*models.EmailSend, int, error) {
if len(states) == 0{ if len(states) == 0 {
return nil,0,nil return nil, 0, nil
} }
emailSends,err := x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states) emailSends, err := x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states)
if err != nil{ if err != nil {
return nil,0,err return nil, 0, err
} }
if len(emailSends) == 0{ if len(emailSends) == 0 {
return nil,0,nil return nil, 0, nil
} }
emailSendMapSlice := make(map[enums.EmailSend_State_Enum][]*models.EmailSend) emailSendMapSlice := make(map[enums.EmailSend_State_Enum][]*models.EmailSend)
for i:=range emailSends{ for i := range emailSends {
emailSendMapSlice[emailSends[i].State] = append(emailSendMapSlice[emailSends[i].State],emailSends[i]) emailSendMapSlice[emailSends[i].State] = append(emailSendMapSlice[emailSends[i].State], emailSends[i])
} }
return emailSendMapSlice,len(emailSends),nil return emailSendMapSlice, len(emailSends), nil
} }
func (x *emailSendDao) GetSliceByEmailID(ctx context.Context, order string, emailID xsf.ID) ([]*models.EmailSend, error) { func (x *emailSendDao) GetSliceByEmailID(ctx context.Context, order string, emailID xsf.ID) ([]*models.EmailSend, error) {
if emailID <= 0 { if emailID <= 0 {
...@@ -64,24 +53,24 @@ func (x *emailSendDao) GetSliceByEmailIDs(ctx context.Context, order string, ema ...@@ -64,24 +53,24 @@ func (x *emailSendDao) GetSliceByEmailIDs(ctx context.Context, order string, ema
if len(emailIDs) == 0 { if len(emailIDs) == 0 {
return nil, nil return nil, nil
} }
emailSends,err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs) emailSends, err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return emailSends, nil return emailSends, nil
} }
func (x *emailSendDao) GetMapSliceByEmailIDs(ctx context.Context,order string, emailIDs []xsf.ID) (map[xsf.ID][]*models.EmailSend,int, error) { func (x *emailSendDao) GetMapSliceByEmailIDs(ctx context.Context, order string, emailIDs []xsf.ID) (map[xsf.ID][]*models.EmailSend, int, error) {
if len(emailIDs) == 0 { if len(emailIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emailSends,err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs) emailSends, err := x.GetOrderSliceByWhere(ctx, order, "email_id IN (?)", emailIDs)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
itemMap := make(map[xsf.ID][]*models.EmailSend) itemMap := make(map[xsf.ID][]*models.EmailSend)
for _, record := range emailSends { for _, record := range emailSends {
itemMap[record.EmailID] = append(itemMap[record.EmailID], record) itemMap[record.EmailID] = append(itemMap[record.EmailID], record)
} }
return itemMap,len(emailSends), nil return itemMap, len(emailSends), nil
} }
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailSendLogDao struct { type emailSendLogDao struct {
*odao.ODao[models.EmailSendLog] *odao.ODao[models.EmailSendLog]
} }
var EmailSendLogDao = &emailSendLogDao{ var EmailSendLogDao = &emailSendLogDao{}
ODao: odao.NewDao[models.EmailSendLog](consts.Schema_operator),
}
func init() {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
EmailSendLogDao.ODao.Cache = cache.NewEmailSendLogCache(database.GetCacheType())
})
}
func (x *emailSendLogDao) GetSliceByState(ctx context.Context, order string, state enums.EmailSendLog_State_Enum) ([]*models.EmailSendLog, error) { func (x *emailSendLogDao) GetSliceByState(ctx context.Context, order string, state enums.EmailSendLog_State_Enum) ([]*models.EmailSendLog, error) {
return x.GetOrderSliceByWhere(ctx, order, "state = ?", state) return x.GetOrderSliceByWhere(ctx, order, "state = ?", state)
} }
func (x *emailSendLogDao) GetSliceByStates(ctx context.Context, order string, states []enums.EmailSendLog_State_Enum) ([]*models.EmailSendLog, error) { func (x *emailSendLogDao) GetSliceByStates(ctx context.Context, order string, states []enums.EmailSendLog_State_Enum) ([]*models.EmailSendLog, error) {
if len(states) == 0{ if len(states) == 0 {
return nil,nil return nil, nil
} }
return x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states) return x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states)
} }
func (x *emailSendLogDao) GetMapSliceByStates(ctx context.Context, order string, states []enums.EmailSendLog_State_Enum) (map[enums.EmailSendLog_State_Enum][]*models.EmailSendLog,int, error) {
if len(states) == 0{
return nil,0,nil
}
emailSendLogs,err := x.GetOrderSliceByWhere(ctx, order, "state IN (?)", states)
if err != nil{
return nil,0,err
}
if len(emailSendLogs) == 0{
return nil,0,nil
}
emailSendLogMapSlice := make(map[enums.EmailSendLog_State_Enum][]*models.EmailSendLog)
for i:=range emailSendLogs{
emailSendLogMapSlice[emailSendLogs[i].State] = append(emailSendLogMapSlice[emailSendLogs[i].State],emailSendLogs[i])
}
return emailSendLogMapSlice,len(emailSendLogs),nil
}
func (x *emailSendLogDao) GetSliceByEmailSendID(ctx context.Context, order string, emailSendID xsf.ID) ([]*models.EmailSendLog, error) { func (x *emailSendLogDao) GetSliceByEmailSendID(ctx context.Context, order string, emailSendID xsf.ID) ([]*models.EmailSendLog, error) {
if emailSendID <= 0 { if emailSendID <= 0 {
return nil, nil return nil, nil
...@@ -64,24 +36,24 @@ func (x *emailSendLogDao) GetSliceByEmailSendIDs(ctx context.Context, order stri ...@@ -64,24 +36,24 @@ func (x *emailSendLogDao) GetSliceByEmailSendIDs(ctx context.Context, order stri
if len(emailSendIDs) == 0 { if len(emailSendIDs) == 0 {
return nil, nil return nil, nil
} }
emailSendLogs,err := x.GetOrderSliceByWhere(ctx, order, "email_send_id IN (?)", emailSendIDs) emailSendLogs, err := x.GetOrderSliceByWhere(ctx, order, "email_send_id IN (?)", emailSendIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return emailSendLogs, nil return emailSendLogs, nil
} }
func (x *emailSendLogDao) GetMapSliceByEmailSendIDs(ctx context.Context,order string, emailSendIDs []xsf.ID) (map[xsf.ID][]*models.EmailSendLog,int, error) { func (x *emailSendLogDao) GetMapSliceByEmailSendIDs(ctx context.Context, order string, emailSendIDs []xsf.ID) (map[xsf.ID][]*models.EmailSendLog, int, error) {
if len(emailSendIDs) == 0 { if len(emailSendIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emailSendLogs,err := x.GetOrderSliceByWhere(ctx, order, "email_send_id IN (?)", emailSendIDs) emailSendLogs, err := x.GetOrderSliceByWhere(ctx, order, "email_send_id IN (?)", emailSendIDs)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
itemMap := make(map[xsf.ID][]*models.EmailSendLog) itemMap := make(map[xsf.ID][]*models.EmailSendLog)
for _, record := range emailSendLogs { for _, record := range emailSendLogs {
itemMap[record.EmailSendID] = append(itemMap[record.EmailSendID], record) itemMap[record.EmailSendID] = append(itemMap[record.EmailSendID], record)
} }
return itemMap,len(emailSendLogs), nil return itemMap, len(emailSendLogs), nil
} }
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailTplDao struct { type emailTplDao struct {
*odao.ODao[models.EmailTpl] *odao.ODao[models.EmailTpl]
} }
var EmailTplDao = &emailTplDao{ var EmailTplDao = &emailTplDao{}
ODao: odao.NewDao[models.EmailTpl](consts.Schema_operator),
}
func init() { func (x *emailTplDao) GetByCode(ctx context.Context, code string) (*models.EmailTpl, error) {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) { if code == "" {
EmailTplDao.ODao.Cache = cache.NewEmailTplCache(database.GetCacheType()) return nil, nil
}) }
return x.GetByWhere(ctx, "code = ?", code)
} }
package dao package dao
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"operator-qt/internal/consts"
"operator-qt/internal/global"
) )
type emailTplReceiverDao struct { type emailTplReceiverDao struct {
*odao.ODao[models.EmailTplReceiver] *odao.ODao[models.EmailTplReceiver]
} }
var EmailTplReceiverDao = &emailTplReceiverDao{ var EmailTplReceiverDao = &emailTplReceiverDao{}
ODao: odao.NewDao[models.EmailTplReceiver](consts.Schema_operator),
}
func init() {
_ = global.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
EmailTplReceiverDao.ODao.Cache = cache.NewEmailTplReceiverCache(database.GetCacheType())
})
}
func (x *emailTplReceiverDao) GetSliceByTplID(ctx context.Context, order string, tplID xsf.ID) ([]*models.EmailTplReceiver, error) { func (x *emailTplReceiverDao) GetSliceByTplID(ctx context.Context, order string, tplID xsf.ID) ([]*models.EmailTplReceiver, error) {
if tplID <= 0 { if tplID <= 0 {
return nil, nil return nil, nil
...@@ -35,24 +24,24 @@ func (x *emailTplReceiverDao) GetSliceByTplIDs(ctx context.Context, order string ...@@ -35,24 +24,24 @@ func (x *emailTplReceiverDao) GetSliceByTplIDs(ctx context.Context, order string
if len(tplIDs) == 0 { if len(tplIDs) == 0 {
return nil, nil return nil, nil
} }
emailTplReceivers,err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs) emailTplReceivers, err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return emailTplReceivers, nil return emailTplReceivers, nil
} }
func (x *emailTplReceiverDao) GetMapSliceByTplIDs(ctx context.Context,order string, tplIDs []xsf.ID) (map[xsf.ID][]*models.EmailTplReceiver,int, error) { func (x *emailTplReceiverDao) GetMapSliceByTplIDs(ctx context.Context, order string, tplIDs []xsf.ID) (map[xsf.ID][]*models.EmailTplReceiver, int, error) {
if len(tplIDs) == 0 { if len(tplIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emailTplReceivers,err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs) emailTplReceivers, err := x.GetOrderSliceByWhere(ctx, order, "tpl_id IN (?)", tplIDs)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
itemMap := make(map[xsf.ID][]*models.EmailTplReceiver) itemMap := make(map[xsf.ID][]*models.EmailTplReceiver)
for _, record := range emailTplReceivers { for _, record := range emailTplReceivers {
itemMap[record.TplID] = append(itemMap[record.TplID], record) itemMap[record.TplID] = append(itemMap[record.TplID], record)
} }
return itemMap,len(emailTplReceivers), nil return itemMap, len(emailTplReceivers), nil
} }
package ecode package ecode
import "errors"
var (
ErrEmailReceiverNotFound = errors.New("email receiver not found")
ErrEmailReceiverAlreadyExists = errors.New("email receiver already exists")
ErrEmailSendLogNotFound = errors.New("email send log not found")
ErrEmailSendLogAlreadyExists = errors.New("email send log already exists")
ErrEmailSendNotFound = errors.New("email send not found")
ErrEmailSendAlreadyExists = errors.New("email send already exists")
ErrEmailTplNotFound = errors.New("email tpl not found")
ErrEmailTplAlreadyExists = errors.New("email tpl already exists")
ErrEmailTplReceiverNotFound = errors.New("email tpl receiver not found")
ErrEmailTplReceiverAlreadyExists = errors.New("email tpl receiver already exists")
ErrEmailNotFound = errors.New("email not found")
ErrEmailAlreadyExists = errors.New("email already exists")
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// email business-level http error codes.
// the emailNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailName = "邮件"
emailBaseCode = errcode.HCode(emailNO)
ErrEmailAlreadyExists = errcode.NewError(emailBaseCode+1, EmailName+"已存在")
ErrEmailCreate = errcode.NewError(emailBaseCode+2, "创建"+EmailName+"失败")
ErrEmailDeleteByID = errcode.NewError(emailBaseCode+3, "通过id删除"+EmailName+"失败")
ErrEmailUpdateByID = errcode.NewError(emailBaseCode+4, "通过id更新"+EmailName+"失败")
ErrEmailGetByID = errcode.NewError(emailBaseCode+5, "通过id查询"+EmailName+"失败")
ErrEmailPage = errcode.NewError(emailBaseCode+6, "分页查询"+EmailName+"失败")
ErrEmailDeleteByIDs = errcode.NewError(emailBaseCode+7, "通过ids删除"+EmailName+"失败")
ErrEmailGetSliceByCondition = errcode.NewError(emailBaseCode+8, "条件查询"+EmailName+"失败")
ErrEmailGetByIDs = errcode.NewError(emailBaseCode+9, "通过ids批量查询"+EmailName+"失败")
ErrEmailListByLastID = errcode.NewError(emailBaseCode+10, "通过lastID倒序查询"+EmailName+"失败")
ErrEmailNotFound = errcode.NewError(emailBaseCode+11,"未查询到"+EmailName)
ErrEmailExport = errcode.NewError(emailBaseCode+12,"导出"+EmailName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// emailReceiver business-level http error codes.
// the emailReceiverNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailReceiverName = "邮件收件人"
emailReceiverBaseCode = errcode.HCode(emailReceiverNO)
ErrEmailReceiverAlreadyExists = errcode.NewError(emailReceiverBaseCode+1, EmailReceiverName+"已存在")
ErrEmailReceiverCreate = errcode.NewError(emailReceiverBaseCode+2, "创建"+EmailReceiverName+"失败")
ErrEmailReceiverDeleteByID = errcode.NewError(emailReceiverBaseCode+3, "通过id删除"+EmailReceiverName+"失败")
ErrEmailReceiverUpdateByID = errcode.NewError(emailReceiverBaseCode+4, "通过id更新"+EmailReceiverName+"失败")
ErrEmailReceiverGetByID = errcode.NewError(emailReceiverBaseCode+5, "通过id查询"+EmailReceiverName+"失败")
ErrEmailReceiverPage = errcode.NewError(emailReceiverBaseCode+6, "分页查询"+EmailReceiverName+"失败")
ErrEmailReceiverDeleteByIDs = errcode.NewError(emailReceiverBaseCode+7, "通过ids删除"+EmailReceiverName+"失败")
ErrEmailReceiverGetSliceByCondition = errcode.NewError(emailReceiverBaseCode+8, "条件查询"+EmailReceiverName+"失败")
ErrEmailReceiverGetByIDs = errcode.NewError(emailReceiverBaseCode+9, "通过ids批量查询"+EmailReceiverName+"失败")
ErrEmailReceiverListByLastID = errcode.NewError(emailReceiverBaseCode+10, "通过lastID倒序查询"+EmailReceiverName+"失败")
ErrEmailReceiverNotFound = errcode.NewError(emailReceiverBaseCode+11,"未查询到"+EmailReceiverName)
ErrEmailReceiverExport = errcode.NewError(emailReceiverBaseCode+12,"导出"+EmailReceiverName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// emailSend business-level http error codes.
// the emailSendNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailSendName = "邮件发送"
emailSendBaseCode = errcode.HCode(emailSendNO)
ErrEmailSendAlreadyExists = errcode.NewError(emailSendBaseCode+1, EmailSendName+"已存在")
ErrEmailSendCreate = errcode.NewError(emailSendBaseCode+2, "创建"+EmailSendName+"失败")
ErrEmailSendDeleteByID = errcode.NewError(emailSendBaseCode+3, "通过id删除"+EmailSendName+"失败")
ErrEmailSendUpdateByID = errcode.NewError(emailSendBaseCode+4, "通过id更新"+EmailSendName+"失败")
ErrEmailSendGetByID = errcode.NewError(emailSendBaseCode+5, "通过id查询"+EmailSendName+"失败")
ErrEmailSendPage = errcode.NewError(emailSendBaseCode+6, "分页查询"+EmailSendName+"失败")
ErrEmailSendDeleteByIDs = errcode.NewError(emailSendBaseCode+7, "通过ids删除"+EmailSendName+"失败")
ErrEmailSendGetSliceByCondition = errcode.NewError(emailSendBaseCode+8, "条件查询"+EmailSendName+"失败")
ErrEmailSendGetByIDs = errcode.NewError(emailSendBaseCode+9, "通过ids批量查询"+EmailSendName+"失败")
ErrEmailSendListByLastID = errcode.NewError(emailSendBaseCode+10, "通过lastID倒序查询"+EmailSendName+"失败")
ErrEmailSendNotFound = errcode.NewError(emailSendBaseCode+11,"未查询到"+EmailSendName)
ErrEmailSendExport = errcode.NewError(emailSendBaseCode+12,"导出"+EmailSendName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// emailSendLog business-level http error codes.
// the emailSendLogNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailSendLogName = "邮件发送记录"
emailSendLogBaseCode = errcode.HCode(emailSendLogNO)
ErrEmailSendLogAlreadyExists = errcode.NewError(emailSendLogBaseCode+1, EmailSendLogName+"已存在")
ErrEmailSendLogCreate = errcode.NewError(emailSendLogBaseCode+2, "创建"+EmailSendLogName+"失败")
ErrEmailSendLogDeleteByID = errcode.NewError(emailSendLogBaseCode+3, "通过id删除"+EmailSendLogName+"失败")
ErrEmailSendLogUpdateByID = errcode.NewError(emailSendLogBaseCode+4, "通过id更新"+EmailSendLogName+"失败")
ErrEmailSendLogGetByID = errcode.NewError(emailSendLogBaseCode+5, "通过id查询"+EmailSendLogName+"失败")
ErrEmailSendLogPage = errcode.NewError(emailSendLogBaseCode+6, "分页查询"+EmailSendLogName+"失败")
ErrEmailSendLogDeleteByIDs = errcode.NewError(emailSendLogBaseCode+7, "通过ids删除"+EmailSendLogName+"失败")
ErrEmailSendLogGetSliceByCondition = errcode.NewError(emailSendLogBaseCode+8, "条件查询"+EmailSendLogName+"失败")
ErrEmailSendLogGetByIDs = errcode.NewError(emailSendLogBaseCode+9, "通过ids批量查询"+EmailSendLogName+"失败")
ErrEmailSendLogListByLastID = errcode.NewError(emailSendLogBaseCode+10, "通过lastID倒序查询"+EmailSendLogName+"失败")
ErrEmailSendLogNotFound = errcode.NewError(emailSendLogBaseCode+11,"未查询到"+EmailSendLogName)
ErrEmailSendLogExport = errcode.NewError(emailSendLogBaseCode+12,"导出"+EmailSendLogName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// emailTpl business-level http error codes.
// the emailTplNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailTplName = "邮件模板"
emailTplBaseCode = errcode.HCode(emailTplNO)
ErrEmailTplAlreadyExists = errcode.NewError(emailTplBaseCode+1, EmailTplName+"已存在")
ErrEmailTplCreate = errcode.NewError(emailTplBaseCode+2, "创建"+EmailTplName+"失败")
ErrEmailTplDeleteByID = errcode.NewError(emailTplBaseCode+3, "通过id删除"+EmailTplName+"失败")
ErrEmailTplUpdateByID = errcode.NewError(emailTplBaseCode+4, "通过id更新"+EmailTplName+"失败")
ErrEmailTplGetByID = errcode.NewError(emailTplBaseCode+5, "通过id查询"+EmailTplName+"失败")
ErrEmailTplPage = errcode.NewError(emailTplBaseCode+6, "分页查询"+EmailTplName+"失败")
ErrEmailTplDeleteByIDs = errcode.NewError(emailTplBaseCode+7, "通过ids删除"+EmailTplName+"失败")
ErrEmailTplGetSliceByCondition = errcode.NewError(emailTplBaseCode+8, "条件查询"+EmailTplName+"失败")
ErrEmailTplGetByIDs = errcode.NewError(emailTplBaseCode+9, "通过ids批量查询"+EmailTplName+"失败")
ErrEmailTplListByLastID = errcode.NewError(emailTplBaseCode+10, "通过lastID倒序查询"+EmailTplName+"失败")
ErrEmailTplNotFound = errcode.NewError(emailTplBaseCode+11,"未查询到"+EmailTplName)
ErrEmailTplExport = errcode.NewError(emailTplBaseCode+12,"导出"+EmailTplName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package ecode
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
)
// emailTplReceiver business-level http error codes.
// the emailTplReceiverNO value range is 1~100, if the same error code is used, it will cause panic.
var (
EmailTplReceiverName = "邮件模板收件人"
emailTplReceiverBaseCode = errcode.HCode(emailTplReceiverNO)
ErrEmailTplReceiverAlreadyExists = errcode.NewError(emailTplReceiverBaseCode+1, EmailTplReceiverName+"已存在")
ErrEmailTplReceiverCreate = errcode.NewError(emailTplReceiverBaseCode+2, "创建"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverDeleteByID = errcode.NewError(emailTplReceiverBaseCode+3, "通过id删除"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverUpdateByID = errcode.NewError(emailTplReceiverBaseCode+4, "通过id更新"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverGetByID = errcode.NewError(emailTplReceiverBaseCode+5, "通过id查询"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverPage = errcode.NewError(emailTplReceiverBaseCode+6, "分页查询"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverDeleteByIDs = errcode.NewError(emailTplReceiverBaseCode+7, "通过ids删除"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverGetSliceByCondition = errcode.NewError(emailTplReceiverBaseCode+8, "条件查询"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverGetByIDs = errcode.NewError(emailTplReceiverBaseCode+9, "通过ids批量查询"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverListByLastID = errcode.NewError(emailTplReceiverBaseCode+10, "通过lastID倒序查询"+EmailTplReceiverName+"失败")
ErrEmailTplReceiverNotFound = errcode.NewError(emailTplReceiverBaseCode+11,"未查询到"+EmailTplReceiverName)
ErrEmailTplReceiverExport = errcode.NewError(emailTplReceiverBaseCode+12,"导出"+EmailTplReceiverName+"失败")
// error codes are globally unique, adding 1 to the previous error code
)
package xemail package xemail
import ( import (
"crypto/rand" "bytes"
"context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"math/big" "io"
"regexp"
"text/template"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/dao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gorm.io/gorm"
"gopkg.in/gomail.v2" "gopkg.in/gomail.v2"
) )
// 配置结构体 (建议从环境变量或配置文件中读取) func NewEmail(from string, to []*models.EmailTplReceiver, subject string, body string, attachments []*config.Attachment, inlineImages map[string]string) *config.Email {
type Config struct { e := config.Email{
SMTPServer string From: from,
SMTPPort int Subject: subject,
SMTPUsername string Body: body,
SMTPPassword string Attachments: attachments,
FromEmail string InlineImages: inlineImages,
} }
for _, r := range to {
func GenerateVerificationCode(length int) (string, error) { name, email, err := extractEmailReceiver(r.Receiver)
code := ""
for i := 0; i < length; i++ {
num, err := rand.Int(rand.Reader, big.NewInt(10))
if err != nil { if err != nil {
return "", err logger.Error("extract email receiver err", logger.Err(err))
continue
} }
code += num.String() e.To = append(e.To, config.Receiver{
Email: email,
DisplayName: name,
})
} }
return code, nil return &e
} }
func SendVerificationCode(cfg Config, toEmail string, code string) error { func extractEmailReceiver(input string) (name, email string, err error) {
re := regexp.MustCompile(`^([^<]+)\s*<([^>]+)>$`)
matches := re.FindStringSubmatch(input)
if len(matches) != 3 {
return "", "", fmt.Errorf("无效的邮件格式")
}
name = matches[1]
name = regexp.MustCompile(`^\s+|\s+$`).ReplaceAllString(name, "")
email = matches[2]
return name, email, nil
}
func SendTLS(ctx context.Context, e *config.Email) error {
m := gomail.NewMessage() m := gomail.NewMessage()
m.SetHeader("From", cfg.FromEmail) m.SetAddressHeader("From", config.Cfg.Email, e.From)
m.SetHeader("To", toEmail) var toList []string
m.SetHeader("Subject", "[万桩严选商城]验证码") for _, r := range e.To {
m.SetBody("text/html", fmt.Sprintf(` toList = append(toList, m.FormatAddress(r.Email, r.DisplayName))
<html> }
<body> m.SetHeader("To", toList...)
<h3>验证码通知</h3> m.SetHeader("Subject", e.Subject)
<p>您的验证码是:<strong>%s</strong></p> if len(e.InlineImages) > 0 {
<p>有效期15分钟,请勿泄露给他人</p> m.SetBody("text/html", e.Body)
</body> for cid, filePath := range e.InlineImages {
</html> m.Embed(filePath, gomail.Rename(cid))
`, code)) }
} else {
m.SetBody("text/html", e.Body)
}
for _, att := range e.Attachments {
if att.FilePath != "" {
if att.ContentType != "" {
m.Attach(att.FilePath, gomail.Rename(att.Filename), gomail.SetHeader(map[string][]string{
"Content-Type": {att.ContentType},
}))
} else {
m.Attach(att.FilePath, gomail.Rename(att.Filename))
}
} else if len(att.Data) > 0 {
reader := bytes.NewReader(att.Data)
if att.ContentType != "" {
m.Attach(att.Filename, gomail.SetCopyFunc(func(w io.Writer) error {
_, err := io.Copy(w, reader)
return err
}), gomail.SetHeader(map[string][]string{
"Content-Type": {att.ContentType},
}))
} else {
m.Attach(att.Filename, gomail.SetCopyFunc(func(w io.Writer) error {
_, err := io.Copy(w, reader)
return err
}))
}
}
}
d := gomail.NewDialer( d := gomail.NewDialer(
cfg.SMTPServer, config.Cfg.SMTPServer,
cfg.SMTPPort, config.Cfg.SMTPPort,
cfg.SMTPUsername, config.Cfg.Email,
cfg.SMTPPassword, config.Cfg.Token,
) )
d.TLSConfig = &tls.Config{ServerName: cfg.SMTPServer} d.TLSConfig = &tls.Config{
d.SSL = false ServerName: config.Cfg.SMTPServer,
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: false,
}
d.SSL = true
if err := d.DialAndSend(m); err != nil { if err := d.DialAndSend(m); err != nil {
return xerror.New(err.Error()) return xerror.New(err.Error())
} }
return nil return nil
} }
type oEmail struct {
}
var OEmail = &oEmail{}
//
//func (x *oEmail) SendAsync(ctx context.Context, tplCode string, params map[string]string, cfg *Config) (err error) {
// et, err := service.EmailTplService.GetByCode(ctx, tplCode, nil)
// if err != nil {
// return err
// }
// if et == nil {
// return xerror.NewC(ecode.ErrEmailTplNotFound.ToXerror())
// }
// rs, err := service.EmailTplReceiverService.GetSliceByTplID(ctx, et.GetID(), nil)
// if err != nil {
// return err
// }
// if len(rs) == 0 {
// return xerror.NewC(ecode.ErrEmailTplReceiverNotFound.ToXerror())
// }
//
// subjectTpl, err := template.New(fmt.Sprintf("%s_%s_subject", tplCode, et.GetID())).Parse(et.Subject)
// if err != nil {
// return xerror.Wrap(err, "parse subjectTpl")
// }
// var subjectBuf bytes.Buffer
// if err = subjectTpl.Execute(&subjectBuf, params); err != nil {
// return xerror.Wrap(err, "render subjectTpl")
// }
// contentTpl, err := template.New(fmt.Sprintf("%s_%s_content", tplCode, et.GetID())).Parse(et.Tpl)
// if err != nil {
// return xerror.Wrap(err, "parse contentTpl")
// }
// var contentBuf bytes.Buffer
// if err = contentTpl.Execute(&contentBuf, params); err != nil {
// return xerror.Wrap(err, "render contentTpl")
// }
//
// from := fmt.Sprintf("%s<%s>", cfg.Name, cfg.Email)
// email := models.Email{}
// email.ID = xsfUtils.EmailID(ctx)
// email.TplID = et.ID
// email.From = from
// email.Subject = subjectBuf.String()
// email.Content = contentBuf.String()
//
// receivers := make([]*models.EmailReceiver, 0, len(rs))
// for _, r := range rs {
// receivers = append(receivers, &models.EmailReceiver{
// EmailID: email.ID,
// Receiver: r.Receiver,
// })
// }
//
// emailSend := models.EmailSend{}
// emailSend.ID = xsfUtils.EmailSendID(ctx)
// emailSend.EmailID = email.ID
// emailSend.State = enums.EmailSend_State_Wait
//
// emailSendLog := models.EmailSendLog{}
// emailSendLog.ID = xsfUtils.EmailSendLogID(ctx)
// emailSendLog.EmailSendID = emailSend.ID
// emailSendLog.State = emailSend.State
//
// if err := dao.EmailDao.Transaction(func(tx *gorm.DB) error {
// if err = dao.EmailDao.CreateTx(ctx, tx, &email); err != nil {
// return err
// }
// if err = dao.EmailReceiverDao.CreateSliceTx(ctx, tx, receivers); err != nil {
// return err
// }
// if err = dao.EmailSendDao.CreateTx(ctx, tx, &emailSend); err != nil {
// return err
// }
// if err = dao.EmailSendLogDao.CreateTx(ctx, tx, &emailSendLog); err != nil {
// return err
// }
// return nil
// }); err != nil {
// return xerror.New(err.Error())
// }
//
// return nil
//}
func (x *oEmail) SendTLS(ctx context.Context, tplCode string, params map[string]string, attachments []*config.Attachment, inlineImages map[string]string) (err error) {
et, err := service.EmailTplService.GetByCode(ctx, tplCode, nil)
if err != nil {
return err
}
if et == nil {
return ecode.ErrEmailTplNotFound
}
rs, err := service.EmailTplReceiverService.GetSliceByTplID(ctx, et.GetID(), nil)
if err != nil {
return err
}
if len(rs) == 0 {
return ecode.ErrEmailTplReceiverNotFound
}
subjectTpl, err := template.New(fmt.Sprintf("%s_%s_subject", tplCode, et.GetID())).Parse(et.Subject)
if err != nil {
return xerror.Wrap(err, "parse subjectTpl")
}
var subjectBuf bytes.Buffer
if err = subjectTpl.Execute(&subjectBuf, params); err != nil {
return xerror.Wrap(err, "render subjectTpl")
}
contentTpl, err := template.New(fmt.Sprintf("%s_%s_content", tplCode, et.GetID())).Parse(et.Tpl)
if err != nil {
return xerror.Wrap(err, "parse contentTpl")
}
var contentBuf bytes.Buffer
if err = contentTpl.Execute(&contentBuf, params); err != nil {
return xerror.Wrap(err, "render contentTpl")
}
from := fmt.Sprintf("%s<%s>", config.Cfg.Name, config.Cfg.Email)
email := models.Email{}
email.ID = xsfUtils.EmailID(ctx)
email.TplID = et.ID
email.From = from
email.Subject = subjectBuf.String()
email.Content = contentBuf.String()
receivers := make([]*models.EmailReceiver, 0, len(rs))
tplReceivers := make([]*models.EmailTplReceiver, 0, len(rs))
for _, r := range rs {
receivers = append(receivers, &models.EmailReceiver{
EmailID: email.ID,
Receiver: r.Receiver,
})
tplReceivers = append(tplReceivers, &models.EmailTplReceiver{
TplID: r.ID,
Receiver: r.Receiver,
})
}
emailSend := models.EmailSend{}
emailSend.ID = xsfUtils.EmailSendID(ctx)
emailSend.EmailID = email.ID
emailSend.State = enums.EmailSend_State_Wait
emailSendLog := models.EmailSendLog{}
emailSendLog.ID = xsfUtils.EmailSendLogID(ctx)
emailSendLog.EmailSendID = emailSend.ID
emailSendLog.State = emailSend.State
e := NewEmail(email.From, tplReceivers, email.Subject, email.Content, attachments, inlineImages)
if err := SendTLS(ctx, e); err != nil {
return err
}
emailSend.State = enums.EmailSend_State_Success
emailSendLog.State = emailSend.State
if err := dao.EmailDao.Transaction(func(tx *gorm.DB) error {
if err = dao.EmailDao.CreateTx(ctx, tx, &email); err != nil {
return err
}
if err = dao.EmailReceiverDao.CreateSliceTx(ctx, tx, receivers); err != nil {
return err
}
if err = dao.EmailSendDao.CreateTx(ctx, tx, &emailSend); err != nil {
return err
}
if err = dao.EmailSendLogDao.CreateTx(ctx, tx, &emailSendLog); err != nil {
return err
}
return nil
}); err != nil {
return xerror.New(err.Error())
}
return nil
}
drop table if exists `email_tpl`;
CREATE TABLE `email_tpl` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`code` tinyint(8) DEFAULT NULL COMMENT '模板代码 eg[SMS_NOTICE]',
`subject` varchar(255) default NULL COMMENT '主题 eg[验证码]',
`tpl` text default NULL COMMENT '模板 eg[<div>hello moon! </div>]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`),
KEY `idx_code` (`code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件模板';
drop table if exists `email_tpl_receiver`;
CREATE TABLE `email_tpl_receiver` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`tpl_id` bigint(20) NOT NULL COMMENT '模板id eg[1]',
`receiver` varchar(255) DEFAULT NULL COMMENT '收件人 eg[月饼<mooncake2026@163.com>]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`),
KEY `idx_tpl_id` (`tpl_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件模板收件人';
drop table if exists `email`;
CREATE TABLE `email` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`tpl_id` bigint(20) NOT NULL COMMENT '模板id eg[1]',
`from` varchar(255) DEFAULT NULL COMMENT '发件人 eg[月饼<mooncake2026@163.com>]',
`content` text default NULL COMMENT '邮件内容 eg[<div>hello moon! </div>]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`),
KEY `idx_from` (`from`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件';
drop table if exists `email_receiver`;
CREATE TABLE `email_receiver` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`email_id` bigint(20) NOT NULL COMMENT '邮件id eg[1]',
`receiver` varchar(255) DEFAULT NULL COMMENT '收件人 eg[月饼<mooncake2026@163.com>]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`),
KEY `idx_email_id` (`email_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件收件人';
drop table if exists `email_send`;
CREATE TABLE `email_send` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`email_id` bigint(20) NOT NULL COMMENT '邮件id eg[1]',
`state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '发送状态 enums[0.Unknown.未知 1.Wait.待处理 2.Doing.处理中 3.Success.成功 4.Fail.失败 ] eg[1]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件发送';
drop table if exists `email_send_log`;
CREATE TABLE `email_send_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户主键id eg[1]',
`email_send_id` bigint(20) NOT NULL COMMENT '邮件发送id eg[1]',
`state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '发送状态 enums[0.Unknown.未知 1.Wait.待处理 2.Doing.处理中 3.Success.成功 4.Fail.失败 ] eg[1]',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 eg[2024-03-27 17:11:00]',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间 eg[2024-03-27 17:11:00]',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='邮件发送记录';
\ No newline at end of file
package enums package enums
type EmailSend_State_Enum int8
func init() { var (
pdict.Add("operator_emailSend_state", EmailSend_State_Enums_Dict)
mdict.Add("emailSend_state", EmailSend_State_Enums_Dict)
}
type EmailSend_State_Enum int8
var (
EmailSend_State_Unknown EmailSend_State_Enum = 0 // 未知 EmailSend_State_Unknown EmailSend_State_Enum = 0 // 未知
EmailSend_State_Wait EmailSend_State_Enum = 1 // 待处理 EmailSend_State_Wait EmailSend_State_Enum = 1 // 待处理
EmailSend_State_Doing EmailSend_State_Enum = 2 // 处理中 EmailSend_State_Doing EmailSend_State_Enum = 2 // 处理中
...@@ -26,8 +22,9 @@ func init() { ...@@ -26,8 +22,9 @@ func init() {
EmailSend_State_Success: EmailSend_State_Success.Desc(), EmailSend_State_Success: EmailSend_State_Success.Desc(),
EmailSend_State_Fail: EmailSend_State_Fail.Desc(), EmailSend_State_Fail: EmailSend_State_Fail.Desc(),
} }
) )
func (x EmailSend_State_Enum) Desc() string {
func (x EmailSend_State_Enum) Desc() string {
desc := "未知" desc := "未知"
switch x { switch x {
case EmailSend_State_Unknown: case EmailSend_State_Unknown:
...@@ -42,4 +39,4 @@ func init() { ...@@ -42,4 +39,4 @@ func init() {
desc = "失败" desc = "失败"
} }
return desc return desc
} }
package enums package enums
type EmailSendLog_State_Enum int8
func init() { var (
pdict.Add("operator_emailSendLog_state", EmailSendLog_State_Enums_Dict)
mdict.Add("emailSendLog_state", EmailSendLog_State_Enums_Dict)
}
type EmailSendLog_State_Enum int8
var (
EmailSendLog_State_Unknown EmailSendLog_State_Enum = 0 // 未知 EmailSendLog_State_Unknown EmailSendLog_State_Enum = 0 // 未知
EmailSendLog_State_Wait EmailSendLog_State_Enum = 1 // 待处理 EmailSendLog_State_Wait EmailSendLog_State_Enum = 1 // 待处理
EmailSendLog_State_Doing EmailSendLog_State_Enum = 2 // 处理中 EmailSendLog_State_Doing EmailSendLog_State_Enum = 2 // 处理中
...@@ -26,8 +22,9 @@ func init() { ...@@ -26,8 +22,9 @@ func init() {
EmailSendLog_State_Success: EmailSendLog_State_Success.Desc(), EmailSendLog_State_Success: EmailSendLog_State_Success.Desc(),
EmailSendLog_State_Fail: EmailSendLog_State_Fail.Desc(), EmailSendLog_State_Fail: EmailSendLog_State_Fail.Desc(),
} }
) )
func (x EmailSendLog_State_Enum) Desc() string {
func (x EmailSendLog_State_Enum) Desc() string {
desc := "未知" desc := "未知"
switch x { switch x {
case EmailSendLog_State_Unknown: case EmailSendLog_State_Unknown:
...@@ -42,4 +39,4 @@ func init() { ...@@ -42,4 +39,4 @@ func init() {
desc = "失败" desc = "失败"
} }
return desc return desc
} }
package xemail package xemail
import (
"context"
"github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
econfig "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/dao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
)
func init() {
_ = eventbus.Eb.Subscribe(eventbus.TopicParseConfFinish, func(ctx context.Context) {
config.Read(func(c *config.Config) {
_ = copier.Copy(econfig.Cfg, &c.Email)
})
})
_ = eventbus.Eb.Subscribe(eventbus.TopicDBInitFinish, func(ctx context.Context) {
dao.EmailDao.ODao = odao.NewDao[models.Email](econfig.Cfg.Schema)
dao.EmailReceiverDao.ODao = odao.NewDao[models.EmailReceiver](econfig.Cfg.Schema)
dao.EmailSendDao.ODao = odao.NewDao[models.EmailSend](econfig.Cfg.Schema)
dao.EmailSendLogDao.ODao = odao.NewDao[models.EmailSendLog](econfig.Cfg.Schema)
dao.EmailTplDao.ODao = odao.NewDao[models.EmailTpl](econfig.Cfg.Schema)
dao.EmailTplReceiverDao.ODao = odao.NewDao[models.EmailTplReceiver](econfig.Cfg.Schema)
})
_ = eventbus.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
dao.EmailDao.ODao = odao.NewDao[models.Email](econfig.Cfg.Schema)
dao.EmailReceiverDao.ODao = odao.NewDao[models.EmailReceiver](econfig.Cfg.Schema)
dao.EmailSendDao.ODao = odao.NewDao[models.EmailSend](econfig.Cfg.Schema)
dao.EmailSendLogDao.ODao = odao.NewDao[models.EmailSendLog](econfig.Cfg.Schema)
dao.EmailTplDao.ODao = odao.NewDao[models.EmailTpl](econfig.Cfg.Schema)
dao.EmailTplReceiverDao.ODao = odao.NewDao[models.EmailTplReceiver](econfig.Cfg.Schema)
})
_ = eventbus.Eb.Subscribe(eventbus.TopicConfChange, func(ctx context.Context) {
config.Read(func(c *config.Config) {
_ = copier.Copy(config.Cfg, &c.Email)
})
})
}
package models package models
import ( import (
"gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"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"
"gorm.io/gorm"
) )
//Email 邮件 // Email 邮件
type Email struct { type Email struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" gorm:"column:tpl_id;type:bigint(20);comment:模板id" example:"1" csv:"模板id"` //模板id TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" gorm:"column:tpl_id;type:bigint(20);comment:模板id" example:"1" csv:"模板id"` //模板id
Subject string `json:"subject" form:"subject" gorm:"column:subject;type:varchar(255);comment:主题" example:"验证码" csv:"subject"` //主题
From string `json:"from" form:"from" gorm:"column:from;type:varchar(255);comment:发件人" example:"月饼<mooncake2026@163.com>" csv:"发件人"` //发件人 From string `json:"from" form:"from" gorm:"column:from;type:varchar(255);comment:发件人" example:"月饼<mooncake2026@163.com>" csv:"发件人"` //发件人
Content string `json:"content" form:"content" gorm:"column:content;type:text;comment:邮件内容" example:"<div>hello moon! </div>" csv:"邮件内容"` //邮件内容 Content string `json:"content" form:"content" gorm:"column:content;type:text;comment:邮件内容" example:"<div>hello moon! </div>" csv:"邮件内容"` //邮件内容
CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间 CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间
...@@ -22,20 +24,20 @@ func (Email) TableName() string { ...@@ -22,20 +24,20 @@ func (Email) TableName() string {
return TBEmail return TBEmail
} }
func (x Email) GetID() xsf.ID{ func (x Email) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x *Email) GetTplID() xsf.ID{ 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())
} }
return set.Slice() return set.Slice()
} }
func (x Email) GetOrder() string{ func (x Email) GetOrder() string {
return "id asc" return "id asc"
} }
......
package models package models
import ( import (
"gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"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"
"gorm.io/gorm"
) )
//EmailReceiver 邮件收件人 // EmailReceiver 邮件收件人
type EmailReceiver struct { type EmailReceiver struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" gorm:"column:email_id;type:bigint(20);comment:邮件id" example:"1" csv:"邮件id"` //邮件id EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" gorm:"column:email_id;type:bigint(20);comment:邮件id" example:"1" csv:"邮件id"` //邮件id
...@@ -21,20 +22,20 @@ func (EmailReceiver) TableName() string { ...@@ -21,20 +22,20 @@ func (EmailReceiver) TableName() string {
return TBEmailReceiver return TBEmailReceiver
} }
func (x EmailReceiver) GetID() xsf.ID{ func (x EmailReceiver) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x *EmailReceiver) GetEmailID() xsf.ID{ 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())
} }
return set.Slice() return set.Slice()
} }
func (x EmailReceiver) GetOrder() string{ func (x EmailReceiver) GetOrder() string {
return "id asc" return "id asc"
} }
......
package models package models
import ( import (
"gorm.io/gorm" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm"
) )
//EmailSend 邮件发送 // EmailSend 邮件发送
type EmailSend struct { type EmailSend struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" gorm:"column:email_id;type:bigint(20);comment:邮件id" example:"1" csv:"邮件id"` //邮件id EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" gorm:"column:email_id;type:bigint(20);comment:邮件id" example:"1" csv:"邮件id"` //邮件id
...@@ -22,20 +23,20 @@ func (EmailSend) TableName() string { ...@@ -22,20 +23,20 @@ func (EmailSend) TableName() string {
return TBEmailSend return TBEmailSend
} }
func (x EmailSend) GetID() xsf.ID{ func (x EmailSend) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x *EmailSend) GetEmailID() xsf.ID{ 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())
} }
return set.Slice() return set.Slice()
} }
func (x EmailSend) GetOrder() string{ func (x EmailSend) GetOrder() string {
return "id asc" return "id asc"
} }
......
package models package models
import ( import (
"gorm.io/gorm" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm"
) )
//EmailSendLog 邮件发送记录 // EmailSendLog 邮件发送记录
type EmailSendLog struct { type EmailSendLog struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
EmailSendID xsf.ID `json:"emailSendID" form:"emailSendID" swaggertype:"string" gorm:"column:email_send_id;type:bigint(20);comment:邮件发送id" example:"1" csv:"邮件发送id"` //邮件发送id EmailSendID xsf.ID `json:"emailSendID" form:"emailSendID" swaggertype:"string" gorm:"column:email_send_id;type:bigint(20);comment:邮件发送id" example:"1" csv:"邮件发送id"` //邮件发送id
State enums.EmailSendLog_State_Enum `json:"state" form:"state" gorm:"column:state;type:tinyint(4);default:1;comment:发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]" example:"1" csv:"发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败] State enums.EmailSend_State_Enum `json:"state" form:"state" gorm:"column:state;type:tinyint(4);default:1;comment:发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]" example:"1" csv:"发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]
CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间 CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间
UpdatedAt xtime.DateTime `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;type:datetime;comment:更新时间" example:"2024-03-27 17:11:00" csv:"更新时间"` //更新时间 UpdatedAt xtime.DateTime `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;type:datetime;comment:更新时间" example:"2024-03-27 17:11:00" csv:"更新时间"` //更新时间
} }
...@@ -22,20 +23,20 @@ func (EmailSendLog) TableName() string { ...@@ -22,20 +23,20 @@ func (EmailSendLog) TableName() string {
return TBEmailSendLog return TBEmailSendLog
} }
func (x EmailSendLog) GetID() xsf.ID{ func (x EmailSendLog) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x *EmailSendLog) GetEmailSendID() xsf.ID{ 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())
} }
return set.Slice() return set.Slice()
} }
func (x EmailSendLog) GetOrder() string{ func (x EmailSendLog) GetOrder() string {
return "id asc" return "id asc"
} }
......
package models package models
import ( import (
"gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm"
) )
//EmailTpl 邮件模板 // EmailTpl 邮件模板
type EmailTpl struct { type EmailTpl struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
Code int `json:"code" form:"code" gorm:"column:code;type:tinyint(8);comment:模板代码" example:"SMS_NOTICE" csv:"模板代码"` //模板代码 Code string `json:"code" form:"code" gorm:"column:code;type:tinyint(8);comment:模板代码" example:"SMS_NOTICE" csv:"模板代码"` //模板代码
Subject string `json:"subject" form:"subject" gorm:"column:subject;type:varchar(255);comment:主题" example:"验证码" csv:"subject"` //主题
Tpl string `json:"tpl" form:"tpl" gorm:"column:tpl;type:text;comment:模板" example:"<div>hello moon! </div>" csv:"模板"` //模板 Tpl string `json:"tpl" form:"tpl" gorm:"column:tpl;type:text;comment:模板" example:"<div>hello moon! </div>" csv:"模板"` //模板
CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间 CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2024-03-27 17:11:00" csv:"创建时间"` //创建时间
UpdatedAt xtime.DateTime `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;type:datetime;comment:更新时间" example:"2024-03-27 17:11:00" csv:"更新时间"` //更新时间 UpdatedAt xtime.DateTime `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;type:datetime;comment:更新时间" example:"2024-03-27 17:11:00" csv:"更新时间"` //更新时间
...@@ -20,10 +22,10 @@ func (EmailTpl) TableName() string { ...@@ -20,10 +22,10 @@ func (EmailTpl) TableName() string {
return TBEmailTpl return TBEmailTpl
} }
func (x EmailTpl) GetID() xsf.ID{ func (x EmailTpl) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x EmailTpl) GetOrder() string{ func (x EmailTpl) GetOrder() string {
return "id asc" return "id asc"
} }
......
package models package models
import ( import (
"gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"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"
"gorm.io/gorm"
) )
//EmailTplReceiver 邮件模板收件人 // EmailTplReceiver 邮件模板收件人
type EmailTplReceiver struct { type EmailTplReceiver struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键 ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1" csv:"用户主键id"` //主键
TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" gorm:"column:tpl_id;type:bigint(20);comment:模板id" example:"1" csv:"模板id"` //模板id TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" gorm:"column:tpl_id;type:bigint(20);comment:模板id" example:"1" csv:"模板id"` //模板id
...@@ -21,20 +22,20 @@ func (EmailTplReceiver) TableName() string { ...@@ -21,20 +22,20 @@ func (EmailTplReceiver) TableName() string {
return TBEmailTplReceiver return TBEmailTplReceiver
} }
func (x EmailTplReceiver) GetID() xsf.ID{ func (x EmailTplReceiver) GetID() xsf.ID {
return x.ID return x.ID
} }
func (x *EmailTplReceiver) GetTplID() xsf.ID{ 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())
} }
return set.Slice() return set.Slice()
} }
func (x EmailTplReceiver) GetOrder() string{ func (x EmailTplReceiver) GetOrder() string {
return "id asc" return "id asc"
} }
......
package service package service
import (
"context"
"github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"time"
)
type commonService struct{}
func newCommonService() *commonService {
return &commonService{}
}
const (
batchSize = 2000
)
func csvName(ctx context.Context, tableName string) string {
if ctxUtils.GetCtxUID(ctx) > 0 {
return "csv/" + tableName + "" + cast.ToString(ctxUtils.GetCtxUID(ctx)) + "_" + time.Now().Format("20060102150405") + ".csv"
}
return "csv/" + tableName + "_" + time.Now().Format("20060102150405") + ".csv"
}
package service package service
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/biz"
"operator-qt/internal/ecode"
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"operator-qt/internal/modules/operator/dao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/dao"
xsfUtils "operator-qt/internal/modules/operator/utils/xsf_utils" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
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/xcommon"
) )
type emailService struct { type emailService struct {
...@@ -29,7 +29,7 @@ func newEmailService() *emailService { ...@@ -29,7 +29,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)
...@@ -49,22 +49,8 @@ func (x *emailService) DeleteByID(ctx context.Context, id xsf.ID, opts *biz.Emai ...@@ -49,22 +49,8 @@ func (x *emailService) DeleteByID(ctx context.Context, id xsf.ID, opts *biz.Emai
return dao.EmailDao.DeleteByID(ctx, id) return dao.EmailDao.DeleteByID(ctx, id)
} }
func (x *emailService) DeleteByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailOpts) error {
if len(ids) == 0{
return nil
}
emails, err := x.GetSliceByIDs(ctx, ids, opts)
if err != nil {
return err
}
if err = sliceUtils.CompareSlice(ids, emails, ecode.ErrEmailNotFound); err != nil {
return err
}
return dao.EmailDao.DeleteByIDs(ctx, ids)
}
func (x *emailService) UpdateByID(ctx context.Context, in *types.EmailUpdateByIDReq, opts *biz.EmailOpts) error { func (x *emailService) UpdateByID(ctx context.Context, in *types.EmailUpdateByIDReq, opts *biz.EmailOpts) error {
if in.ID <= 0{ if in.ID <= 0 {
return nil return nil
} }
if _, err := x.ErrNotFound(ctx, in.ID, opts); err != nil { if _, err := x.ErrNotFound(ctx, in.ID, opts); err != nil {
...@@ -72,26 +58,9 @@ func (x *emailService) UpdateByID(ctx context.Context, in *types.EmailUpdateByID ...@@ -72,26 +58,9 @@ func (x *emailService) UpdateByID(ctx context.Context, in *types.EmailUpdateByID
} }
emailUpd := &models.Email{} emailUpd := &models.Email{}
_ = copier.Copy(emailUpd, in) _ = copier.Copy(emailUpd, in)
return dao.EmailDao.UpdateByID(ctx, in.ID,emailUpd) return dao.EmailDao.UpdateByID(ctx, in.ID, emailUpd)
}
func (x *emailService) UpdateByIDs(ctx context.Context, in *types.EmailUpdateByIDsReq, opts *biz.EmailOpts) error {
if len(in.IDs) == 0 {
return nil
}
emails, err := x.GetSliceByIDs(ctx, in.IDs, opts)
if err != nil {
return err
}
if err = sliceUtils.CompareSlice(in.IDs, emails, ecode.ErrEmailNotFound); err != nil {
return err
}
emailUpd := &models.Email{}
_ = copier.Copy(emailUpd, in)
return dao.EmailDao.UpdateByIDs(ctx, in.IDs, emailUpd)
} }
func (x *emailService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailOpts) (emailBiz *biz.Email, err error) { func (x *emailService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailOpts) (emailBiz *biz.Email, err error) {
if id <= 0 { if id <= 0 {
return nil, nil return nil, nil
...@@ -101,7 +70,7 @@ func (x *emailService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailO ...@@ -101,7 +70,7 @@ func (x *emailService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailO
return nil, err return nil, err
} }
if emailBiz != nil { if emailBiz != nil {
return nil, xerror.NewC(ecode.ErrEmailAlreadyExists.ToXerror()) return nil, ecode.ErrEmailAlreadyExists
} }
return emailBiz, nil return emailBiz, nil
} }
...@@ -115,15 +84,14 @@ func (x *emailService) ErrNotFound(ctx context.Context, id xsf.ID, opts *biz.Ema ...@@ -115,15 +84,14 @@ func (x *emailService) ErrNotFound(ctx context.Context, id xsf.ID, opts *biz.Ema
return nil, err return nil, err
} }
if emailBiz == nil { if emailBiz == nil {
return nil, xerror.NewC(ecode.ErrEmailNotFound.ToXerror()) return nil, ecode.ErrEmailNotFound
} }
return emailBiz, nil return emailBiz, nil
} }
func (x *emailService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailOpts) (emailBiz *biz.Email, err error) {
func (x *emailService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailOpts) (emailBiz *biz.Email,err error) { if id <= 0 {
if id <= 0{ return nil, nil
return nil,nil
} }
email, err := dao.EmailDao.GetByID(ctx, id) email, err := dao.EmailDao.GetByID(ctx, id)
if err != nil { if err != nil {
...@@ -136,28 +104,28 @@ func (x *emailService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailOp ...@@ -136,28 +104,28 @@ func (x *emailService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailOp
} }
func (x *emailService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailOpts) ([]*biz.Email, error) { func (x *emailService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailOpts) ([]*biz.Email, error) {
if len(ids) == 0{ if len(ids) == 0 {
return nil, nil return nil, nil
} }
emails, err := dao.EmailDao.GetSliceByIDs(ctx, ids) emails, err := dao.EmailDao.GetSliceByIDs(ctx, ids)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emails) == 0{ if len(emails) == 0 {
return nil,nil return nil, nil
} }
return x.ToSliceBiz(ctx, emails, opts) return x.ToSliceBiz(ctx, emails, opts)
} }
func (x *emailService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailOpts) (map[xsf.ID]*biz.Email, error) { func (x *emailService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailOpts) (map[xsf.ID]*biz.Email, error) {
if len(ids) == 0{ if len(ids) == 0 {
return nil, nil return nil, nil
} }
emailBizSlice,err := x.GetSliceByIDs(ctx, ids, opts) emailBizSlice, err := x.GetSliceByIDs(ctx, ids, opts)
if err != nil{ if err != nil {
return nil,err return nil, err
} }
if len(emailBizSlice) == 0{ if len(emailBizSlice) == 0 {
return nil, nil return nil, nil
} }
emailBizIDMap := biz.EmailTool.SliceToIDMapBiz(emailBizSlice) emailBizIDMap := biz.EmailTool.SliceToIDMapBiz(emailBizSlice)
...@@ -169,8 +137,8 @@ func (x *emailService) Page(ctx context.Context, in *types.EmailPageReq, opts *b ...@@ -169,8 +137,8 @@ func (x *emailService) Page(ctx context.Context, in *types.EmailPageReq, opts *b
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
if len(emails) == 0{ if len(emails) == 0 {
return nil,total,nil return nil, total, nil
} }
emailBizSlice, err := x.ToSliceBiz(ctx, emails, opts) emailBizSlice, err := x.ToSliceBiz(ctx, emails, opts)
if err != nil { if err != nil {
...@@ -178,50 +146,50 @@ func (x *emailService) Page(ctx context.Context, in *types.EmailPageReq, opts *b ...@@ -178,50 +146,50 @@ func (x *emailService) Page(ctx context.Context, in *types.EmailPageReq, opts *b
} }
return emailBizSlice, total, nil return emailBizSlice, total, nil
} }
func (x *emailService) GetSliceByTplID(ctx context.Context, tplID xsf.ID,opts *biz.EmailOpts) ([]*biz.Email, error) { func (x *emailService) GetSliceByTplID(ctx context.Context, tplID xsf.ID, opts *biz.EmailOpts) ([]*biz.Email, error) {
if tplID == 0{ if tplID == 0 {
return nil, nil return nil, nil
} }
emails, err := dao.EmailDao.GetSliceByTplID(ctx, models.EmailTool.GetOrder(), tplID) emails, err := dao.EmailDao.GetSliceByTplID(ctx, models.EmailTool.GetOrder(), tplID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emails) == 0{ if len(emails) == 0 {
return nil, nil return nil, nil
} }
return x.ToSliceBiz(ctx, emails, opts) return x.ToSliceBiz(ctx, emails, opts)
} }
func (x *emailService) GetSliceByTplIDs(ctx context.Context,tplIDs []xsf.ID,opts *biz.EmailOpts) ([]*biz.Email, error) { func (x *emailService) GetSliceByTplIDs(ctx context.Context, tplIDs []xsf.ID, opts *biz.EmailOpts) ([]*biz.Email, error) {
if len(tplIDs) == 0{ if len(tplIDs) == 0 {
return nil, nil return nil, nil
} }
emails, err := dao.EmailDao.GetSliceByTplIDs(ctx,models.EmailTool.GetOrder(), tplIDs) emails, err := dao.EmailDao.GetSliceByTplIDs(ctx, models.EmailTool.GetOrder(), tplIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emails) == 0 { if len(emails) == 0 {
return nil,nil return nil, nil
} }
return x.ToSliceBiz(ctx, emails, opts) return x.ToSliceBiz(ctx, emails, opts)
} }
func (x *emailService) GetMapSliceByTplIDs(ctx context.Context, tplIDs []xsf.ID,opts *biz.EmailOpts) (map[xsf.ID][]*biz.Email, int, error) { func (x *emailService) GetMapSliceByTplIDs(ctx context.Context, tplIDs []xsf.ID, opts *biz.EmailOpts) (map[xsf.ID][]*biz.Email, int, error) {
if len(tplIDs) == 0{ if len(tplIDs) == 0 {
return nil,0, nil return nil, 0, nil
} }
emailBizSlice,err := x.GetSliceByTplIDs(ctx, tplIDs,opts) emailBizSlice, err := x.GetSliceByTplIDs(ctx, tplIDs, opts)
if err != nil { if err != nil {
return nil,0, err return nil, 0, err
} }
if len(emailBizSlice) == 0{ if len(emailBizSlice) == 0 {
return nil,0, nil return nil, 0, nil
} }
ret := make(map[xsf.ID][]*biz.Email) ret := make(map[xsf.ID][]*biz.Email)
for _,r := range emailBizSlice { for _, r := range emailBizSlice {
ret[r.TplID] = append(ret[r.TplID],r) ret[r.TplID] = append(ret[r.TplID], r)
} }
return ret,len(emailBizSlice), nil return ret, len(emailBizSlice), nil
} }
func (x *emailService) ToBiz(ctx context.Context, email *models.Email, opts *biz.EmailOpts) (emailBiz *biz.Email, err error) { func (x *emailService) ToBiz(ctx context.Context, email *models.Email, opts *biz.EmailOpts) (emailBiz *biz.Email, err error) {
...@@ -249,34 +217,35 @@ func (x *emailService) ToSliceBiz(ctx context.Context, emails []*models.Email, o ...@@ -249,34 +217,35 @@ func (x *emailService) ToSliceBiz(ctx context.Context, emails []*models.Email, o
return emailBizSlice, nil return emailBizSlice, nil
} }
func (x *emailService) Fill(ctx context.Context, emailBiz *biz.Email,opts *biz.EmailOpts) error { func (x *emailService) Fill(ctx context.Context, emailBiz *biz.Email, opts *biz.EmailOpts) error {
if emailBiz == nil { if emailBiz == nil {
return nil return nil
} }
if opts != nil{ if opts != nil {
} }
return nil return nil
} }
func (x *emailService) SliceFill(ctx context.Context, emailBizSlice []*biz.Email,opts *biz.EmailOpts) error { func (x *emailService) SliceFill(ctx context.Context, emailBizSlice []*biz.Email, opts *biz.EmailOpts) error {
if len(emailBizSlice) == 0 { if len(emailBizSlice) == 0 {
return nil return nil
} }
if opts != nil{ if opts != nil {
} }
return nil return nil
} }
func (x *emailService) GetAll(ctx context.Context,opts *biz.EmailOpts) ( []*biz.Email, error) { func (x *emailService) GetAll(ctx context.Context, opts *biz.EmailOpts) ([]*biz.Email, error) {
emails,err := dao.EmailDao.GetAll(ctx) emails, err := dao.EmailDao.GetAll(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emails) == 0{ if len(emails) == 0 {
return nil, nil return nil, nil
} }
return x.ToSliceBiz(ctx, emails, opts) return x.ToSliceBiz(ctx, emails, opts)
} }
func (x *emailService) ExportCSV(ctx context.Context, in *types.EmailExportReq, opts *biz.EmailOpts) (string, error) { func (x *emailService) ExportCSV(ctx context.Context, in *types.EmailExportReq, opts *biz.EmailOpts) (string, error) {
req := &types.EmailPageReq{} req := &types.EmailPageReq{}
_ = copier.Copy(req, in) _ = copier.Copy(req, in)
......
package service package service
import ( import (
"context" "context"
"operator-qt/internal/modules/operator/biz"
"operator-qt/internal/ecode"
"operator-qt/internal/modules/operator/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"operator-qt/internal/modules/operator/types"
"operator-qt/internal/modules/operator/dao"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/dao"
xsfUtils "operator-qt/internal/modules/operator/utils/xsf_utils" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
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/xcommon"
) )
type emailTplService struct { type emailTplService struct {
...@@ -29,7 +29,7 @@ func newEmailTplService() *emailTplService { ...@@ -29,7 +29,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)
...@@ -49,22 +49,8 @@ func (x *emailTplService) DeleteByID(ctx context.Context, id xsf.ID, opts *biz.E ...@@ -49,22 +49,8 @@ func (x *emailTplService) DeleteByID(ctx context.Context, id xsf.ID, opts *biz.E
return dao.EmailTplDao.DeleteByID(ctx, id) return dao.EmailTplDao.DeleteByID(ctx, id)
} }
func (x *emailTplService) DeleteByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailTplOpts) error {
if len(ids) == 0{
return nil
}
emailTpls, err := x.GetSliceByIDs(ctx, ids, opts)
if err != nil {
return err
}
if err = sliceUtils.CompareSlice(ids, emailTpls, ecode.ErrEmailTplNotFound); err != nil {
return err
}
return dao.EmailTplDao.DeleteByIDs(ctx, ids)
}
func (x *emailTplService) UpdateByID(ctx context.Context, in *types.EmailTplUpdateByIDReq, opts *biz.EmailTplOpts) error { func (x *emailTplService) UpdateByID(ctx context.Context, in *types.EmailTplUpdateByIDReq, opts *biz.EmailTplOpts) error {
if in.ID <= 0{ if in.ID <= 0 {
return nil return nil
} }
if _, err := x.ErrNotFound(ctx, in.ID, opts); err != nil { if _, err := x.ErrNotFound(ctx, in.ID, opts); err != nil {
...@@ -72,26 +58,9 @@ func (x *emailTplService) UpdateByID(ctx context.Context, in *types.EmailTplUpda ...@@ -72,26 +58,9 @@ func (x *emailTplService) UpdateByID(ctx context.Context, in *types.EmailTplUpda
} }
emailTplUpd := &models.EmailTpl{} emailTplUpd := &models.EmailTpl{}
_ = copier.Copy(emailTplUpd, in) _ = copier.Copy(emailTplUpd, in)
return dao.EmailTplDao.UpdateByID(ctx, in.ID,emailTplUpd) return dao.EmailTplDao.UpdateByID(ctx, in.ID, emailTplUpd)
}
func (x *emailTplService) UpdateByIDs(ctx context.Context, in *types.EmailTplUpdateByIDsReq, opts *biz.EmailTplOpts) error {
if len(in.IDs) == 0 {
return nil
}
emailTpls, err := x.GetSliceByIDs(ctx, in.IDs, opts)
if err != nil {
return err
}
if err = sliceUtils.CompareSlice(in.IDs, emailTpls, ecode.ErrEmailTplNotFound); err != nil {
return err
}
emailTplUpd := &models.EmailTpl{}
_ = copier.Copy(emailTplUpd, in)
return dao.EmailTplDao.UpdateByIDs(ctx, in.IDs, emailTplUpd)
} }
func (x *emailTplService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailTplOpts) (emailTplBiz *biz.EmailTpl, err error) { func (x *emailTplService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.EmailTplOpts) (emailTplBiz *biz.EmailTpl, err error) {
if id <= 0 { if id <= 0 {
return nil, nil return nil, nil
...@@ -101,7 +70,7 @@ func (x *emailTplService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.Ema ...@@ -101,7 +70,7 @@ func (x *emailTplService) ErrFound(ctx context.Context, id xsf.ID, opts *biz.Ema
return nil, err return nil, err
} }
if emailTplBiz != nil { if emailTplBiz != nil {
return nil, xerror.NewC(ecode.ErrEmailTplAlreadyExists.ToXerror()) return nil, ecode.ErrEmailTplAlreadyExists
} }
return emailTplBiz, nil return emailTplBiz, nil
} }
...@@ -115,15 +84,14 @@ func (x *emailTplService) ErrNotFound(ctx context.Context, id xsf.ID, opts *biz. ...@@ -115,15 +84,14 @@ func (x *emailTplService) ErrNotFound(ctx context.Context, id xsf.ID, opts *biz.
return nil, err return nil, err
} }
if emailTplBiz == nil { if emailTplBiz == nil {
return nil, xerror.NewC(ecode.ErrEmailTplNotFound.ToXerror()) return nil, ecode.ErrEmailTplNotFound
} }
return emailTplBiz, nil return emailTplBiz, nil
} }
func (x *emailTplService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailTplOpts) (emailTplBiz *biz.EmailTpl, err error) {
func (x *emailTplService) GetByID(ctx context.Context, id xsf.ID, opts *biz.EmailTplOpts) (emailTplBiz *biz.EmailTpl,err error) { if id <= 0 {
if id <= 0{ return nil, nil
return nil,nil
} }
emailTpl, err := dao.EmailTplDao.GetByID(ctx, id) emailTpl, err := dao.EmailTplDao.GetByID(ctx, id)
if err != nil { if err != nil {
...@@ -135,29 +103,43 @@ func (x *emailTplService) GetByID(ctx context.Context, id xsf.ID, opts *biz.Emai ...@@ -135,29 +103,43 @@ func (x *emailTplService) GetByID(ctx context.Context, id xsf.ID, opts *biz.Emai
return x.ToBiz(ctx, emailTpl, opts) return x.ToBiz(ctx, emailTpl, opts)
} }
func (x *emailTplService) GetByCode(ctx context.Context, code string, opts *biz.EmailTplOpts) (emailTplBiz *biz.EmailTpl, err error) {
if code == "" {
return nil, nil
}
emailTpl, err := dao.EmailTplDao.GetByCode(ctx, code)
if err != nil {
return nil, err
}
if emailTpl == nil {
return nil, nil
}
return x.ToBiz(ctx, emailTpl, opts)
}
func (x *emailTplService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailTplOpts) ([]*biz.EmailTpl, error) { func (x *emailTplService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailTplOpts) ([]*biz.EmailTpl, error) {
if len(ids) == 0{ if len(ids) == 0 {
return nil, nil return nil, nil
} }
emailTpls, err := dao.EmailTplDao.GetSliceByIDs(ctx, ids) emailTpls, err := dao.EmailTplDao.GetSliceByIDs(ctx, ids)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emailTpls) == 0{ if len(emailTpls) == 0 {
return nil,nil return nil, nil
} }
return x.ToSliceBiz(ctx, emailTpls, opts) return x.ToSliceBiz(ctx, emailTpls, opts)
} }
func (x *emailTplService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailTplOpts) (map[xsf.ID]*biz.EmailTpl, error) { func (x *emailTplService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *biz.EmailTplOpts) (map[xsf.ID]*biz.EmailTpl, error) {
if len(ids) == 0{ if len(ids) == 0 {
return nil, nil return nil, nil
} }
emailTplBizSlice,err := x.GetSliceByIDs(ctx, ids, opts) emailTplBizSlice, err := x.GetSliceByIDs(ctx, ids, opts)
if err != nil{ if err != nil {
return nil,err return nil, err
} }
if len(emailTplBizSlice) == 0{ if len(emailTplBizSlice) == 0 {
return nil, nil return nil, nil
} }
emailTplBizIDMap := biz.EmailTplTool.SliceToIDMapBiz(emailTplBizSlice) emailTplBizIDMap := biz.EmailTplTool.SliceToIDMapBiz(emailTplBizSlice)
...@@ -169,8 +151,8 @@ func (x *emailTplService) Page(ctx context.Context, in *types.EmailTplPageReq, o ...@@ -169,8 +151,8 @@ func (x *emailTplService) Page(ctx context.Context, in *types.EmailTplPageReq, o
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
if len(emailTpls) == 0{ if len(emailTpls) == 0 {
return nil,total,nil return nil, total, nil
} }
emailTplBizSlice, err := x.ToSliceBiz(ctx, emailTpls, opts) emailTplBizSlice, err := x.ToSliceBiz(ctx, emailTpls, opts)
if err != nil { if err != nil {
...@@ -204,30 +186,30 @@ func (x *emailTplService) ToSliceBiz(ctx context.Context, emailTpls []*models.Em ...@@ -204,30 +186,30 @@ func (x *emailTplService) ToSliceBiz(ctx context.Context, emailTpls []*models.Em
return emailTplBizSlice, nil return emailTplBizSlice, nil
} }
func (x *emailTplService) Fill(ctx context.Context, emailTplBiz *biz.EmailTpl,opts *biz.EmailTplOpts) error { func (x *emailTplService) Fill(ctx context.Context, emailTplBiz *biz.EmailTpl, opts *biz.EmailTplOpts) error {
if emailTplBiz == nil { if emailTplBiz == nil {
return nil return nil
} }
if opts != nil{ if opts != nil {
} }
return nil return nil
} }
func (x *emailTplService) SliceFill(ctx context.Context, emailTplBizSlice []*biz.EmailTpl,opts *biz.EmailTplOpts) error { func (x *emailTplService) SliceFill(ctx context.Context, emailTplBizSlice []*biz.EmailTpl, opts *biz.EmailTplOpts) error {
if len(emailTplBizSlice) == 0 { if len(emailTplBizSlice) == 0 {
return nil return nil
} }
if opts != nil{ if opts != nil {
} }
return nil return nil
} }
func (x *emailTplService) GetAll(ctx context.Context,opts *biz.EmailTplOpts) ( []*biz.EmailTpl, error) { func (x *emailTplService) GetAll(ctx context.Context, opts *biz.EmailTplOpts) ([]*biz.EmailTpl, error) {
emailTpls,err := dao.EmailTplDao.GetAll(ctx) emailTpls, err := dao.EmailTplDao.GetAll(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(emailTpls) == 0{ if len(emailTpls) == 0 {
return nil, nil return nil, nil
} }
return x.ToSliceBiz(ctx, emailTpls, opts) return x.ToSliceBiz(ctx, emailTpls, opts)
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailCreateReq request params 邮件 // EmailCreateReq request params 邮件
...@@ -18,11 +20,12 @@ type EmailCreateReq struct { ...@@ -18,11 +20,12 @@ type EmailCreateReq struct {
} }
func (x *EmailCreateReq) Valid() error { func (x *EmailCreateReq) Valid() error {
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
} }
// EmailGetByTplIDReq request params // EmailGetByTplIDReq request params
type EmailGetByTplIDReq struct { type EmailGetByTplIDReq struct {
TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" validate:"required" example:"1"` //模板id TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" validate:"required" example:"1"` //模板id
...@@ -47,7 +50,7 @@ func (x *EmailUpdateByIDReq) Valid() error { ...@@ -47,7 +50,7 @@ func (x *EmailUpdateByIDReq) Valid() error {
if x.ID <= 0 { if x.ID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法")
} }
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
...@@ -65,7 +68,7 @@ func (x *EmailUpdateByIDsReq) Valid() error { ...@@ -65,7 +68,7 @@ func (x *EmailUpdateByIDsReq) Valid() error {
if len(x.IDs) == 0 { if len(x.IDs) == 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空") return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空")
} }
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
...@@ -114,7 +117,6 @@ func (EmailExportReq) TableName() string { ...@@ -114,7 +117,6 @@ func (EmailExportReq) TableName() string {
type EmailObjDetail struct { type EmailObjDetail struct {
biz.Email biz.Email
} }
var EmailObjDetailTool = EmailObjDetail{} var EmailObjDetailTool = EmailObjDetail{}
...@@ -124,7 +126,7 @@ func (x EmailObjDetail) NewFromBiz(emailBiz *biz.Email) *EmailObjDetail { ...@@ -124,7 +126,7 @@ func (x EmailObjDetail) NewFromBiz(emailBiz *biz.Email) *EmailObjDetail {
return nil return nil
} }
return &EmailObjDetail{ return &EmailObjDetail{
Email:*emailBiz, Email: *emailBiz,
} }
} }
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailReceiverCreateReq request params 邮件收件人 // EmailReceiverCreateReq request params 邮件收件人
...@@ -17,11 +19,12 @@ type EmailReceiverCreateReq struct { ...@@ -17,11 +19,12 @@ type EmailReceiverCreateReq struct {
} }
func (x *EmailReceiverCreateReq) Valid() error { func (x *EmailReceiverCreateReq) Valid() error {
if x.EmailID <= 0{ if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
return nil return nil
} }
// EmailReceiverGetByEmailIDReq request params // EmailReceiverGetByEmailIDReq request params
type EmailReceiverGetByEmailIDReq struct { type EmailReceiverGetByEmailIDReq struct {
EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" validate:"required" example:"1"` //邮件id EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" validate:"required" example:"1"` //邮件id
...@@ -45,7 +48,7 @@ func (x *EmailReceiverUpdateByIDReq) Valid() error { ...@@ -45,7 +48,7 @@ func (x *EmailReceiverUpdateByIDReq) Valid() error {
if x.ID <= 0 { if x.ID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法")
} }
if x.EmailID <= 0{ if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
return nil return nil
...@@ -62,7 +65,7 @@ func (x *EmailReceiverUpdateByIDsReq) Valid() error { ...@@ -62,7 +65,7 @@ func (x *EmailReceiverUpdateByIDsReq) Valid() error {
if len(x.IDs) == 0 { if len(x.IDs) == 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空") return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空")
} }
if x.EmailID <= 0{ if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
} }
return nil return nil
...@@ -109,7 +112,6 @@ func (EmailReceiverExportReq) TableName() string { ...@@ -109,7 +112,6 @@ func (EmailReceiverExportReq) TableName() string {
type EmailReceiverObjDetail struct { type EmailReceiverObjDetail struct {
biz.EmailReceiver biz.EmailReceiver
} }
var EmailReceiverObjDetailTool = EmailReceiverObjDetail{} var EmailReceiverObjDetailTool = EmailReceiverObjDetail{}
...@@ -119,7 +121,7 @@ func (x EmailReceiverObjDetail) NewFromBiz(emailReceiverBiz *biz.EmailReceiver) ...@@ -119,7 +121,7 @@ func (x EmailReceiverObjDetail) NewFromBiz(emailReceiverBiz *biz.EmailReceiver)
return nil return nil
} }
return &EmailReceiverObjDetail{ return &EmailReceiverObjDetail{
EmailReceiver:*emailReceiverBiz, EmailReceiver: *emailReceiverBiz,
} }
} }
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/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/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailSendCreateReq request params 邮件发送 // EmailSendCreateReq request params 邮件发送
...@@ -19,7 +21,7 @@ type EmailSendCreateReq struct { ...@@ -19,7 +21,7 @@ type EmailSendCreateReq struct {
} }
func (x *EmailSendCreateReq) Valid() error { 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) {
...@@ -27,6 +29,7 @@ func (x *EmailSendCreateReq) Valid() error { ...@@ -27,6 +29,7 @@ func (x *EmailSendCreateReq) Valid() error {
} }
return nil return nil
} }
// EmailSendGetByEmailIDReq request params // EmailSendGetByEmailIDReq request params
type EmailSendGetByEmailIDReq struct { type EmailSendGetByEmailIDReq struct {
EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" validate:"required" example:"1"` //邮件id EmailID xsf.ID `json:"emailID" form:"emailID" swaggertype:"string" validate:"required" example:"1"` //邮件id
...@@ -38,6 +41,7 @@ func (x *EmailSendGetByEmailIDReq) Valid() error { ...@@ -38,6 +41,7 @@ func (x *EmailSendGetByEmailIDReq) Valid() error {
} }
return nil return nil
} }
// EmailSendGetByStateReq request params // EmailSendGetByStateReq request params
type EmailSendGetByStateReq struct { type EmailSendGetByStateReq struct {
State enums.EmailSend_State_Enum `json:"state" form:"state" validate:"required" example:"1"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败] State enums.EmailSend_State_Enum `json:"state" form:"state" validate:"required" example:"1"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]
...@@ -61,7 +65,7 @@ func (x *EmailSendUpdateByIDReq) Valid() error { ...@@ -61,7 +65,7 @@ func (x *EmailSendUpdateByIDReq) Valid() error {
if x.ID <= 0 { if x.ID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法")
} }
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) {
...@@ -81,7 +85,7 @@ func (x *EmailSendUpdateByIDsReq) Valid() error { ...@@ -81,7 +85,7 @@ func (x *EmailSendUpdateByIDsReq) Valid() error {
if len(x.IDs) == 0 { if len(x.IDs) == 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空") return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空")
} }
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) {
...@@ -142,7 +146,7 @@ func (x EmailSendObjDetail) NewFromBiz(emailSendBiz *biz.EmailSend) *EmailSendOb ...@@ -142,7 +146,7 @@ func (x EmailSendObjDetail) NewFromBiz(emailSendBiz *biz.EmailSend) *EmailSendOb
return nil return nil
} }
return &EmailSendObjDetail{ return &EmailSendObjDetail{
EmailSend:*emailSendBiz, EmailSend: *emailSendBiz,
StateZh: emailSendBiz.State.Desc(), StateZh: emailSendBiz.State.Desc(),
} }
} }
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/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/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"operator-qt/internal/modules/operator/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailSendLogCreateReq request params 邮件发送记录 // EmailSendLogCreateReq request params 邮件发送记录
...@@ -19,7 +21,7 @@ type EmailSendLogCreateReq struct { ...@@ -19,7 +21,7 @@ type EmailSendLogCreateReq struct {
} }
func (x *EmailSendLogCreateReq) Valid() error { 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) {
...@@ -27,6 +29,7 @@ func (x *EmailSendLogCreateReq) Valid() error { ...@@ -27,6 +29,7 @@ func (x *EmailSendLogCreateReq) Valid() error {
} }
return nil return nil
} }
// EmailSendLogGetByEmailSendIDReq request params // EmailSendLogGetByEmailSendIDReq request params
type EmailSendLogGetByEmailSendIDReq struct { type EmailSendLogGetByEmailSendIDReq struct {
EmailSendID xsf.ID `json:"emailSendID" form:"emailSendID" swaggertype:"string" validate:"required" example:"1"` //邮件发送id EmailSendID xsf.ID `json:"emailSendID" form:"emailSendID" swaggertype:"string" validate:"required" example:"1"` //邮件发送id
...@@ -38,6 +41,7 @@ func (x *EmailSendLogGetByEmailSendIDReq) Valid() error { ...@@ -38,6 +41,7 @@ func (x *EmailSendLogGetByEmailSendIDReq) Valid() error {
} }
return nil return nil
} }
// EmailSendLogGetByStateReq request params // EmailSendLogGetByStateReq request params
type EmailSendLogGetByStateReq struct { type EmailSendLogGetByStateReq struct {
State enums.EmailSendLog_State_Enum `json:"state" form:"state" validate:"required" example:"1"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败] State enums.EmailSendLog_State_Enum `json:"state" form:"state" validate:"required" example:"1"` //发送状态 枚举[0:未知 1:待处理 2:处理中 3:成功 4:失败]
...@@ -61,7 +65,7 @@ func (x *EmailSendLogUpdateByIDReq) Valid() error { ...@@ -61,7 +65,7 @@ func (x *EmailSendLogUpdateByIDReq) Valid() error {
if x.ID <= 0 { if x.ID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法")
} }
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) {
...@@ -81,7 +85,7 @@ func (x *EmailSendLogUpdateByIDsReq) Valid() error { ...@@ -81,7 +85,7 @@ func (x *EmailSendLogUpdateByIDsReq) Valid() error {
if len(x.IDs) == 0 { if len(x.IDs) == 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空") return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空")
} }
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) {
...@@ -142,7 +146,7 @@ func (x EmailSendLogObjDetail) NewFromBiz(emailSendLogBiz *biz.EmailSendLog) *Em ...@@ -142,7 +146,7 @@ func (x EmailSendLogObjDetail) NewFromBiz(emailSendLogBiz *biz.EmailSendLog) *Em
return nil return nil
} }
return &EmailSendLogObjDetail{ return &EmailSendLogObjDetail{
EmailSendLog:*emailSendLogBiz, EmailSendLog: *emailSendLogBiz,
StateZh: emailSendLogBiz.State.Desc(), StateZh: emailSendLogBiz.State.Desc(),
} }
} }
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailTplCreateReq request params 邮件模板 // EmailTplCreateReq request params 邮件模板
...@@ -89,7 +91,6 @@ func (EmailTplExportReq) TableName() string { ...@@ -89,7 +91,6 @@ func (EmailTplExportReq) TableName() string {
type EmailTplObjDetail struct { type EmailTplObjDetail struct {
biz.EmailTpl biz.EmailTpl
} }
var EmailTplObjDetailTool = EmailTplObjDetail{} var EmailTplObjDetailTool = EmailTplObjDetail{}
...@@ -99,7 +100,7 @@ func (x EmailTplObjDetail) NewFromBiz(emailTplBiz *biz.EmailTpl) *EmailTplObjDet ...@@ -99,7 +100,7 @@ func (x EmailTplObjDetail) NewFromBiz(emailTplBiz *biz.EmailTpl) *EmailTplObjDet
return nil return nil
} }
return &EmailTplObjDetail{ return &EmailTplObjDetail{
EmailTpl:*emailTplBiz, EmailTpl: *emailTplBiz,
} }
} }
......
package types package types
import ( import (
"operator-qt/internal/modules/operator/biz" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/biz"
"operator-qt/internal/modules/operator/models" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
) )
var _ xtime.DateTime var _ xtime.DateTime
// EmailTplReceiverCreateReq request params 邮件模板收件人 // EmailTplReceiverCreateReq request params 邮件模板收件人
...@@ -17,11 +19,12 @@ type EmailTplReceiverCreateReq struct { ...@@ -17,11 +19,12 @@ type EmailTplReceiverCreateReq struct {
} }
func (x *EmailTplReceiverCreateReq) Valid() error { func (x *EmailTplReceiverCreateReq) Valid() error {
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
} }
// EmailTplReceiverGetByTplIDReq request params // EmailTplReceiverGetByTplIDReq request params
type EmailTplReceiverGetByTplIDReq struct { type EmailTplReceiverGetByTplIDReq struct {
TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" validate:"required" example:"1"` //模板id TplID xsf.ID `json:"tplID" form:"tplID" swaggertype:"string" validate:"required" example:"1"` //模板id
...@@ -45,7 +48,7 @@ func (x *EmailTplReceiverUpdateByIDReq) Valid() error { ...@@ -45,7 +48,7 @@ func (x *EmailTplReceiverUpdateByIDReq) Valid() error {
if x.ID <= 0 { if x.ID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[id]不合法")
} }
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
...@@ -62,7 +65,7 @@ func (x *EmailTplReceiverUpdateByIDsReq) Valid() error { ...@@ -62,7 +65,7 @@ func (x *EmailTplReceiverUpdateByIDsReq) Valid() error {
if len(x.IDs) == 0 { if len(x.IDs) == 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空") return xerror.NewC(errcode.InvalidParams.Code(), "参数[ids]不能为空")
} }
if x.TplID <= 0{ if x.TplID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法") return xerror.NewC(errcode.InvalidParams.Code(), "参数[tplID]不合法")
} }
return nil return nil
...@@ -109,7 +112,6 @@ func (EmailTplReceiverExportReq) TableName() string { ...@@ -109,7 +112,6 @@ func (EmailTplReceiverExportReq) TableName() string {
type EmailTplReceiverObjDetail struct { type EmailTplReceiverObjDetail struct {
biz.EmailTplReceiver biz.EmailTplReceiver
} }
var EmailTplReceiverObjDetailTool = EmailTplReceiverObjDetail{} var EmailTplReceiverObjDetailTool = EmailTplReceiverObjDetail{}
...@@ -119,7 +121,7 @@ func (x EmailTplReceiverObjDetail) NewFromBiz(emailTplReceiverBiz *biz.EmailTplR ...@@ -119,7 +121,7 @@ func (x EmailTplReceiverObjDetail) NewFromBiz(emailTplReceiverBiz *biz.EmailTplR
return nil return nil
} }
return &EmailTplReceiverObjDetail{ return &EmailTplReceiverObjDetail{
EmailTplReceiver:*emailTplReceiverBiz, EmailTplReceiver: *emailTplReceiverBiz,
} }
} }
......
...@@ -3,14 +3,13 @@ package xsfUtils ...@@ -3,14 +3,13 @@ package xsfUtils
import ( import (
"context" "context"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"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"
) )
const ( const (
bizTag_agent = "qt.operator.agent.id" bizTag_agent = "qt.operator.agent.id"
bizTag_agent_operator = "qt.operator.agent.operator.id" bizTag_agent_operator = "qt.operator.agent.operator.id"
...@@ -39,93 +38,95 @@ const ( ...@@ -39,93 +38,95 @@ const (
bizTag_web_log = "qt.operator.web.log.id" bizTag_web_log = "qt.operator.web.log.id"
bizTag_withdraw = "qt.operator.withdraw.id" bizTag_withdraw = "qt.operator.withdraw.id"
) )
func agentID(ctx context.Context) xsf.ID {
func AgentID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_agent) return generateID(ctx, bizTag_agent)
} }
func agent_operatorID(ctx context.Context) xsf.ID { func AgentOperatorID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_agent_operator) return generateID(ctx, bizTag_agent_operator)
} }
func api_notifyID(ctx context.Context) xsf.ID { func ApiNotifyID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_api_notify) return generateID(ctx, bizTag_api_notify)
} }
func app_moduleID(ctx context.Context) xsf.ID { func AppModuleID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_app_module) return generateID(ctx, bizTag_app_module)
} }
func auth_roleID(ctx context.Context) xsf.ID { func AuthRoleID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_auth_role) return generateID(ctx, bizTag_auth_role)
} }
func cron_jobID(ctx context.Context) xsf.ID { func CronJobID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_cron_job) return generateID(ctx, bizTag_cron_job)
} }
func cron_job_logID(ctx context.Context) xsf.ID { func CronJobLogID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_cron_job_log) return generateID(ctx, bizTag_cron_job_log)
} }
func cron_job_recordID(ctx context.Context) xsf.ID { func CronJobRecordID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_cron_job_record) return generateID(ctx, bizTag_cron_job_record)
} }
func emailID(ctx context.Context) xsf.ID { func EmailID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email) return generateID(ctx, bizTag_email)
} }
func email_receiverID(ctx context.Context) xsf.ID { func EmailReceiverID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email_receiver) return generateID(ctx, bizTag_email_receiver)
} }
func email_sendID(ctx context.Context) xsf.ID { func EmailSendID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email_send) return generateID(ctx, bizTag_email_send)
} }
func email_send_logID(ctx context.Context) xsf.ID { func EmailSendLogID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email_send_log) return generateID(ctx, bizTag_email_send_log)
} }
func email_tplID(ctx context.Context) xsf.ID { func EmailTplID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email_tpl) return generateID(ctx, bizTag_email_tpl)
} }
func email_tpl_receiverID(ctx context.Context) xsf.ID { func EmailTplReceiverID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_email_tpl_receiver) return generateID(ctx, bizTag_email_tpl_receiver)
} }
func intakeID(ctx context.Context) xsf.ID { func IntakeID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_intake) return generateID(ctx, bizTag_intake)
} }
func operatorID(ctx context.Context) xsf.ID { func OperatorID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_operator) return generateID(ctx, bizTag_operator)
} }
func platform_configID(ctx context.Context) xsf.ID { func PlatformConfigID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_platform_config) return generateID(ctx, bizTag_platform_config)
} }
func shareID(ctx context.Context) xsf.ID { func ShareID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_share) return generateID(ctx, bizTag_share)
} }
func siteID(ctx context.Context) xsf.ID { func SiteID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_site) return generateID(ctx, bizTag_site)
} }
func site_shareID(ctx context.Context) xsf.ID { func SiteShareID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_site_share) return generateID(ctx, bizTag_site_share)
} }
func site_userID(ctx context.Context) xsf.ID { func SiteUserID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_site_user) return generateID(ctx, bizTag_site_user)
} }
func sms_codeID(ctx context.Context) xsf.ID { func SmsCodeID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_sms_code) return generateID(ctx, bizTag_sms_code)
} }
func userID(ctx context.Context) xsf.ID { func UserID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_user) return generateID(ctx, bizTag_user)
} }
func user_tokenID(ctx context.Context) xsf.ID { func UserTokenID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_user_token) return generateID(ctx, bizTag_user_token)
} }
func web_logID(ctx context.Context) xsf.ID { func WebLogID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_web_log) return generateID(ctx, bizTag_web_log)
} }
func withdrawID(ctx context.Context) xsf.ID { func WithdrawID(ctx context.Context) xsf.ID {
return generateID(ctx, bizTag_withdraw) return generateID(ctx, bizTag_withdraw)
} }
func generateID(ctx context.Context, bizTag string) xsf.ID { func generateID(ctx context.Context, bizTag string) xsf.ID {
xsf, err := dxsf.GenerateApiID(ctx, bizTag) xsf, err := dxsf.GenerateID(ctx, bizTag)
if err != nil { if err != nil {
logger.Error(fmt.Sprintf("GenerateApiID[%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
} }
// insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.agent.id',100000,2000,'qt.operator.agent.id'); // insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.agent.id',100000,2000,'qt.operator.agent.id');
// insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.agent.operator.id',100000,2000,'qt.operator.agent.operator.id'); // insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.agent.operator.id',100000,2000,'qt.operator.agent.operator.id');
// insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.api.notify.id',100000,2000,'qt.operator.api.notify.id'); // insert into leaf_alloc(biz_tag,max_id,step,description) values ('qt.operator.api.notify.id',100000,2000,'qt.operator.api.notify.id');
......
...@@ -5,6 +5,7 @@ var Eb = New() ...@@ -5,6 +5,7 @@ var Eb = New()
const ( const (
TopicParseConf string = "event:application:conf:init" // TopicParseConf string = "event:application:conf:init" //
TopicParseConfFinish string = "event:application:conf:init:finish" // TopicParseConfFinish string = "event:application:conf:init:finish" //
TopicConfChange string = "event:application:conf:change" //
TopicLoggerInit string = "event:application:logger:init" // TopicLoggerInit string = "event:application:logger:init" //
TopicLoggerInitFinish string = "event:application:logger:init:finish" // TopicLoggerInitFinish string = "event:application:logger:init:finish" //
TopicDBInit string = "event:application:database:init" // TopicDBInit string = "event:application:database:init" //
......
...@@ -49,7 +49,7 @@ func Init() error { ...@@ -49,7 +49,7 @@ func Init() error {
} }
} }
} }
logger.Infof("[dxsf] type: %s", config.Cfg.App.IDGeneration.Type)
return nil return nil
} }
......
...@@ -9,7 +9,9 @@ import ( ...@@ -9,7 +9,9 @@ import (
"time" "time"
"github.com/bwmarrin/snowflake" "github.com/bwmarrin/snowflake"
"github.com/spf13/cast"
"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/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
...@@ -98,6 +100,7 @@ func Init() error { ...@@ -98,6 +100,7 @@ func Init() error {
return e return e
} }
node = nod node = nod
logger.Info("[xsf] node " + cast.ToString(n))
return nil return nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论