增加周报模板接口
parent
1e516c6c1f
commit
c1542a3433
|
@ -4,7 +4,9 @@ import "goweb-gin-demo/service"
|
|||
|
||||
type ApiWtGroup struct {
|
||||
WtReportsApi
|
||||
WtTemplateApi
|
||||
}
|
||||
|
||||
var wtReportsService = service.ServiceGroupApp.WtReportsService
|
||||
var wtTemplatesService = service.ServiceGroupApp.WtTemplateService
|
||||
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
package wt
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"goweb-gin-demo/global"
|
||||
"goweb-gin-demo/model/common/request"
|
||||
"goweb-gin-demo/model/common/response"
|
||||
wtReq "goweb-gin-demo/model/wt/request"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type WtTemplateApi struct {
|
||||
}
|
||||
|
||||
|
||||
// CreateWtTemplate 创建周报模板
|
||||
// @Tags WtTemplate
|
||||
// @Summary 创建周报模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.WtTemplateRes true "创建周报模板"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /wtTemplates/createWtTemplate [post]
|
||||
func (wtTemplatesApi *WtTemplateApi) CreateWtTemplate(c *gin.Context) {
|
||||
var templateRes wtReq.WtTemplateRes
|
||||
_ = c.ShouldBindJSON(&templateRes)
|
||||
if err := wtTemplatesService.CreateWtTemplate(templateRes); err != nil {
|
||||
global.GLOBAL_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteWtTemplateByIds 批量删除WtTemplate
|
||||
// @Tags WtTemplate
|
||||
// @Summary 批量删除WtTemplate
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除周报模板"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
|
||||
// @Router /wtTemplates/deleteWtTemplateByIds [delete]
|
||||
func (wtTemplatesApi *WtTemplateApi) DeleteWtTemplateByIds(c *gin.Context) {
|
||||
var IDS request.IdsReq
|
||||
_ = c.ShouldBindJSON(&IDS)
|
||||
if err := wtTemplatesService.DeleteWtTemplateByIds(IDS); err != nil {
|
||||
global.GLOBAL_LOG.Error("批量删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateWtTemplate 更新周报模板
|
||||
// @Tags WtTemplate
|
||||
// @Summary 更新周报模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.WtTemplateRes true "更新周报模板"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /wtTemplates/updateWtTemplate [put]
|
||||
func (wtTemplatesApi *WtTemplateApi) UpdateWtTemplate(c *gin.Context) {
|
||||
var templateRes wtReq.WtTemplateRes
|
||||
_ = c.ShouldBindJSON(&templateRes)
|
||||
|
||||
if err := wtTemplatesService.UpdateWtTemplate(templateRes); err != nil {
|
||||
global.GLOBAL_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// FindWtTemplate 用id查询周报模板
|
||||
// @Tags WtTemplate
|
||||
// @Summary 用id查询周报模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query request.GetById true "用id查询周报模板"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /wtTemplates/findWtTemplate [get]
|
||||
func (wtTemplatesApi *WtTemplateApi) FindWtTemplate(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
|
||||
if err, rewtTemplates := wtTemplatesService.GetWtTemplate(uint(id)); err != nil {
|
||||
global.GLOBAL_LOG.Error("查询失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{"rewtTemplates": rewtTemplates}, c)
|
||||
}
|
||||
}
|
||||
|
||||
// GetWtTemplateList 分页获取周报模板列表
|
||||
// @Tags WtTemplate
|
||||
// @Summary 分页获取周报模板列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query wtReq.WtTemplateSearch true "分页获取周报模板列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /wtTemplates/getWtTemplateList [get]
|
||||
func (wtTemplatesApi *WtTemplateApi) GetWtTemplateList(c *gin.Context) {
|
||||
var pageInfo wtReq.WtTemplateSearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
if err, list, total := wtTemplatesService.GetWtTemplateInfoList(pageInfo); err != nil {
|
||||
global.GLOBAL_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
298
docs/docs.go
298
docs/docs.go
|
@ -1517,6 +1517,11 @@ var doc = `{
|
|||
"name": "pageSize",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "pictures",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "sendTo",
|
||||
|
@ -1527,6 +1532,11 @@ var doc = `{
|
|||
"description": "更新时间",
|
||||
"name": "updatedAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "userName",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
@ -1576,6 +1586,229 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/createWtTemplate": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "创建周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "创建周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.WtTemplateVO"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/deleteWtTemplateByIds": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "批量删除WtTemplate",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "批量删除周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.IdsReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"批量删除成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/findWtTemplate": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "用id查询周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "number",
|
||||
"description": "主键ID",
|
||||
"name": "id",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/getWtTemplateList": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "分页获取周报模板列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "contents",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "创建时间",
|
||||
"name": "createdAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "header",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "主键ID",
|
||||
"name": "id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "页码",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "每页大小",
|
||||
"name": "pageSize",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "更新时间",
|
||||
"name": "updatedAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "userName",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/updateWtTemplate": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "更新周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "更新周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.WtTemplateVO"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
|
@ -2138,7 +2371,7 @@ var doc = `{
|
|||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.Attachments"
|
||||
"$ref": "#/definitions/wt.UploadFileJson"
|
||||
}
|
||||
},
|
||||
"contents": {
|
||||
|
@ -2153,13 +2386,39 @@ var doc = `{
|
|||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"pictures": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.UploadFileJson"
|
||||
}
|
||||
},
|
||||
"sendTo": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/wt.UserInfo"
|
||||
}
|
||||
},
|
||||
"userId": {
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.WtTemplateVO": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"contents": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.Contents"
|
||||
}
|
||||
},
|
||||
"header": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
@ -2378,17 +2637,6 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"wt.Attachments": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attachmentName": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.Contents": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -2399,6 +2647,28 @@ var doc = `{
|
|||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.UploadFileJson": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.UserInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
|
|
@ -1498,6 +1498,11 @@
|
|||
"name": "pageSize",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "pictures",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "sendTo",
|
||||
|
@ -1508,6 +1513,11 @@
|
|||
"description": "更新时间",
|
||||
"name": "updatedAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "userName",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
@ -1557,6 +1567,229 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/createWtTemplate": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "创建周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "创建周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.WtTemplateVO"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/deleteWtTemplateByIds": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "批量删除WtTemplate",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "批量删除周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.IdsReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"批量删除成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/findWtTemplate": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "用id查询周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "number",
|
||||
"description": "主键ID",
|
||||
"name": "id",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/getWtTemplateList": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "分页获取周报模板列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "contents",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "创建时间",
|
||||
"name": "createdAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "header",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "主键ID",
|
||||
"name": "id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "页码",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "每页大小",
|
||||
"name": "pageSize",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "更新时间",
|
||||
"name": "updatedAt",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "userName",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/wtTemplates/updateWtTemplate": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"WtTemplate"
|
||||
],
|
||||
"summary": "更新周报模板",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "更新周报模板",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.WtTemplateVO"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
|
@ -2119,7 +2352,7 @@
|
|||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.Attachments"
|
||||
"$ref": "#/definitions/wt.UploadFileJson"
|
||||
}
|
||||
},
|
||||
"contents": {
|
||||
|
@ -2134,13 +2367,39 @@
|
|||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"pictures": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.UploadFileJson"
|
||||
}
|
||||
},
|
||||
"sendTo": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/wt.UserInfo"
|
||||
}
|
||||
},
|
||||
"userId": {
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.WtTemplateVO": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"contents": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/wt.Contents"
|
||||
}
|
||||
},
|
||||
"header": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
@ -2359,17 +2618,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"wt.Attachments": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attachmentName": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.Contents": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -2380,6 +2628,28 @@
|
|||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.UploadFileJson": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wt.UserInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -387,7 +387,7 @@ definitions:
|
|||
properties:
|
||||
attachments:
|
||||
items:
|
||||
$ref: '#/definitions/wt.Attachments'
|
||||
$ref: '#/definitions/wt.UploadFileJson'
|
||||
type: array
|
||||
contents:
|
||||
items:
|
||||
|
@ -397,11 +397,28 @@ definitions:
|
|||
type: string
|
||||
id:
|
||||
type: integer
|
||||
pictures:
|
||||
items:
|
||||
$ref: '#/definitions/wt.UploadFileJson'
|
||||
type: array
|
||||
sendTo:
|
||||
items:
|
||||
type: string
|
||||
$ref: '#/definitions/wt.UserInfo'
|
||||
type: array
|
||||
userId:
|
||||
userName:
|
||||
type: string
|
||||
type: object
|
||||
request.WtTemplateVO:
|
||||
properties:
|
||||
contents:
|
||||
items:
|
||||
$ref: '#/definitions/wt.Contents'
|
||||
type: array
|
||||
header:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
type: object
|
||||
response.SysAuthorityCopyResponse:
|
||||
|
@ -556,13 +573,6 @@ definitions:
|
|||
config:
|
||||
$ref: '#/definitions/config.Server'
|
||||
type: object
|
||||
wt.Attachments:
|
||||
properties:
|
||||
attachmentName:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
type: object
|
||||
wt.Contents:
|
||||
properties:
|
||||
content:
|
||||
|
@ -570,6 +580,20 @@ definitions:
|
|||
title:
|
||||
type: string
|
||||
type: object
|
||||
wt.UploadFileJson:
|
||||
properties:
|
||||
key:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
wt.UserInfo:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
paths:
|
||||
|
@ -1472,6 +1496,9 @@ paths:
|
|||
in: query
|
||||
name: pageSize
|
||||
type: integer
|
||||
- in: query
|
||||
name: pictures
|
||||
type: string
|
||||
- in: query
|
||||
name: sendTo
|
||||
type: string
|
||||
|
@ -1479,6 +1506,9 @@ paths:
|
|||
in: query
|
||||
name: updatedAt
|
||||
type: string
|
||||
- in: query
|
||||
name: userName
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
@ -1514,4 +1544,140 @@ paths:
|
|||
summary: 更新周报
|
||||
tags:
|
||||
- WtReports
|
||||
/wtTemplates/createWtTemplate:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 创建周报模板
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/request.WtTemplateVO'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: '{"success":true,"data":{},"msg":"获取成功"}'
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 创建周报模板
|
||||
tags:
|
||||
- WtTemplate
|
||||
/wtTemplates/deleteWtTemplateByIds:
|
||||
delete:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 批量删除周报模板
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/request.IdsReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: '{"success":true,"data":{},"msg":"批量删除成功"}'
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 批量删除WtTemplate
|
||||
tags:
|
||||
- WtTemplate
|
||||
/wtTemplates/findWtTemplate:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 主键ID
|
||||
in: query
|
||||
name: id
|
||||
type: number
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: '{"success":true,"data":{},"msg":"查询成功"}'
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 用id查询周报模板
|
||||
tags:
|
||||
- WtTemplate
|
||||
/wtTemplates/getWtTemplateList:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: query
|
||||
name: contents
|
||||
type: string
|
||||
- description: 创建时间
|
||||
in: query
|
||||
name: createdAt
|
||||
type: string
|
||||
- in: query
|
||||
name: header
|
||||
type: string
|
||||
- description: 主键ID
|
||||
in: query
|
||||
name: id
|
||||
type: integer
|
||||
- description: 页码
|
||||
in: query
|
||||
name: page
|
||||
type: integer
|
||||
- description: 每页大小
|
||||
in: query
|
||||
name: pageSize
|
||||
type: integer
|
||||
- description: 更新时间
|
||||
in: query
|
||||
name: updatedAt
|
||||
type: string
|
||||
- in: query
|
||||
name: userName
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: '{"success":true,"data":{},"msg":"获取成功"}'
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 分页获取周报模板列表
|
||||
tags:
|
||||
- WtTemplate
|
||||
/wtTemplates/updateWtTemplate:
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 更新周报模板
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/request.WtTemplateVO'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: '{"success":true,"data":{},"msg":"更新成功"}'
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 更新周报模板
|
||||
tags:
|
||||
- WtTemplate
|
||||
swagger: "2.0"
|
||||
|
|
BIN
goweb-gin-demo
BIN
goweb-gin-demo
Binary file not shown.
|
@ -57,3 +57,33 @@
|
|||
[goweb-demo]2021/11/04 - 19:33:31.774 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 19:33:38.881 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 19:33:38.883 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 19:41:20.592 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 20:27:23.632 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 20:27:23.634 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 20:31:18.604 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 20:31:28.339 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 20:31:28.340 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 20:32:54.516 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 20:33:02.995 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 20:33:02.996 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 20:35:22.380 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 20:36:20.634 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 20:36:20.635 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:15:27.283 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 21:15:37.298 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:15:37.299 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:17:26.176 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 21:17:32.338 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:17:32.341 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:18:41.619 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 21:18:49.420 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:18:49.422 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:20:11.514 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:20:11.519 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:37:34.347 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 21:38:30.752 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:38:30.754 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:43:33.590 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
[goweb-demo]2021/11/04 - 21:43:40.525 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:47 router register success
|
||||
[goweb-demo]2021/11/04 - 21:43:40.528 [34minfo[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8889"}
|
||||
[goweb-demo]2021/11/04 - 21:44:45.065 [31merror[0m /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8889: use of closed network connection
|
||||
|
|
|
@ -10,7 +10,6 @@ type WtReportsSearch struct{
|
|||
request.PageInfo
|
||||
}
|
||||
|
||||
//
|
||||
type WtReportsVO struct{
|
||||
ID uint
|
||||
UserName string `json:"userName"`
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"goweb-gin-demo/model/common/request"
|
||||
"goweb-gin-demo/model/wt"
|
||||
)
|
||||
|
||||
type WtTemplateSearch struct{
|
||||
wt.WtReports
|
||||
request.PageInfo
|
||||
}
|
||||
|
||||
type WtTemplateRes struct{
|
||||
ID uint
|
||||
UserName string `json:"userName"`
|
||||
Header string `json:"header"`
|
||||
Contents []wt.Contents `json:"contents"`
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package response
|
||||
|
||||
import (
|
||||
"goweb-gin-demo/global"
|
||||
"goweb-gin-demo/model/wt"
|
||||
)
|
||||
|
||||
|
||||
type WtReportsResult struct{
|
||||
global.GLOBAL_MODEL
|
||||
UserName string `json:"userName"`
|
||||
SendTo []wt.UserInfo `json:"sendTo"`
|
||||
Header string `json:"header"`
|
||||
Contents []wt.Contents `json:"contents"`
|
||||
Pictures []wt.UploadFileJson `json:"pictures"`
|
||||
Attachments []wt.UploadFileJson `json:"attachments"`
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package response
|
||||
|
||||
import (
|
||||
"goweb-gin-demo/global"
|
||||
"goweb-gin-demo/model/wt"
|
||||
)
|
||||
|
||||
|
||||
type WtTemplateResult struct{
|
||||
global.GLOBAL_MODEL
|
||||
UserName string `json:"userName"`
|
||||
Header string `json:"header"`
|
||||
Contents []wt.Contents `json:"contents"`
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// 自动生成模板WtTemplate
|
||||
package wt
|
||||
|
||||
import (
|
||||
"goweb-gin-demo/global"
|
||||
)
|
||||
|
||||
// WtTemplate 结构体
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type WtTemplate struct {
|
||||
global.GLOBAL_MODEL
|
||||
UserName string `json:"userName" form:"userName" gorm:"column:user_name;comment:用户名;type:varchar(100);"`
|
||||
Header string `json:"header" form:"header" gorm:"column:header;comment:报告标题名;type:varchar(100);"`
|
||||
Contents string `json:"contents" form:"contents" gorm:"column:contents;comment:报告内容;type:mediumtext;"`
|
||||
}
|
||||
|
||||
|
||||
// TableName WtTemplate 表名
|
||||
func (WtTemplate) TableName() string {
|
||||
return "wt_templates"
|
||||
}
|
||||
|
|
@ -24,4 +24,17 @@ func (s *WtReportsRouter) InitWtReportsRouter(Router *gin.RouterGroup) {
|
|||
wtReportsRouterWithoutRecord.GET("findWtReports", wtReportsApi.FindWtReports) // 根据ID获取WtReports
|
||||
wtReportsRouterWithoutRecord.GET("getWtReportsList", wtReportsApi.GetWtReportsList) // 获取WtReports列表
|
||||
}
|
||||
|
||||
wtTemplatesRouter := Router.Group("wtTemplates").Use(middleware.OperationRecord())
|
||||
wtTemplatesRouterWithoutRecord := Router.Group("wtTemplates")
|
||||
var wtTemplatesApi = api.ApiGroupApp.WtServiceGroup.WtTemplateApi
|
||||
{
|
||||
wtTemplatesRouter.POST("createWtTemplate", wtTemplatesApi.CreateWtTemplate) // 新建周报模板
|
||||
wtTemplatesRouter.DELETE("deleteWtTemplateByIds", wtTemplatesApi.DeleteWtTemplateByIds) // 批量删除周报模板
|
||||
wtTemplatesRouter.PUT("updateWtTemplate", wtTemplatesApi.UpdateWtTemplate) // 更新周报模板
|
||||
}
|
||||
{
|
||||
wtTemplatesRouterWithoutRecord.GET("findWtTemplate", wtTemplatesApi.FindWtTemplate) // 根据ID获取周报模板
|
||||
wtTemplatesRouterWithoutRecord.GET("getWtTemplateList", wtTemplatesApi.GetWtTemplateList) // 获取周报模板列表
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ type ServiceGroup struct {
|
|||
AuthorityService
|
||||
|
||||
wt.WtReportsService
|
||||
wt.WtTemplateService
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"goweb-gin-demo/model/common/request"
|
||||
"goweb-gin-demo/model/wt"
|
||||
wtReq "goweb-gin-demo/model/wt/request"
|
||||
wtRes "goweb-gin-demo/model/wt/response"
|
||||
)
|
||||
|
||||
type WtReportsService struct {
|
||||
|
@ -32,7 +33,7 @@ func (wtReportsService *WtReportsService) UpdateWtReports(reportsVO wtReq.WtRepo
|
|||
}
|
||||
|
||||
// GetWtReports 根据id获取周报
|
||||
func (wtReportsService *WtReportsService) GetWtReports(id uint) (err error, reportsVO wtReq.WtReportsVO) {
|
||||
func (wtReportsService *WtReportsService) GetWtReports(id uint) (err error, reportsVO wtRes.WtReportsResult) {
|
||||
report := wt.WtReports{}
|
||||
err = global.GLOBAL_DB.Where("id = ?", id).First(&report).Error
|
||||
reportVO := reportToVO(report)
|
||||
|
@ -79,8 +80,8 @@ func voToRrports(reportsVO wtReq.WtReportsVO) wt.WtReports {
|
|||
}
|
||||
|
||||
// 批量转换 数据转换, 把字符串转换为json
|
||||
func reportsToVOs(wtReportsList []wt.WtReports) []wtReq.WtReportsVO {
|
||||
var reportsVOList []wtReq.WtReportsVO
|
||||
func reportsToVOs(wtReportsList []wt.WtReports) []wtRes.WtReportsResult {
|
||||
var reportsVOList []wtRes.WtReportsResult
|
||||
for _, report := range wtReportsList {
|
||||
reportVO := reportToVO(report)
|
||||
reportsVOList = append(reportsVOList, reportVO)
|
||||
|
@ -89,9 +90,10 @@ func reportsToVOs(wtReportsList []wt.WtReports) []wtReq.WtReportsVO {
|
|||
}
|
||||
|
||||
//单个转换
|
||||
func reportToVO(report wt.WtReports) wtReq.WtReportsVO {
|
||||
reportVO := wtReq.WtReportsVO{}
|
||||
reportVO.ID = report.ID
|
||||
func reportToVO(report wt.WtReports) wtRes.WtReportsResult {
|
||||
reportVO := wtRes.WtReportsResult{}
|
||||
reportVO.GLOBAL_MODEL = report.GLOBAL_MODEL
|
||||
|
||||
reportVO.UserName = report.UserName
|
||||
reportVO.Header = report.Header
|
||||
json.Unmarshal([]byte(report.SendTo), &reportVO.SendTo)
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package wt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"goweb-gin-demo/global"
|
||||
"goweb-gin-demo/model/common/request"
|
||||
"goweb-gin-demo/model/wt"
|
||||
wtReq "goweb-gin-demo/model/wt/request"
|
||||
wtRes "goweb-gin-demo/model/wt/response"
|
||||
)
|
||||
|
||||
type WtTemplateService struct {
|
||||
}
|
||||
|
||||
// CreateWtTemplate 创建周报模板
|
||||
func (wtTemplatesService *WtTemplateService) CreateWtTemplate(templateRes wtReq.WtTemplateRes) (err error) {
|
||||
template := voToTemplate(templateRes)
|
||||
err = global.GLOBAL_DB.Create(&template).Error
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
// DeleteWtTemplateByIds 批量删除周报模板
|
||||
func (wtTemplatesService *WtTemplateService) DeleteWtTemplateByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GLOBAL_DB.Delete(&[]wt.WtTemplate{}, "id in ?", ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateWtTemplate 更新周报模板
|
||||
func (wtTemplatesService *WtTemplateService) UpdateWtTemplate(templateRes wtReq.WtTemplateRes) (err error) {
|
||||
template := voToTemplate(templateRes)
|
||||
err = global.GLOBAL_DB.Updates(&template).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// GetWtTemplate 根据id获取周报模板
|
||||
func (wtTemplatesService *WtTemplateService) GetWtTemplate(id uint) (err error, templateResult wtRes.WtTemplateResult) {
|
||||
var wtTemplates wt.WtTemplate
|
||||
err = global.GLOBAL_DB.Where("id = ?", id).First(&wtTemplates).Error
|
||||
result := templateToResult(wtTemplates)
|
||||
return err, result
|
||||
}
|
||||
|
||||
// GetWtTemplateInfoList 分页获取周报模板
|
||||
func (wtTemplatesService *WtTemplateService) GetWtTemplateInfoList(info wtReq.WtTemplateSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GLOBAL_DB.Model(&wt.WtTemplate{})
|
||||
var wtTemplatess []wt.WtTemplate
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Limit(limit).Offset(offset).Find(&wtTemplatess).Error
|
||||
|
||||
templateVOList := templateToVOs(wtTemplatess)
|
||||
|
||||
return err, templateVOList, total
|
||||
}
|
||||
|
||||
//数据转换一下, 需要把json数据转换为字符串
|
||||
func voToTemplate(templateVO wtReq.WtTemplateRes) wt.WtTemplate {
|
||||
contentJson, _ := json.Marshal(templateVO.Contents)
|
||||
|
||||
wtTemplate := wt.WtTemplate{
|
||||
GLOBAL_MODEL: global.GLOBAL_MODEL{ID: templateVO.ID},
|
||||
UserName: templateVO.UserName,
|
||||
Header: templateVO.Header,
|
||||
Contents: string(contentJson),
|
||||
}
|
||||
return wtTemplate
|
||||
}
|
||||
|
||||
// 批量转换 数据转换, 把字符串转换为json
|
||||
func templateToVOs(templates []wt.WtTemplate) []wtRes.WtTemplateResult {
|
||||
var templateListResult []wtRes.WtTemplateResult
|
||||
for _, template := range templates {
|
||||
templateRes := templateToResult(template)
|
||||
templateListResult = append(templateListResult, templateRes)
|
||||
}
|
||||
return templateListResult
|
||||
}
|
||||
|
||||
//单个转换
|
||||
func templateToResult(template wt.WtTemplate) wtRes.WtTemplateResult {
|
||||
wtTemplateResult := wtRes.WtTemplateResult{}
|
||||
wtTemplateResult.GLOBAL_MODEL = template.GLOBAL_MODEL
|
||||
|
||||
wtTemplateResult.UserName = template.UserName
|
||||
wtTemplateResult.Header = template.Header
|
||||
json.Unmarshal([]byte(template.Contents), &wtTemplateResult.Contents)
|
||||
return wtTemplateResult
|
||||
}
|
Loading…
Reference in New Issue