dengzedong
2024-10-10 c12dae87f1dba43ccc2c5966a134ddf88b5eb102
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -7,6 +7,8 @@
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -30,19 +32,24 @@
    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("@ss.hasPermission('mpk:file:query')")
    public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) {
        PageData<MpkFileDTO> page = mpkFileService.page(params);
        return success(page);
    }
    @PreAuthorize("@ss.hasPermission('mpk:file:query')")
    @GetMapping("{id}")
    public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) {
        MpkFileDTO schedule = mpkFileService.get(id);
        List<String> menuAndGroup = new ArrayList<>();
        menuAndGroup.add(schedule.getMenuName());
        menuAndGroup.add(schedule.getGroupName());
        schedule.setMenuAndGroup(menuAndGroup);
        return success(schedule);
    }
    @PreAuthorize("@ss.hasPermission('mpk:file:query')")
    @GetMapping("list")
    public CommonResult<List<MpkFileDTO>> list() {
        List<MpkFileDTO> list = mpkFileService.list(new HashMap<>());
@@ -50,34 +57,53 @@
        return success(list);
    }
    @PreAuthorize("@ss.hasPermission('mpk:file:create')")
    @PostMapping
    public CommonResult save(@RequestBody MpkFileDTO dto) {
    public CommonResult<Boolean> save(@RequestBody MpkFileDTO dto) {
        if (!CollectionUtils.isEmpty(dto.getMenuAndGroup())) {
            dto.setMenuName(dto.getMenuAndGroup().get(0));
            if (dto.getMenuAndGroup().size() > 1) {
                dto.setGroupName(dto.getMenuAndGroup().get(1));
            }
        }
        mpkFileService.save(dto);
        return CommonResult.success();
        return CommonResult.success(true);
    }
    @PreAuthorize("@ss.hasPermission('mpk:file:delete')")
    @DeleteMapping
    public CommonResult delete(String id) {
    public CommonResult<Boolean> delete(String id) {
        mpkFileService.delete(id);
        return CommonResult.success();
        return CommonResult.success(true);
    }
    @PreAuthorize("@ss.hasPermission('mpk:file:update')")
    @PutMapping
    public CommonResult update(@RequestBody MpkFileDTO dto) {
    public CommonResult<Boolean> update(@RequestBody MpkFileDTO dto) {
        if (!CollectionUtils.isEmpty(dto.getMenuAndGroup())) {
            dto.setMenuName(dto.getMenuAndGroup().get(0));
            if (dto.getMenuAndGroup().size() > 1) {
                dto.setGroupName(dto.getMenuAndGroup().get(1));
            }
        }
        mpkFileService.update(dto);
        return CommonResult.success();
        return CommonResult.success(true);
    }
    @GetMapping("generat")
    public void generat(String id, String remark,String zipFileName, HttpServletResponse response) throws IOException {
        byte[] data = mpkFileService.generatorCode(id, remark,zipFileName);
    public void generat(String id, String remark,String zipFileName, HttpServletResponse response) {
        try {
            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");
            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());
            IOUtils.write(data, response.getOutputStream());
        } catch (Exception e) {
            throw new RuntimeException("代码生成异常",e);
        }
    }
    @GetMapping("packageModel")
@@ -99,8 +125,13 @@
    @PostMapping("/upload")
    @Operation(summary = "python文件上传")
    public CommonResult<Map<String,String>> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
    public CommonResult<Map<String,String>> upload(@RequestParam("file") MultipartFile file) throws Exception {
        Map<String,String> result = mpkFileService.savePyFile(file);
        return success(result);
    }
    @PostMapping("/publish")
    public CommonResult<String> publish(@RequestBody Map<String, Object> params) {
        return mpkFileService.publish(params);
    }
}