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