From 72f4d1963919611b11c3c976d615cb184dd59103 Mon Sep 17 00:00:00 2001 From: cxc2002 <2606714301@qq.com> Date: Fri, 17 Mar 2023 12:03:48 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/swustoj/common/ResponseDataEnum.java | 4 +- .../controller/AdministratorController.java | 9 - .../swustoj/controller/ImgFileController.java | 19 +- .../swustoj/service/AdministratorService.java | 2 - .../service/Impl/RecruitmentServiceImpl.java | 7 +- .../service/Impl/StudentServiceImpl.java | 4 +- .../java/com/swustoj/utils/FileUtils.java | 23 ++ src/main/resources/application-pro.yaml | 5 +- .../com/swustoj/mapper/RecruitmentMapper.xml | 2 +- .../templates/student_info_docx.html | 333 ------------------ 10 files changed, 54 insertions(+), 354 deletions(-) diff --git a/src/main/java/com/swustoj/common/ResponseDataEnum.java b/src/main/java/com/swustoj/common/ResponseDataEnum.java index 3f25553..ce9e7f6 100644 --- a/src/main/java/com/swustoj/common/ResponseDataEnum.java +++ b/src/main/java/com/swustoj/common/ResponseDataEnum.java @@ -22,7 +22,9 @@ public enum ResponseDataEnum { SIGNUP_FAIL_TIME_BEFORE(1011,"报名未开始!"), ACCESS_TOO_FAST(1012,"操作过于频繁,请稍后再试!"), USER_NOT_EXIST(1013,"该用户尚未填写个人信息!"), - REPEAT_ADD_ROLE(1014,"该用户对应角色已被添加!"); + REPEAT_ADD_ROLE(1014,"该用户对应角色已被添加!"), + INVALID_IMAGE_TYPE(1015, "请上传jpg、jpeg、png格式的图片!"), + FILE_SIZE_VALID(1016,"文件大小不能超过5M!"); private Integer code; diff --git a/src/main/java/com/swustoj/controller/AdministratorController.java b/src/main/java/com/swustoj/controller/AdministratorController.java index be3dc5f..93e4fa0 100644 --- a/src/main/java/com/swustoj/controller/AdministratorController.java +++ b/src/main/java/com/swustoj/controller/AdministratorController.java @@ -51,7 +51,6 @@ public class AdministratorController { @AccessVerify(roles = RoleEnum.ADMIN) public Response delRecruit( String enrollId) { Response response = new Response(); - System.out.println(enrollId); try { administratorService.delRecruit(enrollId); response.put("code", 200); @@ -68,7 +67,6 @@ public class AdministratorController { @AccessVerify(roles = RoleEnum.ADMIN) public Response getMsgInfo() { Response response = new Response(); - System.out.println("getMsgInfo"); try { this.msgArray.clear(); this.msgArray = administratorService.getMsgInfo(); @@ -88,19 +86,13 @@ public class AdministratorController { @AccessVerify(roles = {RoleEnum.ADMIN}) public Response pubMsg(HttpServletRequest request, @RequestBody pubMsgMsg Msg) { Response response = new Response(); - System.out.println("pubMsg"); String description = Msg.getDescription(); String pubDate = Msg.getPubDate(); - System.out.println(pubDate); - System.out.println(description); try { String accessToken = request.getHeader("Authorization").replace("Bearer ", ""); Claims claims = Utils.parse(accessToken); - System.out.println(accessToken); String userId = claims.get("userId").toString(); - System.out.println(userId); userId = administratorService.findById(userId); - System.out.println(userId); administratorService.pubMsg(userId,description,pubDate); response.put("code", 200); response.put("msg", "发布成功"); @@ -116,7 +108,6 @@ public class AdministratorController { @AccessVerify(roles = RoleEnum.ADMIN) public Response getRecruit(@PathVariable("state") String state,@PathVariable("page") Integer page) { Response response = new Response(); - System.out.println("getRecruit"); try { this.msgArray.clear(); this.msgArray = administratorService.getRecruit(page,state); diff --git a/src/main/java/com/swustoj/controller/ImgFileController.java b/src/main/java/com/swustoj/controller/ImgFileController.java index 2ea7c65..892d1e2 100644 --- a/src/main/java/com/swustoj/controller/ImgFileController.java +++ b/src/main/java/com/swustoj/controller/ImgFileController.java @@ -3,9 +3,12 @@ package com.swustoj.controller; import com.swustoj.VO.ImgVO; import com.swustoj.aop.RoleEnum; import com.swustoj.aop.annotation.AccessVerify; +import com.swustoj.common.ResponseDataEnum; import com.swustoj.common.ResultVO; +import com.swustoj.common.exception.CommonException; import com.swustoj.service.PrizeImagesService; import com.swustoj.service.StudentService; +import com.swustoj.utils.FileUtils; import com.swustoj.utils.Utils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +35,9 @@ import java.util.UUID; @RestController @Slf4j public class ImgFileController { + + private static String[] imageTypes = new String[]{".jpg",".png",".jpeg",".webp"}; + /** * 时间格式化 */ @@ -71,10 +77,12 @@ public class ImgFileController { } log.info("图片上传,保存位置:" + fileSavePath); + FileUtils.fileSizeValid(file); //3.给文件重新设置一个名字 //后缀 String uid = UUID.randomUUID().toString().replaceAll("-", ""); String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + validImageType(suffix); String newFileName= uid+suffix; //4.创建这个新文件 File newFile = new File(fileSavePath + newFileName); @@ -128,6 +136,15 @@ public class ImgFileController { log.info("图片不存在,终止操作 -> "+file.getName()); return ResultVO.fail(500,"图片不存在,终止操作"); } - }; + } + + private void validImageType(String suffix){ + for (String imageType : imageTypes) { + if (imageType.equalsIgnoreCase(suffix)){ + return; + } + } + throw new CommonException(ResponseDataEnum.INVALID_IMAGE_TYPE); + } } \ No newline at end of file diff --git a/src/main/java/com/swustoj/service/AdministratorService.java b/src/main/java/com/swustoj/service/AdministratorService.java index 5bb9e48..8013f04 100644 --- a/src/main/java/com/swustoj/service/AdministratorService.java +++ b/src/main/java/com/swustoj/service/AdministratorService.java @@ -44,7 +44,6 @@ public class AdministratorService { String name = findTeacherNameById((Integer) list.get(i).get("owner")); list.get(i).remove("owner"); list.get(i).put("owner",name); - System.out.println(list.get(i)); //temp.put("itemArray", list.get(i)); result.add(list.get(i)); } @@ -81,7 +80,6 @@ public class AdministratorService { public List> getRecruit(Integer page,String state) { this.list.clear(); this.list = administratorMapper.getRecruit(state); - System.out.println(this.list); this.getOnePage(page,state); return this.result; } diff --git a/src/main/java/com/swustoj/service/Impl/RecruitmentServiceImpl.java b/src/main/java/com/swustoj/service/Impl/RecruitmentServiceImpl.java index e794abc..a2f8e81 100644 --- a/src/main/java/com/swustoj/service/Impl/RecruitmentServiceImpl.java +++ b/src/main/java/com/swustoj/service/Impl/RecruitmentServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.extra.compress.CompressUtil; -import cn.hutool.extra.compress.archiver.Archiver; import com.alibaba.excel.util.ListUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; @@ -37,11 +36,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.File; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; /** * @description @@ -246,8 +243,12 @@ public class RecruitmentServiceImpl implements RecruitmentService { File studentZipFile = new File(studentZipURI); String fileURI = "studentInfoZips/" + enrollId + "/allStudentInfos.zip"; File file = new File(fileURI); + // 以及html文件 + String htmlFileURI = "htmls/" + studentNum + "--" + enrollId + ".html"; + File htmlFile = new File(htmlFileURI); FileUtil.del(studentZipFile); FileUtil.del(file); + FileUtil.del(htmlFile); } @Override diff --git a/src/main/java/com/swustoj/service/Impl/StudentServiceImpl.java b/src/main/java/com/swustoj/service/Impl/StudentServiceImpl.java index 0cdeb34..a9c8dd6 100644 --- a/src/main/java/com/swustoj/service/Impl/StudentServiceImpl.java +++ b/src/main/java/com/swustoj/service/Impl/StudentServiceImpl.java @@ -151,7 +151,7 @@ public class StudentServiceImpl implements StudentService { // 根据信息tag获取目标学生信息 StudentInfo studentInfo = studentInfoMapper.queryInfoById(studentId); log.info("学生信息为》》》》》》 {}",studentInfo); - Map infoTagData = new HashMap<>(14); + Map infoTagData = new HashMap<>(16); infoTags.forEach(template -> infoTagData.put(template.getStudentInfoField(),1)); // 获取学生获奖的信息 List prizeImages = prizeImagesService.queryList(studentId); @@ -182,7 +182,7 @@ public class StudentServiceImpl implements StudentService { if (!studentFileDir.exists()){ studentFileDir.mkdir(); } - File studentInfoDocx = new File(studentFilePath + studentInfo.getStudentNum() + "--" + recruitmentId + ".docx"); + File studentInfoDocx = new File(studentFilePath + studentInfo.getStudentNum() + "--" + recruitmentId + ".doc"); log.info("studentInfoDocx is >>>>>>>> {}",studentInfoDocx); File studentInfoHtml = new File("htmls/" + studentInfo.getStudentNum() + "--" + recruitmentId + ".html"); log.info("studentInfoDocx path is >>>>> {}",studentInfoDocx.getAbsolutePath()); diff --git a/src/main/java/com/swustoj/utils/FileUtils.java b/src/main/java/com/swustoj/utils/FileUtils.java index f59ac89..58b9ead 100644 --- a/src/main/java/com/swustoj/utils/FileUtils.java +++ b/src/main/java/com/swustoj/utils/FileUtils.java @@ -1,13 +1,17 @@ package com.swustoj.utils; +import com.swustoj.common.ResponseDataEnum; +import com.swustoj.common.exception.CommonException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; /** * @description @@ -53,5 +57,24 @@ public class FileUtils { } } + public static void fileSizeValid(MultipartFile file){ + fileSize(file,5); + } + + /** + * 文件大小校验 + * @param file 文件流 + * @param fileSize 规定文件大小 + */ + public static void fileSize(MultipartFile file,int fileSize){ + long length = file.getSize(); + double size = (double) length / 1024 / 1024; + if (size > fileSize){ + throw new CommonException(ResponseDataEnum.FILE_SIZE_VALID); + } + } + + + } diff --git a/src/main/resources/application-pro.yaml b/src/main/resources/application-pro.yaml index 4187baa..b23d0aa 100644 --- a/src/main/resources/application-pro.yaml +++ b/src/main/resources/application-pro.yaml @@ -1,6 +1,7 @@ server: port: 9011 - + tomcat: + max-http-form-post-size: 8192 spring: cache: type: redis @@ -59,4 +60,4 @@ swagger: #上传文件目录 file-save-path: images/ -static-path: http://202.115.161.211:9091/enroll_static/ +static-path: https://acm.swust.edu.cn/enroll_static/ diff --git a/src/main/resources/com/swustoj/mapper/RecruitmentMapper.xml b/src/main/resources/com/swustoj/mapper/RecruitmentMapper.xml index d5c864f..096132e 100644 --- a/src/main/resources/com/swustoj/mapper/RecruitmentMapper.xml +++ b/src/main/resources/com/swustoj/mapper/RecruitmentMapper.xml @@ -132,7 +132,7 @@ AND status = 1 and deadline <= CURRENT_TIMESTAMP() - + AND status = #{state} diff --git a/src/main/resources/templates/student_info_docx.html b/src/main/resources/templates/student_info_docx.html index 13778c9..fda00a1 100644 --- a/src/main/resources/templates/student_info_docx.html +++ b/src/main/resources/templates/student_info_docx.html @@ -1,336 +1,3 @@ - - - - - -- Gitee