diff --git a/apps/rule/api/rulechain_log.go b/apps/rule/api/rulechain_log.go new file mode 100644 index 0000000..f0b9a6a --- /dev/null +++ b/apps/rule/api/rulechain_log.go @@ -0,0 +1,41 @@ +package api + +import ( + "github.com/XM-GO/PandaKit/model" + "github.com/XM-GO/PandaKit/restfulx" + "pandax/apps/rule/entity" + "pandax/apps/rule/services" + "pandax/pkg/rule_engine/nodes" + "strings" +) + +type RuleChainMsgLogApi struct { + RuleChainMsgLogApp services.RuleChainMsgLogModel +} + +func (r *RuleChainMsgLogApi) GetNodeLabels(rc *restfulx.ReqCtx) { + rc.ResData = nodes.GetCategory() +} + +// GetRuleChainMsgLogList 列表数据 +func (p *RuleChainMsgLogApi) GetRuleChainMsgLogList(rc *restfulx.ReqCtx) { + data := entity.RuleChainMsgLog{} + pageNum := restfulx.QueryInt(rc, "pageNum", 1) + pageSize := restfulx.QueryInt(rc, "pageSize", 10) + data.DeviceName = restfulx.QueryParam(rc, "deviceName") + list, total := p.RuleChainMsgLogApp.FindListPage(pageNum, pageSize, data) + + rc.ResData = model.ResultPage{ + Total: total, + PageNum: int64(pageNum), + PageSize: int64(pageNum), + Data: list, + } +} + +// DeleteRuleChainMsgLog 删除规则链 +func (p *RuleChainMsgLogApi) DeleteRuleChainMsgLog(rc *restfulx.ReqCtx) { + id := restfulx.PathParam(rc, "id") + ids := strings.Split(id, ",") + p.RuleChainMsgLogApp.Delete(ids) +} diff --git a/apps/rule/router/rulechain_log.go b/apps/rule/router/rulechain_log.go new file mode 100644 index 0000000..6cfc666 --- /dev/null +++ b/apps/rule/router/rulechain_log.go @@ -0,0 +1,41 @@ +package router + +import ( + "github.com/XM-GO/PandaKit/model" + "github.com/XM-GO/PandaKit/restfulx" + restfulspec "github.com/emicklei/go-restful-openapi/v2" + "github.com/emicklei/go-restful/v3" + "pandax/apps/rule/api" + "pandax/apps/rule/services" +) + +func InitRuleChainMsgLogRouter(container *restful.Container) { + s := &api.RuleChainMsgLogApi{ + RuleChainMsgLogApp: services.RuleChainMsgLogModelDao, + } + + ws := new(restful.WebService) + ws.Path("/rule/chain/log").Produces(restful.MIME_JSON) + tags := []string{"RuleChainMsgLog"} + + ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) { + restfulx.NewReqCtx(request, response).WithLog("获取规则引擎分页列表").Handle(s.GetRuleChainMsgLogList) + }). + Doc("获取规则引擎分页列表"). + Param(ws.QueryParameter("pageNum", "页数").Required(true).DataType("int")). + Param(ws.QueryParameter("pageSize", "每页条数").Required(true).DataType("int")). + Param(ws.QueryParameter("ruleName", "规则名").Required(false).DataType("string")). + Metadata(restfulspec.KeyOpenAPITags, tags). + Writes(model.ResultPage{}). + Returns(200, "OK", model.ResultPage{})) + + ws.Route(ws.DELETE("/{id}").To(func(request *restful.Request, response *restful.Response) { + restfulx.NewReqCtx(request, response).WithLog("删除规则引擎信息").Handle(s.DeleteRuleChainMsgLog) + }). + Doc("删除规则链日志信息"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.PathParameter("id", "多id 1,2,3").DataType("string"))) + + container.Add(ws) + +} diff --git a/apps/rule/services/rulechain_log.go b/apps/rule/services/rulechain_log.go index 2ac79a7..f5f1246 100644 --- a/apps/rule/services/rulechain_log.go +++ b/apps/rule/services/rulechain_log.go @@ -40,7 +40,6 @@ func (m *ruleChainLogModelImpl) FindListPage(page, pageSize int, data entity.Rul offset := pageSize * (page - 1) db := global.Db.Table(m.table) // 此处填写 where参数判断 - db.Where("delete_time IS NULL") if data.DeviceName != "" { db = db.Where("device_name = ?", data.DeviceName) } diff --git a/pkg/initialize/router.go b/pkg/initialize/router.go index 3d1820c..2381ef0 100644 --- a/pkg/initialize/router.go +++ b/pkg/initialize/router.go @@ -72,6 +72,7 @@ func InitRouter() *transport.HttpServer { } { ruleRouter.InitRuleChainRouter(container) + ruleRouter.InitRuleChainMsgLogRouter(container) } // api接口 middleware.SwaggerConfig(container)