WANG 6 yıl önce
ebeveyn
işleme
4c98f58dfb

+ 41 - 35
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/ResourceController.java

@@ -49,23 +49,26 @@ import io.swagger.annotations.ApiOperation;
 @RestController
 @RequestMapping("${$rmp.ctr.basic}/resource")
 public class ResourceController extends ControllerSupport {
-	
+
 	@Value("${$upyun.site.1.domain}")
 	private String upyunFileUrl;
+
 	@Autowired
 	private ResourceRepo resourceRepo;
+
 	@Autowired
 	private ResourceService resourceService;
-	
+
 	@ApiOperation(value = "分页查询资源")
 	@GetMapping("page/{pageNo}/{pageSize}")
-	public PageInfo<ResourceDomain> getPage(@PathVariable Integer pageNo, @PathVariable Integer pageSize,
-			@RequestParam(required = false) String name,
-			@RequestParam(required = false) Long parentId,@RequestParam(required = true) Long rootOrgId) {
+	public PageInfo<ResourceDomain> getPage(@PathVariable Integer pageNo,
+			@PathVariable Integer pageSize, @RequestParam(required = false) String name,
+			@RequestParam(required = false) Long parentId,
+			@RequestParam(required = true) Long rootOrgId) {
 
-		if(!isSuperAdmin()) {
+		if (!isSuperAdmin()) {
 			User accessUser = getAccessUser();
-			if(!rootOrgId.equals(accessUser.getRootOrgId())) {
+			if (!rootOrgId.equals(accessUser.getRootOrgId())) {
 				throw new StatusException("100000", "无效的请求");
 			}
 		}
@@ -78,16 +81,16 @@ public class ResourceController extends ControllerSupport {
 			if (StringUtils.isNotBlank(name)) {
 				predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
 			}
-			if (null == parentId||-1 == parentId) {
+			if (null == parentId || -1 == parentId) {
 				predicates.add(cb.isNull(root.get("parentId")));
-			}else {
+			} else {
 				predicates.add(cb.equal(root.get("parentId"), parentId));
 			}
 
-
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
-		PageRequest pageRequest = PageRequest.of(pageNo, pageSize, new Sort(Direction.ASC,"isFile").and(new Sort(Direction.DESC,"creationTime")));
+		PageRequest pageRequest = PageRequest.of(pageNo, pageSize,
+				new Sort(Direction.ASC, "isFile").and(new Sort(Direction.DESC, "creationTime")));
 
 		Page<ResourceEntity> page = resourceRepo.findAll(specification, pageRequest);
 		Iterator<ResourceEntity> iterator = page.iterator();
@@ -98,7 +101,7 @@ public class ResourceController extends ControllerSupport {
 			ResourceEntity next = iterator.next();
 			ResourceDomain bean = new ResourceDomain();
 			BeanUtils.copyProperties(next, bean);
-			bean.setFileUrl(upyunFileUrl+bean.getFilePath());
+			bean.setFileUrl(upyunFileUrl + bean.getFilePath());
 			resourceDomainList.add(bean);
 		}
 		PageInfo<ResourceDomain> ret = new PageInfo<ResourceDomain>();
@@ -109,40 +112,43 @@ public class ResourceController extends ControllerSupport {
 
 	@ApiOperation(value = "新增资源")
 	@PostMapping("addFile")
-	public void addResource(@RequestParam @NotNull(message = "RootOrgId不能为空!") Long rootOrgId,@RequestParam @NotNull(message = "parentId不能为空!") Long parentId,
-            @RequestPart @NotNull(message = "上传文件不能为空!") MultipartFile dataFile) {
-		if(!isSuperAdmin()) {
+	public void addResource(@RequestParam @NotNull(message = "RootOrgId不能为空!") Long rootOrgId,
+			@RequestParam @NotNull(message = "parentId不能为空!") Long parentId,
+			@RequestPart @NotNull(message = "上传文件不能为空!") MultipartFile dataFile) {
+		if (!isSuperAdmin()) {
 			User accessUser = getAccessUser();
-			if(!rootOrgId.equals(accessUser.getRootOrgId())) {
+			if (!rootOrgId.equals(accessUser.getRootOrgId())) {
 				throw new StatusException("100021", "无效的请求");
 			}
 		}
-		String fileName=dataFile.getOriginalFilename();
-		String regex="^[a-zA-Z\\-_0-9.]{1,50}$";
-		if(!Pattern.matches(regex, fileName)) {
+		String fileName = dataFile.getOriginalFilename();
+		String regex = "^[a-zA-Z\\-_0-9.]{1,50}$";
+		if (!Pattern.matches(regex, fileName)) {
 			throw new StatusException("100022", "文件名长度最大为50且只能包含字母,数字,'-','_','.'");
 		}
-		resourceService.addFile(rootOrgId,parentId,dataFile);
+		resourceService.addFile(rootOrgId, parentId, dataFile);
 	}
+
 	@ApiOperation(value = "删除资源")
 	@DeleteMapping("/{id}")
 	public void delResource(@PathVariable Long id) {
-		Optional<ResourceEntity>  op=resourceRepo.findById(id);
-		if(op.isPresent()) {
-			ResourceEntity e=op.get();
-			if(!isSuperAdmin()) {
+		Optional<ResourceEntity> op = resourceRepo.findById(id);
+		if (op.isPresent()) {
+			ResourceEntity e = op.get();
+			if (!isSuperAdmin()) {
 				User accessUser = getAccessUser();
-				if(!e.getRootOrgId().equals(accessUser.getRootOrgId())) {
+				if (!e.getRootOrgId().equals(accessUser.getRootOrgId())) {
 					throw new StatusException("100031", "无效的请求");
 				}
 			}
-			if(!e.getIsFile()&&resourceRepo.countByRootOrgIdAndParentId(e.getRootOrgId(), id)>0) {
+			if (!e.getIsFile()
+					&& resourceRepo.countByRootOrgIdAndParentId(e.getRootOrgId(), id) > 0) {
 				throw new StatusException("100032", "请先删除该目录下的文件及目录");
 			}
 			resourceRepo.deleteById(id);
-		}else {
+		} else {
 			throw new StatusException("100033", "文件或目录不存在");
-			
+
 		}
 	}
 
@@ -152,23 +158,23 @@ public class ResourceController extends ControllerSupport {
 		if (StringUtils.isBlank(domain.getName())) {
 			throw new StatusException("100001", "目录名称不能为空");
 		}
-		String regex="^[a-zA-Z\\-_0-9]{1,50}$";
-		if(!Pattern.matches(regex, domain.getName())) {
+		String regex = "^[a-zA-Z\\-_0-9]{1,50}$";
+		if (!Pattern.matches(regex, domain.getName())) {
 			throw new StatusException("100005", "目录名称必须为1-50位字母,数字,'-','_'组合");
 		}
-		if (domain.getRootOrgId()==null) {
+		if (domain.getRootOrgId() == null) {
 			throw new StatusException("100002", "RootOrgId不能为空");
 		}
-		if (domain.getParentId()==null) {
+		if (domain.getParentId() == null) {
 			throw new StatusException("100003", "ParentId不能为空");
 		}
-		if(!isSuperAdmin()) {
+		if (!isSuperAdmin()) {
 			User accessUser = getAccessUser();
-			if(!domain.getRootOrgId().equals(accessUser.getRootOrgId())) {
+			if (!domain.getRootOrgId().equals(accessUser.getRootOrgId())) {
 				throw new StatusException("100004", "无效的请求");
 			}
 		}
-		ResourceInfo info=new ResourceInfo();
+		ResourceInfo info = new ResourceInfo();
 		BeanUtils.copyProperties(domain, info);
 		resourceService.addDir(info);
 	}

+ 1 - 1
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ResourceServiceImpl.java

@@ -68,7 +68,7 @@ public class ResourceServiceImpl implements ResourceService {
 		e.setIsFile(true);
 		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
 		e.setSuffix(suffix);
-		if (parentId == null || parentId.longValue() == -1) {
+		if (parentId == null) {
 			e.setParentId(null);
 			e.setFilePath(FILE_ROOT_PATH + FILE_PATH_SEPARATE + rootOrgId + FILE_PATH_SEPARATE
 					+ fileName);