diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java index cc8fff85..230b77a4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java @@ -79,7 +79,7 @@ public class ExperimentController extends BaseController { */ @PostMapping @ApiOperation("新增实验") - public GenericsAjaxResult add(@RequestBody Experiment experiment) { + public GenericsAjaxResult add(@RequestBody Experiment experiment) throws Exception { return genericsSuccess(this.experimentService.insert(experiment)); } @@ -131,7 +131,7 @@ public class ExperimentController extends BaseController { */ @PostMapping("/addAndRunExperiment") @ApiOperation("实验创建页面确定并运行") - public GenericsAjaxResult addAndRunExperiment(@RequestBody Experiment experiment) { + public GenericsAjaxResult addAndRunExperiment(@RequestBody Experiment experiment) throws Exception { return genericsSuccess(this.experimentService.addAndRunExperiment(experiment)); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workflow/WorkflowController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workflow/WorkflowController.java index 359b3dfc..eec963b2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workflow/WorkflowController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workflow/WorkflowController.java @@ -79,7 +79,7 @@ public class WorkflowController extends BaseController { */ @PostMapping @ApiOperation("新增流水线") - public GenericsAjaxResult add(@RequestBody Workflow workflow) { + public GenericsAjaxResult add(@RequestBody Workflow workflow) throws Exception { return genericsSuccess(this.workflowService.insert(workflow)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workspace/WorkspaceController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workspace/WorkspaceController.java new file mode 100644 index 00000000..541ed8b5 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/workspace/WorkspaceController.java @@ -0,0 +1,36 @@ +package com.ruoyi.platform.controller.workspace; + +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; +import com.ruoyi.platform.service.JupyterService; +import com.ruoyi.platform.service.WorkspaceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Map; + +@RestController +@RequestMapping("workspace") +@Api("工作空间管理") +public class WorkspaceController extends BaseController { + + @Resource + private WorkspaceService workspaceService; + + @GetMapping("/overview") + @ApiOperation("得到运行概览") + public GenericsAjaxResult> getOverview() { + return genericsSuccess(this.workspaceService.getOverview()); + } + + @GetMapping("/assetCount") + @ApiOperation("得到AI资产计数") + public GenericsAjaxResult> getAssetCount(@RequestParam(value = "isPublic", + defaultValue = "true") Boolean isPublic) { + return genericsSuccess(this.workspaceService.getAssetCount(isPublic)); + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Experiment.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Experiment.java index 831302b7..01118a23 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Experiment.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Experiment.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonRawValue; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.ruoyi.common.core.web.domain.BaseEntity; +import com.ruoyi.platform.annotations.CheckDuplicate; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -28,6 +29,7 @@ public class Experiment implements Serializable { @ApiModelProperty(value = "主键") private Integer id; @ApiModelProperty(value = "名称") + @CheckDuplicate private String name; @ApiModelProperty(value = "工作流ID") diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ExperimentIns.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ExperimentIns.java index 9fce8bbe..78926ebf 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ExperimentIns.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ExperimentIns.java @@ -71,6 +71,11 @@ public class ExperimentIns implements Serializable { private Integer state; + + @ApiModelProperty(value = "实验实例对应的流水线ID") + private Long workflowId; + + public ExperimentIns() { } @@ -201,5 +206,9 @@ public class ExperimentIns implements Serializable { this.state = state; } + public Long getWorkflowId() {return workflowId;} + + public void setWorkflowId(Long workflowId) {this.workflowId = workflowId;} + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Image.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Image.java index 981289a1..d3b97185 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Image.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Image.java @@ -2,6 +2,7 @@ package com.ruoyi.platform.domain; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.ruoyi.platform.annotations.CheckDuplicate; import io.swagger.annotations.ApiModelProperty; import java.util.Date; @@ -25,6 +26,7 @@ public class Image implements Serializable { * 镜像名称 */ @ApiModelProperty(value = "名称") + @CheckDuplicate private String name; @ApiModelProperty(value = "镜像描述") diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Workflow.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Workflow.java index 487f7653..97ac1eba 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Workflow.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/Workflow.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonRawValue; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.ruoyi.platform.annotations.CheckDuplicate; import com.ruoyi.platform.handler.BaseMetaObjectHandler; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -33,6 +34,7 @@ public class Workflow extends BaseMetaObjectHandler implements Serializable { private Long id; @ApiModelProperty(value = "工作流名称") + @CheckDuplicate private String name; @ApiModelProperty(value = "流水线描述") diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentDao.java index d1db8828..6a24e02e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentDao.java @@ -1,5 +1,6 @@ package com.ruoyi.platform.mapper; +import com.ruoyi.platform.domain.Dataset; import com.ruoyi.platform.domain.Experiment; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; @@ -80,6 +81,9 @@ public interface ExperimentDao { */ int deleteById(Integer id); - List queryByExperiment(@Param("experiment")Experiment experiment); + List queryByExperiment(@Param("experiment") Experiment experiment); + + Experiment findByName(@Param("name") String name); + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentInsDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentInsDao.java index c5f13883..58642324 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentInsDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ExperimentInsDao.java @@ -39,6 +39,14 @@ public interface ExperimentInsDao { */ long count(@Param("experimentIns") ExperimentIns experimentIns); + /* + 统计实验实例总数 + + + @return 总行数 + */ +// long experimentInsCount(String status); + /** * 新增数据 * @@ -89,6 +97,10 @@ public interface ExperimentInsDao { */ List getByExperimentId(Integer experimentId); + List getLatestInsList(); + + + List queryByExperiment(@Param("experimentIns") ExperimentIns experimentIns); List queryByExperimentId(Integer id); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/WorkflowDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/WorkflowDao.java index c870a17f..e54f6789 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/WorkflowDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/WorkflowDao.java @@ -1,5 +1,6 @@ package com.ruoyi.platform.mapper; +import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.Workflow; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; @@ -32,13 +33,25 @@ public interface WorkflowDao { List queryAllByLimit(@Param("workflow") Workflow workflow, @Param("pageable") Pageable pageable); /** - * 统计总行数 + * 统计总行数 实体作为筛选条件 * * @param workflow 查询条件 * @return 总行数 */ long count(@Param("workflow") Workflow workflow); + + /** + * 统计流水线总数 + * + * + * @return 总行数 + */ + long workflowCount(); + + + + /** * 新增数据 * @@ -87,5 +100,8 @@ public interface WorkflowDao { * @return 对象列表 */ List queryByName(@Param("name") String name); + + Workflow findByName(@Param("name") String name); + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java index c1bfa662..b7ea8648 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java @@ -30,6 +30,7 @@ public class ExperimentInstanceStatusTask { private ExperimentInsDao experimentInsDao; private List experimentIds = new ArrayList<>(); + @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 public void executeExperimentInsStatus() throws IOException { // 首先查到所有非终止态的实验实例 @@ -47,15 +48,16 @@ public class ExperimentInstanceStatusTask { } if (!StringUtils.equals(oldStatus,experimentIns.getStatus())){ experimentIns.setUpdateTime(new Date()); + // 线程安全的添加操作 synchronized (experimentIds) { - experimentIds.add(experimentIns.getExperimentId()); // 线程安全的添加操作 + experimentIds.add(experimentIns.getExperimentId()); } updateList.add(experimentIns); - } experimentInsDao.update(experimentIns); } + } if (updateList.size() > 0){ experimentInsDao.insertOrUpdateBatch(updateList); @@ -85,11 +87,13 @@ public class ExperimentInstanceStatusTask { updateExperiments.add(experiment); } } + if (!updateExperiments.isEmpty()) { experimentDao.insertOrUpdateBatch(updateExperiments); for (int index = 0; index < updateExperiments.size(); index++) { + // 线程安全的删除操作 synchronized (experimentIds) { - experimentIds.remove(index); // 线程安全的删除操作 + experimentIds.remove(index); } } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java index 0f8cc707..edfe8cbe 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/DatasetService.java @@ -79,7 +79,7 @@ DatasetService { List getDatasetVersions(Integer datasetId) throws Exception; String insertDatasetAndVersion(DatasetVo datasetVo) throws Exception; - public void checkDeclaredName(Dataset insert) throws Exception; + void checkDeclaredName(Dataset insert) throws Exception; ResponseEntity downloadAllDatasetFiles(Integer datasetId, String version) throws Exception; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java index 1940fd2d..e8020161 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java @@ -103,4 +103,6 @@ public interface ExperimentInsService { * @return */ List queryByExperimentIsNotTerminated(); + + Map countByStatus(); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java index 44af21bc..4f79f527 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java @@ -1,6 +1,7 @@ package com.ruoyi.platform.service; import com.ruoyi.platform.domain.Experiment; +import com.ruoyi.platform.domain.Workflow; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; @@ -39,7 +40,7 @@ public interface ExperimentService { * @param experiment 实例对象 * @return 实例对象 */ - Experiment insert(Experiment experiment); + Experiment insert(Experiment experiment) throws Exception; /** * 修改数据 @@ -59,7 +60,7 @@ public interface ExperimentService { String removeById(Integer id) throws Exception; Experiment runExperiment(Integer id) throws Exception; - Experiment addAndRunExperiment(Experiment experiment); + Experiment addAndRunExperiment(Experiment experiment) throws Exception; /** * 分页查询实验状态 @@ -75,4 +76,6 @@ public interface ExperimentService { ResponseEntity showExperimentConfig(Experiment experiment); List queryByWorkflowId(Long id); + + void checkDeclaredName(Experiment insert) throws Exception; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkflowService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkflowService.java index 41397348..935a8918 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkflowService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkflowService.java @@ -1,6 +1,7 @@ package com.ruoyi.platform.service; import com.fasterxml.jackson.core.JsonProcessingException; +import com.ruoyi.platform.domain.Dataset; import com.ruoyi.platform.domain.Workflow; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -36,7 +37,7 @@ public interface WorkflowService { * @param workflow 实例对象 * @return 实例对象 */ - Workflow insert(Workflow workflow); + Workflow insert(Workflow workflow) throws Exception; /** * 修改数据 @@ -64,6 +65,8 @@ public interface WorkflowService { Workflow duplicateWorkflow(Long id); + void checkDeclaredName(Workflow insert) throws Exception; + /** * 按流水线id保存 * diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkspaceService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkspaceService.java new file mode 100644 index 00000000..5fdf8998 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/WorkspaceService.java @@ -0,0 +1,24 @@ +package com.ruoyi.platform.service; + +import java.util.Map; + +/** + * (workspace)服务接口 + * + * @author Xidaray + * @since 2024-5-06 14:38:07 + */ +public interface WorkspaceService { + + + + /** + * 得到工作空间数据概览 + * + * @return 概览数据 + */ + Map getOverview(); + + + Map getAssetCount(Boolean isPublic); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java index 14c2997d..940c4a02 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java @@ -1,7 +1,6 @@ package com.ruoyi.platform.service.impl; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.ExperimentIns; import com.ruoyi.platform.mapper.ExperimentDao; import com.ruoyi.platform.mapper.ExperimentInsDao; @@ -62,6 +61,15 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { this.minioUtil = minioUtil; } + public enum ExperimentInsStatus { + Running, + Succeeded, + Pending, + Failed, + Terminated + } + + /** * 通过ID查询单条数据 * @@ -533,6 +541,26 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { return experimentInsDao.queryByExperimentIsNotTerminated(); } + @Override + public Map countByStatus() { + // 创建一个用于存储状态计数的map + Map statusCountMap = new HashMap<>(); + + // 遍历枚举中的所有状态 + for (ExperimentInsStatus status : ExperimentInsStatus.values()) { + ExperimentIns experimentIns = new ExperimentIns(); + experimentIns.setStatus(status.toString()); // 设置实例的状态为枚举中的状态 + + // 查询具有相同状态的实例数量 + Long count = experimentInsDao.count(experimentIns); + + // 将状态及其对应的实例数量放入映射中 + statusCountMap.put(status.toString(), count); + } + + return statusCountMap; + } + private boolean isTerminatedState(ExperimentIns ins) throws IOException { // 定义终止态的列表,例如 "Succeeded", "Failed" 等 String status = ins.getStatus(); @@ -543,8 +571,6 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { //如果跟node_status里面不一样,就要去更新node_status的信息 String nodesStatus = ins.getNodesStatus(); Map nodeMap = JsonUtils.jsonToMap(nodesStatus); - - String keyStartsWithWorkflow = nodeMap.keySet().stream() .filter(key -> key.startsWith("workflow-")) .findFirst() diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java index 3cef14d1..56eb44ba 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.platform.service.impl; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.platform.annotations.CheckDuplicate; import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.ExperimentIns; import com.ruoyi.platform.domain.Workflow; @@ -25,6 +26,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; +import java.lang.reflect.Field; import java.util.*; /** @@ -130,8 +132,9 @@ public class ExperimentServiceImpl implements ExperimentService { * @return 实例对象 */ @Override - public Experiment insert(Experiment experiment) { + public Experiment insert(Experiment experiment) throws Exception { LoginUser loginUser = SecurityUtils.getLoginUser(); + checkDeclaredName(experiment); experiment.setCreateBy(loginUser.getUsername()); experiment.setUpdateBy(loginUser.getUsername()); experiment.setUpdateTime(new Date()); @@ -229,7 +232,7 @@ public class ExperimentServiceImpl implements ExperimentService { //这里全局参数是一个json数组,需要转换成一个list List> params = JacksonUtil.parseJSONStr2MapList(StringUtils.isEmpty(experiment.getGlobalParam()) ? "[]" : experiment.getGlobalParam()); runReqMap.put("params", params); - //// 实验字段的Map,不要写成一行! + //// 实验字段的Map,不要写成一行!否则会返回null Map experimentMap = new HashMap<>(); experimentMap.put("name", "experiment-"+experiment.getId()); runReqMap.put("experiment", experimentMap); @@ -279,7 +282,7 @@ public class ExperimentServiceImpl implements ExperimentService { } @Override - public Experiment addAndRunExperiment(Experiment experiment) { + public Experiment addAndRunExperiment(Experiment experiment) throws Exception { // 第一步: 调用add方法插入实验记录到数据库 Experiment newExperiment = this.insert(experiment); @@ -317,6 +320,28 @@ public class ExperimentServiceImpl implements ExperimentService { return experimentDao.queryByExperiment(experiment); } + public void checkDeclaredName(Experiment insert) throws Exception { + Experiment existingExperiment = experimentDao.findByName(insert.getName()); + + if (existingExperiment != null) { + // 检查找到的流水线是否与要插入的流水线相同 + if (insert.getId() != null && insert.getId().equals(existingExperiment.getId())) { + // 这是相同的流水线,更新操作中没有重复名称问题 + return; + } + // 现在我们知道还有另一个具有相同名称的流水线 + Field[] fields = Experiment.class.getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); // 使私有字段可访问 + if ("name".equals(field.getName()) && field.isAnnotationPresent(CheckDuplicate.class)) { + // 如果字段是“name”并且标记了CheckDuplicate注解 + CheckDuplicate annotation = field.getAnnotation(CheckDuplicate.class); + throw new Exception("重复的实验名称: " + insert.getName() + ". " + annotation.message()); + } + } + } + } + diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java index 59cb170d..18b487f5 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.platform.service.impl; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.platform.annotations.CheckDuplicate; +import com.ruoyi.platform.domain.Dataset; import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.Workflow; import com.ruoyi.platform.mapper.WorkflowDao; @@ -18,6 +20,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.lang.reflect.Field; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -88,8 +91,9 @@ public class WorkflowServiceImpl implements WorkflowService { * @return 实例对象 */ @Override - public Workflow insert(Workflow workflow) { + public Workflow insert(Workflow workflow) throws Exception { LoginUser loginUser = SecurityUtils.getLoginUser(); + checkDeclaredName(workflow); workflow.setCreateBy(loginUser.getUsername()); workflow.setUpdateBy(loginUser.getUsername()); workflow.setUpdateTime(new Date()); @@ -191,7 +195,32 @@ public class WorkflowServiceImpl implements WorkflowService { } return null; + + + } + + public void checkDeclaredName(Workflow insert) throws Exception { + Workflow existingWorkflow = workflowDao.findByName(insert.getName()); + if (existingWorkflow != null) { + // 检查找到的流水线是否与要插入的流水线相同 + if (insert.getId() != null && insert.getId().equals(existingWorkflow.getId())) { + // 这是相同的流水线,更新操作中没有重复名称问题 + return; + } + // 现在我们知道还有另一个具有相同名称的流水线 + Field[] fields = Workflow.class.getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); // 使私有字段可访问 + if ("name".equals(field.getName()) && field.isAnnotationPresent(CheckDuplicate.class)) { + // 如果字段是“name”并且标记了CheckDuplicate注解 + CheckDuplicate annotation = field.getAnnotation(CheckDuplicate.class); + throw new Exception("重复的流水线名称: " + insert.getName() + ". " + annotation.message()); + } + } + } } + + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkspaceServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkspaceServiceImpl.java new file mode 100644 index 00000000..b5392261 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkspaceServiceImpl.java @@ -0,0 +1,117 @@ +package com.ruoyi.platform.service.impl; + +import com.ruoyi.platform.domain.*; +import com.ruoyi.platform.mapper.*; +import com.ruoyi.platform.service.ExperimentInsService; +import com.ruoyi.platform.service.ModelsService; +import com.ruoyi.platform.service.WorkflowService; +import com.ruoyi.platform.service.WorkspaceService; +import lombok.val; +import org.checkerframework.checker.units.qual.C; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service("WorkspaceService") +public class WorkspaceServiceImpl implements WorkspaceService { + + + @Resource + private WorkflowService workflowService; + @Resource + private WorkflowDao workflowDao; + @Resource + private ExperimentDao experimentDao; + + @Resource + private ExperimentInsDao experimentInsDao; + + @Resource + private ExperimentInsService experimentInsService; + + @Resource + private ModelsService modelsService; + @Resource + private ModelsDao modelsDao; + + @Resource + private DatasetDao datasetDao; + + @Resource + private ImageDao imageDao; + + @Resource + private ComponentDao componentDao; + + + + + @Override + public Map getOverview() { + Map resMap = new HashMap(); + + // 获取流水线数量 + Long workflowCount = workflowDao.workflowCount(); + resMap.put("workflowCount", workflowCount); + + // 获取运行中实验实例数量 + List experimentInsList = experimentInsService.queryByExperimentIsNotTerminated(); + if (experimentInsList!=null && !experimentInsList.isEmpty()) { + Integer experimentInsCount = experimentInsList.size(); + resMap.put("runningExperimentInsCount", experimentInsCount); + }else{ + resMap.put("runningExperimentInsCount", 0); + } + //得到最近的三条实例记录,放进返回map + List latestExperimentInsList = experimentInsDao.getLatestInsList(); + if (latestExperimentInsList != null && !latestExperimentInsList.isEmpty()) { + for (ExperimentIns experimentIns : latestExperimentInsList){ + Integer experimentId = experimentIns.getExperimentId(); + Experiment experiment = this.experimentDao.queryById(experimentId); + //拿到对应的流水线id + Long correspondingWorkflowId = experiment.getWorkflowId(); + experimentIns.setWorkflowId(correspondingWorkflowId); + } + resMap.put("latestExperimentInsList", latestExperimentInsList); + } + Map statusMap = experimentInsService.countByStatus(); + resMap.put("experimentInsStatus", statusMap); + return resMap; + } + + @Override + public Map getAssetCount(Boolean isPublic) { + Map assetCountMap = new HashMap(); + int availableRange = isPublic ? 1 : 0; + //统计数据集数量 + Dataset dataset = new Dataset(); + dataset.setAvailableRange(availableRange); + Integer datasetCount = (int) this.datasetDao.count(dataset); + assetCountMap.put("dataset", datasetCount); + //统计模型数量 + Models models = new Models(); + models.setAvailableRange(availableRange); + Integer modelCount = (int) this.modelsDao.count(models); + assetCountMap.put("model", modelCount); + //统计镜像数量 + Image image = new Image(); + image.setImageType(availableRange); + Integer imageCount = (int) this.imageDao.count(image); + assetCountMap.put("image", imageCount); + //统计组件数量 + Component component = new Component(); + Integer componentCount = (int) this.componentDao.count(component); + assetCountMap.put("component", componentCount); + //统计流水线数量 + Workflow workflow = new Workflow(); + Integer workflowCount = (int) this.workflowDao.count(workflow); + assetCountMap.put("workflow", workflowCount); + + return assetCountMap; + } + + +} diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentDaoMapper.xml index c39dcd9e..80a53eb1 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentDaoMapper.xml @@ -24,6 +24,14 @@ where id = #{id} and state = 1 + + + + insert into experiment(name,workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state) diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentInsDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentInsDaoMapper.xml index 6ed73cdb..71dace3e 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentInsDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ExperimentInsDaoMapper.xml @@ -45,6 +45,16 @@ limit 5 + + + + + + + insert into workflow(name, description, dag, global_param, create_by, create_time, update_by, update_time,state) @@ -185,5 +192,13 @@ + + +