2
3

ActivitiService.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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) PostToDu(url string, params string, token string) *http.Response {
  79. client := &http.Client{}
  80. ip := utils.Cfg.MustValue("workflow", "ToDu")
  81. req, err := http.NewRequest("POST", ip+url, strings.NewReader(params))
  82. req.Header.Add("Content-Type", "application/json")
  83. req.Header.Add("Authorization", "Bearer "+token)
  84. resp, err := client.Do(req)
  85. if err != nil {
  86. log.Println("err= ", err)
  87. }
  88. log.Println("resp= ", resp)
  89. return resp
  90. }
  91. func (this *ActivitiService) Get(url string, params string, token string) *http.Response {
  92. client := &http.Client{}
  93. req, err := http.NewRequest("Get", this.BaseUrl+url, strings.NewReader(params))
  94. req.Header.Add("Content-Type", "application/json")
  95. req.Header.Add("Authorization", "Bearer "+token)
  96. resp, err := client.Do(req)
  97. if err != nil {
  98. log.Println("err= ", err)
  99. }
  100. log.Println("resp= ", resp)
  101. return resp
  102. }
  103. func (this *ActivitiService) StartProcess(processKey string, formEntityId string, userNames string) string {
  104. /*vars := make(map[string]string)
  105. vars["processDefinitionKey"] = processKey
  106. vars["formEntityId"] = formEntityId*/
  107. /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
  108. var ActiProcess ActiProcessVM
  109. ActiProcess.ProcessKey = processKey
  110. ActiProcess.BusinessKey = formEntityId
  111. ActiProcess.UserNames = userNames
  112. json, err := json.Marshal(ActiProcess)
  113. if err != nil {
  114. fmt.Println(err, "生成json字符串错误")
  115. }
  116. params := string(json)
  117. fmt.Println(params)
  118. //token = Authorization(this.Username, this.Password)
  119. retVal := this.Post("/start-process", params, "")
  120. p, _ := ioutil.ReadAll(retVal.Body)
  121. return string(p)
  122. }
  123. func (this *ActivitiService) StartProcess2(processKey, formEntityId, userNames, result, supplierType, supplierName string) string {
  124. /*vars := make(map[string]string)
  125. vars["processDefinitionKey"] = processKey
  126. vars["formEntityId"] = formEntityId*/
  127. /*params := "processDefinitionKey="+processKey+"&formEntityId"+formEntityId*/
  128. var ActiProcess ActiProcessVM
  129. ActiProcess.ProcessKey = processKey
  130. ActiProcess.BusinessKey = formEntityId
  131. ActiProcess.UserNames = userNames
  132. ActiProcess.Result = result
  133. ActiProcess.WfType = supplierType
  134. ActiProcess.SupplierName = supplierName
  135. json, err := json.Marshal(ActiProcess)
  136. if err != nil {
  137. // panic(err., "生成json字符串错误")
  138. panic("生成json字符串错误")
  139. }
  140. params := string(json)
  141. fmt.Println(params)
  142. //token = Authorization(this.Username, this.Password)
  143. retVal := this.Post("/start-process-bytype", params, "")
  144. p, _ := ioutil.ReadAll(retVal.Body)
  145. return string(p)
  146. }
  147. //func (this *ActivitiService) TaskComplete(processKey string, formEntityId string, userNames string, userId string, result string, remarks string) string {
  148. /*var ActiComplete ActiCompleteVM
  149. ActiComplete.ProcessKey = processKey
  150. ActiComplete.BusinessKey = formEntityId
  151. ActiComplete.UserNames = userNames
  152. ActiComplete.UserId = userId
  153. ActiComplete.Result = result
  154. ActiComplete.Remarks = remarks*/
  155. func (this *ActivitiService) TaskComplete(ActiComplete ActiCompleteVM) string {
  156. jsonParams, err := json.Marshal(ActiComplete)
  157. if err != nil {
  158. fmt.Println(err, "生成json字符串错误")
  159. }
  160. params := string(jsonParams)
  161. fmt.Println(params)
  162. //token = Authorization(this.Username, this.Password)
  163. retVal := this.Post("/task-complete", params, "")
  164. p, _ := ioutil.ReadAll(retVal.Body)
  165. return string(p)
  166. }
  167. func (this *ActivitiService) SuspendComplete(deleteProcessVM DeleteProcessVM) string {
  168. jsonParams, err := json.Marshal(deleteProcessVM)
  169. if err != nil {
  170. fmt.Println(err, "生成json字符串错误")
  171. }
  172. params := string(jsonParams)
  173. fmt.Println(params)
  174. //token = Authorization(this.Username, this.Password)
  175. retVal := this.Post("/suspend-process-instance", params, "")
  176. p, _ := ioutil.ReadAll(retVal.Body)
  177. return string(p)
  178. }
  179. func (this *ActivitiService) DeleteComplete(deleteProcessVM DeleteProcessVM) string {
  180. jsonParams, err := json.Marshal(deleteProcessVM)
  181. if err != nil {
  182. fmt.Println(err, "生成json字符串错误")
  183. }
  184. params := string(jsonParams)
  185. fmt.Println(params)
  186. //token = Authorization(this.Username, this.Password)
  187. retVal := this.Post("/delete-process-instance", params, "")
  188. p, _ := ioutil.ReadAll(retVal.Body)
  189. return string(p)
  190. }
  191. /*func (this *ActivitiService) MultiTaskComplete(processKey string, formEntityId string, userNames string, multiOrgAudits []MultiOrgAuditVM, userId string, result string, remarks string, callbackUrl string) string {
  192. var ActiComplete MultiActiCompleteVM
  193. ActiComplete.ProcessKey = processKey
  194. ActiComplete.BusinessKey = formEntityId
  195. ActiComplete.UserNames = userNames
  196. ActiComplete.MultiOrgAudits = multiOrgAudits
  197. ActiComplete.UserId = userId
  198. ActiComplete.Result = result
  199. ActiComplete.Remarks = remarks
  200. ActiComplete.CallbackUrl = callbackUrl*/
  201. func (this *ActivitiService) MultiTaskComplete(ActiComplete MultiActiCompleteVM) string {
  202. jsonParams, err := json.Marshal(ActiComplete)
  203. if err != nil {
  204. fmt.Println(err, "生成json字符串错误")
  205. }
  206. params := string(jsonParams)
  207. fmt.Println(params)
  208. //token = Authorization(this.Username, this.Password)
  209. retVal := this.Post("/multi-task-complete", params, "")
  210. p, _ := ioutil.ReadAll(retVal.Body)
  211. return string(p)
  212. }
  213. func (this *ActivitiService) GetMyTasks(processKey string, userId string) string {
  214. var ActiMyTasks ActiMyTasksVM
  215. ActiMyTasks.ProcessKey = processKey
  216. ActiMyTasks.UserId = userId
  217. json, err := json.Marshal(ActiMyTasks)
  218. if err != nil {
  219. fmt.Println(err, "生成json字符串错误")
  220. }
  221. params := string(json)
  222. fmt.Println(params)
  223. //token = Authorization(this.Username, this.Password)
  224. retVal := this.Post("/my-tasks", params, "")
  225. p, _ := ioutil.ReadAll(retVal.Body)
  226. return string(p)
  227. }
  228. func (this *ActivitiService) GetMyTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
  229. var ActiMyTasks ActiMyTasksVM
  230. ActiMyTasks.ProcessKey = processKey
  231. ActiMyTasks.UserId = userId
  232. jsonParam, err := json.Marshal(ActiMyTasks)
  233. if err != nil {
  234. fmt.Println(err, "生成json字符串错误")
  235. }
  236. params := string(jsonParam)
  237. fmt.Println(params)
  238. //token = Authorization(this.Username, this.Password)
  239. retVal := this.Post("/my-tasks-with-time", params, "")
  240. p, _ := ioutil.ReadAll(retVal.Body)
  241. myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
  242. json.Unmarshal(p, &myTasksRetWithTimes)
  243. return myTasksRetWithTimes
  244. }
  245. func (this *ActivitiService) GetMyFinishedTasksWithTime(processKey string, userId string) []ActiMyTasksRetWithTimeVM {
  246. var ActiMyTasks ActiMyTasksVM
  247. ActiMyTasks.ProcessKey = processKey
  248. ActiMyTasks.UserId = userId
  249. jsonParam, err := json.Marshal(ActiMyTasks)
  250. if err != nil {
  251. fmt.Println(err, "生成json字符串错误")
  252. }
  253. params := string(jsonParam)
  254. fmt.Println(params)
  255. //token = Authorization(this.Username, this.Password)
  256. retVal := this.Post("/my-finished-tasks-with-time", params, "")
  257. p, _ := ioutil.ReadAll(retVal.Body)
  258. myTasksRetWithTimes := make([]ActiMyTasksRetWithTimeVM, 0)
  259. json.Unmarshal(p, &myTasksRetWithTimes)
  260. return myTasksRetWithTimes
  261. }
  262. func (this *ActivitiService) GetMyAllTypePagingTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
  263. var myPagingTasks ActiMyPagingTasksVM
  264. myPagingTasks.UserId = userId
  265. myPagingTasks.PageIndex = PageIndex
  266. myPagingTasks.PageSize = PageSize
  267. myPagingTasks.WfName = wfName
  268. myPagingTasks.WfType = wfType
  269. myPagingTasks.SupplierName = supplierName
  270. jsonParam, err := json.Marshal(myPagingTasks)
  271. if err != nil {
  272. fmt.Println(err, "生成json字符串错误")
  273. }
  274. params := string(jsonParam)
  275. //fmt.Println(params)
  276. //token = Authorization(this.Username, this.Password)
  277. retVal := this.Post("/my-all-type-paging-tasks-with-time", params, "")
  278. p, _ := ioutil.ReadAll(retVal.Body)
  279. var myTasksRetWithTimes ActiMyPagingResultVM
  280. json.Unmarshal(p, &myTasksRetWithTimes)
  281. return myTasksRetWithTimes
  282. }
  283. func (this *ActivitiService) GetMyAllTypePagingFinishedTasksWithTime(userId string, PageIndex, PageSize int64, wfName, wfType, supplierName string) ActiMyPagingResultVM {
  284. var myPagingTasks ActiMyPagingTasksVM
  285. myPagingTasks.UserId = userId
  286. myPagingTasks.PageIndex = PageIndex
  287. myPagingTasks.PageSize = PageSize
  288. myPagingTasks.WfName = wfName
  289. myPagingTasks.WfType = wfType
  290. myPagingTasks.SupplierName = supplierName
  291. jsonParam, err := json.Marshal(myPagingTasks)
  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("/my-all-type-paging-finished-tasks-with-time", params, "")
  299. p, _ := ioutil.ReadAll(retVal.Body)
  300. var myTasksRetWithTimes ActiMyPagingResultVM
  301. json.Unmarshal(p, &myTasksRetWithTimes)
  302. return myTasksRetWithTimes
  303. }
  304. func (this *ActivitiService) GetHistoricTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
  305. var ActiProcess ActiProcessVM
  306. ActiProcess.ProcessKey = processKey
  307. ActiProcess.BusinessKey = businessKey
  308. ActiProcess.ProcessInstanceId = processInstanceId
  309. jsonParam, err := json.Marshal(ActiProcess)
  310. if err != nil {
  311. fmt.Println(err, "生成json字符串错误")
  312. }
  313. params := string(jsonParam)
  314. fmt.Println(params)
  315. //token = Authorization(this.Username, this.Password)
  316. retVal := this.Post("/historic-tasks", params, "")
  317. jsonblob, _ := ioutil.ReadAll(retVal.Body)
  318. // var historicTasks []ActiHistoricTask
  319. historicTasks := make([]ActiHistoricTask, 0)
  320. json.Unmarshal(jsonblob, &historicTasks)
  321. return historicTasks
  322. }
  323. func (this *ActivitiService) GetHistoricMultiTasks(processKey string, businessKey string, processInstanceId string) []ActiHistoricTask {
  324. var ActiProcess ActiProcessVM
  325. ActiProcess.ProcessKey = processKey
  326. ActiProcess.BusinessKey = businessKey
  327. ActiProcess.ProcessInstanceId = processInstanceId
  328. jsonParam, err := json.Marshal(ActiProcess)
  329. if err != nil {
  330. fmt.Println(err, "生成json字符串错误")
  331. }
  332. params := string(jsonParam)
  333. fmt.Println(params)
  334. //token = Authorization(this.Username, this.Password)
  335. retVal := this.Post("/historic-multi-tasks", params, "")
  336. jsonblob, _ := ioutil.ReadAll(retVal.Body)
  337. // var historicTasks []ActiHistoricTask
  338. historicTasks := make([]ActiHistoricTask, 0)
  339. json.Unmarshal(jsonblob, &historicTasks)
  340. return historicTasks
  341. }
  342. func (this *ActivitiService) GetActivitiProccessImage(processInstanceId string) []byte {
  343. var ActiProcess ActiProcessVM
  344. ActiProcess.ProcessInstanceId = processInstanceId
  345. jsonParam, err := json.Marshal(ActiProcess)
  346. if err != nil {
  347. fmt.Println(err, "生成json字符串错误")
  348. }
  349. params := string(jsonParam)
  350. //token = Authorization(this.Username, this.Password)
  351. retVal := this.Post("/historic-tasks-image", params, "")
  352. imgByte, _ := ioutil.ReadAll(retVal.Body)
  353. return imgByte
  354. }
  355. func (this *ActivitiService) GetHistoryMyTasks(processKey string, userId string) string {
  356. var ActiMyTasks ActiMyTasksVM
  357. ActiMyTasks.ProcessKey = processKey
  358. ActiMyTasks.UserId = userId
  359. json, err := json.Marshal(ActiMyTasks)
  360. if err != nil {
  361. fmt.Println(err, "生成json字符串错误")
  362. }
  363. params := string(json)
  364. fmt.Println(params)
  365. //token = Authorization(this.Username, this.Password)
  366. retVal := this.Post("/my-tasks-finished", params, "")
  367. p, _ := ioutil.ReadAll(retVal.Body)
  368. return string(p)
  369. }
  370. func (this *ActivitiService) GetAllMyTasks(processKey string, userId string) string {
  371. var ActiMyTasks ActiMyTasksVM
  372. ActiMyTasks.ProcessKey = processKey
  373. ActiMyTasks.UserId = userId
  374. json, err := json.Marshal(ActiMyTasks)
  375. if err != nil {
  376. fmt.Println(err, "生成json字符串错误")
  377. }
  378. params := string(json)
  379. fmt.Println(params)
  380. //token = Authorization(this.Username, this.Password)
  381. retVal := this.Post("/my-tasks-finished", params, "")
  382. p, _ := ioutil.ReadAll(retVal.Body)
  383. retVal2 := this.Post("/my-tasks", params, "")
  384. p2, _ := ioutil.ReadAll(retVal2.Body)
  385. return string(p) + "," + string(p2)
  386. }
  387. func (this *ActivitiService) ExcelToPdf(addressUrl string) string {
  388. var aposeVM AposeVM
  389. aposeVM.AddressUrl = addressUrl
  390. fmt.Println("==addressUrl===", addressUrl)
  391. jsonParam, err := json.Marshal(aposeVM)
  392. if err != nil {
  393. fmt.Println(err, "生成json字符串错误")
  394. }
  395. params := string(jsonParam)
  396. //token = Authorization(this.Username, this.Password)
  397. retVal := this.Post2("/excel-to-pdf", params, "")
  398. if retVal.StatusCode != 200 {
  399. return ""
  400. }
  401. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  402. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  403. //模板下载到服务器
  404. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  405. utils.CreatePath(_dir)
  406. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  407. raw := retVal.Body
  408. defer raw.Close()
  409. file, err := os.Create(_dir)
  410. defer file.Close()
  411. writer := bufio.NewWriter(file)
  412. defer writer.Flush()
  413. body, err := ioutil.ReadAll(raw)
  414. writer.Write(body)
  415. if err != nil {
  416. return ""
  417. }
  418. var sw *Seaweed
  419. var filer []string
  420. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  421. filer = []string{_filer}
  422. }
  423. fmt.Println("GOSWFS_FILER_URL6 == ", os.Getenv("GOSWFS_FILER_URL"))
  424. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  425. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  426. _, _, fID, err := sw.UploadFile(_dir, "", "")
  427. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  428. os.Remove(_dir)
  429. fmt.Println("==retDocUrl==", retDocUrl)
  430. return retDocUrl
  431. }
  432. func (this *ActivitiService) WordToPdf(addressUrl string) string {
  433. var aposeVM AposeVM
  434. aposeVM.AddressUrl = addressUrl
  435. fmt.Println("==addressUrl===", addressUrl)
  436. jsonParam, err := json.Marshal(aposeVM)
  437. if err != nil {
  438. fmt.Println(err, "生成json字符串错误")
  439. }
  440. params := string(jsonParam)
  441. //token = Authorization(this.Username, this.Password)
  442. retVal := this.Post2("/word-to-pdf", params, "")
  443. if retVal.StatusCode != 200 {
  444. return ""
  445. }
  446. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  447. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  448. //模板下载到服务器
  449. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  450. utils.CreatePath(_dir)
  451. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  452. raw := retVal.Body
  453. defer raw.Close()
  454. file, err := os.Create(_dir)
  455. defer file.Close()
  456. writer := bufio.NewWriter(file)
  457. defer writer.Flush()
  458. body, err := ioutil.ReadAll(raw)
  459. writer.Write(body)
  460. if err != nil {
  461. return ""
  462. }
  463. var sw *Seaweed
  464. var filer []string
  465. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  466. filer = []string{_filer}
  467. }
  468. fmt.Println("GOSWFS_FILER_URL5 == ", os.Getenv("GOSWFS_FILER_URL"))
  469. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  470. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  471. _, _, fID, err := sw.UploadFile(_dir, "", "")
  472. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  473. os.Remove(_dir)
  474. fmt.Println("==retDocUrl==", retDocUrl)
  475. return retDocUrl
  476. }
  477. func (this *ActivitiService) WordToPdfWithWatermark(wartermark, addressUrl string) string {
  478. var aposeVM AposeVM
  479. aposeVM.AddressUrl = addressUrl
  480. aposeVM.Watermark = wartermark
  481. fmt.Println("==addressUrl===", addressUrl)
  482. jsonParam, err := json.Marshal(aposeVM)
  483. if err != nil {
  484. fmt.Println(err, "生成json字符串错误")
  485. }
  486. params := string(jsonParam)
  487. //token = Authorization(this.Username, this.Password)
  488. retVal := this.Post2("/word-to-pdf-watermark", params, "")
  489. if retVal.StatusCode != 200 {
  490. return ""
  491. }
  492. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  493. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  494. //模板下载到服务器
  495. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
  496. utils.CreatePath(_dir)
  497. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
  498. raw := retVal.Body
  499. defer raw.Close()
  500. file, err := os.Create(_dir)
  501. defer file.Close()
  502. writer := bufio.NewWriter(file)
  503. defer writer.Flush()
  504. body, err := ioutil.ReadAll(raw)
  505. writer.Write(body)
  506. if err != nil {
  507. return ""
  508. }
  509. var sw *Seaweed
  510. var filer []string
  511. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  512. filer = []string{_filer}
  513. }
  514. fmt.Println("GOSWFS_FILER_URL4 == ", os.Getenv("GOSWFS_FILER_URL"))
  515. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  516. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  517. _, _, fID, err := sw.UploadFile(_dir, "", "")
  518. fmt.Println("err_表单下载4=", err)
  519. fmt.Println("fID_表单下载4=", fID)
  520. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  521. os.Remove(_dir)
  522. fmt.Println("==retDocUrl==", retDocUrl)
  523. return retDocUrl
  524. }
  525. func (this *ActivitiService) FillWordTemplate(datas map[string]interface{}, templateUrl string, fileName string) string {
  526. var wordTempVM WordTemplateVM
  527. wordTempVM.Datas = datas
  528. wordTempVM.TemplateUrl = templateUrl
  529. wordTempVM.FileName = fileName
  530. fmt.Println("==templateUrl===", templateUrl)
  531. jsonParam, err := json.Marshal(wordTempVM)
  532. if err != nil {
  533. fmt.Println(err, "生成json字符串错误")
  534. }
  535. params := string(jsonParam)
  536. //token = Authorization(this.Username, this.Password)
  537. retVal := this.PostOrigin("/word/fill-word", params, "")
  538. if retVal.StatusCode != 200 {
  539. return ""
  540. }
  541. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  542. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  543. //模板下载到服务器
  544. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
  545. utils.CreatePath(_dir)
  546. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
  547. raw := retVal.Body
  548. defer raw.Close()
  549. file, err := os.Create(_dir)
  550. defer file.Close()
  551. writer := bufio.NewWriter(file)
  552. defer writer.Flush()
  553. body, err := ioutil.ReadAll(raw)
  554. writer.Write(body)
  555. if err != nil {
  556. return ""
  557. }
  558. var sw *Seaweed
  559. var filer []string
  560. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  561. filer = []string{_filer}
  562. }
  563. fmt.Println("GOSWFS_FILER_URL3 == ", os.Getenv("GOSWFS_FILER_URL"))
  564. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  565. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  566. _, _, fID, err := sw.UploadFile(_dir, "", "")
  567. fmt.Println("err_表单下载3=", err)
  568. fmt.Println("fID_表单下载3=", fID)
  569. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  570. os.Remove(_dir)
  571. fmt.Println("==retDocUrl==", retDocUrl)
  572. return retDocUrl
  573. }
  574. func (this *ActivitiService) FillExcel(datas map[string]interface{}, ContractClass string, templateUrl string, fileName string) string {
  575. var wordTempVM excelTemplateVM
  576. wordTempVM.ContractClass = ContractClass
  577. wordTempVM.Datas = datas
  578. wordTempVM.TemplateUrl = templateUrl
  579. wordTempVM.FileName = fileName
  580. jsonParam, err := json.Marshal(wordTempVM)
  581. if err != nil {
  582. fmt.Println(err, "生成json字符串错误")
  583. }
  584. params := string(jsonParam)
  585. retVal := this.PostOrigin("/excel/fill-excel", params, "")
  586. if retVal.StatusCode != 200 {
  587. return ""
  588. }
  589. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
  590. utils.CreatePath(_dir)
  591. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  592. raw := retVal.Body
  593. defer raw.Close()
  594. file, err := os.Create(_dir)
  595. defer file.Close()
  596. writer := bufio.NewWriter(file)
  597. defer writer.Flush()
  598. body, err := ioutil.ReadAll(raw)
  599. writer.Write(body)
  600. if err != nil {
  601. return ""
  602. }
  603. var sw *Seaweed
  604. var filer []string
  605. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  606. filer = []string{_filer}
  607. }
  608. fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
  609. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  610. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  611. _, _, fID, err := sw.UploadFile(_dir, "", "")
  612. fmt.Println("err_表单下载2=", err)
  613. fmt.Println("fID_表单下载2=", fID)
  614. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  615. os.Remove(_dir)
  616. fmt.Println("==retDocUrl==", retDocUrl)
  617. return retDocUrl
  618. }
  619. func (this *ActivitiService) ContrastExcel(datas map[string]interface{}, templateUrl string, fileName string) string {
  620. var wordTempVM excelContrastVM
  621. wordTempVM.Datas = datas
  622. wordTempVM.TemplateUrl = templateUrl
  623. wordTempVM.FileName = fileName
  624. jsonParam, err := json.Marshal(wordTempVM)
  625. if err != nil {
  626. fmt.Println(err, "生成json字符串错误")
  627. }
  628. params := string(jsonParam)
  629. retVal := this.PostOrigin("/excel/contrast-excel", params, "")
  630. if retVal.StatusCode != 200 {
  631. return ""
  632. }
  633. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
  634. utils.CreatePath(_dir)
  635. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  636. raw := retVal.Body
  637. defer raw.Close()
  638. file, err := os.Create(_dir)
  639. if err != nil {
  640. fmt.Println("文件创建失败", err)
  641. }
  642. defer file.Close()
  643. writer := bufio.NewWriter(file)
  644. defer writer.Flush()
  645. body, err := ioutil.ReadAll(raw)
  646. writer.Write(body)
  647. if err != nil {
  648. return ""
  649. }
  650. var sw *Seaweed
  651. var filer []string
  652. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  653. filer = []string{_filer}
  654. }
  655. fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
  656. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  657. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  658. _, _, fID, err := sw.UploadFile(_dir, "", "")
  659. fmt.Println("err_表单下载2=", err)
  660. fmt.Println("fID_表单下载2=", fID)
  661. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  662. os.Remove(_dir)
  663. fmt.Println("==retDocUrl==", retDocUrl)
  664. return retDocUrl
  665. }
  666. /**
  667. 资质配置Java导出
  668. */
  669. func (this *ActivitiService) ExportAptitudeExcel(datas map[string]interface{}, supplierType string, templateUrl string, fileName string) string {
  670. var aptitudeVm excelAptitudeVM
  671. aptitudeVm.SupplierType = supplierType
  672. aptitudeVm.DataList = datas
  673. aptitudeVm.TemplateUrl = templateUrl
  674. aptitudeVm.FileName = "tech_service_tmp_new.xlsx"
  675. jsonParam, err := json.Marshal(aptitudeVm)
  676. if err != nil {
  677. fmt.Println(err, "生成json字符串错误")
  678. }
  679. params := string(jsonParam)
  680. retVal := this.PostOrigin("/excel/aptitude-excel", params, "")
  681. if retVal.StatusCode != 200 {
  682. return ""
  683. }
  684. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "excel"
  685. utils.CreatePath(_dir)
  686. name := ""
  687. if supplierType == "1" {
  688. name = "/goods_"
  689. } else if supplierType == "2" {
  690. name = "/tech_service_"
  691. } else {
  692. name = "/tmp_"
  693. }
  694. _dir += name + strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  695. raw := retVal.Body
  696. defer raw.Close()
  697. file, err := os.Create(_dir)
  698. defer file.Close()
  699. writer := bufio.NewWriter(file)
  700. defer writer.Flush()
  701. body, err := ioutil.ReadAll(raw)
  702. writer.Write(body)
  703. if err != nil {
  704. return ""
  705. }
  706. var sw *Seaweed
  707. var filer []string
  708. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  709. filer = []string{_filer}
  710. }
  711. fmt.Println("GOSWFS_FILER_URL2 == ", os.Getenv("GOSWFS_FILER_URL"))
  712. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  713. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  714. _, _, fID, err := sw.UploadFile(_dir, "", "")
  715. fmt.Println("err_表单下载2=", err)
  716. fmt.Println("fID_表单下载2=", fID)
  717. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  718. os.Remove(_dir)
  719. fmt.Println("==retDocUrl==", retDocUrl)
  720. return retDocUrl
  721. }
  722. // 带水印
  723. func (this *ActivitiService) FillWordWatermarkTemplate(datas map[string]interface{}, templateUrl string, fileName, watermark string) string {
  724. var wordTempVM WordTemplateWatermarkVM
  725. wordTempVM.Datas = datas
  726. wordTempVM.TemplateUrl = templateUrl
  727. wordTempVM.FileName = fileName
  728. wordTempVM.Watermark = watermark
  729. fmt.Println("==templateWatermarkUrl===", templateUrl)
  730. jsonParam, err := json.Marshal(wordTempVM)
  731. if err != nil {
  732. fmt.Println(err, "生成json字符串错误")
  733. }
  734. params := string(jsonParam)
  735. //token = Authorization(this.Username, this.Password)
  736. retVal := this.PostOrigin("/word/fill-word-watermark", params, "")
  737. if retVal.StatusCode != 200 {
  738. return ""
  739. }
  740. //pdfByte, err := ioutil.ReadAll(retVal.Body)
  741. //ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
  742. //模板下载到服务器
  743. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "word"
  744. utils.CreatePath(_dir)
  745. _dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".docx"
  746. raw := retVal.Body
  747. defer raw.Close()
  748. file, err := os.Create(_dir)
  749. defer file.Close()
  750. writer := bufio.NewWriter(file)
  751. defer writer.Flush()
  752. body, err := ioutil.ReadAll(raw)
  753. writer.Write(body)
  754. if err != nil {
  755. return ""
  756. }
  757. var sw *Seaweed
  758. var filer []string
  759. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  760. filer = []string{_filer}
  761. }
  762. fmt.Println("GOSWFS_FILER_URL1 == ", os.Getenv("GOSWFS_FILER_URL"))
  763. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  764. //_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
  765. _, _, fID, err := sw.UploadFile(_dir, "", "")
  766. fmt.Println("err_表单下载=", err)
  767. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  768. os.Remove(_dir)
  769. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  770. return retDocUrl
  771. }
  772. // 获取所有待办任务的审批人
  773. func (this *ActivitiService) GetAllTodoTasksUserId() string {
  774. retVal := this.Post("/all-todo-tasks-user-id", "", "")
  775. p, _ := ioutil.ReadAll(retVal.Body)
  776. return string(p)
  777. }