|
@@ -1,20 +1,20 @@
|
|
package controllers
|
|
package controllers
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bufio"
|
|
|
|
|
|
+ //"bufio"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/medivhzhan/weapp/v2"
|
|
"github.com/medivhzhan/weapp/v2"
|
|
- "github.com/pdfcpu/pdfcpu/pkg/api"
|
|
|
|
- "github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
|
|
|
|
|
|
+ //"github.com/pdfcpu/pdfcpu/pkg/api"
|
|
|
|
+ //"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
|
|
"hongze/hongze_cygx/models"
|
|
"hongze/hongze_cygx/models"
|
|
"hongze/hongze_cygx/services"
|
|
"hongze/hongze_cygx/services"
|
|
"hongze/hongze_cygx/utils"
|
|
"hongze/hongze_cygx/utils"
|
|
"html"
|
|
"html"
|
|
- "io"
|
|
|
|
|
|
+ //"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
nhttp "net/http"
|
|
nhttp "net/http"
|
|
- "os"
|
|
|
|
|
|
+ //"os"
|
|
"regexp"
|
|
"regexp"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -799,66 +799,69 @@ func (this *ArticleController) Pdfwatermark() {
|
|
if mobile == "" {
|
|
if mobile == "" {
|
|
mobile = user.Email
|
|
mobile = user.Email
|
|
}
|
|
}
|
|
- pdfPath := "static/"
|
|
|
|
- pdfUrl := fileLink
|
|
|
|
- fileName := utils.GetRandStringNoSpecialChar(28) + ".pdf"
|
|
|
|
- res, err := nhttp.Get(pdfUrl)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("A error occurred!")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- defer res.Body.Close()
|
|
|
|
- // 获得get请求响应的reader对象
|
|
|
|
- reader := bufio.NewReaderSize(res.Body, 32*1024)
|
|
|
|
- file, err := os.Create(pdfPath + fileName)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
|
|
+ sliceLink := strings.Split(fileLink, "/")
|
|
|
|
+ fmt.Println(fileLink)
|
|
|
|
+ fmt.Println(sliceLink[len(sliceLink)-1])
|
|
|
|
+ //pdfPath := "static/"
|
|
|
|
+ //pdfUrl := fileLink
|
|
|
|
+ //fileName := utils.GetRandStringNoSpecialChar(28) + ".pdf"
|
|
|
|
+ //res, err := nhttp.Get(pdfUrl)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // fmt.Println("A error occurred!")
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //defer res.Body.Close()
|
|
|
|
+ //// 获得get请求响应的reader对象
|
|
|
|
+ //reader := bufio.NewReaderSize(res.Body, 32*1024)
|
|
|
|
+ //file, err := os.Create(pdfPath + fileName)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // panic(err)
|
|
|
|
+ //}
|
|
//获得文件的writer对象
|
|
//获得文件的writer对象
|
|
- writer := bufio.NewWriter(file)
|
|
|
|
- written, _ := io.Copy(writer, reader)
|
|
|
|
- fmt.Printf("Total length: %d", written)
|
|
|
|
- str, _ := os.Getwd()
|
|
|
|
- fileLink = str + "/" + pdfPath + fileName
|
|
|
|
- oldFile := pdfPath + fileName
|
|
|
|
- newFile := pdfPath + "new" + fileName
|
|
|
|
- onTop := true
|
|
|
|
- wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, "sc:4 abs, d:1, op:.4, pos:c ,points:16", onTop, 1)
|
|
|
|
- if err != nil {
|
|
|
|
- br.Msg = "下载失败"
|
|
|
|
- br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
|
|
|
|
- if err != nil {
|
|
|
|
- br.Msg = "下载失败"
|
|
|
|
- br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- resp := new(models.ArticleDetailFileLink)
|
|
|
|
- randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
|
- fileName = randStr + ".pdf"
|
|
|
|
- hzUploadDir := "static/pdf/"
|
|
|
|
- savePath := hzUploadDir + time.Now().Format("200601/20060102/")
|
|
|
|
- savePath += fileName
|
|
|
|
- //上传到阿里云
|
|
|
|
- err = services.UploadFileToAliyun(fileName, newFile, savePath)
|
|
|
|
- if err != nil {
|
|
|
|
- br.Msg = "下载失败"
|
|
|
|
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- fileHost := "https://hzstatic.hzinsights.com/"
|
|
|
|
- resourceUrl := fileHost + savePath
|
|
|
|
- defer func() {
|
|
|
|
- os.Remove(newFile)
|
|
|
|
- os.Remove(fileLink)
|
|
|
|
- }()
|
|
|
|
- resp.FileLink = resourceUrl
|
|
|
|
|
|
+ //writer := bufio.NewWriter(file)
|
|
|
|
+ //written, _ := io.Copy(writer, reader)
|
|
|
|
+ //fmt.Printf("Total length: %d", written)
|
|
|
|
+ //str, _ := os.Getwd()
|
|
|
|
+ //fileLink = str + "/" + pdfPath + fileName
|
|
|
|
+ //oldFile := pdfPath + fileName
|
|
|
|
+ //newFile := pdfPath + "new" + fileName
|
|
|
|
+ //onTop := true
|
|
|
|
+ //wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, "sc:4 abs, d:1, op:.4, pos:c ,points:16", onTop, 1)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // br.Msg = "下载失败"
|
|
|
|
+ // br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // br.Msg = "下载失败"
|
|
|
|
+ // br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //resp := new(models.ArticleDetailFileLink)
|
|
|
|
+ //randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
|
+ //fileName = randStr + ".pdf"
|
|
|
|
+ //hzUploadDir := "static/pdf/"
|
|
|
|
+ //savePath := hzUploadDir + time.Now().Format("200601/20060102/")
|
|
|
|
+ //savePath += fileName
|
|
|
|
+ ////上传到阿里云
|
|
|
|
+ //err = services.UploadFileToAliyun(fileName, newFile, savePath)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // br.Msg = "下载失败"
|
|
|
|
+ // br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //fileHost := "https://hzstatic.hzinsights.com/"
|
|
|
|
+ //resourceUrl := fileHost + savePath
|
|
|
|
+ //defer func() {
|
|
|
|
+ // os.Remove(newFile)
|
|
|
|
+ // os.Remove(fileLink)
|
|
|
|
+ //}()
|
|
|
|
+ //resp.FileLink = resourceUrl
|
|
br.Ret = 200
|
|
br.Ret = 200
|
|
br.Success = true
|
|
br.Success = true
|
|
br.Msg = "获取成功"
|
|
br.Msg = "获取成功"
|
|
- br.Data = resp
|
|
|
|
|
|
+ //br.Data = resp
|
|
}
|
|
}
|
|
|
|
|
|
// @Title 同步策略报告内容
|
|
// @Title 同步策略报告内容
|