package com.ruoyi.bst.fault.service.impl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.fault.domain.FaultQuery;
import com.ruoyi.bst.fault.mapper.FaultMapper;
import com.ruoyi.bst.fault.service.FaultValidator;

@Service
public class FaultValidatorImpl implements FaultValidator {

    @Autowired
    private FaultMapper faultMapper;

    @Override
    public boolean canEdit(Long faultId) {
        return hasPermission(Arrays.asList(faultId), AreaJoinPermission.FAULT_EDIT.getCode());
    }

    // 是否拥有权限
    private boolean hasPermission(List<Long> faultIds, String permission) {
        FaultQuery query = new FaultQuery();
        query.setIds(faultIds);
        query.setScope(true);
        query.addAreaPermission(permission);
        List<Long> faultList = faultMapper.selectIdByQuery(query);
        return new HashSet<>(faultList).containsAll(faultIds);
    }

}
