|
|
@@ -1,5 +1,11 @@
|
|
|
package com.chuanghai.ihotel.service.impl;
|
|
|
|
|
|
+import com.chuanghai.ihotel.controller.request.RoomTypeQueryRequest;
|
|
|
+import com.chuanghai.ihotel.service.RoomRealtimeStatuService;
|
|
|
+import com.chuanghai.ihotel.vo.RoomTypeShortDescVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -12,18 +18,45 @@ import com.chuanghai.ihotel.dao.RoomTypeDao;
|
|
|
import com.chuanghai.ihotel.entity.RoomTypeEntity;
|
|
|
import com.chuanghai.ihotel.service.RoomTypeService;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
@Service("roomTypeService")
|
|
|
public class RoomTypeServiceImpl extends ServiceImpl<RoomTypeDao, RoomTypeEntity> implements RoomTypeService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RoomRealtimeStatuService roomRealtimeStatuService;
|
|
|
+
|
|
|
@Override
|
|
|
public PageUtils queryPage(PageParam pageParam) {
|
|
|
IPage<RoomTypeEntity> page = this.page(
|
|
|
new MyQuery<RoomTypeEntity>().getPage(pageParam),
|
|
|
- new QueryWrapper<RoomTypeEntity>()
|
|
|
+ new QueryWrapper<>()
|
|
|
);
|
|
|
|
|
|
return new PageUtils(page);
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = {"roomType"},key = "#root.method.name + '-' + #request.startTime + '-' + #request.endTime")
|
|
|
+ @Override
|
|
|
+ public List<RoomTypeShortDescVO> listForClientIndex(RoomTypeQueryRequest request) {
|
|
|
+ List<RoomTypeEntity> all = this.list();
|
|
|
+ List<RoomTypeShortDescVO> vos = all.stream().map(e -> {
|
|
|
+ RoomTypeShortDescVO vo = new RoomTypeShortDescVO();
|
|
|
+ BeanUtils.copyProperties(e, vo);
|
|
|
+
|
|
|
+ // 获取主图
|
|
|
+ String masterImage = e.getTypeImage().split(",")[0];
|
|
|
+ vo.setMasterImage(masterImage);
|
|
|
+
|
|
|
+ // 获取当前时间繁忙状态的房间数量
|
|
|
+ int num = roomRealtimeStatuService.getBusyNum(e.getId(), request.getStartTime(), request.getEndTime());
|
|
|
+ int enableNum = e.getRoomNum() - num;
|
|
|
+ vo.setEnableNum(enableNum >= 0 ? enableNum : 0);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
}
|