| @@ -79,7 +79,7 @@ public class ExperimentController extends BaseController { | |||||
| */ | */ | ||||
| @PostMapping | @PostMapping | ||||
| @ApiOperation("新增实验") | @ApiOperation("新增实验") | ||||
| public GenericsAjaxResult<Experiment> add(@RequestBody Experiment experiment) { | |||||
| public GenericsAjaxResult<Experiment> add(@RequestBody Experiment experiment) throws Exception { | |||||
| return genericsSuccess(this.experimentService.insert(experiment)); | return genericsSuccess(this.experimentService.insert(experiment)); | ||||
| } | } | ||||
| @@ -131,7 +131,7 @@ public class ExperimentController extends BaseController { | |||||
| */ | */ | ||||
| @PostMapping("/addAndRunExperiment") | @PostMapping("/addAndRunExperiment") | ||||
| @ApiOperation("实验创建页面确定并运行") | @ApiOperation("实验创建页面确定并运行") | ||||
| public GenericsAjaxResult<Experiment> addAndRunExperiment(@RequestBody Experiment experiment) { | |||||
| public GenericsAjaxResult<Experiment> addAndRunExperiment(@RequestBody Experiment experiment) throws Exception { | |||||
| return genericsSuccess(this.experimentService.addAndRunExperiment(experiment)); | return genericsSuccess(this.experimentService.addAndRunExperiment(experiment)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -79,7 +79,7 @@ public class WorkflowController extends BaseController { | |||||
| */ | */ | ||||
| @PostMapping | @PostMapping | ||||
| @ApiOperation("新增流水线") | @ApiOperation("新增流水线") | ||||
| public GenericsAjaxResult<Workflow> add(@RequestBody Workflow workflow) { | |||||
| public GenericsAjaxResult<Workflow> add(@RequestBody Workflow workflow) throws Exception { | |||||
| return genericsSuccess(this.workflowService.insert(workflow)); | return genericsSuccess(this.workflowService.insert(workflow)); | ||||
| } | } | ||||
| @@ -0,0 +1,22 @@ | |||||
| package com.ruoyi.platform.controller.workspace; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | |||||
| import com.ruoyi.common.core.web.domain.AjaxResult; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.PathVariable; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @RestController | |||||
| @RequestMapping("workspace") | |||||
| @Api("工作空间管理") | |||||
| public class WorkspaceController extends BaseController { | |||||
| @GetMapping("/overview") | |||||
| @ApiOperation("运行概览") | |||||
| public AjaxResult queryById(@PathVariable("id") Integer id) { | |||||
| return AjaxResult.success(this.datasetService.queryById(id)); | |||||
| } | |||||
| } | |||||
| @@ -1,5 +1,6 @@ | |||||
| package com.ruoyi.platform.mapper; | package com.ruoyi.platform.mapper; | ||||
| import com.ruoyi.platform.domain.Experiment; | |||||
| import com.ruoyi.platform.domain.Workflow; | import com.ruoyi.platform.domain.Workflow; | ||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import org.springframework.data.domain.Pageable; | import org.springframework.data.domain.Pageable; | ||||
| @@ -87,5 +88,8 @@ public interface WorkflowDao { | |||||
| * @return 对象列表 | * @return 对象列表 | ||||
| */ | */ | ||||
| List<Workflow> queryByName(@Param("name") String name); | List<Workflow> queryByName(@Param("name") String name); | ||||
| Workflow findByName(@Param("name") String name); | |||||
| } | } | ||||
| @@ -40,7 +40,7 @@ public interface ExperimentService { | |||||
| * @param experiment 实例对象 | * @param experiment 实例对象 | ||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| Experiment insert(Experiment experiment); | |||||
| Experiment insert(Experiment experiment) throws Exception; | |||||
| /** | /** | ||||
| * 修改数据 | * 修改数据 | ||||
| @@ -60,7 +60,7 @@ public interface ExperimentService { | |||||
| String removeById(Integer id) throws Exception; | String removeById(Integer id) throws Exception; | ||||
| Experiment runExperiment(Integer id) throws Exception; | Experiment runExperiment(Integer id) throws Exception; | ||||
| Experiment addAndRunExperiment(Experiment experiment); | |||||
| Experiment addAndRunExperiment(Experiment experiment) throws Exception; | |||||
| /** | /** | ||||
| * 分页查询实验状态 | * 分页查询实验状态 | ||||
| @@ -37,7 +37,7 @@ public interface WorkflowService { | |||||
| * @param workflow 实例对象 | * @param workflow 实例对象 | ||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| Workflow insert(Workflow workflow); | |||||
| Workflow insert(Workflow workflow) throws Exception; | |||||
| /** | /** | ||||
| * 修改数据 | * 修改数据 | ||||
| @@ -0,0 +1,11 @@ | |||||
| package com.ruoyi.platform.service; | |||||
| /** | |||||
| * (workspace)服务接口 | |||||
| * | |||||
| * @author Xidaray | |||||
| * @since 2024-5-06 14:38:07 | |||||
| */ | |||||
| public class WorkspaceService { | |||||
| } | |||||
| @@ -132,8 +132,9 @@ public class ExperimentServiceImpl implements ExperimentService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public Experiment insert(Experiment experiment) { | |||||
| public Experiment insert(Experiment experiment) throws Exception { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| checkDeclaredName(experiment); | |||||
| experiment.setCreateBy(loginUser.getUsername()); | experiment.setCreateBy(loginUser.getUsername()); | ||||
| experiment.setUpdateBy(loginUser.getUsername()); | experiment.setUpdateBy(loginUser.getUsername()); | ||||
| experiment.setUpdateTime(new Date()); | experiment.setUpdateTime(new Date()); | ||||
| @@ -231,7 +232,7 @@ public class ExperimentServiceImpl implements ExperimentService { | |||||
| //这里全局参数是一个json数组,需要转换成一个list<Map> | //这里全局参数是一个json数组,需要转换成一个list<Map> | ||||
| List<Map<String, Object>> params = JacksonUtil.parseJSONStr2MapList(StringUtils.isEmpty(experiment.getGlobalParam()) ? "[]" : experiment.getGlobalParam()); | List<Map<String, Object>> params = JacksonUtil.parseJSONStr2MapList(StringUtils.isEmpty(experiment.getGlobalParam()) ? "[]" : experiment.getGlobalParam()); | ||||
| runReqMap.put("params", params); | runReqMap.put("params", params); | ||||
| //// 实验字段的Map,不要写成一行! | |||||
| //// 实验字段的Map,不要写成一行!否则会返回null | |||||
| Map<String, Object> experimentMap = new HashMap<>(); | Map<String, Object> experimentMap = new HashMap<>(); | ||||
| experimentMap.put("name", "experiment-"+experiment.getId()); | experimentMap.put("name", "experiment-"+experiment.getId()); | ||||
| runReqMap.put("experiment", experimentMap); | runReqMap.put("experiment", experimentMap); | ||||
| @@ -281,7 +282,7 @@ public class ExperimentServiceImpl implements ExperimentService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public Experiment addAndRunExperiment(Experiment experiment) { | |||||
| public Experiment addAndRunExperiment(Experiment experiment) throws Exception { | |||||
| // 第一步: 调用add方法插入实验记录到数据库 | // 第一步: 调用add方法插入实验记录到数据库 | ||||
| Experiment newExperiment = this.insert(experiment); | Experiment newExperiment = this.insert(experiment); | ||||
| @@ -91,8 +91,9 @@ public class WorkflowServiceImpl implements WorkflowService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public Workflow insert(Workflow workflow) { | |||||
| public Workflow insert(Workflow workflow) throws Exception { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| checkDeclaredName(workflow); | |||||
| workflow.setCreateBy(loginUser.getUsername()); | workflow.setCreateBy(loginUser.getUsername()); | ||||
| workflow.setUpdateBy(loginUser.getUsername()); | workflow.setUpdateBy(loginUser.getUsername()); | ||||
| workflow.setUpdateTime(new Date()); | workflow.setUpdateTime(new Date()); | ||||
| @@ -199,9 +200,7 @@ public class WorkflowServiceImpl implements WorkflowService { | |||||
| } | } | ||||
| public void checkDeclaredName(Workflow insert) throws Exception { | public void checkDeclaredName(Workflow insert) throws Exception { | ||||
| List<Workflow> existingWorkflowList = workflowDao.queryByName(insert.getName()); | |||||
| Workflow existingWorkflow = existingWorkflowList.stream().findFirst().orElse(null); | |||||
| Workflow existingWorkflow = workflowDao.findByName(insert.getName()); | |||||
| if (existingWorkflow != null) { | if (existingWorkflow != null) { | ||||
| // 检查找到的流水线是否与要插入的流水线相同 | // 检查找到的流水线是否与要插入的流水线相同 | ||||
| if (insert.getId() != null && insert.getId().equals(existingWorkflow.getId())) { | if (insert.getId() != null && insert.getId().equals(existingWorkflow.getId())) { | ||||
| @@ -0,0 +1,7 @@ | |||||
| package com.ruoyi.platform.service.impl; | |||||
| import com.ruoyi.platform.service.ModelsService; | |||||
| public class WorkspaceServiceImpl implements ModelsService { | |||||
| } | |||||
| @@ -185,5 +185,13 @@ | |||||
| </if> | </if> | ||||
| </where> | </where> | ||||
| </select> | </select> | ||||
| <!--通过流水线名字进行精准查询--> | |||||
| <select id="findByName" resultMap="WorkflowMap"> | |||||
| select | |||||
| id, name, description, dag, global_param, create_by, create_time, update_by, update_time, state | |||||
| from workflow | |||||
| where name = #{name} and state = 1 limit 1 | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||