heheng
2025-09-23 733d48f803a002033c5f1d6c22dcc799bf1b724c
gkhy-system/src/main/java/com/gkhy/system/service/impl/HazardsServiceImpl.java
@@ -8,7 +8,6 @@
import com.gkhy.common.core.domain.entity.SysUser;
import com.gkhy.common.core.domain.model.LoginUser;
import com.gkhy.common.utils.SecurityUtils;
import com.gkhy.system.domain.DailySafetyInspection;
import com.gkhy.system.domain.Hazards;
import com.gkhy.system.domain.dto.HazardsEditDTO;
import com.gkhy.system.mapper.HazardsMapper;
@@ -17,7 +16,6 @@
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
/**
@@ -38,8 +36,22 @@
    @Override
    public List<Hazards> getHazardsList(Hazards hazards) {
        if (hazards != null && "2".equals(hazards.getHazardsType())){
            boolean b = check2Per();
            if (!b){
                hazards.setReformUserId(SecurityUtils.getUserId());
            }
        }
        return hazardsMapper.getHazardsList(hazards);
    }
    boolean check2Per(){
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId()) || SecurityUtils.hasRole(Constants.SYS_ADMIN) || SecurityUtils.hasRole(Constants.PLACE_SAFETY_OFFICER)){
            return true;
        }
        return false;
    }
    @Override
    public int saveHazards(Hazards inspection) {
@@ -75,13 +87,17 @@
    private void checkPer(){
        boolean admin = SecurityUtils.isAdmin(SecurityUtils.getUserId());
        if (!admin){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            List<SysRole> roles = user.getRoles();
            long sysAdmin = roles.stream().filter(role -> role.getRoleKey().equals(Constants.SYS_ADMIN)).count();
            if (sysAdmin == 0){
            boolean placeSafetyOfficer = SecurityUtils.hasRole(Constants.SYS_ADMIN);
            if (!placeSafetyOfficer){
                throw new RuntimeException("没有权限");
            }
//            LoginUser loginUser = SecurityUtils.getLoginUser();
//            SysUser user = loginUser.getUser();
//            List<SysRole> roles = user.getRoles();
//            long sysAdmin = roles.stream().filter(role -> role.getRoleKey().equals(Constants.SYS_ADMIN)).count();
//            if (sysAdmin == 0){
//                throw new RuntimeException("没有权限");
//            }
        }
    }