From 3f3a1ed182e96214e66f6456ee692427bf04d454 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 28 十一月 2025 11:10:23 +0800
Subject: [PATCH] yys 1.库存管理导出修改 2.来票登记分页查询修改
---
src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java | 266 +++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 235 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
index d3550ea..5070319 100644
--- a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
@@ -4,30 +4,42 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.procurementrecord.dto.ProcurementRecordOutPageDto;
-import com.ruoyi.production.dto.ProcessSchedulingDto;
-import com.ruoyi.production.dto.ProductionDispatchAddDto;
-import com.ruoyi.production.dto.SalesLedgerSchedulingDto;
-import com.ruoyi.production.dto.SalesLedgerSchedulingProcessDto;
+import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.production.dto.*;
import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
+import com.ruoyi.production.mapper.SpeculativeTradingInfoMapper;
import com.ruoyi.production.pojo.SalesLedgerScheduling;
import com.ruoyi.production.pojo.SalesLedgerWork;
+import com.ruoyi.production.pojo.SpeculativeTradingInfo;
import com.ruoyi.production.service.SalesLedgerSchedulingService;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.sales.mapper.LossMapper;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.Loss;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/**
@@ -61,8 +73,38 @@
.filter(j -> j.getSalesLedgerProductId().equals(i.getSalesLedgerProductId()))
.map(SalesLedgerWork::getFinishedNum)
.reduce(BigDecimal.ZERO, BigDecimal::add));
+ // 鐘舵�� = 鏁伴噺鍜屽畬宸ユ暟閲忔瘮杈�
+ if(i.getSchedulingNum().compareTo(new BigDecimal(0)) == 0){
+ i.setStatus("鏈畬鎴�");
+ } else if(i.getSchedulingNum().compareTo(i.getSuccessNum()) == 0){
+ i.setStatus("宸插畬鎴�");
+ }else{
+ i.setStatus("鐢熶骇涓�");
+ }
+ // 璁$畻鐢熶骇鎬婚噺 = 瑙勬牸 * 鏁伴噺 / 1000
+ String[] split = i.getSpecificationModel().split("\\*");
+ if(split.length == 2 && isNumeric(split[0]) && isNumeric(split[1])){
+ BigDecimal multiply = new BigDecimal(split[0])
+ .multiply(new BigDecimal(split[1])
+ .multiply(i.getQuantity()).divide(new BigDecimal(1000),2, RoundingMode.CEILING));
+ i.setTotalProduction(multiply);
+ }
+
});
return list;
+ }
+
+ public static boolean isNumeric(String str) {
+ if (str == null || str.isEmpty()) {
+ return false;
+ }
+ // 閬嶅巻瀛楃涓茬殑姣忎釜瀛楃锛屾鏌ユ槸鍚︿负鏁板瓧
+ for (int i = 0; i < str.length(); i++) {
+ if (!Character.isDigit(str.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
}
@Override
@@ -90,38 +132,171 @@
private final SysUserMapper sysUserMapper;
+ private final SpeculativeTradingInfoMapper speculativeTradingInfoMapper;
+
@Override
- public int productionDispatch(ProductionDispatchAddDto productionDispatchAddDto) {
- SysUser sysUser = sysUserMapper.selectUserById(productionDispatchAddDto.getSchedulingUserId());
- if(sysUser == null) throw new RuntimeException("鎺掍骇浜轰笉瀛樺湪");
- SalesLedgerScheduling salesLedgerScheduling = SalesLedgerScheduling.builder()
- .salesLedgerId(productionDispatchAddDto.getSalesLedgerId())
- .salesLedgerProductId(productionDispatchAddDto.getSalesLedgerProductId())
- .schedulingUserId(productionDispatchAddDto.getSchedulingUserId())
- .schedulingUserName(sysUser.getNickName())
- .schedulingNum(productionDispatchAddDto.getSchedulingNum())
- .schedulingDate(LocalDate.parse(productionDispatchAddDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE))
- .status(1)
- .build();
- return salesLedgerSchedulingMapper.insert(salesLedgerScheduling);
+ public String productionDispatch(List<ProductionDispatchAddDto> productionDispatchAddDtoList) {
+ int i = 0;
+ int successNum = 0;
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ for (ProductionDispatchAddDto productionDispatchAddDto : productionDispatchAddDtoList) {
+ SysUser sysUser = sysUserMapper.selectUserById(productionDispatchAddDto.getSchedulingUserId() == null ? loginUser.getUser().getUserId() : productionDispatchAddDto.getSchedulingUserId());
+ if(sysUser == null){
+ i++;
+ continue;
+ }
+ // 鑾峰彇绌轰綑鐐掓満
+ String[] split = productionDispatchAddDto.getSpeculativeTradingName().split(",");
+ if(split != null && split.length == 0){
+ i++;
+ continue;
+ }
+ List<SpeculativeTradingInfo> speculativeTradingInfos = speculativeTradingInfoMapper.selectList(new LambdaQueryWrapper<SpeculativeTradingInfo>()
+ .in(SpeculativeTradingInfo::getName, Arrays.asList(split))
+ .orderByAsc(SpeculativeTradingInfo::getSort));
+ if(CollectionUtils.isEmpty(speculativeTradingInfos)){
+ i++;
+ continue;
+ }
+ AtomicReference<String> name = new AtomicReference<>(""); //闇�瑕佺粦瀹氱殑鐐掓満
+ //閫氳繃瑙勬牸鍨嬪彿鍜屾帓浜ф暟閲忚绠楁湰娆$敓浜т骇閲�
+ String[] split1 = productionDispatchAddDto.getSpecificationModel().split("\\*");
+ if(split1.length != 2){
+ i++;
+ continue;
+ }
+ // 鏈鐢熶骇浜ч噺
+ BigDecimal productionNum = new BigDecimal(split1[0])
+ .multiply(new BigDecimal(split1[1]).multiply(productionDispatchAddDto.getSchedulingNum()));
+ // 澶氫釜鐐掓満鎯呭喌
+ if(speculativeTradingInfos.size() > 1){
+ for (SpeculativeTradingInfo speculativeTradingInfo : speculativeTradingInfos) {
+ // 鑾峰彇璇ョ倰鏈烘鍦ㄦ帓浜ч噺
+ BigDecimal schedulingNumBySpeculativeTradingName = getSchedulingNumBySpeculativeTradingName(speculativeTradingInfo.getName());
+ // 濡傛灉璇ョ倰鏈烘�婚噺(鍗曚綅kg闇�瑕佷箻1000) - 姝e湪鎺掍骇閲� >=鏈鐢熶骇浜ч噺灏卞垎閰嶆鐐掓満
+ if(speculativeTradingInfo.getWorkLoad().multiply(new BigDecimal(1000)).subtract(schedulingNumBySpeculativeTradingName).compareTo(productionNum) >= 0){
+ name.set(speculativeTradingInfo.getName());
+ break;
+ }
+ }
+ }else{
+ // 鍗曚釜鐐掓満鎯呭喌
+ name.set(speculativeTradingInfos.get(0).getName());
+ }
+ if(name.get().isEmpty()){
+ i++;
+ continue;
+ }
+ SalesLedgerScheduling salesLedgerScheduling = SalesLedgerScheduling.builder()
+ .salesLedgerId(productionDispatchAddDto.getSalesLedgerId())
+ .salesLedgerProductId(productionDispatchAddDto.getSalesLedgerProductId())
+ .speculativeTradingName(name.get())
+ .schedulingUserId(sysUser.getUserId())
+ .schedulingUserName(sysUser.getNickName())
+ .schedulingNum(productionDispatchAddDto.getSchedulingNum())
+ .schedulingDate(productionDispatchAddDto.getSchedulingDate() == null ? LocalDate.now() : LocalDate.parse(productionDispatchAddDto.getSchedulingDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")))
+ .status(1)
+ .build();
+ salesLedgerSchedulingMapper.insert(salesLedgerScheduling);
+ successNum++;
+ }
+
+ return "娲惧伐鎴愬姛鏁伴噺" + successNum + "锛屽け璐ユ暟閲�" + i;
+ }
+
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
+
+ /**
+ *閫氳繃鐐掓満鍚嶇О鑾峰彇褰撳ぉ姝e湪鎺掍骇閲�
+ * @return
+ */
+ public BigDecimal getSchedulingNumBySpeculativeTradingName(String speculativeTradingName){
+ LambdaQueryWrapper<SalesLedgerScheduling> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(SalesLedgerScheduling::getSpeculativeTradingName, speculativeTradingName)
+ .eq(SalesLedgerScheduling::getSchedulingDate, LocalDate.now());
+ List<SalesLedgerScheduling> salesLedgerSchedulings = salesLedgerSchedulingMapper.selectList(queryWrapper);
+ if(CollectionUtils.isEmpty(salesLedgerSchedulings)){
+ return BigDecimal.ZERO;
+ }
+ List<Long> collect = salesLedgerSchedulings.stream().map(SalesLedgerScheduling::getSalesLedgerProductId).collect(Collectors.toList());
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+ .in(SalesLedgerProduct::getId, collect));
+ if(CollectionUtils.isEmpty(salesLedgerProducts)) return BigDecimal.ZERO;
+ AtomicInteger totalNum = new AtomicInteger(0); //鎬绘暟
+ salesLedgerSchedulings.forEach(item ->{
+ List<SalesLedgerProduct> collect1 = salesLedgerProducts.stream()
+ .filter(j -> j.getId().equals(item.getSalesLedgerProductId()))
+ .collect(Collectors.toList());
+ if(!CollectionUtils.isEmpty(collect1)){
+ SalesLedgerProduct salesLedgerProduct = collect1.get(0);
+ // 鏍规嵁浜у搧瑙勬牸 * 鎺掍骇鏁伴噺 鑾峰彇鏈鐢熶骇浜ч噺骞剁疮璁�
+ String[] split = salesLedgerProduct.getSpecificationModel().split("\\*");
+ BigDecimal productionNum = new BigDecimal(split[0])
+ .multiply(new BigDecimal(split[1]).multiply(item.getSchedulingNum()));
+ totalNum.addAndGet(productionNum.intValue());
+ }
+ });
+ // 闇�瑕� / 鎹熻�楃巼
+ Loss loss = lossMapper.selectOne(new LambdaQueryWrapper<Loss>().last("limit 1"));
+ BigDecimal lossNum = loss == null ? new BigDecimal(6) : loss.getRate(); //娌℃湁鎹熻�楃巼鍒欓粯璁や负6
+
+ return new BigDecimal(totalNum.get()).multiply(new BigDecimal(100)).divide(lossNum, 2,RoundingMode.HALF_UP);
+ }
+
+ private final LossMapper lossMapper;
+
+
+ /**
+ *閫氳繃鎵归噺鐐掓満鍚嶇О鑾峰彇褰撳ぉ姝e湪鎺掍骇閲�
+ * @return
+ */
+ public BigDecimal getSchedulingNumBySpeculativeTradingNameList(List<String> speculativeTradingName){
+ LambdaQueryWrapper<SalesLedgerScheduling> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(SalesLedgerScheduling::getSpeculativeTradingName, speculativeTradingName)
+ .eq(SalesLedgerScheduling::getSchedulingDate, LocalDate.now());
+ List<SalesLedgerScheduling> salesLedgerSchedulings = salesLedgerSchedulingMapper.selectList(queryWrapper);
+ if(CollectionUtils.isEmpty(salesLedgerSchedulings)){
+ return BigDecimal.ZERO;
+ }
+ List<Long> collect = salesLedgerSchedulings.stream().map(SalesLedgerScheduling::getSalesLedgerProductId).collect(Collectors.toList());
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+ .in(SalesLedgerProduct::getId, collect));
+ if(CollectionUtils.isEmpty(salesLedgerProducts)) return BigDecimal.ZERO;
+ AtomicInteger totalNum = new AtomicInteger(0); //鎬绘暟
+ salesLedgerSchedulings.forEach(item ->{
+ List<SalesLedgerProduct> collect1 = salesLedgerProducts.stream()
+ .filter(j -> j.getId().equals(item.getSalesLedgerProductId()))
+ .collect(Collectors.toList());
+ if(!CollectionUtils.isEmpty(collect1)){
+ SalesLedgerProduct salesLedgerProduct = collect1.get(0);
+ // 鏍规嵁浜у搧瑙勬牸 * 鎺掍骇鏁伴噺 鑾峰彇鏈鐢熶骇浜ч噺骞剁疮璁�
+ String[] split = salesLedgerProduct.getSpecificationModel().split("\\*");
+ BigDecimal productionNum = new BigDecimal(split[0])
+ .multiply(new BigDecimal(split[1]).multiply(item.getSchedulingNum()));
+ totalNum.addAndGet(productionNum.intValue());
+ }
+ });
+ return new BigDecimal(totalNum.get());
}
@Override
public IPage<SalesLedgerSchedulingProcessDto> listPageProcess(Page page, SalesLedgerSchedulingProcessDto salesLedgerSchedulingDto) {
IPage<SalesLedgerSchedulingProcessDto> list = salesLedgerSchedulingMapper.listPageProcess(page, salesLedgerSchedulingDto);
- Set<Long> collect = list.getRecords().stream().map(SalesLedgerSchedulingProcessDto::getSalesLedgerProductId).collect(Collectors.toSet());
- if(CollectionUtils.isEmpty(collect)) return list;
- LambdaQueryWrapper<SalesLedgerWork> salesLedgerWorkLambdaQueryWrapper = new LambdaQueryWrapper<>();
- salesLedgerWorkLambdaQueryWrapper.in(SalesLedgerWork::getSalesLedgerProductId, collect)
- .ne(SalesLedgerWork::getStatus, 1);
- List<SalesLedgerWork> salesLedgerWorks = salesLedgerWorkMapper.selectList(salesLedgerWorkLambdaQueryWrapper);
+// Set<Long> collect = list.getRecords().stream().map(SalesLedgerSchedulingProcessDto::getId).collect(Collectors.toSet());
+// if(CollectionUtils.isEmpty(collect)) return list;
+// LambdaQueryWrapper<SalesLedgerWork> salesLedgerWorkLambdaQueryWrapper = new LambdaQueryWrapper<>();
+// salesLedgerWorkLambdaQueryWrapper.in(SalesLedgerWork::getSalesLedgerSchedulingId, collect)
+// .ne(SalesLedgerWork::getStatus, 1);
+// List<SalesLedgerWork> salesLedgerWorks = salesLedgerWorkMapper.selectList(salesLedgerWorkLambdaQueryWrapper);
list.getRecords().forEach(i -> {
- // 鑾峰彇瀹屾垚鏁伴噺
- i.setSuccessNum(salesLedgerWorks
- .stream()
- .filter(j -> j.getSalesLedgerProductId().equals(i.getSalesLedgerProductId()))
- .map(SalesLedgerWork::getFinishedNum)
- .reduce(BigDecimal.ZERO, BigDecimal::add));
+ // 璁$畻鐢熶骇鎬婚噺 = 瑙勬牸 * 鏁伴噺 / 1000
+ String[] split = i.getSpecificationModel().split("\\*");
+ if(split.length == 2 && isNumeric(split[0]) && isNumeric(split[1])){
+ BigDecimal multiply = new BigDecimal(split[0])
+ .multiply(new BigDecimal(split[1])
+ .multiply(i.getSuccessNum()).divide(new BigDecimal(1000),2, RoundingMode.CEILING));
+ i.setTotalProduction(multiply);
+ }
});
return list;
}
@@ -147,7 +322,14 @@
SysUser sysUser = sysUserMapper.selectUserById(processSchedulingDto.getSchedulingUserId());
if(sysUser == null) throw new RuntimeException("鎺掍骇浜轰笉瀛樺湪");
salesLedgerScheduling.setFinishedNum(salesLedgerScheduling.getFinishedNum().add(processSchedulingDto.getSchedulingNum()));
- if(salesLedgerScheduling.getSchedulingNum().compareTo(salesLedgerScheduling.getFinishedNum()) <= 0){
+// LambdaQueryWrapper<SalesLedgerWork> salesLedgerWorkLambdaQueryWrapper = new LambdaQueryWrapper<>();
+// salesLedgerWorkLambdaQueryWrapper.eq(SalesLedgerWork::getSalesLedgerSchedulingId, salesLedgerScheduling.getId())
+// .ne(SalesLedgerWork::getStatus, 1);
+// List<SalesLedgerWork> salesLedgerWorks = salesLedgerWorkMapper.selectList(salesLedgerWorkLambdaQueryWrapper);
+ if(salesLedgerScheduling.getSchedulingNum().compareTo(salesLedgerScheduling.getFinishedNum()) < 0){
+ throw new RuntimeException("褰撳墠鎺掍骇鏁伴噺澶т簬寰呮帓浜ф暟閲忥紝璇蜂粩缁嗘牳瀵癸紒");
+ }
+ if(salesLedgerScheduling.getSchedulingNum().compareTo(salesLedgerScheduling.getFinishedNum()) == 0){
salesLedgerScheduling.setStatus(3);
}else{
salesLedgerScheduling.setStatus(2);
@@ -156,6 +338,10 @@
SalesLedgerWork.SalesLedgerWorkBuilder salesLedgerWorkBuilder = SalesLedgerWork.builder()
.salesLedgerSchedulingId(salesLedgerScheduling.getId())
.salesLedgerId(salesLedgerScheduling.getSalesLedgerId())
+ .remark(processSchedulingDto.getRemark())
+ .type(processSchedulingDto.getType())
+ .loss(processSchedulingDto.getLoss())
+ .receive(processSchedulingDto.getReceive())
.salesLedgerProductId(salesLedgerScheduling.getSalesLedgerProductId())
.schedulingUserId(salesLedgerScheduling.getSchedulingUserId())
.schedulingUserName(sysUser.getNickName())
@@ -168,4 +354,22 @@
}
return 0;
}
+
+ @Override
+ public void exportOne(HttpServletResponse response) {
+ List<SalesLedgerSchedulingDto> list = salesLedgerSchedulingMapper.list();
+ if(CollectionUtils.isEmpty(list)){
+ throw new RuntimeException("鏃犲鍑烘暟鎹�");
+ }
+ List<DaiDto> dais = new ArrayList<>();
+ list.forEach(i -> {
+ DaiDto daiDto = new DaiDto();
+ BeanUtils.copyProperties(i, daiDto);
+ // 鑾峰彇寰呮帓浜ф暟閲�
+ daiDto.setDaiNum(daiDto.getQuantity().subtract(i.getSchedulingNum()));
+ dais.add(daiDto);
+ });
+ ExcelUtil<DaiDto> util = new ExcelUtil<>(DaiDto.class);
+ util.exportExcel(response, dais, "鐢熶骇娲惧伐");
+ }
}
--
Gitblit v1.9.3