# AdjCheckUserEffectiveServiceImpl.java

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

    import cloud.wconnect.commonlib.cons.DataPermissionConfigConstant;
    import cloud.wconnect.commonlib.pojo.dto.UserDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.DataPermissionConfigInternalService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.frontoffice.service.adjustment.IAdjCheckUserEffectiveService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.ImmutableMap;
    import lombok.RequiredArgsConstructor;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;

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

    /**
     *
     * @author: yyt
     * 2026-03-19
     */
    @RequiredArgsConstructor
    @Service
    @DS("logbook")
    public class AdjCheckUserEffectiveServiceImpl implements IAdjCheckUserEffectiveService {

        private final UserInternalService userInternalService;
        private final PropertyI18nRedisService propertyI18nRedisService;
        private final DataPermissionConfigInternalService dataPermissionConfigInternalService;

        /**
         * 检查并返回有效的用户
         *
         * @param propertyId  资产 id
         * @param approverIds 审批人 id
         * @return 有效的用户
         * @author yyt
         * @date 2026/3/19
         **/
        @Override
        public List<Integer> checkUserEffective(Integer propertyId, List<Integer> approverIds) {
            Integer tenantId = propertyI18nRedisService.get(propertyId).getTenantId();
            approverIds = userInternalService.getUsers(tenantId, approverIds).stream().filter(UserDTO::getStatus).map(UserDTO::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(approverIds)) return Collections.emptyList();

            Map<Integer, Boolean> haPermissionByUserId = dataPermissionConfigInternalService.checkContainsApi(tenantId, propertyId,
                    ImmutableMap.of(DataPermissionConfigConstant.IDENTITY_TYPE_USER, new HashSet<>(approverIds)),
                    DataPermissionConfigConstant.ADJ_APPROVE_API_ID).getOrDefault(DataPermissionConfigConstant.IDENTITY_TYPE_USER, Collections.emptyMap());
            return approverIds.stream().filter(item -> haPermissionByUserId.getOrDefault(item, false)).toList();
        }

    }