|
|
|
@ -23,6 +23,9 @@ import com.dxhy.order.baseservice.module.thirdservice.redis.service.RedisService |
|
|
|
|
import com.dxhy.order.baseservice.module.thirdservice.simsback.service.SimsBackService; |
|
|
|
|
import com.dxhy.order.baseservice.module.thirdservice.user.service.UserInfoService; |
|
|
|
|
import com.dxhy.order.constant.*; |
|
|
|
|
import com.dxhy.order.consumer.model.page.PageCommonOrderInfo; |
|
|
|
|
import com.dxhy.order.consumer.model.page.PageOrderInfo; |
|
|
|
|
import com.dxhy.order.consumer.model.page.PageOrderItemInfo; |
|
|
|
|
import com.dxhy.order.consumer.modules.manager.service.InvoiceService; |
|
|
|
|
import com.dxhy.order.consumer.modules.order.model.PageInvoiceItem; |
|
|
|
|
import com.dxhy.order.consumer.modules.order.model.PageInvoiceReq; |
|
|
|
@ -48,9 +51,11 @@ import com.dxhy.order.utils.JsonUtils; |
|
|
|
|
import com.dxhy.order.utils.NsrsbhUtils; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
@ -141,6 +146,9 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
@Autowired |
|
|
|
|
private OrderInfoMapper orderInfoMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private OrderSplitService orderSplitService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
@ -148,8 +156,14 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
List<PageInvoiceItem> pageInvoiceItemList = pageInvoiceReq.getPageInvoiceItemList(); |
|
|
|
|
//查询数据列表
|
|
|
|
|
List<CommonOrderInfo> commonOrderInfos = orderInfoService.batchQueryOrderInfoByOrderIdsAndNsrsbh(pageInvoiceItemList); |
|
|
|
|
log.info("commonOrderInfos---->batch query order info"+JSON.toJSONString(commonOrderInfos)); |
|
|
|
|
//存储成品油和非成品油不是混开的结算单
|
|
|
|
|
List<CommonOrderInfo> commonOrderInfoList=new ArrayList<CommonOrderInfo>(); |
|
|
|
|
//存储成品油和非成品油混开的结算单
|
|
|
|
|
List<List<PageCommonOrderInfo>> lists=new ArrayList<>(); |
|
|
|
|
//购方是否为空、税编是否为空校验、成品油校验
|
|
|
|
|
for(CommonOrderInfo commonOrderInfo:commonOrderInfos){ |
|
|
|
|
List<PageCommonOrderInfo> mixCommonOrderInfoList=new ArrayList<>(); |
|
|
|
|
if (StrUtil.isBlank(commonOrderInfo.getOrderInfo().getGhfMc())) { |
|
|
|
|
return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"购方信息为空,请补全!"); |
|
|
|
|
} |
|
|
|
@ -158,37 +172,92 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
// if(StrUtil.isBlank(commonOrderInfo.getOrderInfo().getGhfNsrsbh()) || StrUtil.isBlank(commonOrderInfo.getOrderInfo().getGhfMc()) ){
|
|
|
|
|
// return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"购方信息为空,请补全!");
|
|
|
|
|
// }
|
|
|
|
|
String cpy = ""; |
|
|
|
|
String kcp = baseServiceConfig.getKcp(); |
|
|
|
|
boolean kcpMark; |
|
|
|
|
List<OrderItemInfo> cpyOrderItems = new ArrayList<OrderItemInfo>(); |
|
|
|
|
List<OrderItemInfo> nocpyOrderItems = new ArrayList<OrderItemInfo>(); |
|
|
|
|
for(OrderItemInfo orderItemInfo: commonOrderInfo.getOrderItemInfo()){ |
|
|
|
|
if(StrUtil.isBlank(orderItemInfo.getSpbm())){ |
|
|
|
|
return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"第"+orderItemInfo.getSphxh()+"行商品税编为空,请补全!"); |
|
|
|
|
}else { |
|
|
|
|
kcpMark = kcp.contains(commonOrderInfo.getOrderItemInfo().get(0).getSpbm()); |
|
|
|
|
TaxClassCodeEntity taxClassCodeEntity = taxClassCodeMapper.selectTaxClassCodeBySpbm(orderItemInfo.getSpbm()); |
|
|
|
|
if(StrUtil.isNotBlank(cpy)){ |
|
|
|
|
if(!cpy.equals(taxClassCodeEntity.getCpy())){ |
|
|
|
|
return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"成品油和非成品油税编不能混开,请做手动拆分处理!"); |
|
|
|
|
} |
|
|
|
|
if(ConfigureConstant.STRING_Y.equals(taxClassCodeEntity.getCpy())){ |
|
|
|
|
//成品油明细
|
|
|
|
|
cpyOrderItems.add(orderItemInfo); |
|
|
|
|
}else { |
|
|
|
|
cpy = taxClassCodeEntity.getCpy(); |
|
|
|
|
//非成品油明细
|
|
|
|
|
nocpyOrderItems.add(orderItemInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(kcp.contains(orderItemInfo.getSpbm()) != kcpMark){ |
|
|
|
|
return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"矿产品与非矿产品税编不能混开,请做手动拆分处理!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(ConfigureConstant.STRING_Y.equals(cpy) && commonOrderInfo.getOrderItemInfo().size()>ConfigureConstant.INT_8){ |
|
|
|
|
if(CollectionUtils.isEmpty(cpyOrderItems)||CollectionUtils.isEmpty(nocpyOrderItems)){ |
|
|
|
|
commonOrderInfo.setOrderItemInfo(CollectionUtils.isEmpty(cpyOrderItems)?nocpyOrderItems:nocpyOrderItems); |
|
|
|
|
commonOrderInfoList.add(commonOrderInfo); |
|
|
|
|
}else { |
|
|
|
|
//封装成品油
|
|
|
|
|
PageCommonOrderInfo cpyPageCommonOrderInfo = new PageCommonOrderInfo(); |
|
|
|
|
//成品油和非成品油混合
|
|
|
|
|
PageOrderInfo cpyPageOrderInfo = new PageOrderInfo(); |
|
|
|
|
BeanUtils.copyProperties(commonOrderInfo.getOrderInfo(),cpyPageOrderInfo); |
|
|
|
|
cpyPageOrderInfo.setKphjje(cpyOrderItems.stream().map(m->new BigDecimal(m.getSe()).add(new BigDecimal(m.getXmje()))).reduce(BigDecimal.ZERO, BigDecimal::add).toString()); |
|
|
|
|
List<PageOrderItemInfo> cpyOrderItemInfo = new ArrayList<PageOrderItemInfo>(); |
|
|
|
|
for (OrderItemInfo cpyOrderItem : cpyOrderItems) { |
|
|
|
|
PageOrderItemInfo pageOrderItemInfo = new PageOrderItemInfo(); |
|
|
|
|
BeanUtils.copyProperties(cpyOrderItem,pageOrderItemInfo); |
|
|
|
|
cpyOrderItemInfo.add(pageOrderItemInfo); |
|
|
|
|
} |
|
|
|
|
cpyPageCommonOrderInfo.setOrderInfo(cpyPageOrderInfo); |
|
|
|
|
cpyPageCommonOrderInfo.setOrderItemInfo(cpyOrderItemInfo); |
|
|
|
|
mixCommonOrderInfoList.add(cpyPageCommonOrderInfo); |
|
|
|
|
//封装非成品油
|
|
|
|
|
PageCommonOrderInfo nocpyPageCommonOrderInfo = new PageCommonOrderInfo(); |
|
|
|
|
//成品油和非成品油混合
|
|
|
|
|
PageOrderInfo nocpyPageOrderInfo = new PageOrderInfo(); |
|
|
|
|
BeanUtils.copyProperties(commonOrderInfo.getOrderInfo(),nocpyPageOrderInfo); |
|
|
|
|
nocpyPageOrderInfo.setKphjje(nocpyOrderItems.stream().map(m->new BigDecimal(m.getSe()).add(new BigDecimal(m.getXmje()))).reduce(BigDecimal.ZERO, BigDecimal::add).toString()); |
|
|
|
|
List<PageOrderItemInfo> nocpyOrderItemInfo = new ArrayList<PageOrderItemInfo>(); |
|
|
|
|
for (OrderItemInfo nocpyOrderItem : nocpyOrderItems) { |
|
|
|
|
PageOrderItemInfo pageOrderItemInfo = new PageOrderItemInfo(); |
|
|
|
|
BeanUtils.copyProperties(nocpyOrderItem,pageOrderItemInfo); |
|
|
|
|
nocpyOrderItemInfo.add(pageOrderItemInfo); |
|
|
|
|
} |
|
|
|
|
nocpyPageCommonOrderInfo.setOrderInfo(nocpyPageOrderInfo); |
|
|
|
|
nocpyPageCommonOrderInfo.setOrderItemInfo(nocpyOrderItemInfo); |
|
|
|
|
mixCommonOrderInfoList.add(nocpyPageCommonOrderInfo); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if(cpyOrderItems.size()>ConfigureConstant.INT_8){ |
|
|
|
|
return R.error("结算单:"+commonOrderInfo.getOrderInfo().getDdh()+"是成品油发票,明细行数不能超过8行,请先进行手动拆分!"); |
|
|
|
|
} |
|
|
|
|
if(!CollectionUtils.isEmpty(mixCommonOrderInfoList)){ |
|
|
|
|
lists.add(mixCommonOrderInfoList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//如果是混开的 走明细拆分
|
|
|
|
|
if(!CollectionUtils.isEmpty(lists)){ |
|
|
|
|
try { |
|
|
|
|
for (List<PageCommonOrderInfo> list : lists) { |
|
|
|
|
orderSplitService.saveOrderSplitOrder(list); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//如果不是混开的 走原来的逻辑
|
|
|
|
|
if(CollectionUtils.isEmpty(commonOrderInfoList)){ |
|
|
|
|
return R.ok("生成预制发票成功,请到【发票处理中心】页面查看"); |
|
|
|
|
} |
|
|
|
|
//客户冻结状态校验、确认智能赋码、单价误差校验
|
|
|
|
|
List<Map<String,String>> consumerList = new ArrayList<>(); |
|
|
|
|
List<Map<String,String>> confirmList = new ArrayList<>(); |
|
|
|
|
List<Map<String,String>> djOverflowList = new ArrayList<>(); |
|
|
|
|
for (CommonOrderInfo commonOrderInfo : commonOrderInfos) { |
|
|
|
|
for (CommonOrderInfo commonOrderInfo : commonOrderInfoList) { |
|
|
|
|
OrderInfo orderInfo = commonOrderInfo.getOrderInfo(); |
|
|
|
|
List<OrderItemInfo> orderItemInfoList = commonOrderInfo.getOrderItemInfo(); |
|
|
|
|
BuyerEntity buyerEntity = null; |
|
|
|
@ -218,6 +287,7 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
confirmList.add(map); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 订单超限额拆分
|
|
|
|
|
String terminalCode = simsBackService.getTerminalCode(commonOrderInfo.getOrderInfo().getXhfNsrsbh(), commonOrderInfo.getOrderInfo().getEntId()); |
|
|
|
|
List<CommonOrderInfo> originalCommonOrderInfo = new ArrayList<>(); |
|
|
|
@ -255,19 +325,19 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
log.error("{}校验单价容差范围发生错误:在原结算单中未匹配到唯一明细,找到了{}条", LOGGER_MSG, collect.size()); |
|
|
|
|
R.error("校验单价容差范围发生错误:在原结算单中未匹配到唯一明细"); |
|
|
|
|
throw new RuntimeException("校验单价容差范围发生错误:在原结算单中未匹配到唯一明细"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if(consumerList.size()>0){ |
|
|
|
|
return R.error(ConfigureConstant.STRING_9001, "以下结算单中客户的状态为“冻结”状态,不能进行开票。",consumerList); |
|
|
|
|
throw new RuntimeException(String.format("以下结算单中%s客户的状态为“冻结”状态,不能进行开票。",consumerList)); |
|
|
|
|
}else if((StrUtil.isBlank(pageInvoiceReq.getConfirmZnfm()) || !ConfigureConstant.STRING_0.equals(pageInvoiceReq.getConfirmZnfm())) && confirmList.size()>0){ |
|
|
|
|
return R.error(ConfigureConstant.STRING_9002,"请将以下物料同步至公司库,再进行生成预制",confirmList); |
|
|
|
|
throw new RuntimeException(String.format("请将以下物料同步至公司库,再进行生成预制",confirmList)); |
|
|
|
|
}else if(djOverflowList.size() > 0){ |
|
|
|
|
return R.error(ConfigureConstant.STRING_9003, "以下订单自动拆分时单价超过设定范围,请手动拆分",djOverflowList); |
|
|
|
|
throw new RuntimeException(String.format("以下订单自动拆分时单价超过设定范围,请手动拆分",djOverflowList)); |
|
|
|
|
}else { |
|
|
|
|
for (CommonOrderInfo f : commonOrderInfos) { |
|
|
|
|
for (CommonOrderInfo f : commonOrderInfoList) { |
|
|
|
|
TaxClassCodeEntity taxClassCodeEntity = taxClassCodeMapper.selectTaxClassCodeBySpbm(f.getOrderItemInfo().get(0).getSpbm()); |
|
|
|
|
if(ObjectUtil.isNotNull(taxClassCodeEntity) && ConfigureConstant.STRING_Y.equals(taxClassCodeEntity.getCpy())){ |
|
|
|
|
f.getOrderInfo().setQdBz(OrderInfoEnum.QDBZ_CODE_4.getKey()); |
|
|
|
@ -301,10 +371,7 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
|
OrderProcessInfo processInfo = orderProcessService.selectOrderProcessInfoByProcessId(s.getOrderInfo().getProcessId(),null); |
|
|
|
|
processInfo.setYzfp(ConfigureConstant.STRING_1); |
|
|
|
|
orderProcessService.updateOrderProcessInfoByProcessId(processInfo, null); |
|
|
|
|
//
|
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return R.ok("生成预制发票成功,请到【发票处理中心】页面查看"); |
|
|
|
|