|
|
@ -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,17 +124,22 @@ 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()); |
|
|
@ -157,42 +167,75 @@ public class InvoiceServiceImpl implements InvoiceService { |
|
|
|
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)); |
|
|
|
} catch (OrderSplitException e) { |
|
|
|
|
|
|
|
log.error("{}生成预制发票拆分异常:",LOGGER_MSG,e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (orderSplit.size() == 1) { |
|
|
|
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("生成预制发票成功,请到发票处理页面查看"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|