Commit d942f839 authored by zuoyh's avatar zuoyh

Merge remote-tracking branch 'origin/order_received_statistics' into order_received_statistics

parents b111e4b2 6ed0c570
......@@ -2,7 +2,6 @@ package com.xxfc.platform.order.biz;
import cn.hutool.core.util.ObjectUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum;
import com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics;
import com.xxfc.platform.order.mapper.OrderRentVehicleReceivedStatisticsMapper;
......@@ -12,7 +11,6 @@ import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.dto.OrderReceivedStatisticsFindDTO;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -62,25 +60,29 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
//数据处理 状态组合 按支付状态分组 而后按组合状态
Map<Boolean, Map<String, List<OrderDTO>>> stateGroupMap = orderDTOS.stream().peek(x -> {
x.setStateGroup(String.format("%d-%d-%d-%d", x.getCompanyId(), x.getOrderOrigin(), x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(), x.getStatus()));
x.setStateGroup(String.format("%d-%d-%d-%d", x.getCompanyId(), x.getOrderOrigin(), x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),x.getHasPay()));
stisticsActiveState.add(x.getStateGroup());
})
.collect(Collectors.partitioningBy(x -> Objects.isNull(x.getPayWay()), Collectors.groupingBy(OrderDTO::getStateGroup, Collectors.toList())));
.collect(Collectors.partitioningBy(x -> Objects.nonNull(x.getPayWay()), Collectors.groupingBy(OrderDTO::getStateGroup, Collectors.toList())));
//订单账目信息
List<OrderAccountBo> orderAccountBoList = orderAccountBiz.selectByDate(startDate, endDate);
//账目数据处理 状态组合
Map<String, List<OrderAccountBo>> ordersMap = orderAccountBoList.stream().peek(x -> {
x.setStateGroup(String.format("%d-%d-%d-%d", x.getCompanyId(), x.getOrderOrigin(), x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(), x.getStatus()));
x.setStateGroup(String.format("%d-%d-%d-%d", x.getCompanyId(), x.getOrderOrigin(), x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),x.getHasPay()));
}).collect(Collectors.groupingBy(OrderAccountBo::getStateGroup, Collectors.toList()));
BigDecimal globalTotalAmount = BigDecimal.ZERO;
//已经支付单
Set<Map.Entry<String, List<OrderAccountBo>>> ordersSet = ordersMap.entrySet();
for (Map.Entry<String, List<OrderAccountBo>> orderEntry : ordersSet) {
String orderKey = orderEntry.getKey();
List<OrderAccountBo> orderAccountBos = orderEntry.getValue();
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey, new OrderRentVehicleReceivedStatistics());
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal refundAmount = BigDecimal.ZERO;
for (OrderAccountBo orderAccountBo : orderAccountBos) {
OrderAccountDetail accountDetailEntity = orderAccountBo.getAccountDetailEntity();
if (orderAccountBo.getAccountType() == PAY_ORDER) {
......@@ -89,10 +91,15 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
refundAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
}
}
orderRentVehicleReceivedStatistics.setTotalAmount(totalAmount.subtract(refundAmount));
Long totalQuantity = stateGroupMap == null ? 0L : stateGroupMap.get(Boolean.TRUE) == null ? 0L : stateGroupMap.get(Boolean.TRUE).get(orderKey)==null?0:stateGroupMap.get(Boolean.TRUE).get(orderKey).size();
orderRentVehicleReceivedStatistics.setTotalQuantity(totalQuantity.intValue());
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatistics);
boolean flag = stateGroupMap == null ? false : stateGroupMap.get(Boolean.TRUE) == null ? false : stateGroupMap.get(Boolean.TRUE).get(orderKey)==null?false:true;
if (flag){
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey, new OrderRentVehicleReceivedStatistics());
orderRentVehicleReceivedStatistics.setTotalAmount(totalAmount.subtract(refundAmount));
orderRentVehicleReceivedStatistics.setTotalQuantity(stateGroupMap.get(Boolean.TRUE).get(orderKey).size());
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatistics);
}
globalTotalAmount.add(totalAmount.subtract(refundAmount));
}
//未支付单
......@@ -102,7 +109,7 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
//查询分公司ids
List<Integer> companyIds = vehicleFeign.findCompanyIdsByAreaId(null);
//创建剩余状态组合的租车统计对象
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, stisticsActiveState, companyIds);
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate,globalTotalAmount,stisticsActiveState, companyIds);
orderRentVehicleReceivedStatisticsList.addAll(otherStatisticsStateGroupList);
//保存
insertMemberReceivedStatisticsBatch(orderRentVehicleReceivedStatisticsList);
......@@ -136,11 +143,13 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
* 创建剩余状态数据
*
* @param startDate 时间
* @param totalAmount 订单状态
* @param statisticsStateGroups 状态组合 集合
* @param companyIds 公司ids
* @return
*/
private List<OrderRentVehicleReceivedStatistics> createOtherStatisticsStateGroupList(Date startDate,
BigDecimal totalAmount,
List<String> statisticsStateGroups,
List<Integer> companyIds) {
......@@ -152,7 +161,7 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
//统计对象的生成
otherStatisticsStateGroup.parallelStream().map(stateGroup -> {
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGroup, ObjectUtil.cloneByStream(orderRentVehicleReceivedStatistics));
orderRentVehicleReceivedStatisticsClone.setTotalAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setTotalAmount(totalAmount);
orderRentVehicleReceivedStatisticsClone.setTotalQuantity(0);
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatisticsClone);
return orderRentVehicleReceivedStatisticsClone;
......
......@@ -61,6 +61,7 @@
bo.`status`,
bo.order_origin,
bo.pay_way,
bo.has_pay,
brvd.start_company_id AS `companyId`
FROM
`order_account` AS `oa`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment