package com.iailab.module.model.mpk.controller.admin;
|
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.pojo.CommonResult;
|
import com.iailab.module.model.mpk.dto.MpkFileDTO;
|
import com.iailab.module.model.mpk.service.MpkFileService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import org.apache.commons.io.IOUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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 MpkFileService mpkFileService;
|
|
@GetMapping("page")
|
@Operation(summary = "分页")
|
public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) {
|
PageData<MpkFileDTO> page = mpkFileService.page(params);
|
|
return success(page);
|
}
|
|
@GetMapping("{id}")
|
public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) {
|
MpkFileDTO schedule = mpkFileService.get(id);
|
|
return success(schedule);
|
}
|
|
@GetMapping("list")
|
public CommonResult<List<MpkFileDTO>> list() {
|
List<MpkFileDTO> list = mpkFileService.list(new HashMap<>());
|
|
return success(list);
|
}
|
|
@PostMapping
|
public CommonResult save(@RequestBody MpkFileDTO dto) {
|
mpkFileService.save(dto);
|
return CommonResult.success();
|
}
|
|
@DeleteMapping
|
public CommonResult delete(String id) {
|
mpkFileService.delete(id);
|
return CommonResult.success();
|
}
|
|
@PutMapping
|
public CommonResult update(@RequestBody MpkFileDTO dto) {
|
mpkFileService.update(dto);
|
return CommonResult.success();
|
}
|
|
@GetMapping("generat")
|
public void generat(String id, String remark,String zipFileName, HttpServletResponse response) throws IOException {
|
byte[] data = mpkFileService.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 = mpkFileService.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 = mpkFileService.savePyFile(file);
|
return success(result);
|
}
|
}
|