| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.procurementrecord.dto.ProcurementRecordOutPageDto; |
| | | 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.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | |
| | | 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("æäº§äººä¸åå¨"); |
| | | // è·å空ä½çæº |
| | | String[] split = productionDispatchAddDto.getSpeculativeTradingName().split(","); |
| | | if(split != null && split.length == 0){ |
| | | throw new RuntimeException("çäº§çæºä¸è½ä¸ºç©º"); |
| | | } |
| | | List<SpeculativeTradingInfo> speculativeTradingInfos = speculativeTradingInfoMapper.selectList(new LambdaQueryWrapper<SpeculativeTradingInfo>() |
| | | .in(SpeculativeTradingInfo::getName, Arrays.asList(split)) |
| | | .orderByAsc(SpeculativeTradingInfo::getSort)); |
| | | if(CollectionUtils.isEmpty(speculativeTradingInfos)){ |
| | | throw new RuntimeException("æ 空ä½çæº,è¯·æ£æ¥çæºè¡¨"); |
| | | } |
| | | AtomicReference<String> name = new AtomicReference<>(""); //éè¦ç»å®ççæº |
| | | //éè¿è§æ ¼åå·åæäº§æ°éè®¡ç®æ¬æ¬¡ç产产é |
| | | String[] split1 = productionDispatchAddDto.getSpecificationModel().split("\\*"); |
| | | if(split1.length != 2) throw new RuntimeException("è§æ ¼åå·æ ¼å¼é误"); |
| | | // æ¬æ¬¡ç产产é |
| | | BigDecimal productionNum = new BigDecimal(split1[0]) |
| | | .multiply(new BigDecimal(split1[1]).multiply(productionDispatchAddDto.getSchedulingNum())); |
| | | // å¤ä¸ªçæºæ
åµ |
| | | if(speculativeTradingInfos.size() > 1){ |
| | | speculativeTradingInfos.forEach(item ->{ |
| | | // è·åè¯¥çæºæ£å¨æäº§é |
| | | BigDecimal schedulingNumBySpeculativeTradingName = getSchedulingNumBySpeculativeTradingName(item.getName()); |
| | | // å¦æè¯¥çæºæ»é - æ£å¨æäº§é >=æ¬æ¬¡ç产产éå°±åé
æ¤çæº |
| | | if(item.getWorkLoad().subtract(schedulingNumBySpeculativeTradingName).compareTo(productionNum) >= 0){ |
| | | name.set(item.getName()); |
| | | } |
| | | }); |
| | | } |
| | | if(name.get().isEmpty()) throw new RuntimeException("æ 空ä½çæº,è¯·æ£æ¥çæºè¡¨"); |
| | | SalesLedgerScheduling salesLedgerScheduling = SalesLedgerScheduling.builder() |
| | | .salesLedgerId(productionDispatchAddDto.getSalesLedgerId()) |
| | | .salesLedgerProductId(productionDispatchAddDto.getSalesLedgerProductId()) |
| | | .speculativeTradingName(name.get()) |
| | | .schedulingUserId(productionDispatchAddDto.getSchedulingUserId()) |
| | | .schedulingUserName(sysUser.getNickName()) |
| | | .schedulingNum(productionDispatchAddDto.getSchedulingNum()) |
| | |
| | | return salesLedgerSchedulingMapper.insert(salesLedgerScheduling); |
| | | } |
| | | |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | /** |
| | | *éè¿çæºåç§°è·åå½å¤©æ£å¨æäº§é |
| | | * @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()); |
| | | } |
| | | }); |
| | | return new BigDecimal(totalNum.get()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | *éè¿æ¹éçæºåç§°è·åå½å¤©æ£å¨æäº§é |
| | | * @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); |