Commit d7e9de3a by wuwenlong

订单结束且保洁结束解除房间锁定可预约

parent 9a681d57
......@@ -87,6 +87,8 @@ public interface ISCleanRecordsService extends IService<SCleanRecords>
List<SCleanRecords> unCleanedListByRoomIds(List<Long> roomIds);
SCleanRecords lastCleanByRoomId(Long roomId);
/**
* 结束保洁
* @param sCleanRecords
......
......@@ -4,19 +4,19 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.constant.Constants;
import share.common.enums.CleaningStatusEnum;
import share.common.enums.OrderStatusEnum;
import share.common.enums.OrderTypeEnum;
import share.common.enums.RoomStatusEnum;
import share.common.utils.DateUtils;
import share.common.utils.StringUtils;
import share.system.domain.SCleanRecords;
import share.system.domain.SConsumer;
import share.system.domain.SOrder;
import share.system.domain.SStore;
import share.system.domain.vo.FrontTokenComponent;
import share.system.domain.vo.RoomStatusVo;
import share.system.service.ISOrderService;
import share.system.service.ISStoreService;
import share.system.service.RoomStatusService;
import share.system.service.SConsumerService;
import share.system.service.*;
import java.util.*;
......@@ -39,6 +39,9 @@ public class RoomStatusServiceImpl implements RoomStatusService {
@Autowired
private SConsumerService consumerService;
@Autowired
private ISCleanRecordsService cleanRecordsService;
@Override
public List<RoomStatusVo> roomStatus(Long storeId, Long roomId, Date day, Integer orderType) {
SConsumer user = consumerService.getInfo();
......@@ -49,12 +52,13 @@ public class RoomStatusServiceImpl implements RoomStatusService {
SStore store = storeService.getById(storeId);
// 通过门店及房间查询指定日期T+1的订单
List<SOrder> orderList = orderService.listByRoomInfo(storeId,roomId,day);
List<RoomStatusVo> voList = generatorRoomStatusList(store,roomId,orderList,day,orderType);
voList.addAll(generatorRoomStatusList(store,roomId,orderList,DateUtils.addDays(day,1),orderType));
SCleanRecords cleanRecords = cleanRecordsService.lastCleanByRoomId(roomId);
List<RoomStatusVo> voList = generatorRoomStatusList(store,roomId,orderList,cleanRecords,day,orderType);
voList.addAll(generatorRoomStatusList(store,roomId,orderList,cleanRecords,DateUtils.addDays(day,1),orderType));
return voList;
}
private List<RoomStatusVo> generatorRoomStatusList(SStore store,Long roomId,List<SOrder> orderList,Date day, Integer orderType){
private List<RoomStatusVo> generatorRoomStatusList(SStore store,Long roomId,List<SOrder> orderList,SCleanRecords cleanRecords,Date day, Integer orderType){
String nowTime = "00:00";
String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day);
Boolean isToday = StringUtils.equals(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day)
......@@ -78,19 +82,19 @@ public class RoomStatusServiceImpl implements RoomStatusService {
vo.setRoomId(roomId);
vo.setTimeHour(timeHour);
Date timeHourDate = DateUtils.parseDate(timeHour);
setTimeHourStatus(vo,timeHourDate,store,orderList,dayStr,finalNowTime,isToday,orderType);
setTimeHourStatus(vo,timeHourDate,store,orderList,cleanRecords,dayStr,finalNowTime,isToday,orderType);
voList.add(vo);
});
return voList;
}
//设置时间段房间可预约状态(可预约:大于营业开始时间,小于营业结束时间,大于当前时间,当前时间没有订单)
private void setTimeHourStatus(RoomStatusVo vo,Date timeHourDate, SStore store, List<SOrder> orderList, String day, String finalNowTime, Boolean isToday, Integer orderType){
private void setTimeHourStatus(RoomStatusVo vo,Date timeHourDate, SStore store, List<SOrder> orderList, SCleanRecords cleanRecords, String day, String finalNowTime, Boolean isToday, Integer orderType){
vo.setStatus(RoomStatusEnum.FREE.getValue());
checkTimeHourToSysDate(vo,timeHourDate,day,finalNowTime,isToday);
checkTimeHourToBusiness(vo,timeHourDate,store,day);
checkTimeHourToOrder(vo,timeHourDate,orderList,orderType);
checkTimeHourToOrder(vo,timeHourDate,orderList,cleanRecords,orderType);
}
private void changeEndHoldTime(RoomStatusVo vo, Date date){
......@@ -151,7 +155,7 @@ public class RoomStatusServiceImpl implements RoomStatusService {
}
}
private void checkTimeHourToOrder(RoomStatusVo vo,Date timeHourDate, List<SOrder> orderList, Integer orderType){
private void checkTimeHourToOrder(RoomStatusVo vo,Date timeHourDate, List<SOrder> orderList, SCleanRecords cleanRecords, Integer orderType){
SConsumer user = consumerService.getInfo();
if(CollectionUtils.isNotEmpty(orderList)){
orderList.stream().forEach(order -> {
......@@ -161,7 +165,15 @@ public class RoomStatusServiceImpl implements RoomStatusService {
//否则开始时间-30分钟保洁时间,结束时间+30分钟保洁时间
if(OrderTypeEnum.RESERVER.getCode().compareTo(orderType)==0
||Objects.isNull(user)||Objects.isNull(user.getId())||order.getConsumerId().compareTo(user.getId())!=0){
orderEndDate = DateUtils.addMinutes(orderEndDate,Constants.ROOM_LOCK_DELAY_MINUTE);
if(order.getStatus().compareTo(OrderStatusEnum.USED.getCode())==0&&Objects.nonNull(cleanRecords)
&&cleanRecords.getStatus().compareTo(CleaningStatusEnum.CLEANED.getCode())==0) {
if(cleanRecords.getEndDate().compareTo(orderEndDate)>0){
//如果订单结束 并且 最后一个保洁订单为保洁结束 并且保洁结束时间大于订单结束时间,设置结束时间为保洁结束时间
orderEndDate = cleanRecords.getEndDate();
}
}else{
orderEndDate = DateUtils.addMinutes(orderEndDate, Constants.ROOM_LOCK_DELAY_MINUTE);
}
orderStartDate = DateUtils.addMinutes(orderStartDate, -Constants.ROOM_LOCK_DELAY_MINUTE);
}
......
package share.system.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.date.DateUtil;
......@@ -265,6 +261,19 @@ public class SCleanRecordsServiceImpl extends ServiceImpl<SCleanRecordsMapper,SC
}
@Override
public SCleanRecords lastCleanByRoomId(Long roomId) {
LambdaQueryWrapper<SCleanRecords> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SCleanRecords::getRoomId, roomId);
queryWrapper.gt(SCleanRecords::getCreateTime,DateUtils.addDays(new Date(),-1));
List<SCleanRecords> records = list(queryWrapper);
if(CollectionUtils.isNotEmpty(records)){
Optional<SCleanRecords> cleanRecords = records.stream().max(Comparator.comparing(SCleanRecords::getCreateTime));
return cleanRecords.orElse(null);
}
return null;
}
@Override
public int endCleanRecords(SCleanRecords sCleanRecords) {
SCleanRecords records = baseMapper.selectSCleanRecordsById(sCleanRecords.getId());
if (records == null) {
......
......@@ -20,7 +20,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import share.common.constant.Constants;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
......@@ -100,6 +99,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired
private SmsService smsService;
@Autowired
private ISCleanRecordsService cleanRecordsService;
/**
* 查询订单
......@@ -464,9 +466,18 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
List<SOrder> orderList = list(queryWrapper);
if (CollectionUtils.isNotEmpty(orderList)) {
Optional<SOrder> lastOrderOp = orderList.stream().max(Comparator.comparing(SOrder::getPreEndDate));
SOrder lastOrder = lastOrderOp.orElse(null);
if(Objects.nonNull(lastOrder)&&Objects.nonNull(lastOrder.getEndDate())){
SCleanRecords sCleanRecords = cleanRecordsService.lastCleanByRoomId(lastOrder.getRoomId());
if(sCleanRecords.getStatus().compareTo(CleaningStatusEnum.CLEANED.getCode())==0
&&sCleanRecords.getEndDate().compareTo(lastOrder.getEndDate())>0
&&sCleanRecords.getEndDate().compareTo(request.getPreStartDate())<0){
return;
}
}
throw new BaseException("下单时间已被预定!");
}
}
private void checkOrderPrice(SOrder order, SConsumer user) {
......
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