| | |
| | | import com.gkhy.common.core.domain.entity.SysRole; |
| | | import com.gkhy.common.core.domain.entity.SysUser; |
| | | import com.gkhy.common.core.domain.model.LoginUser; |
| | | import com.gkhy.common.exception.ServiceException; |
| | | 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; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @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) { |
| | |
| | | @Override |
| | | public int updateHazards(HazardsEditDTO dto) { |
| | | |
| | | checkPer(); |
| | | Hazards hazards = hazardsMapper.selectById(dto.getId()); |
| | | if (hazards == null){ |
| | | throw new ServiceException("没有此数据"); |
| | | } |
| | | if (!hazards.getReformUserId().toString().equals(SecurityUtils.getUserId().toString())){ |
| | | throw new ServiceException("只能整改本人数据"); |
| | | } |
| | | Hazards inspection = new Hazards(); |
| | | inspection.setId(dto.getId()); |
| | | inspection.setReformPeriod(dto.getReformPeriod()); |
| | |
| | | } |
| | | |
| | | 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){ |
| | | throw new RuntimeException("没有权限"); |
| | | } |
| | | } |
| | | |
| | | // boolean admin = SecurityUtils.isAdmin(SecurityUtils.getUserId()); |
| | | // if (!admin){ |
| | | // 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("没有权限"); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | |