Commit 42c80f85 by 吕明尚

订单换房接口

parent 057f8f2a
...@@ -136,4 +136,19 @@ public class SOrderController extends BaseController ...@@ -136,4 +136,19 @@ public class SOrderController extends BaseController
return toAjax(sOrderService.refundOp(request)); return toAjax(sOrderService.refundOp(request));
} }
//查询当前门店可更换房间列表
@GetMapping("/changeRoomList")
public AjaxResult changeRoomList(@PathVariable("id") Long id) {
return success(sOrderService.changeRoomList(id));
}
/**
* 更换房间
*/
@PostMapping("/changeRoom")
public AjaxResult changeRoom(@RequestBody SOrderDto dto) {
return success(sOrderService.changeRoom(dto));
}
} }
...@@ -4,10 +4,16 @@ import lombok.Data; ...@@ -4,10 +4,16 @@ import lombok.Data;
@Data @Data
public class SOrderDto { public class SOrderDto {
//订单ID
private Long id;
//新房间id
private Long roomId;
//订单滨海 //订单滨海
private String orderNo; private String orderNo;
//是否消劵 //是否消劵
private Integer isReverseconsume; private Integer isReverseconsume;
//是否生成保洁
private Integer isClean;
//备注 //备注
private String remark; private String remark;
} }
...@@ -6,6 +6,7 @@ import share.system.domain.SConsumerCoupon; ...@@ -6,6 +6,7 @@ import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder; import share.system.domain.SOrder;
import share.system.domain.vo.SOrderDto; import share.system.domain.vo.SOrderDto;
import share.system.domain.vo.SOrderVo; import share.system.domain.vo.SOrderVo;
import share.system.domain.vo.SRoomVo;
import share.system.request.AdminRefundRequest; import share.system.request.AdminRefundRequest;
import share.system.request.CreateOrderRequest; import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest; import share.system.request.OrderComputedPriceRequest;
...@@ -202,4 +203,9 @@ public interface ISOrderService extends IService<SOrder> ...@@ -202,4 +203,9 @@ public interface ISOrderService extends IService<SOrder>
int refundOp(AdminRefundRequest request); int refundOp(AdminRefundRequest request);
List<SOrder> queryOrderList(SOrder sOrder); List<SOrder> queryOrderList(SOrder sOrder);
List<SRoomVo> changeRoomList(Long id);
String changeRoom(SOrderDto dto);
} }
...@@ -494,6 +494,95 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -494,6 +494,95 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return baseMapper.queryList(sOrder.getRoomId()); return baseMapper.queryList(sOrder.getRoomId());
} }
@Override
public List<SRoomVo> changeRoomList(Long id) {
//查询订单
SOrder sOrder = getById(id);
//查询当前门店下所有的房间
LambdaQueryWrapper<SRoom> queryWrapper = new LambdaQueryWrapper<>();
//当前门店
queryWrapper.eq(SRoom::getStoreId, sOrder.getStoreId());
//状态为空闲
queryWrapper.eq(SRoom::getStatus, YesNoEnum.no.getIndex());
//去除当前房间
queryWrapper.ne(SRoom::getId, sOrder.getRoomId());
//房间状态为上架
queryWrapper.eq(SRoom::getRoomStat, YesNoEnum.yes.getIndex());
List<SRoom> list = roomService.list(queryWrapper);
if (CollectionUtils.isEmpty(list)) {
throw new BaseException("当前门店没有空闲房间");
}
List<Long> roomIds = list.stream().map(SRoom::getId).collect(Collectors.toList());
//查询当前房间是否有保洁
LambdaQueryWrapper<SCleanRecords> cleanRecordsQueryWrapper = new LambdaQueryWrapper<>();
cleanRecordsQueryWrapper.in(SCleanRecords::getRoomId, roomIds);
cleanRecordsQueryWrapper.ne(SCleanRecords::getStatus, CleaningStatusEnum.CLEANED.getCode());
List<SCleanRecords> sCleanRecords = isCleanRecordsService.list(cleanRecordsQueryWrapper);
if (CollectionUtils.isNotEmpty(sCleanRecords)) {
//去掉保洁中的房间
List<Long> cleanRoomIds = Optional.ofNullable(sCleanRecords).orElse(new ArrayList<>()).parallelStream().map(SCleanRecords::getRoomId).collect(Collectors.toList());
//获取不在保洁的房间
list = list.stream().filter(sRoom -> !cleanRoomIds.contains(sRoom.getId())).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(list)) {
throw new BaseException("当前门店没有空闲房间");
}
//查询剩余房间的订单时段是否被占用
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getValidOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
sOrderLambdaQueryWrapper.eq(SOrder::getStoreId, sOrder.getStoreId());
sOrderLambdaQueryWrapper.in(SOrder::getRoomId, list.stream().map(SRoom::getId).collect(Collectors.toList()));
queryWrapper.apply("(IFNULL(start_date,pre_start_date) BETWEEN '"
+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sOrder.getPreStartDate())
+ "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(sOrder.getPreEndDate(), Constants.ROOM_LOCK_DELAY_MINUTE)) + "' " +
"OR IFNULL(end_date,pre_end_date) BETWEEN '"
+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(sOrder.getPreStartDate(), -Constants.ROOM_LOCK_DELAY_MINUTE))
+ "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sOrder.getPreEndDate()) + "' )");
List<SOrder> orderList = list(sOrderLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(orderList)) {
//去掉被占用的房间
List<Long> orderRoomIds = Optional.ofNullable(orderList).orElse(new ArrayList<>()).parallelStream().map(SOrder::getRoomId).collect(Collectors.toList());
list = list.stream().filter(sRoom -> !orderRoomIds.contains(sRoom.getId())).collect(Collectors.toList());
}
return list.stream().map(sRoom -> {
SRoomVo sRoomVo = new SRoomVo();
BeanUtils.copyProperties(sRoom, sRoomVo);
return sRoomVo;
}).collect(Collectors.toList());
}
@Override
public String changeRoom(SOrderDto dto) {
SOrder sOrder = getById(dto.getId());
// 判断原房间是否生成保洁
if (dto.getIsClean().equals(YesNoEnum.yes.getIndex())) {
//判断订单是否已经添加保洁记录
SCleanRecords cleanRecords = isCleanRecordsService.lastCleanByRoomId(sOrder.getRoomId());
if (ObjectUtil.isEmpty(cleanRecords) || cleanRecords.getStatus().equals(CleaningStatusEnum.CLEANED.getCode())) {
//房间添加保洁记录
boolean b = isCleanRecordsService.addSCleanRecords(sOrder.getStoreId(), sOrder.getRoomId());
}
}
//原订单是否使用中
if (sOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode())) {
// 使用中订单断电, 延时3分钟断电
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(),
OpTypeEnum.CUT_ELECTRIC.getCode(), false, 0);
//修改原房间状态
SRoom sRoom = new SRoom();
sRoom.setId(sOrder.getRoomId());
sRoom.setStatus(RoomStatusEnum.FREE.getValue());
roomService.updateById(sRoom);
}
//发送短信
sOrder.setRoomId(dto.getRoomId());
updateById(sOrder);
return null;
}
/** /**
* 新增订单 * 新增订单
* *
......
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