Commit e05de2b1 authored by 周健威's avatar 周健威

修改代码

parent 6c618efb
...@@ -4,8 +4,8 @@ import java.util.HashMap; ...@@ -4,8 +4,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public enum RefundTypeEnum { public enum RefundTypeEnum {
RentVehicle(1, "订单款"), ORDER_FUND(1, "订单款"),
TOUR(2, "押金"), DEPOSIT(2, "押金"),
; ;
/** /**
* 编码 * 编码
......
...@@ -5,6 +5,7 @@ import javax.persistence.Column; ...@@ -5,6 +5,7 @@ import javax.persistence.Column;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
@Data @Data
...@@ -19,7 +20,7 @@ public class OrderViolation { ...@@ -19,7 +20,7 @@ public class OrderViolation {
* 违章总金额 * 违章总金额
*/ */
@Column(name="price") @Column(name="price")
private Double price; private BigDecimal price;
/** /**
......
...@@ -326,7 +326,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> { ...@@ -326,7 +326,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
//退款金额 //退款金额
BigDecimal refundAmount = depositAmount.add(refundGoodsAmount); BigDecimal refundAmount = depositAmount.add(refundGoodsAmount);
//退款子流程: 订单基础,退款描述,退款金额 //退款子流程: 订单基础,退款描述,退款金额
refundSubProcess(baseOrder, refundDesc, refundAmount, RefundTypeEnum.RentVehicle.getCode(), RefundStatusEnum.ALL.getCode()); refundSubProcess(baseOrder, refundDesc, refundAmount, RefundTypeEnum.ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode());
} }
public BigDecimal calculateRefund(BigDecimal goodsAmount, Long timeLag, String dicParentKey, String refundDesc) { public BigDecimal calculateRefund(BigDecimal goodsAmount, Long timeLag, String dicParentKey, String refundDesc) {
...@@ -412,7 +412,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> { ...@@ -412,7 +412,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
setOrderId(orderId); setOrderId(orderId);
setRefundTime(System.currentTimeMillis()); setRefundTime(System.currentTimeMillis());
setTradeNo(refundTradeNo); setTradeNo(refundTradeNo);
setRefundType(RefundTypeEnum.RentVehicle.getCode()); setRefundType(RefundTypeEnum.ORDER_FUND.getCode());
}}; }};
orderRefund.setRefundAmount(refundAmount); orderRefund.setRefundAmount(refundAmount);
orderRefund.setRefundDesc(refundDesc); orderRefund.setRefundDesc(refundDesc);
...@@ -523,6 +523,18 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> { ...@@ -523,6 +523,18 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
* @return * @return
*/ */
public BaseOrder updateSelectiveByIdReT(BaseOrder baseOrder) { public BaseOrder updateSelectiveByIdReT(BaseOrder baseOrder) {
return updateSelectiveByIdReT(baseOrder, false);
}
/**
* 更新(不成功抛异常)
* @param baseOrder
* @return
*/
public BaseOrder updateSelectiveByIdReT(BaseOrder baseOrder, boolean needVersion) {
if(needVersion) {
baseOrder.setVersion(selectById(baseOrder.getId()).getVersion());
}
if(updateSelectiveByIdRe(baseOrder) > 0) { if(updateSelectiveByIdRe(baseOrder) > 0) {
return selectById(baseOrder.getId()); return selectById(baseOrder.getId());
}else { }else {
...@@ -530,6 +542,19 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> { ...@@ -530,6 +542,19 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
} }
} }
// /**
// * 更新(不成功抛异常)
// * @param baseOrder
// * @return
// */
// public BaseOrder updateSelectiveByIdReT(BaseOrder baseOrder) {
// if(updateSelectiveByIdRe(baseOrder) > 0) {
// return selectById(baseOrder.getId());
// }else {
// throw new BaseException(ResultCode.DB_OPERATION_FAIL_CODE);
// }
// }
public boolean getTodyTime(Long time) { public boolean getTodyTime(Long time) {
Long startTime = getDayStart(); Long startTime = getDayStart();
if(time > startTime && time < startTime + 24 * 60 * 60 * 1000 - 1) { if(time > startTime && time < startTime + 24 * 60 * 60 * 1000 - 1) {
......
...@@ -6,6 +6,7 @@ import com.xxfc.platform.order.entity.BaseOrder; ...@@ -6,6 +6,7 @@ import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail; import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
import com.xxfc.platform.order.entity.OrderVehicleCrosstown; import com.xxfc.platform.order.entity.OrderVehicleCrosstown;
import com.xxfc.platform.order.pojo.DedDetailDTO; import com.xxfc.platform.order.pojo.DedDetailDTO;
import com.xxfc.platform.order.pojo.mq.OrderMQDTO;
import com.xxfc.platform.universal.constant.DictionaryKey; import com.xxfc.platform.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.entity.Dictionary; import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign; import com.xxfc.platform.universal.feign.ThirdFeign;
...@@ -15,8 +16,6 @@ import org.springframework.stereotype.Service; ...@@ -15,8 +16,6 @@ import org.springframework.stereotype.Service;
import com.xxfc.platform.order.entity.OrderRefund; import com.xxfc.platform.order.entity.OrderRefund;
import com.xxfc.platform.order.mapper.OrderRefundMapper; import com.xxfc.platform.order.mapper.OrderRefundMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
...@@ -45,39 +44,35 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> { ...@@ -45,39 +44,35 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
@Autowired @Autowired
OrderVehicalCrosstownBiz crosstownBiz; OrderVehicalCrosstownBiz crosstownBiz;
public void refundDeposit(){ public void refundDeposit(OrderMQDTO orderMQDTO){
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData(); Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
BigDecimal illegalReserve = new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ILLEGAL_RESERVE).getDetail()); BigDecimal illegalReserve = new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ILLEGAL_RESERVE).getDetail());
List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class) //未退还, 进行保留违章预备金 的退还
//订单已完成的租车订单 if(RefundStatusEnum.NONE.getCode().equals(orderMQDTO.getRefundStatus())) {
.where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE) OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{
.andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH) setOrderId(orderMQDTO.getId());
// .andLike(BaseOrder::getId, "%"+ String.valueOf(i)) setType(CrosstownTypeEnum.TOUR.getCode());
).build());
//处理自动退押金
for(BaseOrder baseOrder : lists) {
OrderRentVehicleDetail orvd = orderRentVehicleBiz.selectOne(new OrderRentVehicleDetail() {{
setOrderId(baseOrder.getId());
}}); }});
//未退还, 进行保留违章预备金 的退还 //还车扣除款 剩余的 钱,再减去违章预备金
if(RefundStatusEnum.NONE.getCode().equals(baseOrder.getRefundStatus())) { BigDecimal refundAmont = crosstown.getRestDeposit().subtract(illegalReserve);
OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{ List<DedDetailDTO> dddList = JSONUtil.toBean(crosstown.getDedDetail(), List.class);
setOrderId(baseOrder.getId()); String refundDesc = "退还押金:"+ refundAmont.toString()+ "(已扣除 违章预备金:"+ illegalReserve.toString();
setType(CrosstownTypeEnum.TOUR.getCode()); for(DedDetailDTO ddd : dddList) {
}}); refundDesc += ", "+ ddd.getDeductions()+ ":"+ ddd.getCost();
BigDecimal refundAmont = crosstown.getRestDeposit().subtract(illegalReserve);
List<DedDetailDTO> dddList = JSONUtil.toBean(crosstown.getDedDetail(), List.class);
String refundDesc = "退还押金:"+ refundAmont.toString()+ "(已扣除 违章预备金:"+ illegalReserve.toString();
for(DedDetailDTO ddd : dddList) {
refundDesc += ", "+ ddd.getDeductions()+ ":"+ ddd.getCost();
}
refundDesc += ")";
//退款子流程: 订单基础,退款描述,退款金额
baseOrderBiz.refundSubProcess(baseOrder, refundDesc, refundAmont, RefundTypeEnum.RentVehicle.getCode(), RefundStatusEnum.RESIDUE_ILLEGAL.getCode());
//设置剩余
} }
refundDesc += ")";
refundTrigger(orderMQDTO, orderMQDTO.getOrderRentVehicleDetail(), illegalReserve, refundAmont, refundDesc, RefundStatusEnum.RESIDUE_ILLEGAL.getCode());
} }
} }
public void refundTrigger(BaseOrder baseOrder, OrderRentVehicleDetail orvd, BigDecimal residueAmount, BigDecimal refundAmont, String refundDesc, Integer refundStatus) {
//退款子流程: 订单基础,退款描述,退款金额
baseOrderBiz.refundSubProcess(baseOrder, refundDesc, refundAmont, RefundTypeEnum.DEPOSIT.getCode(), refundStatus);
//设置剩余没有返还的钱
orderRentVehicleBiz.updateSelectiveById(new OrderRentVehicleDetail(){{
setId(orvd.getId());
setReturnPayResidue(residueAmount);
}});
}
} }
\ No newline at end of file
...@@ -2,13 +2,12 @@ package com.xxfc.platform.order.jobhandler; ...@@ -2,13 +2,12 @@ package com.xxfc.platform.order.jobhandler;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.util.IntervalUtil; import com.github.wxiaoqi.security.common.util.IntervalUtil;
import com.xxfc.platform.order.biz.BaseOrderBiz; import com.xxfc.platform.order.biz.*;
import com.xxfc.platform.order.biz.OrderRentVehicleBiz;
import com.xxfc.platform.order.biz.OrderVehicalCrosstownBiz;
import com.xxfc.platform.order.contant.enumerate.*; import com.xxfc.platform.order.contant.enumerate.*;
import com.xxfc.platform.order.entity.BaseOrder; import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail; import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
import com.xxfc.platform.order.entity.OrderVehicleCrosstown; import com.xxfc.platform.order.entity.OrderVehicleCrosstown;
import com.xxfc.platform.order.entity.OrderViolation;
import com.xxfc.platform.order.pojo.DedDetailDTO; import com.xxfc.platform.order.pojo.DedDetailDTO;
import com.xxfc.platform.universal.constant.DictionaryKey; import com.xxfc.platform.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.entity.Dictionary; import com.xxfc.platform.universal.entity.Dictionary;
...@@ -27,6 +26,7 @@ import java.math.BigDecimal; ...@@ -27,6 +26,7 @@ import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER; import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER;
/** /**
...@@ -37,7 +37,7 @@ import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER; ...@@ -37,7 +37,7 @@ import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER;
@JobHandler(value = "rentDepositHandler") @JobHandler(value = "rentDepositHandler")
@Component @Component
@Slf4j @Slf4j
public class RentDepositHandler extends IJobHandler { public class RentDepositJobHandler extends IJobHandler {
@Autowired @Autowired
BaseOrderBiz baseOrderBiz; BaseOrderBiz baseOrderBiz;
...@@ -48,50 +48,51 @@ public class RentDepositHandler extends IJobHandler { ...@@ -48,50 +48,51 @@ public class RentDepositHandler extends IJobHandler {
@Autowired @Autowired
OrderVehicalCrosstownBiz crosstownBiz; OrderVehicalCrosstownBiz crosstownBiz;
@Autowired
OrderViolationBiz orderViolationBiz;
@Autowired
OrderRefundBiz orderRefundBiz;
@Autowired @Autowired
ThirdFeign thirdFeign; ThirdFeign thirdFeign;
@Override @Override
public ReturnT<String> execute(String idLastNumInterval) throws Exception { public ReturnT<String> execute(String idLastNumInterval) throws Exception {
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData(); Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
BigDecimal illegalReserve = new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ILLEGAL_RESERVE).getDetail()); Integer rentDepositAutoRefundTime = new Integer(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.RENT_DEPOSIT_AUTO_REFUND_TIME).getDetail());
try { try {
for(int i = 0; i < 10; i++) { for(int i = 0; i < 10; i++) {
if(IntervalUtil.staticIsInTheInterval(String.valueOf(i), idLastNumInterval)) { if(IntervalUtil.staticIsInTheInterval(String.valueOf(i), idLastNumInterval)) {
//三十天
List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class) List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class)
//订单已完成的租车订单 //订单已完成的租车订单
.where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE) .where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE)
.andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH) .andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH) //已完成的订单
.andLike(BaseOrder::getId, "%"+ String.valueOf(i))).build()); .andEqualTo(BaseOrder::getRefundStatus, RefundStatusEnum.RESIDUE_ILLEGAL) //已归还了部分押金
.andLessThanOrEqualTo(BaseOrder::getRefundTime, System.currentTimeMillis() - (rentDepositAutoRefundTime * 60 * 60 * 1000))
.andLike(BaseOrder::getId, "%"+ i)).build());
//处理自动退押金 //处理自动退剩余押金
for(BaseOrder baseOrder : lists) { for(BaseOrder baseOrder : lists) {
OrderRentVehicleDetail orvd = orderRentVehicleBiz.selectOne(new OrderRentVehicleDetail() {{ OrderRentVehicleDetail orvd = orderRentVehicleBiz.selectOne(new OrderRentVehicleDetail() {{
setOrderId(baseOrder.getId()); setOrderId(baseOrder.getId());
}}); }});
//未退还, 进行保留违章预备金 的退还
if(RefundStatusEnum.NONE.getCode().equals(baseOrder.getRefundStatus())) { OrderViolation orderViolation = orderViolationBiz.selectOne(new OrderViolation(){{
OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{ setDetailId(orvd.getId());
setOrderId(baseOrder.getId()); setIsDel(SYS_FALSE);
setType(CrosstownTypeEnum.TOUR.getCode()); }});
}});
BigDecimal refundAmont = crosstown.getRestDeposit().subtract(illegalReserve); //还车扣除款 剩余的 钱,再减去违章预备金
List<DedDetailDTO> dddList = JSONUtil.toBean(crosstown.getDedDetail(), List.class); BigDecimal refundAmont = orvd.getReturnPayResidue().subtract(orderViolation.getPrice());
String refundDesc = "退还押金:"+ refundAmont.toString()+ "(已扣除 违章预备金:"+ illegalReserve.toString(); String refundDesc = "退还押金:"+ refundAmont.toString()+ "(已扣除 违章扣款:"+ refundAmont.toString();
for(DedDetailDTO ddd : dddList) { // for(DedDetailDTO ddd : dddList) {
refundDesc += ", "+ ddd.getDeductions()+ ":"+ ddd.getCost(); // refundDesc += ", "+ ddd.getDeductions()+ ":"+ ddd.getCost();
} // }
refundDesc += ")"; refundDesc += ")";
//退款子流程: 订单基础,退款描述,退款金额 orderRefundBiz.refundTrigger(baseOrder, orvd, refundAmont, refundAmont, refundDesc, RefundStatusEnum.REFUND_DEPOSIT.getCode());
baseOrderBiz.refundSubProcess(baseOrder, refundDesc, refundAmont, RefundTypeEnum.RentVehicle.getCode(), RefundStatusEnum.RESIDUE_ILLEGAL.getCode());
//设置剩余
}else if(RefundStatusEnum.RESIDUE_ILLEGAL.getCode().equals(baseOrder.getRefundStatus())){
//判断是否违章
//扣违章的钱
//baseOrderBiz.refundSubProcess(baseOrder, refundDesc, refundAmont, RefundTypeEnum.RENT_VEHICLE.getCode(), RefundStatusEnum.RESIDUE_ILLEGAL.getCode());
}
// baseOrderBiz.refundSubProcess(baseOrder, refundDesc, refundAmont);
} }
} }
......
package com.xxfc.platform.order.mqhandler;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.admin.dto.OrderGoodsDTO;
import com.github.wxiaoqi.security.admin.dto.OrderWaterDTO;
import com.rabbitmq.client.Channel;
import com.xxfc.platform.order.biz.OrderRefundBiz;
import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum;
import com.xxfc.platform.order.pojo.mq.OrderMQDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static com.xxfc.platform.order.config.RabbitOrderConfig.ORDER_DEPOSIT_REFUND_QUEUE;
import static com.xxfc.platform.order.pojo.mq.OrderMQDTO.*;
@Component
@Slf4j
public class RefundMQHandler {
@Autowired
OrderRefundBiz orderRefundBiz;
/**
* 佣金
* @param
*/
@RabbitListener(queues = ORDER_DEPOSIT_REFUND_QUEUE)
public void integralHandler(Message message, @Headers Map<String, Object> headers, Channel channel) {
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.execute(new Runnable() {
@Override
public void run() {
try {
String messageId = message.getMessageProperties().getMessageId();
String msg = new String(message.getBody(), "UTF-8");
OrderMQDTO orderMQDTO = JSONUtil.toBean(msg, OrderMQDTO.class);
orderRefundBiz.refundDeposit(orderMQDTO);
executorService.shutdown();
Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
// 手动签收
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
log.info("接收到的消息失败");
try {
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
} catch (IOException i) {
i.printStackTrace();
}
e.printStackTrace();
}
}
});
}
}
...@@ -42,4 +42,9 @@ public class DictionaryKey { ...@@ -42,4 +42,9 @@ public class DictionaryKey {
* 支付价格减低 * 支付价格减低
*/ */
public static final String PAY_DEMOTION = "PAY_DEMOTION"; public static final String PAY_DEMOTION = "PAY_DEMOTION";
/**
* 自动退款保留押金的时间(小时)
*/
public static final String RENT_DEPOSIT_AUTO_REFUND_TIME = "RENT_DEPOSIT_AUTO_REFUND_TIME";
} }
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