| | |
| | | |
| | | @Override |
| | | public ExResource selectResourceById(Long resourceId) { |
| | | return baseMapper.selectResourceById(resourceId); |
| | | ExResource resource= baseMapper.selectResourceById(resourceId); |
| | | if(resource==null){ |
| | | return resource; |
| | | } |
| | | if(resource.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | return resource; |
| | | } |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | return resource; |
| | | } |
| | | if(!resource.getCompanyId().equals(currentUser.getCompanyId())){ |
| | | throw new ApiException("无权限查看其它企业资源"); |
| | | } |
| | | return resource; |
| | | } |
| | | |
| | | @Override |
| | | public ExResource selectResourceByPeriodId(Long periodId) { |
| | | return baseMapper.selectResourceByPeriodId(periodId); |
| | | ExResource resource= baseMapper.selectResourceByPeriodId(periodId); |
| | | if(resource==null){ |
| | | return resource; |
| | | } |
| | | if(resource.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | return resource; |
| | | } |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | return resource; |
| | | } |
| | | if(!resource.getCompanyId().equals(currentUser.getCompanyId())){ |
| | | throw new ApiException("无权限查看其它企业资源"); |
| | | } |
| | | return resource; |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int insertResource(ExResource resource) { |
| | | checkUserAllowed(resource); |
| | | if(!checkNameUnique(resource)){ |
| | | throw new ApiException("资源名称已存在"); |
| | | } |
| | |
| | | if(user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | resource.setPrivatize(PrivatizeEnum.PUBLIC.getCode()); |
| | | }else{ |
| | | if(user.getCompanyId()==null){ |
| | | throw new ApiException("获取用户公司id失败"); |
| | | } |
| | | resource.setCompanyId(user.getCompanyId()); |
| | | resource.setPrivatize(PrivatizeEnum.PRIVATE.getCode()); |
| | | } |
| | | UploadObjectVO uploadObjectVO =commonService.doUpload(resource.getFile()); |
| | | resource.setResourceUri(uploadObjectVO.getPath()); |
| | |
| | | |
| | | @Override |
| | | public int updateResource(ExResource resource) { |
| | | checkUserAllowed(resource); |
| | | if(!checkNameUnique(resource)){ |
| | | throw new ApiException("资源名称已存在"); |
| | | } |
| | |
| | | return row; |
| | | } |
| | | |
| | | public void checkUserAllowed(ExResource resource) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | return; |
| | | } |
| | | if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){ |
| | | throw new ApiException("没有权限操作"); |
| | | } |
| | | if(!currentUser.getCompanyId().equals(resource.getCompanyId())){ |
| | | throw new ApiException("没有权限操作其他企业资源"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int deleteResourceById(Long resourceId) { |
| | | //校验资源是否绑定 |
| | | checkUserAllowed(baseMapper.selectById(resourceId)); |
| | | ExResource resource=getById(resourceId); |
| | | int row=baseMapper.deleteById(resourceId); |
| | | if(row<1){ |