| | |
| | | package test |
| | | |
| | | import ( |
| | | "github.com/flipped-aurora/gin-vue-admin/server/global" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/model/common/request" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/model/test" |
| | | testReq "github.com/flipped-aurora/gin-vue-admin/server/model/test/request" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/service" |
| | | "github.com/gin-gonic/gin" |
| | | "go.uber.org/zap" |
| | | "srm/global" |
| | | "srm/model/common/request" |
| | | "srm/model/common/response" |
| | | "srm/model/test" |
| | | testReq "srm/model/test/request" |
| | | "srm/service" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ContractApi struct { |
| | |
| | | // @Param file formData file true "上传文件" |
| | | // @Param name formData string true "文件名称" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
| | | // @Router /api/con/createContract [post] |
| | | // @Router /con/createContract [post] |
| | | func (conApi *ContractApi) CreateContract(c *gin.Context) { |
| | | name := c.Param("name") |
| | | file, err := c.FormFile("file") |
| | |
| | | // @Produce application/json |
| | | // @Param data body test.Contract true "删除Contract" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" |
| | | // @Router /api/con/deleteContract [delete] |
| | | // @Router /con/deleteContract [delete] |
| | | func (conApi *ContractApi) DeleteContract(c *gin.Context) { |
| | | var con test.Contract |
| | | err := c.ShouldBindJSON(&con) |
| | |
| | | // @Produce application/json |
| | | // @Param data body request.IdsReq true "批量删除Contract" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}" |
| | | // @Router /api/con/deleteContractByIds [delete] |
| | | // @Router /con/deleteContractByIds [delete] |
| | | func (conApi *ContractApi) DeleteContractByIds(c *gin.Context) { |
| | | var IDS request.IdsReq |
| | | err := c.ShouldBindJSON(&IDS) |
| | |
| | | // @Produce application/json |
| | | // @Param data body test.Contract true "更新Contract" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" |
| | | // @Router /api/con/updateContract [put] |
| | | // @Router /con/updateContract [put] |
| | | func (conApi *ContractApi) UpdateContract(c *gin.Context) { |
| | | var con test.Contract |
| | | err := c.ShouldBindJSON(&con) |
| | |
| | | // @Produce application/json |
| | | // @Param data query test.Contract true "用id查询Contract" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" |
| | | // @Router /api/con/findContract [get] |
| | | // @Router /con/findContract [get] |
| | | func (conApi *ContractApi) FindContract(c *gin.Context) { |
| | | var con test.Contract |
| | | err := c.ShouldBindQuery(&con) |
| | |
| | | // @Produce application/json |
| | | // @Param data query testReq.ContractSearch true "分页获取Contract列表" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
| | | // @Router /api/con/getContractList [get] |
| | | // @Router /con/getContractList [get] |
| | | func (conApi *ContractApi) GetContractList(c *gin.Context) { |
| | | var pageInfo testReq.ContractSearch |
| | | err := c.ShouldBindQuery(&pageInfo) |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data query testReq.ContractSearch true "预览Contract" |
| | | // @Param data query test.Contract true "用id查询Contract" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"预览成功"}" |
| | | // @Router /api/con/previewContract [get] |
| | | // @Router /con/previewContract [get] |
| | | func (conApi *ContractApi) PreviewContract(c *gin.Context) { |
| | | var pageInfo testReq.ContractSearch |
| | | err := c.ShouldBindQuery(&pageInfo) |
| | | var con test.Contract |
| | | err := c.ShouldBindQuery(&con) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | contract, err := conService.GetContract(pageInfo.ID) |
| | | |
| | | id := c.Query("id") |
| | | if id == "" { |
| | | response.FailWithMessage("id不能为空", c) |
| | | return |
| | | } |
| | | |
| | | val64, err := strconv.ParseUint(id, 10, 64) |
| | | if err != nil { |
| | | response.FailWithMessage("id格式错误", c) |
| | | return |
| | | } |
| | | |
| | | // Convert uint64 to uint |
| | | conId := uint(val64) |
| | | |
| | | contract, err := conService.GetContract(conId) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } else { |
| | | c.Data(200, "application/pdf", contract.FileContent) |
| | | //c.Writer.Header().Set("Content-Type", "application/octect-stream") |
| | | //c.Writer.Header().Set("Content-Disposition", "attachment;filename="+contract.FileName) |
| | | //c.Writer.Write(contract.FileContent) |
| | | c.Data(200, "application/octect-stream", contract.FileContent) |
| | | } |
| | | } |