Commit f54347ec authored by libin's avatar libin

会员与租车订单统计

parent ce24187c
package com.xxfc.platform.order.pojo.account;
import com.alibaba.fastjson.JSON;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import lombok.Data;
import org.springframework.util.StringUtils;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/14 19:16
*/
@Data
public class OrderAccountBo extends OrderDTO {
private Integer accountType;
private String accountDetail;
private OrderAccountDetail accountDetailEntity;
public OrderAccountDetail getAccountDetailEntity() {
return StringUtils.hasText(accountDetail)? JSON.parseObject(accountDetail,OrderAccountDetail.class):new OrderAccountDetail();
}
}
......@@ -113,11 +113,7 @@ public class OrderAccountDTO implements Serializable {
@Column(name = "oneDay")
private String oneDay;
private OrderAccountDetail accountDetailEntity;
public OrderAccountDetail getAccountDetailEntity() {
return StringUtils.hasText(accountDetail)? JSON.parseObject(accountDetail,OrderAccountDetail.class):new OrderAccountDetail();
}
@Override
public String toString() {
......
......@@ -34,8 +34,4 @@ public class OrderDTO {
*/
private Integer memberLevel;
/**
* 租车相关
*/
}
......@@ -18,6 +18,7 @@ import com.xxfc.platform.order.entity.*;
import com.xxfc.platform.order.mapper.OrderAccountMapper;
import com.xxfc.platform.order.pojo.DedDetailDTO;
import com.xxfc.platform.order.pojo.Term;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDTO;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
......@@ -30,6 +31,7 @@ import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.universal.vo.OrderRefundVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.jexl2.MapContext;
import org.mockito.internal.util.collections.Sets;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -37,9 +39,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
......@@ -621,8 +621,14 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
orderMsgBiz.handelMsgDeposit(orvd, baseOrder, userFeign.userDetailById(baseOrder.getUserId()).getData());
}
public List<OrderAccountDTO> selectByOrders(List<Integer> orderIds) {
return null;
/**
*根据开始与结束时间查询账目
* @param startDate
* @param endDate
* @return
*/
public List<OrderAccountBo> selectByDate(Date startDate, Date endDate) {
List<OrderAccountBo> accountBos = mapper.selectOrderAccountByStartTimeAndEndTime(startDate.getTime(),endDate.getTime());
return CollectionUtils.isEmpty(accountBos)? Collections.EMPTY_LIST:accountBos;
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package com.xxfc.platform.order.biz;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.enumconstant.LevelEnum;
import com.google.common.collect.Lists;
......@@ -45,7 +44,6 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
Date endDate = date == null ? DateUtil.endOfDay(yesterday).toJdkDate() : DateUtil.beginOfDay(date);
List<OrderDTO> orders = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(3), startDate, endDate);
TimeInterval timer = DateUtil.timer();
//数据处理 把 完成状态6 取消状态2 的其他数据转换成状态为未完成3
Map<String, Map<Integer, List<OrderDTO>>> ordersMap = orders.stream().peek(x -> {
Integer status = x.getStatus() == StatisticsStatusEnum.CANCEL ? StatisticsStatusEnum.CANCEL : x.getStatus() == StatisticsStatusEnum.FINISH ? StatisticsStatusEnum.FINISH : StatisticsStatusEnum.UNFINISH;
......@@ -54,45 +52,45 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
})
.collect(Collectors.groupingBy(OrderDTO::getStateGroup, Collectors.groupingBy(OrderDTO::getMemberLevel, Collectors.toList())));
Set<Map.Entry<String, Map<Integer, List<OrderDTO>>>> orderSet = ordersMap.entrySet();
for (Map.Entry<String, Map<Integer, List<OrderDTO>>> orderEntry : orderSet) {
//获取状态
String orderStatisticsGroup = orderEntry.getKey();
Map<Integer, List<OrderDTO>> orderEntryValue = orderEntry.getValue();
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderStatisticsGroup, new OrderMemberReceivedStatistics());
//1.普通会员
List<OrderDTO> generalOrders = orderEntryValue.get(LevelEnum.GENERAL.getLevel());
generalOrders = CollectionUtils.isEmpty(generalOrders) ? Collections.EMPTY_LIST : generalOrders;
BigDecimal totalCommAmount = generalOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setToalCommonAmmount(totalCommAmount);
orderMemberReceivedStatistics.setTotalCommonQuantity(generalOrders.size());
if (!ordersMap.isEmpty()) {
Set<Map.Entry<String, Map<Integer, List<OrderDTO>>>> orderSet = ordersMap.entrySet();
for (Map.Entry<String, Map<Integer, List<OrderDTO>>> orderEntry : orderSet) {
//获取状态
String orderStatisticsGroup = orderEntry.getKey();
Map<Integer, List<OrderDTO>> orderEntryValue = orderEntry.getValue();
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderStatisticsGroup, new OrderMemberReceivedStatistics());
//1.普通会员
List<OrderDTO> generalOrders = orderEntryValue.get(LevelEnum.GENERAL.getLevel());
generalOrders = CollectionUtils.isEmpty(generalOrders) ? Collections.EMPTY_LIST : generalOrders;
BigDecimal totalCommAmount = generalOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setToalCommonAmmount(totalCommAmount);
orderMemberReceivedStatistics.setTotalCommonQuantity(generalOrders.size());
//2.黄金会员
List<OrderDTO> goldOrders = orderEntryValue.get(LevelEnum.GOLD.getLevel());
goldOrders = CollectionUtils.isEmpty(goldOrders) ? Collections.EMPTY_LIST : goldOrders;
BigDecimal totalGoldAmount = goldOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setTotalGoldAmount(totalGoldAmount);
orderMemberReceivedStatistics.setTotalGoldQuantity(goldOrders.size());
//2.黄金会员
List<OrderDTO> goldOrders = orderEntryValue.get(LevelEnum.GOLD.getLevel());
goldOrders = CollectionUtils.isEmpty(goldOrders) ? Collections.EMPTY_LIST : goldOrders;
BigDecimal totalGoldAmount = goldOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setTotalGoldAmount(totalGoldAmount);
orderMemberReceivedStatistics.setTotalGoldQuantity(goldOrders.size());
//3.钻石会员
List<OrderDTO> diamondOrders = orderEntryValue.get(LevelEnum.DIAMOND.getLevel());
diamondOrders = CollectionUtils.isEmpty(diamondOrders) ? Collections.EMPTY_LIST : diamondOrders;
BigDecimal totalDiamondAmount = diamondOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setTotalDiamondAmmount(totalDiamondAmount);
orderMemberReceivedStatistics.setTotalDiamondQuantity(diamondOrders.size());
BigDecimal totalAmount = totalCommAmount.add(totalGoldAmount).add(totalDiamondAmount);
orderMemberReceivedStatistics.setTotalAmount(totalAmount);
orderMemberReceivedStatisticsList.add(orderMemberReceivedStatistics);
//3.钻石会员
List<OrderDTO> diamondOrders = orderEntryValue.get(LevelEnum.DIAMOND.getLevel());
diamondOrders = CollectionUtils.isEmpty(diamondOrders) ? Collections.EMPTY_LIST : diamondOrders;
BigDecimal totalDiamondAmount = diamondOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
orderMemberReceivedStatistics.setTotalDiamondAmmount(totalDiamondAmount);
orderMemberReceivedStatistics.setTotalDiamondQuantity(diamondOrders.size());
BigDecimal totalAmount = totalCommAmount.add(totalGoldAmount).add(totalDiamondAmount);
orderMemberReceivedStatistics.setTotalAmount(totalAmount);
orderMemberReceivedStatisticsList.add(orderMemberReceivedStatistics);
}
}
//创建剩余状态数据
List<OrderMemberReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, Lists.newArrayList(ordersMap.keySet()), 1);
List stisticsActiveState = ordersMap.isEmpty() ? Collections.EMPTY_LIST : Lists.newArrayList(ordersMap.keySet());
List<OrderMemberReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, stisticsActiveState, 1);
orderMemberReceivedStatisticsList.addAll(otherStatisticsStateGroupList);
//保存
insertMemberReceivedStatisticsBatch(orderMemberReceivedStatisticsList);
long interval = timer.interval();
System.out.println("花费时间:" + interval);
}
/**
......
......@@ -5,9 +5,8 @@ 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;
import com.xxfc.platform.order.pojo.account.OrderAccountDTO;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
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;
......@@ -31,54 +30,49 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehicleReceivedStatisticsMapper, OrderRentVehicleReceivedStatistics> {
private final BaseOrderBiz baseOrderBiz;
private final OrderAccountBiz orderAccountBiz;
private final VehicleFeign vehicleFeign;
private final int PAY_ORDER=101;
public List<OrderRentVehicleReceivedStatistics> selectOrderReceivedStatistics(OrderReceivedStatisticsFindDTO orderReceivedStatisticsFindDTO) {
return mapper.selectOrderRentVehicleReceivedStatistics(orderReceivedStatisticsFindDTO);
}
public void orderRentVehicleReceivedStatistics(Date startDate,Date endDate) {
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>(18);
List<OrderDTO> orders = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(1), startDate, endDate);
List<Integer> orderIds = orders.stream().map(OrderDTO::getId).collect(Collectors.toList());
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>();
//订单账目信息
List<OrderAccountDTO> orderAccountDTOList = orderAccountBiz.selectByOrders(orderIds);
Map<Integer, List<OrderAccountDTO>> orderAccountMap = orderAccountDTOList.stream().collect(Collectors.groupingBy(OrderAccountDTO::getOrderId, Collectors.toList()));
List<OrderAccountBo> orderAccountBoList = orderAccountBiz.selectByDate(startDate,endDate);
//数据处理 把 完成状态6 取消状态2 的其他数据转换成状态为未完成3
Map<String, List<OrderAccountBo>> orderAccountBoMap = orderAccountBoList.stream().peek(x -> {
Integer status = x.getStatus() == StatisticsStatusEnum.CANCEL ? StatisticsStatusEnum.CANCEL : x.getStatus() == StatisticsStatusEnum.FINISH ? StatisticsStatusEnum.FINISH : StatisticsStatusEnum.UNFINISH;
x.setStatus(status);
x.setStateGroup(String.format("%d-%d-%d-%d", 1, x.getOrderOrigin(), x.getPayWay() == null ? 1 : x.getPayWay(), x.getStatus()));
}).collect(Collectors.groupingBy(OrderAccountBo::getStateGroup, Collectors.toList()));
// //数据处理 把 完成状态6 取消状态2 的其他数据转换成状态为未完成3
Map<String, List<OrderDTO>> ordersMap = orders.stream().peek(x -> {
Integer status = x.getStatus() == StatisticsStatusEnum.CANCEL ? StatisticsStatusEnum.CANCEL : x.getStatus() == StatisticsStatusEnum.FINISH ? StatisticsStatusEnum.FINISH : StatisticsStatusEnum.UNFINISH;
x.setStatus(status);
x.setStateGroup(String.format("%d-%d-%d-%d", 1, x.getOrderOrigin(), x.getPayWay()==null?1:x.getPayWay(), x.getStatus()));
}
).collect(Collectors.groupingBy(OrderDTO::getStateGroup, Collectors.toList()));
Set<Map.Entry<String, List<OrderDTO>>> ordersSet = ordersMap.entrySet();
for (Map.Entry<String, List<OrderDTO>> orderEntry : ordersSet) {
String orderKey = orderEntry.getKey();
List<OrderDTO> orderDTOS = orderEntry.getValue();
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey, new OrderRentVehicleReceivedStatistics());
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal refundAmount = BigDecimal.ZERO;
for (OrderDTO orderDTO : orderDTOS) {
List<OrderAccountDTO> orderAccountDTOS = orderAccountMap.get(orderDTO.getId());
for (OrderAccountDTO orderAccountDTO : orderAccountDTOS) {
OrderAccountDetail accountDetailEntity = orderAccountDTO.getAccountDetailEntity();
totalAmount.add(accountDetailEntity.getOriginOrderAmount()).add(accountDetailEntity.getOriginDepositAmount());
refundAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
if (!orderAccountBoMap.isEmpty()) {
Set<Map.Entry<String, List<OrderAccountBo>>> ordersSet = orderAccountBoMap.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) {
totalAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
} else {
refundAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
}
}
orderRentVehicleReceivedStatistics.setTotalAmount(totalAmount);
orderRentVehicleReceivedStatistics.setRealAmount(totalAmount.subtract(refundAmount));
orderRentVehicleReceivedStatistics.setTotalQuantity(orderAccountBos.size());
}
orderRentVehicleReceivedStatistics.setTotalAmount(totalAmount);
orderRentVehicleReceivedStatistics.setRealAmount(totalAmount.subtract(refundAmount));
orderRentVehicleReceivedStatistics.setTotalQuantity(orderDTOS.size());
}
List<Integer> companyIds = vehicleFeign.findCompanyIdsByAreaId(null);
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, Lists.newArrayList(ordersMap.keySet()), companyIds);
List stisticsActiveState = orderAccountBoMap.isEmpty() ? Collections.EMPTY_LIST : Lists.newArrayList(orderAccountBoMap.keySet());
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate,stisticsActiveState,companyIds);
orderRentVehicleReceivedStatisticsList.addAll(otherStatisticsStateGroupList);
insertMemberReceivedStatisticsBatch(orderRentVehicleReceivedStatisticsList);
}
......
......@@ -2,6 +2,7 @@ package com.xxfc.platform.order.mapper;
import com.xxfc.platform.order.entity.OrderAccount;
import com.xxfc.platform.order.pojo.Term;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDTO;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
......@@ -19,4 +20,7 @@ import java.util.List;
public interface OrderAccountMapper extends Mapper<OrderAccount> {
List<OrderAccountDTO> getOrderAccountByOrderType(Term term);
List<OrderAccountBo> selectOrderAccountByStartTimeAndEndTime(@Param("startTime") long startTime,
@Param("endTime") long endTime);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.order.mapper.OrderAccountMapper">
<select id="getOrderAccountByOrderType" parameterType="com.xxfc.platform.order.pojo.Term" resultType="com.xxfc.platform.order.pojo.account.OrderAccountDTO">
<select id="getOrderAccountByOrderType" parameterType="com.xxfc.platform.order.pojo.Term"
resultType="com.xxfc.platform.order.pojo.account.OrderAccountDTO">
SELECT
<if test="subdivide !=null and subdivide ==1">
date( FROM_UNIXTIME( a.crt_time / 1000 ) ) as oneDay,
......@@ -27,7 +28,7 @@
AND
b.type = #{orderType}
<if test="startTime != null">
AND a.crt_time <![CDATA[>= ]]> #{startTime}
AND a.crt_time <![CDATA[>= ]]> #{startTime}
</if>
<if test="endTime != null">
AND a.crt_time &gt; endTime
......@@ -51,4 +52,18 @@
</if>
</select>
<select id="selectOrderAccountByStartTimeAndEndTime"
resultType="com.xxfc.platform.order.pojo.account.OrderAccountBo">
SELECT
oa.*,
bo.id,
bo.`status`,
bo.order_origin,
bo.pay_way
FROM
`order_account` AS `oa`
INNER JOIN `base_order` AS `bo` ON bo.id = oa.order_id
WHERE oa.`crt_time` BETWEEN #{startTime} AND #{endTime}
</select>
</mapper>
\ No newline at end of file
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