# WalkRoomApproveConfigServiceImpl.java

    package cloud.wconnect.frontoffice.service.walkroomrequest.impl;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.frontoffice.entity.walkroomrequest.WalkRoomApproveConfig;
    import cloud.wconnect.frontoffice.mapper.walkroomrequest.WalkRoomApproveConfigMapper;
    import cloud.wconnect.frontoffice.service.walkroomrequest.IWalkRoomApproveConfigService;
    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.stereotype.Service;

    import java.util.*;
    import java.util.stream.Collectors;

    /**
     * <p>
     * walk room审批配置表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-07-08
     */
    @Service
    @DS("logbook")
    public class WalkRoomApproveConfigServiceImpl extends ServiceImpl<WalkRoomApproveConfigMapper, WalkRoomApproveConfig> implements IWalkRoomApproveConfigService {

        /**
         * 根据审批级别id集合查询审批配置信息
         *
         * @param levelIds 审批级别id集合
         * @return java.util.List<cloud.wconnect.frontoffice.entity.walkroom.WalkRoomApproveConfig>
         * @author lichen
         * @date 2023/7/11
         */
        @Override
        public List<WalkRoomApproveConfig> listByLevelIds(Collection<Long> levelIds) {
            if (CollectionUtils.isEmpty(levelIds)) return Collections.emptyList();
            return list(new LambdaQueryWrapper<WalkRoomApproveConfig>()
                    .in(WalkRoomApproveConfig::getLevelId, levelIds));
        }

        /**
         * 根据资产id和审批类型 查询审批配置人员
         *
         * @param propertyId    资产id
         * @param type          审批类型1:Sent 2:Receive
         * @param ignoreLevelId 忽略的审批级别id
         * @return java.util.List<cloud.wconnect.frontoffice.entity.walkroom.WalkRoomApproveConfig>
         * @author lichen
         * @date 2023/7/12
         */
        @Override
        public List<WalkRoomApproveConfig> listByPropertyIdAndType(Integer propertyId, Integer type, Long ignoreLevelId) {
            return list(new LambdaQueryWrapper<WalkRoomApproveConfig>()
                    .eq(WalkRoomApproveConfig::getPropertyId, propertyId)
                    .eq(WalkRoomApproveConfig::getType, type)
                    .ne(ignoreLevelId > BaseConstant.LONG_ZERO, WalkRoomApproveConfig::getLevelId, ignoreLevelId));
        }

        /**
         * 检查用户是否重复
         *
         * @param propertyId 资产id
         * @param type       审批类型1:Sent 2:Receive
         * @param userIds    用户id集合
         * @param ignoreId   忽略的审批配置id
         * @author lichen
         * @date 2025/12/30
         */
        @Override
        public void checkUserRepeat(int propertyId, Integer type, List<Integer> userIds, Long ignoreId) {
            List<WalkRoomApproveConfig> approvedConfigs = listByPropertyIdAndType(propertyId, type, ignoreId);
            if (CollectionUtils.isNotEmpty(approvedConfigs)) {
                //配置的用户id集合
                List<Integer> configUserIds = approvedConfigs.stream().map(WalkRoomApproveConfig::getUserId).collect(Collectors.toList());
                //校验用户是否已经存在其他审批级别中
                if (org.apache.commons.collections4.CollectionUtils.containsAny(configUserIds, userIds)) {
                    throw new BadRequestException(CommonErrorI18nConstant.APPROVE_USER_ALREADY_EXIST,
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                            "user already exist approve setting");
                }
            }
        }

    }