Commit 24c90ef7 authored by 周健威's avatar 周健威

添加特惠租车定时

parent d2f0f326
......@@ -24,7 +24,6 @@ public class SpecialRent implements Serializable {
public static final int STATUS_CRT = 1;
public static final int STATUS_CNL = 2;
public static final int STATUS_ORDER = 4;
public static final int STATUS_AUTOCNL_REQUIRE = 501;
public static final int STATUS_AUTOCNL_ORDER = 502;
public static final int STATUS_AUTOCNL_TOPAY = 503;
public static final int STATUS_AUTOCNL_PAYED = 504;
......@@ -257,4 +256,10 @@ public class SpecialRent implements Serializable {
@ApiModelProperty(value = "还车城市名称")
private String endCityName;
/**
* 超时时间戳
*/
@Column(name = "over_time")
@ApiModelProperty(value = "超时时间戳", hidden = true )
private Long overTime;
}
......@@ -13,6 +13,7 @@ import com.github.wxiaoqi.security.common.util.AssertUtils;
import com.github.wxiaoqi.security.common.util.OrderUtil;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.mqhandler.RabbitProduct;
import com.xxfc.platform.order.pojo.order.RentVehicleBO;
import com.xxfc.platform.order.service.OrderRentVehicleService;
import com.xxfc.platform.vehicle.entity.Vehicle;
......@@ -20,6 +21,7 @@ import com.xxfc.platform.vehicle.entity.VehicleCategory;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import com.xxfc.platform.vehicle.pojo.BookVehicleVO;
import com.xxfc.platform.vehicle.pojo.CompanyDetail;
import com.xxfc.platform.vehicle.pojo.vo.VehicleVO;
import org.mockito.internal.util.collections.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -29,6 +31,7 @@ import com.xxfc.platform.order.mapper.SpecialRentMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Date;
import java.util.List;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
......@@ -49,6 +52,9 @@ public class SpecialRentBiz extends BaseBiz<SpecialRentMapper, SpecialRent> {
@Autowired
OrderRentVehicleService orderRentVehicleService;
@Autowired
RabbitProduct rabbitProduct;
@Autowired
UserFeign userFeign;
......@@ -88,7 +94,8 @@ public class SpecialRentBiz extends BaseBiz<SpecialRentMapper, SpecialRent> {
throw new BaseException(ResultCode.PARAM_ILLEGAL_CODE);
}
Vehicle vehicle = vehicleFeign.get(specialRent.getVehicleId()).getData();
//Vehicle vehicle = vehicleFeign.get(specialRent.getVehicleId()).getData();
VehicleVO vehicle = vehicleFeign.getVehicleDetail(specialRent.getVehicleId()).getData();
if(null == vehicle) {
throw new BaseException(ResultCode.PARAM_ILLEGAL_CODE);
......@@ -175,11 +182,12 @@ public class SpecialRentBiz extends BaseBiz<SpecialRentMapper, SpecialRent> {
setState(STATE_DOWN);
}});
}
// rabbitProduct.sendApplyDelayMessage(baseBiz.selectById(specialRent.getId()), 1000L * 3601L);
// Long delayTime = DateUtil.date().getTime() - DateUtil.offsetDay(endDateTime, -1).getTime();
// specialRent.setOverTime(delayTime);
Date endDateTime = DateUtil.date(specialRent.getEndTime());
Long delayTime = DateUtil.date().getTime() - DateUtil.offsetHour(endDateTime, -1).getTime();
specialRent.setOverTime(delayTime);
insertSelective(specialRent);
// rabbitProduct.sendApplyRequireDelayMessage(baseBiz.selectById(shuntApply.getId()), delayTime);
rabbitProduct.sendSpecialDelayMessage(selectById(specialRent.getId()), delayTime);
}
}
\ No newline at end of file
......@@ -4,9 +4,11 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.rabbitmq.client.Channel;
import com.xxfc.platform.order.biz.ShuntApplyBiz;
import com.xxfc.platform.order.biz.SpecialRentBiz;
import com.xxfc.platform.order.biz.inner.OrderCancelBiz;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.ShuntApply;
import com.xxfc.platform.order.entity.SpecialRent;
import com.xxfc.platform.order.pojo.order.RentVehicleBO;
import com.xxfc.platform.order.service.OrderRentVehicleService;
import lombok.extern.slf4j.Slf4j;
......@@ -35,6 +37,9 @@ public class RabbitConsumer {
@Autowired
ShuntApplyBiz shuntApplyBiz;
@Autowired
SpecialRentBiz specialRentBiz;
@Autowired
OrderRentVehicleService orderRentVehicleService;
......@@ -138,4 +143,37 @@ public class RabbitConsumer {
channel.basicRecover(true);
}
}
@RabbitListener(queues = SPECIAL_CANCEL_QUE)
public void specialCancelReceiveDealy(SpecialRent specialRent, Message message, Channel channel) throws IOException {
log.info("===============接收队列接收消息====================");
log.info("接收时间:{},接受内容:{}", LocalDateTime.now(), specialRent.toString());
//通知 MQ 消息已被接收,可以ACK(从队列中删除)了
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
try {
//判断updateTime 是否一致(即乐观锁)
SpecialRent dbSpecialRent = specialRentBiz.selectById(specialRent.getId());
if(dbSpecialRent.getUpdTime().equals(specialRent.getUpdTime())) {
specialRentBiz.updateSelectiveById(new SpecialRent(){{
setId(specialRent.getId());
setStatus(SpecialRent.STATUS_AUTOCNL_ORDER);
}});
}
}catch (BaseException e) {
if(ResultCode.DB_OPERATION_FAIL_CODE == e.getStatus()) {
log.info("取消操作被取消;订单id:"+ specialRent.getId());
}
}catch (Exception e) {
log.error("============消费失败,尝试消息补发再次消费!==============");
log.error(e.getMessage());
/**
* basicRecover方法是进行补发操作,
* 其中的参数如果为true是把消息退回到queue但是有可能被其它的consumer(集群)接收到,
* 设置为false是只补发给当前的consumer
*/
channel.basicRecover(true);
}
}
}
......@@ -2,6 +2,7 @@ package com.xxfc.platform.order.mqhandler;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.ShuntApply;
import com.xxfc.platform.order.entity.SpecialRent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,6 +11,7 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import static com.xxfc.platform.order.config.RabbitDelayConfig.*;
import static com.xxfc.platform.order.config.RabbitDelayConfig.SPECIAL_CANCEL_KEY;
/**
* rabbitMq生产者类
......@@ -73,5 +75,22 @@ public class RabbitProduct {
);
log.info("{}ms后执行", delayTime);
}
public void sendSpecialDelayMessage(SpecialRent specialRent, Long delayTime) {
//这里的消息可以是任意对象,无需额外配置,直接传即可
log.info("===============延时队列生产消息====================");
log.info("发送时间:{},发送内容:{}", LocalDateTime.now(), specialRent.toString());
this.rabbitTemplate.convertAndSend(
SPECIAL_CANCEL_EXC,
SPECIAL_CANCEL_KEY,
specialRent,
message -> {
//注意这里时间可以使long,而且是设置header
message.getMessageProperties().setHeader("x-delay", delayTime);
return message;
}
);
log.info("{}ms后执行", delayTime);
}
}
......@@ -10,10 +10,7 @@ import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyAreaDTO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyFindDTO;
import com.xxfc.platform.vehicle.pojo.dto.CompanyInfoFindDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
import com.xxfc.platform.vehicle.pojo.vo.AccompanyingItemVo;
import com.xxfc.platform.vehicle.pojo.vo.BranComanyLeaderVo;
import com.xxfc.platform.vehicle.pojo.vo.BranchCompanyListVO;
import com.xxfc.platform.vehicle.pojo.vo.UsableVeicleVO;
import com.xxfc.platform.vehicle.pojo.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
......@@ -68,9 +65,14 @@ public interface VehicleFeign {
@RequestMapping(value = "/vehicleInfo/apply/book/vehicle", method = RequestMethod.POST)
public ObjectRestResponse<VehicleBookRecord> applyBookVehicle(@RequestBody RentVehicleBookDTO rentVehicleBookDTO);
//查询公司详情
@RequestMapping(value = "/branchCompany/app/unauth/detail/{id}", method = RequestMethod.GET)
public ObjectRestResponse<CompanyDetail> getCompanyDetail(@PathVariable(value = "id") Integer id);
//查询车辆详情
@RequestMapping(value = "/app/vehicle/app/unauth/detail/{id}", method = RequestMethod.GET)
public ObjectRestResponse<VehicleVO> getVehicleDetail(@PathVariable("id") String id);
//租车拒绝预约
@RequestMapping(value = "/vehicleInfo/rent/book/reject/{bookRecordId}", method = RequestMethod.PUT)
public RestResponse<Integer> rentRejectVehicleBooking(@PathVariable(value = "bookRecordId") Long bookRecordId);
......
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