2023-04-12 16:56:55 +08:00
|
|
|
package contracts
|
|
|
|
|
|
|
|
import (
|
2024-05-09 13:15:24 +08:00
|
|
|
"git.fsdpf.net/go/req"
|
2023-04-12 16:56:55 +08:00
|
|
|
"github.com/samber/do"
|
|
|
|
"github.com/samber/lo"
|
|
|
|
)
|
|
|
|
|
2024-07-20 21:00:18 +08:00
|
|
|
type ResEventService interface {
|
|
|
|
Start() error
|
|
|
|
Stop() error
|
|
|
|
Restart() error
|
|
|
|
}
|
2023-04-12 16:56:55 +08:00
|
|
|
|
|
|
|
type ResListener interface {
|
2024-05-09 13:15:24 +08:00
|
|
|
Insert(new map[string]any, u req.User, id int64) error
|
|
|
|
Update(new map[string]any, u req.User, old map[string]any) error
|
|
|
|
Delete(old map[string]any, u req.User) error
|
|
|
|
GetResource() req.Resource
|
2023-04-12 16:56:55 +08:00
|
|
|
GetCode() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type BaseListener struct {
|
|
|
|
Container *do.Injector
|
2024-05-09 13:15:24 +08:00
|
|
|
res req.Resource // 监听资源
|
|
|
|
code string // code
|
|
|
|
events []string // 监听动作
|
2023-04-12 16:56:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this BaseListener) GetCode() string {
|
|
|
|
return this.code
|
|
|
|
}
|
|
|
|
|
2024-05-09 13:15:24 +08:00
|
|
|
func (this BaseListener) GetResource() req.Resource {
|
2023-04-12 16:56:55 +08:00
|
|
|
return this.res
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this BaseListener) HasEvent(event string) bool {
|
|
|
|
return lo.Contains(this.events, event)
|
|
|
|
}
|
|
|
|
|
2024-05-09 13:15:24 +08:00
|
|
|
func (BaseListener) Insert(new map[string]any, u req.User, id int64) error {
|
2023-04-12 16:56:55 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-09 13:15:24 +08:00
|
|
|
func (BaseListener) Update(new map[string]any, u req.User, old map[string]any) error {
|
2023-04-12 16:56:55 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-09 13:15:24 +08:00
|
|
|
func (BaseListener) Delete(old map[string]any, u req.User) error {
|
2023-04-12 16:56:55 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-09 13:15:24 +08:00
|
|
|
func NewBaseListener(code string, res req.Resource, container *do.Injector) *BaseListener {
|
2023-04-12 16:56:55 +08:00
|
|
|
return &BaseListener{code: code, res: res, Container: container}
|
|
|
|
}
|