| | |
| | | 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.basic.pojo.SupplierManage; |
| | | import com.ruoyi.basic.service.ISupplierService; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | |
| | | 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.stereotype.Service; |
| | |
| | | List<ProcurementRecordStorage> collect1 = procurementRecordStorages.stream() |
| | | .filter(procurementRecordStorage -> procurementRecordStorage.getSalesLedgerProductId().equals(dto.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | |
| | | // 如果没有相关的入库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | dto.setQuantity0(dto.getQuantity()); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // 计算已入库数量总和,并设置待入库数量 |
| | | BigDecimal totalInboundNum = collect1.stream() |
| | | .map(ProcurementRecordStorage::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | |
| | | // 待入库数量 = 总数量 - 已入库数量 |
| | | dto.setQuantity0(dto.getQuantity().subtract(totalInboundNum)); |
| | | } |
| | |
| | | public int updatePro(ProcurementUpdateDto procurementDto) { |
| | | ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId()); |
| | | procurementRecordStorageById.setInboundNum(procurementDto.getQuantityStock()); |
| | | procurementRecordStorageById.setWarnNum(procurementDto.getWarnNum()); |
| | | procurementRecordStorageById.setUpdateUser(SecurityUtils.getLoginUser().getUserId()); |
| | | procurementRecordStorageById.setUpdateTime(LocalDateTime.now()); |
| | | procurementRecordStorageById.setOutStockQuantity(procurementDto.getOutStockQuantity()); |
| | | procurementRecordStorageById.setShortageDescription(procurementDto.getShortageDescription()); |
| | | return procurementRecordMapper.updateById(procurementRecordStorageById); |
| | | } |
| | | |
| | |
| | | public int updateManagement(ProcurementManagementUpdateDto procurementDto) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | SysUser sysUser = sysUserMapper.selectUserById(procurementDto.getCreateUser()); |
| | | if(sysUser == null){ |
| | | if (sysUser == null) { |
| | | throw new RuntimeException("入库人不存在"); |
| | | } |
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | String entryDateStr = procurementDto.getEntryDate() + " 00:00:00"; |
| | | String createTimeStr = procurementDto.getCreateTime() + " 00:00:00"; |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(procurementDto.getSalesLedgerProductId()); |
| | | if (procurementDto.getSalesLedgerProductId() != null && salesLedgerProduct == null) { |
| | | throw new RuntimeException("销售台账产品不存在"); |
| | | } |
| | | if (procurementDto.getSalesLedgerProductId() != null && salesLedgerProduct != null) { |
| | | salesLedgerProduct.setMinStock(procurementDto.getMinStock()); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId()); |
| | | procurementRecordStorageById.setCreateBy(sysUser.getNickName()); |
| | | procurementRecordStorageById.setCreateUser(sysUser.getUserId()); |
| | | procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr,df)); |
| | | procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr, df)); |
| | | procurementRecordStorageById.setUpdateUser(loginUser.getUserId()); |
| | | procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr,df)); |
| | | procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr, df)); |
| | | procurementRecordMapper.updateById(procurementRecordStorageById); |
| | | return 0; |
| | | } |
| | |
| | | |
| | | ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder() |
| | | .salesLedgerProductId(detail.getId()) |
| | | .productModelId(detail.getProductModelId()) |
| | | .inboundBatches(aLong.equals(0L) ? "第1批次" : "第"+ (aLong + 1) + "批次") |
| | | .inboundNum(detail.getInboundQuantity()) |
| | | .warnNum(detail.getWarnNum()) |
| | | .outStockQuantity(detail.getOutStockQuantity()) |
| | | .shortageDescription(detail.getShortageDescription()) |
| | | .createTime(LocalDateTime.now()) |
| | | .createUser(loginUser.getUserId()) |
| | | .updateTime(LocalDateTime.now()) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int addProduct(Details detail) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | |
| | | ProcurementRecordStorage.ProcurementRecordStorageBuilder builder = ProcurementRecordStorage.builder() |
| | | .id(detail.getId()) |
| | | .inboundBatches("第1批次") |
| | | .inboundNum(detail.getInboundQuantity()) |
| | | .warnNum(detail.getWarnNum()) |
| | | .outStockQuantity(detail.getOutStockQuantity()) |
| | | .shortageDescription(detail.getShortageDescription()) |
| | | .productModelId(detail.getProductModelId()) |
| | | .updateTime(LocalDateTime.now()) |
| | | .updateUser(loginUser.getUserId()); |
| | | if (detail.getId() == null) { |
| | | builder.createTime(LocalDateTime.now()) |
| | | .createUser(loginUser.getUserId()) |
| | | .createBy(loginUser.getNickName()); |
| | | } |
| | | |
| | | boolean success = this.saveOrUpdate(builder.build()); |
| | | return success ? 1 : 0; |
| | | } |
| | | |
| | | // @Override |
| | | // public IPage<ProcurementPageDto> listPage(Page page, ProcurementPageDto procurementDto) { |
| | | // IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPage(page, procurementDto); |
| | | // List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords(); |
| | | // // 计算待入库数量 |
| | | // // 查询采购记录已入库数量 |
| | | // List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | // if(CollectionUtils.isEmpty( collect)){ |
| | | // return procurementPageDtoIPage; |
| | | // } |
| | | // LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | // List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | // if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | // return procurementPageDtoIPage; |
| | | // } |
| | | // for (ProcurementPageDto dto : procurementPageDtos) { |
| | | // // 根据采购台账ID筛选对应的出库记录 |
| | | // List<ProcurementRecordOut> collect1 = procurementRecords.stream() |
| | | // .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId())) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // // 如果没有相关的出库记录,跳过该条数据 |
| | | // if(CollectionUtils.isEmpty(collect1)){ |
| | | // dto.setInboundNum0(dto.getInboundNum()); |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 计算已出库数量总和,并设置待出库数量 |
| | | // BigDecimal totalInboundNum = collect1.stream() |
| | | // .map(ProcurementRecordOut::getInboundNum) |
| | | // .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // |
| | | // // 待出库数量 = 总数量 - 已出库数量 |
| | | // dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | // } |
| | | // return procurementPageDtoIPage; |
| | | // } |
| | | |
| | | private final ISupplierService supplierService; |
| | | @Override |
| | | public IPage<ProcurementPageDto> listPage(Page page, ProcurementPageDto procurementDto) { |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPage(page, procurementDto); |
| | | List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords(); |
| | | |
| | | if (CollectionUtils.isEmpty(procurementPageDtos)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | |
| | | List<SupplierManage> allSuppliers = supplierService.list(); |
| | | java.util.Random random = new java.util.Random(); |
| | | List<BigDecimal> taxRates = Arrays.asList(new BigDecimal("1"), new BigDecimal("6"), new BigDecimal("13")); |
| | | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | return procurementPageDtoIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | return procurementPageDtoIPage; |
| | | } |
| | | |
| | | for (ProcurementPageDto dto : procurementPageDtos) { |
| | | if (dto.getSupplierName() == null || dto.getSupplierName().isEmpty()) { |
| | | if (!allSuppliers.isEmpty()) { |
| | | dto.setSupplierName(allSuppliers.get(random.nextInt(allSuppliers.size())).getSupplierName()); |
| | | } |
| | | } |
| | | if (dto.getTaxRate() == null) { |
| | | dto.setTaxRate(taxRates.get(random.nextInt(taxRates.size()))); |
| | | } |
| | | if (dto.getTaxInclusiveUnitPrice() == null) { |
| | | // 生成 50 - 500 之间的随机价格 |
| | | double randomPrice = 50 + random.nextDouble() * 450; |
| | | dto.setTaxInclusiveUnitPrice(new BigDecimal(randomPrice).setScale(2, java.math.RoundingMode.HALF_UP)); |
| | | } |
| | | // 计算总价 |
| | | if (dto.getInboundNum() != null) { |
| | | dto.setTaxInclusiveTotalPrice(dto.getInboundNum().multiply(dto.getTaxInclusiveUnitPrice()).setScale(2, java.math.RoundingMode.HALF_UP)); |
| | | BigDecimal taxFactor = BigDecimal.ONE.add(dto.getTaxRate().divide(new BigDecimal("100"), 4, java.math.RoundingMode.HALF_UP)); |
| | | dto.setTaxExclusiveTotalPrice(dto.getTaxInclusiveTotalPrice().divide(taxFactor, 2, java.math.RoundingMode.HALF_UP)); |
| | | } |
| | | |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | dto.setInboundNum0(dto.getInboundNum() != null ? dto.getInboundNum() : BigDecimal.ZERO); |
| | | continue; |
| | | } |
| | | |
| | | // 根据采购台账ID筛选对应的出库记录 |
| | | List<ProcurementRecordOut> collect1 = procurementRecords.stream() |
| | | .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | // 如果没有相关的出库记录 |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum() != null ? dto.getInboundNum() : BigDecimal.ZERO); |
| | | continue; |
| | | } |
| | | |
| | |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 待出库数量 = 总数量 - 已出库数量 |
| | | dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | dto.setInboundNum0(dto.getInboundNum() != null ? dto.getInboundNum().subtract(totalInboundNum) : BigDecimal.ZERO.subtract(totalInboundNum)); |
| | | } |
| | | return procurementPageDtoIPage; |
| | | } |