diff --git a/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java b/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java index f078878..b631845 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/CaseStepController.java @@ -55,7 +55,7 @@ public class CaseStepController { @PostMapping("updateCase") public ResultEntity updateCase(@RequestBody SysCaseQuestionStepWithBLOBs caseQuestionStepWithBLOBs, @ApiParam("谁调的请求,传管理员/学校ID") @RequestParam String source) { - List sysTopicAndCourses = getSysTopicAndCourses(caseQuestionStepWithBLOBs.getCaseId()); +// List sysTopicAndCourses = getSysTopicAndCourses(caseQuestionStepWithBLOBs.getCaseId()); // if (!sysTopicAndCourses.isEmpty()) { // return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该案例题正在被使用!"); // } @@ -63,7 +63,7 @@ public class CaseStepController { //todo 管理员任意修改,老师只能改自己的 SysCaseQuestion sysCaseQuestion = sysCaseQuestionMapper.selectByPrimaryKey(caseQuestionStepWithBLOBs.getCaseId()); if ("管理员".equals(source) || source.equals(sysCaseQuestion.getSource())) { - caseQuestionStepMapper.updateByPrimaryKey(caseQuestionStepWithBLOBs); + caseQuestionStepMapper.updateByPrimaryKeyWithBLOBs(caseQuestionStepWithBLOBs); return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); } else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足!"); diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java index 9b2c28d..989b15e 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/CaseApi.java @@ -293,6 +293,7 @@ public class CaseApi { SysCaseQuestionExample example1 = new SysCaseQuestionExample(); example1.createCriteria().andCaseIdIn(collect).andSourceEqualTo("管理员"); + example1.setOrderByClause("create_time"); List list = caseQuestionMapper.selectByExampleWithBLOBs(example1); return list; } @@ -307,12 +308,8 @@ public class CaseApi { @PostMapping("selectCaseStepListBatchByIdListAndSort") @ApiOperation("查询案例题步骤并排序") @AnonymousAccess - public List selectCaseStepListBatchByIdListAndSort(@RequestBody List caseIdList) { - SysCaseQuestionStepExample example = new SysCaseQuestionStepExample(); - example.createCriteria().andCaseIdIn(caseIdList); - example.setOrderByClause("sort"); - List sysCaseQuestionStepWithBLOBs = caseQuestionStepMapper.selectByExampleWithBLOBs(example); - return sysCaseQuestionStepWithBLOBs; + public List selectCaseStepListBatchByIdListAndSort(@RequestParam String threeId) { + return caseQuestionStepMapper.selectCaseStepListBatchByIdListAndSort(threeId); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java index d802ce9..9487714 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java @@ -126,7 +126,7 @@ public class ResourceDataApi { List> filePaths = sysResourceDataMapper.getByIds(ids); String zipName = "TZ_" + ((int) (Math.random() * 10000)) + ".zip"; String zipPath = filePath + "/" + zipName; - CompressUtil.compress(filePaths, zipPath, false); + CompressUtil.compress11(filePaths, zipPath, false); File pocZipFile = new File(zipPath); CompressUtil.downloadZip(response, zipName, pocZipFile); pocZipFile.delete(); diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java index 007d1ec..69b44c5 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysCaseQuestionStepMapper.java @@ -45,4 +45,6 @@ public interface SysCaseQuestionStepMapper { List selectTrainingByIds(@Param("list") List caseStepIdList); List getCaseStepByIds(@Param("ids") List ids); + + List selectCaseStepListBatchByIdListAndSort(@Param("threeId") String threeId); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/resource_center/util/CompressUtil.java b/src/main/java/com/sztzjy/resource_center/util/CompressUtil.java index 40ba6f6..8748cf9 100644 --- a/src/main/java/com/sztzjy/resource_center/util/CompressUtil.java +++ b/src/main/java/com/sztzjy/resource_center/util/CompressUtil.java @@ -48,7 +48,51 @@ public class CompressUtil { if (keepDirStructure != null && keepDirStructure) { zos.putNextEntry(new ZipEntry(relativePath)); } else { - zos.putNextEntry(new ZipEntry(i + "_" + relativeName)); + zos.putNextEntry(new ZipEntry(relativeName)); + } + int len; + while ((len = fis.read(buf)) > 0) { + zos.write(buf, 0, len); + } + zos.closeEntry(); + // zos.close(); + } + zos.close(); + if (!zipFile.exists()) { + zipFile.createNewFile(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * 生成zip压缩文件 + * @param filePaths + * @param zipFilePath + * @param keepDirStructure + */ + public static void compress11(List> filePaths, String zipFilePath, Boolean keepDirStructure) { + byte[] buf = new byte[1024]; + File zipFile = new File(zipFilePath); + try { + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); + for (int i = 0; i < filePaths.size(); i++) { + String relativeName = filePaths.get(i).get("resource_name"); + String relativePath = filePath+filePaths.get(i).get("url"); + if (StringUtils.isEmpty(relativePath)) { + continue; + } + File sourceFile = new File(relativePath); + if (sourceFile == null || !sourceFile.exists()) { + continue; + } + FileInputStream fis = new FileInputStream(sourceFile); + if (keepDirStructure != null && keepDirStructure) { + zos.putNextEntry(new ZipEntry(relativePath)); + } else { + zos.putNextEntry(new ZipEntry(relativeName)); } int len; while ((len = fis.read(buf)) > 0) { diff --git a/src/main/resources/mapper/SysCaseQuestionStepMapper.xml b/src/main/resources/mapper/SysCaseQuestionStepMapper.xml index 0a95801..809df3a 100644 --- a/src/main/resources/mapper/SysCaseQuestionStepMapper.xml +++ b/src/main/resources/mapper/SysCaseQuestionStepMapper.xml @@ -421,7 +421,8 @@ + + \ No newline at end of file