From a3c54410de03f0fd242e1a1118d6471300cf1eda Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 30 四月 2026 17:36:25 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_pro' into dev_New_pro
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 137 +++++++++------------------------------------
1 files changed, 27 insertions(+), 110 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
index 700836d..c4a48cd 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -6,15 +6,18 @@
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.approve.bean.vo.ApproveProcessVO;
import com.ruoyi.approve.pojo.ApproveProcess;
import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
-import com.ruoyi.approve.bean.vo.ApproveProcessVO;
+import com.ruoyi.basic.enums.ApplicationTypeEnum;
+import com.ruoyi.basic.enums.RecordTypeEnum;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.mapper.SupplierManageMapper;
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.pojo.SupplierManage;
+import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
@@ -23,7 +26,6 @@
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.other.mapper.TempFileMapper;
-import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage;
import com.ruoyi.project.system.domain.SysUser;
@@ -59,22 +61,15 @@
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
-import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
-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.ZoneId;
@@ -116,9 +111,7 @@
private final QualityInspectParamMapper qualityInspectParamMapper;
private final ApproveProcessServiceImpl approveProcessService;
private final ProcurementRecordMapper procurementRecordStorageMapper;
-
- @Value("${file.upload-dir}")
- private String uploadDir;
+ private final FileUtil fileUtil;
@Override
public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) {
@@ -181,7 +174,7 @@
}
purchaseLedgerMapper.updateById(purchaseLedger);
}
- // 6.閲囪喘瀹℃牳鏂板
+ // 6.閲囪喘瀹℃牳鏂板锛涘鎵圭鐞嗘湭閰嶇疆閲囪喘瀹℃壒浜烘椂锛屽鎵规湇鍔′細鑷姩缃负瀹℃壒閫氳繃銆�
addApproveByPurchase(loginUser, purchaseLedger);
// 4. 澶勭悊瀛愯〃鏁版嵁
@@ -199,9 +192,7 @@
// }
// }
// 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰�
- if (purchaseLedgerDto.getTempFileIds() != null && !purchaseLedgerDto.getTempFileIds().isEmpty()) {
- migrateTempFilesToFormal(purchaseLedger.getId(), purchaseLedgerDto.getTempFileIds());
- }
+ fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId(), purchaseLedgerDto.getStorageBlobDTOS());
return 1;
}
@@ -238,6 +229,7 @@
if (products == null || products.isEmpty()) {
throw new BaseException("浜у搧淇℃伅涓嶅瓨鍦�");
}
+ Integer ledgerType = type == null ? 2 : type;
// 鎻愬墠鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑ID
Set<Long> productIds = products.stream()
@@ -289,14 +281,14 @@
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
for (SalesLedgerProduct product : updateList) {
- product.setType(type);
+ product.setType(ledgerType);
salesLedgerProductMapper.updateById(product);
}
}
// 鎵ц鎻掑叆鎿嶄綔
if (!insertList.isEmpty()) {
for (SalesLedgerProduct salesLedgerProduct : insertList) {
- salesLedgerProduct.setType(type);
+ salesLedgerProduct.setType(ledgerType);
Date entryDate = purchaseLedger.getEntryDate();
LocalDateTime localDateTime = entryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
@@ -318,80 +310,6 @@
if (salesLedgerId != null) {
// 鐩存帴鏇存柊鎸囧畾ID鐨勮褰曠殑contractAmount瀛楁涓簍otalTaxInclusiveAmount
purchaseLedgerMapper.updateContractAmountById(salesLedgerId, totalTaxInclusiveAmount);
- }
- }
-
- /**
- * 灏嗕复鏃舵枃浠惰縼绉诲埌姝e紡鐩綍
- *
- * @param businessId 涓氬姟ID锛堥攢鍞彴璐D锛�
- * @param tempFileIds 涓存椂鏂囦欢ID鍒楄〃
- * @throws IOException 鏂囦欢鎿嶄綔寮傚父
- */
- private 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) +
- (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
-
- Path formalFilePath = formalDirPath.resolve(formalFilename);
-
- try {
- // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
-// Files.move(
-// Paths.get(tempFile.getTempPath()),
-// formalFilePath,
-// StandardCopyOption.REPLACE_EXISTING,
-// StandardCopyOption.ATOMIC_MOVE
-// );
- // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
- Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
- Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
- 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(FileNameType.PURCHASE.getValue());
- commonFileMapper.insert(fileRecord);
-
- // 鍒犻櫎涓存椂鏂囦欢璁板綍
- tempFileMapper.deleteById(tempFile);
-
- log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
- } catch (IOException e) {
- log.error("鏂囦欢杩佺Щ澶辫触: {}", tempFile.getTempPath(), e);
- // 鍙�夋嫨鍥炴粴浜嬪姟鎴栬褰曞け璐ユ枃浠�
- throw new IOException("鏂囦欢杩佺Щ寮傚父", e);
- }
}
}
@@ -492,11 +410,6 @@
.eq(SalesLedgerProduct::getType, purchaseLedgerDto.getType());
List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
- // 3.鏌ヨ涓婁紶鏂囦欢
- LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
- salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId())
- .eq(CommonFile::getType,FileNameType.PURCHASE.getValue());
- List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
// 4. 杞崲 DTO
PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
@@ -504,7 +417,7 @@
if (!products.isEmpty()) {
resultDto.setHasChildren(true);
resultDto.setProductData(products);
- resultDto.setSalesLedgerFiles(salesLedgerFiles);
+ resultDto.setStorageBlobVOS(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId()));
}
return resultDto;
}
@@ -689,20 +602,21 @@
if(salesLedger1 != null){
salesLedger.setSalesLedgerId(salesLedger1.getId());
}
- // 閲囪喘瀹℃牳
- // 閫氳繃鏄电О鑾峰彇鐢ㄦ埛ID
- String[] split = salesLedger.getApproveUserIds().split("锛�");
- List<Long> ids = new ArrayList<>();
- for (int i = 0; i < split.length; i++) {
- SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getNickName, split[i])
- .last("LIMIT 1"));
- if (sysUser != null) {
- ids.add(sysUser.getUserId());
+ if (StringUtils.hasText(salesLedger.getApproveUserIds())) {
+ // 閲囪喘瀹℃牳锛氬巻鍙插鍏ユā鏉夸紶瀹℃壒浜哄鍚嶆椂锛岀户缁吋瀹硅浆鎹负鐢ㄦ埛ID銆�
+ String[] split = salesLedger.getApproveUserIds().split("锛�");
+ List<Long> ids = new ArrayList<>();
+ for (int i = 0; i < split.length; i++) {
+ SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getNickName, split[i])
+ .last("LIMIT 1"));
+ if (sysUser != null) {
+ ids.add(sysUser.getUserId());
+ }
}
+ // 灏嗛泦鍚堣浆涓哄瓧绗︿覆锛岄殧寮�
+ String collect = ids.stream().map(Object::toString).collect(Collectors.joining(","));
+ salesLedger.setApproveUserIds(collect);
}
- // 灏嗛泦鍚堣浆涓哄瓧绗︿覆锛岄殧寮�
- String collect = ids.stream().map(Object::toString).collect(Collectors.joining(","));
- salesLedger.setApproveUserIds(collect);
purchaseLedgerMapper.insert(salesLedger);
for (PurchaseLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) {
@@ -770,6 +684,9 @@
}
public void addApproveByPurchase(LoginUser loginUser,PurchaseLedger purchaseLedger) throws Exception {
+ if (loginUser == null) {
+ return;
+ }
ApproveProcessVO approveProcessVO = new ApproveProcessVO();
approveProcessVO.setApproveType(5);
approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
--
Gitblit v1.9.3