3 changed files with 94 additions and 0 deletions
@ -0,0 +1,70 @@ |
|||||
|
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}) |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package modelAppPlatform |
||||
|
|
||||
|
// 行政组织类型
|
||||
|
type PrintTemplate struct { |
||||
|
Id int `json:"id" gorm:"primaryKey;column:id;type:int unsigned;not null;comment:Id;index"` |
||||
|
Title string `json:"title" gorm:"column:title;type:varchar(255) ;default:'';not null;comment:标题"` |
||||
|
Type string `json:"type" gorm:"column:type;type:varchar(255) ;default:'form';not null;comment:类型"` |
||||
|
//Mode string `json:"mode" gorm:"column:type;type:varchar(20) ;default:'html';not null;comment:类型"`
|
||||
|
CreaterTime int64 `json:"creater_time" gorm:"column:creater_time;type:bigint unsigned;default:0;not null;comment:创建时间"` |
||||
|
EditTime int64 `json:"editTime" gorm:"column:edit_time;type:bigint unsigned;default:0;not null;comment:编辑时间"` |
||||
|
|
||||
|
VersionId string `json:"version_id" gorm:"column:version_id;type:varchar(40) ;default:0;not null;comment:来源于哪个表单"` |
||||
|
FormKey string `json:"form_key" gorm:"column:form_key;type:varchar(40) ;default:0;not null;comment:主表标识"` |
||||
|
PageConfigJson string `json:"pageconfigjson" gorm:"column:pageconfigjson;type:varchar(300);comment:页面配置json"` |
||||
|
FormTemplateJson string `json:"formtemplatejson" gorm:"column:formtemplatejson;type:mediumtext;comment:表单结构json"` |
||||
|
TreeDataJson string `json:"treedatajson" gorm:"column:treedatajson;type:mediumtext;comment:表单结构json"` |
||||
|
NodeCheckedList string `json:"nodecheckedlist" gorm:"column:nodecheckedlist;type:text;comment:打印字段json"` |
||||
|
} |
||||
|
|
||||
|
func (pt *PrintTemplate) TableName() string { |
||||
|
return "print_templates" |
||||
|
} |
||||
Loading…
Reference in new issue