Commit 85a95ae2 authored by hanfeng's avatar hanfeng

修改订单统计

parent a78e721d
package com.xxfc.platform.order.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat;
import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.code.IdentityDialect;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
/**
* 每日租车订单
* 每日租车订单统计
* @author Administrator
*/
@Data
@Table(name = "daily_vehicle_order_statistics")
public class DailyVehicleOrderStatistics {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
/**
* 日期
*/
@Column(name = "on_day")
@Column(name = "one_day")
private String oneDay;
/**
......@@ -61,5 +74,13 @@ public class DailyVehicleOrderStatistics {
*/
@Column(name = "postpone")
private BigDecimal postpone;
/**
* 创建时间
*/
@Column(name = "crt_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date crtTime;
}
......@@ -52,7 +52,7 @@ import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TR
import static com.xxfc.platform.universal.constant.DictionaryKey.*;
/**
*
*
*
* @author zjw
* @email nishijjo@qq.com
......@@ -377,17 +377,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
}
}
// @Scheduled(cron = "0 0/2 * * * ? ")
public boolean getTotalOrder() {
//获取车辆成交总额和预付押金总额
Map<String, BigDecimal> map = mapper.getTotalOrder();
return false;
}
// @Scheduled(cron = "0 0 2 * * ? ")
// private void countDailyOrdersRegularly(){
// DailyOrderStatistics dailyOrderStatistics= mapper.getTotalOrder();
// }
}
\ No newline at end of file
package com.xxfc.platform.order.biz;
import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.order.entity.DailyVehicleOrderStatistics;
import com.xxfc.platform.order.mapper.DailyVehicleOrderStatisticsMapper;
import com.xxfc.platform.order.pojo.DedDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class DailyVehicleOrderStatisticsBiz extends BaseBiz<DailyVehicleOrderStatisticsMapper, DailyVehicleOrderStatistics> {
private final Integer TYPE_DEFERRED = 1;
private final Integer TYPE_DAMAGE = 2;
@Transactional(rollbackFor = Exception.class)
public boolean getTotalOrder() {
try {
HashMap<String, Object> resultMap = new HashMap<>();
// 获取每日租车订单成交金和押金总额
Map<String, BigDecimal> gmvAndMarginTotal = mapper.getGmvAndMarginTotal();
resultMap.putAll(gmvAndMarginTotal);
// 获取车辆
BigDecimal penalSum = mapper.getPenalSum();
resultMap.put("penalSum", penalSum);
// 获取订单退还押金总额
BigDecimal refundSecurityDeposit = mapper.getRefundSecurityDeposit();
resultMap.put("refundSecurityDeposit", refundSecurityDeposit);
// 获取违章查询总和
BigDecimal violationMoney = mapper.getViolationMoney();
resultMap.put("violationMoney", violationMoney);
// 获取赔偿和延期JSON字符串
List<String> compensationAndPostpone = mapper.getCompensationAndPostpone();
// 获取赔偿和延期JSON字符串转换为map
Map<String, BigDecimal> cpMap = getCompensationAndPostponeMap(compensationAndPostpone);
resultMap.putAll(cpMap);
DailyVehicleOrderStatistics orderStatistics = new DailyVehicleOrderStatistics();
BeanUtils.copyProperties(orderStatistics,resultMap);
super.insertSelective(orderStatistics);
return true;
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return false;
}
}
/**
* 获取赔偿总额和延期总额
*/
private Map<String, BigDecimal> getCompensationAndPostponeMap(List<String> compensationAndPostpone) {
if (CollectionUtils.isNotEmpty(compensationAndPostpone)) {
List<DedDetailDTO> sumDedDetailDTOs = new ArrayList<>();
for (String value : compensationAndPostpone) {
List<DedDetailDTO> dedDetailDTOS = JSON.parseArray(value, DedDetailDTO.class);
sumDedDetailDTOs.addAll(dedDetailDTOS);
}
// 获取赔偿金额总和
BigDecimal compensation = get(sumDedDetailDTOs, TYPE_DAMAGE);
// 获取延期金额总和
BigDecimal postpone = get(sumDedDetailDTOs, TYPE_DEFERRED);
Map<String, BigDecimal> resultMap = new HashMap<>();
resultMap.put("compensation", compensation);
resultMap.put("postpone", postpone);
return resultMap;
}
return new HashMap<String, BigDecimal>();
}
/**
* 根据type获取对应的金额总和
*
* @param sumDedDetailDTOs
* @param TYPE_DAMAGE
* @return
*/
private BigDecimal get(List<DedDetailDTO> sumDedDetailDTOs, Integer TYPE_DAMAGE) {
if (CollectionUtils.isNotEmpty(sumDedDetailDTOs)) {
BigDecimal aggregateAmount = sumDedDetailDTOs.stream()
.filter(d -> TYPE_DAMAGE.equals(d.getType()))
.map(DedDetailDTO::getCost)
.reduce(BigDecimal.ZERO, BigDecimal::add);
return aggregateAmount;
}
return null;
}
// @Scheduled(cron = "0 0 2 * * ? ")
// private void countDailyOrdersRegularly(){
// DailyOrderStatistics dailyOrderStatistics= mapper.getTotalOrder();
// }
}
package com.xxfc.platform.order.jobhandler;
import com.xxfc.platform.order.biz.BaseOrderBiz;
import com.xxfc.platform.order.biz.DailyVehicleOrderStatisticsBiz;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
......@@ -12,22 +13,23 @@ import org.springframework.stereotype.Component;
/**
* 每天2定时统计前一天的数据
*/
@JobHandler(value = "baseOrderStatistics")
@JobHandler(value = "baseOrderStatisticsHandler")
@Component
@Slf4j
public class BaseOrderStatisticsJobHandler extends IJobHandler {
@Autowired
private BaseOrderBiz baseOrderBiz;
private DailyVehicleOrderStatisticsBiz statisticsBiz;
@Override
public ReturnT<String> execute(String s) throws Exception {
try {
baseOrderBiz.getTotalOrder();
ReturnT returnT = new ReturnT(){{
setCode(100);
setMsg("成功");
}};
XxlJobLogger.log("-----定时器进入---baseOrderStatisticsHandler---");
// log.info("-----定时器进入---baseOrderStatisticsHandler---");
statisticsBiz.getTotalOrder();
ReturnT returnT = new ReturnT();
returnT.setCode(100);
returnT.setMsg("成功");
return returnT;
} catch (Exception e) {
XxlJobLogger.log(e);
......
......@@ -28,5 +28,4 @@ public interface BaseOrderMapper extends Mapper<BaseOrder> {
public OrderPageVO getOrderDetail(String no);
Map<String, BigDecimal> getTotalOrder();
}
package com.xxfc.platform.order.mapper;
import com.xxfc.platform.order.entity.DailyVehicleOrderStatistics;
import tk.mybatis.mapper.common.Mapper;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 每日统计数据
* @author Administrator
*/
public interface DailyVehicleOrderStatisticsMapper extends Mapper<DailyVehicleOrderStatistics> {
Map<String, BigDecimal> getGmvAndMarginTotal();
List<String> getCompensationAndPostpone();
BigDecimal getPenalSum();
BigDecimal getRefundSecurityDeposit();
BigDecimal getViolationMoney();
}
......@@ -219,36 +219,6 @@
where no = #{no}
</select>
<!-- 获取每日租车订单成交金额和押金金额-->
<select id="getTotalOrder" resultType="HashMap">
select
date_format(FROM_UNIXTIME(pay_time/1000),'%Y-%c-%d') as oneDay,
IFNULL(SUM(b.real_amount-v.deposit),0) as gmv,
IFNULL(SUM(v.deposit),0) as marginTotal
from
base_order b
left join
order_rent_vehicle_detail v
on
b.id=v.order_id
where
b.type=1
AND
date(FROM_UNIXTIME(pay_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
<!-- <select id="getTotalOrder" resultType="com.xxfc.platform.order.entity.DailyOrderStatistics">-->
<!-- select-->
<!-- date_format(refund_time,'%Y-%c-%d') as oneDay,-->
<!-- sum(1) as totalOrders,-->
<!-- sum(refund_time)as actualTotalIncome-->
<!-- from-->
<!-- base_order-->
<!-- where-->
<!-- date(refund_time)=date(now())-1-->
<!-- group by-->
<!-- date_format(refund_time,'%d')-->
<!-- </select>-->
</mapper>
\ No newline at end of file
<?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.DailyVehicleOrderStatisticsMapper">
<!-- 获取每日租车订单成交金和押金总额-->
<select id="getGmvAndMarginTotal" resultType="HashMap">
select
COALESCE(date_format(FROM_UNIXTIME(b.pay_time/1000),'%Y-%c-%d'),date(DATE_SUB(now(),interval 1 day))) as oneDay,
IFNULL(SUM(b.real_amount-v.deposit),0) as gmv,
IFNULL(SUM(v.deposit),0) as marginTotal
from
base_order b
left join
order_rent_vehicle_detail v
on
b.id=v.order_id
where
b.type=1
AND
date(FROM_UNIXTIME(b.pay_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
<!-- 退还押金总额-->
<select id="getRefundSecurityDeposit" resultType="BigDecimal">
SELECT
IFNULL(SUM(r.refund_amount),0) as refundSecurityDeposit
FROM
base_order o
left join
order_refund r
on
o.id=r.order_id
WHERE
o.type=1
and
r.refund_status=1
and
r.refund_type >1
and
date(FROM_UNIXTIME(r.refund_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
<!-- 取消订单扣除款项总和-->
<select id="getPenalSum" resultType="BigDecimal">
SELECT
IFNULL(SUM(r.deduct_amount),0) as penalSum
FROM
base_order o
left join
order_refund r
on
o.id=r.order_id
WHERE
o.type=1
and
r.refund_status=1
and
r.refund_type =1
and
date(FROM_UNIXTIME(r.refund_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
<!-- 获取赔偿和延期JSON字符串-->
<select id="getCompensationAndPostpone" resultType="List">
SELECT
ded_detail
FROM
order_refund r
LEFT JOIN
order_vehicle_crosstown c
on
r.order_id = c.order_id
WHERE
r.refund_status=1
and
r.refund_type = 3
and
c.type=2
and
date(FROM_UNIXTIME(refund_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
<select id="getViolationMoney" resultType="BigDecimal">
SELECT
v.price
FROM
order_refund r
left JOIN
base_order o
on
o.id=r.order_id
LEFT JOIN
order_rent_vehicle_detail d
on
o.id = d.order_id
left join
order_violation v
on
d.id = v.detail_id
WHERE
r.refund_status=1
and
r.refund_type = 4
and
date(FROM_UNIXTIME(r.refund_time/1000))=date(DATE_SUB(now(),interval 1 day))
</select>
</mapper>
\ No newline at end of file
......@@ -206,7 +206,7 @@ public class TrafficViolationsService {
* 定时修改车牌类型
* @throws SQLException
*/
@Scheduled(cron = "0 0 0 0/7 * ?")
// @Scheduled(cron = "0 0 0 0/7 * ?")
private void updateLicensePlateType() throws SQLException {
List<LicensePlateType> licensePlateTypes = licensePlateTypeBiz.selectListAll();
licensePlateTypeBiz.updateLicensePlateType(licensePlateTypes);
......
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