应用集成平台服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
2.1 KiB

package customerform
import (
"appPlatform/models/modelAppPlatform"
"appPlatform/overall"
"net/http"
"github.com/gin-gonic/gin"
)
type TemplateStruct struct {
Name string `json:"name"`
Type string `json:"type"`
//Mode string `json:"mode"` //当前模板渲染方式: html简单自动布局 custom高级自主定义
VersionId string `json:"versionid"`
FormKey string `json:"formkey"`
FormTemplateJson string `json:"formtemplatejson"`
TreeDataJson string `json:"treedatajson"`
PageConfigJson string `json:"pageconfigjson"`
NodeCheckedList string `json:"nodecheckedlist"`
}
// 修改模板
func (a *ApiMethod) SaveTemplate(c *gin.Context) {
var req TemplateStruct
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var template modelAppPlatform.PrintTemplate
template.Title = req.Name
template.Type = req.Type
//template.Mode = req.Mode
template.FormTemplateJson = req.FormTemplateJson
template.TreeDataJson = req.TreeDataJson
template.NodeCheckedList = req.NodeCheckedList
template.PageConfigJson = req.PageConfigJson
err := overall.CONSTANT_DB_AppPlatform.Model(&template).
Where("version_id = ? AND form_key = ?", req.VersionId, req.FormKey).
Updates(&template).Error
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "success"})
}
// 创建或查询模板
func (a *ApiMethod) GetTemplate(c *gin.Context) {
var req TemplateStruct
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var template modelAppPlatform.PrintTemplate
template.VersionId = req.VersionId
template.FormKey = req.FormKey
if err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.PrintTemplate{}).
Where("version_id = ? AND form_key = ?", req.VersionId, req.FormKey).
FirstOrCreate(&template).Error; err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "success", "data": template})
}