From 38f2af69069f0ac5d7f3532e446caa159adabc41 Mon Sep 17 00:00:00 2001 From: wangxy <1356089412@qq.com> Date: Mon, 15 Apr 2024 10:02:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=9A=E6=9D=90=E6=96=99=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/ApplyInfoListManager.java | 4 - .../manager/FileRelationManager.java | 82 ++++++++++++++++++- .../controller/manager/ScoreInfoManager.java | 1 - .../controller/manager/SysNoticeManager.java | 4 - .../reward/FileRelationController.java | 24 +++++- 5 files changed, 101 insertions(+), 14 deletions(-) diff --git a/hyp-admin/src/main/java/com/hyp/web/controller/manager/ApplyInfoListManager.java b/hyp-admin/src/main/java/com/hyp/web/controller/manager/ApplyInfoListManager.java index fa5f963..ec9ad84 100644 --- a/hyp-admin/src/main/java/com/hyp/web/controller/manager/ApplyInfoListManager.java +++ b/hyp-admin/src/main/java/com/hyp/web/controller/manager/ApplyInfoListManager.java @@ -120,7 +120,6 @@ public class ApplyInfoListManager { * @param applyId * @return boolean */ - public boolean deleteById(String applyId){ relationService.lambdaUpdate() .eq(RewFileRelation::getApplyId, applyId) @@ -135,7 +134,6 @@ public class ApplyInfoListManager { * @param applyId * @return com.hyp.system.domain.vo.ApplyInfoListVO */ - public ApplyInfoListVO detail(String applyId){ RewApplyInfoList applyInfoList = applyInfoListService.getById(applyId); ApplyInfoListVO applyInfoListVO = Convert.convert(ApplyInfoListVO.class, applyInfoList); @@ -154,7 +152,6 @@ public class ApplyInfoListManager { * @param applyId * @return boolean */ - public boolean audit(String applyId){ return applyInfoListService.lambdaUpdate() .eq(RewApplyInfoList::getApplyId, applyId) @@ -169,7 +166,6 @@ public class ApplyInfoListManager { * @param applyMsg * @return boolean */ - public boolean applyBack(String applyId,String applyMsg){ return applyInfoListService.lambdaUpdate() .eq(RewApplyInfoList::getApplyId, applyId) diff --git a/hyp-admin/src/main/java/com/hyp/web/controller/manager/FileRelationManager.java b/hyp-admin/src/main/java/com/hyp/web/controller/manager/FileRelationManager.java index a46b799..45a7a08 100644 --- a/hyp-admin/src/main/java/com/hyp/web/controller/manager/FileRelationManager.java +++ b/hyp-admin/src/main/java/com/hyp/web/controller/manager/FileRelationManager.java @@ -2,14 +2,25 @@ package com.hyp.web.controller.manager; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hyp.common.config.HypConfig; import com.hyp.common.core.domain.AjaxResult; import com.hyp.common.exception.ServiceException; +import com.hyp.common.utils.file.FileUploadUtils; +import com.hyp.common.utils.file.FileUtils; +import com.hyp.framework.config.ServerConfig; import com.hyp.system.domain.RewFileRelation; +import com.hyp.system.domain.RewScoreInfo; import com.hyp.system.service.RewFileRelationService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -28,6 +39,10 @@ public class FileRelationManager { @Resource private RewFileRelationService fileRelationService; + + @Autowired + private ServerConfig serverConfig; + /** * * 删除文件 @@ -66,7 +81,6 @@ public class FileRelationManager { * @param applyId * @return com.hyp.common.core.domain.AjaxResult */ - public AjaxResult checkFile(String applyId){ List list = fileRelationService.lambdaQuery() .eq(RewFileRelation::getApplyId, applyId) @@ -81,6 +95,16 @@ public class FileRelationManager { return AjaxResult.success(); } + /** + * + * 单个保存 + * @param applyId + * @param filename + * @param fileCode + * @param url + * @param originalFilename + * @return com.hyp.system.domain.RewFileRelation + */ @Transactional(rollbackFor = Exception.class) public RewFileRelation save(String applyId,String filename,String fileCode,String url,String originalFilename){ RewFileRelation rewFileRelation = new RewFileRelation(); @@ -93,13 +117,52 @@ public class FileRelationManager { return rewFileRelation; } + + + /** + * + * 批量保存文件 + * @param files + * @param applyId + * @param filename + * @param fileCode + * @return java.util.List + */ + @Transactional(rollbackFor = Exception.class) + public List saveBatch(List files, + String applyId, + String filename, + String fileCode) throws IOException { + List fileRelations = new ArrayList<>(); + // 上传文件路径 + String filePath = HypConfig.getUploadPath(); + for (MultipartFile file : files) { + if (!file.isEmpty()) { + // 上传并返回新文件名称 + String fileNames = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileNames; + if(StringUtils.isBlank(filename)){ + filename = fileNames; + } + RewFileRelation rewFileRelation = new RewFileRelation(); + rewFileRelation.setApplyId(applyId); + rewFileRelation.setFileName(filename); + rewFileRelation.setFileCode(fileCode); + rewFileRelation.setFilePath(url); + rewFileRelation.setRealName(FileUtils.getNameNotSuffix(file.getOriginalFilename())); + fileRelations.add(rewFileRelation); + } + } + fileRelationService.saveBatch(fileRelations); + return fileRelations; + } + /** * * 获取文件路劲 * @param fileId * @return java.lang.String */ - public String getFilePath(String fileId){ RewFileRelation fileRelation = fileRelationService.getById(fileId); if(Objects.nonNull(fileRelation)){ @@ -114,7 +177,6 @@ public class FileRelationManager { * @param fileId * @return java.lang.String */ - public String getRealName(String fileId){ RewFileRelation fileRelation = fileRelationService.getById(fileId); if(Objects.nonNull(fileRelation)){ @@ -123,6 +185,20 @@ public class FileRelationManager { return null; } + /** + * + * 文件列表啥 + * @param applyId + * @param fileCode + * @return java.util.List + */ + public List getFileInfo(String applyId,String fileCode){ + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(RewFileRelation::getApplyId,applyId); + queryWrapper.eq(Objects.nonNull(fileCode), RewFileRelation::getFileCode, fileCode); + return fileRelationService.list(queryWrapper); + } + diff --git a/hyp-admin/src/main/java/com/hyp/web/controller/manager/ScoreInfoManager.java b/hyp-admin/src/main/java/com/hyp/web/controller/manager/ScoreInfoManager.java index 3cf8d8e..150481c 100644 --- a/hyp-admin/src/main/java/com/hyp/web/controller/manager/ScoreInfoManager.java +++ b/hyp-admin/src/main/java/com/hyp/web/controller/manager/ScoreInfoManager.java @@ -61,7 +61,6 @@ public class ScoreInfoManager { * @param createId * @return java.util.List */ - public List getScoreInfo(String applyId,Long createId){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(RewScoreInfo::getApplyId,applyId); diff --git a/hyp-admin/src/main/java/com/hyp/web/controller/manager/SysNoticeManager.java b/hyp-admin/src/main/java/com/hyp/web/controller/manager/SysNoticeManager.java index 0a2ad18..481deb4 100644 --- a/hyp-admin/src/main/java/com/hyp/web/controller/manager/SysNoticeManager.java +++ b/hyp-admin/src/main/java/com/hyp/web/controller/manager/SysNoticeManager.java @@ -32,7 +32,6 @@ public class SysNoticeManager { * @param notice * @return java.util.List */ - public List selectNoticeList(SysNotice notice){ return noticeService.selectNoticeList(notice); } @@ -43,7 +42,6 @@ public class SysNoticeManager { * @param notice * @return boolean */ - public boolean saveOrUpdate(SysNotice notice){ if(StringUtils.isNotEmpty(notice.getNoticeId())){ notice.setUpdateTime(new Date()); @@ -59,7 +57,6 @@ public class SysNoticeManager { * @param noticeId * @return com.hyp.system.domain.SysNotice */ - public SysNotice selectNoticeById(String noticeId){ return noticeService.getById(noticeId); } @@ -70,7 +67,6 @@ public class SysNoticeManager { * @param ids * @return boolean */ - public boolean removeByIds(String ids){ return noticeService.removeByIds(Arrays.asList(Convert.toStrArray(ids))); } diff --git a/hyp-admin/src/main/java/com/hyp/web/controller/reward/FileRelationController.java b/hyp-admin/src/main/java/com/hyp/web/controller/reward/FileRelationController.java index 4ff144b..553bbb5 100644 --- a/hyp-admin/src/main/java/com/hyp/web/controller/reward/FileRelationController.java +++ b/hyp-admin/src/main/java/com/hyp/web/controller/reward/FileRelationController.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; +import java.util.List; /** @@ -70,6 +71,21 @@ public class FileRelationController extends BaseController { } } + /** + * 通用上传请求(多个) + */ + @PostMapping("/uploads") + public AjaxResult uploadFiles(List files, + @RequestParam String applyId, + @RequestParam(required = false) String filename, + @RequestParam String fileCode){ + try { + return AjaxResult.success(fileRelationManager.saveBatch(files,applyId,filename,fileCode)); + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + } + @ApiOperation("材料预览") @GetMapping("fileView/{fileId}") public void fileView(@PathVariable String fileId, HttpServletResponse response) throws IOException { @@ -130,8 +146,12 @@ public class FileRelationController extends BaseController { return fileRelationManager.checkFile(applyId); } - - + @ApiOperation("文件查询") + @GetMapping("/getFileInfo") + public AjaxResult getFileInfo(@RequestParam String applyId, + @RequestParam(required = false) String fileCode) { + return success(fileRelationManager.getFileInfo(applyId,fileCode)); + } }