dengzedong
2024-09-14 e18f2001fda0eccfbf2aa617e127c70b92083909
提交 | 用户 | 时间
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;
10 import org.springframework.web.bind.annotation.*;
11 import org.springframework.web.multipart.MultipartFile;
12
13 import javax.servlet.http.HttpServletResponse;
14 import java.io.IOException;
15 import java.net.URLEncoder;
16 import java.util.*;
17
18 import static com.iailab.framework.common.pojo.CommonResult.success;
19
20 /**
21  * @author dzd
22  * @Description
23  * @createTime 2024年08月14日
24  */
25 @RestController
26 @RequestMapping("/model/mpk/file")
27 public class MpkFileController {
28     @Autowired
0255ea 29     private MpkFileService mpkFileService;
449017 30
D 31     @GetMapping("page")
32     @Operation(summary = "分页")
33     public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) {
0255ea 34         PageData<MpkFileDTO> page = mpkFileService.page(params);
449017 35
D 36         return success(page);
37     }
38
39     @GetMapping("{id}")
40     public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) {
0255ea 41         MpkFileDTO schedule = mpkFileService.get(id);
449017 42
D 43         return success(schedule);
44     }
45
46     @GetMapping("list")
47     public CommonResult<List<MpkFileDTO>> list() {
0255ea 48         List<MpkFileDTO> list = mpkFileService.list(new HashMap<>());
449017 49
D 50         return success(list);
51     }
52
53     @PostMapping
54     public CommonResult save(@RequestBody MpkFileDTO dto) {
0255ea 55         mpkFileService.save(dto);
449017 56         return CommonResult.success();
D 57     }
58
59     @DeleteMapping
60     public CommonResult delete(String id) {
0255ea 61         mpkFileService.delete(id);
449017 62         return CommonResult.success();
D 63     }
64
65     @PutMapping
66     public CommonResult update(@RequestBody MpkFileDTO dto) {
0255ea 67         mpkFileService.update(dto);
449017 68         return CommonResult.success();
D 69     }
70
71     @GetMapping("generat")
72     public void generat(String id, String remark,String zipFileName, HttpServletResponse response) throws IOException {
0255ea 73         byte[] data = mpkFileService.generatorCode(id, remark,zipFileName);
449017 74
D 75         response.reset();
76         response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\"");
77         response.addHeader("Content-Length", "" + data.length);
78         response.setContentType("application/octet-stream; charset=UTF-8");
79
80         IOUtils.write(data, response.getOutputStream());
81     }
82
83     @GetMapping("packageModel")
84     public void packageModel(String ids ,String projectId,String log ,String projectName,String version,String zipFileName,HttpServletResponse response) throws IOException {
85         byte[] data;
86         try {
0255ea 87             data = mpkFileService.packageModel(Arrays.asList(ids.split(",")),projectId,projectName,zipFileName,log,version);
449017 88         } catch (InterruptedException e) {
D 89             throw new RuntimeException("模型打包失败",e);
90         }
91
92         response.reset();
93         response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\"");
94         response.addHeader("Content-Length", "" + data.length);
95         response.setContentType("application/octet-stream; charset=UTF-8");
96
97         IOUtils.write(data, response.getOutputStream());
98     }
99
100     @PostMapping("/upload")
101     @Operation(summary = "python文件上传")
102     public CommonResult<Map<String,String>> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
0255ea 103         Map<String,String> result = mpkFileService.savePyFile(file);
449017 104         return success(result);
D 105     }
106 }