mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【添加】规则消息通知
This commit is contained in:
65
apps/rule/api/rule_notice.go
Normal file
65
apps/rule/api/rule_notice.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package api
|
||||
|
||||
// ==========================================================================
|
||||
// 生成日期:2022-09-02 15:49:39 +0800 CST
|
||||
// 生成路径: apps/rule/api/rule_notice.go
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"pandax/apps/rule/entity"
|
||||
"pandax/apps/rule/services"
|
||||
)
|
||||
|
||||
type RuleNoticeApi struct {
|
||||
RuleNoticeApp services.RuleNoticeModel
|
||||
}
|
||||
|
||||
// GetRuleNoticeList Notice列表数据
|
||||
func (p *RuleNoticeApi) GetRuleNoticeList(rc *restfulx.ReqCtx) {
|
||||
data := entity.RuleNotice{}
|
||||
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
|
||||
data.Name = restfulx.QueryParam(rc, "name")
|
||||
|
||||
list, total := p.RuleNoticeApp.FindListPage(pageNum, pageSize, data)
|
||||
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
PageSize: int64(pageNum),
|
||||
Data: list,
|
||||
}
|
||||
}
|
||||
|
||||
// GetRuleNotice 获取Notice
|
||||
func (p *RuleNoticeApi) GetRuleNotice(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParamInt(rc, "id")
|
||||
rc.ResData = p.RuleNoticeApp.FindOne(int64(id))
|
||||
}
|
||||
|
||||
// InsertRuleNotice 添加Notice
|
||||
func (p *RuleNoticeApi) InsertRuleNotice(rc *restfulx.ReqCtx) {
|
||||
var data entity.RuleNotice
|
||||
restfulx.BindQuery(rc, &data)
|
||||
|
||||
p.RuleNoticeApp.Insert(data)
|
||||
}
|
||||
|
||||
// UpdateRuleNotice 修改Notice
|
||||
func (p *RuleNoticeApi) UpdateRuleNotice(rc *restfulx.ReqCtx) {
|
||||
var data entity.RuleNotice
|
||||
restfulx.BindQuery(rc, &data)
|
||||
|
||||
p.RuleNoticeApp.Update(data)
|
||||
}
|
||||
|
||||
// DeleteRuleNotice 删除Notice
|
||||
func (p *RuleNoticeApi) DeleteRuleNotice(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParam(rc, "id")
|
||||
ids := utils.IdsStrToIdsIntGroup(id)
|
||||
p.RuleNoticeApp.Delete(ids)
|
||||
}
|
||||
62
apps/rule/entity/notice.go
Normal file
62
apps/rule/entity/notice.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
)
|
||||
|
||||
type RuleNotice struct {
|
||||
model.BaseAutoModel
|
||||
UserId string `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"` // http,mail
|
||||
Description string `json:"description"`
|
||||
Model string `json:"model"` // 配置或模板 setting or template
|
||||
ExParam json.RawMessage `json:"ex_param" gorm:"type:jsonb;comment: 拓展参数"`
|
||||
}
|
||||
|
||||
func (RuleNotice) TableName() string {
|
||||
return "rule_notice"
|
||||
}
|
||||
|
||||
type RestSetting struct {
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
BodyType string `json:"bodyType"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
CertificationPath string `json:"certificationPath"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
RootCaPath string `json:"rootCaPath"`
|
||||
InsecureSkipVerify bool `json:"insecureSkipVerify"`
|
||||
}
|
||||
|
||||
type MqttSetting struct {
|
||||
Server string `json:"server"`
|
||||
Topic string `json:"topic"`
|
||||
Qos byte `json:"qos"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Retained bool `json:"retained"`
|
||||
CertificationPath string `json:"certificationPath"`
|
||||
PrivateKeyPath string `json:"privateKeyPath"`
|
||||
RootCaPath string `json:"rootCaPath"`
|
||||
InsecureSkipVerify bool `json:"insecureSkipVerify"`
|
||||
}
|
||||
|
||||
type MailSetting struct {
|
||||
Host string `json:"host"` // 服务器地址
|
||||
Port int `json:"port"` // 服务器端口
|
||||
From string `json:"from"` // 邮箱账号
|
||||
Nickname string `json:"nickname"` // 发件人
|
||||
Secret string `json:"secret"` // 邮箱密码
|
||||
IsSSL bool `json:"isSsl"` // 是否开启ssl
|
||||
}
|
||||
|
||||
type ScriptSetting struct {
|
||||
Category string `json:"category"` // 0 python,1 javascript 2 shell
|
||||
}
|
||||
|
||||
type DataTemplate struct {
|
||||
DataTemplate string `json:"dataTemplate"`
|
||||
}
|
||||
70
apps/rule/router/rule_notice.go
Normal file
70
apps/rule/router/rule_notice.go
Normal file
@@ -0,0 +1,70 @@
|
||||
// ==========================================================================
|
||||
// 生成日期:2022-09-02 15:49:39 +0800 CST
|
||||
// 生成路径: apps/rule/router/rule_notice.go
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"pandax/apps/rule/api"
|
||||
"pandax/apps/rule/entity"
|
||||
"pandax/apps/rule/services"
|
||||
|
||||
restfulspec "github.com/emicklei/go-restful-openapi/v2"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
)
|
||||
|
||||
func InitRuleNoticeRouter(container *restful.Container) {
|
||||
s := &api.RuleNoticeApi{
|
||||
RuleNoticeApp: services.RuleNoticeModelDao,
|
||||
}
|
||||
|
||||
ws := new(restful.WebService)
|
||||
ws.Path("/rule/notice").Produces(restful.MIME_JSON)
|
||||
tags := []string{"notice"}
|
||||
|
||||
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取Notice分页列表").Handle(s.GetRuleNoticeList)
|
||||
}).
|
||||
Doc("获取Notice分页列表").
|
||||
Param(ws.QueryParameter("pageNum", "页数").Required(true).DataType("int")).
|
||||
Param(ws.QueryParameter("pageSize", "每页条数").Required(true).DataType("int")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(model.ResultPage{}).
|
||||
Returns(200, "OK", model.ResultPage{}))
|
||||
|
||||
ws.Route(ws.GET("/{id}").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取Notice信息").Handle(s.GetRuleNotice)
|
||||
}).
|
||||
Doc("获取Notice信息").
|
||||
Param(ws.PathParameter("id", "Id").DataType("int")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.RuleNotice{}). // on the response
|
||||
Returns(200, "OK", entity.RuleNotice{}).
|
||||
Returns(404, "Not Found", nil))
|
||||
|
||||
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("添加Notice信息").Handle(s.InsertRuleNotice)
|
||||
}).
|
||||
Doc("添加Notice信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.RuleNotice{}))
|
||||
|
||||
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改Notice信息").Handle(s.UpdateRuleNotice)
|
||||
}).
|
||||
Doc("修改Notice信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.RuleNotice{}))
|
||||
|
||||
ws.Route(ws.DELETE("/{id}").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("删除Notice信息").Handle(s.DeleteRuleNotice)
|
||||
}).
|
||||
Doc("删除Notice信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Param(ws.PathParameter("id", "多id 1,2,3").DataType("string")))
|
||||
|
||||
container.Add(ws)
|
||||
}
|
||||
101
apps/rule/services/rule_notice.go
Normal file
101
apps/rule/services/rule_notice.go
Normal file
@@ -0,0 +1,101 @@
|
||||
// ==========================================================================
|
||||
// 生成日期:2022-09-02 15:49:39 +0800 CST
|
||||
// 生成路径: apps/rule/services/rule_notice.go
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"pandax/apps/rule/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
RuleNoticeModel interface {
|
||||
Insert(data entity.RuleNotice) *entity.RuleNotice
|
||||
FindOne(id int64) *entity.RuleNotice
|
||||
FindListPage(page, pageSize int, data entity.RuleNotice) (*[]entity.RuleNotice, int64)
|
||||
FindList(data entity.RuleNotice) *[]entity.RuleNotice
|
||||
Update(data entity.RuleNotice) *entity.RuleNotice
|
||||
Delete(ids []int64)
|
||||
}
|
||||
|
||||
noticeModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var RuleNoticeModelDao RuleNoticeModel = ¬iceModelImpl{
|
||||
table: `rule_notice`,
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) Insert(data entity.RuleNotice) *entity.RuleNotice {
|
||||
err := global.Db.Table(m.table).Create(&data).Error
|
||||
biz.ErrIsNil(err, "添加规则通知配置失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) FindOne(id int64) *entity.RuleNotice {
|
||||
resData := new(entity.RuleNotice)
|
||||
db := global.Db.Table(m.table).Where("id = ?", id)
|
||||
err := db.First(resData).Error
|
||||
biz.ErrIsNil(err, "查询规则通知配置失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) FindListPage(page, pageSize int, data entity.RuleNotice) (*[]entity.RuleNotice, int64) {
|
||||
list := make([]entity.RuleNotice, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Description != "" {
|
||||
db = db.Where("description = ?", data.Description)
|
||||
}
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Category != "" {
|
||||
db = db.Where("category = ?", data.Category)
|
||||
}
|
||||
if data.Model != "" {
|
||||
db = db.Where("model = ?", data.Model)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询规则通知配置分页列表失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) FindList(data entity.RuleNotice) *[]entity.RuleNotice {
|
||||
list := make([]entity.RuleNotice, 0)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Description != "" {
|
||||
db = db.Where("description = ?", data.Description)
|
||||
}
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Category != "" {
|
||||
db = db.Where("category = ?", data.Category)
|
||||
}
|
||||
if data.Model != "" {
|
||||
db = db.Where("model = ?", data.Model)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
biz.ErrIsNil(db.Order("create_time").Find(&list).Error, "查询规则通知配置列表失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) Update(data entity.RuleNotice) *entity.RuleNotice {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Updates(&data).Error, "修改规则通知配置失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *noticeModelImpl) Delete(ids []int64) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.RuleNotice{}, "id in (?)", ids).Error, "删除规则通知配置失败")
|
||||
}
|
||||
Reference in New Issue
Block a user