|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.order.baseservice.config.BaseServiceConfig; |
|
|
|
|
import com.dxhy.order.baseservice.module.thirdservice.rabbitmq.service.RabbitMqSendMessageService; |
|
|
|
@ -15,6 +16,7 @@ import com.dxhy.order.consumer.model.protocol.CommonResponse; |
|
|
|
|
import com.dxhy.order.consumer.model.protocol.ResponseData; |
|
|
|
|
import com.dxhy.order.consumer.model.protocol.ResponseStatus; |
|
|
|
|
import com.dxhy.order.consumer.modules.jdjos.service.PushInvoiceToJdJosService; |
|
|
|
|
import com.dxhy.order.consumer.modules.manager.model.OpenTextResult; |
|
|
|
|
import com.dxhy.order.consumer.modules.manager.service.PushInvoiceService; |
|
|
|
|
import com.dxhy.order.consumer.modules.manager.service.QuickCodeInfoService; |
|
|
|
|
import com.dxhy.order.consumer.modules.order.service.OrderCommonService; |
|
|
|
@ -48,6 +50,7 @@ import com.dxhy.order.consumer.openapi.service.CommonDisposeService; |
|
|
|
|
import com.dxhy.order.consumer.openapi.service.InterfaceServiceV5; |
|
|
|
|
import com.dxhy.order.consumer.utils.BeanTransitionUtils; |
|
|
|
|
import com.dxhy.order.consumer.utils.InterfaceBeanTransUtils; |
|
|
|
|
import com.dxhy.order.consumer.utils.OpentextUtils; |
|
|
|
|
import com.dxhy.order.exception.InterfaceException; |
|
|
|
|
import com.dxhy.order.exception.OrderReceiveException; |
|
|
|
|
import com.dxhy.order.invoice.config.InvoiceConfig; |
|
|
|
@ -69,6 +72,9 @@ 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.*; |
|
|
|
@ -356,6 +362,8 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String fptsParam = ""; |
|
|
|
|
//opentext 推送图片
|
|
|
|
|
this.openTextUploadFile(fpTsMqData,shList); |
|
|
|
|
//多个地址循环推送
|
|
|
|
|
for (PushInfo pushInfo : pushInfoList) { |
|
|
|
|
|
|
|
|
@ -538,6 +546,76 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void openTextUploadFile (CommonTsMqData fpTsMqData,List<String> shList){ |
|
|
|
|
|
|
|
|
|
String uuid = 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()); |
|
|
|
|
if (!redisService.setNx(invoiceRedisLock, uuid,RedisConstant.REDIS_EXPIRE_TIME_1MIN)) { |
|
|
|
|
//判断数据过期时间是否为-1,如果为-1,设置为30分钟
|
|
|
|
|
Long expire = redisService.getExpire(invoiceRedisLock); |
|
|
|
|
if(ConfigureConstant.LONG_1_ == expire){ |
|
|
|
|
redisService.setExpire(invoiceRedisLock,RedisConstant.REDIS_EXPIRE_TIME_1MIN); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
OrderInvoiceInfo orderInvoiceInfo1 = new OrderInvoiceInfo(); |
|
|
|
|
orderInvoiceInfo1.setFpqqlsh(fpTsMqData.getFpTsMqData().getFpqqlsh()); |
|
|
|
|
OrderInvoiceInfo orderInvoiceInfo = orderInvoiceInfoService.selectOrderInvoiceInfo(orderInvoiceInfo1, shList); |
|
|
|
|
if(orderInvoiceInfo == null || StringUtils.isNotBlank(orderInvoiceInfo.getDocuId())){ |
|
|
|
|
log.info("发送opentext,发票号码{}不存在或此发票已推送不允许重复推送",fpTsMqData.getFpTsMqData().getFphm()); |
|
|
|
|
throw new Exception("发送opentext,发票号码"+ fpTsMqData.getFpTsMqData().getFphm() +"不存在或此发票已推送不允许重复推送"); |
|
|
|
|
} |
|
|
|
|
boolean fpdmhmDp = (OrderInfoEnum.ORDER_INVOICE_TYPE_51.getKey().equals(orderInvoiceInfo.getFpzlDm()) |
|
|
|
|
|| OrderInfoEnum.ORDER_INVOICE_TYPE_01.getKey().equals(orderInvoiceInfo.getFpzlDm()) |
|
|
|
|
|| OrderInfoEnum.ORDER_INVOICE_TYPE_02.getKey().equals(orderInvoiceInfo.getFpzlDm()) |
|
|
|
|
|| OrderInfoEnum.ORDER_INVOICE_TYPE_52.getKey().equals(orderInvoiceInfo.getFpzlDm())) |
|
|
|
|
&& StringUtils.isNotEmpty(orderInvoiceInfo.getFphm()); |
|
|
|
|
if(!fpdmhmDp){ |
|
|
|
|
throw new Exception("非电票不推送"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<FileDownLoad> fileDownLoadList = orderInvoiceInfoService.getInvoiceFile( |
|
|
|
|
"6", orderInvoiceInfo.getFpzlDm(), orderInvoiceInfo.getPdfUrl(), orderInvoiceInfo.getKplsh(), orderInvoiceInfo.getFpdm(), |
|
|
|
|
orderInvoiceInfo.getFphm(), orderInvoiceInfo.getXhfNsrsbh(), orderInvoiceInfo.getSksbdm(),""); |
|
|
|
|
//将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(); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
|
openTextResults.forEach(t->sb.append(t.getDocuId()).append(",")); |
|
|
|
|
orderInvoiceInfo1.setDocuId(sb.toString()); |
|
|
|
|
orderInvoiceInfoService.updateOrderInvoiceInfoByFpqqlsh(orderInvoiceInfo, shList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} 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()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String cacheFpqqlsh = String.format(RedisConstant.REDIS_ORDER_LOCK_OPENTEXT_KEY, fpTsMqData.getFpTsMqData().getFpqqlsh()); |
|
|
|
|
if (uuid.equals(redisService.get(cacheFpqqlsh))) { |
|
|
|
|
redisService.del(cacheFpqqlsh); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private R processPushFail(CommonTsMqData commonTsMqData, String pushUrl, String msg, List<String> shList) { |
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(pushUrl)) { |
|
|
|
|