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