From f5624a59380db70633eebe3612e2d3c703012b41 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 08 一月 2026 17:58:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/jtwy' into jtwy
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 300 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index b6c43ed..2154217 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.sales.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -8,6 +9,8 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.pojo.AccountIncome;
+import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.basic.mapper.CustomerMapper;
import com.ruoyi.basic.pojo.Customer;
import com.ruoyi.common.enums.FileNameType;
@@ -16,10 +19,11 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
-import com.ruoyi.production.pojo.SalesLedgerScheduling;
+import com.ruoyi.production.mapper.*;
+import com.ruoyi.production.pojo.*;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
+import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.mapper.*;
@@ -62,6 +66,7 @@
@RequiredArgsConstructor
@Slf4j
public class SalesLedgerServiceImpl extends ServiceImpl<SalesLedgerMapper, SalesLedger> implements ISalesLedgerService {
+ private final AccountIncomeService accountIncomeService;
private final SalesLedgerMapper salesLedgerMapper;
@@ -78,6 +83,32 @@
private final InvoiceLedgerMapper invoiceLedgerMapper;
private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
+
+ private final SalesLedgerWorkMapper salesLedgerWorkMapper;
+
+ private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
+
+ private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+ private final InvoiceRegistrationMapper invoiceRegistrationMapper;
+
+ private final ProductOrderMapper productOrderMapper;
+
+ private final ProcessRouteMapper processRouteMapper;
+
+ private final ProcessRouteItemMapper processRouteItemMapper;
+
+ private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
+
+ private final ProductWorkOrderMapper productWorkOrderMapper;
+
+ private final ProductionProductMainMapper productionProductMainMapper;
+
+ private final ProductionProductOutputMapper productionProductOutputMapper;
+
+ private final ProductionProductInputMapper productionProductInputMapper;
+
+ private final QualityInspectMapper qualityInspectMapper;
@Autowired
private SysDeptMapper sysDeptMapper;
@@ -120,7 +151,8 @@
// 3.鏌ヨ涓婁紶鏂囦欢
LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
- salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId());
+ salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId())
+ .eq(CommonFile::getType, FileNameType.SALE.getValue());
List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
// 4. 杞崲 DTO
@@ -204,53 +236,77 @@
}
@Override
- public List<MonthlyAmountDto> getAmountHalfYear() {
+ public List<MonthlyAmountDto> getAmountHalfYear(Integer type) {
LocalDate now = LocalDate.now();
- YearMonth currentMonth = YearMonth.from(now);
+ LocalDateTime currentDateTime = LocalDateTime.now();
- List<MonthlyAmountDto> monthlyAmounts = new ArrayList<>();
+ // 鏍规嵁 type 纭畾鏌ヨ鐨勬椂闂撮棿闅旓紙澶╂暟锛夊拰鎬绘煡璇㈠ぉ鏁�
+ int daysPerPeriod;
+ int totalDays;
+ switch (type) {
+ case 1:
+ daysPerPeriod = 5; // 姣�5澶╂煡涓�娆�
+ totalDays = 30; // 6娆� 脳 5澶� = 30澶�
+ break;
+ case 2:
+ daysPerPeriod = 15; // 姣�15澶╂煡涓�娆�
+ totalDays = 90; // 6娆� 脳 15澶� = 90澶�
+ break;
+ case 3:
+ daysPerPeriod = 30; // 姣�30澶╂煡涓�娆�
+ totalDays = 180; // 6娆� 脳 30澶� = 180澶�
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid type value: " + type);
+ }
+ List<MonthlyAmountDto> result = new ArrayList<>();
+
+ // 寰幆6娆★紝姣忔鏌ヨ涓�涓椂闂存鐨勬暟鎹�
for (int i = 0; i < 6; i++) {
- YearMonth targetMonth = currentMonth.minusMonths(i);
- LocalDate firstDayOfMonth = targetMonth.atDay(1);
- LocalDate firstDayOfNextMonth = targetMonth.plusMonths(1).atDay(1);
+ // 璁$畻褰撳墠鏃堕棿娈电殑璧峰鍜岀粨鏉熸椂闂�
+ LocalDateTime endTime = currentDateTime.minusDays(i * daysPerPeriod);
+ LocalDateTime startTime = endTime.minusDays(daysPerPeriod);
- LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
- LocalDateTime startOfNextMonth = firstDayOfNextMonth.atStartOfDay();
+ // 鏌ヨ鍥炴閲戦
+ LambdaQueryWrapper<ReceiptPayment> receiptPaymentQuery = new LambdaQueryWrapper<>();
+ receiptPaymentQuery
+ .ge(ReceiptPayment::getCreateTime, startTime)
+ .lt(ReceiptPayment::getCreateTime, endTime);
+ List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(receiptPaymentQuery);
- LambdaQueryWrapper<ReceiptPayment> receiptPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
- receiptPaymentLambdaQueryWrapper.ge(ReceiptPayment::getCreateTime, startOfMonth)
- .lt(ReceiptPayment::getCreateTime, startOfNextMonth);
+ // 鏌ヨ寮�绁ㄩ噾棰�
+ LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>();
+ invoiceLedgerQuery
+ .ge(InvoiceLedger::getCreateTime, startTime)
+ .lt(InvoiceLedger::getCreateTime, endTime);
+ List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(invoiceLedgerQuery);
- LambdaQueryWrapper<InvoiceLedger> invoiceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
- invoiceLedgerLambdaQueryWrapper.ge(InvoiceLedger::getCreateTime, startOfMonth)
- .lt(InvoiceLedger::getCreateTime, startOfNextMonth);
-
- // 鑾峰彇鍥炴閲戦
- List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(receiptPaymentLambdaQueryWrapper);
- //寮�绁ㄩ噾棰�
- List<InvoiceLedger> invoiceLedgerList = invoiceLedgerMapper.selectList(invoiceLedgerLambdaQueryWrapper);
-
- // 浣跨敤 Stream 姹傚拰
- BigDecimal invoiceAmount = invoiceLedgerList.stream()
- .map(InvoiceLedger::getInvoiceTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
-
- BigDecimal receiptAmount = receiptPaymentList.stream()
+ // 璁$畻鍥炴鎬婚
+ BigDecimal receiptAmount = receiptPayments.stream()
.map(ReceiptPayment::getReceiptPaymentAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- MonthlyAmountDto monthlyAmount = new MonthlyAmountDto();
- monthlyAmount.setMonth(targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
- monthlyAmount.setInvoiceAmount(invoiceAmount);
- monthlyAmount.setReceiptAmount(receiptAmount);
+ // 璁$畻寮�绁ㄦ�婚
+ BigDecimal invoiceAmount = invoiceLedgers.stream()
+ .map(InvoiceLedger::getInvoiceTotal)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
- monthlyAmounts.add(monthlyAmount);
+ // 鏋勯�犺繑鍥炵殑 DTO
+ MonthlyAmountDto dto = new MonthlyAmountDto();
+ dto.setMonth(startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " ~ " +
+ endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ dto.setReceiptAmount(receiptAmount);
+ dto.setInvoiceAmount(invoiceAmount);
+
+ result.add(dto);
}
- Collections.reverse(monthlyAmounts);
- return monthlyAmounts;
+
+ // 鍙嶈浆鍒楄〃锛屼娇鏃堕棿椤哄簭浠庢棭鍒版櫄
+ Collections.reverse(result);
+ return result;
}
@Override
@@ -319,20 +375,124 @@
if (CollectionUtils.isEmpty(idList)) {
return 0;
}
- // 鐢熶骇璁㈠崟鏈夊緟鎺掍骇鏁版嵁锛屽彴璐︿笉鍙垹闄�
- LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<SalesLedgerScheduling>()
- .in(SalesLedgerScheduling::getSalesLedgerId, idList);
- if (salesLedgerSchedulingMapper.selectCount(salesLedgerSchedulingLambdaQueryWrapper) > 0) {
- throw new BaseException("鏈夋帓浜ф暟鎹紝涓嶅彲鍒犻櫎");
+ // 鍒犻櫎閿�鍞鐞嗘暟鎹�
+ LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList)
+ .select(SalesLedgerProduct::getId);
+
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(queryWrapper);
+ List<Long> productIds = products.stream()
+ .map(SalesLedgerProduct::getId)
+ .collect(Collectors.toList());
+
+ //鎵归噺鏌ヨproductOrder
+ List<ProductOrder> productOrders = productOrderMapper.selectList(
+ new LambdaQueryWrapper<ProductOrder>()
+ .in(ProductOrder::getProductModelId, productIds)
+ );
+
+ if (!org.springframework.util.CollectionUtils.isEmpty(productOrders)) {
+ List<Long> orderIds = productOrders.stream()
+ .map(ProductOrder::getId)
+ .collect(Collectors.toList());
+
+ // 鎵归噺鏌ヨprocessRouteItems
+ List<ProductProcessRouteItem> allRouteItems = productProcessRouteItemMapper.selectList(
+ new LambdaQueryWrapper<ProductProcessRouteItem>()
+ .in(ProductProcessRouteItem::getRouteId, orderIds)
+ );
+
+ if (!CollectionUtils.isEmpty(allRouteItems)) {
+ // 鑾峰彇瑕佸垹闄ょ殑宸ュ簭椤笽D
+ List<Long> routeItemIds = allRouteItems.stream()
+ .map(ProductProcessRouteItem::getId)
+ .collect(Collectors.toList());
+
+ // 鏌ヨ鍏宠仈鐨勫伐鍗旾D
+ List<ProductWorkOrder> workOrders = productWorkOrderMapper.selectList(
+ new LambdaQueryWrapper<ProductWorkOrder>()
+ .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds)
+ );
+ if (!CollectionUtils.isEmpty(workOrders)) {
+ List<Long> workOrderIds = workOrders.stream()
+ .map(ProductWorkOrder::getId)
+ .collect(Collectors.toList());
+
+ // 鏌ヨ鍏宠仈鐨勭敓浜т富琛↖D
+ List<ProductionProductMain> productMains = productionProductMainMapper.selectList(
+ new LambdaQueryWrapper<ProductionProductMain>()
+ .in(ProductionProductMain::getWorkOrderId, workOrderIds)
+ );
+ List<Long> productMainIds = productMains.stream()
+ .map(ProductionProductMain::getId)
+ .collect(Collectors.toList());
+
+ // 鍒犻櫎浜у嚭琛ㄣ�佹姇鍏ヨ〃鏁版嵁
+ if (!CollectionUtils.isEmpty(productMainIds)) {
+ productionProductOutputMapper.deleteByProductMainIds(productMainIds);
+ productionProductInputMapper.deleteByProductMainIds(productMainIds);
+ qualityInspectMapper.deleteByProductMainIds(productMainIds);
+ }
+
+ // 鍒犻櫎鐢熶骇涓昏〃鏁版嵁
+ productionProductMainMapper.deleteByWorkOrderIds(workOrderIds);
+
+ // 鍒犻櫎宸ュ崟鏁版嵁
+ productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>()
+ .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
+ }
+ }
+ // 鎵归噺鍒犻櫎processRouteItem
+ productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>()
+ .in(ProductProcessRouteItem::getRouteId, orderIds));
+
+ // 鎵归噺鍒犻櫎productOrder
+ productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>()
+ .in(ProductOrder::getProductModelId, productIds));
}
- // 1. 鍏堝垹闄ゅ瓙琛ㄦ暟鎹�
- LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
- productWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList);
- salesLedgerProductMapper.delete(productWrapper);
+
+ // 鎵归噺鍒犻櫎浜у搧瀛愯〃
+ if (!productIds.isEmpty()) {
+ salesLedgerProductMapper.deleteBatchIds(productIds);
+ }
+
+ LambdaQueryWrapper<InvoiceRegistrationProduct> wrapper = new LambdaQueryWrapper<>();
+ wrapper.in(InvoiceRegistrationProduct::getSalesLedgerId, idList);
+ List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(wrapper);
+ List<Integer> invoiceLedgerIds = new ArrayList<>();
+ if(CollectionUtils.isNotEmpty(invoiceRegistrationProducts)){
+ LambdaQueryWrapper<InvoiceLedger> wrapperOne = new LambdaQueryWrapper<>();
+ wrapperOne.in(InvoiceLedger::getInvoiceRegistrationProductId, invoiceRegistrationProducts.stream().map(InvoiceRegistrationProduct::getId).collect(Collectors.toList()));
+ List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(wrapperOne);
+ if(CollectionUtils.isNotEmpty(invoiceLedgers)){
+ invoiceLedgerIds = invoiceLedgers.stream().map(InvoiceLedger::getId).collect(Collectors.toList());
+ }
+ invoiceLedgerMapper.delete(wrapperOne);
+ }
+ invoiceRegistrationProductMapper.delete(wrapper);
+ LambdaQueryWrapper<InvoiceRegistration> wrapperTwo = new LambdaQueryWrapper<>();
+ wrapperTwo.in(InvoiceRegistration::getSalesLedgerId, idList);
+ invoiceRegistrationMapper.delete(wrapperTwo);
+
+ if(CollectionUtils.isNotEmpty(invoiceLedgerIds)){
+ LambdaQueryWrapper<ReceiptPayment> wrapperTree = new LambdaQueryWrapper<>();
+ wrapperTree.in(ReceiptPayment::getInvoiceLedgerId, invoiceLedgerIds);
+ receiptPaymentMapper.delete(wrapperTree);
+ }
+
+ // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
// 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
.in(SalesLedgerScheduling::getSalesLedgerId, idList);
salesLedgerSchedulingMapper.delete(in);
+ // 鍒犻櫎鐢熶骇娲惧伐鏁版嵁
+ LambdaQueryWrapper<SalesLedgerWork> workOrderWrapper = new LambdaQueryWrapper<>();
+ workOrderWrapper.in(SalesLedgerWork::getSalesLedgerId, idList);
+ salesLedgerWorkMapper.delete(workOrderWrapper);
+ // 鍒犻櫎鐢熶骇鎶ュ伐鏁版嵁
+ LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
+ reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, idList);
+ salesLedgerProductionAccountingMapper.delete(reportWrapper);
// 2. 鍐嶅垹闄や富琛ㄦ暟鎹�
return salesLedgerMapper.deleteBatchIds(idList);
}
@@ -352,13 +512,38 @@
salesLedger.setCustomerName(customer.getCustomerName());
salesLedger.setTenantId(customer.getTenantId());
+ AccountIncome accountIncome = new AccountIncome();
+ accountIncome.setIncomeDate(salesLedger.getEntryDate());
+ accountIncome.setIncomeType("0");
+ accountIncome.setCustomerName(customer.getCustomerName());
+ accountIncome.setIncomeMoney(salesLedger.getContractAmount());
+ accountIncome.setIncomeMethod("0");
+ accountIncome.setInputTime(new Date());
+ accountIncome.setInputUser(salesLedger.getEntryPerson());
// 3. 鏂板鎴栨洿鏂颁富琛�
if (salesLedger.getId() == null) {
String contractNo = generateSalesContractNo();
salesLedger.setSalesContractNo(contractNo);
salesLedgerMapper.insert(salesLedger);
+ accountIncome.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedger.getSalesContractNo());
+ accountIncome.setInvoiceNumber(salesLedger.getSalesContractNo());
+ accountIncomeService.save(accountIncome);
} else {
salesLedgerMapper.updateById(salesLedger);
+ SalesLedger salesLedgerDB = salesLedgerMapper.selectById(salesLedger.getId());
+ List<AccountIncome> accountIncomeDBs = accountIncomeService.getByInvoiceNumberList(salesLedger.getSalesContractNo());
+ if (!org.springframework.util.CollectionUtils.isEmpty(accountIncomeDBs)) {
+ accountIncomeDBs.forEach(accountIncomeDB -> {
+ accountIncomeDB.setCustomerName(salesLedgerDB.getCustomerName());
+ accountIncomeDB.setIncomeMoney(salesLedgerDB.getContractAmount());
+ accountIncomeDB.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedgerDB.getSalesContractNo());
+ accountIncomeDB.setInvoiceNumber(salesLedgerDB.getSalesContractNo());
+ accountIncomeDB.setInputTime(new Date());
+ accountIncomeDB.setInputUser(salesLedgerDB.getEntryPerson());
+ accountIncomeService.updateById(accountIncomeDB);
+ });
+ }
+
}
// 4. 澶勭悊瀛愯〃鏁版嵁
@@ -428,12 +613,15 @@
try {
// 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
- Files.move(
- Paths.get(tempFile.getTempPath()),
- formalFilePath,
- StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
- );
+// 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锛�
@@ -482,6 +670,62 @@
salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
salesLedgerProductMapper.insert(salesLedgerProduct);
+
+ ProductOrder productOrder = new ProductOrder();
+ productOrder.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
+ productOrder.setProductModelId(salesLedgerProduct.getId());
+ productOrder.setNpsNo("SC" + String.format("%08d", salesLedgerProduct.getId()));
+ productOrderMapper.insert(productOrder);
+
+ ProcessRoute processRoute = processRouteMapper.selectOne(new QueryWrapper<ProcessRoute>().lambda().eq(ProcessRoute::getProductModelId, salesLedgerProduct.getProductModelId()));
+ if (processRoute != null) {
+ List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(new QueryWrapper<ProcessRouteItem>().lambda().eq(ProcessRouteItem::getRouteId, processRoute.getId()));
+ // 鐢熸垚褰撳墠鏃ユ湡鐨勫墠缂�锛氬勾鏈堟棩
+ String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+ int dragSort = 1;
+ for (ProcessRouteItem processRouteItem : processRouteItems) {
+ ProductProcessRouteItem productProcessRouteItem = new ProductProcessRouteItem();
+ productProcessRouteItem.setProductModelId(processRouteItem.getProductModelId());
+ productProcessRouteItem.setProcessId(processRouteItem.getProcessId());
+ productProcessRouteItem.setRouteId(productOrder.getId());
+ productProcessRouteItem.setDragSort(dragSort);
+ int insert = productProcessRouteItemMapper.insert(productProcessRouteItem);
+ if (insert > 0) {
+ // 鏌ヨ浠婃棩宸插瓨鍦ㄧ殑鏈�澶у伐鍗曞彿
+ QueryWrapper<ProductWorkOrder> queryWrapper = new QueryWrapper<>();
+ queryWrapper.likeRight("work_order_no", datePrefix)
+ .orderByDesc("work_order_no")
+ .last("LIMIT 1");
+
+ ProductWorkOrder lastWorkOrder = productWorkOrderMapper.selectOne(queryWrapper);
+
+ int sequenceNumber = 1; // 榛樿搴忓彿
+ if (lastWorkOrder != null && lastWorkOrder.getWorkOrderNo() != null) {
+ String lastNo = lastWorkOrder.getWorkOrderNo().toString();
+ if (lastNo.startsWith(datePrefix)) {
+ String seqStr = lastNo.substring(datePrefix.length());
+ try {
+ sequenceNumber = Integer.parseInt(seqStr) + 1;
+ } catch (NumberFormatException e) {
+ sequenceNumber = 1;
+ }
+ }
+ }
+ // 鐢熸垚瀹屾暣鐨勫伐鍗曞彿
+ String workOrderNoStr = String.format("%s%03d", datePrefix, sequenceNumber);
+ ProductWorkOrder productWorkOrder = new ProductWorkOrder();
+ productWorkOrder.setProductProcessRouteItemId(productProcessRouteItem.getId());
+ productWorkOrder.setProductOrderId(productOrder.getId());
+ productWorkOrder.setPlanQuantity(salesLedgerProduct.getQuantity());
+ productWorkOrder.setWorkOrderNo(workOrderNoStr);
+ productWorkOrder.setStatus(1);
+ productWorkOrderMapper.insert(productWorkOrder);
+ }
+ dragSort++;
+ }
+ productOrder.setRouteId(processRoute.getId());
+ productOrderMapper.updateById(productOrder);
+ }
}
}
}
@@ -535,12 +779,12 @@
return datePart + String.format("%03d", nextSequence);
} finally {
- // 3. 閲婃斁閿侊紙浣跨敤Lua鑴氭湰淇濊瘉鍘熷瓙鎬э紝閬垮厤璇垹鍏朵粬绾跨▼鐨勯攣锛�
+ // 3. 閲婃斁閿�
String luaScript = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end";
redisTemplate.execute(
new DefaultRedisScript<>(luaScript, Long.class),
Collections.singletonList(lockKey),
- lockValue // 鍙湁鎸佹湁鐩稿悓鍊肩殑绾跨▼鎵嶈兘鍒犻櫎閿�
+ lockValue
);
}
}
@@ -549,7 +793,7 @@
if (sequences.isEmpty()) {
return 1;
}
- // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁帮紙涓庡師閫昏緫涓�鑷达級
+ // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁�
sequences.sort(Integer::compareTo);
int next = 1;
for (int seq : sequences) {
@@ -579,14 +823,13 @@
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- // 鏋勯�犱富琛ㄦ洿鏂板璞★紙鏀寔浠绘剰涓昏〃绫诲瀷锛�
+ // 鏋勯�犱富琛ㄦ洿鏂板璞�
try {
S entity = mainEntityClass.getDeclaredConstructor().newInstance();
Field idField = mainEntityClass.getDeclaredField("id");
idField.setAccessible(true);
idField.set(entity, mainId);
- // 璁剧疆 contractAmount 瀛楁锛屾敞鎰忚繖閲屽亣璁惧瓧娈靛悕涓� "contractAmount"
Field amountField = mainEntityClass.getDeclaredField("contractAmount");
amountField.setAccessible(true);
amountField.set(entity, totalAmount);
--
Gitblit v1.9.3