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