【feat】导出tsl

This commit is contained in:
XM-GO
2023-09-22 17:10:22 +08:00
parent 661246609d
commit 79314f6f7e
4 changed files with 316 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/PandaXGO/PandaKit/biz"
"github.com/PandaXGO/PandaKit/model"
"github.com/PandaXGO/PandaKit/restfulx"
"pandax/pkg/global"
"pandax/pkg/tool"
"strings"
@@ -56,6 +57,39 @@ func (p *ProductApi) GetProductListAll(rc *restfulx.ReqCtx) {
rc.ResData = p.ProductApp.FindList(data)
}
// GetProductTsl Template列表数据
func (p *ProductApi) GetProductTsl(rc *restfulx.ReqCtx) {
data := entity.ProductTemplate{}
data.Pid = restfulx.PathParam(rc, "id")
templates := p.TemplateApp.FindList(data)
attributes := make([]map[string]interface{}, 0)
telemetry := make([]map[string]interface{}, 0)
commands := make([]map[string]interface{}, 0)
for _, template := range *templates {
tslData := map[string]interface{}{
"name": template.Name,
"identifier": template.Key,
"type": template.Type,
"define": template.Define,
}
if template.Classify == global.TslAttributesType {
attributes = append(attributes, tslData)
}
if template.Classify == global.TslTelemetryType {
telemetry = append(telemetry, tslData)
}
if template.Classify == global.TslCommandsType {
commands = append(commands, tslData)
}
}
rc.ResData = map[string]interface{}{
"attributes": attributes,
"telemetry": telemetry,
"commands": commands,
}
}
// GetProduct 获取Product
func (p *ProductApi) GetProduct(rc *restfulx.ReqCtx) {
id := restfulx.PathParam(rc, "id")

View File

@@ -61,6 +61,15 @@ func InitProductRouter(container *restful.Container) {
Returns(200, "OK", entity.Product{}).
Returns(404, "Not Found", nil))
ws.Route(ws.GET("/{id}/tsl").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取Product的TSL信息").Handle(s.GetProductTsl)
}).
Doc("获取Product的TSL信息").
Param(ws.PathParameter("id", "Id").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", map[string]interface{}{}).
Returns(404, "Not Found", nil))
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加Product信息").Handle(s.InsertProduct)
}).