From fc6e85021c65e0ddc533c0bae211cfc31df1f92c Mon Sep 17 00:00:00 2001 From: han2015 <1019850453@qq.com> Date: Fri, 28 Nov 2025 11:22:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=A8=A1=E6=9D=BF=E5=92=8C=E5=AD=98=E5=82=A8?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customerform/fromPrintTemplate.go | 70 +++++++++++++++++++ apirouter/v1/customerformrouter/router.go | 2 + models/modelAppPlatform/print_templates.go | 22 ++++++ 3 files changed, 94 insertions(+) create mode 100644 api/version1/customerform/fromPrintTemplate.go create mode 100644 models/modelAppPlatform/print_templates.go diff --git a/api/version1/customerform/fromPrintTemplate.go b/api/version1/customerform/fromPrintTemplate.go new file mode 100644 index 0000000..4d2c559 --- /dev/null +++ b/api/version1/customerform/fromPrintTemplate.go @@ -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}) +} diff --git a/apirouter/v1/customerformrouter/router.go b/apirouter/v1/customerformrouter/router.go index af803aa..f125a1d 100644 --- a/apirouter/v1/customerformrouter/router.go +++ b/apirouter/v1/customerformrouter/router.go @@ -63,6 +63,8 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.POST("gainFormPageMapCont", methodBinding.GainFormPageMapCont) //获取表单地图翻页数据 + apiRouter.POST("getPrintTemplate", methodBinding.GetTemplate) //获取表单打印模板 + apiRouter.POST("savePrintTemplate", methodBinding.SaveTemplate) //编辑表单打印模板 } appApiRouter := router.Group("app") diff --git a/models/modelAppPlatform/print_templates.go b/models/modelAppPlatform/print_templates.go new file mode 100644 index 0000000..deb21ff --- /dev/null +++ b/models/modelAppPlatform/print_templates.go @@ -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" +}