提交 | 用户 | 时间
|
3e61b6
|
1 |
package com.iailab.module.model.matlab.controller.admin; |
D |
2 |
|
|
3 |
import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
|
4 |
import com.iailab.framework.common.page.PageData; |
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
|
6 |
import com.iailab.module.model.matlab.common.exceptions.IllegalityJarException; |
|
7 |
import com.iailab.module.model.matlab.dto.MatlabJarFileInfoDTO; |
|
8 |
import com.iailab.module.model.matlab.dto.MatlabRunDTO; |
|
9 |
import com.iailab.module.model.matlab.dto.MlModelDTO; |
|
10 |
import com.iailab.module.model.matlab.service.MlModelService; |
|
11 |
import com.iailab.module.model.mpk.dto.MpkFileDTO; |
|
12 |
import io.swagger.v3.oas.annotations.Operation; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
|
14 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
15 |
import org.springframework.web.bind.annotation.*; |
|
16 |
import org.springframework.web.multipart.MultipartFile; |
|
17 |
|
|
18 |
import java.util.HashMap; |
|
19 |
import java.util.List; |
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* @author Dzd |
|
27 |
* @since 1.0.0 2025-02-08 |
|
28 |
*/ |
|
29 |
@RestController |
|
30 |
@RequestMapping("/model/matlab/model") |
|
31 |
public class MlModelController { |
|
32 |
@Autowired |
|
33 |
private MlModelService mlModelService; |
|
34 |
|
|
35 |
@GetMapping("page") |
|
36 |
@Operation(summary = "分页") |
|
37 |
@PreAuthorize("@ss.hasPermission('ml:model:query')") |
|
38 |
public CommonResult<PageData<MlModelDTO>> page(@RequestParam Map<String, Object> params) { |
|
39 |
PageData<MlModelDTO> page = mlModelService.page(params); |
|
40 |
return success(page); |
|
41 |
} |
|
42 |
|
|
43 |
@GetMapping("{id}") |
|
44 |
@Operation(summary = "信息") |
|
45 |
@PreAuthorize("@ss.hasPermission('ml:model:query')") |
|
46 |
public CommonResult<MlModelDTO> get(@PathVariable("id") String id){ |
|
47 |
MlModelDTO data = mlModelService.get(id); |
|
48 |
|
|
49 |
return success(data); |
|
50 |
} |
|
51 |
|
|
52 |
@PreAuthorize("@ss.hasPermission('ml:model:query')") |
|
53 |
@GetMapping("list") |
|
54 |
public CommonResult<List<MlModelDTO>> list(@RequestParam Map<String, Object> params) { |
|
55 |
List<MlModelDTO> list = mlModelService.list(params); |
|
56 |
|
|
57 |
return success(list); |
|
58 |
} |
|
59 |
|
|
60 |
@PostMapping |
|
61 |
@Operation(summary = "保存") |
|
62 |
@PreAuthorize("@ss.hasPermission('ml:model:create')") |
|
63 |
public CommonResult save(@RequestBody MlModelDTO dto){ |
|
64 |
mlModelService.save(dto); |
|
65 |
|
|
66 |
return success(); |
|
67 |
} |
|
68 |
|
|
69 |
@PutMapping |
|
70 |
@Operation(summary = "修改") |
|
71 |
@PreAuthorize("@ss.hasPermission('ml:model:update')") |
|
72 |
public CommonResult update(@RequestBody MlModelDTO dto){ |
|
73 |
mlModelService.update(dto); |
|
74 |
|
|
75 |
return success(); |
|
76 |
} |
|
77 |
|
|
78 |
@DeleteMapping |
|
79 |
@Operation(summary = "删除") |
|
80 |
@PreAuthorize("@ss.hasPermission('ml:model:delete')") |
|
81 |
public CommonResult delete(String id){ |
|
82 |
|
|
83 |
mlModelService.delete(id); |
|
84 |
|
|
85 |
return success(); |
|
86 |
} |
|
87 |
|
|
88 |
@PostMapping("/upload") |
|
89 |
@Operation(summary = "算法封装jar文件上传") |
|
90 |
public CommonResult<MatlabJarFileInfoDTO> upload(@RequestParam("file") MultipartFile file){ |
|
91 |
MatlabJarFileInfoDTO result = null; |
|
92 |
try { |
|
93 |
result = mlModelService.uploadJarFile(file); |
|
94 |
} catch (IllegalityJarException e) { |
|
95 |
return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"非法jar包"); |
|
96 |
} |
|
97 |
return success(result); |
|
98 |
} |
|
99 |
|
|
100 |
@PostMapping("/test") |
|
101 |
@Operation(summary = "Matlab测试运行") |
|
102 |
public CommonResult<String> test(@RequestBody MatlabRunDTO dto) { |
|
103 |
return mlModelService.test(dto); |
|
104 |
} |
|
105 |
|
|
106 |
@PostMapping("/importData") |
|
107 |
@Operation(summary = "导入参数") |
|
108 |
public CommonResult<List<HashMap<String,Object>>> importData(@RequestParam("file") MultipartFile file) throws Exception { |
|
109 |
List<HashMap<String,Object>> result = mlModelService.importData(file); |
|
110 |
return success(result); |
|
111 |
} |
|
112 |
|
|
113 |
} |