feature 1.调用openText方式修改

release
zhenghaiyang@ele-cloud.com 2 years ago
parent d074295cd7
commit 565b585fab
  1. 32
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/PushInvoiceServiceImpl.java
  2. 50
      order-management-consumer/src/main/java/com/dxhy/order/consumer/utils/OpentextUtils.java

@ -72,9 +72,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@ -547,10 +544,9 @@ public class PushInvoiceServiceImpl implements PushInvoiceService {
}
private void openTextUploadFile (CommonTsMqData fpTsMqData,List<String> shList){
String uuid = null;
File file = null;
FileOutputStream fos = null;
// File file = null;
// FileOutputStream fos = null;
try {
uuid = UUID.randomUUID().toString();
String invoiceRedisLock = String.format(RedisConstant.REDIS_ORDER_LOCK_OPENTEXT_KEY, fpTsMqData.getFpTsMqData().getFpqqlsh());
@ -583,12 +579,13 @@ public class PushInvoiceServiceImpl implements PushInvoiceService {
//将base64 转为文件对象
if(fileDownLoadList != null && fileDownLoadList.size()> 0){
byte[] decode = Base64Encoding.decode(fileDownLoadList.get(0).getFileContent().getBytes());
file = new File(invoiceConfig.getOpenTextTempPath() + fileDownLoadList.get(0).getFileName());
fos = new FileOutputStream(file);
fos.write(decode);
fos.flush();
// file = new File(invoiceConfig.getOpenTextTempPath() + fileDownLoadList.get(0).getFileName());
// fos = new FileOutputStream(file);
// fos.write(decode);
// fos.flush();
String openTextResult = HttpUtils.uploadFile(file, invoiceConfig.getOpentextUrl(), invoiceConfig.getArcId(), invoiceConfig.getOpentextUserName(), invoiceConfig.getOpentextPasswd());
String openTextResult = OpentextUtils.uploadFile(decode, fileDownLoadList.get(0).getFileName());
// String openTextResult = HttpUtils.uploadFile(file, invoiceConfig.getOpentextUrl(), invoiceConfig.getArcId(), invoiceConfig.getOpentextUserName(), invoiceConfig.getOpentextPasswd());
log.info("调用opentext接口返回结果:{}",openTextResult);
if(StringUtils.isNotBlank(openTextResult)){
List<OpenTextResult> openTextResults = JSONArray.parseArray(openTextResult, OpenTextResult.class);
@ -601,13 +598,12 @@ public class PushInvoiceServiceImpl implements PushInvoiceService {
} catch (Exception e) {
log.error("发送opentext异常:{}",e.getMessage());
} finally {
try {
if(file != null){file.delete();}
if(fos != null) {fos.close();}
} catch (IOException e) {
log.error("发送opentext关闭文件流异常:{}",e.getMessage());
}
// try {
// if(file != null){file.delete();}
// if(fos != null) {fos.close();}
// } catch (IOException e) {
// log.error("发送opentext关闭文件流异常:{}",e.getMessage());
// }
String cacheFpqqlsh = String.format(RedisConstant.REDIS_ORDER_LOCK_OPENTEXT_KEY, fpTsMqData.getFpTsMqData().getFpqqlsh());
if (uuid.equals(redisService.get(cacheFpqqlsh))) {
redisService.del(cacheFpqqlsh);

@ -1,7 +1,6 @@
package com.dxhy.order.consumer.utils;
import com.dxhy.order.model.R;
import com.dxhy.order.utils.JsonUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
@ -13,24 +12,13 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.rmi.RemoteException;
import java.util.Map;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
/**
* @Description: 文件存储工具类
@ -147,7 +135,6 @@ public class OpentextUtils {
try {
builder.addBinaryBody("file", inputStream, ContentType.DEFAULT_BINARY, fileName);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response;
@ -163,6 +150,43 @@ public class OpentextUtils {
}
}
/**
* 上传文件
*
* @param bytes
* @param fileName
* @return
*/
public static String uploadFile(byte[] bytes, String fileName) {
String uploadPath = url + "/uploadFile/UploadServlet?ArcId=" + arcId;
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost(uploadPath);
uploadFile.setHeader("USERNAME", userName);
uploadFile.setHeader("PASSWORD", password);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.RFC6532);
try {
builder.addBinaryBody("file", bytes, ContentType.DEFAULT_BINARY, fileName);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response;
response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();
String sResponse = EntityUtils.toString(responseEntity, "UTF-8");
return sResponse;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 查看文件
*

Loading…
Cancel
Save