RoomServiceImpl.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.chuanghai.ihotel.service.impl;
  2. import com.chuanghai.ihotel.common.exception.BizCodeEnume;
  3. import com.chuanghai.ihotel.common.exception.RRException;
  4. import com.chuanghai.ihotel.controller.request.RoomQueryRequest;
  5. import com.chuanghai.ihotel.entity.RoomTypeEntity;
  6. import com.chuanghai.ihotel.service.RoomTypeService;
  7. import com.chuanghai.ihotel.vo.RoomGroupVO;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.cache.annotation.Cacheable;
  10. import org.springframework.stereotype.Service;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.baomidou.mybatisplus.core.metadata.IPage;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.chuanghai.ihotel.common.utils.PageUtils;
  15. import com.chuanghai.ihotel.common.utils.MyQuery;
  16. import com.chuanghai.ihotel.common.utils.PageParam;
  17. import com.chuanghai.ihotel.dao.RoomDao;
  18. import com.chuanghai.ihotel.entity.RoomEntity;
  19. import com.chuanghai.ihotel.service.RoomService;
  20. import org.springframework.util.StringUtils;
  21. import java.util.Map;
  22. @Service("roomService")
  23. public class RoomServiceImpl extends ServiceImpl<RoomDao, RoomEntity> implements RoomService {
  24. @Autowired
  25. private RoomTypeService roomTypeService;
  26. @Cacheable(value = {"room"}, key = "#root.method.name " +
  27. "+ '-' + #pageParam.curPage " +
  28. "+ '-' + #pageParam.pageSize " +
  29. "+ '-' + #pageParam.orderField " +
  30. "+ '-' + #pageParam.order " +
  31. "+ '-' + #request.roomNo " +
  32. "+ '-' + #request.build " +
  33. "+ '-' + #request.floor " +
  34. "+ '-' + #request.roomTypeId")
  35. @Override
  36. public PageUtils queryPage(PageParam pageParam, RoomQueryRequest request) {
  37. QueryWrapper<RoomEntity> queryWrapper = new QueryWrapper<>();
  38. queryWrapper.eq(StringUtils.hasText(request.getRoomNo()), "room_no", request.getRoomNo());
  39. queryWrapper.eq(StringUtils.hasText(request.getBuild()), "build", request.getBuild());
  40. queryWrapper.eq(StringUtils.hasText(request.getFloor()), "floor", request.getFloor());
  41. queryWrapper.eq(request.getRoomTypeId() != null, "room_type_id", request.getRoomTypeId());
  42. IPage<RoomEntity> page = this.page(
  43. new MyQuery<RoomEntity>().getPage(pageParam),
  44. queryWrapper
  45. );
  46. return new PageUtils(page);
  47. }
  48. @Cacheable(value = {"room"},
  49. key = "#root.method.name " +
  50. "+ '-' + #pageParam.curPage " +
  51. "+ '-' + #pageParam.pageSize " +
  52. "+ '-' + #pageParam.orderField " +
  53. "+ '-' + #pageParam.order " +
  54. "+ '-' + #request.roomNo " +
  55. "+ '-' + #request.build " +
  56. "+ '-' + #request.floor " +
  57. "+ '-' + #request.roomTypeId")
  58. @Override
  59. public PageUtils queryPageGroup(PageParam pageParam, RoomQueryRequest request) {
  60. IPage<RoomGroupVO> page =this.getBaseMapper().queryPageGroup(new MyQuery<RoomEntity>().getPage(pageParam), request);
  61. return new PageUtils<>(page);
  62. }
  63. @Override
  64. public void mySave(RoomEntity room) {
  65. // 检测房型是否存在
  66. RoomTypeEntity roomType = roomTypeService.getById(room.getRoomTypeId());
  67. if (roomType == null) {
  68. throw new RRException(BizCodeEnume.PARAMETER_ERROR, "无效的roomTypeId");
  69. }
  70. room.setRoomTypeName(roomType.getTypeName());
  71. this.save(room);
  72. }
  73. }