From cd8c0a32e364c9a5f9041b81e5d2819292d020c0 Mon Sep 17 00:00:00 2001 From: "liang.chao" <1360241448@qq.com> Date: Wed, 21 May 2025 14:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BD=E5=90=8E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80=EF=BC=8C?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=86=85=E5=AE=B9=E4=B8=BA=E7=A9=BAbug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoursewareLibraryController.java | 21 +++-- .../impl/CoursewareLibraryServiceImpl.java | 70 +++++++++++--- .../service/impl/ProjectServiceImpl.java | 93 ++++++++++++------- 3 files changed, 132 insertions(+), 52 deletions(-) diff --git a/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/controller/CoursewareLibraryController.java b/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/controller/CoursewareLibraryController.java index 51bfef2..19be09d 100644 --- a/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/controller/CoursewareLibraryController.java +++ b/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/controller/CoursewareLibraryController.java @@ -93,9 +93,12 @@ public class CoursewareLibraryController { while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line); } - String str=decord(stringBuilder.toString()); + String str = decord(stringBuilder.toString()); + if (str.startsWith("[") && str.endsWith("]")) { + str = str.substring(1, str.length() - 1); + } String courseId = str.split("&")[0].split("=")[1]; - String fileType =str.split("&")[1].split("=")[1]; + String fileType = str.split("&")[1].split("=")[1]; if (!StaticVariableUtils.ONE.equals(fileType)) { dto.setCoursewareId(Integer.parseInt(courseId)); } @@ -108,16 +111,17 @@ public class CoursewareLibraryController { } } - public String decord(String str){ - try{ - return URLDecoder.decode(str, StandardCharsets.UTF_8.toString()); - }catch (Exception e){ - log.error(e.toString(),e); + public String decord(String str) { + try { + return URLDecoder.decode(str, StandardCharsets.UTF_8.toString()); + } catch (Exception e) { + log.error(e.toString(), e); } - return str; + return str; } + /** * 课件上传 * @@ -146,6 +150,7 @@ public class CoursewareLibraryController { /** * 1.新增题库使用的tree 2.移动使用的tree + * * @param dto * @return AjaxResult * @author cwchen diff --git a/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/service/impl/CoursewareLibraryServiceImpl.java b/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/service/impl/CoursewareLibraryServiceImpl.java index bca9b8c..da23905 100644 --- a/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/service/impl/CoursewareLibraryServiceImpl.java +++ b/bonus-modules/bonus-exam/src/main/java/com/bonus/exam/service/impl/CoursewareLibraryServiceImpl.java @@ -35,6 +35,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -148,7 +151,7 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService { if (Objects.equals(dto.getFileType(), BusinessConstants.FILE_TYPE)) { // 多个文件下载 CoursewareVo vo = new CoursewareVo(); - String[] split = dto.getCourseId().split("%252C"); + String[] split = dto.getCourseId().split("%2C"); List list = mapper.getSelectFileToDownload(split); downLoadBatchFile(response, list); @@ -217,7 +220,7 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService { String tempTime = "temp_" + System.currentTimeMillis(); String parentSourceFilePath = upload_path + File.separator + "coursewareZip"; if (!new File(parentSourceFilePath).exists()) { - new File(parentSourceFilePath).mkdir(); + new File(parentSourceFilePath).mkdirs(); } String sourceFilePath = parentSourceFilePath + File.separator + tempTime; String zipFilePath = null; @@ -245,13 +248,34 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService { invokeAllTasks(testTaskExecutor,tasks); //对/usr/local/bonus/uploadPath/tempTime文件夹进行压缩 - // Compress files into a zip - String zipFileName = "courseware_" + tempTime + ".zip"; + String zipFileName = tempTime + ".zip"; zipFilePath = parentSourceFilePath + File.separator + zipFileName; - zipFolderContents(sourceFilePath, zipFilePath); - // Set response headers + zipFolder(sourceFilePath, zipFilePath); + File zipFile = new File(zipFilePath); + if (!zipFile.exists() || zipFile.isDirectory()) { + response.sendError(HttpServletResponse.SC_NOT_FOUND, "文件不存在"); + return; + } + response.setCharacterEncoding("utf-8"); + response.setContentType("application/zip"); + response.setHeader("Content-Disposition", "attachment;filename=" + + URLEncoder.encode(zipFileName, "UTF-8")); + response.setContentLength((int) zipFile.length()); + + try (InputStream is = new FileInputStream(zipFile); + OutputStream os = response.getOutputStream()) { + + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = is.read(buffer)) != -1) { + os.write(buffer, 0, bytesRead); + } + } +// zipFolderContents(sourceFilePath, zipFilePath); + // Set response headers + /* response.setCharacterEncoding("utf-8"); response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment;filename=" .concat(String.valueOf(URLEncoder.encode(zipFileName, "UTF-8")))); @@ -260,19 +284,39 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService { try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { File sourceFolder = new File(sourceFilePath); compressFolderContents(sourceFolder, zos, ""); - } + }*/ } catch (Exception e) { log.error(e.toString(), e); throw new ServiceException("文件下载异常"); - } finally { - -// FileUtil.deleteFolder(Paths.get(sourceFilePath)); -// if (zipFilePath != null) { -// FileUtil.deleteFolder(Paths.get(zipFilePath)); -// } } } + public static void zipFolder(String sourceFolderPath, String zipFilePath) throws IOException { + Path sourcePath = Paths.get(sourceFolderPath); + if (!Files.exists(sourcePath) || !Files.isDirectory(sourcePath)) { + throw new IllegalArgumentException("源文件夹不存在或不是目录: " + sourceFolderPath); + } + Path zipPath = Paths.get(zipFilePath); + try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipPath))) { + Files.walk(sourcePath) + .filter(path -> !Files.isDirectory(path)) // 只处理文件,排除目录本身 + .forEach(path -> { + try { + // 计算相对于源文件夹的相对路径 + Path targetPath = sourcePath.relativize(path); + ZipEntry zipEntry = new ZipEntry(targetPath.toString().replace("\\", "/")); + zos.putNextEntry(zipEntry); + + // 将文件内容写入 ZIP 输出流 + Files.copy(path, zos); + + zos.closeEntry(); + } catch (IOException e) { + System.err.println("无法添加文件到ZIP: " + path + ", 错误信息: " + e.getMessage()); + } + }); + } + } public static boolean zipFolderContents(String sourceFolderPath, String zipFilePath) { try { FileOutputStream fos = new FileOutputStream(zipFilePath); diff --git a/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ProjectServiceImpl.java b/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ProjectServiceImpl.java index 90b01f3..52b4bc0 100644 --- a/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ProjectServiceImpl.java +++ b/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ProjectServiceImpl.java @@ -84,7 +84,7 @@ public class ProjectServiceImpl implements ProjectService { for (BaseBean bean : list) { //获取处理后的短信内容 String content = getMessage(bean); - // ShortMessageUtils.sendShortMessage(bean.getUuid(), content); + // ShortMessageUtils.sendShortMessage(bean.getUuid(), content); MsgBean b = new MsgBean(); b.setPhone(bean.getUuid()); b.setMsg(content); @@ -103,8 +103,10 @@ public class ProjectServiceImpl implements ProjectService { @Value("${user.url}") private String url; + /** * 短信内容处理 + * * @param bean 实体 * @return 短信内容 */ @@ -112,10 +114,10 @@ public class ProjectServiceImpl implements ProjectService { private String getMessage(BaseBean bean) { String content; if (StaticVariableUtils.ZERO_01.equals(bean.getUserType())) { - content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:"+url+ + content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:" + url + ";初始账号:" + bean.getUuid() + ",初始密码:" + supervisionPassword; } else { - content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:"+url+ + content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:" + url + "初始账号:" + bean.getUuid() + ",初始密码:" + contractorPassword; } return content; @@ -159,7 +161,7 @@ public class ProjectServiceImpl implements ProjectService { projectMapper.delConsPersonToPcp(project); projectMapper.delConsPersonToLk(project); - }catch (Exception e){ + } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); log.error("Failed to delete project due to exception", e); } @@ -178,12 +180,12 @@ public class ProjectServiceImpl implements ProjectService { //设置回滚点 Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); try { - if(StringHelper.isNullOrEmptyString(bean.getJlId())){ - return AjaxResult.error("请先选择监理单位"); - }else { + if (StringHelper.isNullOrEmptyString(bean.getJlId())) { + return AjaxResult.error("请先选择监理单位"); + } else { //对监理人员信息进行赋值 - SupervisoryUnit unit= projectMapper.getSupervisoryUnitById(bean); - if(unit==null){ + SupervisoryUnit unit = projectMapper.getSupervisoryUnitById(bean); + if (unit == null) { return AjaxResult.error("监理单位不存在"); } bean.setJlUuid(unit.getJlUuid()); @@ -206,7 +208,7 @@ public class ProjectServiceImpl implements ProjectService { //查询身份证是否重复 result = projectMapper.checkIsExistIdCard(bean.getDirectorsIdCard()); if (result > 0) { - return AjaxResult.error("总监身份证号码已存在!"); + return AjaxResult.error("总监身份证号码已存在!"); } // 添加监理信息到人员表 AdmissionRequest admissionRequest = new AdmissionRequest(); @@ -217,7 +219,7 @@ public class ProjectServiceImpl implements ProjectService { if (result <= 0) { TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); // 抛出异常触发事务回滚 - return AjaxResult.error("添加总监人员失败!"); + return AjaxResult.error("添加总监人员失败!"); } //向SysUser bean中添加监理人员id SysUser sysUser = new SysUser(); @@ -232,28 +234,29 @@ public class ProjectServiceImpl implements ProjectService { // 新增用户角色信息 insertUserRole(Long.valueOf(bean.getId()), roleIds); } else { - return AjaxResult.error("总监手机号已存在!"); + return AjaxResult.error("总监手机号已存在!"); } // 添加监理信息到监理单位表 result = projectMapper.addSupervisoryUnit(bean); if (result > 0) { // 抛出异常触发事务回滚 - return AjaxResult.success("添加成功"); + return AjaxResult.success("添加成功"); } TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); // 返回操作结果,可能是插入的记录数或者其他标识 } catch (Exception e) { // 手动进行回滚 TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); - log.error(e.toString(),e); + log.error(e.toString(), e); } - return AjaxResult.error("添加总监人员失败,请联系管理员!"); + return AjaxResult.error("添加总监人员失败,请联系管理员!"); } + @Override public AjaxResult addSupervisoryUnitUser(SupervisoryUnit bean) { - try{ - int nums=projectMapper.getSupervisoryUnitUser(bean); - if(nums>0){ + try { + int nums = projectMapper.getSupervisoryUnitUser(bean); + if (nums > 0) { return AjaxResult.error("监理单位名称已存在"); } // 新增监理信息到人员表 @@ -261,36 +264,38 @@ public class ProjectServiceImpl implements ProjectService { bean.setCreatePerson(SecurityUtils.getUsername()); bean.setCreatePersonId(String.valueOf(SecurityUtils.getUserId())); bean.setUuid(StringUtils.getUuid()); - int successNum=projectMapper.addSupervisoryUnitUser(bean); - if(successNum<1){ + int successNum = projectMapper.addSupervisoryUnitUser(bean); + if (successNum < 1) { return AjaxResult.error("监理单位添加失败,请联系管理员"); } - return AjaxResult.success("添加成功",bean); - }catch (Exception e){ - log.error(e.toString(),e); + return AjaxResult.success("添加成功", bean); + } catch (Exception e) { + log.error(e.toString(), e); } return AjaxResult.error("监理单位添加失败,请联系管理员"); } /** * 查询工程必填项 + * * @param entity * @return */ @Override public AjaxResult getProRequest(Project entity) { - try{ - List list=projectMapper.getProRequest(entity); - String data= String.join(",", list); - return AjaxResult.success(data); - }catch (Exception e){ - log.error(e.toString(),e); + try { + List list = projectMapper.getProRequest(entity); + String data = String.join(",", list); + return AjaxResult.success(data); + } catch (Exception e) { + log.error(e.toString(), e); } - return AjaxResult.error("查询参数异常"); + return AjaxResult.error("查询参数异常"); } /** * 新增承包商单位 + * * @param bean 监理单位实体 * @return 是否新增成功 */ @@ -528,6 +533,31 @@ public class ProjectServiceImpl implements ProjectService { throw new RuntimeException("Failed to add address project"); } } + //插入承包商-工程关联信息(先删后增---临时先放开 后期可能会删除) + projectMapper.delConsProject(project); + projectMapper.delMaterialProject(project); + projectMapper.delConsPersonToPcp(project); + projectMapper.delConsPersonToLk(project); + for (int i = 0; i < project.getConsArr().size(); i++) { + project.setConsId(projectMapper.getConsUuid(project.getConsArr().get(i).getValue())); + project.setRelateUuid(StringUtils.getUuid()); + result = projectMapper.addConsProject(project); + if (result <= 0) { + throw new RuntimeException("Failed to add cons project"); + } + for (int j = 0; j < project.getConsArr().get(i).getCheckList().size(); j++) { + //插入材料-工程关联信息 + project.setMaterialId(project.getConsArr().get(i).getCheckList().get(j)); + project.setRelateUuid(StringUtils.getUuid()); + project.setConsId(project.getConsArr().get(i).getValue()); + result = projectMapper.addMaterialProject(project); + if (result <= 0) { + throw new RuntimeException("Failed to add material project"); + } + } + // TODO 获取承包商信息 --- 新增承包商信息到承包商人员表 + addConsPerson(project); + } } catch (Exception e) { result = 0; TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); @@ -536,7 +566,6 @@ public class ProjectServiceImpl implements ProjectService { } - /** * 插入关联信息 * @@ -588,6 +617,7 @@ public class ProjectServiceImpl implements ProjectService { } return result; } + /** * 新增监理人员 * @@ -603,6 +633,7 @@ public class ProjectServiceImpl implements ProjectService { //插入关联表 projectMapper.addSupPersonToLk(subPerson); } + /** * 新增承包商人员 *