From 9a2271957bdee8f4bfdbb3216fa1567a868f0dba Mon Sep 17 00:00:00 2001 From: "JiaXing_Cheng@163.com" Date: Tue, 19 Oct 2021 15:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/IStandardInfoService.java | 2 +- .../service/impl/StandardInfoServiceImpl.java | 47 ++++++++++++++++--- .../StandardInfoController.java | 2 +- .../com/ruoyi/common/constant/Constants.java | 7 ++- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/productManager/src/main/java/com/ruoyi/productionManager/service/IStandardInfoService.java b/productManager/src/main/java/com/ruoyi/productionManager/service/IStandardInfoService.java index 9a71e1f2d..4e5a137d7 100644 --- a/productManager/src/main/java/com/ruoyi/productionManager/service/IStandardInfoService.java +++ b/productManager/src/main/java/com/ruoyi/productionManager/service/IStandardInfoService.java @@ -43,7 +43,7 @@ public interface IStandardInfoService * @param standardInfo 试验标准管理 * @return 结果 */ - public int updateStandardInfo(StandardInfo standardInfo); + public int updateStandardInfo(StandardManagerVO standardManagerVO); /** * 批量删除试验标准管理 diff --git a/productManager/src/main/java/com/ruoyi/productionManager/service/impl/StandardInfoServiceImpl.java b/productManager/src/main/java/com/ruoyi/productionManager/service/impl/StandardInfoServiceImpl.java index 52009b0f7..93b0e98c9 100644 --- a/productManager/src/main/java/com/ruoyi/productionManager/service/impl/StandardInfoServiceImpl.java +++ b/productManager/src/main/java/com/ruoyi/productionManager/service/impl/StandardInfoServiceImpl.java @@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; import com.ruoyi.productionManager.mapper.StandardInfoMapper; import com.ruoyi.productionManager.domain.StandardInfo; import com.ruoyi.productionManager.service.IStandardInfoService; +import org.springframework.util.Assert; import org.springframework.web.multipart.MultipartFile; import org.apache.http.entity.ContentType; @@ -84,19 +85,19 @@ public class StandardInfoServiceImpl implements IStandardInfoService String name = ""; String fileName = ""; StringBuffer sb = new StringBuffer(); + Assert.notNull(standardManagerVO.getPath(),"文件未上传!"); // String s:standardManagerVO.getPath().split("/",9) String[] str = standardManagerVO.getPath().split("/",6); for(int i=0;i>>"+str[i]); if(i>=2){ sb.append("/"); sb.append(str[i]); } name = str[i]; } - System.out.println("sb>>>"+sb.toString()); try{ byte[] bytes = redisCache.getCacheObject(Constants.UPLOAD_FILE+name); + String s = redisCache.getCacheObject(Constants.UPLOAD_FILE_NAME+name); InputStream inputStream = new ByteArrayInputStream(bytes); // String fileType = FileTypeUtils.getType(bytes); MultipartFile files = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); @@ -108,11 +109,14 @@ public class StandardInfoServiceImpl implements IStandardInfoService standardInfoMapper.insertStandardInfo(standardManagerVO); StandardInfoDetails standardInfoDetails = new StandardInfoDetails(); standardInfoDetails.setFileUrl(filePath+fileName); - standardInfoDetails.setFileName(name); + standardInfoDetails.setFileName(s); standardInfoDetails.setStandardId(standardManagerVO.getStandardId()); standardInfoDetails.setCreateBy(SecurityUtils.getLoginUser().getUsername()); redisCache.deleteObject(Constants.UPLOAD_FILE+name); + redisCache.deleteObject(Constants.UPLOAD_FILE_NAME+name); return standardInfoDetailsService.insertStandardInfoDetails(standardInfoDetails); + }catch (NullPointerException e){ + throw new ServiceException("新增失败:文件已过期重新上传!"); }catch (Exception e){ throw new ServiceException("新增失败:" + e.getMessage()); } @@ -125,10 +129,40 @@ public class StandardInfoServiceImpl implements IStandardInfoService * @return 结果 */ @Override - public int updateStandardInfo(StandardInfo standardInfo) + public int updateStandardInfo(StandardManagerVO standardManagerVO) { - standardInfo.setUpdateTime(DateUtils.getNowDate()); - return standardInfoMapper.updateStandardInfo(standardInfo); + String filePath = RuoYiConfig.getUploadPath(); + // 取出缓存数据 + String name = ""; + String fileName = ""; + StringBuffer sb = new StringBuffer(); + Assert.notNull(standardManagerVO.getPath(),"文件未上传!"); +// String s:standardManagerVO.getPath().split("/",9) + String[] str = standardManagerVO.getPath().split("/",6); + for(int i=0;i=2){ + sb.append("/"); + sb.append(str[i]); + } + name = str[i]; + } + try { + byte[] bytes = redisCache.getCacheObject(Constants.UPLOAD_FILE+name); + InputStream inputStream = new ByteArrayInputStream(bytes); +// String fileType = FileTypeUtils.getType(bytes); + MultipartFile files = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); + fileName = sb.toString(); + File desc = FileUploadUtils.getAbsoluteFile(filePath, fileName); + files.transferTo(desc); + + standardManagerVO.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); + standardManagerVO.setUpdateTime(DateUtils.getNowDate()); + return standardInfoMapper.updateStandardInfo(standardManagerVO); + }catch (NullPointerException e){ + throw new ServiceException("修改失败:文件已过期重新上传!"); + }catch (Exception e){ + throw new ServiceException("修改失败:" + e.getMessage()); + } } /** @@ -172,6 +206,7 @@ public class StandardInfoServiceImpl implements IStandardInfoService redisCache.setCacheObject(Constants.UPLOAD_FILE+name, data, 30, TimeUnit.MINUTES); + redisCache.setCacheObject(Constants.UPLOAD_FILE_NAME+name,file.getOriginalFilename(),30,TimeUnit.MINUTES); // byte[] bytes = redisCache.getCacheObject(Constants.UPLOAD_FILE+name); // InputStream inputStream = new ByteArrayInputStream(bytes); // String fileType = FileTypeUtils.getType(bytes); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/productionManager/StandardInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/productionManager/StandardInfoController.java index 89136e21b..b55be367a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/productionManager/StandardInfoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/productionManager/StandardInfoController.java @@ -96,7 +96,7 @@ public class StandardInfoController extends BaseController @PreAuthorize("@ss.hasPermi('productionManager:standard:edit')") @Log(title = "试验标准管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody StandardInfo standardInfo) + public AjaxResult edit(@RequestBody StandardManagerVO standardInfo) { return toAjax(standardInfoService.updateStandardInfo(standardInfo)); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 0d526f84b..2f65cc95b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -150,7 +150,12 @@ public class Constants public static final String LOOKUP_LDAP = "ldap://"; /** - * LDAP 远程方法调用 + * 文件上传 */ public static final String UPLOAD_FILE = "file:"; + + /** + * 文件上传 + */ + public static final String UPLOAD_FILE_NAME = "filename:"; }