From 78626d4b0f68a2bf25586d8ee570c587e889b906 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 06 五月 2026 17:20:50 +0800
Subject: [PATCH] feat(sales): 添加发货信息详情查询功能
---
src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java | 130 ++++++------------------------------------
1 files changed, 20 insertions(+), 110 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
index 464810e..eb36693 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
@@ -1,31 +1,17 @@
package com.ruoyi.sales.service.impl;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.other.mapper.TempFileMapper;
-import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.sales.mapper.CommonFileMapper;
import com.ruoyi.sales.pojo.CommonFile;
import com.ruoyi.sales.service.ICommonFileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FilenameUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.multipart.MultipartFile;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
@Service
@RequiredArgsConstructor
@@ -36,111 +22,35 @@
private final TempFileMapper tempFileMapper;
- @Value("${file.upload-dir}")
- private String uploadDir;
+ public List<CommonFile> getFileListByBusinessId(Long businessId,Integer type) {
+ return commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, businessId)
+ .eq(CommonFile::getType, type));
+ }
+
+ public void deleteByBusinessId(Long businessId,Integer type) {
+ commonFileMapper.delete(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, businessId)
+ .eq(CommonFile::getType, type));
+ }
+
+ public void deleteByBusinessIds(List<Long> businessId,Integer type) {
+ commonFileMapper.delete(new LambdaQueryWrapper<CommonFile>().in(CommonFile::getCommonId, businessId)
+ .eq(CommonFile::getType, type));
+ }
@Override
public int deleteSalesLedgerByIds(Long[] ids) {
+ for (Long id : ids) {
+ if (id == null) {
+ return 1;
+ }
+ }
return commonFileMapper.deleteBatchIds(Arrays.asList(ids));
}
- @Override
- public CommonFile uploadFile(MultipartFile file, Long id, String type) throws IOException {
- // 1. 鐢熸垚姝e紡鏂囦欢ID鍜岃矾寰�
- String tempId = UUID.randomUUID().toString();
- Path tempFilePath = Paths.get(uploadDir, tempId + "_" + file.getOriginalFilename());
-
- // 2. 纭繚鐩綍瀛樺湪
- Path parentDir = tempFilePath.getParent();
- if (parentDir != null) {
- Files.createDirectories(parentDir); // 閫掑綊鍒涘缓鐩綍
- }
-
- // 3. 淇濆瓨鏂囦欢鍒扮洰褰�
- file.transferTo(tempFilePath.toFile());
-
- // 4. 淇濆瓨鏂囦欢璁板綍
- CommonFile commonFile = new CommonFile();
- commonFile.setCommonId(id);
- commonFile.setName(file.getOriginalFilename());
- commonFile.setUrl(tempFilePath.toString());
- commonFile.setType(type);
- commonFileMapper.insert(commonFile);
- return commonFile;
- }
@Override
public int delCommonFileByIds(Long[] ids) {
return commonFileMapper.deleteBatchIds(Arrays.asList(ids));
- }
-
- /**
- * 灏嗕复鏃舵枃浠惰縼绉诲埌姝e紡鐩綍
- *
- * @param businessId 涓氬姟ID锛堥攢鍞彴璐D锛�
- * @param tempFileIds 涓存椂鏂囦欢ID鍒楄〃
- * @throws IOException 鏂囦欢鎿嶄綔寮傚父
- */
- @Transactional(rollbackFor = Exception.class)
- public void migrateTempFilesToFormal(Long businessId, List<String> tempFileIds) throws IOException {
- if (CollectionUtils.isEmpty(tempFileIds)) {
- return;
- }
-
- // 鏋勫缓姝e紡鐩綍璺緞锛堟寜涓氬姟绫诲瀷鍜屾棩鏈熷垎缁勶級
- String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
-
- Path formalDirPath = Paths.get(formalDir);
-
- // 纭繚姝e紡鐩綍瀛樺湪锛堥�掑綊鍒涘缓锛�
- if (!Files.exists(formalDirPath)) {
- Files.createDirectories(formalDirPath);
- }
-
- for (String tempFileId : tempFileIds) {
- // 鏌ヨ涓存椂鏂囦欢璁板綍
- TempFile tempFile = tempFileMapper.selectById(tempFileId);
- if (tempFile == null) {
- log.warn("涓存椂鏂囦欢涓嶅瓨鍦紝璺宠繃澶勭悊: {}", tempFileId);
- continue;
- }
-
- // 鏋勫缓姝e紡鏂囦欢鍚嶏紙鍖呭惈涓氬姟ID鍜屾椂闂存埑锛岄伩鍏嶅啿绐侊級
- String originalFilename = tempFile.getOriginalName();
- String fileExtension = FilenameUtils.getExtension(originalFilename);
- String formalFilename = businessId + "_" +
- System.currentTimeMillis() + "_" +
- UUID.randomUUID().toString().substring(0, 8) +
- (com.ruoyi.common.utils.StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
-
- Path formalFilePath = formalDirPath.resolve(formalFilename);
-
- try {
- // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
- Files.move(
- Paths.get(tempFile.getTempPath()),
- formalFilePath,
- StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
- );
- log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
-
- // 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
- CommonFile fileRecord = new CommonFile();
- fileRecord.setCommonId(businessId);
- fileRecord.setName(originalFilename);
- fileRecord.setUrl(formalFilePath.toString());
- fileRecord.setCreateTime(LocalDateTime.now());
- fileRecord.setType(tempFile.getType());
- commonFileMapper.insert(fileRecord);
-
- log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
- } catch (IOException e) {
- log.error("鏂囦欢杩佺Щ澶辫触: {}", tempFile.getTempPath(), e);
- // 鍙�夋嫨鍥炴粴浜嬪姟鎴栬褰曞け璐ユ枃浠�
- throw new IOException("鏂囦欢杩佺Щ寮傚父", e);
- }
- }
}
}
--
Gitblit v1.9.3