|
|
@@ -0,0 +1,153 @@
|
|
|
+package org.dromara.backstage.basics.service.impl;
|
|
|
+
|
|
|
+import org.dromara.backstage.basics.domain.PtRoom;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.backstage.basics.domain.bo.PtRoomTypeBo;
|
|
|
+import org.dromara.backstage.basics.domain.vo.PtRoomTypeVo;
|
|
|
+import org.dromara.backstage.basics.domain.PtRoomType;
|
|
|
+import org.dromara.backstage.basics.mapper.PtRoomTypeMapper;
|
|
|
+import org.dromara.backstage.basics.service.IPtRoomTypeService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 房型管理Service业务层处理
|
|
|
+ *
|
|
|
+ * @author bing
|
|
|
+ * @date 2024-11-14
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class PtRoomTypeServiceImpl implements IPtRoomTypeService {
|
|
|
+
|
|
|
+ private final PtRoomTypeMapper baseMapper;
|
|
|
+
|
|
|
+ private final PtRoomServiceImpl roomService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询房型管理
|
|
|
+ *
|
|
|
+ * @param roomTypeId 主键
|
|
|
+ * @return 房型管理
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PtRoomTypeVo queryById(Long roomTypeId){
|
|
|
+ return baseMapper.selectVoById(roomTypeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询房型管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 房型管理分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<PtRoomTypeVo> queryPageList(PtRoomTypeBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<PtRoomType> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<PtRoomTypeVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的房型管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 房型管理列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PtRoomTypeVo> queryList(PtRoomTypeBo bo) {
|
|
|
+ LambdaQueryWrapper<PtRoomType> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<PtRoomType> buildQueryWrapper(PtRoomTypeBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<PtRoomType> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getRoomTypeName()), PtRoomType::getRoomTypeName, bo.getRoomTypeName());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ private QueryWrapper<PtRoomType> buildQueryWrapper(PtRoomTypeBo bo,String tableAlias) {
|
|
|
+ QueryWrapper<PtRoomType> lqw = new QueryWrapper<>();
|
|
|
+ String columnPrefix = "";
|
|
|
+ if(StringUtils.isNotBlank(tableAlias)){
|
|
|
+ columnPrefix = tableAlias + ".";
|
|
|
+ }
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getRoomTypeName()), columnPrefix+"room_type_name", bo.getRoomTypeName());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增房型管理
|
|
|
+ *
|
|
|
+ * @param bo 房型管理
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(PtRoomTypeBo bo) {
|
|
|
+ PtRoomType add = MapstructUtils.convert(bo, PtRoomType.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setRoomTypeId(add.getRoomTypeId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改房型管理
|
|
|
+ *
|
|
|
+ * @param bo 房型管理
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(PtRoomTypeBo bo) {
|
|
|
+ PtRoomType update = MapstructUtils.convert(bo, PtRoomType.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(PtRoomType entity){
|
|
|
+ //做一些数据校验,如唯一约束 房间类型不能重复
|
|
|
+ LambdaQueryWrapper<PtRoomType> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(PtRoomType::getRoomTypeName, entity.getRoomTypeName());
|
|
|
+ wrapper.ne(entity.getRoomTypeId()!=null,PtRoomType::getRoomTypeId, entity.getRoomTypeId());
|
|
|
+ if (baseMapper.selectCount(wrapper) > 0) {
|
|
|
+ throw new ServiceException("房间类型已经存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除房型管理信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //做一些业务上的校验,判断是否需要校验
|
|
|
+ if(roomService.count(ids) > 0){
|
|
|
+ throw new ServiceException("该房型下有房间,不能删除");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|