ActivitiService.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. package workflow
  2. import (
  3. "bufio"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "log"
  8. "net/http"
  9. "os"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "dashoo.cn/utils"
  14. . "dashoo.cn/utils/db"
  15. "github.com/go-xorm/xorm"
  16. . "github.com/linxGnu/goseaweedfs"
  17. )
  18. type ActivitiService struct {
  19. BaseUrl string
  20. AposeUrl string
  21. OriginUrl string
  22. Username string
  23. Password string
  24. ServiceBase
  25. }
  26. func GetActivitiService(xormEngine *xorm.Engine) *ActivitiService {
  27. s := new(ActivitiService)
  28. s.DBE = xormEngine
  29. //s.BaseUrl = "http://123.56.168.26:8080/activiti-rest/service"
  30. //s.BaseUrl = "http://192.168.0.120:8081/api/acti"
  31. s.BaseUrl = utils.Cfg.MustValue("workflow", "BaseUrl")
  32. //s.BaseUrl = "http://localhost:8081/api/acti"
  33. s.AposeUrl = utils.Cfg.MustValue("workflow", "AposeUrl")
  34. //s.OriginUrl = "http://localhost:8081/api"
  35. s.OriginUrl = utils.Cfg.MustValue("workflow", "OriginUrl")
  36. //s.AposeUrl = "http://localhost:8081/api/apose"
  37. //s.AposeUrl = "http://192.168.0.171:8081/api/apose"
  38. s.Username = "leader"
  39. s.Password = "123456"
  40. return s
  41. }
  42. func (this *ActivitiService) Post(url string, params string, token string) *http.Response {
  43. client := &http.Client{}
  44. req, err := http.NewRequest("POST", this.BaseUrl+url, strings.NewReader(params))
  45. req.Header.Add("Content-Type", "application/json")
  46. req.Header.Add("Authorization", "Bearer "+token)
  47. resp, err := client.Do(req)
  48. if err != nil {
  49. log.Println("err= ", err)
  50. }
  51. log.Println("resp= ", resp)
  52. return resp
  53. }
  54. func (this *ActivitiService) Post2(url string, params string, token string) *http.Response {
  55. client := &http.Client{}
  56. req, err := http.NewRequest("POST", this.AposeUrl+url, strings.NewReader(params))
  57. req.Header.Add("Content-Type", "application/json")
  58. req.Header.Add("Authorization", "Bearer "+token)
  59. resp, err := client.Do(req)
  60. if err != nil {
  61. log.Println("err= ", err)
  62. }
  63. log.Println("resp= ", resp)
  64. return resp
  65. }
  66. func (this *ActivitiService) PostOrigin(url string, params string, token string) *http.Response {
  67. client := &http.Client{}
  68. req, err := http.NewRequest("POST", this.OriginUrl+url, strings.NewReader(params))
  69. req.Header.Add("Content-Type", "application/json")
  70. req.Header.Add("Authorization", "Bearer "+token)
  71. resp, err := client.Do(req)
  72. if err != nil {
  73. log.Println("err= ", err)
  74. }
  75. log.Println("resp= ", resp)
  76. return resp
  77. }
  78. func (this *ActivitiService) Get(url string, params string, token string) *http.Response {
  79. client := &http.Client{}
  80. req, err := http.NewRequest("Get", this.BaseUrl+url, strings.NewReader(params))
  81. req.Header.Add("Content-Type", "application/json")
  82. req.Header.Add("Authorization", "Bearer "+token)
  83. resp, err := client.Do(req)
  84. if err != nil {
  85. log.Println("err= ", err)
  86. }
  87. log.Println("resp= ", resp)
  88. return resp
  89. }
  90. func (this *ActivitiService) StartProcess(processKey string, formEntityId string, userNames string) string {
  91. /*vars := make(map[string]string)
  92. vars["processDefinitionKey"] = processKey
  93. vars["formEntityId"] = formEntityId*/
  94. /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
  95. var ActiProcess ActiProcessVM
  96. ActiProcess.ProcessKey = processKey
  97. ActiProcess.BusinessKey = formEntityId
  98. ActiProcess.UserNames = userNames
  99. json, err := json.Marshal(ActiProcess)
  100. if err != nil {
  101. fmt.Println(err, "生成json字符串错误")
  102. }
  103. params := string(json)
  104. fmt.Println(params)
  105. //token = Authorization(this.Username, this.Password)
  106. retVal := this.Post("/start-process", params, "")
  107. p, _ := ioutil.ReadAll(retVal.Body)
  108. return string(p)
  109. }
  110. func (this *ActivitiService) StartProcess2(processKey, formEntityId, userNames, result, supplierType, supplierName string) string {
  111. /*vars := make(map[string]string)
  112. vars["processDefinitionKey"] = processKey
  113. vars["formEntityId"] = formEntityId*/
  114. /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
  115. var ActiProcess ActiProcessVM
  116. ActiProcess.ProcessKey = processKey
  117. ActiProcess.BusinessKey = formEntityId
  118. ActiProcess.UserNames = userNames
  119. ActiProcess.Result = result
  120. ActiProcess.WfType = supplierType
  121. ActiProcess.SupplierName = supplierName
  122. json, err := json.Marshal(ActiProcess)
  123. if err != nil {
  124. // panic(err., "生成json字符串错误")
  125. panic("生成json字符串错误")
  126. }
  127. params := string(json)
  128. fmt.Println(params)
  129. //token = Authorization(this.Username, this.Password)
  130. retVal := this.Post("/start-process-bytype", params, "")
  131. p, _ := ioutil.ReadAll(retVal.Body)
  132. return string(p)
  133. }
  134. //func (this *ActivitiService) TaskComplete(processKey string, formEntityId string, userNames string, userId string, result string, remarks string) string {
  135. /*var ActiComplete ActiCompleteVM
  136. ActiComplete.ProcessKey = processKey
  137. ActiComplete.BusinessKey = formEntityId
  138. ActiComplete.UserNames = userNames
  139. ActiComplete.UserId = userId
  140. ActiComplete.Result = result
  141. ActiComplete.Remarks = remarks*/
  142. func (this *ActivitiService) TaskComplete(ActiComplete ActiCompleteVM) string {
  143. jsonParams, err := json.Marshal(ActiComplete)
  144. if err != nil {
  145. fmt.Println(err, "生成json字符串错误")
  146. }
  147. params := string(jsonParams)
  148. fmt.Println(params)
  149. //token = Authorization(this.Username, this.Password)
  150. retVal := this.Post("/task-complete", params, "")
  151. p, _ := ioutil.ReadAll(retVal.Body)
  152. return string(p)
  153. }
  154. /*func (this *ActivitiService) MultiTaskComplete(processKey string, formEntityId string, userNames string, multiOrgAudits []MultiOrgAuditVM, userId string, result string, remarks string, callbackUrl string) string {
  155. var ActiComplete MultiActiCompleteVM
  156. ActiComplete.ProcessKey = processKey
  157. ActiComplete.BusinessKey = formEntityId
  158. ActiComplete.UserNames = userNames
  159. ActiComplete.MultiOrgAudits = multiOrgAudits
  160. ActiComplete.UserId = userId
  161. ActiComplete.Result = result
  162. ActiComplete.Remarks = remarks
  163. ActiComplete.CallbackUrl = callbackUrl*/
  164. func (this *ActivitiService) MultiTaskComplete(ActiComplete MultiActiCompleteVM) string {
  165. jsonParams, err := json.Marshal(ActiComplete)
  166. if err != nil {
  167. fmt.Println(err, "生成json字符串错误")
  168. }
  169. params := string(jsonParams)
  170. fmt.Println(params)
  171. //token = Authorization(this.Username, this.Password)
  172. retVal := this.Post("/multi-task-complete", params, "")
  173. p, _ := ioutil.ReadAll(retVal.Body)
  174. return string(p)
  175. }
  176. func (this *ActivitiService) GetMyTasks(processKey string, userId string) string {
  177. var ActiMyTasks ActiMyTasksVM
  178. ActiMyTasks.ProcessKey = processKey
  179. ActiMyTasks.UserId = userId
  180. json, err := json.Marshal(ActiMyTasks)
  181. if err != nil {
  182. fmt.Println(err, "生成json字符串错误")
  183. }
  184. params := string(json)
  185. fmt.Println(params)
  186. //token = Authorization(this.Username, this.Password)
  187. retVal := this.Post("/my-tasks", params, "")
  188. p, _ := ioutil.ReadAll(retVal.Body)
  189. return string(p)
  190. }
  191. func (this *ActivitiService) GetMyTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
  192. var ActiMyTasks ActiMyTasksVM
  193. ActiMyTasks.ProcessKey = processKey
  194. ActiMyTasks.UserId = userId
  195. jsonParam, err := json.Marshal(ActiMyTasks)
  196. if err != nil {
  197. fmt.Println(err, "生成json字符串错误")
  198. }
  199. params := string(jsonParam)
  200. fmt.Println(params)
  201. //token = Authorization(this.Username, this.Password)
  202. retVal := this.Post("/my-tasks-with-time", params, "")
  203. p, _ := ioutil.ReadAll(retVal.Body)
  204. myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
  205. json.Unmarshal(p, &myTasksRetWithTimes)
  206. return myTasksRetWithTimes
  207. }
  208. func (this *ActivitiService) GetMyFinishedTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
  209. var ActiMyTasks ActiMyTasksVM
  210. ActiMyTasks.ProcessKey = processKey
  211. ActiMyTasks.UserId = userId
  212. jsonParam, err := json.Marshal(ActiMyTasks)
  213. if err != nil {
  214. fmt.Println(err, "生成json字符串错误")
  215. }
  216. params := string(jsonParam)
  217. fmt.Println(params)
  218. //token = Authorization(this.Username, this.Password)
  219. retVal := this.Post("/my-finished-tasks-with-time", params, "")
  220. p, _ := ioutil.ReadAll(retVal.Body)
  221. myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
  222. json.Unmarshal(p, &myTasksRetWithTimes)
  223. return myTasksRetWithTimes
  224. }
  225. func (this *ActivitiService) GetMyAllTypePagingTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
  226. var myPagingTasks ActiMyPagingTasksVM
  227. myPagingTasks.UserId = userId
  228. myPagingTasks.PageIndex = PageIndex
  229. myPagingTasks.PageSize = PageSize
  230. myPagingTasks.WfName = wfName
  231. myPagingTasks.WfType = wfType
  232. myPagingTasks.SupplierName = supplierName
  233. jsonParam, err := json.Marshal(myPagingTasks)
  234. if err != nil {
  235. fmt.Println(err, "生成json字符串错误")
  236. }
  237. params := string(jsonParam)
  238. fmt.Println(params)
  239. //token = Authorization(this.Username, this.Password)
  240. retVal := this.Post("/my-all-type-paging-tasks-with-time", params, "")
  241. p, _ := ioutil.ReadAll(retVal.Body)
  242. var myTasksRetWithTimes ActiMyPagingResultVM
  243. json.Unmarshal(p, &myTasksRetWithTimes)
  244. return myTasksRetWithTimes
  245. }
  246. func (this *ActivitiService) GetMyAllTypePagingFinishedTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
  247. var myPagingTasks ActiMyPagingTasksVM
  248. myPagingTasks.UserId = userId
  249. myPagingTasks.PageIndex = PageIndex
  250. myPagingTasks.PageSize = PageSize
  251. myPagingTasks.WfName = wfName
  252. myPagingTasks.WfType = wfType
  253. myPagingTasks.SupplierName = supplierName
  254. jsonParam, err := json.Marshal(myPagingTasks)
  255. if err != nil {
  256. fmt.Println(err, "生成json字符串错误")
  257. }
  258. params := string(jsonParam)
  259. fmt.Println(params)
  260. //token = Authorization(this.Username, this.Password)
  261. retVal := this.Post("/my-all-type-paging-finished-tasks-with-time", params, "")
  262. p, _ := ioutil.ReadAll(retVal.Body)
  263. var myTasksRetWithTimes ActiMyPagingResultVM
  264. json.Unmarshal(p, &myTasksRetWithTimes)
  265. return myTasksRetWithTimes
  266. }
  267. func (this *ActivitiService) GetHistoricTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
  268. var ActiProcess ActiProcessVM
  269. ActiProcess.ProcessKey = processKey
  270. ActiProcess.BusinessKey = businessKey
  271. ActiProcess.ProcessInstanceId = processInstanceId
  272. jsonParam, err := json.Marshal(ActiProcess)
  273. if err != nil {
  274. fmt.Println(err, "生成json字符串错误")
  275. }
  276. params := string(jsonParam)
  277. fmt.Println(params)
  278. //token = Authorization(this.Username, this.Password)
  279. retVal := this.Post("/historic-tasks", params, "")
  280. jsonblob, _ := ioutil.ReadAll(retVal.Body)
  281. // var historicTasks []ActiHistoricTask
  282. historicTasks := make([]ActiHistoricTask, 0)
  283. json.Unmarshal(jsonblob, &historicTasks)
  284. return historicTasks
  285. }
  286. func (this *ActivitiService) GetHistoricMultiTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
  287. var ActiProcess ActiProcessVM
  288. ActiProcess.ProcessKey = processKey
  289. ActiProcess.BusinessKey = businessKey
  290. ActiProcess.ProcessInstanceId = processInstanceId
  291. jsonParam, err := json.Marshal(ActiProcess)
  292. if err != nil {
  293. fmt.Println(err, "生成json字符串错误")
  294. }
  295. params := string(jsonParam)
  296. fmt.Println(params)
  297. //token = Authorization(this.Username, this.Password)
  298. retVal := this.Post("/historic-multi-tasks", params, "")
  299. jsonblob, _ := ioutil.ReadAll(retVal.Body)
  300. // var historicTasks []ActiHistoricTask
  301. historicTasks := make([]ActiHistoricTask, 0)
  302. json.Unmarshal(jsonblob, &historicTasks)
  303. return historicTasks
  304. }
  305. func (this *ActivitiService) GetActivitiProccessImage(processInstanceId string) []byte {
  306. var ActiProcess ActiProcessVM
  307. ActiProcess.ProcessInstanceId = processInstanceId
  308. jsonParam, err := json.Marshal(ActiProcess)
  309. if err != nil {
  310. fmt.Println(err, "生成json字符串错误")
  311. }
  312. params := string(jsonParam)
  313. //token = Authorization(this.Username, this.Password)
  314. retVal := this.Post("/historic-tasks-image", params, "")
  315. imgByte, _ := ioutil.ReadAll(retVal.Body)
  316. return imgByte
  317. }
  318. func (this *ActivitiService) GetHistoryMyTasks(processKey string, userId string) string {
  319. var ActiMyTasks ActiMyTasksVM
  320. ActiMyTasks.ProcessKey = processKey
  321. ActiMyTasks.UserId = userId
  322. json, err := json.Marshal(ActiMyTasks)
  323. if err != nil {
  324. fmt.Println(err, "生成json字符串错误")
  325. }
  326. params := string(json)
  327. fmt.Println(params)
  328. //token = Authorization(this.Username, this.Password)
  329. retVal := this.Post("/my-tasks-finished", params, "")
  330. p, _ := ioutil.ReadAll(retVal.Body)
  331. return string(p)
  332. }
  333. func (this *ActivitiService) GetAllMyTasks(processKey string, userId string) string {
  334. var ActiMyTasks ActiMyTasksVM
  335. ActiMyTasks.ProcessKey = processKey
  336. ActiMyTasks.UserId = userId
  337. json, err := json.Marshal(ActiMyTasks)
  338. if err != nil {
  339. fmt.Println(err, "生成json字符串错误")
  340. }
  341. params := string(json)
  342. fmt.Println(params)
  343. //token = Authorization(this.Username, this.Password)
  344. retVal := this.Post("/my-tasks-finished", params, "")
  345. p, _ := ioutil.ReadAll(retVal.Body)
  346. retVal2 := this.Post("/my-tasks", params, "")
  347. p2, _ := ioutil.ReadAll(retVal2.Body)
  348. return string(p) + "," + string(p2)
  349. }
  350. func (this *ActivitiService) ExcelToPdf(addressUrl string) string {
  351. var aposeVM AposeVM
  352. aposeVM.AddressUrl = addressUrl
  353. fmt.Println("==addressUrl===", addressUrl)
  354. jsonParam, err := json.Marshal(aposeVM)
  355. if err != nil {
  356. fmt.Println(err, "生成json字符串错误")
  357. }
  358. params := string(jsonParam)
  359. //token = Authorization(this.Username, this.Password)
  360. retVal := this.Post2("/excel-to-pdf", params, "")
  361. if retVal.StatusCode != 200 {
  362. return ""
  363. }
  364. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  365. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  366. //模板下载到服务器
  367. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  368. utils.CreatePath(_dir)
  369. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  370. raw := retVal.Body
  371. defer raw.Close()
  372. file, err := os.Create(_dir)
  373. defer file.Close()
  374. writer := bufio.NewWriter(file)
  375. defer writer.Flush()
  376. body, err := ioutil.ReadAll(raw)
  377. writer.Write(body)
  378. if err != nil {
  379. return ""
  380. }
  381. var sw *Seaweed
  382. var filer []string
  383. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  384. filer = []string{_filer}
  385. }
  386. fmt.Println("GOSWFS_FILER_URL6 == ", os.Getenv("GOSWFS_FILER_URL"))
  387. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  388. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  389. _, _, fID, err := sw.UploadFile(_dir, "", "")
  390. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  391. os.Remove(_dir)
  392. fmt.Println("==retDocUrl==", retDocUrl)
  393. return retDocUrl
  394. }
  395. func (this *ActivitiService) WordToPdf(addressUrl string) string {
  396. var aposeVM AposeVM
  397. aposeVM.AddressUrl = addressUrl
  398. fmt.Println("==addressUrl===", addressUrl)
  399. jsonParam, err := json.Marshal(aposeVM)
  400. if err != nil {
  401. fmt.Println(err, "生成json字符串错误")
  402. }
  403. params := string(jsonParam)
  404. //token = Authorization(this.Username, this.Password)
  405. retVal := this.Post2("/word-to-pdf", params, "")
  406. if retVal.StatusCode != 200 {
  407. return ""
  408. }
  409. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  410. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  411. //模板下载到服务器
  412. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  413. utils.CreatePath(_dir)
  414. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  415. raw := retVal.Body
  416. defer raw.Close()
  417. file, err := os.Create(_dir)
  418. defer file.Close()
  419. writer := bufio.NewWriter(file)
  420. defer writer.Flush()
  421. body, err := ioutil.ReadAll(raw)
  422. writer.Write(body)
  423. if err != nil {
  424. return ""
  425. }
  426. var sw *Seaweed
  427. var filer []string
  428. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  429. filer = []string{_filer}
  430. }
  431. fmt.Println("GOSWFS_FILER_URL5 == ", os.Getenv("GOSWFS_FILER_URL"))
  432. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  433. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  434. _, _, fID, err := sw.UploadFile(_dir, "", "")
  435. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  436. os.Remove(_dir)
  437. fmt.Println("==retDocUrl==", retDocUrl)
  438. return retDocUrl
  439. }
  440. func (this *ActivitiService) WordToPdfWithWatermark(wartermark, addressUrl string) string {
  441. var aposeVM AposeVM
  442. aposeVM.AddressUrl = addressUrl
  443. aposeVM.Watermark = wartermark
  444. fmt.Println("==addressUrl===", addressUrl)
  445. jsonParam, err := json.Marshal(aposeVM)
  446. if err != nil {
  447. fmt.Println(err, "生成json字符串错误")
  448. }
  449. params := string(jsonParam)
  450. //token = Authorization(this.Username, this.Password)
  451. retVal := this.Post2("/word-to-pdf-watermark", params, "")
  452. if retVal.StatusCode != 200 {
  453. return ""
  454. }
  455. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  456. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  457. //模板下载到服务器
  458. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  459. utils.CreatePath(_dir)
  460. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  461. raw := retVal.Body
  462. defer raw.Close()
  463. file, err := os.Create(_dir)
  464. defer file.Close()
  465. writer := bufio.NewWriter(file)
  466. defer writer.Flush()
  467. body, err := ioutil.ReadAll(raw)
  468. writer.Write(body)
  469. if err != nil {
  470. return ""
  471. }
  472. var sw *Seaweed
  473. var filer []string
  474. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  475. filer = []string{_filer}
  476. }
  477. fmt.Println("GOSWFS_FILER_URL4 == ", os.Getenv("GOSWFS_FILER_URL"))
  478. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  479. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  480. _, _, fID, err := sw.UploadFile(_dir, "", "")
  481. fmt.Println("err_表单下载4=", err)
  482. fmt.Println("fID_表单下载4=", fID)
  483. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  484. os.Remove(_dir)
  485. fmt.Println("==retDocUrl==", retDocUrl)
  486. return retDocUrl
  487. }
  488. func (this *ActivitiService) FillWordTemplate(datas map[string]interface{}, templateUrl string, fileName string) string {
  489. var wordTempVM WordTemplateVM
  490. wordTempVM.Datas = datas
  491. wordTempVM.TemplateUrl = templateUrl
  492. wordTempVM.FileName = fileName
  493. fmt.Println("==templateUrl===", templateUrl)
  494. jsonParam, err := json.Marshal(wordTempVM)
  495. if err != nil {
  496. fmt.Println(err, "生成json字符串错误")
  497. }
  498. params := string(jsonParam)
  499. //token = Authorization(this.Username, this.Password)
  500. retVal := this.PostOrigin("/word/fill-word", params, "")
  501. if retVal.StatusCode != 200 {
  502. return ""
  503. }
  504. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  505. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  506. //模板下载到服务器
  507. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
  508. utils.CreatePath(_dir)
  509. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
  510. raw := retVal.Body
  511. defer raw.Close()
  512. file, err := os.Create(_dir)
  513. defer file.Close()
  514. writer := bufio.NewWriter(file)
  515. defer writer.Flush()
  516. body, err := ioutil.ReadAll(raw)
  517. writer.Write(body)
  518. if err != nil {
  519. return ""
  520. }
  521. var sw *Seaweed
  522. var filer []string
  523. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  524. filer = []string{_filer}
  525. }
  526. fmt.Println("GOSWFS_FILER_URL3 == ", os.Getenv("GOSWFS_FILER_URL"))
  527. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  528. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  529. _, _, fID, err := sw.UploadFile(_dir, "", "")
  530. fmt.Println("err_表单下载3=", err)
  531. fmt.Println("fID_表单下载3=", fID)
  532. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  533. os.Remove(_dir)
  534. fmt.Println("==retDocUrl==", retDocUrl)
  535. return retDocUrl
  536. }
  537. func (this *ActivitiService) FillExcel(datas map[string]interface{}, ContractClass string, templateUrl string, fileName string) string {
  538. var wordTempVM excelTemplateVM
  539. wordTempVM.ContractClass = ContractClass
  540. wordTempVM.Datas = datas
  541. wordTempVM.TemplateUrl = templateUrl
  542. wordTempVM.FileName = fileName
  543. jsonParam, err := json.Marshal(wordTempVM)
  544. if err != nil {
  545. fmt.Println(err, "生成json字符串错误")
  546. }
  547. params := string(jsonParam)
  548. retVal := this.PostOrigin("/excel/fill-excel", params, "")
  549. if retVal.StatusCode != 200 {
  550. return ""
  551. }
  552. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
  553. utils.CreatePath(_dir)
  554. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  555. raw := retVal.Body
  556. defer raw.Close()
  557. file, err := os.Create(_dir)
  558. defer file.Close()
  559. writer := bufio.NewWriter(file)
  560. defer writer.Flush()
  561. body, err := ioutil.ReadAll(raw)
  562. writer.Write(body)
  563. if err != nil {
  564. return ""
  565. }
  566. var sw *Seaweed
  567. var filer []string
  568. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  569. filer = []string{_filer}
  570. }
  571. fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
  572. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  573. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  574. _, _, fID, err := sw.UploadFile(_dir, "", "")
  575. fmt.Println("err_表单下载2=", err)
  576. fmt.Println("fID_表单下载2=", fID)
  577. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  578. os.Remove(_dir)
  579. fmt.Println("==retDocUrl==", retDocUrl)
  580. return retDocUrl
  581. }
  582. func (this *ActivitiService) ContrastExcel(datas map[string]interface{}, templateUrl string, fileName string) string {
  583. var wordTempVM excelContrastVM
  584. wordTempVM.Datas = datas
  585. wordTempVM.TemplateUrl = templateUrl
  586. wordTempVM.FileName = fileName
  587. jsonParam, err := json.Marshal(wordTempVM)
  588. if err != nil {
  589. fmt.Println(err, "生成json字符串错误")
  590. }
  591. params := string(jsonParam)
  592. retVal := this.PostOrigin("/excel/contrast-excel", params, "")
  593. if retVal.StatusCode != 200 {
  594. return ""
  595. }
  596. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
  597. utils.CreatePath(_dir)
  598. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  599. raw := retVal.Body
  600. defer raw.Close()
  601. file, err := os.Create(_dir)
  602. defer file.Close()
  603. writer := bufio.NewWriter(file)
  604. defer writer.Flush()
  605. body, err := ioutil.ReadAll(raw)
  606. writer.Write(body)
  607. if err != nil {
  608. return ""
  609. }
  610. var sw *Seaweed
  611. var filer []string
  612. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  613. filer = []string{_filer}
  614. }
  615. fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
  616. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  617. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  618. _, _, fID, err := sw.UploadFile(_dir, "", "")
  619. fmt.Println("err_表单下载2=", err)
  620. fmt.Println("fID_表单下载2=", fID)
  621. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  622. os.Remove(_dir)
  623. fmt.Println("==retDocUrl==", retDocUrl)
  624. return retDocUrl
  625. }
  626. // 带水印
  627. func (this *ActivitiService) FillWordWatermarkTemplate(datas map[string]interface{}, templateUrl string, fileName,watermark string) string {
  628. var wordTempVM WordTemplateWatermarkVM
  629. wordTempVM.Datas = datas
  630. wordTempVM.TemplateUrl = templateUrl
  631. wordTempVM.FileName = fileName
  632. wordTempVM.Watermark = watermark
  633. fmt.Println("==templateWatermarkUrl===", templateUrl)
  634. jsonParam, err := json.Marshal(wordTempVM)
  635. if err != nil {
  636. fmt.Println(err, "生成json字符串错误")
  637. }
  638. params := string(jsonParam)
  639. //token = Authorization(this.Username, this.Password)
  640. retVal := this.PostOrigin("/word/fill-word-watermark", params, "")
  641. if retVal.StatusCode != 200 {
  642. return ""
  643. }
  644. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  645. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  646. //模板下载到服务器
  647. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
  648. utils.CreatePath(_dir)
  649. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
  650. raw := retVal.Body
  651. defer raw.Close()
  652. file, err := os.Create(_dir)
  653. defer file.Close()
  654. writer := bufio.NewWriter(file)
  655. defer writer.Flush()
  656. body, err := ioutil.ReadAll(raw)
  657. writer.Write(body)
  658. if err != nil {
  659. return ""
  660. }
  661. var sw *Seaweed
  662. var filer []string
  663. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  664. filer = []string{_filer}
  665. }
  666. fmt.Println("GOSWFS_FILER_URL1 == ", os.Getenv("GOSWFS_FILER_URL"))
  667. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  668. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  669. _, _, fID, err := sw.UploadFile(_dir, "", "")
  670. fmt.Println("err_表单下载=", err)
  671. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  672. os.Remove(_dir)
  673. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  674. return retDocUrl
  675. }