dengzedong
10 天以前 f1fe397df175a7ee809ea28530419116af84af28
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -4,8 +4,10 @@
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.module.model.mpk.dto.MpkFileDTO;
import com.iailab.module.model.mpk.service.MpkFileService;
import com.iailab.module.model.mpk.service.PackService;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
@@ -30,6 +32,9 @@
    @Autowired
    private MpkFileService mpkFileService;
    @Autowired
    private PackService packService;
    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("@ss.hasPermission('mpk:file:query')")
@@ -43,16 +48,20 @@
    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());
        if (StringUtils.isNotBlank(schedule.getMenuName())) {
            menuAndGroup.add(schedule.getMenuName());
        }
        if (StringUtils.isNotBlank(schedule.getGroupName())) {
            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<>());
    public CommonResult<List<MpkFileDTO>> list(@RequestParam Map<String, Object> params) {
        List<MpkFileDTO> list = mpkFileService.list(params);
        return success(list);
    }
@@ -66,6 +75,7 @@
                dto.setGroupName(dto.getMenuAndGroup().get(1));
            }
        }
        dto.setPyModule(packService.getModelPath(dto.getPkgName()));
        mpkFileService.save(dto);
        return CommonResult.success(true);
    }
@@ -86,6 +96,7 @@
                dto.setGroupName(dto.getMenuAndGroup().get(1));
            }
        }
        dto.setPyModule(packService.getModelPath(dto.getPkgName()));
        mpkFileService.update(dto);
        return CommonResult.success(true);
    }
@@ -102,15 +113,15 @@
            IOUtils.write(data, response.getOutputStream());
        } catch (Exception e) {
            throw new RuntimeException("代码生成异常");
            throw new RuntimeException("代码生成异常",e);
        }
    }
    @GetMapping("packageModel")
    public void packageModel(String ids ,String projectId,String log ,String projectName,String version,String zipFileName,HttpServletResponse response) throws IOException {
    public void packageModel(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);
            data = mpkFileService.packageModel(projectId,projectName,zipFileName,log,version);
        } catch (InterruptedException e) {
            throw new RuntimeException("模型打包失败",e);
        }
@@ -125,8 +136,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);
    }
}