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