| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736 |
- package workflow
- import (
- "bufio"
- "encoding/json"
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/utils"
- . "dashoo.cn/utils/db"
- "github.com/go-xorm/xorm"
- . "github.com/linxGnu/goseaweedfs"
- )
- type ActivitiService struct {
- BaseUrl string
- AposeUrl string
- OriginUrl string
- Username string
- Password string
- ServiceBase
- }
- func GetActivitiService(xormEngine *xorm.Engine) *ActivitiService {
- s := new(ActivitiService)
- s.DBE = xormEngine
- //s.BaseUrl = "http://123.56.168.26:8080/activiti-rest/service"
- //s.BaseUrl = "http://192.168.0.120:8081/api/acti"
- s.BaseUrl = utils.Cfg.MustValue("workflow", "BaseUrl")
- //s.BaseUrl = "http://localhost:8081/api/acti"
- s.AposeUrl = utils.Cfg.MustValue("workflow", "AposeUrl")
- //s.OriginUrl = "http://localhost:8081/api"
- s.OriginUrl = utils.Cfg.MustValue("workflow", "OriginUrl")
- //s.AposeUrl = "http://localhost:8081/api/apose"
- //s.AposeUrl = "http://192.168.0.171:8081/api/apose"
- s.Username = "leader"
- s.Password = "123456"
- return s
- }
- func (this *ActivitiService) Post(url string, params string, token string) *http.Response {
- client := &http.Client{}
- req, err := http.NewRequest("POST", this.BaseUrl+url, strings.NewReader(params))
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+token)
- resp, err := client.Do(req)
- if err != nil {
- log.Println("err= ", err)
- }
- log.Println("resp= ", resp)
- return resp
- }
- func (this *ActivitiService) Post2(url string, params string, token string) *http.Response {
- client := &http.Client{}
- req, err := http.NewRequest("POST", this.AposeUrl+url, strings.NewReader(params))
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+token)
- resp, err := client.Do(req)
- if err != nil {
- log.Println("err= ", err)
- }
- log.Println("resp= ", resp)
- return resp
- }
- func (this *ActivitiService) PostOrigin(url string, params string, token string) *http.Response {
- client := &http.Client{}
- req, err := http.NewRequest("POST", this.OriginUrl+url, strings.NewReader(params))
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+token)
- resp, err := client.Do(req)
- if err != nil {
- log.Println("err= ", err)
- }
- log.Println("resp= ", resp)
- return resp
- }
- func (this *ActivitiService) Get(url string, params string, token string) *http.Response {
- client := &http.Client{}
- req, err := http.NewRequest("Get", this.BaseUrl+url, strings.NewReader(params))
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+token)
- resp, err := client.Do(req)
- if err != nil {
- log.Println("err= ", err)
- }
- log.Println("resp= ", resp)
- return resp
- }
- func (this *ActivitiService) StartProcess(processKey string, formEntityId string, userNames string) string {
- /*vars := make(map[string]string)
- vars["processDefinitionKey"] = processKey
- vars["formEntityId"] = formEntityId*/
- /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
- var ActiProcess ActiProcessVM
- ActiProcess.ProcessKey = processKey
- ActiProcess.BusinessKey = formEntityId
- ActiProcess.UserNames = userNames
- json, err := json.Marshal(ActiProcess)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(json)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/start-process", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- func (this *ActivitiService) StartProcess2(processKey, formEntityId, userNames, result, supplierType, supplierName string) string {
- /*vars := make(map[string]string)
- vars["processDefinitionKey"] = processKey
- vars["formEntityId"] = formEntityId*/
- /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
- var ActiProcess ActiProcessVM
- ActiProcess.ProcessKey = processKey
- ActiProcess.BusinessKey = formEntityId
- ActiProcess.UserNames = userNames
- ActiProcess.Result = result
- ActiProcess.WfType = supplierType
- ActiProcess.SupplierName = supplierName
- json, err := json.Marshal(ActiProcess)
- if err != nil {
- // panic(err., "生成json字符串错误")
- panic("生成json字符串错误")
- }
- params := string(json)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/start-process-bytype", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- //func (this *ActivitiService) TaskComplete(processKey string, formEntityId string, userNames string, userId string, result string, remarks string) string {
- /*var ActiComplete ActiCompleteVM
- ActiComplete.ProcessKey = processKey
- ActiComplete.BusinessKey = formEntityId
- ActiComplete.UserNames = userNames
- ActiComplete.UserId = userId
- ActiComplete.Result = result
- ActiComplete.Remarks = remarks*/
- func (this *ActivitiService) TaskComplete(ActiComplete ActiCompleteVM) string {
- jsonParams, err := json.Marshal(ActiComplete)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParams)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/task-complete", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- /*func (this *ActivitiService) MultiTaskComplete(processKey string, formEntityId string, userNames string, multiOrgAudits []MultiOrgAuditVM, userId string, result string, remarks string, callbackUrl string) string {
- var ActiComplete MultiActiCompleteVM
- ActiComplete.ProcessKey = processKey
- ActiComplete.BusinessKey = formEntityId
- ActiComplete.UserNames = userNames
- ActiComplete.MultiOrgAudits = multiOrgAudits
- ActiComplete.UserId = userId
- ActiComplete.Result = result
- ActiComplete.Remarks = remarks
- ActiComplete.CallbackUrl = callbackUrl*/
- func (this *ActivitiService) MultiTaskComplete(ActiComplete MultiActiCompleteVM) string {
- jsonParams, err := json.Marshal(ActiComplete)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParams)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/multi-task-complete", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- func (this *ActivitiService) GetMyTasks(processKey string, userId string) string {
- var ActiMyTasks ActiMyTasksVM
- ActiMyTasks.ProcessKey = processKey
- ActiMyTasks.UserId = userId
- json, err := json.Marshal(ActiMyTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(json)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-tasks", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- func (this *ActivitiService) GetMyTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
- var ActiMyTasks ActiMyTasksVM
- ActiMyTasks.ProcessKey = processKey
- ActiMyTasks.UserId = userId
- jsonParam, err := json.Marshal(ActiMyTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-tasks-with-time", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
- json.Unmarshal(p, &myTasksRetWithTimes)
- return myTasksRetWithTimes
- }
- func (this *ActivitiService) GetMyFinishedTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
- var ActiMyTasks ActiMyTasksVM
- ActiMyTasks.ProcessKey = processKey
- ActiMyTasks.UserId = userId
- jsonParam, err := json.Marshal(ActiMyTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-finished-tasks-with-time", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
- json.Unmarshal(p, &myTasksRetWithTimes)
- return myTasksRetWithTimes
- }
- func (this *ActivitiService) GetMyAllTypePagingTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
- var myPagingTasks ActiMyPagingTasksVM
- myPagingTasks.UserId = userId
- myPagingTasks.PageIndex = PageIndex
- myPagingTasks.PageSize = PageSize
- myPagingTasks.WfName = wfName
- myPagingTasks.WfType = wfType
- myPagingTasks.SupplierName = supplierName
- jsonParam, err := json.Marshal(myPagingTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-all-type-paging-tasks-with-time", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- var myTasksRetWithTimes ActiMyPagingResultVM
- json.Unmarshal(p, &myTasksRetWithTimes)
- return myTasksRetWithTimes
- }
- func (this *ActivitiService) GetMyAllTypePagingFinishedTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
- var myPagingTasks ActiMyPagingTasksVM
- myPagingTasks.UserId = userId
- myPagingTasks.PageIndex = PageIndex
- myPagingTasks.PageSize = PageSize
- myPagingTasks.WfName = wfName
- myPagingTasks.WfType = wfType
- myPagingTasks.SupplierName = supplierName
- jsonParam, err := json.Marshal(myPagingTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-all-type-paging-finished-tasks-with-time", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- var myTasksRetWithTimes ActiMyPagingResultVM
- json.Unmarshal(p, &myTasksRetWithTimes)
- return myTasksRetWithTimes
- }
- func (this *ActivitiService) GetHistoricTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
- var ActiProcess ActiProcessVM
- ActiProcess.ProcessKey = processKey
- ActiProcess.BusinessKey = businessKey
- ActiProcess.ProcessInstanceId = processInstanceId
- jsonParam, err := json.Marshal(ActiProcess)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/historic-tasks", params, "")
- jsonblob, _ := ioutil.ReadAll(retVal.Body)
- // var historicTasks []ActiHistoricTask
- historicTasks := make([]ActiHistoricTask, 0)
- json.Unmarshal(jsonblob, &historicTasks)
- return historicTasks
- }
- func (this *ActivitiService) GetHistoricMultiTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
- var ActiProcess ActiProcessVM
- ActiProcess.ProcessKey = processKey
- ActiProcess.BusinessKey = businessKey
- ActiProcess.ProcessInstanceId = processInstanceId
- jsonParam, err := json.Marshal(ActiProcess)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/historic-multi-tasks", params, "")
- jsonblob, _ := ioutil.ReadAll(retVal.Body)
- // var historicTasks []ActiHistoricTask
- historicTasks := make([]ActiHistoricTask, 0)
- json.Unmarshal(jsonblob, &historicTasks)
- return historicTasks
- }
- func (this *ActivitiService) GetActivitiProccessImage(processInstanceId string) []byte {
- var ActiProcess ActiProcessVM
- ActiProcess.ProcessInstanceId = processInstanceId
- jsonParam, err := json.Marshal(ActiProcess)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/historic-tasks-image", params, "")
- imgByte, _ := ioutil.ReadAll(retVal.Body)
- return imgByte
- }
- func (this *ActivitiService) GetHistoryMyTasks(processKey string, userId string) string {
- var ActiMyTasks ActiMyTasksVM
- ActiMyTasks.ProcessKey = processKey
- ActiMyTasks.UserId = userId
- json, err := json.Marshal(ActiMyTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(json)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-tasks-finished", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- return string(p)
- }
- func (this *ActivitiService) GetAllMyTasks(processKey string, userId string) string {
- var ActiMyTasks ActiMyTasksVM
- ActiMyTasks.ProcessKey = processKey
- ActiMyTasks.UserId = userId
- json, err := json.Marshal(ActiMyTasks)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(json)
- fmt.Println(params)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post("/my-tasks-finished", params, "")
- p, _ := ioutil.ReadAll(retVal.Body)
- retVal2 := this.Post("/my-tasks", params, "")
- p2, _ := ioutil.ReadAll(retVal2.Body)
- return string(p) + "," + string(p2)
- }
- func (this *ActivitiService) ExcelToPdf(addressUrl string) string {
- var aposeVM AposeVM
- aposeVM.AddressUrl = addressUrl
- fmt.Println("==addressUrl===", addressUrl)
- jsonParam, err := json.Marshal(aposeVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post2("/excel-to-pdf", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- //pdfByte, err := ioutil.ReadAll(retVal.Body)
- //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
- //模板下载到服务器
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL6 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- func (this *ActivitiService) WordToPdf(addressUrl string) string {
- var aposeVM AposeVM
- aposeVM.AddressUrl = addressUrl
- fmt.Println("==addressUrl===", addressUrl)
- jsonParam, err := json.Marshal(aposeVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post2("/word-to-pdf", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- //pdfByte, err := ioutil.ReadAll(retVal.Body)
- //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
- //模板下载到服务器
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL5 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- func (this *ActivitiService) WordToPdfWithWatermark(wartermark, addressUrl string) string {
- var aposeVM AposeVM
- aposeVM.AddressUrl = addressUrl
- aposeVM.Watermark = wartermark
- fmt.Println("==addressUrl===", addressUrl)
- jsonParam, err := json.Marshal(aposeVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.Post2("/word-to-pdf-watermark", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- //pdfByte, err := ioutil.ReadAll(retVal.Body)
- //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
- //模板下载到服务器
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL4 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- fmt.Println("err_表单下载4=", err)
- fmt.Println("fID_表单下载4=", fID)
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- func (this *ActivitiService) FillWordTemplate(datas map[string]interface{}, templateUrl string, fileName string) string {
- var wordTempVM WordTemplateVM
- wordTempVM.Datas = datas
- wordTempVM.TemplateUrl = templateUrl
- wordTempVM.FileName = fileName
- fmt.Println("==templateUrl===", templateUrl)
- jsonParam, err := json.Marshal(wordTempVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.PostOrigin("/word/fill-word", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- //pdfByte, err := ioutil.ReadAll(retVal.Body)
- //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
- //模板下载到服务器
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL3 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- fmt.Println("err_表单下载3=", err)
- fmt.Println("fID_表单下载3=", fID)
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- func (this *ActivitiService) FillExcel(datas map[string]interface{}, ContractClass string, templateUrl string, fileName string) string {
- var wordTempVM excelTemplateVM
- wordTempVM.ContractClass = ContractClass
- wordTempVM.Datas = datas
- wordTempVM.TemplateUrl = templateUrl
- wordTempVM.FileName = fileName
- jsonParam, err := json.Marshal(wordTempVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- retVal := this.PostOrigin("/excel/fill-excel", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- fmt.Println("err_表单下载2=", err)
- fmt.Println("fID_表单下载2=", fID)
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- func (this *ActivitiService) ContrastExcel(datas map[string]interface{}, templateUrl string, fileName string) string {
- var wordTempVM excelContrastVM
- wordTempVM.Datas = datas
- wordTempVM.TemplateUrl = templateUrl
- wordTempVM.FileName = fileName
- jsonParam, err := json.Marshal(wordTempVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- retVal := this.PostOrigin("/excel/contrast-excel", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- fmt.Println("err_表单下载2=", err)
- fmt.Println("fID_表单下载2=", fID)
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocUrl==", retDocUrl)
- return retDocUrl
- }
- // 带水印
- func (this *ActivitiService) FillWordWatermarkTemplate(datas map[string]interface{}, templateUrl string, fileName,watermark string) string {
- var wordTempVM WordTemplateWatermarkVM
- wordTempVM.Datas = datas
- wordTempVM.TemplateUrl = templateUrl
- wordTempVM.FileName = fileName
- wordTempVM.Watermark = watermark
- fmt.Println("==templateWatermarkUrl===", templateUrl)
- jsonParam, err := json.Marshal(wordTempVM)
- if err != nil {
- fmt.Println(err, "生成json字符串错误")
- }
- params := string(jsonParam)
- //token = Authorization(this.Username, this.Password)
- retVal := this.PostOrigin("/word/fill-word-watermark", params, "")
- if retVal.StatusCode != 200 {
- return ""
- }
- //pdfByte, err := ioutil.ReadAll(retVal.Body)
- //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
- //模板下载到服务器
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
- utils.CreatePath(_dir)
- _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
- raw := retVal.Body
- defer raw.Close()
- file, err := os.Create(_dir)
- defer file.Close()
- writer := bufio.NewWriter(file)
- defer writer.Flush()
- body, err := ioutil.ReadAll(raw)
- writer.Write(body)
- if err != nil {
- return ""
- }
- var sw *Seaweed
- var filer []string
- if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
- filer = []string{_filer}
- }
- fmt.Println("GOSWFS_FILER_URL1 == ", os.Getenv("GOSWFS_FILER_URL"))
- sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
- //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
- _, _, fID, err := sw.UploadFile(_dir, "", "")
- fmt.Println("err_表单下载=", err)
- retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
- os.Remove(_dir)
- fmt.Println("==retDocWatermarkUrl==", retDocUrl)
- return retDocUrl
- }
|