|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package com.dxhy.order.consumer.modules.bespoke.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.io.IoUtil; |
|
|
|
|
import cn.hutool.extra.spring.SpringUtil; |
|
|
|
@ -20,12 +21,15 @@ import com.dxhy.order.baseservice.constant.NsrQueueEnum; |
|
|
|
|
import com.dxhy.order.baseservice.exception.OrderReceiveException; |
|
|
|
|
import com.dxhy.order.baseservice.model.OrderInvoiceInfo; |
|
|
|
|
import com.dxhy.order.baseservice.model.OrderOriginExtendInfo; |
|
|
|
|
import com.dxhy.order.baseservice.model.queue.CommonTsMqData; |
|
|
|
|
import com.dxhy.order.baseservice.model.queue.FpYxTsMqData; |
|
|
|
|
import com.dxhy.order.consumer.dao.OrderOriginExtendInfoMapper; |
|
|
|
|
import com.dxhy.order.consumer.dao.OrderProcessInfoMapper; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.config.FtpConfig; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.config.FtpProperties; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.config.ServiceConfig; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.config.datasource.config.DynamicContextHolder; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.model.req.FileModel; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.model.req.ReqParam; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.service.FtpProcessor; |
|
|
|
|
import com.dxhy.order.consumer.modules.bespoke.service.OrderHandleService; |
|
|
|
@ -41,6 +45,7 @@ import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.commons.lang3.time.DateUtils; |
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -49,6 +54,7 @@ import javax.annotation.Resource; |
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.jar.Pack200; |
|
|
|
@ -257,7 +263,11 @@ public class OrderHandleServiceImpl implements OrderHandleService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String saveInvoiceFile(OrderInvoiceInfo orderInvoiceInfo) { |
|
|
|
|
public FileModel saveInvoiceFile(OrderInvoiceInfo orderInvoiceInfo) { |
|
|
|
|
|
|
|
|
|
//返回实体
|
|
|
|
|
FileModel fileModel = new FileModel(); |
|
|
|
|
//查询文件
|
|
|
|
|
Date kprq = orderInvoiceInfo.getKprq(); |
|
|
|
|
String xhfNsrsbh = orderInvoiceInfo.getXhfNsrsbh(); |
|
|
|
|
String entId = orderInvoiceInfo.getEntId(); |
|
|
|
@ -265,6 +275,10 @@ public class OrderHandleServiceImpl implements OrderHandleService { |
|
|
|
|
TaxEquipmentInfo taxEquipmentInfo = simsBackService.queryTaxEquipment(xhfNsrsbh, entId); |
|
|
|
|
//获取文件
|
|
|
|
|
List<FileDownLoad> invoiceFile = orderInvoiceInfoService.getInvoiceFile("", orderInvoiceInfo, taxEquipmentInfo.getSksbCode(), OrderInfoEnum.FILE_TYPE_PDF.getKey()); |
|
|
|
|
if (CollectionUtils.isEmpty(invoiceFile)) { |
|
|
|
|
fileModel.setCode(ConfigureConstant.STRING_9999); |
|
|
|
|
return fileModel; |
|
|
|
|
} |
|
|
|
|
FileDownLoad fileDownLoad = invoiceFile.get(ConfigureConstant.INT_0); |
|
|
|
|
//拼接路径
|
|
|
|
|
StringBuilder path = new StringBuilder(ftpProperties.getBasePath()); |
|
|
|
@ -286,9 +300,13 @@ public class OrderHandleServiceImpl implements OrderHandleService { |
|
|
|
|
boolean flag = ftpProcessor.uploadFile(path.toString(), fileDownLoad.getFileName(), utf8Stream); |
|
|
|
|
|
|
|
|
|
if (flag){ |
|
|
|
|
return path.append(ConfigureConstant.STRING_SLASH_LINE).append(fileDownLoad.getFileName()).toString(); |
|
|
|
|
fileModel.setCode(ConfigureConstant.STRING_0000); |
|
|
|
|
fileModel.setFilePath(path.toString()); |
|
|
|
|
fileModel.setFileName(fileDownLoad.getFileName()); |
|
|
|
|
return fileModel; |
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
fileModel.setCode(ConfigureConstant.STRING_9999); |
|
|
|
|
return fileModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -326,4 +344,71 @@ public class OrderHandleServiceImpl implements OrderHandleService { |
|
|
|
|
|
|
|
|
|
return count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R backMsg(String message) { |
|
|
|
|
CommonTsMqData commonTsMqData = JsonUtils.getInstance().parseObject(message, CommonTsMqData.class); |
|
|
|
|
List<String> shList = Arrays.asList(commonTsMqData.getNsrsbh()); |
|
|
|
|
|
|
|
|
|
OrderInvoiceInfo orderInvoiceInfo = orderInvoiceInfoService.selectOrderInvoiceInfoByFpqqlsh(commonTsMqData.getFpTsMqData().getFpqqlsh(), shList); |
|
|
|
|
if (ObjectUtils.isEmpty(orderInvoiceInfo)){ |
|
|
|
|
log.error("发票信息不存在无法进行推送"); |
|
|
|
|
updatePushErrorMsgToDb(commonTsMqData.getFpTsMqData().getFpqqlsh(),"发票信息不存在无法进行推送", shList); |
|
|
|
|
return R.error("发票信息不存在"); |
|
|
|
|
} |
|
|
|
|
//保存版式文件到ftp
|
|
|
|
|
FileModel fileModel = saveInvoiceFile(orderInvoiceInfo); |
|
|
|
|
|
|
|
|
|
//获取原始订单信息
|
|
|
|
|
OrderOriginExtendInfo orderOriginExtendInfo = new OrderOriginExtendInfo(); |
|
|
|
|
orderOriginExtendInfo.setOrderId(orderInvoiceInfo.getOrderInfoId()); |
|
|
|
|
List<OrderOriginExtendInfo> orderOriginExtendInfos = orderOriginExtendInfoMapper.queryOriginOrderByOrder(orderOriginExtendInfo, shList); |
|
|
|
|
if (CollectionUtils.isEmpty(orderOriginExtendInfos)){ |
|
|
|
|
updatePushErrorMsgToDb(commonTsMqData.getFpTsMqData().getFpqqlsh(),"原始订单信息不存在无法进行推送", shList); |
|
|
|
|
log.error("原始订单信息不存在无法进行推送"); |
|
|
|
|
} |
|
|
|
|
OrderService orderService = SpringUtil.getBean(ServiceConfig.getService(commonTsMqData.getNsrsbh()), OrderService.class); |
|
|
|
|
R r; |
|
|
|
|
try { |
|
|
|
|
r = orderService.backMsg(orderInvoiceInfo,orderOriginExtendInfos,fileModel); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
log.error("推送失败", e); |
|
|
|
|
r = R.error("推送时发生异常"); |
|
|
|
|
}finally { |
|
|
|
|
DynamicContextHolder.push(com.dxhy.management.common.constant.ConfigureConstant.MAIN); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ConfigureConstant.STRING_0000.equals(r.get(ConfigureConstant.CODE))){ |
|
|
|
|
updateSuccessMsg(commonTsMqData.getFpTsMqData().getFpqqlsh(), shList); |
|
|
|
|
log.info("推送成功"); |
|
|
|
|
} |
|
|
|
|
updatePushErrorMsgToDb(commonTsMqData.getFpTsMqData().getFpqqlsh(),r.get(ConfigureConstant.MSG).toString(), shList); |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updatePushErrorMsgToDb(String fpqqlsh, String errorMessage, List<String> shList) { |
|
|
|
|
if (StringUtils.isNotBlank(fpqqlsh) && CollUtil.isNotEmpty(shList)) { |
|
|
|
|
OrderInvoiceInfo orderQuery = new OrderInvoiceInfo(); |
|
|
|
|
orderQuery.setFpqqlsh(fpqqlsh); |
|
|
|
|
orderQuery.setPushStatus(OrderInfoEnum.PUSH_STATUS_2.getKey()); |
|
|
|
|
orderQuery.setInvoicePushSbyy(errorMessage); |
|
|
|
|
int updateByPrimaryKeySelective = orderInvoiceInfoService.updateOrderInvoiceInfoByFpqqlsh(orderQuery, shList); |
|
|
|
|
if (updateByPrimaryKeySelective <= 0) { |
|
|
|
|
log.error("{}推送状态更新失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateSuccessMsg(String fpqqlsh, List<String> shList) { |
|
|
|
|
if (StringUtils.isNotBlank(fpqqlsh) && CollUtil.isNotEmpty(shList)) { |
|
|
|
|
OrderInvoiceInfo orderQuery = new OrderInvoiceInfo(); |
|
|
|
|
orderQuery.setFpqqlsh(fpqqlsh); |
|
|
|
|
orderQuery.setPushStatus(OrderInfoEnum.PUSH_STATUS_1.getKey()); |
|
|
|
|
int updateByPrimaryKeySelective = orderInvoiceInfoService.updateOrderInvoiceInfoByFpqqlsh(orderQuery, shList); |
|
|
|
|
if (updateByPrimaryKeySelective <= 0) { |
|
|
|
|
log.error("{}推送状态更新失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|