//package com.trs.project.util;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//
//import java.io.*;
//import java.util.HashMap;
//import java.util.Map;
//
//public class UpdateFile {
//	private static final String GATEWAY_URL = "http://10.20.100.48:29999";
//	    private static final String APPID = "FT20210610330881";
//	    private static final String SIGN_SECRET = "CiMvFwR5n8dxem8kdhK0vTRhUjGhEag5";
//
//	    public static void main(String[] args) {
//	    	JSONObject htmlsubmitPost = SubmitPost("D:\\work\\upload\\wcm-ipv6.docx","D:\\work\\upload\\wcm-ipv6.html","html","分发正文.doc");
//	    	JSONObject pdfsubmitPost = SubmitPost("C:\\Users\\feihu\\Desktop\\发文发电转换永中\\分发正文.doc","C:\\Users\\feihu\\Desktop\\发文发电转换永中\\分发正文.pdf","pdf","分发正文.doc");
//
//
//		}
//
//	    public static JSONObject SubmitPost(String fileUploadPath,String FileDownloadPath,String targetType,String fileName) {
//	        String fileId = System.currentTimeMillis() + "";
//	        // 上传文件
//	        Map<String, Object> map = new HashMap<>();
//	        map.put("fileName", fileName);
//	        map.put("appId", APPID);
//	        map.put("fileId", fileId);
//	        map.put("userId", "1");
//	        map.put("userName", "张三");
//	        map.put("timeStamp", System.currentTimeMillis() + "");
//	        String signStr = MD5Utils.getRequestSign(new JSONObject(map), SIGN_SECRET);
//	        map.put("sign", signStr);
//	        map.put("file", new File(fileUploadPath));
//	        String responseBody = HttpRequest.post(GATEWAY_URL + "/doc/center/upload/fileUpload").form(map).execute().body();
//	        JSONObject jsonObject = JSON.parseObject(responseBody);
//	        System.out.println("文件上传请求结果:" + jsonObject);
//	        if(jsonObject.getJSONObject("data")==null) {
//	        	return jsonObject;
//	        }
//	        // 转换文件
//	        Map<String, Object> postMap = new HashMap<>();
//	        postMap.put("appId", APPID);
//	        postMap.put("fileId", fileId);
//	        postMap.put("targetType", targetType);
//	        postMap.put("userInfo", new JSONObject().fluentPut("userId", "1").fluentPut("userName", "张三").toJSONString());
//	        postMap.put("timeStamp", System.currentTimeMillis() + "");
//	        String requestSign = MD5Utils.getRequestSign(new JSONObject(postMap), SIGN_SECRET);
//	        postMap.put("sign", requestSign);
//	        String requestBody = JSONObject.toJSONString(postMap);
//	        String requestResult = HttpRequest.post(GATEWAY_URL + "/doc/center/file/convert").body(requestBody).execute().body();
//
//	        JSONObject resultbject = JSON.parseObject(requestResult);
//	        System.out.println("文件转换请求结果:" + resultbject);
//	        if(resultbject.getJSONObject("data")==null) {
//	        	return resultbject;
//	        }
//	        // 下载文件
//	        Map<String, Object> downloadMap = new HashMap<>();
//	        downloadMap.put("appId", APPID);
//	        downloadMap.put("fileId", resultbject.getJSONObject("data").getString("fileId"));
//	        downloadMap.put("userInfo", new JSONObject().fluentPut("userId", "1").fluentPut("userName", "张三").toJSONString());
//	        downloadMap.put("timeStamp", System.currentTimeMillis() + "");
//	        String downloadSign = MD5Utils.getRequestSign(new JSONObject(downloadMap), SIGN_SECRET);
//	        downloadMap.put("sign", downloadSign);
//
//	        HttpResponse centerResponse = HttpRequest.get(GATEWAY_URL + "/doc/center/file/download").form(downloadMap).execute();
//	        InputStream inputStream = centerResponse.bodyStream();
//
//			try {
//				FileOutputStream fileOutputStream = new FileOutputStream(FileDownloadPath);
//		        byte[] b = new byte[1024];
//		        int number = 0;
//		        while (number != -1) {
//		            number = (inputStream.read(b));
//		            if (number == -1) {
//		                break;
//		            } else if (number < 1024) {
//		                byte[] a = new byte[number];
//		                for (int i = 0; i < number; i++) {
//		                    a[i] = b[i];
//		                }
//		                fileOutputStream.write(a);// 写入数据
//		            } else {
//		                fileOutputStream.write(b);// 写入数据
//		            }
//		        }
//		        inputStream.close();
//		        fileOutputStream.close();// 保存数据
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//
//			return resultbject;
//
//	    }
//}
//
