From 79cceefe43f14643781b76def9b980398990d458 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 20 五月 2026 11:48:10 +0800
Subject: [PATCH] feat(approve): 添加审批实例相关DTO、VO类及审批流程工具类
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 175 +++++++++++++++++++---------------------------------------
1 files changed, 58 insertions(+), 117 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 8660993..3afd306 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,22 @@
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.pojo.ApproveProcess;
-import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
+import com.ruoyi.approve.bean.dto.ApprovalInstanceDto;
import com.ruoyi.approve.bean.vo.ApproveProcessVO;
+import com.ruoyi.approve.mapper.ApprovalTemplateMapper;
+import com.ruoyi.approve.pojo.ApprovalInstance;
+import com.ruoyi.approve.pojo.ApproveProcess;
+import com.ruoyi.approve.service.ApprovalInstanceService;
+import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
+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 +30,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 +65,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 +115,9 @@
private final QualityInspectParamMapper qualityInspectParamMapper;
private final ApproveProcessServiceImpl approveProcessService;
private final ProcurementRecordMapper procurementRecordStorageMapper;
-
- @Value("${file.upload-dir}")
- private String uploadDir;
+ private final FileUtil fileUtil;
+ private final ApprovalInstanceService approvalInstanceService;
+ private final ApprovalTemplateMapper approvalTemplateMapper;
@Override
public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) {
@@ -139,6 +138,8 @@
@Transactional(rollbackFor = Exception.class)
public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws Exception {
PurchaseLedger purchaseLedger = new PurchaseLedger();
+ // DTO杞珽ntity
+ BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger);
SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
//褰曞叆浜�
SysUser sysUser = userMapper.selectUserById(purchaseLedgerDto.getRecorderId());
@@ -153,9 +154,6 @@
SupplierManage supplierManage = supplierManageMapper.selectById(purchaseLedgerDto.getSupplierId());
- // DTO杞珽ntity
-
- BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger);
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) {
purchaseLedger.setTenantId(loginUser.getTenantId());
@@ -170,7 +168,7 @@
if (purchaseLedger.getId() == null) {
purchaseLedgerMapper.insert(purchaseLedger);
} else {
- // 鍒犻櫎閲囪喘瀹℃牳锛岄噸鏂版彁浜�
+// // 鍒犻櫎閲囪喘瀹℃牳锛岄噸鏂版彁浜�
ApproveProcess one = approveProcessService.getOne(new LambdaQueryWrapper<ApproveProcess>()
.eq(ApproveProcess::getApproveType, 5)
.eq(ApproveProcess::getApproveReason, purchaseLedger.getPurchaseContractNumber())
@@ -180,28 +178,31 @@
approveProcessService.delByIds(Collections.singletonList(one.getId()));
}
purchaseLedgerMapper.updateById(purchaseLedger);
+ //鍒犻櫎鏂伴噰璐鎵�
+ approvalInstanceService.remove(new LambdaQueryWrapper<ApprovalInstance>().eq(ApprovalInstance::getBusinessId, purchaseLedger.getId()).eq(ApprovalInstance::getBusinessType, 5));
}
- // 6.閲囪喘瀹℃牳鏂板锛涘鎵圭鐞嗘湭閰嶇疆閲囪喘瀹℃壒浜烘椂锛屽鎵规湇鍔′細鑷姩缃负瀹℃壒閫氳繃銆�
- addApproveByPurchase(loginUser, purchaseLedger);
+ //鏂伴噰璐鎵�
+ ApprovalInstanceDto approvalInstanceDto = new ApprovalInstanceDto();
+ approvalInstanceDto.setTemplateId(purchaseLedger.getTemplateId());
+ approvalInstanceDto.setBusinessId(purchaseLedger.getId());
+ approvalInstanceDto.setBusinessType(5L);
+ approvalInstanceDto.setTitle("閲囪喘鍚堝悓鍙凤細" + purchaseLedger.getPurchaseContractNumber());
+ approvalInstanceDto.setApplicantId(SecurityUtils.getUserId());
+ approvalInstanceDto.setTemplateId(purchaseLedger.getTemplateId());
+ approvalInstanceDto.setTemplateName(approvalTemplateMapper.selectById(purchaseLedger.getTemplateId()).getTemplateName());
+ approvalInstanceDto.setApplicantName(SecurityUtils.getLoginUser().getNickName());
+ approvalInstanceDto.setApplyTime(LocalDateTime.now());
+ approvalInstanceService.add(approvalInstanceDto);
// 4. 澶勭悊瀛愯〃鏁版嵁
List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData();
if (productList != null && !productList.isEmpty()) {
handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType());
}
- //鏂板鍘熸潗鏂欐楠� 瀹℃壒涔嬪悗鎵嶇敓鎴愭楠�
-// if (productList != null) {
-// for (SalesLedgerProduct saleProduct : productList) {
-// //鏄惁鎺ㄩ�佽川妫�锛屽鏋渢rue灏辨坊鍔�
-// if (saleProduct.getIsChecked()) {
-// addQualityInspect(purchaseLedger, saleProduct);
-// }
-// }
-// }
+ // 6.閲囪喘瀹℃牳鏂板锛涘鎵圭鐞嗘湭閰嶇疆閲囪喘瀹℃壒浜烘椂锛屽鎵规湇鍔′細鑷姩缃负瀹℃壒閫氳繃銆�
+ addApproveByPurchase(loginUser, purchaseLedger);
// 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;
}
@@ -322,80 +323,6 @@
}
}
- /**
- * 灏嗕复鏃舵枃浠惰縼绉诲埌姝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);
- }
- }
- }
-
@Override
@Transactional(rollbackFor = Exception.class)
public int deletePurchaseLedgerByIds(Long[] ids) {
@@ -493,11 +420,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();
@@ -505,7 +427,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;
}
@@ -591,10 +513,29 @@
@Override
public IPage<PurchaseLedgerDto> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedgerDto purchaseLedger) {
IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger);
- purchaseLedgerDtoIPage.getRecords().forEach(purchaseLedgerDto -> {
- List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASE.getValue()));
- purchaseLedgerDto.setSalesLedgerFiles(commonFiles);
- });
+ List<PurchaseLedgerDto> records = purchaseLedgerDtoIPage.getRecords();
+ if (records == null || records.isEmpty()) {
+ return purchaseLedgerDtoIPage;
+ }
+
+ // 鎵归噺鏌ヨ鏂囦欢锛岄伩鍏� N+1 闂
+ List<Long> ledgerIds = records.stream()
+ .map(PurchaseLedgerDto::getId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ if (!ledgerIds.isEmpty()) {
+ List<CommonFile> allFiles = commonFileMapper.selectList(
+ new LambdaQueryWrapper<CommonFile>()
+ .in(CommonFile::getCommonId, ledgerIds)
+ .eq(CommonFile::getType, FileNameType.PURCHASE.getValue())
+ );
+
+ Map<Long, List<CommonFile>> fileMap = allFiles.stream()
+ .collect(Collectors.groupingBy(CommonFile::getCommonId));
+
+ records.forEach(dto -> dto.setSalesLedgerFiles(fileMap.getOrDefault(dto.getId(), new ArrayList<>())));
+ }
return purchaseLedgerDtoIPage;
}
@@ -740,9 +681,9 @@
return AjaxResult.success("瀵煎叆鎴愬姛");
} catch (Exception e) {
- e.printStackTrace();
+ log.error("PurchaseLedgerServiceImpl importData error", e);
+ return AjaxResult.error("瀵煎叆澶辫触: " + e.getMessage());
}
- return AjaxResult.success("瀵煎叆澶辫触");
}
@Override
--
Gitblit v1.9.3