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