| @@ -3,6 +3,8 @@ package com.ruoyi.platform.controller.dataset; | |||
| import com.ruoyi.platform.domain.*; | |||
| import com.ruoyi.platform.service.*; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.core.io.InputStreamResource; | |||
| import org.springframework.data.domain.Page; | |||
| @@ -98,27 +100,33 @@ public class DatasetController { | |||
| /** | |||
| * 下载数据集 | |||
| * | |||
| * @param id ps:这里的id是dataset_version表的主键 | |||
| * @param dataset_version_id ps:这里的id是dataset_version表的主键 | |||
| * @return 单条数据 | |||
| */ | |||
| @GetMapping("/download/{id}") | |||
| @ApiOperation("下载数据集") | |||
| public ResponseEntity<InputStreamResource> downloadDataset(@PathVariable("id") Integer id) { | |||
| return datasetService.downloadDataset(id); | |||
| @GetMapping("/download/{dataset_version_id}") | |||
| @ApiOperation(value = "下载数据集", notes = "根据数据集版本表id下载数据集文件") | |||
| public ResponseEntity<InputStreamResource> downloadDataset(@PathVariable("dataset_version_id") Integer dataset_version_id) { | |||
| return datasetService.downloadDataset(dataset_version_id); | |||
| } | |||
| /** | |||
| * 上传数据集 | |||
| * | |||
| * @param id ps:这里的id是dataset_version表的主键 | |||
| * @param dataset_version_id ps:这里的id是dataset_version表的主键 | |||
| * @param file 上传的数据集文件 | |||
| * @return 上传结果 | |||
| */ | |||
| @PostMapping("/upload/{id}") | |||
| @ApiOperation("上传数据集") | |||
| public ResponseEntity<String> uploadDataset(@RequestParam("file") MultipartFile file , @PathVariable("id") Integer id) throws Exception { | |||
| return ResponseEntity.ok(this.datasetService.uploadDataset(file,id)); | |||
| @PostMapping("/upload/{dataset_version_id}") | |||
| @ApiOperation(value = "上传数据集", notes = "根据数据集版本表id上传数据集文件,并将信息存入数据库。") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "file", value = "要上传的数据集文件", required = true, dataType = "file", paramType = "form"), | |||
| @ApiImplicitParam(name = "dataset_version_id", value = "数据集版本表id", required = true, dataType = "integer", paramType = "path") | |||
| }) | |||
| public ResponseEntity<String> uploadDataset(@RequestParam("file") MultipartFile file, | |||
| @PathVariable("dataset_version_id") Integer dataset_version_id) throws Exception { | |||
| return ResponseEntity.ok(this.datasetService.uploadDataset(file, dataset_version_id)); | |||
| } | |||
| } | |||
| @@ -100,13 +100,14 @@ public class ModelsController { | |||
| * | |||
| * | |||
| * @param file 文件 | |||
| * @param models_version_id 模型版本表主键 | |||
| * @return 上传结果 | |||
| */ | |||
| @PostMapping("/upload/{id}") | |||
| @ApiOperation("上传数据集") | |||
| public ResponseEntity<String> uploadModels(@RequestParam("file") MultipartFile file, @PathVariable("id") Integer id) throws Exception { | |||
| return ResponseEntity.ok(this.modelsService.uploadModels(file,id)); | |||
| @PostMapping("/upload/{models_version_id}") | |||
| @ApiOperation(value = "上传模型", notes = "根据模型版本表id上传模型文件,并将信息存入数据库。") | |||
| public ResponseEntity<String> uploadModels(@RequestParam("file") MultipartFile file, @PathVariable("models_version_id") Integer models_version_id) throws Exception { | |||
| return ResponseEntity.ok(this.modelsService.uploadModels(file,models_version_id)); | |||
| } | |||
| @@ -114,17 +115,13 @@ public class ModelsController { | |||
| /** | |||
| * 模型下载 | |||
| * | |||
| * | |||
| * | |||
| * @param id 主键 | |||
| *@param models_version_id 模型版本表主键 | |||
| * @return 单条数据 | |||
| */ | |||
| @GetMapping("/download/{id}") | |||
| @ApiOperation("下载模型") | |||
| public ResponseEntity<InputStreamResource> downloadModels(@PathVariable("id") Integer id) | |||
| { | |||
| return modelsService.downloadModels(id); | |||
| @GetMapping("/download/{models_version_id}") | |||
| @ApiOperation(value = "下载模型", notes = "根据模型版本表id下载模型文件。") | |||
| public ResponseEntity<InputStreamResource> downloadModels(@PathVariable("models_version_id") Integer models_version_id) { | |||
| return modelsService.downloadModels(models_version_id); | |||
| } | |||
| } | |||
| @@ -37,7 +37,7 @@ public interface WorkflowDao { | |||
| * @param workflow 查询条件 | |||
| * @return 总行数 | |||
| */ | |||
| long count(@Param("workflow")Workflow workflow); | |||
| long count(@Param("workflow") Workflow workflow); | |||
| /** | |||
| * 新增数据 | |||
| @@ -45,7 +45,7 @@ public interface WorkflowDao { | |||
| * @param workflow 实例对象 | |||
| * @return 影响行数 | |||
| */ | |||
| int insert(Workflow workflow); | |||
| int insert(@Param("workflow") Workflow workflow); | |||
| /** | |||
| * 批量新增数据(MyBatis原生foreach方法) | |||
| @@ -70,7 +70,7 @@ public interface WorkflowDao { | |||
| * @param workflow 实例对象 | |||
| * @return 影响行数 | |||
| */ | |||
| int update(Workflow workflow); | |||
| int update(@Param("workflow") Workflow workflow); | |||
| /** | |||
| * 通过主键删除数据 | |||
| @@ -86,6 +86,6 @@ public interface WorkflowDao { | |||
| * @param name 主键 | |||
| * @return 对象列表 | |||
| */ | |||
| List<Workflow> queryByName(String name); | |||
| List<Workflow> queryByName(@Param("name") String name); | |||
| } | |||
| @@ -213,6 +213,9 @@ public class DatasetServiceImpl implements DatasetService { | |||
| if(file.isEmpty()){ | |||
| throw new Exception("文件为空,无法上传"); | |||
| } | |||
| // 获取文件大小并转换为KB | |||
| long sizeInBytes = file.getSize(); | |||
| double sizeInKB = sizeInBytes / 1024.0; | |||
| //拿到dataset表的id去查数据集名字 | |||
| DatasetVersion datasetVersion = this.datasetVersionDao.queryById(id); | |||
| @@ -243,6 +246,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| // 更新数据库中dataset_version表url记录 | |||
| datasetVersion.setUrl(objectName); | |||
| datasetVersion.setFileName(fileName); | |||
| datasetVersion.setFileSize(String.valueOf(sizeInKB)); | |||
| datasetVersionDao.update(datasetVersion); | |||
| return "数据集成功上传到: " + objectName; | |||
| } catch (Exception e) { | |||
| @@ -202,6 +202,10 @@ public class ModelsServiceImpl implements ModelsService { | |||
| if(file.isEmpty()){ | |||
| throw new Exception("文件为空,无法上传"); | |||
| } | |||
| // 获取文件大小并转换为KB | |||
| long sizeInBytes = file.getSize(); | |||
| double sizeInKB = sizeInBytes / 1024.0; | |||
| //拿到models表的id去查模型名字 | |||
| ModelsVersion modelsVersion = this.modelsVersionDao.queryById(id); | |||
| if (modelsVersion == null){ | |||
| @@ -231,6 +235,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| // 更新数据库url | |||
| modelsVersion.setUrl(objectName); | |||
| modelsVersion.setFileName(fileName); | |||
| modelsVersion.setFileSize(String.valueOf(sizeInKB)); | |||
| modelsVersionDao.update(modelsVersion); | |||
| return "模型成功上传到: " + objectName; | |||
| } catch (Exception e) { | |||
| @@ -19,7 +19,7 @@ | |||
| select | |||
| id, name, description, dag, create_by, create_time, update_by, update_time, state | |||
| from workflow | |||
| where id = #{id} and state = 1 | |||
| where id = #{id} and state = 1 | |||
| </select> | |||
| <!--查询指定行数据--> | |||
| @@ -92,10 +92,12 @@ | |||
| <!--新增所有列--> | |||
| <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | |||
| insert into workflow(name, description, dag, create_by, create_time, update_by, update_time, state) | |||
| values (#{name}, #{description}, #{dag}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{state}) | |||
| insert into workflow(name, description, dag, create_by, create_time, update_by, update_time,state) | |||
| values (#{workflow.name}, #{workflow.description}, #{workflow.dag}, #{workflow.createBy}, #{workflow.createTime}, #{workflow.updateBy}, #{workflow.updateTime}, #{workflow.state}) | |||
| </insert> | |||
| <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> | |||
| insert into workflow(name, description, dag, create_by, create_time, update_by, update_time, state) | |||
| values | |||
| @@ -127,32 +129,32 @@ | |||
| <update id="update"> | |||
| update workflow | |||
| <set> | |||
| <if test="name != null and name != ''"> | |||
| name = #{name}, | |||
| <if test="workflow.name != null and workflow.name != ''"> | |||
| name = #{workflow.name}, | |||
| </if> | |||
| <if test="description != null and description != ''"> | |||
| description = #{description}, | |||
| <if test="workflow.description != null and workflow.description != ''"> | |||
| description = #{workflow.description}, | |||
| </if> | |||
| <if test="dag != null and dag != ''"> | |||
| dag = #{dag}, | |||
| <if test="workflow.dag != null and workflow.dag != ''"> | |||
| dag = #{workflow.dag}, | |||
| </if> | |||
| <if test="createBy != null and createBy != ''"> | |||
| create_by = #{createBy}, | |||
| <if test="workflow.createBy != null and workflow.createBy != ''"> | |||
| create_by = #{workflow.createBy}, | |||
| </if> | |||
| <if test="createTime != null"> | |||
| create_time = #{createTime}, | |||
| <if test="workflow.createTime != null"> | |||
| create_time = #{workflow.createTime}, | |||
| </if> | |||
| <if test="updateBy != null and updateBy != ''"> | |||
| update_by = #{updateBy}, | |||
| <if test="workflow.updateBy != null and workflow.updateBy != ''"> | |||
| update_by = #{workflow.updateBy}, | |||
| </if> | |||
| <if test="updateTime != null"> | |||
| update_time = #{updateTime}, | |||
| <if test="workflow.updateTime != null"> | |||
| update_time = #{workflow.updateTime}, | |||
| </if> | |||
| <if test="state != null"> | |||
| state = #{state}, | |||
| <if test="workflow.state != null"> | |||
| state = #{workflow.state} | |||
| </if> | |||
| </set> | |||
| where id = #{id} | |||
| where id = #{workflow.id} | |||
| </update> | |||
| <!--通过主键删除--> | |||
| @@ -167,8 +169,8 @@ | |||
| from workflow | |||
| <where> | |||
| state = 1 | |||
| <if test="name != null and name != ''"> | |||
| and name like "%"#{name}"%" | |||
| <if test="workflow.name != null and workflow.name != ''"> | |||
| and name like "%"#{workflow.name}"%" | |||
| </if> | |||
| </where> | |||
| </select> | |||