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

修改代码

parent 6c618efb
......@@ -4,8 +4,8 @@ import java.util.HashMap;
import java.util.Map;
public enum RefundTypeEnum {
RentVehicle(1, "订单款"),
TOUR(2, "押金"),
ORDER_FUND(1, "订单款"),
DEPOSIT(2, "押金"),
;
/**
* 编码
......
......@@ -5,6 +5,7 @@ import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.math.BigInteger;
@Data
......@@ -19,7 +20,7 @@ public class OrderViolation {
* 违章总金额
*/
@Column(name="price")
private Double price;
private BigDecimal price;
/**
......
......@@ -326,7 +326,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
//退款金额
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) {
......@@ -412,7 +412,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
setOrderId(orderId);
setRefundTime(System.currentTimeMillis());
setTradeNo(refundTradeNo);
setRefundType(RefundTypeEnum.RentVehicle.getCode());
setRefundType(RefundTypeEnum.ORDER_FUND.getCode());
}};
orderRefund.setRefundAmount(refundAmount);
orderRefund.setRefundDesc(refundDesc);
......@@ -523,6 +523,18 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
* @return
*/
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) {
return selectById(baseOrder.getId());
}else {
......@@ -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) {
Long startTime = getDayStart();
if(time > startTime && time < startTime + 24 * 60 * 60 * 1000 - 1) {
......
......@@ -6,6 +6,7 @@ import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
import com.xxfc.platform.order.entity.OrderVehicleCrosstown;
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.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign;
......@@ -15,8 +16,6 @@ import org.springframework.stereotype.Service;
import com.xxfc.platform.order.entity.OrderRefund;
import com.xxfc.platform.order.mapper.OrderRefundMapper;
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.util.List;
......@@ -45,39 +44,35 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
@Autowired
OrderVehicalCrosstownBiz crosstownBiz;
public void refundDeposit(){
public void refundDeposit(OrderMQDTO orderMQDTO){
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
BigDecimal illegalReserve = new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ILLEGAL_RESERVE).getDetail());
List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class)
//订单已完成的租车订单
.where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE)
.andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH)
// .andLike(BaseOrder::getId, "%"+ String.valueOf(i))
).build());
//处理自动退押金
for(BaseOrder baseOrder : lists) {
OrderRentVehicleDetail orvd = orderRentVehicleBiz.selectOne(new OrderRentVehicleDetail() {{
setOrderId(baseOrder.getId());
//未退还, 进行保留违章预备金 的退还
if(RefundStatusEnum.NONE.getCode().equals(orderMQDTO.getRefundStatus())) {
OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{
setOrderId(orderMQDTO.getId());
setType(CrosstownTypeEnum.TOUR.getCode());
}});
//未退还, 进行保留违章预备金 的退还
if(RefundStatusEnum.NONE.getCode().equals(baseOrder.getRefundStatus())) {
OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{
setOrderId(baseOrder.getId());
setType(CrosstownTypeEnum.TOUR.getCode());
}});
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());
//设置剩余
//还车扣除款 剩余的 钱,再减去违章预备金
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 += ")";
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;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.util.IntervalUtil;
import com.xxfc.platform.order.biz.BaseOrderBiz;
import com.xxfc.platform.order.biz.OrderRentVehicleBiz;
import com.xxfc.platform.order.biz.OrderVehicalCrosstownBiz;
import com.xxfc.platform.order.biz.*;
import com.xxfc.platform.order.contant.enumerate.*;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
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.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.entity.Dictionary;
......@@ -27,6 +26,7 @@ import java.math.BigDecimal;
import java.util.List;
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;
/**
......@@ -37,7 +37,7 @@ import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER;
@JobHandler(value = "rentDepositHandler")
@Component
@Slf4j
public class RentDepositHandler extends IJobHandler {
public class RentDepositJobHandler extends IJobHandler {
@Autowired
BaseOrderBiz baseOrderBiz;
......@@ -48,50 +48,51 @@ public class RentDepositHandler extends IJobHandler {
@Autowired
OrderVehicalCrosstownBiz crosstownBiz;
@Autowired
OrderViolationBiz orderViolationBiz;
@Autowired
OrderRefundBiz orderRefundBiz;
@Autowired
ThirdFeign thirdFeign;
@Override
public ReturnT<String> execute(String idLastNumInterval) throws Exception {
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 {
for(int i = 0; i < 10; i++) {
if(IntervalUtil.staticIsInTheInterval(String.valueOf(i), idLastNumInterval)) {
//三十天
List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class)
//订单已完成的租车订单
.where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE)
.andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH)
.andLike(BaseOrder::getId, "%"+ String.valueOf(i))).build());
.andEqualTo(BaseOrder::getStatus, OrderStatusEnum.ORDER_FINISH) //已完成的订单
.andEqualTo(BaseOrder::getRefundStatus, RefundStatusEnum.RESIDUE_ILLEGAL) //已归还了部分押金
.andLessThanOrEqualTo(BaseOrder::getRefundTime, System.currentTimeMillis() - (rentDepositAutoRefundTime * 60 * 60 * 1000))
.andLike(BaseOrder::getId, "%"+ i)).build());
//处理自动退押金
//处理自动退剩余押金
for(BaseOrder baseOrder : lists) {
OrderRentVehicleDetail orvd = orderRentVehicleBiz.selectOne(new OrderRentVehicleDetail() {{
setOrderId(baseOrder.getId());
}});
//未退还, 进行保留违章预备金 的退还
if(RefundStatusEnum.NONE.getCode().equals(baseOrder.getRefundStatus())) {
OrderVehicleCrosstown crosstown = crosstownBiz.selectOne(new OrderVehicleCrosstown(){{
setOrderId(baseOrder.getId());
setType(CrosstownTypeEnum.TOUR.getCode());
}});
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());
//设置剩余
}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);
OrderViolation orderViolation = orderViolationBiz.selectOne(new OrderViolation(){{
setDetailId(orvd.getId());
setIsDel(SYS_FALSE);
}});
//还车扣除款 剩余的 钱,再减去违章预备金
BigDecimal refundAmont = orvd.getReturnPayResidue().subtract(orderViolation.getPrice());
String refundDesc = "退还押金:"+ refundAmont.toString()+ "(已扣除 违章扣款:"+ refundAmont.toString();
// for(DedDetailDTO ddd : dddList) {
// refundDesc += ", "+ ddd.getDeductions()+ ":"+ ddd.getCost();
// }
refundDesc += ")";
orderRefundBiz.refundTrigger(baseOrder, orvd, refundAmont, refundAmont, refundDesc, RefundStatusEnum.REFUND_DEPOSIT.getCode());
}
}
......
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 {
* 支付价格减低
*/
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