Browse Source

统计分析 修改bug

ioioio 3 years ago
parent
commit
0e86573e23

+ 3 - 0
blade-service-api/trade-finance-api/src/main/java/org/springblade/finance/vojo/Acc.java

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 import lombok.Data;
 import io.swagger.annotations.ApiModel;
@@ -296,5 +297,7 @@ public class Acc implements Serializable {
 	private String tradeType;
 
 	private String itemType;
+	@TableField(exist = false)
+	private List<Long> SrcFeesIds;
 
 }

+ 154 - 117
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/controller/OrderController.java

@@ -40,6 +40,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.finance.vojo.Acc;
 import org.springblade.finance.feign.IFinanceClient;
+import org.springblade.purchase.sales.entity.OrderFees;
 import org.springblade.purchase.sales.entity.OrderItems;
 import org.springblade.purchase.sales.service.*;
 import org.springblade.purchase.sales.vo.OrderItemsVO;
@@ -54,6 +55,7 @@ import org.springblade.core.boot.ctrl.BladeController;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 国内销售或采购订单表 控制器
@@ -374,133 +376,198 @@ public class OrderController extends BladeController {
 				Order service = orderService.getOne(orderLambdaQueryWrapper);
 
 
-				//调用-费用微服务-获取费用设置详情
+				//调用-费用微服务-获取关税设置详情
 				R<FeesDesc> customDuty = feesDescClient.getFeesByName("关税");
 				Long customDutyId=null;
                 if(customDuty.isSuccess()&&customDuty.getData()!=null)
                 {
 					customDutyId=customDuty.getData().getId();
 				}
+				//关税
+				BigDecimal customDutyMoney=BigDecimal.ZERO;
+                //查询采购订单关税的费用明细
+                if(customDutyId!=null)
+                {
+					LambdaQueryWrapper<OrderFees> orderFeesLambdaQueryWrapper=new LambdaQueryWrapper<>();
+					orderFeesLambdaQueryWrapper
+						.eq(OrderFees::getPid,orderId)
+						.eq(OrderFees::getItemId,customDutyId);
+					List<Long> customDutyIds = orderFeesService.list(orderFeesLambdaQueryWrapper).stream().map(OrderFees::getId).collect(Collectors.toList());
 
+					if(CollectionUtils.isNotEmpty(customDutyIds))
+					{
+						Acc customDutyAcc=new Acc();
+						customDutyAcc.setSrcType(2);
+						customDutyAcc.setSrcFeesIds(customDutyIds);
+						//只有 itemType=采购 && billType=申请 才是付钱
+						customDutyAcc.setItemType("采购");
+						customDutyAcc.setBillType("申请");
+						R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
+						if(accListByCondition.isSuccess())
+						{
+							List<Acc> customDutyList = accListByCondition.getData();
+							//关税
+
+							if(CollectionUtils.isNotEmpty(customDutyList))
+							{
+								customDutyMoney=customDutyList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
+							}
+							else
+							{
+								customDutyMoney=BigDecimal.ZERO;
+							}
 
+						}
+					}
+                }
+				e.setCustomDutyMoney(customDutyMoney);
+
+
+
+                //调用-费用微服务-获取配额设置详情
 				Long quotaId=null;
 				R<FeesDesc> quota = feesDescClient.getFeesByName("配额");
 				if(quota.isSuccess()&&quota.getData()!=null)
 				{
 					quotaId=quota.getData().getId();
 				}
+                //配额
+				BigDecimal quotaMoney=BigDecimal.ZERO;
+				//查询采购订单配额的费用明细
+				if(quotaId!=null)
+				{
+					LambdaQueryWrapper<OrderFees> quotaLambdaQueryWrapper=new LambdaQueryWrapper<>();
+					quotaLambdaQueryWrapper
+						.eq(OrderFees::getPid,orderId)
+						.eq(OrderFees::getItemId,quotaId);
+					List<Long> quotaIdIds = orderFeesService.list(quotaLambdaQueryWrapper).stream().map(OrderFees::getId).collect(Collectors.toList());
+
+					if(CollectionUtils.isNotEmpty(quotaIdIds))
+					{
+						Acc customDutyAcc=new Acc();
+						customDutyAcc.setSrcType(2);
+						customDutyAcc.setSrcFeesIds(quotaIdIds);
+						//只有 itemType=采购 && billType=申请 才是付钱
+						customDutyAcc.setItemType("采购");
+						customDutyAcc.setBillType("申请");
+						R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
+						if(accListByCondition.isSuccess())
+						{
+							List<Acc> quotaList = accListByCondition.getData();
+							//关税
+
+							if(CollectionUtils.isNotEmpty(quotaList))
+							{
+								quotaMoney=quotaList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
+							}
+							else
+							{
+								quotaMoney=BigDecimal.ZERO;
+							}
+
+						}
+					}
+
+				}
+				e.setQuotaMoney(quotaMoney);
 
 
+
+                //调用-费用微服务-获取增值税设置详情
 				Long gstId=null;
 				R<FeesDesc> GST = feesDescClient.getFeesByName("增值税");
 				if(GST.isSuccess()&&GST.getData()!=null)
 				{
 					gstId=GST.getData().getId();
 				}
+				//增值税
+				BigDecimal gstMoney=BigDecimal.ZERO;
+				if(gstId!=null)
+				{
+					LambdaQueryWrapper<OrderFees> quotaLambdaQueryWrapper=new LambdaQueryWrapper<>();
+					quotaLambdaQueryWrapper
+						.eq(OrderFees::getPid,orderId)
+						.eq(OrderFees::getItemId,gstId);
+					List<Long> gstIds = orderFeesService.list(quotaLambdaQueryWrapper).stream().map(OrderFees::getId).collect(Collectors.toList());
 
+					if(CollectionUtils.isNotEmpty(gstIds))
+					{
+						Acc customDutyAcc=new Acc();
+						customDutyAcc.setSrcType(2);
+						customDutyAcc.setSrcFeesIds(gstIds);
+						//只有 itemType=采购 && billType=申请 才是付钱
+						customDutyAcc.setItemType("采购");
+						customDutyAcc.setBillType("申请");
+						R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
+						if(accListByCondition.isSuccess())
+						{
+							List<Acc> gstList = accListByCondition.getData();
+							//关税
+
+							if(CollectionUtils.isNotEmpty(gstList))
+							{
+								gstMoney=gstList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
+							}
+							else
+							{
+								gstMoney=BigDecimal.ZERO;
+							}
 
+						}
+					}
+
+				}
+				e.setGstMoney(gstMoney);
+
+
+
+				//调用-费用微服务-获取物流费设置详情
 				Long deliverId=null;
 				R<FeesDesc> deliver = feesDescClient.getFeesByName("物流费");
 				if(deliver.isSuccess()&&deliver.getData()!=null)
 				{
 					deliverId=deliver.getData().getId();
 				}
-
-
-				//获取关税账单明细
-				//关税
-				BigDecimal customDutyMoney=BigDecimal.ZERO;
-				if(customDutyId!=null)
+				BigDecimal deliverMoney=BigDecimal.ZERO;
+				if(deliverId!=null)
 				{
-					Acc customDutyAcc=new Acc();
-					customDutyAcc.setSrcType(2);
-					customDutyAcc.setSrcFeesId(customDutyId);
-					customDutyAcc.setSrcParentId(orderId);
-					//只有 itemType=采购 && billType=申请 才是付钱
-					customDutyAcc.setItemType("采购");
-					customDutyAcc.setBillType("申请");
-					R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
-
-					if(accListByCondition.isSuccess())
-					{
-						List<Acc> customDutyList = accListByCondition.getData();
-						//关税
+					LambdaQueryWrapper<OrderFees> quotaLambdaQueryWrapper=new LambdaQueryWrapper<>();
+					quotaLambdaQueryWrapper
+						.eq(OrderFees::getPid,orderId)
+						.eq(OrderFees::getItemId,deliverId);
+					List<Long> deliverIds = orderFeesService.list(quotaLambdaQueryWrapper).stream().map(OrderFees::getId).collect(Collectors.toList());
 
-						if(CollectionUtils.isNotEmpty(customDutyList))
-						{
-							customDutyMoney=customDutyList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
-						}
-						else
-						{
-							customDutyMoney=BigDecimal.ZERO;
-						}
-
-					}
-				}
-                e.setCustomDutyMoney(customDutyMoney);
-
-				//获取配额账单明细
-				//配额
-				BigDecimal quotaMoney=BigDecimal.ZERO;
-				if(quotaId!=null)
-				{
-					Acc quotaAcc=new Acc();
-					quotaAcc.setSrcType(2);
-					quotaAcc.setSrcFeesId(quotaId);
-					quotaAcc.setSrcParentId(orderId);
-					//只有 itemType=采购 && billType=申请 才是付钱
-					quotaAcc.setItemType("采购");
-					quotaAcc.setBillType("申请");
-					R<List<Acc>> accListByCondition2 = iFinanceClient.getAccListByCondition(quotaAcc);
-
-					if(accListByCondition2.isSuccess())
+					if(CollectionUtils.isNotEmpty(deliverIds))
 					{
-						List<Acc> quotaList = accListByCondition2.getData();
-						//配额
-						if(CollectionUtils.isNotEmpty(quotaList))
+						Acc customDutyAcc=new Acc();
+						customDutyAcc.setSrcType(2);
+						customDutyAcc.setSrcFeesIds(deliverIds);
+						//只有 itemType=采购 && billType=申请 才是付钱
+						customDutyAcc.setItemType("采购");
+						customDutyAcc.setBillType("申请");
+						R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
+						if(accListByCondition.isSuccess())
 						{
-							quotaMoney=quotaList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
-						}
-						else
-						{
-							quotaMoney=BigDecimal.ZERO;
-						}
+							List<Acc> deliverList = accListByCondition.getData();
+							//物流费
+
+							if(CollectionUtils.isNotEmpty(deliverList))
+							{
+								deliverMoney=deliverList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
+							}
+							else
+							{
+								deliverMoney=BigDecimal.ZERO;
+							}
 
+						}
 					}
+
 				}
