Commit e2d3ef39 authored by jiaorz's avatar jiaorz

车辆服务次数统计

parent 91842fdc
......@@ -5,6 +5,7 @@ import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
@Table(name = "order_vehicle_service_statistics")
......@@ -45,4 +46,10 @@ public class OrderVehicleServiceStatistics {
*/
@Column(name = "rent_num")
private Integer rentNum;
/**
* 时间字符串,用户查询
*/
@Transient
private String dateStr;
}
\ No newline at end of file
......@@ -62,7 +62,6 @@ import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.*;
......@@ -811,4 +810,8 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements
return CollectionUtils.isEmpty(orderDTOS)?Collections.EMPTY_LIST:orderDTOS;
}
public List<OrderPageVO> selectAllRentVehicleOrder(Map<String, Object> paramMap) {
return mapper.selectAllRentVehicleOrder(paramMap);
}
}
\ No newline at end of file
......@@ -4,10 +4,18 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.order.Utils.OrderDateUtils;
import com.xxfc.platform.order.biz.inner.OrderCalculateBiz;
import com.xxfc.platform.order.contant.enumerate.CrosstownTypeEnum;
import com.xxfc.platform.order.contant.enumerate.OrderStatusEnum;
import com.xxfc.platform.order.entity.OrderVehicleServiceStatistics;
import com.xxfc.platform.order.mapper.OrderVehicleServiceStatisticsMapper;
import com.xxfc.platform.order.pojo.CountVehicleServiceNumVo;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import com.xxfc.platform.order.pojo.order.OrderVehicleCrosstownDto;
import com.xxfc.platform.universal.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -23,12 +31,66 @@ public class OrderVehicleServiceStatisticsBiz extends BaseBiz<OrderVehicleServic
@Autowired
BaseOrderBiz baseOrderBiz;
@Autowired
OrderVehicleCrosstownBiz orderVehicleCrosstownBiz;
@Autowired
OrderCalculateBiz orderCalculateBiz;
Map<Integer, Map<String, Integer>> mapMap = new HashMap<>();
//获取订单,解析租车天数
//
public void getAllOrder() {
//根据订单状态,待出行的添加一天,出行中的加一天,已完成的判断订单时间和实际结束时间如果实际结束天数大于订单天数,则需要加一天
public void getAllOrder(DateTime dateTime) {
Date nowTime = DateTime.now().minusDays(1).toDate();
if (dateTime != null) {
nowTime = dateTime.minusDays(1).toDate();
}
String timeStr = DateUtil.dateToStr(nowTime, "yyyy-MM-dd");
//以公司ID为key, 日期+次数为value组成map
Map<String, Object> param = new HashMap<>();
param.put("startTime", OrderDateUtils.getStartOfDay(nowTime));
param.put("endTime", OrderDateUtils.getEndOfDay(nowTime));
param.put("status", 1);
List<OrderPageVO> orderPageVOS = baseOrderBiz.selectAllRentVehicleOrder(param);
if (orderPageVOS != null && orderPageVOS.size() > 0) {
orderPageVOS.parallelStream().forEach(result -> {
if (result.getOrderRentVehicleDetail() != null) {
Map<String, Integer> dateNumMap = mapMap.getOrDefault(result.getOrderRentVehicleDetail().getStartCompanyId(), new HashMap<>());
if (result.getStatus() == OrderStatusEnum.ORDER_TOSTART.getCode() || result.getStatus() == OrderStatusEnum.ORDER_WAIT.getCode()) {//待出行或者出行中
dateNumMap.put(timeStr, dateNumMap.getOrDefault(timeStr, 0) + 1);
}
if (result.getStatus() == OrderStatusEnum.ORDER_TOSTART.getCode() || result.getStatus() == OrderStatusEnum.ORDER_FIXED_LOSS.getCode()) {//已完成或者定损中
//判断租车时间是否小于实际用车时间
//实际预定天数
Integer bookDays = result.getOrderRentVehicleDetail().getDayNum();
//实际使用天数
Integer actualUsedDays = result.getOrderRentVehicleDetail().getUsedDay();
Long startTime = result.getOrderRentVehicleDetail().getStartTime();
if (actualUsedDays == null) {//字段为空,重新计算天数
//查询还车时间
OrderVehicleCrosstownDto orderVehicleCrosstownDto = new OrderVehicleCrosstownDto();
orderVehicleCrosstownDto.setOrderId(result.getId());
List<OrderVehicleCrosstownDto> list = orderVehicleCrosstownBiz.selectByOrderId(orderVehicleCrosstownDto);
if(list != null && list.size() > 0) {
list.parallelStream().forEach(order -> {
//获取还车时间
if (order.getType() == CrosstownTypeEnum.ARRIVE.getCode() || order.getType() == CrosstownTypeEnum.FIXED_LOSS.getCode() || order.getType() == CrosstownTypeEnum.FIXED_LOSS_NOW.getCode()) {
Long endTime = order.getCrtTime();
int userUsedDay = orderCalculateBiz.getIncludeDays(startTime, endTime);
if (bookDays < userUsedDay) { //实际使用天数>预定天数,还车当天+1
dateNumMap.put(timeStr, dateNumMap.getOrDefault(timeStr, 0) + 1);
}
}
});
} else { //还车记录不存在,异常数据
log.info("还车记录不存在,异常数据, {}", result.toString());
}
}
}
mapMap.put(result.getOrderRentVehicleDetail().getStartCompanyId(), dateNumMap);
}
});
}
log.info("统计数据,Map = {}", mapMap);
}
......@@ -58,9 +120,12 @@ public class OrderVehicleServiceStatisticsBiz extends BaseBiz<OrderVehicleServic
public void add(OrderVehicleServiceStatistics orderVehicleServiceStatistics) {
if(orderVehicleServiceStatistics != null) {
OrderVehicleServiceStatistics oldValue = mapper.selectOne(orderVehicleServiceStatistics);
OrderVehicleServiceStatistics oldValue = mapper.selectByCompanyIdAndDate(orderVehicleServiceStatistics);
if (oldValue == null) {
insertSelectiveRe(orderVehicleServiceStatistics);
} else {
BeanUtil.copyProperties(orderVehicleServiceStatistics, oldValue, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
updateSelectiveByIdRe(oldValue);
}
}
}
......@@ -70,6 +135,27 @@ public class OrderVehicleServiceStatisticsBiz extends BaseBiz<OrderVehicleServic
DateTime dateTime = DateTime.parse("2019-08-01");
for(DateTime curDate = dateTime.plusDays(1); curDate.compareTo(DateTime.now()) < 0; curDate = curDate.plusDays(1)) {
countVehicleServiceNum(curDate);
getAllOrder(curDate);
}
if (MapUtils.isNotEmpty(mapMap)) {
for (Map.Entry<Integer, Map<String, Integer>> entry : mapMap.entrySet()) {
if (MapUtils.isNotEmpty(entry.getValue())) {
OrderVehicleServiceStatistics orderVehicleServiceStatistics = new OrderVehicleServiceStatistics();
orderVehicleServiceStatistics.setCompanyId(entry.getKey());
for (Map.Entry<String, Integer> values : entry.getValue().entrySet()) {
if (StringUtils.isNotBlank(values.getKey()) && StringUtils.isNotBlank(values.getValue() + "")) {
DateTime dateTime1 = DateTime.parse(values.getKey());
orderVehicleServiceStatistics.setCountDate(dateTime1.toDate());
orderVehicleServiceStatistics.setRentNum(values.getValue());
orderVehicleServiceStatistics.setCountYear(dateTime1.getYear() + "");
orderVehicleServiceStatistics.setCountMonth(dateTime1.getYear() + "" + dateTime1.getMonthOfYear() + "");
orderVehicleServiceStatistics.setCountWeek(dateTime1.getYear() + "" + dateTime1.getWeekOfWeekyear() + "");
add(orderVehicleServiceStatistics);
}
}
}
}
}
}
}
......@@ -12,4 +12,6 @@ import java.util.Map;
*/
public interface OrderVehicleServiceStatisticsMapper extends Mapper<OrderVehicleServiceStatistics> {
List<CountVehicleServiceNumVo> countVehicleServiceNum(Map<String, Object> param);
OrderVehicleServiceStatistics selectByCompanyIdAndDate(OrderVehicleServiceStatistics orderVehicleServiceStatistics);
}
\ No newline at end of file
......@@ -271,12 +271,12 @@
select b.*
from base_order b
LEFT JOIN order_rent_vehicle_detail r on r.order_id = b.id
where b.type = 2 and b.status &gt;= 4
where b.type = 1 and b.status &gt;= 4
<if test="startTime != null and status == 1">
and r.start_time between #{startTime} and #{endTime}
</if>
<if test="startTime != null and status == 2">
and r.start_time between #{startTime} and #{endTime}
and r.end_time between #{startTime} and #{endTime}
</if>
</select>
......
......@@ -23,4 +23,8 @@
) tmp2 on tmp1.companyId = tmp2.companyId
</select>
<select id="selectByCompanyIdAndDate" resultType="com.xxfc.platform.order.entity.OrderVehicleServiceStatistics" parameterType="com.xxfc.platform.order.entity.OrderVehicleServiceStatistics">
select * from order_vehicle_service_statistics where company_id = #{companyId} and count_date = #{countDate}
</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