Commit 5ae7bd84 by 吕明尚

修改订单开放接口

parent ca03eca2
package share.system.service.impl; package share.system.service.impl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import share.common.enums.DeviceOpSourceEnum; import share.common.constant.Constants;
import share.common.enums.DeviceType; import share.common.enums.*;
import share.common.enums.RoomType;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import share.common.utils.bean.BeanUtils; import share.common.utils.bean.BeanUtils;
import share.system.domain.*; import share.system.domain.*;
import share.system.domain.vo.OrderVo; import share.system.domain.vo.OrderVo;
import share.system.domain.vo.SRoomVo; import share.system.domain.vo.SRoomVo;
import share.system.service.*; import share.system.service.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -42,6 +46,11 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService { ...@@ -42,6 +46,11 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService {
@Autowired @Autowired
private DeviceOpService deviceOpService; private DeviceOpService deviceOpService;
@Autowired
private ISCleanRecordsService cleanRecordsService;
@Override @Override
public OrderVo orderInfo(String orderNo) { public OrderVo orderInfo(String orderNo) {
SOrder en = orderService.getByOrderNo(orderNo); SOrder en = orderService.getByOrderNo(orderNo);
...@@ -61,10 +70,7 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService { ...@@ -61,10 +70,7 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(en.getCouponId()); SConsumerCoupon consumerCoupon = consumerCouponService.getById(en.getCouponId());
vo.setCouponName(consumerCoupon.getName()); vo.setCouponName(consumerCoupon.getName());
// 判断是否可以退款 // 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, consumerCoupon)); vo.setIsRefund(Boolean.FALSE);
} else {
// 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, null));
} }
if (ObjectUtil.isNotEmpty(en.getPackId())) { if (ObjectUtil.isNotEmpty(en.getPackId())) {
SPack byId = packService.getById(en.getPackId()); SPack byId = packService.getById(en.getPackId());
...@@ -102,7 +108,62 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService { ...@@ -102,7 +108,62 @@ public class OpenInterfaceServiceImpl implements OpenInterfaceService {
).collect(Collectors.toList()).isEmpty()) { ).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间取电设备不存在!"); throw new BaseException("房间取电设备不存在!");
} }
if (sOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode())) {
if (RoomStatusEnum.HOLD.getValue().compareTo(sRoomVo.getStatus()) == 0
|| !checkOrderOpenDoor(sOrder)) {
throw new BaseException("房间当前时段已被占用不可开门!");
}
//判断预约时间是否到达,可提前一个小时开门
if (DateUtils.addHours(sOrder.getPreStartDate(), Constants.OPEN_DOOR_AHEAD_HOUR_MINUS).compareTo(new Date()) > 0) {
throw new BaseException("预约时间未到达,可提前" + Constants.OPEN_DOOR_AHEAD_HOUR + "小时进场,请耐心等候!");
}
// 判断房间是否脏房中
// if (sRoomVo.getIsDirtyRoom() > 0) {
// throw new BaseException("当前房间未保洁,请等待!");
// }
// 55分钟内是否有保洁记录
LambdaQueryWrapper<SCleanRecords> recordsQueryWrapper = new LambdaQueryWrapper<>();
recordsQueryWrapper.eq(SCleanRecords::getRoomId, sOrder.getRoomId());
recordsQueryWrapper.ge(SCleanRecords::getCreateTime, cn.hutool.core.date.DateUtil.offset(cn.hutool.core.date.DateUtil.date(), DateField.MINUTE, -60));
List<SCleanRecords> recordsList = cleanRecordsService.list(recordsQueryWrapper);
if (recordsList != null && recordsList.size() > 0) {
SCleanRecords records = recordsList.get(0);
if (CleaningStatusEnum.CLEANED.getCode().equals(records.getStatus())) {
// 如果保洁状态未不是保洁中
throw new BaseException("当前房间待保洁中,请等待!");
}
}
}
deviceOpService.openDoor(sRoomVo.getId(), sOrder.getConsumerPhone(), DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode()); deviceOpService.openDoor(sRoomVo.getId(), sOrder.getConsumerPhone(), DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode());
return "开锁成功"; return "开锁成功";
} }
/**
* 查询非当前用户,预约时间或使用时间为当前时间的订单,如果存在,房间不可开门
*
* @return
*/
private boolean checkOrderOpenDoor(SOrder order) {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ne(SOrder::getOrderNo, order.getOrderNo());
queryWrapper.eq(SOrder::getStoreId, order.getStoreId());
queryWrapper.eq(SOrder::getRoomId, order.getRoomId());
queryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
queryWrapper.notIn(SOrder::getStatus, new ArrayList<Integer>() {{
add(OrderStatusEnum.USED.getCode());
add(OrderStatusEnum.CANCEL.getCode());
add(OrderStatusEnum.REFUNDING.getCode());
add(OrderStatusEnum.REFUNDED.getCode());
}});
queryWrapper.notIn(SOrder::getRefundStatus, new ArrayList<Integer>() {{
add(RefundStatusEnum.INREFUND.getCode());
add(RefundStatusEnum.REFUNDED.getCode());
}});
//订单开始时间大于等于当前时间 并且 订单开始时间小于等于当前订单实际结束时间+30分钟保洁
BigDecimal bigDecimal = DateUtils.differentHour(order.getPreStartDate(), order.getPreEndDate());
Date orderEndDate = DateUtils.addMinutes(DateUtils.addHours(new Date(), bigDecimal.intValue()), Constants.ROOM_LOCK_DELAY_MINUTE);
queryWrapper.apply("IFNULL(start_date,pre_start_date) >= '" + DateUtils.getTime() + "' " +
" AND IFNULL(start_date,pre_start_date) <= '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderEndDate) + "'");
return orderService.count(queryWrapper) == 0;
}
} }
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