# RoomTypeInfoRelServiceImpl.java

    package cloud.wconnect.rateshop.service.rateshop.impl;

    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.rateshop.entity.rateshop.RoomTypeInfoRel;
    import cloud.wconnect.rateshop.mapper.rateshop.RoomTypeInfoRelMapper;
    import cloud.wconnect.rateshop.service.rateshop.IRoomTypeInfoRelService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.Collections;
    import java.util.List;
    import java.util.stream.Collectors;

    /**
     * <p>
     * rateShop功能维护的房间类型和采集的房型关系表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2024-05-14
     */
    @Service
    @DS("rate_shop")
    public class RoomTypeInfoRelServiceImpl extends ServiceImpl<RoomTypeInfoRelMapper, RoomTypeInfoRel> implements IRoomTypeInfoRelService {

        @Autowired
        private UpdateLogUtil updateLogUtil;

        /**
         * 根据房间类型查询对应的实际房型
         *
         * @param propertyId 资产ID
         * @param roomTypeId 房间类型ID
         * @return java.util.List<cloud.wconnect.rateshop.entity.rateshop.RoomTypeInfoRel>
         * @author lichen
         * @date 2024/5/14
         */
        @Override
        public List<RoomTypeInfoRel> listByTypeId(Integer propertyId, Integer roomTypeId) {
            return list(new LambdaQueryWrapper<RoomTypeInfoRel>()
                    .eq(RoomTypeInfoRel::getPropertyId, propertyId)
                    .eq(RoomTypeInfoRel::getRoomTypeId, roomTypeId));
        }

        /**
         * 保存roomType和roomInfo的关系
         *
         * @param propertyId 资产ID
         * @param roomTypeId 类型ID，等于0时表示删除绑定关系
         * @param roomInfoId 房型ID
         * @param userId     用户ID
         * @return void
         * @author lichen
         * @date 2024/7/10
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(Integer propertyId, Integer roomTypeId, Integer roomInfoId, int userId) {
            //删除roomInfo在指定资产下的关系
            remove(new LambdaQueryWrapper<RoomTypeInfoRel>()
                    .eq(RoomTypeInfoRel::getPropertyId, propertyId)
                    .eq(RoomTypeInfoRel::getRoomInfoId, roomInfoId));

            if (roomTypeId > 0) {
                //新增关系
                RoomTypeInfoRel roomTypeInfoRel = new RoomTypeInfoRel()
                        .setPropertyId(propertyId)
                        .setRoomTypeId(roomTypeId)
                        .setRoomInfoId(roomInfoId)
                        .setUpdateLog(updateLogUtil.get(userId));
                save(roomTypeInfoRel);
            }
        }

        /**
         * 根据房型ID查询对应的房间类型
         *
         * @param propertyId  资产ID
         * @param roomInfoIds 房型ID
         * @return java.util.List<cloud.wconnect.rateshop.entity.rateshop.RoomTypeInfoRel>
         * @author lichen
         * @date 2025/12/30
         */
        @Override
        public List<RoomTypeInfoRel> listByRoomInfoId(int propertyId, List<Integer> roomInfoIds) {
            if (CollectionUtils.isEmpty(roomInfoIds)) {
                return Collections.emptyList();
            }
            return list(new LambdaQueryWrapper<RoomTypeInfoRel>()
                    .eq(RoomTypeInfoRel::getPropertyId, propertyId)
                    .in(RoomTypeInfoRel::getRoomInfoId, roomInfoIds));
        }

    }