Merge branch 'dev'
commit
b314f7abb3
|
@ -1,6 +1,7 @@
|
||||||
package cc.iotkit.manager.config;
|
package cc.iotkit.manager.config;
|
||||||
|
|
||||||
import cn.dev33.satoken.exception.NotLoginException;
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
|
import cn.dev33.satoken.exception.NotPermissionException;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -24,6 +25,11 @@ public class GlobalExceptionHandler {
|
||||||
return new RequestResult("401", "未授权的请求");
|
return new RequestResult("401", "未授权的请求");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e instanceof NotPermissionException) {
|
||||||
|
response.setStatus(403);
|
||||||
|
return new RequestResult("403", "没有权限");
|
||||||
|
}
|
||||||
|
|
||||||
if (e.getMessage().contains("Unauthorized")) {
|
if (e.getMessage().contains("Unauthorized")) {
|
||||||
response.setStatus(403);
|
response.setStatus(403);
|
||||||
return new RequestResult("403", "没有权限");
|
return new RequestResult("403", "没有权限");
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cc.iotkit.manager.config;
|
||||||
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
|
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
|
||||||
import cn.dev33.satoken.interceptor.SaRouteInterceptor;
|
import cn.dev33.satoken.interceptor.SaRouteInterceptor;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
import cn.dev33.satoken.router.SaRouterStaff;
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
|
@ -53,7 +53,9 @@ public class ProtocolController {
|
||||||
private ComponentManager componentManager;
|
private ComponentManager componentManager;
|
||||||
|
|
||||||
@PostMapping("/uploadJar")
|
@PostMapping("/uploadJar")
|
||||||
public String uploadJar(@RequestParam("file") MultipartFile file, String id) {
|
public String uploadJar(
|
||||||
|
@RequestParam("file") MultipartFile file,
|
||||||
|
@RequestParam("id") String id) {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new BizException("file is null");
|
throw new BizException("file is null");
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class RuleEngineController {
|
||||||
@PostMapping("/rule/{ruleId}/pause")
|
@PostMapping("/rule/{ruleId}/pause")
|
||||||
public void pauseRule(@PathVariable("ruleId") String ruleId) {
|
public void pauseRule(@PathVariable("ruleId") String ruleId) {
|
||||||
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
||||||
if (!ruleOpt.isPresent()) {
|
if (ruleOpt.isEmpty()) {
|
||||||
throw new BizException("Rule does not exist");
|
throw new BizException("Rule does not exist");
|
||||||
}
|
}
|
||||||
RuleInfo ruleInfo = ruleOpt.get();
|
RuleInfo ruleInfo = ruleOpt.get();
|
||||||
|
@ -112,7 +112,7 @@ public class RuleEngineController {
|
||||||
@PostMapping("/rule/{ruleId}/resume")
|
@PostMapping("/rule/{ruleId}/resume")
|
||||||
public void resumeRule(@PathVariable("ruleId") String ruleId) {
|
public void resumeRule(@PathVariable("ruleId") String ruleId) {
|
||||||
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
||||||
if (!ruleOpt.isPresent()) {
|
if (ruleOpt.isEmpty()) {
|
||||||
throw new BizException("Rule does not exist");
|
throw new BizException("Rule does not exist");
|
||||||
}
|
}
|
||||||
RuleInfo ruleInfo = ruleOpt.get();
|
RuleInfo ruleInfo = ruleOpt.get();
|
||||||
|
@ -125,7 +125,7 @@ public class RuleEngineController {
|
||||||
@DeleteMapping("/rule/{ruleId}/delete")
|
@DeleteMapping("/rule/{ruleId}/delete")
|
||||||
public void deleteRule(@PathVariable("ruleId") String ruleId) {
|
public void deleteRule(@PathVariable("ruleId") String ruleId) {
|
||||||
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
Optional<RuleInfo> ruleOpt = ruleInfoRepository.findById(ruleId);
|
||||||
if (!ruleOpt.isPresent()) {
|
if (ruleOpt.isEmpty()) {
|
||||||
throw new BizException("Rule does not exist");
|
throw new BizException("Rule does not exist");
|
||||||
}
|
}
|
||||||
RuleInfo ruleInfo = ruleOpt.get();
|
RuleInfo ruleInfo = ruleOpt.get();
|
||||||
|
@ -169,7 +169,7 @@ public class RuleEngineController {
|
||||||
taskInfo.setState(TaskInfo.STATE_STOP);
|
taskInfo.setState(TaskInfo.STATE_STOP);
|
||||||
} else {
|
} else {
|
||||||
Optional<TaskInfo> taskOpt = taskInfoRepository.findById(taskInfo.getId());
|
Optional<TaskInfo> taskOpt = taskInfoRepository.findById(taskInfo.getId());
|
||||||
if (!taskOpt.isPresent()) {
|
if (taskOpt.isEmpty()) {
|
||||||
throw new BizException("Task does not exist");
|
throw new BizException("Task does not exist");
|
||||||
}
|
}
|
||||||
TaskInfo oldTask = taskOpt.get();
|
TaskInfo oldTask = taskOpt.get();
|
||||||
|
@ -183,7 +183,7 @@ public class RuleEngineController {
|
||||||
@PostMapping("/task/{taskId}/pause")
|
@PostMapping("/task/{taskId}/pause")
|
||||||
public void pauseTask(@PathVariable("taskId") String taskId) {
|
public void pauseTask(@PathVariable("taskId") String taskId) {
|
||||||
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
||||||
if (!optionalTaskInfo.isPresent()) {
|
if (optionalTaskInfo.isEmpty()) {
|
||||||
throw new BizException("Task does not exist");
|
throw new BizException("Task does not exist");
|
||||||
}
|
}
|
||||||
dataOwnerService.checkOwner(optionalTaskInfo.get());
|
dataOwnerService.checkOwner(optionalTaskInfo.get());
|
||||||
|
@ -193,7 +193,7 @@ public class RuleEngineController {
|
||||||
@PostMapping("/task/{taskId}/resume")
|
@PostMapping("/task/{taskId}/resume")
|
||||||
public void resumeTask(@PathVariable("taskId") String taskId) {
|
public void resumeTask(@PathVariable("taskId") String taskId) {
|
||||||
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
||||||
if (!optionalTaskInfo.isPresent()) {
|
if (optionalTaskInfo.isEmpty()) {
|
||||||
throw new BizException("Task does not exist");
|
throw new BizException("Task does not exist");
|
||||||
}
|
}
|
||||||
dataOwnerService.checkOwner(optionalTaskInfo.get());
|
dataOwnerService.checkOwner(optionalTaskInfo.get());
|
||||||
|
@ -203,7 +203,7 @@ public class RuleEngineController {
|
||||||
@PostMapping("/task/{taskId}/renew")
|
@PostMapping("/task/{taskId}/renew")
|
||||||
public void renewTask(@PathVariable("taskId") String taskId) {
|
public void renewTask(@PathVariable("taskId") String taskId) {
|
||||||
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
||||||
if (!optionalTaskInfo.isPresent()) {
|
if (optionalTaskInfo.isEmpty()) {
|
||||||
throw new BizException("Task does not exist");
|
throw new BizException("Task does not exist");
|
||||||
}
|
}
|
||||||
TaskInfo taskInfo = optionalTaskInfo.get();
|
TaskInfo taskInfo = optionalTaskInfo.get();
|
||||||
|
@ -222,7 +222,7 @@ public class RuleEngineController {
|
||||||
@DeleteMapping("/task/{taskId}/delete")
|
@DeleteMapping("/task/{taskId}/delete")
|
||||||
public void deleteTask(@PathVariable("taskId") String taskId) {
|
public void deleteTask(@PathVariable("taskId") String taskId) {
|
||||||
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
Optional<TaskInfo> optionalTaskInfo = taskInfoRepository.findById(taskId);
|
||||||
if (!optionalTaskInfo.isPresent()) {
|
if (optionalTaskInfo.isEmpty()) {
|
||||||
throw new BizException("Task does not exist");
|
throw new BizException("Task does not exist");
|
||||||
}
|
}
|
||||||
TaskInfo taskInfo = optionalTaskInfo.get();
|
TaskInfo taskInfo = optionalTaskInfo.get();
|
||||||
|
|
|
@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -40,8 +41,13 @@ public class VirtualDeviceController {
|
||||||
@PathVariable("size") int size,
|
@PathVariable("size") int size,
|
||||||
@PathVariable("page") int page) {
|
@PathVariable("page") int page) {
|
||||||
String uid = AuthUtil.getUserId();
|
String uid = AuthUtil.getUserId();
|
||||||
Page<VirtualDevice> virtualDevices = virtualDeviceRepository.findByUid(uid,
|
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt")));
|
||||||
PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt"))));
|
Page<VirtualDevice> virtualDevices;
|
||||||
|
if (AuthUtil.isAdmin()) {
|
||||||
|
virtualDevices = virtualDeviceRepository.findAll(pageable);
|
||||||
|
} else {
|
||||||
|
virtualDevices = virtualDeviceRepository.findByUid(uid, pageable);
|
||||||
|
}
|
||||||
return new Paging<>(virtualDevices.getTotalElements(), virtualDevices.getContent());
|
return new Paging<>(virtualDevices.getTotalElements(), virtualDevices.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue