Commit d4bbe843 authored by libin's avatar libin

订单统计

parent 572901e9
package com.github.wxiaoqi.security.common.enumconstant;
import org.assertj.core.util.Lists;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -29,9 +32,11 @@ public enum LevelEnum {
private Integer level;
private String desc;
private static Map<Integer, LevelEnum> levelMap;
public static List<Integer> levels;
static {
levelMap = EnumSet.allOf(LevelEnum.class).stream().collect(Collectors.toMap(LevelEnum::getLevel, Function.identity()));
levels = Lists.newArrayList(levelMap.keySet());
}
public Integer getLevel() {
......
package com.xxfc.platform.order.bo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/23 14:39
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class CompanyPerformanceBo {
private Date date;
private Integer year;
private String month;
private String weekOfYear;
private Integer companyId;
private String companyName;
private BigDecimal memberAmount;
private BigDecimal rentVehilceAmount;
private BigDecimal travelAmount;
private BigDecimal noDeductibleAmount;
private Integer rentDays;
private BigDecimal extralAmount;
private Integer departureNum;
private Integer arrivalNum;
private Date startDate;
private Date endDate;
}
package com.xxfc.platform.order.contant.enumerate;
import org.assertj.core.util.Lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum DeductionTypeEnum {
......@@ -22,19 +26,48 @@ public enum DeductionTypeEnum {
* 类型描述
*/
private String desc;
/**
* 违约相关code
*/
public static List<Integer> lateFeeCode;
/**
* 定损相关code
*/
public static List<Integer> lossSpecifiedCode;
/**
* 违章相关code
*/
public static List<Integer> breakRulesRegulationCode;
/**
*消费金额相关code
*/
public static List<Integer> consumerCode;
private static Map<Integer,String> codeAndDesc = new HashMap<Integer, String>();
//Maps.newHashMap();
private static Map<Integer, String> codeAndDesc = new HashMap<Integer, String>();
static{
for(DeductionTypeEnum enumE : DeductionTypeEnum.values()){
codeAndDesc.put(enumE.getCode(),enumE.getDesc());
static {
for (DeductionTypeEnum enumE : DeductionTypeEnum.values()) {
codeAndDesc.put(enumE.getCode(), enumE.getDesc());
}
lateFeeCode = Lists.newArrayList(VIOLATE_CANCEL.getCode(),
VIOLATE_ADVANCE.getCode(),
VIOLATE_DELAY.getCode(),
VIOLATE_CHANGE_C.getCode());
lossSpecifiedCode = Lists.newArrayList(DAMAGES.getCode());
breakRulesRegulationCode = Lists.newArrayList(
VIOLATE_TRAFFIC_DEDUCT.getCode()
);
consumerCode = Lists.newArrayList(CONSUME.getCode());
}
DeductionTypeEnum(Integer code, String desc){
this.code=code;
this.desc=desc;
DeductionTypeEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public Integer getCode() {
......@@ -53,7 +86,7 @@ public enum DeductionTypeEnum {
this.desc = desc;
}
public static Boolean exists(Integer code){
public static Boolean exists(Integer code) {
return codeAndDesc.containsKey(code);
}
}
\ No newline at end of file
......@@ -5,14 +5,13 @@ import cn.hutool.core.date.DateTime;
import com.xxfc.platform.order.entity.OrderReceivedStatisticsBase;
import org.apache.commons.collections4.CollectionUtils;
import org.assertj.core.util.Lists;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.*;
/**
* @author libin
......@@ -26,12 +25,16 @@ public enum StatisticsStatusEnum {
public static final int ORDER_MEMBER_TYPE=3;
public static final int ORDER_RENT_VEHICLE_TYPE=1;
public static final int ORDER_TOUR_TYPE=2;
public static final String UN_PAY_STATE="0";
public static final int NO_PAY_WAY=0;
public static final int NO_ORDER_ORIGN=99;
public static final int NO_ORDER_STATE=99;
public static final Integer DEFAULT_SQL_SIZE=1000;
public static final String ORDER_AMOUNT="order_amount";
public static final String LATEFEE_AMOUNT="late_fee";
public static final String ORDER_REFUND_AMOUNT="order_refund_amount";
public static final String ORDER_DEPOSIT_AMOUNT="order_deposit_amount";
public static final String COMPANY_DEFAULT="欣新房车控股集团";
public static final String NO_DEDUCTIBLE_AMOUNT="damageSafeAmount";
public static final String PARMAM_JSON="paramJson";
public static final int DAMAGE_SAFE=1;
public static List<String> orderStates;
public static List<String> orderOrigins;
public static List<String> orderPayWays;
......@@ -75,11 +78,7 @@ public enum StatisticsStatusEnum {
return stateGroupList;
}
public static Integer getCompnayId(String stateGroup){
return Integer.valueOf(stateGroup.split("-")[0]);
}
public static<T extends OrderReceivedStatisticsBase> T wrapStatisticsObject(Date date,String stateGroup,T targetObj){
public static<T extends OrderReceivedStatisticsBase> T wrapStatisticsObject(Date date, String stateGroup, Map<Integer,String> companyMap, T targetObj){
LocalDate localDate = LocalDate.from(new Date().toInstant().atZone(ZoneId.systemDefault()));
String year = String.valueOf(localDate.getYear());
String month = String.format("%s%d", year, localDate.getMonthValue());
......@@ -87,6 +86,8 @@ public enum StatisticsStatusEnum {
String[] status = stateGroup.split("-");
targetObj.setCrtTime(new Date());
targetObj.setCompanyId(Integer.valueOf(status[0]));
String companyName = Objects.isNull(companyMap)?COMPANY_DEFAULT: StringUtils.hasText(companyMap.get(targetObj.getCompanyId()))?companyMap.get(targetObj.getCompanyId()):COMPANY_DEFAULT;
targetObj.setCompanyName(companyName);
targetObj.setHasPay(Integer.valueOf(status[3]));
targetObj.setOrderOrigin(Integer.valueOf(status[1]));
targetObj.setPayWay(Integer.valueOf(status[2]));
......@@ -94,6 +95,12 @@ public enum StatisticsStatusEnum {
targetObj.setYear(year);
targetObj.setMonth(month);
targetObj.setWeekOfYear(weekOfYear);
targetObj.setExtraAmount(BigDecimal.ZERO);
targetObj.setLateFeeAmount(BigDecimal.ZERO);
targetObj.setTotalAmount(BigDecimal.ZERO);
targetObj.setTotalQuantity(0);
targetObj.setOrderRefundAmount(BigDecimal.ZERO);
targetObj.setStateGroup(stateGroup);
return targetObj;
}
}
......@@ -6,6 +6,7 @@ import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
/**
......@@ -20,12 +21,41 @@ import java.io.Serializable;
public class OrderReceivedStatistics extends OrderReceivedStatisticsBase implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 订单总量
*/
@Column(name = "total_quantity")
@ApiModelProperty(value = "订单总量")
private Integer totalQuantity;
@Column(name = "member_amount")
@ApiModelProperty("会员费")
private BigDecimal memberAmount;
@Column(name = "travel_amount")
@ApiModelProperty("旅游费")
private BigDecimal travelAmount;
@Column(name = "rent_vehicle_amount")
@ApiModelProperty("租车费")
private BigDecimal rentVehicleAmount;
@Column(name = "no_deductible_amount")
@ApiModelProperty("不计免赔费")
private BigDecimal noDeductibleAmount;
@Column(name = "no_deductible_refund_amount")
@ApiModelProperty("不计免赔退款费用")
private BigDecimal noDeductibleRefundAmount;
@Column(name = "deposit_amount")
@ApiModelProperty("押金")
private BigDecimal depositAmount;
@Column(name = "deposit_refund_amount")
@ApiModelProperty("押金退款")
private BigDecimal depositRefundAmount;
@Column(name = "break_rules_regulation_amount")
@ApiModelProperty("违章金")
private BigDecimal breakRulesRegulationAmount;
@Column(name = "loss_specified_amount")
@ApiModelProperty("定损金")
private BigDecimal lossSpecifiedAmount;
}
......@@ -57,7 +57,7 @@ public class OrderReceivedStatisticsBase implements Serializable {
* 订单总额
*/
@Column(name = "total_amount")
@ApiModelProperty(value = "订单总额")
@ApiModelProperty(value = "订单总额(不包含押金)")
protected BigDecimal totalAmount;
/**
......@@ -65,7 +65,7 @@ public class OrderReceivedStatisticsBase implements Serializable {
*/
@Column(name = "total_quantity")
@ApiModelProperty(value = "订单总量")
private Integer totalQuantity;
protected Integer totalQuantity;
@Column(name = "has_pay")
@ApiModelProperty(value = "是否支付 1已经支付 0未支付")
......@@ -89,13 +89,33 @@ public class OrderReceivedStatisticsBase implements Serializable {
@ApiModelProperty(value = "分公司id")
protected Integer companyId;
@Transient
protected Integer divisor;
@Column(name = "company_name")
@ApiModelProperty("分公司名称")
protected String companyName;
@ApiModelProperty("违约金")
@Column(name = "late_fee_amount")
protected BigDecimal lateFeeAmount;
@ApiModelProperty("订单退款")
@Column(name = "order_refund_amount")
protected BigDecimal orderRefundAmount;
@ApiModelProperty("额外费用")
@Column(name = "extra_amount")
protected BigDecimal extraAmount;
/**
* 创建时间
*/
@Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true)
private Date crtTime;
protected Date crtTime;
@Transient
protected Integer divisor;
@Transient
private String stateGroup;
}
......@@ -6,6 +6,7 @@ import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
/**
......@@ -20,11 +21,28 @@ import java.io.Serializable;
public class OrderRentVehicleReceivedStatistics extends OrderReceivedStatisticsBase implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 订单总量
*/
@Column(name = "total_quantity")
@ApiModelProperty(value = "订单总量")
private Integer totalQuantity;
@Column(name = "deposit_amount")
@ApiModelProperty("押金")
private BigDecimal depositAmount;
@Column(name = "deposit_refund_amount")
@ApiModelProperty("押金退款")
private BigDecimal depositRefundAmount;
@Column(name = "break_rules_regulation_amount")
@ApiModelProperty("违章金")
private BigDecimal breakRulesRegulationAmount;
@Column(name = "loss_specified_amount")
@ApiModelProperty("定损金")
private BigDecimal lossSpecifiedAmount;
@Column(name = "no_deductible_amount")
@ApiModelProperty("不计免赔费用")
private BigDecimal noDeductibleAmount;
@Column(name = "no_deductible_refund_amount")
@ApiModelProperty("不计免赔费用")
private BigDecimal noDeductibleRefundAmount;
}
package com.xxfc.platform.order.pojo.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/23 14:36
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class CompanyPerformanceFindDTO extends PageParam {
private Date startDate;
private Date endDate;
@ApiModelProperty("统计方式 1:日 2:周 3:月")
@NotNull(message = "统计方式不能为null")
private Integer statisticalWay;
private String companyName;
}
package com.xxfc.platform.order.pojo.dto;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.enumconstant.LevelEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author libin
......@@ -30,6 +32,13 @@ public class OrderDTO {
protected Integer companyId;
protected String stateGroup;
protected Integer hasPay;
private JSONObject data;
private Integer damageSafe;
private BigDecimal deposit;
/**
* 费用其他明细 租车使用
*/
protected String costDetailExtend;
/**
* 会员相关
*/
......@@ -42,4 +51,7 @@ public class OrderDTO {
return LevelEnum.getLevelEnumByLevel(this.memberLevel);
}
public JSONObject getData() {
return StringUtils.hasText(costDetailExtend)?JSONUtil.parseObj(costDetailExtend):new JSONObject();
}
}
package com.xxfc.platform.order.biz;
import cn.hutool.core.date.DateUtil;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.order.contant.enumerate.ReceivedStatisticsEnum;
import com.xxfc.platform.order.pojo.dto.CompanyPerformanceFindDTO;
import com.xxfc.platform.order.bo.CompanyPerformanceBo;
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;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/23 14:48
*/
@Transactional(rollbackFor = Exception.class)
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CompanyPerformanceBiz {
private final OrderReceivedStatisticsBiz orderReceivedStatisticsBiz;
private final VehicleFeign vehicleFeign;
public PageDataVO<CompanyPerformanceBo> selectCompanyPerformancePage(CompanyPerformanceFindDTO companyPerformanceFindDTO) {
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
PageDataVO<CompanyPerformanceBo> pageDataVO = new PageDataVO<>();
//日统计
if (companyPerformanceFindDTO.getStatisticalWay() == ReceivedStatisticsEnum.DAY.getWayCode()) {
pageDataVO = orderReceivedStatisticsBiz.selectCompanyPerformanceWithDayPage(companyPerformanceFindDTO);
}
//按周
if (companyPerformanceFindDTO.getStatisticalWay() == ReceivedStatisticsEnum.WEEK.getWayCode()) {
pageDataVO = orderReceivedStatisticsBiz.selectCompanyPerformanceWithWeekPage(companyPerformanceFindDTO);
}
//按月
if (companyPerformanceFindDTO.getStatisticalWay() == ReceivedStatisticsEnum.MONTH.getWayCode()) {
pageDataVO = orderReceivedStatisticsBiz.selectCompanyPerformanceWithMonthPage(companyPerformanceFindDTO);
}
List<CompanyPerformanceBo> data = pageDataVO.getData();
if (CollectionUtils.isEmpty(data)) {
return pageDataVO;
}
for (CompanyPerformanceBo companyPerformanceBo : data) {
String companyName = companyMap == null ? "" : companyMap.get(companyPerformanceBo.getCompanyId());
companyPerformanceBo.setCompanyName(companyName);
if (companyPerformanceFindDTO.getStatisticalWay() == ReceivedStatisticsEnum.WEEK.getWayCode()) {
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.YEAR, companyPerformanceBo.getYear());
cal.set(Calendar.WEEK_OF_YEAR, Integer.valueOf(companyPerformanceBo.getWeekOfYear().replace("" + companyPerformanceBo.getYear(), "")));
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
Date startDate = cal.getTime();
cal.add(Calendar.DAY_OF_WEEK, 6);
Date endDate = cal.getTime();
companyPerformanceBo.setStartDate(DateUtil.beginOfDay(startDate));
companyPerformanceBo.setEndDate(DateUtil.beginOfDay(endDate));
}
}
return pageDataVO;
}
}
......@@ -3,16 +3,19 @@ package com.xxfc.platform.order.biz;
import cn.hutool.core.util.ObjectUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.enumconstant.LevelEnum;
import com.github.wxiaoqi.security.common.util.CollectorsUtil;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.DeductionTypeEnum;
import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum;
import com.xxfc.platform.order.entity.OrderMemberReceivedStatistics;
import com.xxfc.platform.order.mapper.OrderMemberReceivedStatisticsMapper;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
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.order.pojo.order.CompanyAmountBo;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
......@@ -34,12 +37,11 @@ import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceivedStatisticsMapper, OrderMemberReceivedStatistics> {
public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceivedStatisticsMapper, OrderMemberReceivedStatistics>{
private final BaseOrderBiz baseOrderBiz;
private final OrderAccountBiz orderAccountBiz;
private final int PAY_ORDER = 101;
/**
* 会员统计查询
*
......@@ -55,20 +57,19 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
*
* @param startDate 开始时间
* @param endDate 结束时间
* @param companyMap 公司
*/
public void orderMemberReceivedStatistics(Date startDate, Date endDate) {
public List<OrderMemberReceivedStatistics> orderMemberReceivedStatistics(Date startDate, Date endDate,Map<Integer,String> companyMap) {
List<OrderMemberReceivedStatistics> orderMemberReceivedStatisticsList = new ArrayList<>(18);
List<String> stisticsActiveState = new ArrayList<>();
//公司的收入与支出 ---》无状态
List<CompanyAmountBo> companyAmoutList = new ArrayList<>();
//根据时间范围查询出会员单
List<OrderDTO> orders = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_MEMBER_TYPE), startDate, endDate);
//数据处理 状态组合 按支付状态分组 而后按组合状态
Map<Boolean, Map<String, Map<LevelEnum, List<OrderDTO>>>> stateGroupMap = orders.stream().peek(x -> {
x.setStateGroup(String.format("%d-%d-%d-%d", StatisticsStatusEnum.DEFAULT_COMPANY,
x.getOrderOrigin(), x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),
x.setStateGroup(String.format("%d-%d-%d-%d", Objects.isNull(x.getCompanyId())?StatisticsStatusEnum.DEFAULT_COMPANY:x.getCompanyId(),
x.getOrderOrigin(), Objects.isNull(x.getPayWay()) ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),
x.getHasPay()));
stisticsActiveState.add(x.getStateGroup());
})
......@@ -78,12 +79,12 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
List<OrderAccountBo> orderAccountBoList = orderAccountBiz.selectByTypeAndDate(StatisticsStatusEnum.ORDER_MEMBER_TYPE, startDate, endDate);
//账目数据处理 状态组合
Map<String, Map<LevelEnum, List<OrderAccountBo>>> orderAccountMap = orderAccountBoList.stream().peek(x -> {
x.setStateGroup(String.format("%d-%d-%d-%d", StatisticsStatusEnum.DEFAULT_COMPANY, x.getOrderOrigin(),
x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),
x.setStateGroup(String.format("%d-%d-%d-%d", Objects.isNull(x.getCompanyId())?StatisticsStatusEnum.DEFAULT_COMPANY:x.getCompanyId(), x.getOrderOrigin(),
Objects.isNull(x.getPayWay()) ? StatisticsStatusEnum.NO_PAY_WAY : x.getPayWay(),
x.getHasPay()));
stisticsActiveState.add(x.getStateGroup());
}).collect(Collectors.groupingBy(OrderAccountBo::getStateGroup, Collectors.groupingBy(OrderAccountBo::getLevelEnum, Collectors.toList())));
//已经支付单
Set<Map.Entry<String, Map<LevelEnum, List<OrderAccountBo>>>> ordersSet = orderAccountMap.entrySet();
for (Map.Entry<String, Map<LevelEnum, List<OrderAccountBo>>> orderEntry : ordersSet) {
......@@ -94,40 +95,25 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
MemberLevelStatistics memberLevelStatistics = new MemberLevelStatistics();
//遍历
for (Map.Entry<LevelEnum, List<OrderAccountBo>> orderMemberLevelEntry : ordermemberLevelentries) {
Integer totalQuantity = stateGroupMap.get(Boolean.TRUE).get(orderKey) == null ? 0 : stateGroupMap.get(Boolean.TRUE).get(orderKey).size();
Integer totalQuantity = stateGroupMap==null?0:stateGroupMap.get(Boolean.TRUE).get(orderKey) == null ? 0 : stateGroupMap.get(Boolean.TRUE).get(orderKey).size();
wrapMemberLevelStatistics(orderMemberLevelEntry.getKey(), orderMemberLevelEntry.getValue(), totalQuantity, memberLevelStatistics);
}
if (stisticsActiveState.contains(orderKey)) {
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey, new OrderMemberReceivedStatistics());
BeanUtils.copyProperties(memberLevelStatistics, orderMemberReceivedStatistics);
orderMemberReceivedStatisticsList.add(orderMemberReceivedStatistics);
} else {
Integer compnayId = StatisticsStatusEnum.getCompnayId(orderKey);
CompanyAmountBo companyAmountBo = CompanyAmountBo.builder().companyId(compnayId).amount(memberLevelStatistics.getTotalAmount()).build();
companyAmoutList.add(companyAmountBo);
}
}
//无状态组合统计对象生成
Map<Integer, BigDecimal> companyAmountMap = companyAmoutList.stream().collect(Collectors.groupingBy(CompanyAmountBo::getCompanyId,
CollectorsUtil.summingBigDecimal(CompanyAmountBo::getAmount)));
Set<Map.Entry<Integer, BigDecimal>> companyAmountSet = companyAmountMap.entrySet();
for (Map.Entry<Integer, BigDecimal> companyAmountEntry : companyAmountSet) {
String stateGrp = String.format("%d-%d-%d-%d", companyAmountEntry.getKey(), StatisticsStatusEnum.NO_ORDER_ORIGN, StatisticsStatusEnum.NO_PAY_WAY, StatisticsStatusEnum.NO_ORDER_STATE);
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGrp, new OrderMemberReceivedStatistics());
orderMemberReceivedStatistics.setTotalAmount(companyAmountEntry.getValue());
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey,companyMap,new OrderMemberReceivedStatistics());
BeanUtils.copyProperties(memberLevelStatistics, orderMemberReceivedStatistics);
orderMemberReceivedStatisticsList.add(orderMemberReceivedStatistics);
}
//未支付单
List<OrderMemberReceivedStatistics> noPayOrderMemberReceivedStatisticsList = createOrderMemberReceivedStatisticsList(startDate, stateGroupMap.get(Boolean.FALSE));
Map<String, Map<LevelEnum, List<OrderDTO>>> noPayOrdersMap = stateGroupMap==null?Collections.EMPTY_MAP:stateGroupMap.get(Boolean.FALSE)==null?Collections.EMPTY_MAP:stateGroupMap.get(Boolean.FALSE);
List<OrderMemberReceivedStatistics> noPayOrderMemberReceivedStatisticsList = createOrderMemberReceivedStatisticsList(startDate,noPayOrdersMap,companyMap);
orderMemberReceivedStatisticsList.addAll(noPayOrderMemberReceivedStatisticsList);
//创建剩余状态数据
List<OrderMemberReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, stisticsActiveState, StatisticsStatusEnum.DEFAULT_COMPANY);
List<OrderMemberReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate, stisticsActiveState,companyMap);
orderMemberReceivedStatisticsList.addAll(otherStatisticsStateGroupList);
//保存
insertMemberReceivedStatisticsBatch(orderMemberReceivedStatisticsList);
return orderMemberReceivedStatisticsList;
}
/**
......@@ -140,8 +126,10 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
* @return
*/
private MemberLevelStatistics wrapMemberLevelStatistics(LevelEnum levelEnum, List<OrderAccountBo> orderAccountBos, Integer totalQuantity, MemberLevelStatistics memberLevelStatistics) {
BigDecimal realAmount = getRealAmount(orderAccountBos);
return wrapMemberLevelStatistics(levelEnum,realAmount,totalQuantity,memberLevelStatistics);
Map<String,BigDecimal> orderFeeMap = getOrderAmountAndLateFeeAmount(orderAccountBos);
memberLevelStatistics.setLateFeeAmount(orderFeeMap.get(StatisticsStatusEnum.LATEFEE_AMOUNT));
memberLevelStatistics.setOrderRefundAmount(orderFeeMap.get(StatisticsStatusEnum.ORDER_REFUND_AMOUNT));
return wrapMemberLevelStatistics(levelEnum,orderFeeMap.get(StatisticsStatusEnum.ORDER_AMOUNT),totalQuantity,memberLevelStatistics);
}
/**
......@@ -150,21 +138,36 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
* @param orderAccountBos
* @return
*/
private BigDecimal getRealAmount(List<OrderAccountBo> orderAccountBos) {
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal refundAmount = BigDecimal.ZERO;
private Map<String,BigDecimal> getOrderAmountAndLateFeeAmount(List<OrderAccountBo> orderAccountBos) {
Map<String,BigDecimal> orderAndLateMap = new HashMap<>();
//订单金额
BigDecimal totalOrderAmount = BigDecimal.ZERO;
//续约金额
BigDecimal totalLateFeeAmount = BigDecimal.ZERO;
//订单退款金额
BigDecimal totalOrderRefundAmount = BigDecimal.ZERO;
if (CollectionUtils.isEmpty(orderAccountBos)) {
return BigDecimal.ZERO;
return orderAndLateMap;
}
for (OrderAccountBo orderAccountBo : orderAccountBos) {
OrderAccountDetail accountDetailEntity = orderAccountBo.getAccountDetailEntity();
if (orderAccountBo.getAccountType() == PAY_ORDER) {
totalAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
totalOrderAmount = totalOrderAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
} else {
refundAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
totalOrderRefundAmount = totalOrderRefundAmount.add(accountDetailEntity.getOrderAmount());
List<OrderAccountDeduction> deductions = accountDetailEntity.getDeductions();
for (OrderAccountDeduction deduction : deductions) {
Integer type = deduction.getType();
if (DeductionTypeEnum.lateFeeCode.contains(type)){
totalLateFeeAmount = totalLateFeeAmount.add(deduction.getAmount());
}
}
}
}
return totalAmount.subtract(refundAmount);
orderAndLateMap.put(StatisticsStatusEnum.ORDER_AMOUNT,totalOrderAmount);
orderAndLateMap.put(StatisticsStatusEnum.LATEFEE_AMOUNT,totalLateFeeAmount);
orderAndLateMap.put(StatisticsStatusEnum.ORDER_REFUND_AMOUNT,totalOrderRefundAmount);
return orderAndLateMap;
}
/**
......@@ -172,7 +175,7 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
* @param noPayOrdersMap 未支付单map
* @return
*/
private List<OrderMemberReceivedStatistics> createOrderMemberReceivedStatisticsList(Date startDate, Map<String, Map<LevelEnum, List<OrderDTO>>> noPayOrdersMap) {
private List<OrderMemberReceivedStatistics> createOrderMemberReceivedStatisticsList(Date startDate, Map<String, Map<LevelEnum, List<OrderDTO>>> noPayOrdersMap,Map<Integer,String> companyMap) {
List<OrderMemberReceivedStatistics> orderMemberReceivedStatisticsList = new ArrayList<>();
if (noPayOrdersMap == null || noPayOrdersMap.isEmpty()) {
return orderMemberReceivedStatisticsList;
......@@ -183,7 +186,7 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
//获取状态
String noPayOrderStateGroup = noPayOrderEntry.getKey();
Map<LevelEnum, List<OrderDTO>> noPayOrderEntryValue = noPayOrderEntry.getValue();
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, noPayOrderStateGroup, new OrderMemberReceivedStatistics());
OrderMemberReceivedStatistics orderMemberReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, noPayOrderStateGroup,companyMap,new OrderMemberReceivedStatistics());
Set<Map.Entry<LevelEnum, List<OrderDTO>>> noPayOrderEntries = noPayOrderEntryValue.entrySet();
for (Map.Entry<LevelEnum, List<OrderDTO>> orderEntry : noPayOrderEntries) {
wrapOrderMemberReceivedStatistics(orderEntry.getValue(), orderEntry.getKey(), memberLevelStatistics);
......@@ -203,7 +206,7 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
private MemberLevelStatistics wrapOrderMemberReceivedStatistics(List<OrderDTO> orders, LevelEnum levelEnum, MemberLevelStatistics memberLevelStatistics) {
orders = CollectionUtils.isEmpty(orders) ? Collections.EMPTY_LIST : orders;
BigDecimal totalAmount = orders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
return wrapMemberLevelStatistics(levelEnum,totalAmount,orders.size(),memberLevelStatistics);
return wrapMemberLevelStatistics(levelEnum,totalAmount,orders.size(),memberLevelStatistics);
}
/**
......@@ -239,18 +242,19 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
*
* @param startDate 时间
* @param statisticsStateGroups 状态组合 集合
* @param companyId 公司 id
* @param companyMap 公司
* @return
*/
private List<OrderMemberReceivedStatistics> createOtherStatisticsStateGroupList(Date startDate, List<String> statisticsStateGroups, Integer companyId) {
private List<OrderMemberReceivedStatistics> createOtherStatisticsStateGroupList(Date startDate, List<String> statisticsStateGroups,Map<Integer,String> companyMap) {
List<OrderMemberReceivedStatistics> orderMemberReceivedStatisticsList = new ArrayList<>();
//获取剩余状态组合
List<String> otherStatisticsStateGroup = StatisticsStatusEnum.getOtherStatisticsStateGroup(Arrays.asList(companyId), statisticsStateGroups);
List<Integer> companyIds = Objects.isNull(companyMap)?Collections.EMPTY_LIST: Lists.newArrayList(companyMap.keySet());
List<String> otherStatisticsStateGroup = StatisticsStatusEnum.getOtherStatisticsStateGroup(companyIds,statisticsStateGroups);
//创建会员克隆统计对象
OrderMemberReceivedStatistics orderMemberReceivedStatistics = createDefaultOrderMemberReceivedStatistics();
//统计对象的生成
otherStatisticsStateGroup.stream().peek(stateGroup -> {
OrderMemberReceivedStatistics orderMemberReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGroup,
OrderMemberReceivedStatistics orderMemberReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGroup,companyMap,
ObjectUtil.clone(orderMemberReceivedStatistics));
orderMemberReceivedStatisticsList.add(orderMemberReceivedStatisticsClone);
}).count();
......@@ -285,6 +289,7 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
}
@Data
@NoArgsConstructor
private class MemberLevelStatistics {
private BigDecimal toalCommonAmmount = BigDecimal.ZERO;
......@@ -302,6 +307,25 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
private Integer totalQuantity;
/**
* 违约金
*/
private BigDecimal lateFeeAmount = BigDecimal.ZERO;
/**
* 订单退款金额
*/
private BigDecimal orderRefundAmount = BigDecimal.ZERO;
/**
* 非会员费
*/
private BigDecimal totalNonMemberAmount;
/**
* 非会员费
*/
private BigDecimal totalMemberAmount;
public BigDecimal getTotalAmount() {
return toalCommonAmmount.add(totalGoldAmount).add(totalDiamondAmmount);
}
......
......@@ -2,11 +2,15 @@ package com.xxfc.platform.order.biz;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.bo.CompanyPerformanceBo;
import com.xxfc.platform.order.contant.enumerate.*;
import com.xxfc.platform.order.entity.*;
import com.xxfc.platform.order.mapper.OrderReceivedStatisticsMapper;
import com.xxfc.platform.order.pojo.dto.CompanyPerformanceFindDTO;
import com.xxfc.platform.order.pojo.dto.OrderReceivedStatisticsFindDTO;
import com.xxfc.platform.order.pojo.vo.OrderReceivedStatisticsVo;
import lombok.RequiredArgsConstructor;
......@@ -20,9 +24,11 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -48,6 +54,37 @@ public class OrderReceivedStatisticsBiz extends BaseBiz<OrderReceivedStatisticsM
private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/**
* 公司业绩(按日统计)
* @param companyPerformanceFindDTO
* @return
*/
public PageDataVO<CompanyPerformanceBo> selectCompanyPerformanceWithDayPage(CompanyPerformanceFindDTO companyPerformanceFindDTO) {
return PageDataVO.pageInfo(companyPerformanceFindDTO.getPage(), companyPerformanceFindDTO.getLimit(),
() -> mapper.selectCompanyPerformanceWithDay(companyPerformanceFindDTO));
}
/**
* 公司业绩(按月统计)
* @param companyPerformanceFindDTO
* @return
*/
public PageDataVO<CompanyPerformanceBo> selectCompanyPerformanceWithMonthPage(CompanyPerformanceFindDTO companyPerformanceFindDTO) {
return PageDataVO.pageInfo(companyPerformanceFindDTO.getPage(), companyPerformanceFindDTO.getLimit(),
() -> mapper.selectCompanyPerformanceWithMonth(companyPerformanceFindDTO));
}
/**
* 公司业绩(按周统计)
* @param companyPerformanceFindDTO
* @return
*/
public PageDataVO<CompanyPerformanceBo> selectCompanyPerformanceWithWeekPage(CompanyPerformanceFindDTO companyPerformanceFindDTO) {
return PageDataVO.pageInfo(companyPerformanceFindDTO.getPage(), companyPerformanceFindDTO.getLimit(),
() -> mapper.selectCompanyPerformanceWithWeek(companyPerformanceFindDTO));
}
/**
* 订单统计数据导出
*
......@@ -178,6 +215,88 @@ public class OrderReceivedStatisticsBiz extends BaseBiz<OrderReceivedStatisticsM
return resultMap;
}
/**
* 统计汇总
*
* @param orderMemberReceivedStatistics
* @param orderTourReceivedStatistics
* @param orderRentVehicleReceivedStatistics
*/
public void orderReceivedStatistics(List<OrderMemberReceivedStatistics> orderMemberReceivedStatistics,
List<OrderTourReceivedStatistics> orderTourReceivedStatistics,
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatistics, Date date) {
List<OrderReceivedStatistics> orderReceivedStatisticsList = new ArrayList<>();
Map<String, List<OrderMemberReceivedStatistics>> memberMap = orderMemberReceivedStatistics.stream().collect(Collectors.groupingBy(OrderMemberReceivedStatistics::getStateGroup, Collectors.toList()));
Map<String, List<OrderTourReceivedStatistics>> tourMap = orderTourReceivedStatistics.stream().collect(Collectors.groupingBy(OrderTourReceivedStatistics::getStateGroup, Collectors.toList()));
Map<String, List<OrderRentVehicleReceivedStatistics>> rentVehicleMap = orderRentVehicleReceivedStatistics.stream().collect(Collectors.groupingBy(OrderRentVehicleReceivedStatistics::getStateGroup, Collectors.toList()));
OrderReceivedStatistics orderReceivedStatistics = new OrderReceivedStatistics();
Set<Map.Entry<String, List<OrderRentVehicleReceivedStatistics>>> rentVehicleSet = rentVehicleMap.entrySet();
for (Map.Entry<String, List<OrderRentVehicleReceivedStatistics>> rentVehicleEntry : rentVehicleSet) {
String stateGroup = rentVehicleEntry.getKey();
List<OrderRentVehicleReceivedStatistics> rentVehicleEntryValue = rentVehicleEntry.getValue();
OrderRentVehicleReceivedStatistics orderRentVehicle = rentVehicleEntryValue.get(0);
OrderReceivedStatistics orderReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(date, stateGroup, Collections.EMPTY_MAP, ObjectUtil.clone(orderReceivedStatistics));
orderReceivedStatisticsClone.setCompanyId(orderRentVehicle.getCompanyId());
orderReceivedStatisticsClone.setCompanyName(orderRentVehicle.getCompanyName());
OrderMemberReceivedStatistics orderMember = memberMap.get(stateGroup).get(0);
OrderTourReceivedStatistics orderTour = tourMap==null?null:tourMap.get(stateGroup)==null?null:tourMap.get(stateGroup).get(0);
orderReceivedStatisticsClone.setExtraAmount(orderRentVehicle.getExtraAmount());
orderReceivedStatisticsClone.setLossSpecifiedAmount(orderRentVehicle.getLossSpecifiedAmount());
orderReceivedStatisticsClone.setDepositAmount(orderRentVehicle.getDepositAmount());
orderReceivedStatisticsClone.setDepositRefundAmount(orderRentVehicle.getDepositRefundAmount());
orderReceivedStatisticsClone.setBreakRulesRegulationAmount(orderRentVehicle.getBreakRulesRegulationAmount());
orderReceivedStatisticsClone.setNoDeductibleRefundAmount(orderRentVehicle.getNoDeductibleRefundAmount());
orderReceivedStatisticsClone.setNoDeductibleAmount(orderRentVehicle.getNoDeductibleAmount());
orderReceivedStatisticsClone.setTravelAmount(orderTour == null?BigDecimal.ZERO:orderTour.getTotalAmount());
orderReceivedStatisticsClone.setMemberAmount(orderMember.getTotalAmount());
orderReceivedStatisticsClone.setRentVehicleAmount(orderRentVehicle.getTotalAmount());
BigDecimal totalAmount = orderRentVehicle.getTotalAmount().add(orderTour == null?BigDecimal.ZERO:orderTour.getTotalAmount()).add(orderMember.getTotalAmount());
BigDecimal totalRefundAmount = orderRentVehicle.getOrderRefundAmount().add(orderTour==null?BigDecimal.ZERO:orderTour.getOrderRefundAmount()).add(orderMember.getOrderRefundAmount());
BigDecimal lateFeeAmount = orderRentVehicle.getLateFeeAmount().add(orderTour==null?BigDecimal.ZERO:orderTour.getLateFeeAmount()).add(orderMember.getLateFeeAmount());
Integer totalQuantity = orderRentVehicle.getTotalQuantity() + (orderTour == null?0:orderTour.getTotalQuantity()) + orderMember.getTotalQuantity();
orderReceivedStatisticsClone.setLateFeeAmount(lateFeeAmount);
orderReceivedStatisticsClone.setTotalAmount(totalAmount);
orderReceivedStatisticsClone.setOrderRefundAmount(totalRefundAmount);
orderReceivedStatisticsClone.setTotalQuantity(totalQuantity);
orderReceivedStatisticsList.add(orderReceivedStatisticsClone);
}
insertReceivedStatisticsBatch(orderReceivedStatisticsList);
}
/**
* 批量插入数据 mysql sql语句默认不能超过4M
*
* @param orderReceivedStatistics
*/
public void insertReceivedStatisticsBatch(List<OrderReceivedStatistics> orderReceivedStatistics) {
orderReceivedStatistics.sort(Comparator.comparing(OrderReceivedStatistics::getCompanyId));
int orderSize = orderReceivedStatistics.size();
int sqlAdq = orderSize / StatisticsStatusEnum.DEFAULT_SQL_SIZE;
int sqlMod = orderSize % StatisticsStatusEnum.DEFAULT_SQL_SIZE;
sqlAdq = sqlMod == 0 ? sqlAdq : sqlAdq + 1;
for (int i = 0; i < sqlAdq; i++) {
int fromIndex = StatisticsStatusEnum.DEFAULT_SQL_SIZE * i;
int toIndex = StatisticsStatusEnum.DEFAULT_SQL_SIZE * (i + 1);
toIndex = toIndex > orderSize ? orderSize : toIndex;
List<OrderReceivedStatistics> orderRentVehicleReceivedStatisticsList = orderReceivedStatistics.subList(fromIndex, toIndex);
mapper.insertList(orderRentVehicleReceivedStatisticsList);
}
}
/**
* 订单统计
......
package com.xxfc.platform.order.biz;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.util.CollectorsUtil;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.DeductionTypeEnum;
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.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
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.order.pojo.order.CompanyAmountBo;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -35,7 +37,6 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
private final BaseOrderBiz baseOrderBiz;
private final OrderAccountBiz orderAccountBiz;
private final VehicleFeign vehicleFeign;
private final int PAY_ORDER = 101;
/**
......@@ -53,12 +54,11 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
*
* @param startDate 开始时间
* @param endDate 结束时间
* @param companyMap 公司
*/
public void orderRentVehicleReceivedStatistics(Date startDate, Date endDate) {
public List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatistics(Date startDate, Date endDate,Map<Integer,String> companyMap) {
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>();
List<String> stisticsActiveState = new ArrayList<>();
//公司的收入与支出 ---》无状态
List<CompanyAmountBo> companyAmoutList = new ArrayList<>();
//根据租车订单类型 时间查询
List<OrderDTO> orderDTOS = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE), startDate, endDate);
......@@ -80,60 +80,116 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
x.getOrderOrigin(),
x.getPayWay() == null ? StatisticsStatusEnum.NO_PAY_WAY:x.getPayWay(),
x.getHasPay()));
stisticsActiveState.add(x.getStateGroup());
}).collect(Collectors.groupingBy(OrderAccountBo::getStateGroup, Collectors.toList()));
//已经支付单
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();
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal refundAmount = BigDecimal.ZERO;
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, orderKey,companyMap,new OrderRentVehicleReceivedStatistics());
//订单总金额
BigDecimal totalOrderAmount = BigDecimal.ZERO;
//订单总押金
BigDecimal totalDepositAmount = BigDecimal.ZERO;
//总违约金
BigDecimal totalLateFeeAmount = BigDecimal.ZERO;
//订单退款总金额
BigDecimal totalOrderRefundAmount = BigDecimal.ZERO;
//订单押金退款总金额
BigDecimal totalDepositRefundAmount = BigDecimal.ZERO;
//订单违章总金额
BigDecimal totalBreakRulesRegulationAmount = BigDecimal.ZERO;
//订单定损金总金额
BigDecimal totalLossSpecifiedAmount = BigDecimal.ZERO;
//不计免赔金额
BigDecimal damageSafeAmount = BigDecimal.ZERO;
//不计免赔金额退款
BigDecimal refundDamageSafeAmount = BigDecimal.ZERO;
//其它费用
BigDecimal totalExtendAmount = BigDecimal.ZERO;
for (OrderAccountBo orderAccountBo : orderAccountBos) {
OrderAccountDetail accountDetailEntity = orderAccountBo.getAccountDetailEntity();
if (orderAccountBo.getAccountType() == PAY_ORDER) {
totalAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
totalOrderAmount = totalOrderAmount.add(accountDetailEntity.getOrderAmount());
totalDepositAmount = totalDepositAmount.add(accountDetailEntity.getDepositAmount());
if (Objects.nonNull(orderAccountBo.getDamageSafe()) && (orderAccountBo.getDamageSafe() == StatisticsStatusEnum.DAMAGE_SAFE)){
JSONObject data = orderAccountBo.getData();
if (!data.isEmpty()) {
Object paramJson = data.get(StatisticsStatusEnum.PARMAM_JSON);
JSONObject jsonObject = JSONUtil.parseObj(paramJson);
BigDecimal safeAmount = jsonObject.get(StatisticsStatusEnum.NO_DEDUCTIBLE_AMOUNT, BigDecimal.class);
damageSafeAmount = damageSafeAmount.add(safeAmount);
}
}
} else {
refundAmount.add(accountDetailEntity.getOrderAmount()).add(accountDetailEntity.getDepositAmount());
totalOrderRefundAmount = totalOrderRefundAmount.add(accountDetailEntity.getOrderAmount());
totalDepositRefundAmount = totalDepositRefundAmount.add(accountDetailEntity.getDepositAmount());
List<OrderAccountDeduction> deductions = accountDetailEntity.getDeductions();
for (OrderAccountDeduction deduction : deductions) {
if (DeductionTypeEnum.lateFeeCode.contains(deduction.getType())){
totalLateFeeAmount = totalLateFeeAmount.add(deduction.getAmount());
if (deduction.getType().equals(DeductionTypeEnum.VIOLATE_CANCEL.getCode())){
if (Objects.nonNull(orderAccountBo.getDamageSafe()) && (orderAccountBo.getDamageSafe() == StatisticsStatusEnum.DAMAGE_SAFE)){
JSONObject data = orderAccountBo.getData();
if(!data.isEmpty()) {
Object paramJson = data.get(StatisticsStatusEnum.PARMAM_JSON);
JSONObject jsonObject = JSONUtil.parseObj(paramJson);
BigDecimal safeAmount = jsonObject.get(StatisticsStatusEnum.NO_DEDUCTIBLE_AMOUNT, BigDecimal.class);
refundDamageSafeAmount = refundDamageSafeAmount.add(safeAmount);
}
}
}
}
if (DeductionTypeEnum.breakRulesRegulationCode.contains(deduction.getType())){
totalBreakRulesRegulationAmount = totalBreakRulesRegulationAmount.add(deduction.getAmount());
}
if (DeductionTypeEnum.lossSpecifiedCode.contains(deduction.getType())){
totalLossSpecifiedAmount = totalLossSpecifiedAmount.add(deduction.getAmount());
}
if (DeductionTypeEnum.consumerCode.contains(deduction.getType())){
BigDecimal extendAmount = deduction.getAmount().subtract(accountDetailEntity.getOriginOrderAmount());
totalExtendAmount = totalExtendAmount.add(extendAmount);
}
}
}
}
if (stisticsActiveState.contains(orderKey)){
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);
}else {
Integer compnayId = StatisticsStatusEnum.getCompnayId(orderKey);
CompanyAmountBo companyAmountBo = CompanyAmountBo.builder().companyId(compnayId).amount(totalAmount.subtract(refundAmount)).build();
companyAmoutList.add(companyAmountBo);
}
}
orderRentVehicleReceivedStatistics.setNoDeductibleRefundAmount(refundDamageSafeAmount);
orderRentVehicleReceivedStatistics.setNoDeductibleAmount(damageSafeAmount);
orderRentVehicleReceivedStatistics.setTotalAmount(totalOrderAmount);
orderRentVehicleReceivedStatistics.setDepositAmount(totalDepositAmount);
orderRentVehicleReceivedStatistics.setLateFeeAmount(totalLateFeeAmount);
orderRentVehicleReceivedStatistics.setOrderRefundAmount(totalOrderRefundAmount);
orderRentVehicleReceivedStatistics.setDepositRefundAmount(totalDepositRefundAmount);
orderRentVehicleReceivedStatistics.setBreakRulesRegulationAmount(totalBreakRulesRegulationAmount);
orderRentVehicleReceivedStatistics.setLossSpecifiedAmount(totalLossSpecifiedAmount);
Integer totalQuantity = stateGroupMap ==null?0:stateGroupMap.get(Boolean.TRUE)==null?0:stateGroupMap.get(Boolean.TRUE).get(orderKey)==null?0:stateGroupMap.get(Boolean.TRUE).get(orderKey).size();
orderRentVehicleReceivedStatistics.setTotalQuantity(totalQuantity);
//无状态组合统计对象生成
Map<Integer, BigDecimal> companyAmountMap = companyAmoutList.stream().collect(Collectors.groupingBy(CompanyAmountBo::getCompanyId,
CollectorsUtil.summingBigDecimal(CompanyAmountBo::getAmount)));
Set<Map.Entry<Integer, BigDecimal>> companyAmountSet = companyAmountMap.entrySet();
for (Map.Entry<Integer, BigDecimal> companyAmountEntry : companyAmountSet) {
String stateGrp = String.format("%d-%d-%d-%d",companyAmountEntry.getKey(),StatisticsStatusEnum.NO_ORDER_ORIGN,StatisticsStatusEnum.NO_PAY_WAY,StatisticsStatusEnum.NO_ORDER_STATE);
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGrp, new OrderRentVehicleReceivedStatistics());
orderRentVehicleReceivedStatistics.setTotalQuantity(0);
orderRentVehicleReceivedStatistics.setTotalAmount(companyAmountEntry.getValue());
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatistics);
}
//未支付单
List<OrderRentVehicleReceivedStatistics> noPayOrderRentVehicleStatisticsList = createNoPayOrderRentVehicleStatisticsList(startDate, stateGroupMap.get(Boolean.FALSE));
Map<String, List<OrderDTO>> noPayOrderRentvehicleMap = stateGroupMap == null?Collections.EMPTY_MAP:stateGroupMap.get(Boolean.FALSE)==null?Collections.EMPTY_MAP:stateGroupMap.get(Boolean.FALSE);
List<OrderRentVehicleReceivedStatistics> noPayOrderRentVehicleStatisticsList = createNoPayOrderRentVehicleStatisticsList(startDate,noPayOrderRentvehicleMap,companyMap);
orderRentVehicleReceivedStatisticsList.addAll(noPayOrderRentVehicleStatisticsList);
//查询分公司ids
List<Integer> companyIds = vehicleFeign.findCompanyIdsByAreaId(null);
//创建剩余状态组合的租车统计对象
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate,stisticsActiveState, companyIds);
List<OrderRentVehicleReceivedStatistics> otherStatisticsStateGroupList = createOtherStatisticsStateGroupList(startDate,stisticsActiveState, companyMap);
orderRentVehicleReceivedStatisticsList.addAll(otherStatisticsStateGroupList);
//保存
insertMemberReceivedStatisticsBatch(orderRentVehicleReceivedStatisticsList);
return orderRentVehicleReceivedStatisticsList;
}
/**
......@@ -142,7 +198,7 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
* @param noPayOrdersMap 未支付单map
* @return
*/
private List<OrderRentVehicleReceivedStatistics> createNoPayOrderRentVehicleStatisticsList(Date startDate,Map<String, List<OrderDTO>> noPayOrdersMap) {
private List<OrderRentVehicleReceivedStatistics> createNoPayOrderRentVehicleStatisticsList(Date startDate,Map<String, List<OrderDTO>> noPayOrdersMap,Map<Integer,String> companyMap) {
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>();
if (noPayOrdersMap==null || noPayOrdersMap.isEmpty()){
return orderRentVehicleReceivedStatisticsList;
......@@ -151,9 +207,31 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
for (Map.Entry<String, List<OrderDTO>> noPayOrderEntry : noPayOrderSet) {
String noPayOrderStateGroup = noPayOrderEntry.getKey();
List<OrderDTO> noPayOrders = noPayOrderEntry.getValue();
BigDecimal totalNoPayAmount = noPayOrders.stream().map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, noPayOrderStateGroup, new OrderRentVehicleReceivedStatistics());
orderRentVehicleReceivedStatistics.setTotalAmount(totalNoPayAmount);
List<BigDecimal> damageSafeAmountList = new ArrayList<>();
BigDecimal totalNoPayAmount = noPayOrders.stream().peek(x->{
//免赔
if (Objects.nonNull(x.getDamageSafe()) && (x.getDamageSafe() == StatisticsStatusEnum.DAMAGE_SAFE)){
JSONObject data = x.getData();
if (!data.isEmpty()) {
Object paramJson = data.get(StatisticsStatusEnum.PARMAM_JSON);
JSONObject jsonObject = JSONUtil.parseObj(paramJson);
BigDecimal safeAmount = jsonObject.get(StatisticsStatusEnum.NO_DEDUCTIBLE_AMOUNT, BigDecimal.class);
damageSafeAmountList.add(safeAmount);
}
}
}).map(OrderDTO::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = StatisticsStatusEnum.wrapStatisticsObject(startDate, noPayOrderStateGroup,companyMap,new OrderRentVehicleReceivedStatistics());
BigDecimal damageSafeAmount = damageSafeAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
orderRentVehicleReceivedStatistics.setNoDeductibleAmount(damageSafeAmount);
BigDecimal depositAmount = noPayOrders.stream().map(OrderDTO::getDeposit).reduce(BigDecimal.ZERO, BigDecimal::add);
//押金
orderRentVehicleReceivedStatistics.setDepositAmount(depositAmount);
orderRentVehicleReceivedStatistics.setNoDeductibleRefundAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatistics.setDepositRefundAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatistics.setLossSpecifiedAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatistics.setBreakRulesRegulationAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatistics.setTotalAmount(totalNoPayAmount.subtract(depositAmount));
orderRentVehicleReceivedStatistics.setTotalQuantity(noPayOrders.size());
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatistics);
}
......@@ -165,21 +243,28 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
*
* @param startDate 时间
* @param statisticsStateGroups 状态组合 集合
* @param companyIds 公司ids
* @param companyMap 公司
* @return
*/
private List<OrderRentVehicleReceivedStatistics> createOtherStatisticsStateGroupList(Date startDate,
List<String> statisticsStateGroups,
List<Integer> companyIds) {
Map<Integer,String> companyMap) {
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>();
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>(statisticsStateGroups.size());
//获取剩余状态组合
List<String> otherStatisticsStateGroup = StatisticsStatusEnum.getOtherStatisticsStateGroup(companyIds, statisticsStateGroups);
List<Integer> companyIds = Objects.isNull(companyMap)?Collections.EMPTY_LIST:Lists.newArrayList(companyMap.keySet());
List<String> otherStatisticsStateGroup = StatisticsStatusEnum.getOtherStatisticsStateGroup(companyIds,statisticsStateGroups);
//创建租车统计克隆对象
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatistics = new OrderRentVehicleReceivedStatistics();
//统计对象的生成
otherStatisticsStateGroup.stream().map(stateGroup -> {
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGroup, ObjectUtil.cloneByStream(orderRentVehicleReceivedStatistics));
OrderRentVehicleReceivedStatistics orderRentVehicleReceivedStatisticsClone = StatisticsStatusEnum.wrapStatisticsObject(startDate, stateGroup,companyMap,ObjectUtil.cloneByStream(orderRentVehicleReceivedStatistics));
orderRentVehicleReceivedStatisticsClone.setDepositAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setDepositRefundAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setNoDeductibleAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setNoDeductibleRefundAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setLossSpecifiedAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setBreakRulesRegulationAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setTotalAmount(BigDecimal.ZERO);
orderRentVehicleReceivedStatisticsClone.setTotalQuantity(0);
orderRentVehicleReceivedStatisticsList.add(orderRentVehicleReceivedStatisticsClone);
......
......@@ -6,19 +6,27 @@ import com.xxfc.platform.order.biz.OrderMemberReceivedStatisticsBiz;
import com.xxfc.platform.order.biz.OrderReceivedStatisticsBiz;
import com.xxfc.platform.order.biz.OrderRentVehicleReceivedStatisticsBiz;
import com.xxfc.platform.order.biz.OrderTourReceivedStatisticsBiz;
import com.xxfc.platform.order.entity.OrderMemberReceivedStatistics;
import com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics;
import com.xxfc.platform.order.entity.OrderTourReceivedStatistics;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author libin
* @version 1.0
* @description 订单统计 定时任务
* @description 订单统计 定时任务
* @data 2019/11/11 11:09
*/
@JobHandler(value = "orderReceivedStatisticsJobHandler")
......@@ -26,22 +34,34 @@ import java.util.Date;
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderReceivedStatisticsJobHandler extends IJobHandler {
private final OrderReceivedStatisticsBiz orderReceivedStatisticsBiz;
private final OrderRentVehicleReceivedStatisticsBiz orderRentVehicleReceivedStatisticsBiz;
private final OrderTourReceivedStatisticsBiz orderTourReceivedStatisticsBiz;
private final OrderMemberReceivedStatisticsBiz orderMemberReceivedStatisticsBiz;
private final OrderReceivedStatisticsBiz orderReceivedStatisticsBiz;
private final OrderRentVehicleReceivedStatisticsBiz orderRentVehicleReceivedStatisticsBiz;
private final OrderTourReceivedStatisticsBiz orderTourReceivedStatisticsBiz;
private final OrderMemberReceivedStatisticsBiz orderMemberReceivedStatisticsBiz;
private final VehicleFeign vehicleFeign;
@Override
public ReturnT<String> execute(String s) throws Exception {
public ReturnT<String> execute(String arg) throws Exception {
DateTime yesterday = DateUtil.yesterday();
if (StringUtils.hasText(arg)){
yesterday = DateUtil.parse(arg,"yyyy-MM-dd");
}
Date startDate = DateUtil.beginOfDay(yesterday).toJdkDate();
Date endDate = DateUtil.endOfDay(yesterday).toJdkDate();
//订单
//租车订单
orderRentVehicleReceivedStatisticsBiz.orderRentVehicleReceivedStatistics(startDate,endDate);
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
//旅游订单
List<OrderTourReceivedStatistics> orderTourReceivedStatisticsList = Collections.EMPTY_LIST;
//租车订单
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = orderRentVehicleReceivedStatisticsBiz.orderRentVehicleReceivedStatistics(startDate, endDate, companyMap);
//会员订单
orderMemberReceivedStatisticsBiz.orderMemberReceivedStatistics(startDate,endDate);
return null;
List<OrderMemberReceivedStatistics> orderMemberReceivedStatisticsList = orderMemberReceivedStatisticsBiz.orderMemberReceivedStatistics(startDate, endDate, companyMap);
//订单
orderReceivedStatisticsBiz.orderReceivedStatistics(orderMemberReceivedStatisticsList,
orderTourReceivedStatisticsList,
orderRentVehicleReceivedStatisticsList,
startDate);
return new ReturnT<>(ReturnT.SUCCESS_CODE,"订单统计成功执行");
}
}
package com.xxfc.platform.order.mapper;
import com.xxfc.platform.order.bo.CompanyPerformanceBo;
import com.xxfc.platform.order.entity.OrderReceivedStatistics;
import com.xxfc.platform.order.pojo.dto.CompanyPerformanceFindDTO;
import com.xxfc.platform.order.pojo.dto.OrderReceivedStatisticsFindDTO;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
......@@ -13,7 +16,13 @@ import java.util.List;
* @email 18178966185@163.com
* @date 2019-11-08 18:03:42
*/
public interface OrderReceivedStatisticsMapper extends Mapper<OrderReceivedStatistics> {
public interface OrderReceivedStatisticsMapper extends Mapper<OrderReceivedStatistics>, InsertListMapper<OrderReceivedStatistics> {
List<OrderReceivedStatistics> selectOrderReceivedStatisticsList(OrderReceivedStatisticsFindDTO orderReceivedStatisticsFindDTO);
List<CompanyPerformanceBo> selectCompanyPerformanceWithDay(CompanyPerformanceFindDTO companyPerformanceFindDTO);
List<CompanyPerformanceBo> selectCompanyPerformanceWithMonth(CompanyPerformanceFindDTO companyPerformanceFindDTO);
List<CompanyPerformanceBo> selectCompanyPerformanceWithWeek(CompanyPerformanceFindDTO companyPerformanceFindDTO);
}
package com.xxfc.platform.order.rest.background;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.order.biz.CompanyPerformanceBiz;
import com.xxfc.platform.order.pojo.dto.CompanyPerformanceFindDTO;
import com.xxfc.platform.order.bo.CompanyPerformanceBo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author libin
* @version 1.0
* @description 公司业绩查询
* @data 2019/11/23 14:32
*/
@RestController
@RequestMapping("/statistics")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CompanyOrderReceivedStatiscsAdminController {
private final CompanyPerformanceBiz companyPerformanceBiz;
@PostMapping("/company_performance")
public ObjectRestResponse<PageDataVO<CompanyPerformanceBo>> companyPerformance(@RequestBody CompanyPerformanceFindDTO companyPerformanceFindDTO){
PageDataVO<CompanyPerformanceBo> dataVO = companyPerformanceBiz.selectCompanyPerformancePage(companyPerformanceFindDTO);
return ObjectRestResponse.succ(dataVO);
}
}
......@@ -354,7 +354,7 @@
</select>
<select id="selectOrdersByTypeAndTime" resultType="com.xxfc.platform.order.pojo.dto.OrderDTO">
select bo.*,omd.memberLevel,IFNULL(orvd.start_company_id,otd.start_company_id) AS `companyId` from (select `id`,`type`,`status`,`order_amount` AS `orderAmount`, `real_amount`AS
select bo.*,omd.memberLevel,IFNULL(orvd.start_company_id,otd.start_company_id) AS `companyId`,orvd.deposit,orvd.cost_detail_extend AS `costDetailExtend` from (select `id`,`type`,`status`,`order_amount` AS `orderAmount`, `real_amount`AS
`realAmount`,`order_origin` AS `orderOrigin`, `has_pay` AS `hasPay`,
`pay_way` AS `payWay`
from `base_order` where (`crt_time` between #{startDate} and #{endDate} or `pay_time` between #{startDate} and #{endDate} ) and `type` IN <foreach collection="types"
......@@ -363,7 +363,7 @@
separator=",">
#{type}
</foreach> ) AS `bo`
LEFT JOIN (select `order_id`,`start_company_id` from `order_rent_vehicle_detail`) AS `orvd` ON
LEFT JOIN (select `order_id`,`start_company_id`,`deposit`,`cost_detail_extend` from `order_rent_vehicle_detail`) AS `orvd` ON
orvd.order_id=bo.id
LEFT JOIN (select `order_id`,`start_company_id` from `order_tour_detail`) AS `otd` ON otd.order_id=bo.id
LEFT JOIN (select `order_id`,`member_level` AS `memberLevel` from `order_member_detail`) AS `omd` ON
......
......@@ -63,12 +63,15 @@
bo.pay_way,
bo.has_pay,
brvd.start_company_id AS `companyId`,
brvd.cost_detail_extend AS `costDetailExtend`,
brvd.damage_safe AS `damageSafe`,
omd.member_level AS `memberLevel`
FROM
`order_account` AS `oa`
INNER JOIN `base_order` AS `bo` ON bo.id = oa.order_id
LEFT JOIN `base_order` AS `bo` ON bo.id = oa.order_id
LEFT JOIN `order_rent_vehicle_detail` AS `brvd` ON brvd.order_id=oa.order_id
LEFT JOIN `order_member_detail` AS `omd` ON omd.order_id=oa.order_id
WHERE bo.type=#{orderType} AND oa.`crt_time` BETWEEN #{startTime} AND #{endTime}
WHERE bo.type=#{orderType} AND `oa`.account_status=1 AND oa.`crt_time` BETWEEN #{startTime} AND #{endTime}
</select>
</mapper>
\ No newline at end of file
......@@ -10,6 +10,11 @@
<result property="month" column="month"/>
<result property="date" column="date"/>
<result property="weekOfYear" column="week_of_year"/>
<result property="companyName" column="company_name"/>
<result property="extraAmount" column="extra_amount"/>
<result property="lateFeeAmount" column="late_fee_amount"/>
<result property="orderRefundAmount" column="order_refund_amount"/>
<result property="companyName" column="company_name"/>
<result property="totalAmount" column="total_amount"/>
<result property="toalCommonAmmount" column="toal_common_ammount"/>
<result property="totalCommonQuantity" column="total_common_quantity"/>
......
......@@ -3,25 +3,36 @@
<mapper namespace="com.xxfc.platform.order.mapper.OrderReceivedStatisticsMapper">
<!-- 可根据自己的需求,是否要使用 -->
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.xxfc.platform.order.entity.OrderReceivedStatistics" id="orderReceivedStatisticsMap">
<result property="id" column="id"/>
<result property="year" column="year"/>
<result property="month" column="month"/>
<result property="date" column="date"/>
<result property="weekOfYear" column="week_of_year"/>
<result property="breakRulesRegulationAmount" column="break_rules_regulation_amount"/>
<result property="companyName" column="company_name"/>
<result property="depositAmount" column="deposit_amount"/>
<result property="depositRefundAmount" column="deposit_refund_amount"/>
<result property="extraAmount" column="extra_amount"/>
<result property="lateFeeAmount" column="late_fee_amount" />
<result property="lossSpecifiedAmount" column="loss_specified_amount" />
<result property="memberAmount" column="member_amount" />
<result property="travelAmount" column="travel_amount"/>
<result property="rentVehicleAmount" column="rent_vehicle_amount"/>
<result property="noDeductibleAmount" column="no_deductible_amount"/>
<result property="noDeductibleRefundAmount" column="no_deductible_refund_amount"/>
<result property="orderRefundAmount" column="order_refund_amount"/>
<result property="totalAmount" column="total_amount"/>
<result property="totalQuantity" column="total_quantity"/>
<result property="realAmount" column="real_amount"/>
<result property="isFinish" column="is_finish"/>
<result property="orderOrigin" column="order_origin"/>
<result property="payWay" column="pay_way"/>
<result property="companyId" column="company_id"/>
<result property="crtTime" column="crt_time"/>
</resultMap>
<select id="selectOrderReceivedStatisticsList" resultMap="orderReceivedStatisticsMap">
select * from `order_received_statistics` where 1=1
<select id="selectOrderReceivedStatisticsList" resultMap="orderReceivedStatisticsMap">
select * from `order_received_statistics` where 1=1
<if test="orderState!=null">
and `is_finish`=#{orderState}
</if>
......@@ -47,4 +58,230 @@
</if>
</select>
<!--按日统计-->
<select id="selectCompanyPerformanceWithDay" resultType="com.xxfc.platform.order.bo.CompanyPerformanceBo">
SELECT
ors.*,
IFNULL(ovss.departureNum,0),
IFNULL(ovss.rentDays,0),
IFNULL(ovss.arrivalNum,0)
FROM
(
SELECT
`company_id` AS `companyId`,
`year`,
`date`,
SUM(`member_amount` ) AS `memberAmount`,
SUM(`travel_amount` ) AS `travelAmount`,
SUM(`rent_vehicle_amount` ) AS `rentVehilceAmount`
FROM
`order_received_statistics`
WHERE 1=1
<if test="companyName!=null and companyName!=''">
AND `company_name` LIKE CONCAT('%',#{companyName},'%')
</if>
<if test="startDate!=null and endDate!=null">
AND `date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`date` <= #{startDate}
]]>
</if>
GROUP BY
`company_id` ,
`year`,
`date`
) AS `ors`
LEFT JOIN (
SELECT
`company_id` AS `cyid`,
`count_date`,
IFNULL(SUM( `departure_num` ),0) AS `departureNum`,
IFNULL(SUM( `arrival_num` ),0) AS `arrivalNum`,
IFNULL(SUM( `rent_num` ),0) AS `rentDays`
FROM
`order_vehicle_service_statistics`
WHERE 1=1
<if test="startDate!=null and endDate!=null">
AND `count_date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`count_date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`count_date` <= #{startDate}
]]>
</if>
GROUP BY
`company_id`,
`count_year`,
`count_date`
) AS `ovss` ON ovss.cyid = ors.companyId
AND ovss.count_date = ors.date
</select>
<!--按月统计-->
<select id="selectCompanyPerformanceWithMonth"
resultType="com.xxfc.platform.order.bo.CompanyPerformanceBo">
SELECT
ors.*,
IFNULL(ovss.departureNum,0),
IFNULL(ovss.rentDays,0),
IFNULL(ovss.arrivalNum,0)
FROM
(
SELECT
company_id AS `companyId`,
`year`,
`month`,
COALESCE(SUM(`member_amount` ),0) AS `memberAmount`,
COALESCE(SUM(`travel_amount` ),0) AS `travelAmount`,
COALESCE(SUM(`rent_vehicle_amount` ),0) AS `rentVehilceAmount`
FROM
`order_received_statistics`
WHERE 1=1
<if test="companyName!=null and companyName!=''">
AND `company_name` LIKE CONCAT('%',#{companyName},'%')
</if>
<if test="startDate!=null and endDate!=null">
AND `date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`date` <= #{startDate}
]]>
</if>
GROUP BY
company_id,
`year`,
`month`
) AS `ors`
LEFT JOIN (
SELECT
`company_id` AS `cyid`,
`count_month`,
COALESCE(SUM( `departure_num` ),0) AS `departureNum`,
COALESCE(SUM( `arrival_num` ),0) AS `arrivalNum`,
COALESCE(SUM( `rent_num` ),0) AS `rentDays`
FROM
`order_vehicle_service_statistics`
WHERE 1=1
<if test="startDate!=null and endDate!=null">
AND `count_date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`count_date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`count_date` <= #{startDate}
]]>
</if>
GROUP BY
`company_id`,
`count_year`,
`count_month`
) AS `ovss` ON ovss.cyid = ors.companyId
AND ovss.count_month = ors.month
</select>
<!--按周统计-->
<select id="selectCompanyPerformanceWithWeek" resultType="com.xxfc.platform.order.bo.CompanyPerformanceBo">
SELECT
ors.*,
IFNULL(ovss.departureNum,0),
IFNULL(ovss.rentDays,0),
IFNULL(ovss.arrivalNum,0)
FROM
(
SELECT
company_id AS `companyId`,
`year`,
`week_of_year` AS `weekOfYear`,
COALESCE(SUM(`member_amount` ),0) AS `memberAmount`,
COALESCE(SUM(`travel_amount` ),0) AS `travelAmount`,
COALESCE(SUM(`rent_vehicle_amount` ),0) AS `rentVehilceAmount`
FROM
`order_received_statistics`
WHERE 1=1
<if test="companyName!=null and companyName!=''">
AND `company_name` LIKE CONCAT('%',#{companyName},'%')
</if>
<if test="startDate!=null and endDate!=null">
AND `date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`date` <= #{startDate}
]]>
</if>
GROUP BY
company_id,
`year`,
`week_of_year`
) AS `ors`
LEFT JOIN (
SELECT
`company_id` AS `cyid`,
`count_week`,
IFNULL(SUM( `departure_num` ),0) AS `departureNum`,
IFNULL(SUM( `arrival_num` ),0) AS `arrivalNum`,
IFNULL(SUM( `rent_num` ),0) AS `rentDays`
FROM
`order_vehicle_service_statistics`
WHERE 1=1
<if test="startDate!=null and endDate!=null">
AND `count_date` BETWEEN #{startDate} AND #{endDate}
</if>
<if test="startDate!=null and endDate==null">
AND <![CDATA[
`count_date` >= #{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
AND <![CDATA[
`count_date` <= #{startDate}
]]>
</if>
GROUP BY
`company_id`,
`count_year`,
`count_week`
) AS `ovss` ON ovss.cyid = ors.companyId
AND ovss.count_week = ors.weekOfYear
</select>
</mapper>
\ No newline at end of file
......@@ -10,6 +10,10 @@
<result property="month" column="month"/>
<result property="date" column="date"/>
<result property="weekOfYear" column="week_of_year"/>
<result property="companyName" column="company_name"/>
<result property="extraAmount" column="extra_amount"/>
<result property="lateFeeAmount" column="late_fee_amount"/>
<result property="orderRefundAmount" column="order_refund_amount"/>
<result property="totalAmount" column="total_amount"/>
<result property="totalQuantity" column="total_quantity"/>
<result property="hasPay" column="has_pay"/>
......
......@@ -5,6 +5,7 @@ import com.xxfc.platform.order.biz.OrderMemberReceivedStatisticsBiz;
import com.xxfc.platform.order.biz.OrderRentVehicleReceivedStatisticsBiz;
import com.xxfc.platform.order.jobhandler.BaseOrderStatisticsJobHandler;
import com.xxfc.platform.order.jobhandler.OrderReceivedStatisticsJobHandler;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.SneakyThrows;
import org.joda.time.DateTime;
import org.junit.Test;
......@@ -16,6 +17,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
/**
* @author libin
......@@ -41,7 +43,8 @@ public class ServiceTest {
@Autowired
private OrderReceivedStatisticsJobHandler orderReceivedStatisticsJobHandler;
@Autowired
private VehicleFeign vehicleFeign;
@Test
public void testSchedu(){
......@@ -51,24 +54,26 @@ public class ServiceTest {
@Test
public void testMemberStatisticsInsert(){
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
Date date = cn.hutool.core.date.DateTime.of("2019-11-15", "yyyy-MM-dd").toJdkDate();
Date startDate = DateUtil.beginOfDay(date).toJdkDate();
Date endDate = DateUtil.endOfDay(date).toJdkDate();
orderMemberReceivedStatisticsBiz.orderMemberReceivedStatistics(startDate,endDate);
orderMemberReceivedStatisticsBiz.orderMemberReceivedStatistics(startDate,endDate,companyMap);
}
@Test
public void testRentvehicleStatistics(){
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
Date date = cn.hutool.core.date.DateTime.of("2019-11-15", "yyyy-MM-dd").toJdkDate();
Date startDate = DateUtil.beginOfDay(date).toJdkDate();
Date endDate = DateUtil.endOfDay(date).toJdkDate();
orderRentVehicleReceivedStatisticsBiz.orderRentVehicleReceivedStatistics(startDate,endDate);
orderRentVehicleReceivedStatisticsBiz.orderRentVehicleReceivedStatistics(startDate,endDate,companyMap);
}
@Test
@SneakyThrows
public void testReceivedStatistics(){
orderReceivedStatisticsJobHandler.execute("");
orderReceivedStatisticsJobHandler.execute("2019-11-21");
}
......
......@@ -177,4 +177,6 @@ public interface VehicleFeign {
@GetMapping(value = "/bookRecord/get")
public ObjectRestResponse<List<BookRecordUpdateLog>> get(@RequestParam(value = "bookRecordId")Long bookRecordId);
@GetMapping("/branchCompany/company_info")
Map<Integer, String> findCompanyMap();
}
......@@ -432,4 +432,13 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
return ObjectRestResponse.succ();
}
public Map<Integer, String> selectCompanyMap() {
Example example = new Example(BranchCompany.class);
example.createCriteria().andEqualTo("isDel", 0);
List<BranchCompany> branchCompanies = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(branchCompanies)){
return Collections.EMPTY_MAP;
}
return branchCompanies.stream().collect(Collectors.toMap(BranchCompany::getId,BranchCompany::getName));
}
}
......@@ -227,4 +227,9 @@ public class BranchCompanyController extends BaseController<BranchCompanyBiz> {
return RestResponse.suc(baseBiz.getCompanyIds(dataZone,dataCompany));
}
@GetMapping("/company_info")
public Map<Integer, String> findCompanyMap(){
return baseBiz.selectCompanyMap();
}
}
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