提交 | 用户 | 时间
|
449017
|
1 |
package com.iailab.module.model.mpk.controller.admin; |
D |
2 |
|
|
3 |
import com.iailab.framework.common.page.PageData; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.module.model.mpk.dto.MpkFileDTO; |
0255ea
|
6 |
import com.iailab.module.model.mpk.service.MpkFileService; |
449017
|
7 |
import io.swagger.v3.oas.annotations.Operation; |
D |
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
b425df
|
10 |
import org.springframework.security.access.prepost.PreAuthorize; |
d8db4b
|
11 |
import org.springframework.util.CollectionUtils; |
449017
|
12 |
import org.springframework.web.bind.annotation.*; |
D |
13 |
import org.springframework.web.multipart.MultipartFile; |
|
14 |
|
|
15 |
import javax.servlet.http.HttpServletResponse; |
|
16 |
import java.io.IOException; |
|
17 |
import java.net.URLEncoder; |
|
18 |
import java.util.*; |
|
19 |
|
|
20 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author dzd |
|
24 |
* @Description |
|
25 |
* @createTime 2024年08月14日 |
|
26 |
*/ |
|
27 |
@RestController |
|
28 |
@RequestMapping("/model/mpk/file") |
|
29 |
public class MpkFileController { |
|
30 |
@Autowired |
0255ea
|
31 |
private MpkFileService mpkFileService; |
449017
|
32 |
|
D |
33 |
@GetMapping("page") |
|
34 |
@Operation(summary = "分页") |
b425df
|
35 |
@PreAuthorize("@ss.hasPermission('mpk:file:query')") |
449017
|
36 |
public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) { |
0255ea
|
37 |
PageData<MpkFileDTO> page = mpkFileService.page(params); |
449017
|
38 |
return success(page); |
D |
39 |
} |
|
40 |
|
b425df
|
41 |
@PreAuthorize("@ss.hasPermission('mpk:file:query')") |
449017
|
42 |
@GetMapping("{id}") |
D |
43 |
public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) { |
0255ea
|
44 |
MpkFileDTO schedule = mpkFileService.get(id); |
d8db4b
|
45 |
List<String> menuAndGroup = new ArrayList<>(); |
潘 |
46 |
menuAndGroup.add(schedule.getMenuName()); |
|
47 |
menuAndGroup.add(schedule.getGroupName()); |
|
48 |
schedule.setMenuAndGroup(menuAndGroup); |
449017
|
49 |
return success(schedule); |
D |
50 |
} |
|
51 |
|
b425df
|
52 |
@PreAuthorize("@ss.hasPermission('mpk:file:query')") |
449017
|
53 |
@GetMapping("list") |
D |
54 |
public CommonResult<List<MpkFileDTO>> list() { |
0255ea
|
55 |
List<MpkFileDTO> list = mpkFileService.list(new HashMap<>()); |
449017
|
56 |
|
D |
57 |
return success(list); |
|
58 |
} |
|
59 |
|
b425df
|
60 |
@PreAuthorize("@ss.hasPermission('mpk:file:create')") |
449017
|
61 |
@PostMapping |
b425df
|
62 |
public CommonResult<Boolean> save(@RequestBody MpkFileDTO dto) { |
d8db4b
|
63 |
if (!CollectionUtils.isEmpty(dto.getMenuAndGroup())) { |
潘 |
64 |
dto.setMenuName(dto.getMenuAndGroup().get(0)); |
|
65 |
if (dto.getMenuAndGroup().size() > 1) { |
|
66 |
dto.setGroupName(dto.getMenuAndGroup().get(1)); |
|
67 |
} |
|
68 |
} |
0255ea
|
69 |
mpkFileService.save(dto); |
b425df
|
70 |
return CommonResult.success(true); |
449017
|
71 |
} |
D |
72 |
|
b425df
|
73 |
@PreAuthorize("@ss.hasPermission('mpk:file:delete')") |
449017
|
74 |
@DeleteMapping |
b425df
|
75 |
public CommonResult<Boolean> delete(String id) { |
0255ea
|
76 |
mpkFileService.delete(id); |
b425df
|
77 |
return CommonResult.success(true); |
449017
|
78 |
} |
D |
79 |
|
b425df
|
80 |
@PreAuthorize("@ss.hasPermission('mpk:file:update')") |
449017
|
81 |
@PutMapping |
b425df
|
82 |
public CommonResult<Boolean> update(@RequestBody MpkFileDTO dto) { |
d8db4b
|
83 |
if (!CollectionUtils.isEmpty(dto.getMenuAndGroup())) { |
潘 |
84 |
dto.setMenuName(dto.getMenuAndGroup().get(0)); |
|
85 |
if (dto.getMenuAndGroup().size() > 1) { |
|
86 |
dto.setGroupName(dto.getMenuAndGroup().get(1)); |
|
87 |
} |
|
88 |
} |
0255ea
|
89 |
mpkFileService.update(dto); |
b425df
|
90 |
return CommonResult.success(true); |
449017
|
91 |
} |
D |
92 |
|
|
93 |
@GetMapping("generat") |
1fea3e
|
94 |
public void generat(String id, String remark,String zipFileName, HttpServletResponse response) { |
D |
95 |
try { |
|
96 |
byte[] data = mpkFileService.generatorCode(id, remark,zipFileName); |
449017
|
97 |
|
1fea3e
|
98 |
response.reset(); |
D |
99 |
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\""); |
|
100 |
response.addHeader("Content-Length", "" + data.length); |
|
101 |
response.setContentType("application/octet-stream; charset=UTF-8"); |
449017
|
102 |
|
1fea3e
|
103 |
IOUtils.write(data, response.getOutputStream()); |
D |
104 |
} catch (Exception e) { |
912a1e
|
105 |
throw new RuntimeException("代码生成异常",e); |
1fea3e
|
106 |
} |
449017
|
107 |
} |
D |
108 |
|
|
109 |
@GetMapping("packageModel") |
|
110 |
public void packageModel(String ids ,String projectId,String log ,String projectName,String version,String zipFileName,HttpServletResponse response) throws IOException { |
|
111 |
byte[] data; |
|
112 |
try { |
0255ea
|
113 |
data = mpkFileService.packageModel(Arrays.asList(ids.split(",")),projectId,projectName,zipFileName,log,version); |
449017
|
114 |
} catch (InterruptedException e) { |
D |
115 |
throw new RuntimeException("模型打包失败",e); |
|
116 |
} |
|
117 |
|
|
118 |
response.reset(); |
|
119 |
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\""); |
|
120 |
response.addHeader("Content-Length", "" + data.length); |
|
121 |
response.setContentType("application/octet-stream; charset=UTF-8"); |
|
122 |
|
|
123 |
IOUtils.write(data, response.getOutputStream()); |
|
124 |
} |
|
125 |
|
|
126 |
@PostMapping("/upload") |
|
127 |
@Operation(summary = "python文件上传") |
|
128 |
public CommonResult<Map<String,String>> importExcel(@RequestParam("file") MultipartFile file) throws Exception { |
0255ea
|
129 |
Map<String,String> result = mpkFileService.savePyFile(file); |
449017
|
130 |
return success(result); |
D |
131 |
} |
|
132 |
} |