| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.config.MinioConfig; |
| | | import com.gkhy.exam.common.constant.UserConstant; |
| | | import com.gkhy.exam.common.domain.entity.SysUser; |
| | | import com.gkhy.exam.common.enums.PrivatizeEnum; |
| | |
| | | public class ExResourceServiceImpl extends ServiceImpl<ExResourceMapper, ExResource> implements ExResourceService { |
| | | @Autowired |
| | | private SysCommonService commonService; |
| | | |
| | | @Autowired |
| | | private MinioConfig minioConfig; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public CommonPage selectResourseList(ExResource resource) { |
| | | SysUser currentUser = SecurityUtils.getLoginUser().getUser(); |
| | |
| | | } |
| | | PageUtils.startPage(); |
| | | List<ExResource> resourceList=baseMapper.selectResourceList(resource); |
| | | resourceList.forEach(item -> { |
| | | item.setResourcePath(minioConfig.getEndpoint()+minioConfig.getBucketName()+"/"+item.getResourcePath()); |
| | | }); |
| | | return CommonPage.restPage(resourceList); |
| | | } |
| | | |
| | |
| | | if(resource==null){ |
| | | return resource; |
| | | } |
| | | resource.setResourcePath(minioConfig.getEndpoint()+minioConfig.getBucketName()+"/"+resource.getResourcePath()); |
| | | if(resource.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | return resource; |
| | | } |
| | |
| | | if(!resource.getCompanyId().equals(currentUser.getCompanyId())){ |
| | | throw new ApiException("无权限查看其它企业资源"); |
| | | } |
| | | |
| | | return resource; |
| | | } |
| | | |
| | |
| | | if(resource==null){ |
| | | return resource; |
| | | } |
| | | resource.setResourcePath(minioConfig.getEndpoint()+minioConfig.getBucketName()+"/"+resource.getResourcePath()); |
| | | if(resource.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | return resource; |
| | | } |
| | |
| | | if(!checkNameUnique(resource)){ |
| | | throw new ApiException("资源名称已存在"); |
| | | } |
| | | String resourcePath=resource.getResourcePath(); |
| | | if(resourcePath.startsWith(minioConfig.getEndpoint()+minioConfig.getBucketName()+"/")) { |
| | | resourcePath = resourcePath.replace(minioConfig.getEndpoint()+minioConfig.getBucketName() + "/", ""); |
| | | resource.setResourcePath(resourcePath); |
| | | } |
| | | int row=baseMapper.updateById(resource); |
| | | if(row<1){ |
| | | throw new ApiException("更新资源失败"); |
| | |
| | | if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){ |
| | | throw new ApiException("没有权限操作"); |
| | | } |
| | | if(!currentUser.getCompanyId().equals(resource.getCompanyId())){ |
| | | if(resource.getCompanyId()!=null&&!currentUser.getCompanyId().equals(resource.getCompanyId())){ |
| | | throw new ApiException("没有权限操作其他企业资源"); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = RuntimeException.class) |
| | | public int deleteResourceById(Long resourceId) { |
| | | //校验资源是否绑定 |
| | | checkUserAllowed(baseMapper.selectById(resourceId)); |
| | | //校验资源是否绑定 |
| | | int count= baseMapper.checkResourceAssign(resourceId); |
| | | if(count>0){ |
| | | throw new ApiException("资源已跟课时关联,不能删除"); |
| | | } |
| | | ExResource resource=getById(resourceId); |
| | | int row=baseMapper.deleteById(resourceId); |
| | | if(row<1){ |