Delete Regular by ID API
@PostMapping("/deleteOneRegularByID")
public Result<Object> deleteOneRegularByID(@RequestBody Map<String, Object> params, HttpServletRequest request) {
//权限验证
String token = (String) request.getAttribute("claims_admin");
if (token == null || "".equals(token)) {
throw new RuntimeException("权限不足!");
}
log.info("deleteOneRegularByID请求报文:" + params);
//前端传递参数
Long regularId;
if (params.get("regularId") != null) {
regularId = Long.valueOf(params.get("regularId").toString());
} else {
log.error("regularId为null");
return new Result<>(ResultCode.FAIL);
}
//前端传递参数
String phone = (String) params.get("phone");
if (StringUtils.isEmpty(phone)) {
log.error("phone为空!");
return new Result<>(ResultCode.FAIL);
}
String userCode = (String) params.get("code");
if (StringUtils.isEmpty(userCode)) {
log.error("userCode为空!");
return new Result<>(ResultCode.FAIL);
}
String regularDelete_uuid = redisTemplate.opsForValue().get("regularDelete_uuid" + phone);
String myCode = redisTemplate.opsForValue().get("regularDelete_" + regularDelete_uuid + phone);
log.info("myCode:" + myCode);
if (StringUtils.isEmpty(myCode)) {
log.error("myCode为空!");
return new Result<>(ResultCode.FAIL);
}
if (!userCode.equals(myCode)) {
log.error("验证码错误!");
return new Result<>(ResultCode.CODE_FALSE);
}
Regular regular = regularService.queryOneRegularByID(regularId);
List<DeviceEntity> deviceEntities = deviceEntityService.queryDevicesByRegularId(regular.getRegularId());
if (!deviceEntities.isEmpty()) {
log.error("此规则已绑定设备,不能删除!");
return new Result<>(ResultCode.REGULAR_DELETE);
}
//调用方法
int ret = regularService.deleteOneRegularByID(regularId);
//操作成功
if (ret < 0) {
log.error("删除规则失败!");
return new Result<>(ResultCode.FAIL);
}
log.info("删除规则成功!");
//同时删除其对应的具体规则
List<SpecificRegular> specificRegulars = specificRegularService.querySpecificRegularsByRegularId(regularId);
if (!CollectionUtils.isEmpty(specificRegulars)) {
List<SpecificRegular> specificRegularList = specificRegulars.stream()
.map(specificRegular -> {
specificRegular.setEnableState(0);
return specificRegular;
})
.collect(Collectors.toList());
boolean batch = specificRegularService.updateBatchById(specificRegularList);
if (!batch) {
log.error("具体规则删除失败!");
return new Result<>(ResultCode.FAIL);
}
log.info("具体规则删除成功!");
springToGameService.reloadDeleteRegularWithSpecificRegular(regular, specificRegularList);
}
return new Result<>(ResultCode.SUCCESS);
}
// 异步执行删除规则后的具体规则,不使用注解内容:
```java
// 创建一个新的线程用于异步执行
Thread thread = new Thread(() -> {
// 删除具体规则的代码
// ...
});
// 启动线程
thread.start();
// 返回成功响应
return new Result<>(ResultCode.SUCCESS);
This code creates a new thread and executes the code to delete the specific rules asynchronously. After starting the thread, the success response is returned immediately.
原文地址: https://www.cveoy.top/t/topic/gXZa 著作权归作者所有。请勿转载和采集!