提交 | 用户 | 时间
|
c06f48
|
1 |
package com.iailab.module.model.mcs.pre.controller.admin; |
7fd198
|
2 |
|
1a2b62
|
3 |
import cn.hutool.core.io.FileUtil; |
5c6007
|
4 |
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
7fd198
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
潘 |
6 |
import com.iailab.framework.common.pojo.PageResult; |
137356
|
7 |
import com.iailab.module.model.common.enums.CommonConstant; |
7fd198
|
8 |
import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO; |
潘 |
9 |
import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
9f049d
|
10 |
import com.iailab.module.model.mcs.pre.vo.*; |
137356
|
11 |
import com.iailab.module.model.mpk.common.utils.IAILModelUtil; |
9f049d
|
12 |
import lombok.extern.slf4j.Slf4j; |
7fd198
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
137356
|
14 |
import org.springframework.beans.factory.annotation.Value; |
abba54
|
15 |
import org.springframework.security.access.prepost.PreAuthorize; |
5c6007
|
16 |
import org.springframework.validation.annotation.Validated; |
7fd198
|
17 |
import org.springframework.web.bind.annotation.*; |
潘 |
18 |
import org.springframework.web.multipart.MultipartFile; |
|
19 |
|
137356
|
20 |
import javax.annotation.security.PermitAll; |
潘 |
21 |
import java.io.File; |
9f049d
|
22 |
import java.util.*; |
7fd198
|
23 |
|
潘 |
24 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author PanZhibao |
|
28 |
* @date 2021年04月26日 14:42 |
|
29 |
*/ |
9f049d
|
30 |
@Slf4j |
7fd198
|
31 |
@RestController |
137356
|
32 |
@RequestMapping("/model/pre/item") |
7fd198
|
33 |
public class MmPredictItemController { |
137356
|
34 |
|
潘 |
35 |
@Value("${mpk.model-file-path}") |
|
36 |
private String modelPath; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private IAILModelUtil iAILModelUtil; |
7fd198
|
40 |
|
潘 |
41 |
@Autowired |
|
42 |
private MmPredictItemService mmPredictItemService; |
48c57b
|
43 |
|
7fd198
|
44 |
/** |
潘 |
45 |
* 预测项列表 |
|
46 |
*/ |
|
47 |
@GetMapping("/page") |
905742
|
48 |
@PreAuthorize("@ss.hasPermission('model:pre-item:query')") |
5c6007
|
49 |
public CommonResult<PageResult<MmPredictItemRespVO>> page(@Validated MmPredictItemPageReqVO reqVO) { |
137356
|
50 |
PageResult<MmPredictItemRespVO> page = mmPredictItemService.queryPage(reqVO); |
潘 |
51 |
return success(page); |
7fd198
|
52 |
} |
潘 |
53 |
|
5d299c
|
54 |
@GetMapping("/list") |
4be7d8
|
55 |
public CommonResult<List<MmPredictItemRespVO>> list(@RequestParam Map<String, Object> params) { |
a97b38
|
56 |
List<MmPredictItemRespVO> list = mmPredictItemService.list(params); |
5d299c
|
57 |
return success(list); |
L |
58 |
} |
|
59 |
|
7fd198
|
60 |
/** |
潘 |
61 |
* 预测项信息 |
|
62 |
*/ |
d395d2
|
63 |
@GetMapping("/get/{id}") |
905742
|
64 |
@PreAuthorize("@ss.hasPermission('model:pre-item:query')") |
137356
|
65 |
public CommonResult<MmPredictItemDTO> info(@PathVariable("id") String id) { |
5c6007
|
66 |
MmPredictItemDTO predictItem = mmPredictItemService.info(id); |
7fd198
|
67 |
return success(predictItem); |
潘 |
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* 保存预测项 |
|
72 |
*/ |
d395d2
|
73 |
@PostMapping("/create") |
905742
|
74 |
@PreAuthorize("@ss.hasPermission('model:pre-item:create')") |
137356
|
75 |
@DSTransactional(rollbackFor = Exception.class) |
潘 |
76 |
public CommonResult<Boolean> save(@RequestBody MmPredictItemDTO mmPredictItemDto) { |
5d299c
|
77 |
mmPredictItemService.add(mmPredictItemDto); |
7fd198
|
78 |
return success(true); |
潘 |
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* 修改预测项 |
|
83 |
*/ |
d395d2
|
84 |
@PutMapping("/update") |
905742
|
85 |
@PreAuthorize("@ss.hasPermission('model:pre-item:update')") |
137356
|
86 |
@DSTransactional(rollbackFor = Exception.class) |
潘 |
87 |
public CommonResult<Boolean> update(@RequestBody MmPredictItemDTO mmPredictItemDTO) { |
5d299c
|
88 |
mmPredictItemService.update(mmPredictItemDTO); |
7fd198
|
89 |
return success(true); |
潘 |
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* 删除预测项 |
|
94 |
*/ |
d395d2
|
95 |
@DeleteMapping("/delete") |
905742
|
96 |
@PreAuthorize("@ss.hasPermission('model:pre-item:delete')") |
137356
|
97 |
@DSTransactional(rollbackFor = Exception.class) |
d395d2
|
98 |
public CommonResult<Boolean> delete(@RequestParam("id") String id) { |
L |
99 |
mmPredictItemService.deleteBatch(new String[]{id}); |
7fd198
|
100 |
return success(true); |
潘 |
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* 预测项列表 |
|
105 |
*/ |
|
106 |
@GetMapping("/count-itemtype") |
137356
|
107 |
public CommonResult<List<CountItemtypeVO>> countItemtype(@RequestParam Map<String, Object> params) { |
7fd198
|
108 |
List<CountItemtypeVO> list = new ArrayList<>(); |
潘 |
109 |
return success(list); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* 上传模型 |
|
114 |
*/ |
137356
|
115 |
@PermitAll |
潘 |
116 |
@PostMapping("/upload-model") |
|
117 |
public CommonResult<Map<String, Object>> uploadModel(@RequestParam("file") MultipartFile file) throws Exception { |
|
118 |
String uploadDir = modelPath + file.getOriginalFilename(); |
1a2b62
|
119 |
FileUtil.mkParentDirs(uploadDir); |
137356
|
120 |
file.transferTo(new File(uploadDir)); |
潘 |
121 |
Map<String, Object> result = iAILModelUtil.parseModel(uploadDir); |
|
122 |
result.put("originalFilename", file.getOriginalFilename().replace(CommonConstant.MDK_SUFFIX, "")); |
9f049d
|
123 |
return success(result); |
J |
124 |
} |
7fd198
|
125 |
} |