修改删除报错接口

This commit is contained in:
fans 2024-01-25 15:41:41 +08:00
parent 35e40fdf0b
commit 9a7898df96
3 changed files with 6 additions and 6 deletions

View File

@ -97,7 +97,7 @@ public class ExperimentController {
*/
@DeleteMapping("{id}")
@ApiOperation("删除流水线")
public AjaxResult deleteById(@PathVariable("id") Integer id) {
public AjaxResult deleteById(@PathVariable("id") Integer id) throws Exception {
return AjaxResult.success(this.experimentService.removeById(id));
}

View File

@ -55,7 +55,7 @@ public interface ExperimentService {
* @return 是否成功
*/
boolean deleteById(Integer id);
String removeById(Integer id);
String removeById(Integer id) throws Exception;
Experiment runExperiment(Integer id) throws Exception;
Experiment addAndRunExperiment(Experiment experiment);

View File

@ -165,10 +165,10 @@ public class ExperimentServiceImpl implements ExperimentService {
}
@Override
public String removeById(Integer id) {
public String removeById(Integer id) throws Exception {
Experiment experiment = experimentDao.queryById(id);
if (experiment==null){
return "实验不存在";
throw new Exception("实验不存在");
}
//判断权限只有admin和创建者本身可以删除该实验
@ -176,12 +176,12 @@ public class ExperimentServiceImpl implements ExperimentService {
String username = loginUser.getUsername();
String createdBy = experiment.getCreateBy();
if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){
return "无权限删除该实验";
throw new Exception("无权限删除该实验");
}
List<ExperimentIns> experimentInsList = experimentInsService.queryByExperimentId(experiment.getId());
if (experimentInsList!=null&&experimentInsList.size()>0){
return "该实验存在实例,无法删除";
throw new Exception("该实验存在实例,无法删除");
}
experiment.setState(0);
return this.experimentDao.update(experiment)>0?"删除成功":"删除失败";