1. 联调
This commit is contained in:
parent
156e7f33a4
commit
a4b28c47dd
|
@ -71,7 +71,6 @@ public class AppVerifyController extends BaseController
|
||||||
private IEtOperatingAreaService etOperatingAreaService;
|
private IEtOperatingAreaService etOperatingAreaService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 故障上报
|
* 故障上报
|
||||||
*/
|
*/
|
||||||
|
@ -144,12 +143,10 @@ public class AppVerifyController extends BaseController
|
||||||
if(order.getRuleId()==null){
|
if(order.getRuleId()==null){
|
||||||
return error("=============================================ruleId未传!!!=============================================");
|
return error("=============================================ruleId未传!!!=============================================");
|
||||||
}
|
}
|
||||||
// //设备是否在线
|
AsDevice asDevice = asDeviceService.selectAsDeviceBySn(order.getSn());
|
||||||
// if(!asDeviceService.isOnline(order.getSn())){
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId());
|
||||||
// return error("设备不在线");
|
|
||||||
// }
|
|
||||||
//实名判断
|
//实名判断
|
||||||
if(!asUserService.checkIsAuthentication(order.getUserId())){
|
if(area.getAuthentication().equals(ServiceConstants.IS_AUTHENTICATION_YES) && !asUserService.checkIsAuthentication(order.getUserId())){
|
||||||
return error("您还未实名,请先实名");
|
return error("您还未实名,请先实名");
|
||||||
}
|
}
|
||||||
//运营时间判断
|
//运营时间判断
|
||||||
|
@ -157,9 +154,9 @@ public class AppVerifyController extends BaseController
|
||||||
return error("不在营业时间内,不得骑行");
|
return error("不在营业时间内,不得骑行");
|
||||||
}
|
}
|
||||||
//非正常状态不得骑行
|
//非正常状态不得骑行
|
||||||
AsDevice asDevice = asDeviceService.selectAsDeviceBySn(order.getSn());
|
|
||||||
String status = asDevice.getStatus();
|
String status = asDevice.getStatus();
|
||||||
if(!ServiceConstants.VEHICLE_STATUS_NORMAL.equals(status)){
|
EtOrder order1 = etOrderService.selectEtOrderByOrderNo(order.getOrderNo());
|
||||||
|
if(!ServiceConstants.VEHICLE_STATUS_NORMAL.equals(status) && !order1.getSn().equals(order.getSn())){
|
||||||
//根据状态值返回不同的提示
|
//根据状态值返回不同的提示
|
||||||
return error(CommonUtil.format(status));
|
return error(CommonUtil.format(status));
|
||||||
}
|
}
|
||||||
|
@ -301,10 +298,16 @@ public class AppVerifyController extends BaseController
|
||||||
public AjaxResult deviceAppointment(EtOrderVo appointmentVo)
|
public AjaxResult deviceAppointment(EtOrderVo appointmentVo)
|
||||||
{
|
{
|
||||||
logger.info("【车辆预约信息】:{}", JSON.toJSON(appointmentVo));
|
logger.info("【车辆预约信息】:{}", JSON.toJSON(appointmentVo));
|
||||||
|
AsDevice asDevice = asDeviceService.selectAsDeviceBySn(appointmentVo.getSn());
|
||||||
//设备是否在线
|
//设备是否在线
|
||||||
if(!asDeviceService.isOnline(appointmentVo.getSn())){
|
if(!asDeviceService.isOnline(appointmentVo.getSn())){
|
||||||
return error("设备不在线");
|
return error("设备不在线");
|
||||||
}
|
}
|
||||||
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId());
|
||||||
|
//实名判断
|
||||||
|
if(area.getAuthentication().equals(ServiceConstants.IS_AUTHENTICATION_YES) && !asUserService.checkIsAuthentication(appointmentVo.getUserId())){
|
||||||
|
return error("您还未实名,请先实名");
|
||||||
|
}
|
||||||
//运营时间判断
|
//运营时间判断
|
||||||
if(!asDeviceService.isOperatingTime(appointmentVo.getSn())){
|
if(!asDeviceService.isOperatingTime(appointmentVo.getSn())){
|
||||||
return error("不在营业时间内,不得骑行");
|
return error("不在营业时间内,不得骑行");
|
||||||
|
@ -321,7 +324,6 @@ public class AppVerifyController extends BaseController
|
||||||
throw new ServiceException("您有预约中的订单,请务重复操作");
|
throw new ServiceException("您有预约中的订单,请务重复操作");
|
||||||
}
|
}
|
||||||
appointmentVo.setType("2");
|
appointmentVo.setType("2");
|
||||||
AsDevice asDevice = asDeviceService.selectAsDeviceBySn(appointmentVo.getSn());
|
|
||||||
String status = asDevice.getStatus();
|
String status = asDevice.getStatus();
|
||||||
if(!ServiceConstants.VEHICLE_STATUS_NORMAL.equals(status)){
|
if(!ServiceConstants.VEHICLE_STATUS_NORMAL.equals(status)){
|
||||||
//根据状态值返回不同的提示
|
//根据状态值返回不同的提示
|
||||||
|
|
|
@ -216,6 +216,23 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||||
return minutes;
|
return minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算时间差(只返回秒数)
|
||||||
|
*
|
||||||
|
* @param endDate 结束时间
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @return 时间差(秒)
|
||||||
|
*/
|
||||||
|
public static int timeDifferenceInSeconds(Date endDate, Date startTime) {
|
||||||
|
// 获得两个时间的毫秒时间差异
|
||||||
|
long diff = endDate.getTime() - startTime.getTime();
|
||||||
|
|
||||||
|
// 直接计算差多少秒
|
||||||
|
int seconds = (int) Math.abs(diff / 1000);
|
||||||
|
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加 LocalDateTime ==> Date
|
* 增加 LocalDateTime ==> Date
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,7 +10,7 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class EtOrderVo {
|
public class EtOrderVo {
|
||||||
|
|
||||||
/** 用户id Cannot deserialize value of type `long` from String "union select 1,md5(3141592657)--": not a valid `long` value */
|
/** 用户id */
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/** 设备编码 */
|
/** 设备编码 */
|
||||||
|
|
|
@ -207,4 +207,9 @@ public interface EtOrderMapper
|
||||||
* 最近一笔订单
|
* 最近一笔订单
|
||||||
*/
|
*/
|
||||||
EtOrder selectLatestOrder(EtOrder etOrder);
|
EtOrder selectLatestOrder(EtOrder etOrder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预约未完成订单处理
|
||||||
|
*/
|
||||||
|
List<EtOrder> selectAppointmentUnfinished();
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,68 +161,68 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
// 新增资金流水记录
|
// 新增资金流水记录
|
||||||
capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_RIDING);
|
capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_RIDING);
|
||||||
// 还车结算___小时后自动退押金---创建一个定时器TimerTask,计算出退还时间后,执行退款操作
|
// 还车结算___小时后自动退押金---创建一个定时器TimerTask,计算出退还时间后,执行退款操作
|
||||||
EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(order.getRuleId());
|
|
||||||
Integer autoRefundDeposit = rule.getAutoRefundDeposit();
|
|
||||||
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
||||||
if(autoRefundDeposit!=null && autoRefundDeposit>0){
|
// 退还押金处理
|
||||||
//创建一个定时器,计算出退还时间后,执行退款操作
|
refundDeposit(area.getDeposit(), order, asUser);
|
||||||
// 往后推autoRefundDeposit小时执行
|
|
||||||
scheduledExecutorService.schedule(() -> {
|
|
||||||
// 如果退款成功直接返回
|
|
||||||
EtRefund refund2 = etRefundMapper.selectEtRefundByOrderNo(order.getOrderNo());
|
|
||||||
if(ObjectUtil.isNotNull(refund2) && refund2.getRefundResult().equals(Constants.SUCCESS2)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.info("【微信支付回调】退还押金定时任务开始");
|
|
||||||
// 退款
|
|
||||||
Long userId = order.getUserId();
|
|
||||||
EtOrder etOrder = new EtOrder();
|
|
||||||
etOrder.setUserId(userId);
|
|
||||||
etOrder.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
|
|
||||||
etOrder.setType(ServiceConstants.ORDER_TYPE_DEPOSIT);
|
|
||||||
etOrder.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
||||||
List<EtOrder> etOrders = etOrderMapper.selectEtOrderList(etOrder);
|
|
||||||
if (etOrders.size() == 0 || ObjectUtil.isNull(etOrders) ) {
|
|
||||||
throw new ServiceException("押金充值记录不存在");
|
|
||||||
}
|
|
||||||
Optional<EtOrder> latestOrder = etOrders.stream()
|
|
||||||
.max(Comparator.comparing(EtOrder::getPayTime));
|
|
||||||
if (latestOrder.isPresent()) {
|
|
||||||
EtOrder newestOrder = latestOrder.get();
|
|
||||||
logger.info("【微信支付回调】最后一次押金充值记录 : " + JSON.toJSONString(newestOrder));
|
|
||||||
// 处理找到的最新支付时间的订单
|
|
||||||
String deposit = area.getDeposit();
|
|
||||||
if(newestOrder.getTotalFee().compareTo(new BigDecimal(deposit))!=0){
|
|
||||||
throw new ServiceException("押金充值记录与当前运营区的押金不同");
|
|
||||||
}
|
|
||||||
String reason = autoRefundDeposit + "个小时后自动退押金";
|
|
||||||
Refund refund = wxPayService.refund(newestOrder,reason, newestOrder.getTotalFee());
|
|
||||||
newestOrder.setReason(reason);
|
|
||||||
EtRefund refund1= orderService.createRefund(newestOrder, newestOrder.getTotalFee(), null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT);
|
|
||||||
int i = etRefundService.insertEtRefund(refund1);
|
|
||||||
if(i>0){
|
|
||||||
logger.info("【自动退款】保存退款对象成功");
|
|
||||||
}
|
|
||||||
// 新增资金流水记录
|
|
||||||
capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND);
|
|
||||||
|
|
||||||
// 更新用户信息,清除缓存
|
// 请求分账处理
|
||||||
asUser.setBalance(BigDecimal.ZERO);
|
if (dividendHandle(transactionId, order, area)) return;
|
||||||
|
|
||||||
|
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_APPOINTMENT)){
|
||||||
|
logger.info("【微信支付回调】取消预约支付");
|
||||||
|
// 2-取消预约支付
|
||||||
|
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
||||||
|
order.setMark("取消预约支付");
|
||||||
|
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//取消预约支付后车辆正常运营
|
||||||
|
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
|
||||||
|
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_DEPOSIT)){
|
||||||
|
logger.info("【微信支付回调】押金支付");
|
||||||
|
// 4-押金支付
|
||||||
|
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
||||||
|
asUser.setBalance(order.getTotalFee());
|
||||||
|
order.setMark("押金支付");
|
||||||
|
|
||||||
|
// 新增资金流水记录
|
||||||
|
capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_DEPOSIT);
|
||||||
|
// 删除用户缓存
|
||||||
|
String token = attachVo.getToken();
|
||||||
|
logger.info("【微信支付回调】删除用户缓存:"+token);
|
||||||
|
if (StringUtils.isNotNull(token))
|
||||||
|
{
|
||||||
|
redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logger.error("【微信支付回调】 : 支付场景不存在");
|
||||||
|
throw new ServiceException("【微信支付回调】支付场景不存在");
|
||||||
|
}
|
||||||
|
if(ObjectUtil.isNotNull(asDevice)){
|
||||||
|
int device = asDeviceService.updateAsDevice(asDevice);
|
||||||
|
if(device==0){
|
||||||
|
logger.error("【微信支付回调】更新车辆状态失败");
|
||||||
|
throw new ServiceException("【微信支付回调】更新车辆状态失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("=================【微信支付回调】开始更新订单信息==================");
|
||||||
|
int updateEtOrder = orderService.updateEtOrder(order);
|
||||||
|
if(updateEtOrder==0){
|
||||||
|
logger.error("【微信支付回调】更新订单信息失败");
|
||||||
|
throw new ServiceException("【微信支付回调】更新订单信息失败");
|
||||||
|
}
|
||||||
|
logger.info("=================【微信支付回调】开始更新用户信息==================");
|
||||||
int updateUser = userService.updateUser(asUser);
|
int updateUser = userService.updateUser(asUser);
|
||||||
if(updateUser>0){
|
if(updateUser==0){
|
||||||
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
|
logger.error("【微信支付回调】更新用户押金失败");
|
||||||
redisCache.deleteObject(keys);
|
throw new ServiceException("【微信支付回调】更新用户押金失败");
|
||||||
logger.info("【微信支付回调】退还押金,更新用户余额成功!");
|
|
||||||
}
|
}
|
||||||
logger.info("=================【微信支付回调】退还押金定时任务结束!!!==================");
|
logger.info("=================【微信支付回调】全部结束!!!!!==================");
|
||||||
} else {
|
|
||||||
throw new ServiceException("没有找到押金充值记录");
|
|
||||||
}
|
}
|
||||||
}, autoRefundDeposit , TimeUnit.HOURS);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean dividendHandle(String transactionId, EtOrder order, EtOperatingArea area) {
|
||||||
List<EtDividendDetail> etDividendDetails = dividendDetailService.selectEtDividendDetailByOrderNo(order.getOrderNo());
|
List<EtDividendDetail> etDividendDetails = dividendDetailService.selectEtDividendDetailByOrderNo(order.getOrderNo());
|
||||||
if(ObjectUtil.isNotNull(etDividendDetails) && etDividendDetails.size()>0){
|
if(ObjectUtil.isNotNull(etDividendDetails) && etDividendDetails.size()>0){
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
logger.info("=================【微信支付回调】开始请求分账==================");
|
logger.info("=================【微信支付回调】开始请求分账==================");
|
||||||
logger.info("区域对象====="+JSON.toJSONString(area));
|
logger.info("区域对象====="+JSON.toJSONString(area));
|
||||||
|
@ -285,54 +285,70 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
logger.info("【微信支付回调】发起分账失败");
|
logger.info("【微信支付回调】发起分账失败");
|
||||||
throw new ServiceException("发起分账失败");
|
throw new ServiceException("发起分账失败");
|
||||||
}
|
}
|
||||||
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_APPOINTMENT)){
|
return false;
|
||||||
logger.info("【微信支付回调】取消预约支付");
|
}
|
||||||
// 2-取消预约支付
|
|
||||||
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
||||||
order.setMark("取消预约支付");
|
|
||||||
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//取消预约支付后车辆正常运营
|
|
||||||
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
|
|
||||||
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_DEPOSIT)){
|
|
||||||
logger.info("【微信支付回调】押金支付");
|
|
||||||
// 4-押金支付
|
|
||||||
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
||||||
asUser.setBalance(order.getTotalFee());
|
|
||||||
order.setMark("押金支付");
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退还押金定时任务
|
||||||
|
*/
|
||||||
|
private void refundDeposit(String deposit, EtOrder order, AsUser asUser) {
|
||||||
|
EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(order.getRuleId());
|
||||||
|
Integer autoRefundDeposit = rule.getAutoRefundDeposit();
|
||||||
|
|
||||||
|
if(autoRefundDeposit!=null && autoRefundDeposit>0){
|
||||||
|
//创建一个定时器,计算出退还时间后,执行退款操作
|
||||||
|
// 往后推autoRefundDeposit小时执行
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
// 如果退款成功直接返回
|
||||||
|
EtRefund refund2 = etRefundMapper.selectEtRefundByOrderNo(order.getOrderNo());
|
||||||
|
if(ObjectUtil.isNotNull(refund2) && refund2.getRefundResult().equals(Constants.SUCCESS2)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.info("【微信支付回调】退还押金定时任务开始");
|
||||||
|
// 退款
|
||||||
|
Long userId = order.getUserId();
|
||||||
|
EtOrder etOrder = new EtOrder();
|
||||||
|
etOrder.setUserId(userId);
|
||||||
|
etOrder.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
|
||||||
|
etOrder.setType(ServiceConstants.ORDER_TYPE_DEPOSIT);
|
||||||
|
etOrder.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
||||||
|
List<EtOrder> etOrders = etOrderMapper.selectEtOrderList(etOrder);
|
||||||
|
if (etOrders.size() == 0 || ObjectUtil.isNull(etOrders) ) {
|
||||||
|
throw new ServiceException("押金充值记录不存在");
|
||||||
|
}
|
||||||
|
Optional<EtOrder> latestOrder = etOrders.stream()
|
||||||
|
.max(Comparator.comparing(EtOrder::getPayTime));
|
||||||
|
if (latestOrder.isPresent()) {
|
||||||
|
EtOrder newestOrder = latestOrder.get();
|
||||||
|
logger.info("【微信支付回调】最后一次押金充值记录 : " + JSON.toJSONString(newestOrder));
|
||||||
|
// 处理找到的最新支付时间的订单
|
||||||
|
if(newestOrder.getTotalFee().compareTo(new BigDecimal(deposit))!=0){
|
||||||
|
throw new ServiceException("押金充值记录与当前运营区的押金不同");
|
||||||
|
}
|
||||||
|
String reason = autoRefundDeposit + "个小时后自动退押金";
|
||||||
|
Refund refund = wxPayService.refund(newestOrder,reason, newestOrder.getTotalFee());
|
||||||
|
newestOrder.setReason(reason);
|
||||||
|
EtRefund refund1= orderService.createRefund(newestOrder, newestOrder.getTotalFee(), null, null, null, null, refund,ServiceConstants.REFUND_TYPE_DEPOSIT);
|
||||||
|
int i = etRefundService.insertEtRefund(refund1);
|
||||||
|
if(i>0){
|
||||||
|
logger.info("【自动退款】保存退款对象成功");
|
||||||
|
}
|
||||||
// 新增资金流水记录
|
// 新增资金流水记录
|
||||||
capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_DEPOSIT);
|
capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND);
|
||||||
// 删除用户缓存
|
|
||||||
String token = attachVo.getToken();
|
// 更新用户信息,清除缓存
|
||||||
logger.info("【微信支付回调】删除用户缓存:"+token);
|
asUser.setBalance(BigDecimal.ZERO);
|
||||||
if (StringUtils.isNotNull(token))
|
|
||||||
{
|
|
||||||
redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
logger.error("【微信支付回调】 : 支付场景不存在");
|
|
||||||
throw new ServiceException("【微信支付回调】支付场景不存在");
|
|
||||||
}
|
|
||||||
if(ObjectUtil.isNotNull(asDevice)){
|
|
||||||
int device = asDeviceService.updateAsDevice(asDevice);
|
|
||||||
if(device==0){
|
|
||||||
logger.error("【微信支付回调】更新车辆状态失败");
|
|
||||||
throw new ServiceException("【微信支付回调】更新车辆状态失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.info("=================【微信支付回调】开始更新订单信息==================");
|
|
||||||
int updateEtOrder = orderService.updateEtOrder(order);
|
|
||||||
if(updateEtOrder==0){
|
|
||||||
logger.error("【微信支付回调】更新订单信息失败");
|
|
||||||
throw new ServiceException("【微信支付回调】更新订单信息失败");
|
|
||||||
}
|
|
||||||
logger.info("=================【微信支付回调】开始更新用户信息==================");
|
|
||||||
int updateUser = userService.updateUser(asUser);
|
int updateUser = userService.updateUser(asUser);
|
||||||
if(updateUser==0){
|
if(updateUser>0){
|
||||||
logger.error("【微信支付回调】更新用户押金失败");
|
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
|
||||||
throw new ServiceException("【微信支付回调】更新用户押金失败");
|
redisCache.deleteObject(keys);
|
||||||
|
logger.info("【微信支付回调】退还押金,更新用户余额成功!");
|
||||||
}
|
}
|
||||||
logger.info("=================【微信支付回调】全部结束!!!!!==================");
|
logger.info("=================【微信支付回调】退还押金定时任务结束!!!==================");
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("没有找到押金充值记录");
|
||||||
}
|
}
|
||||||
|
}, autoRefundDeposit , TimeUnit.HOURS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,11 @@ import com.ruoyi.common.constant.ServiceConstants;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.system.domain.AsDevice;
|
||||||
import com.ruoyi.system.domain.EtDividendDetail;
|
import com.ruoyi.system.domain.EtDividendDetail;
|
||||||
import com.ruoyi.system.domain.EtOperatingArea;
|
import com.ruoyi.system.domain.EtOperatingArea;
|
||||||
import com.ruoyi.system.domain.EtOrder;
|
import com.ruoyi.system.domain.EtOrder;
|
||||||
|
import com.ruoyi.system.mapper.AsDeviceMapper;
|
||||||
import com.ruoyi.system.mapper.EtOrderMapper;
|
import com.ruoyi.system.mapper.EtOrderMapper;
|
||||||
import com.ruoyi.system.mapper.SysUserMapper;
|
import com.ruoyi.system.mapper.SysUserMapper;
|
||||||
import com.ruoyi.system.service.IEtDividendDetailService;
|
import com.ruoyi.system.service.IEtDividendDetailService;
|
||||||
|
@ -24,7 +26,10 @@ import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,14 +53,67 @@ public class EtTask {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IEtDividendDetailService dividendDetailService;
|
private IEtDividendDetailService dividendDetailService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IEtOrderService etOrderService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AsDeviceMapper asDeviceMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动时判断是否有未取消预约的订单、已完成的订单未退还押金的
|
* 1.启动时判断是否有未取消预约的订单
|
||||||
|
* 2.判断已完成的订单未退还押金的
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
|
log.info("=========启动时判断是否有未取消预约的订单、已完成的订单未退还押金的==========");
|
||||||
log.info("websocket====>init方法被执行");
|
List<EtOrder> orders= etOrderMapper.selectAppointmentUnfinished();
|
||||||
|
log.info("预约未完成的订单 = " + JSON.toJSONString(orders));
|
||||||
|
for (EtOrder order:orders) {
|
||||||
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
||||||
|
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(order.getSn());
|
||||||
|
Date appointmentEndTime = DateUtils.getTimeAfterXMinutes(order.getAppointmentStartTime(), area.getTimeoutMinutes());//预约结束时间
|
||||||
|
int timeDifferenceInSeconds = DateUtils.timeDifferenceInSeconds(appointmentEndTime, order.getAppointmentStartTime());//(超时时间-开始时间)的秒数
|
||||||
|
int differenceInSeconds = DateUtils.timeDifferenceInSeconds(new Date(), order.getAppointmentStartTime());//(当前时间-开始时间)的秒数
|
||||||
|
int delay = timeDifferenceInSeconds - differenceInSeconds;
|
||||||
|
log.info("【定时取消预约】延迟:【{}】秒", delay);
|
||||||
|
//定时取消预约
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
log.error("【车辆超时预约】系统自动取消");
|
||||||
|
EtOrder order1 = etOrderService.selectEtOrderByOrderNo(order.getOrderNo());
|
||||||
|
log.info("【定时取消预约】重新获取订单信息:{}",JSON.toJSON(order1));
|
||||||
|
if(order1.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_PAID)){//已支付订单,跳过
|
||||||
|
log.error("【车辆超时预约】订单已支付,跳过");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.error("【车辆超时预约】订单未支付,系统自动处理");
|
||||||
|
//未支付 订单更新最后预约时间,并结束订单,做超出预约时间标记
|
||||||
|
order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT);
|
||||||
|
order.setAppointmentEndTime(new Date());
|
||||||
|
order.setAppointmentTimeout("1");
|
||||||
|
//计算预约费
|
||||||
|
BigDecimal appointmentServiceFee = area.getAppointmentServiceFee();
|
||||||
|
BigDecimal fee = appointmentServiceFee.multiply(new BigDecimal(area.getTimeoutMinutes()).divide(new BigDecimal(10)));
|
||||||
|
order.setAppointmentFee(fee);
|
||||||
|
order.setTotalFee(fee);
|
||||||
|
int update = etOrderService.updateEtOrder(order);
|
||||||
|
if(update==0){
|
||||||
|
throw new ServiceException("【车辆超时预约】:更新订单状态失败");
|
||||||
|
}
|
||||||
|
// 改变车辆状态
|
||||||
|
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);
|
||||||
|
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
|
||||||
|
int device = asDeviceMapper.updateAsDevice(asDevice);
|
||||||
|
if(device==0){
|
||||||
|
log.error("【车辆超时预约】更新车辆状态失败");
|
||||||
|
throw new ServiceException("【车辆超时预约】更新车辆状态失败");
|
||||||
|
}
|
||||||
|
}, delay, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 每天凌晨0点5分执行,计算分账结果
|
* 每天凌晨0点5分执行,计算分账结果
|
||||||
|
|
|
@ -295,6 +295,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
ORDER BY create_time DESC
|
ORDER BY create_time DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectAppointmentUnfinished" resultType="com.ruoyi.system.domain.EtOrder">
|
||||||
|
select * from et_order where appointment_start_time is not null and appointment_start_time != '' AND appointment_end_time IS NULL
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertEtOrder" parameterType="EtOrder" useGeneratedKeys="true" keyProperty="orderId">
|
<insert id="insertEtOrder" parameterType="EtOrder" useGeneratedKeys="true" keyProperty="orderId">
|
||||||
insert into et_order
|
insert into et_order
|
||||||
|
|
Loading…
Reference in New Issue
Block a user