+				e.setDeliverMoney(deliverMoney);
 
-                e.setQuotaMoney(quotaMoney);
-				//获取增值税账单明细
-				//增值税
-				BigDecimal gstMoney=BigDecimal.ZERO;
-				if(gstId!=null)
-				{
-					Acc gstAcc=new Acc();
-					gstAcc.setSrcType(2);
-					gstAcc.setSrcFeesId(gstId);
-					gstAcc.setSrcParentId(orderId);
-					//只有 itemType=采购 && billType=申请 才是付钱
-					gstAcc.setItemType("采购");
-					gstAcc.setBillType("申请");
-					R<List<Acc>> accListByCondition3 = iFinanceClient.getAccListByCondition(gstAcc);
-
-					if(accListByCondition3.isSuccess())
-					{
-						List<Acc> gstList = accListByCondition3.getData();
 
-						//增值税
-						if(CollectionUtils.isNotEmpty(gstList))
-						{
-							gstMoney=gstList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
-						}
-						else
-						{
-							gstMoney=BigDecimal.ZERO;
-						}
 
-					}
-				}
-                e.setGstMoney(gstMoney);
 				//获取货款账单明细
 				Acc itemAcc=new Acc();
 				itemAcc.setSrcType(1);
@@ -546,37 +613,7 @@ public class OrderController extends BladeController {
 				//成本金额=提货数量*成本价格
 				BigDecimal costAmount=e.getSaleBillWeight().multiply(unitPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
 				e.setCostAmount(costAmount);
-				//物流费用
-				BigDecimal deliverMoney=BigDecimal.ZERO;
-				if(deliverId!=null)
-				{
-					Acc deliverAcc=new Acc();
-					deliverAcc.setSrcType(2);
-					deliverAcc.setSrcFeesId(deliverId);
-					deliverAcc.setSrcParentId(e.getOrderSaleId());
-					//只有 itemType=采购 && billType=申请 才是付钱
-					deliverAcc.setItemType("采购");
-					deliverAcc.setBillType("申请");
-					R<List<Acc>> accListByCondition5 = iFinanceClient.getAccListByCondition(deliverAcc);
-
-					if(accListByCondition5.isSuccess())
-					{
-						List<Acc> deliverMoneyList = accListByCondition5.getData();
-						//关税
-
-						if(CollectionUtils.isNotEmpty(deliverMoneyList))
-						{
-							deliverMoney=deliverMoneyList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
-						}
-						else
-						{
-							deliverMoney=BigDecimal.ZERO;
-						}
 
-					}
-				}
-
-				e.setDeliverMoney(deliverMoney);
                 //利润=开票金额-成本金额-物流费用
 				BigDecimal profit=(InvoiceAmount.subtract(costAmount)).subtract(deliverMoney).setScale(2,BigDecimal.ROUND_HALF_UP);
                 e.setProfit(profit);

+ 1 - 0
blade-service/trade-finance/src/main/java/org/springblade/finance/controller/AccController.java

@@ -181,6 +181,7 @@ public class AccController extends BladeController {
 	{
         LambdaQueryWrapper<Acc> accLambdaQueryWrapper=new LambdaQueryWrapper<>();
 		accLambdaQueryWrapper
+			.in(CollectionUtils.isNotEmpty(acc.getSrcFeesIds()),Acc::getSrcFeesId,acc.getSrcFeesIds())
 			.eq(Acc::getTenantId, AuthUtil.getTenantId())
 			.eq(Acc::getSrcType,acc.getSrcType())
 			.eq(StringUtils.isNotBlank(acc.getBillType()),Acc::getBillType,acc.getBillType())