From f5ef1f0adaab886c66d14bda8576243831c9d99d Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Fri, 23 Apr 2021 10:25:45 +0800 Subject: [PATCH] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](master):=20=E6=8F=90?= =?UTF-8?q?=E4=BA=A4Bug=E4=BF=AE=E5=A4=8D=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 请按fixme修复 --- .../rest/TbUploadFileNewController.java | 37 +++++++++++-------- .../impl/TbUploadFileNewServiceImpl.java | 18 ++++----- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java index a3dc458..ea67aa9 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java @@ -16,44 +16,42 @@ package me.zhengjie.modules.uploadnew.rest; import cn.hutool.core.collection.CollectionUtil; -import io.swagger.models.auth.In; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.AnonymousAccess; import me.zhengjie.annotation.Log; import me.zhengjie.common.http.CommonResponse; import me.zhengjie.common.http.ResponseCode; -import me.zhengjie.modules.security.security.TokenFilter; -import me.zhengjie.modules.upload.service.dto.UploadFileDto; -import me.zhengjie.modules.upload.service.dto.UploadFileQueryCriteria; import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewQueryCriteria; import me.zhengjie.modules.uploadnew.task.SaveToFileNewTask; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; -import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -//import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import io.swagger.annotations.*; import org.springframework.web.multipart.MultipartFile; -import org.apache.commons.lang3.StringUtils; -import java.io.IOException; -import java.util.List; -import java.util.Objects; import javax.servlet.ServletRequest; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Objects; import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT; +//import org.springframework.util.StringUtils; + /** * @website https://el-admin.vip * @author weizhongxi @@ -126,10 +124,15 @@ public class TbUploadFileNewController { @AnonymousAccess @PostMapping("/fileUpload") // @ResponseBody - public ResponseEntity fileUpload(@RequestParam("file") MultipartFile file, @RequestParam(value = "taskName") String taskName, @RequestParam(value = "isEcryptionNew") String isEcryptionNew, ServletRequest servletRequest) { + public ResponseEntity fileUpload(@RequestParam("file") MultipartFile file, + @RequestParam(value = "taskName") String taskName, + @RequestParam(value = "isEcryptionNew") String isEcryptionNew, + ServletRequest servletRequest) { // 记录日志 log.info("TbUploadFileNewController:fileUpload | taskName="+taskName+"===== isEcryptionNew="+isEcryptionNew); + // FIXME: 2021/4/23 0023 Integer isEcryption = Integer.parseInt(isEcryptionNew); + // FIXME: 2021/4/23 0023 String name=file.getOriginalFilename(); String keyName = ""; @@ -140,22 +143,24 @@ public class TbUploadFileNewController { //获取cookie的名字 String cookieName = cookie.getName(); token=cookie.getValue(); - System.out.println(cookieName); - System.out.println(cookieName+" : "+ cookie.getValue() ); + // FIXME: 2021/4/23 0023 +// System.out.println(cookieName); +// System.out.println(cookieName+" : "+ cookie.getValue() ); } + // FIXME: 2021/4/23 0023 === keyName = token+"==="+name; Object keyValue = redisTemplate.opsForValue().get(keyName); //防止用户多次提交 if (keyValue != null){ return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_STAETING), HttpStatus.OK); } - redisTemplate.opsForValue().set(keyName, "value11"); + redisTemplate.opsForValue().set(keyName, "value11"); int lastIndexOf = name.lastIndexOf("."); - String nameStr = name.substring(lastIndexOf); // 校验文件格式 + String nameStr = name.substring(lastIndexOf); if (!((nameStr.equals(".xlsx")||nameStr.equals(".xls")) || nameStr.equals(".txt") ||nameStr.equals(".csv"))){ return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_FORMAT), HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java index 275f434..88fbd65 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java @@ -19,35 +19,34 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.system.OsInfo; import cn.hutool.system.SystemUtil; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.modules.upload.consts.SysConst; import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; -import me.zhengjie.modules.uploadnew.util.ExcelUtils; -import me.zhengjie.modules.uploadnew.util.TxtUtils; -import me.zhengjie.utils.*; -import lombok.RequiredArgsConstructor; import me.zhengjie.modules.uploadnew.repository.TbUploadFileNewRepository; import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewQueryCriteria; import me.zhengjie.modules.uploadnew.service.mapstruct.TbUploadFileNewMapper; +import me.zhengjie.modules.uploadnew.util.TxtUtils; +import me.zhengjie.utils.*; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.io.IOException; import java.nio.file.Paths; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; import static me.zhengjie.modules.uploadnew.consts.SysConstNew.TEST_USER_NAME; -import static me.zhengjie.modules.uploadnew .consts.UploadFileNewConst.*; +import static me.zhengjie.modules.uploadnew.consts.UploadFileNewConst.*; /** * @website https://el-admin.vip @@ -174,6 +173,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService { List list = null; //根据文件类型进行解析 try { + // FIXME: 2021/4/23 0023 if(nameStr.equals(".xlsx")||nameStr.equals(".xls")){ fileFormat = "excel文件"; list = FileUtil.readLines(eachFilePath, "UTF-8");