|
|
@@ -477,6 +477,34 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
return invoiceIds;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 开票前计算应收金额等信息
|
|
|
+ *
|
|
|
+ * @param invoicingVo 获取订单编号等信息
|
|
|
+ * @author lipf
|
|
|
+ * @date 2026/5/26 10:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public InsPlyIncomeInvoiceVO calBeforeInvoice(InvoicingVo invoicingVo) {
|
|
|
+ log.info("开票前校验并计算应收金额等金额。 invoicingVO=[{}]", JSONUtil.toJsonStr(invoicingVo));
|
|
|
+ InsPlyIncomeInvoiceVO invoice = new InsPlyIncomeInvoiceVO();
|
|
|
+ boolean b = this.invoicingCheck(invoicingVo);
|
|
|
+ if(!b){
|
|
|
+ List<String> invoiceIds = this.queryIncomeBindInvoice(invoicingVo);
|
|
|
+ invoice.setCanInvoice(false);
|
|
|
+ invoice.setErrMsg("订单已开票。发票序号是"+ invoiceIds.toString());
|
|
|
+ return invoice;
|
|
|
+ }
|
|
|
+ invoice.setCanInvoice(true);
|
|
|
+ BigDecimal receivableAmount = this.getReceivableAmount(invoicingVo);
|
|
|
+ log.info("根据订单号[{}]计算得到的应收金额是[{}]",JSONUtil.toJsonStr(invoicingVo),receivableAmount);
|
|
|
+ invoice.setReceivableSupervisePremium(receivableAmount);
|
|
|
+ invoice.setCompanyId(invoicingVo.getCompanyId());
|
|
|
+ invoice.setInvoiceTime(LocalDateTime.now());
|
|
|
+ invoice.setInvoiceType(invoicingVo.getInvoiceType());
|
|
|
+ return invoice;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 开票重复校验
|
|
|
* 功能:DB+Redis双重校验,防止并发重复开票
|
|
|
@@ -574,6 +602,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
|
|
|
@Override
|
|
|
public BigDecimal getReceivableAmount(InvoicingVo invoicingVo) {
|
|
|
+ log.info("获取订单的应收金额:invoicingVo=[{}]", JSONUtil.toJsonStr(invoicingVo));
|
|
|
String invoiceType = invoicingVo.getInvoiceType();
|
|
|
List<String> orderNos = invoicingVo.getOrderNos();
|
|
|
orderNos = orderNos.stream()
|
|
|
@@ -616,17 +645,17 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
/**
|
|
|
* 添加发票
|
|
|
*
|
|
|
- * @param invoicingVo
|
|
|
- * @return
|
|
|
+ * @param invoicingVo 开票相关的信息
|
|
|
+ * @return InvoiceingResult 开票的结果
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public InvoiceingResult addInvoicing(InvoicingVo invoicingVo) {
|
|
|
+ public InvoiceingResult addInvoicing(InsPlyIncomeInvoiceVO invoicingVo) {
|
|
|
+ log.info("开票:invoicingVo=[{}]", JSONUtil.toJsonStr(invoicingVo));
|
|
|
try {
|
|
|
- invoicingVo.setReceivablePremium(this.getReceivableAmount(invoicingVo));
|
|
|
-
|
|
|
InvoiceingResult result = new InvoiceingResult();
|
|
|
InsPlyIncomeInvoice invoice = new InsPlyIncomeInvoice();
|
|
|
+ BeanUtils.copyProperties(invoicingVo, invoice);
|
|
|
invoice.setId(IdGenerate.nextId());
|
|
|
invoice.setCompanyId(invoicingVo.getCompanyId());
|
|
|
invoice.setInvoiceType(invoicingVo.getInvoiceType());
|
|
|
@@ -640,12 +669,10 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
}
|
|
|
invoice.setInvoiceParty(invoicingVo.getInvoiceParty());
|
|
|
invoice.setOverinflatedAmount(invoicingVo.getOverinflatedAmount());
|
|
|
- invoice.setReceivableSupervisePremium(invoicingVo.getReceivablePremium());
|
|
|
+ invoice.setReceivableSupervisePremium(invoicingVo.getReceivableSupervisePremium());
|
|
|
invoice.setTaxPoint(invoicingVo.getTaxPoint());
|
|
|
insPlyIncomeInvoiceMapper.insert(invoice);
|
|
|
-
|
|
|
- List<InsPlyIncomeInvoiceLink> invoicingLinkList = new ArrayList();
|
|
|
-
|
|
|
+ List<InsPlyIncomeInvoiceLink> invoicingLinkList = new ArrayList<InsPlyIncomeInvoiceLink>();
|
|
|
invoicingVo.getIncomeIds().forEach(incomeId -> {
|
|
|
InsPlyIncomeInvoiceLink link = new InsPlyIncomeInvoiceLink();
|
|
|
link.setId(IdGenerate.nextId());
|
|
|
@@ -656,7 +683,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
});
|
|
|
insPlyIncomeInvoiceLinkMapper.insert(invoicingLinkList);
|
|
|
result.setInvoiceId(invoice.getId());
|
|
|
- result.setSumPrice(null != invoicingVo.getReceivablePremium() ? invoicingVo.getReceivablePremium().toString() : null);
|
|
|
+ result.setSumPrice(null != invoicingVo.getReceivableSupervisePremium() ? invoicingVo.getReceivableSupervisePremium().toString() : null);
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
log.info("开票异常.invoicingVo=[{}]",JSONUtil.toJsonStr(invoicingVo), e);
|
|
|
@@ -722,6 +749,31 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
return result > 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 开票并结算
|
|
|
+ *
|
|
|
+ * @param settlementVo 开票信息和结算信息
|
|
|
+ * @author lipf
|
|
|
+ * @date 2026/5/26 11:44
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpResult<String> invoiceAndSettlement(InvoiceAndSettlementVo settlementVo) {
|
|
|
+ log.info("开票并结算: settlementVo=[{}]", JSONUtil.toJsonStr(settlementVo));
|
|
|
+ InvoiceingResult result = this.addInvoicing(settlementVo.getInvoiceVO());
|
|
|
+ if (Objects.nonNull(result)){
|
|
|
+ SettlementVo settlementVo1 = new SettlementVo();
|
|
|
+ BeanUtils.copyProperties(settlementVo, settlementVo1);
|
|
|
+ settlementVo1.setInvoicingId(result.getInvoiceId());
|
|
|
+ boolean settlement = this.settlement(settlementVo1);
|
|
|
+ if(settlement){
|
|
|
+ return HttpResult.ok("开票并结算成功");
|
|
|
+ }else{
|
|
|
+ return HttpResult.error("开票成功但结算失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.error("开票失败");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean platformSettlement(PlatformSettlementVo platformSettlementVo) {
|
|
|
@@ -843,6 +895,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
insPlyIncomeInvoiceSettlementMapper.insert(settlement);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(settlementVo.getAttachmentIds())) {
|
|
|
+ log.info("结算的凭证是:settlementVo.getAttachmentIds()=[{}]", JSONUtil.toJsonStr(settlementVo.getAttachmentIds()));
|
|
|
// 添加发票附件
|
|
|
List<InsPlyIncomeInvoiceSettlementFile> files = new ArrayList<>();
|
|
|
for (String fileId : settlementVo.getAttachmentIds()) {
|
|
|
@@ -898,7 +951,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
List<SuperviseExcelVo> dataList = listener.getDataList();
|
|
|
return dataList;
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("导入excel异常。",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|