feat: 超限额拆分单价容差校验

release
liufeilong 2 years ago
parent 2f154d2089
commit 5c5ac69dd9
  1. 4
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/InvoiceService.java
  2. 113
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/InvoiceServiceImpl.java

@ -1,5 +1,7 @@
package com.dxhy.order.consumer.modules.manager.service; package com.dxhy.order.consumer.modules.manager.service;
import com.dxhy.base.constant.OrderSplitException;
import com.dxhy.order.exception.OrderReceiveException;
import com.dxhy.order.model.CommonOrderInfo; import com.dxhy.order.model.CommonOrderInfo;
import com.dxhy.order.model.R; import com.dxhy.order.model.R;
import com.dxhy.order.model.sk.kp.CommonInvoiceStatus; import com.dxhy.order.model.sk.kp.CommonInvoiceStatus;
@ -23,7 +25,7 @@ public interface InvoiceService {
* @param pageInvoiceReq * @param pageInvoiceReq
* @return * @return
*/ */
R preInvoice(PageInvoiceReq pageInvoiceReq); R preInvoice(PageInvoiceReq pageInvoiceReq) throws OrderSplitException, OrderReceiveException;
/** /**
* 根据id查询数据开票 * 根据id查询数据开票
* *

@ -10,8 +10,10 @@ import com.dxhy.base.constant.TaxSeparateConfig;
import com.dxhy.base.utils.PriceTaxSeparationUtilNew; import com.dxhy.base.utils.PriceTaxSeparationUtilNew;
import com.dxhy.order.baseservice.config.BaseServiceConfig; import com.dxhy.order.baseservice.config.BaseServiceConfig;
import com.dxhy.order.baseservice.module.base.model.DrawerInfoEntity; import com.dxhy.order.baseservice.module.base.model.DrawerInfoEntity;
import com.dxhy.order.baseservice.module.base.model.RuleSplitEntity;
import com.dxhy.order.baseservice.module.base.service.BaseService; import com.dxhy.order.baseservice.module.base.service.BaseService;
import com.dxhy.order.baseservice.module.base.service.DrawerInfoService; import com.dxhy.order.baseservice.module.base.service.DrawerInfoService;
import com.dxhy.order.baseservice.module.base.service.RuleSplitService;
import com.dxhy.order.baseservice.module.buyer.model.BuyerEntity; import com.dxhy.order.baseservice.module.buyer.model.BuyerEntity;
import com.dxhy.order.baseservice.module.buyer.service.BuyerService; import com.dxhy.order.baseservice.module.buyer.service.BuyerService;
import com.dxhy.order.baseservice.module.thirdservice.redis.service.RedisService; import com.dxhy.order.baseservice.module.thirdservice.redis.service.RedisService;
@ -43,9 +45,12 @@ import com.dxhy.order.utils.NsrsbhUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author 杨士勇 * @author 杨士勇
@ -119,80 +124,118 @@ public class InvoiceServiceImpl implements InvoiceService {
@Resource @Resource
private BuyerService buyerService; private BuyerService buyerService;
@Resource
private RuleSplitService ruleSplitService;
@Override @Override
public R preInvoice(PageInvoiceReq pageInvoiceReq) { @Transactional
public R preInvoice(PageInvoiceReq pageInvoiceReq) throws OrderSplitException, OrderReceiveException {
List<PageInvoiceItem> pageInvoiceItemList = pageInvoiceReq.getPageInvoiceItemList(); List<PageInvoiceItem> pageInvoiceItemList = pageInvoiceReq.getPageInvoiceItemList();
//查询数据列表 //查询数据列表
List<CommonOrderInfo> commonOrderInfos = orderInfoService.batchQueryOrderInfoByOrderIdsAndNsrsbh(pageInvoiceItemList); List<CommonOrderInfo> commonOrderInfos = orderInfoService.batchQueryOrderInfoByOrderIdsAndNsrsbh(pageInvoiceItemList);
List<Map<String,String>> consumerList = new ArrayList<>(); List<Map<String,String>> consumerList = new ArrayList<>();
List<Map<String,String>> confirmList = new ArrayList<>(); List<Map<String,String>> confirmList = new ArrayList<>();
commonOrderInfos.stream().forEach(f -> { List<Map<String,String>> djOverflowList = new ArrayList<>();
OrderInfo orderInfo = f.getOrderInfo(); for (CommonOrderInfo commonOrderInfo : commonOrderInfos) {
List<OrderItemInfo> orderItemInfoList = f.getOrderItemInfo(); OrderInfo orderInfo = commonOrderInfo.getOrderInfo();
List<OrderItemInfo> orderItemInfoList = commonOrderInfo.getOrderItemInfo();
BuyerEntity buyerEntity = null; BuyerEntity buyerEntity = null;
if(StrUtil.isNotBlank(orderInfo.getGhfId())){ if (StrUtil.isNotBlank(orderInfo.getGhfId())) {
buyerEntity = buyerService.queryBuyerInfoByxhfNsrsbhAndBuyerCode(orderInfo.getXhfNsrsbh(), orderInfo.getGhfId()); buyerEntity = buyerService.queryBuyerInfoByxhfNsrsbhAndBuyerCode(orderInfo.getXhfNsrsbh(), orderInfo.getGhfId());
if(ObjectUtil.isNull(buyerEntity)){ if (ObjectUtil.isNull(buyerEntity)) {
buyerEntity = buyerService.queryBuyerInfoByxhfNsrsbhAndBuyerCode(ConfigureConstant.STRING_1_, orderInfo.getGhfId()); buyerEntity = buyerService.queryBuyerInfoByxhfNsrsbhAndBuyerCode(ConfigureConstant.STRING_1_, orderInfo.getGhfId());
} }
} }
if(ObjectUtil.isNotNull(buyerEntity) && ConfigureConstant.STRING_0.equals(buyerEntity.getStatus())){ if (ObjectUtil.isNotNull(buyerEntity) && ConfigureConstant.STRING_0.equals(buyerEntity.getStatus())) {
Map map = new HashMap(); Map map = new HashMap();
map.put("ddh",orderInfo.getDdh()); map.put("ddh", orderInfo.getDdh());
map.put("ghfMc",orderInfo.getGhfMc()); map.put("ghfMc", orderInfo.getGhfMc());
map.put("ghfNsrsbh",orderInfo.getGhfNsrsbh()); map.put("ghfNsrsbh", orderInfo.getGhfNsrsbh());
map.put("hsje",orderInfo.getKphjje()); map.put("hsje", orderInfo.getKphjje());
consumerList.add(map); consumerList.add(map);
} }
orderItemInfoList.stream().forEach(item -> { orderItemInfoList.stream().forEach(item -> {
if(ConfigureConstant.STRING_1.equals(item.getZnfm())){ if (ConfigureConstant.STRING_1.equals(item.getZnfm())) {
Map map = new HashMap(); Map map = new HashMap();
map.put("ddh",orderInfo.getDdh()); map.put("ddh", orderInfo.getDdh());
map.put("xh",item.getSphxh()); map.put("xh", item.getSphxh());
String xmmc = item.getXmmc(); String xmmc = item.getXmmc();
map.put("xmmc",xmmc.substring(xmmc.lastIndexOf("*")+1,xmmc.length())); map.put("xmmc", xmmc.substring(xmmc.lastIndexOf("*") + 1, xmmc.length()));
map.put("ssjc",xmmc.substring(1,xmmc.lastIndexOf("*"))); map.put("ssjc", xmmc.substring(1, xmmc.lastIndexOf("*")));
map.put("ssbm",item.getSpbm()); map.put("ssbm", item.getSpbm());
confirmList.add(map); confirmList.add(map);
} }
}); });
}); // 订单超限额拆分
String terminalCode = simsBackService.getTerminalCode(commonOrderInfo.getOrderInfo().getXhfNsrsbh(), commonOrderInfo.getOrderInfo().getEntId());
List<CommonOrderInfo> originalCommonOrderInfo = new ArrayList<>();
originalCommonOrderInfo.add(commonOrderInfo);
List<CommonOrderInfo> orderSplit = new ArrayList<>();
orderSplit = generateReadyOpenOrderService.orderSplit(originalCommonOrderInfo, terminalCode, pageInvoiceReq.getUserId());
log.info("{},{}生成预制发票拆分结果:{}", LOGGER_MSG, commonOrderInfo.getOrderInfo().getDdh(), JsonUtils.getInstance().toJsonString(orderSplit));
orderSplit.stream().forEach(splitEn -> {
List<OrderItemInfo> orderItemInfo = splitEn.getOrderItemInfo();
orderItemInfo.stream().forEach(splitItem -> {
List<OrderItemInfo> collect = commonOrderInfo.getOrderItemInfo().stream().filter(oi -> oi.getXmmc().equals(splitItem.getXmmc()) &&
((StrUtil.isBlank(oi.getGgxh()) && StrUtil.isBlank(splitItem.getGgxh())) || oi.getGgxh().equals(splitItem.getGgxh())) &&
((StrUtil.isBlank(oi.getXmdw()) && StrUtil.isBlank(splitItem.getXmdw())) || oi.getXmdw().equals(splitItem.getXmdw())) &&
((StrUtil.isBlank(oi.getSl()) && StrUtil.isBlank(splitItem.getSl())) || oi.getSl().equals(splitItem.getSl()))).collect(Collectors.toList());
if (collect.size() == 1) {
List<RuleSplitEntity> ruleSplitEntityList = ruleSplitService.queryRuleSplit(commonOrderInfo.getOrderInfo().getXhfNsrsbh(), pageInvoiceReq.getUserId());
log.info("税号:{},用户ID:{},查询的拆分限额信息结果:{}", commonOrderInfo.getOrderInfo().getXhfNsrsbh(),
pageInvoiceReq.getUserId(), JsonUtils.getInstance().toJsonString(ruleSplitEntityList));
String djce = ruleSplitEntityList.get(0).getDjce();
BigDecimal abs = new BigDecimal(collect.get(0).getXmdj()).subtract(new BigDecimal(splitItem.getXmdj())).abs();
if (abs.compareTo(new BigDecimal(djce)) > 0) {
Map map = new HashMap();
map.put("ddh", commonOrderInfo.getOrderInfo().getDdh());
map.put("ghfMc", commonOrderInfo.getOrderInfo().getGhfMc());
map.put("xhfMc", commonOrderInfo.getOrderInfo().getXhfMc());
map.put("jshj", commonOrderInfo.getOrderInfo().getKphjje());
djOverflowList.add(map);
}
} else {
log.error("{}校验单价容差范围发生错误:在原结算单中未匹配到唯一明细,找到了{}条", LOGGER_MSG, collect.size());
R.error("校验单价容差范围发生错误:在原结算单中未匹配到唯一明细");
}
});
});
}
if(consumerList.size()>0){ if(consumerList.size()>0){
return R.error(ConfigureConstant.STRING_9001, "校验客户提示",consumerList); return R.error(ConfigureConstant.STRING_9001, "校验客户提示",consumerList);
}else if((StrUtil.isBlank(pageInvoiceReq.getConfirmZnfm()) || !ConfigureConstant.STRING_0.equals(pageInvoiceReq.getConfirmZnfm())) && confirmList.size()>0){ }else if((StrUtil.isBlank(pageInvoiceReq.getConfirmZnfm()) || !ConfigureConstant.STRING_0.equals(pageInvoiceReq.getConfirmZnfm())) && confirmList.size()>0){
return R.error(ConfigureConstant.STRING_9002,"请确认以下物料税收分类编码是否准确",confirmList); return R.error(ConfigureConstant.STRING_9002,"请确认以下物料税收分类编码是否准确",confirmList);
}else if(djOverflowList.size() > 0){
return R.error(ConfigureConstant.STRING_9003, "以下订单自动拆分时单价超过设定范围,请手动拆分",djOverflowList);
}else { }else {
commonOrderInfos.stream().forEach(f -> { for (CommonOrderInfo f : commonOrderInfos) {
String terminalCode = simsBackService.getTerminalCode(f.getOrderInfo().getXhfNsrsbh(), f.getOrderInfo().getEntId()); String terminalCode = simsBackService.getTerminalCode(f.getOrderInfo().getXhfNsrsbh(), f.getOrderInfo().getEntId());
List<CommonOrderInfo> originalCommonOrderInfo = new ArrayList<>(); List<CommonOrderInfo> originalCommonOrderInfo = new ArrayList<>();
originalCommonOrderInfo.add(f); originalCommonOrderInfo.add(f);
List<CommonOrderInfo> orderSplit = new ArrayList<>(); List<CommonOrderInfo> orderSplit = new ArrayList<>();
// 订单超限额拆分 // 订单超限额拆分
try { orderSplit = generateReadyOpenOrderService.orderSplit(originalCommonOrderInfo, terminalCode, pageInvoiceReq.getUserId());
orderSplit = generateReadyOpenOrderService.orderSplit(originalCommonOrderInfo, terminalCode, pageInvoiceReq.getUserId()); log.info("{},{}生成预制发票拆分结果:{}", LOGGER_MSG, f.getOrderInfo().getDdh(), JsonUtils.getInstance().toJsonString(orderSplit));
log.info("{},{}生成预制发票拆分结果:{}",LOGGER_MSG,f.getOrderInfo().getDdh(),JsonUtils.getInstance().toJsonString(orderSplit)); if (orderSplit.size() == 1) {
} catch (OrderSplitException e) {
log.error("{}生成预制发票拆分异常:",LOGGER_MSG,e);
}
if(orderSplit.size() == 1){
OrderProcessInfo processInfo = f.getProcessInfo(); OrderProcessInfo processInfo = f.getProcessInfo();
processInfo.setYzfp(ConfigureConstant.STRING_1); processInfo.setYzfp(ConfigureConstant.STRING_1);
orderProcessService.updateOrderProcessInfoByProcessId(processInfo,null); orderProcessService.updateOrderProcessInfoByProcessId(processInfo, null);
}else if(orderSplit.size() > 1){ } else if (orderSplit.size() > 1) {
List<CommonOrderInfo> commonOrderInfoSaveResults = new ArrayList<>(); List<CommonOrderInfo> commonOrderInfoSaveResults = new ArrayList<>();
try {
commonOrderInfoSaveResults = generateReadyOpenOrderService.saveOrderSplitInfo(orderSplit); commonOrderInfoSaveResults = generateReadyOpenOrderService.saveOrderSplitInfo(orderSplit);
} catch (OrderReceiveException e) {
log.error("{}生成预制发票拆分后保存异常:",LOGGER_MSG,e);
}
commonOrderInfoSaveResults.stream().forEach(s -> { commonOrderInfoSaveResults.stream().forEach(s -> {
OrderProcessInfo processInfo = s.getProcessInfo(); OrderProcessInfo processInfo = s.getProcessInfo();
processInfo.setYzfp(ConfigureConstant.STRING_1); processInfo.setYzfp(ConfigureConstant.STRING_1);
orderProcessService.updateOrderProcessInfoByProcessId(processInfo,null); orderProcessService.updateOrderProcessInfoByProcessId(processInfo, null);
}); });
} else {
continue;
} }
}); }
return R.ok("生成预制发票成功,请到发票处理页面查看"); return R.ok("生成预制发票成功,请到发票处理页面查看");
} }
} }

Loading…
Cancel
Save