【添加】规则消息通知

This commit is contained in:
PandaGoAdmin
2022-09-02 17:16:45 +08:00
parent 6312617f49
commit 31fe267d0a
13 changed files with 353 additions and 101 deletions

View File

@@ -196,19 +196,19 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
wg := sync.WaitGroup{}
dcs := *dbColumn
for i := 0; i < len(dcs); i++ {
index := i
for x := 0; x < len(dcs); x++ {
index := x
wg.Add(1)
go func(wg *sync.WaitGroup, i int) {
go func(wg *sync.WaitGroup, y int) {
defer wg.Done()
var column entity.DevGenTableColumn
column.ColumnComment = dcs[i].ColumnComment
column.ColumnName = dcs[i].ColumnName
column.ColumnType = dcs[i].ColumnType
column.Sort = i + 1
column.ColumnComment = dcs[y].ColumnComment
column.ColumnName = dcs[y].ColumnName
column.ColumnType = dcs[y].ColumnType
column.Sort = y + 1
column.IsPk = "0"
nameList := strings.Split(dcs[i].ColumnName, "_")
nameList := strings.Split(dcs[y].ColumnName, "_")
for i := 0; i < len(nameList); i++ {
strStart := string([]byte(nameList[i])[:1])
strend := string([]byte(nameList[i])[1:])
@@ -219,13 +219,12 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
column.JsonField += strings.ToUpper(strStart) + strend
}
}
if strings.Contains(dcs[i].ColumnKey, "PR") {
if strings.Contains(dcs[y].ColumnKey, "PR") {
column.IsPk = "1"
data.PkColumn = dcs[i].ColumnName
data.PkColumn = dcs[y].ColumnName
data.PkGoField = column.GoField
data.PkJsonField = column.JsonField
global.Log.Info("是否自增主键", dcs[i].Extra)
if dcs[i].Extra == "auto_increment" {
if dcs[y].Extra == "auto_increment" {
column.IsIncrement = "1"
}
}
@@ -331,6 +330,7 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
// 类型&性别字段设置下拉框
column.HtmlType = "select"
}
global.Log.Info(y)
data.Columns = append(data.Columns, column)
}(&wg, index)
}

View 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)
}

View 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"` // httpmail
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 python1 javascript 2 shell
}
type DataTemplate struct {
DataTemplate string `json:"dataTemplate"`
}

View 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)
}

View 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 = &noticeModelImpl{
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, "删除规则通知配置失败")
}