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.
99 lines
2.9 KiB
99 lines
2.9 KiB
package customerform
|
|
|
|
import (
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"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) {
|
|
dataVal, err := publicmethod.ReceiveData(c) //接收数据处理
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
var req TemplateStruct
|
|
err = json.Unmarshal(dataVal, &req)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
// 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()})
|
|
publicmethod.Result(0, err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "success"})
|
|
publicmethod.Result(200, "success", c, "success")
|
|
}
|
|
|
|
// 创建或查询模板
|
|
func (a *ApiMethod) GetTemplate(c *gin.Context) {
|
|
dataVal, err := publicmethod.ReceiveData(c) //接收数据处理
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
var req TemplateStruct
|
|
err = json.Unmarshal(dataVal, &req)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
|
|
// 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()})
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
|
|
// c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "success", "data": template})
|
|
publicmethod.Result(200, template, c, "success")
|
|
}
|
|
|