| | |
| | | package com.ruoyi.procurementrecord.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.service.IProductModelService; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.procurementrecord.service.ProcurementRecordService; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | |
| | | private final ProcurementRecordOutMapper procurementRecordOutMapper; |
| | | |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private final StockUtils stockUtils; |
| | | private final ProductModelMapper productModelMapper; |
| | | |
| | | private final IProductModelService productModelService; |
| | | |
| | | @Override |
| | | public List<ProcurementDto> listProcurementBySalesLedgerId(ProcurementDto procurementDto) { |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementDtos.stream().map(ProcurementDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementDtos; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, collect); |
| | | List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty(procurementRecordStorages)){ |
| | | if (CollectionUtils.isEmpty(procurementRecordStorages)) { |
| | | return procurementDtos; |
| | | } |
| | | for (ProcurementDto dto : procurementDtos) { |
| | |
| | | List<ProcurementRecordStorage> collect1 = procurementRecordStorages.stream() |
| | | .filter(procurementRecordStorage -> procurementRecordStorage.getSalesLedgerProductId().equals(dto.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | |
| | | // 如果没有相关的入库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | 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)); |
| | | } |
| | | return procurementDtos; |
| | | } |
| | | |
| | | public ProcurementRecordStorage getProcurementRecordById(Integer id){ |
| | | public ProcurementRecordStorage getProcurementRecordById(Integer id) { |
| | | ProcurementRecordStorage procurementRecordStorage = procurementRecordMapper.selectById(id); |
| | | if(procurementRecordStorage == null) { |
| | | if (procurementRecordStorage == null) { |
| | | throw new RuntimeException("未找到该采购入库记录"); |
| | | } |
| | | return procurementRecordStorage; |
| | | } |
| | | |
| | | public List<ProcurementRecordStorage> getProcurementRecordByIds(List<Integer> id){ |
| | | public List<ProcurementRecordStorage> getProcurementRecordByIds(List<Integer> id) { |
| | | List<ProcurementRecordStorage> procurementRecordStorage = procurementRecordMapper.selectBatchIds(id); |
| | | if(procurementRecordStorage == null) { |
| | | if (procurementRecordStorage == null) { |
| | | throw new RuntimeException("未找到该采购入库记录"); |
| | | } |
| | | return procurementRecordStorage; |
| | |
| | | // 删除所有对应的出库记录 |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordOutLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordOutLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, procurementDto.getIds()) |
| | | .eq(ProcurementRecordOut::getType,procurementDto.getType()); |
| | | .eq(ProcurementRecordOut::getType, procurementDto.getType()); |
| | | List<ProcurementRecordOut> procurementRecordOuts = procurementRecordOutMapper.selectList(procurementRecordOutLambdaQueryWrapper); |
| | | if(!CollectionUtils.isEmpty(procurementRecordOuts)){ |
| | | if (!CollectionUtils.isEmpty(procurementRecordOuts)) { |
| | | procurementRecordOutMapper.deleteBatchIds(procurementRecordOuts.stream().map(ProcurementRecordOut::getId).collect(Collectors.toList())); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public void export(HttpServletResponse response,Integer type) { |
| | | public void export(HttpServletResponse response, Integer type) { |
| | | List<ProcurementPageDto> list = new ArrayList<>(); |
| | | if(type == 1){ |
| | | if (type == 1) { |
| | | list = procurementRecordMapper.list(); |
| | | }else{ |
| | | } else { |
| | | list = procurementRecordMapper.listOne(); |
| | | } |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = list.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class); |
| | | util.exportExcel(response, list, "入库台账"); |
| | | return; |
| | |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class); |
| | | util.exportExcel(response, list, "入库台账"); |
| | | return; |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | 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(salesLedgerProduct == null){ |
| | | if (salesLedgerProduct == null) { |
| | | throw new RuntimeException("销售台账产品不存在"); |
| | | } |
| | | // 根据大类,规格查询所有产品id |
| | |
| | | .eq(SalesLedgerProduct::getSpecificationModel, salesLedgerProduct.getSpecificationModel()) |
| | | .eq(SalesLedgerProduct::getType, 1); |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(salesLedgerProductLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty(salesLedgerProducts)){ |
| | | if (CollectionUtils.isEmpty(salesLedgerProducts)) { |
| | | throw new RuntimeException("没有找到对应的产品"); |
| | | } |
| | | salesLedgerProduct.setMinStock(procurementDto.getMinStock()); |
| | |
| | | procurementRecordStorage.setTotalPrice(procurementDto.getTotalPrice()); |
| | | procurementRecordStorage.setCreateBy(sysUser.getNickName()); |
| | | procurementRecordStorage.setCreateUser(sysUser.getUserId()); |
| | | procurementRecordStorage.setUpdateTime(LocalDateTime.parse(entryDateStr,df)); |
| | | procurementRecordStorage.setUpdateTime(LocalDateTime.parse(entryDateStr, df)); |
| | | procurementRecordStorage.setUpdateUser(loginUser.getUserId()); |
| | | procurementRecordStorage.setCreateTime(LocalDateTime.parse(createTimeStr,df)); |
| | | procurementRecordMapper.update(procurementRecordStorage,procurementRecordStorageLambdaQueryWrapper); |
| | | procurementRecordStorage.setCreateTime(LocalDateTime.parse(createTimeStr, df)); |
| | | procurementRecordMapper.update(procurementRecordStorage, procurementRecordStorageLambdaQueryWrapper); |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public void exportCopy(HttpServletResponse response,Integer type) { |
| | | public void exportCopy(HttpServletResponse response, Integer type) { |
| | | List<ProcurementPageDtoCopy> list = new ArrayList<>(); |
| | | if(type == 1){ |
| | | if (type == 1) { |
| | | list = procurementRecordMapper.listCopy(); |
| | | }else{ |
| | | } else { |
| | | list = procurementRecordMapper.listCopyOne(); |
| | | } |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = list.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void exportCopyTwo(HttpServletResponse response,Integer type) { |
| | | public void exportCopyTwo(HttpServletResponse response, Integer type) { |
| | | LambdaQueryWrapper<CustomStorage> customStorageLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | customStorageLambdaQueryWrapper.groupBy(CustomStorage::getSupplierName, CustomStorage::getProductCategory, CustomStorage::getSpecificationModel); |
| | | List<CustomStorage> list = customStorageMapper.selectList(customStorageLambdaQueryWrapper); |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = list.stream().map(CustomStorage::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | ExcelUtil<CustomStorage> util = new ExcelUtil<CustomStorage>(CustomStorage.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, type); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | ExcelUtil<CustomStorage> util = new ExcelUtil<CustomStorage>(CustomStorage.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | reportData.put("tableData", procurementPageDtoCopyList); |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(collect)){ |
| | | return reportData; |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return reportData; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | return reportData; |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return reportData; |
| | | } |
| | | int totalIn =0; |
| | | int totalOut =0; |
| | | int currentStock =0; |
| | | int turnoverRate =0; |
| | | int totalIn = 0; |
| | | int totalOut = 0; |
| | | int currentStock = 0; |
| | | int turnoverRate = 0; |
| | | List<String> dates = new ArrayList<>(); |
| | | List<Integer> values = new ArrayList<>(); |
| | | List<String> comparisonDates = new ArrayList<>(); |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | currentStock += dto.getInboundNum().intValue() - totalInboundNum.intValue(); |
| | | values.add(currentStock); |
| | | // 计算周转率 |
| | | if(totalIn > 0){ |
| | | if (totalIn > 0) { |
| | | turnoverRate = totalOut * 100 / totalIn; |
| | | } |
| | | } |
| | |
| | | public InventoryInformationDto getReportList() { |
| | | InventoryInformationDto inventoryInformationDto = new InventoryInformationDto(); |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = this.listPage(new Page<>(1, -1), new ProcurementPageDto()); |
| | | if(CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())){ |
| | | if (CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())) { |
| | | return inventoryInformationDto; |
| | | } |
| | | // 计算总库存数量 |
| | |
| | | inventoryInformationDto.setInventoryChangeValue(inventoryChangeValue.subtract(totalInventoryValue)); |
| | | return inventoryInformationDto; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProcurementPageDto> listPageByProduction(Page page, ProcurementPageDto procurementDto) { |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProduction(page, procurementDto); |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect) |
| | | .eq(ProcurementRecordOut::getType,2); |
| | | .eq(ProcurementRecordOut::getType, 2); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | for (ProcurementPageDto dto : procurementPageDtos) { |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | @Override |
| | | public AjaxResult addCustom(List<CustomStorage> customStorage) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if(CollectionUtils.isEmpty(customStorage)){ |
| | | if (CollectionUtils.isEmpty(customStorage)) { |
| | | return AjaxResult.error("数据不能为空"); |
| | | } |
| | | customStorage.forEach(item -> { |
| | | // 查询采购入库数量 |
| | | Long aLong = customStorageMapper.selectCount(null); |
| | | item.setInboundBatches(aLong.equals(0L) ? "第1批次(自定义入库)" : "第"+ (aLong + 1) + "批次(自定义入库)" ); |
| | | item.setInboundBatches(aLong.equals(0L) ? "第1批次(自定义入库)" : "第" + (aLong + 1) + "批次(自定义入库)"); |
| | | item.setCreateBy(loginUser.getNickName()); |
| | | item.setCode(OrderUtils.countTodayByCreateTime(customStorageMapper, "")); |
| | | customStorageMapper.insert(item); |
| | |
| | | @Override |
| | | public IPage<CustomStorage> listPageByCustom(Page page, CustomStorage customStorage) { |
| | | LambdaQueryWrapper<CustomStorage> customStorageLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if(customStorage != null){ |
| | | if(!StringUtils.isEmpty(customStorage.getSupplierName())){ |
| | | if (customStorage != null) { |
| | | if (!StringUtils.isEmpty(customStorage.getSupplierName())) { |
| | | customStorageLambdaQueryWrapper.like(CustomStorage::getSupplierName, customStorage.getSupplierName()); |
| | | } |
| | | // 筛选入库时间 |
| | | if(customStorage.getTimeStr() != null){ |
| | | if (customStorage.getTimeStr() != null) { |
| | | customStorageLambdaQueryWrapper.eq(CustomStorage::getInboundDate, customStorage.getTimeStr()); |
| | | } |
| | | if(!StringUtils.isEmpty(customStorage.getProductCategory())){ |
| | | if (!StringUtils.isEmpty(customStorage.getProductCategory())) { |
| | | customStorageLambdaQueryWrapper.like(CustomStorage::getProductCategory, customStorage.getProductCategory()); |
| | | } |
| | | } |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtos.stream().map(CustomStorage::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect) |
| | | .eq(ProcurementRecordOut::getType, 3); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | for (CustomStorage dto : procurementPageDtos) { |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | // 1. 查询采购记录已入库的出库记录(按storageId分组) |
| | |
| | | List<ProcurementRecordOut> recordOutList = procurementRecordOutMapper.selectList(queryWrapper); |
| | | |
| | | // 2. 按SalesLedgerProductId分组,统计每个id对应的已出库数量总和-已出库数量 |
| | | Map<Integer, BigDecimal> storageIdToTotalOutNumMap = recordOutList.stream() |
| | | Map<Long, BigDecimal> storageIdToTotalOutNumMap = recordOutList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | ProcurementRecordOut::getSalesLedgerProductId, |
| | | Collectors.reducing( |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(CustomStorage::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return pageList; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, 3); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return pageList; |
| | | } |
| | | for (CustomStorage dto : procurementPageDtoCopyList) { |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | dto.setTotalInboundNum(BigDecimal.ZERO); |
| | | continue; |
| | |
| | | // 待出库数量 = 总数量 - 已出库数量 |
| | | dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | // 库存价值 |
| | | if(dto.getTaxInclusiveUnitPrice() != null){ |
| | | if (dto.getTaxInclusiveUnitPrice() != null) { |
| | | dto.setTaxInclusiveTotalPrice(dto.getInboundNum0().multiply(dto.getTaxInclusiveUnitPrice())); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public int updateManagementByCustom(ProcurementManagementUpdateDto procurementDto) { |
| | | CustomStorage customStorage = customStorageMapper.selectById(procurementDto.getId()); |
| | | if(customStorage == null){ |
| | | if (customStorage == null) { |
| | | throw new RuntimeException("材料库存不存在"); |
| | | } |
| | | LambdaQueryWrapper<CustomStorage> customStorageLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | CustomStorage one = new CustomStorage(); |
| | | one.setTaxInclusiveUnitPrice(procurementDto.getTaxInclusiveUnitPrice()); |
| | | one.setTaxInclusiveTotalPrice(procurementDto.getTaxInclusiveTotalPrice()); |
| | | return customStorageMapper.update(one,customStorageLambdaQueryWrapper); |
| | | return customStorageMapper.update(one, customStorageLambdaQueryWrapper); |
| | | } |
| | | |
| | | @Override |
| | |
| | | procurementRecordStorageLambdaQueryWrapper.eq(ProcurementRecordStorage::getSalesLedgerProductId, salesProductId) |
| | | .eq(ProcurementRecordStorage::getType, 2); |
| | | List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordStorageLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecordStorages)){ |
| | | if (CollectionUtils.isEmpty(procurementRecordStorages)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return procurementRecordStorages.stream() |
| | |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordStorage::getSalesLedgerProductId, detail.getId()) |
| | | .eq(ProcurementRecordStorage::getType, procurementDto.getType()); |
| | | Long aLong = procurementRecordMapper.selectCount(procurementRecordLambdaQueryWrapper); |
| | | |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(detail.getId()); |
| | | if (ObjectUtils.isNull(detail.getProductModelId())) { |
| | | detail.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | } |
| | | ProcurementRecordStorage.ProcurementRecordStorageBuilder procurementRecordBuilder = ProcurementRecordStorage.builder() |
| | | .salesLedgerProductId(detail.getId()) |
| | | .inboundBatches(aLong.equals(0L) ? "第1批次("+ procurementDto.getTypeName() +")" : "第"+ (aLong + 1) + "批次(" + procurementDto.getTypeName() + ")" ) |
| | | .inboundBatches(aLong.equals(0L) ? "第1批次(" + procurementDto.getTypeName() + ")" : "第" + (aLong + 1) + "批次(" + procurementDto.getTypeName() + ")") |
| | | .inboundNum(detail.getInboundQuantity()) |
| | | .type(procurementDto.getType()) |
| | | .warnNum(detail.getWarnNum()) |
| | |
| | | .updateTime(LocalDateTime.now()) |
| | | .updateUser(loginUser.getUserId()) |
| | | .createBy(procurementDto.getNickName()) |
| | | .productModelId(detail.getProductModelId()); |
| | | .productModelId(detail.getProductModelId()) |
| | | .qualityInspectId(ObjectUtils.isNotNull(procurementDto.getQualityInspectId()) ? procurementDto.getQualityInspectId() : 0L); |
| | | this.save(procurementRecordBuilder.build()); |
| | | // 入库成功减掉采购数量 |
| | | // LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtos.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect) |
| | | .eq(ProcurementRecordOut::getType, 1); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return procurementPageDtoIPage; |
| | | } |
| | | for (ProcurementPageDto dto : procurementPageDtos) { |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | continue; |
| | | } |
| | |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | if (CollectionUtils.isEmpty(collect)) { |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType,1); |
| | | procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, 1); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | if (CollectionUtils.isEmpty(procurementRecords)) { |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) { |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果没有相关的出库记录,跳过该条数据 |
| | | if(CollectionUtils.isEmpty(collect1)){ |
| | | if (CollectionUtils.isEmpty(collect1)) { |
| | | dto.setInboundNum0(dto.getInboundNum()); |
| | | dto.setTotalInboundNum(BigDecimal.ZERO); |
| | | continue; |
| | |
| | | // 待出库数量 = 总数量 - 已出库数量 |
| | | dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | // 库存价值 |
| | | if(dto.getUnitPrice() != null){ |
| | | if (dto.getUnitPrice() != null) { |
| | | dto.setTotalPrice(dto.getInboundNum0().multiply(dto.getUnitPrice())); |
| | | } |
| | | } |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProductModel> listPageProductionStock(Page page, ProcurementPageDto dto) { |
| | | return productModelMapper.listPageProductionStock(page, dto); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProcurementPageDto> listPageByProductProduction(Page page, ProcurementPageDto procurementDto) { |
| | | IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProductProduction(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) |
| | | .eq(ProcurementRecordOut::getType, 4); |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public boolean frozenStorageQuality(List<Integer> frozenIds) { |
| | | if (frozenIds == null || frozenIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | LambdaUpdateWrapper<ProcurementRecordStorage> storageLambdaUpdateWrapper = new LambdaUpdateWrapper<ProcurementRecordStorage>() |
| | | .set(ProcurementRecordStorage::getIsFrozen, true) |
| | | .in(ProcurementRecordStorage::getSalesLedgerProductId, frozenIds) |
| | | .eq(ProcurementRecordStorage::getIsFrozen, false); |
| | | |
| | | return update(storageLambdaUpdateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public boolean thawStorageQuality(List<Integer> thawIds) { |
| | | if (thawIds == null || thawIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | LambdaUpdateWrapper<ProcurementRecordStorage> storageLambdaUpdateWrapper = new LambdaUpdateWrapper<ProcurementRecordStorage>() |
| | | .set(ProcurementRecordStorage::getIsFrozen, false) |
| | | .in(ProcurementRecordStorage::getSalesLedgerProductId, thawIds) |
| | | .eq(ProcurementRecordStorage::getIsFrozen, true); |
| | | |
| | | return update(storageLambdaUpdateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public boolean frozenFinishedQuality(List<Integer> frozenIds) { |
| | | if (frozenIds == null || frozenIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | List<ProductModel> modelList = productModelService.list(new LambdaQueryWrapper<ProductModel>().in(ProductModel::getProductId, frozenIds)); |
| | | |
| | | List<Long> productModelIds = modelList.stream() |
| | | .map(ProductModel::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (productModelIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | LambdaUpdateWrapper<ProcurementRecordStorage> updateWrapper = new LambdaUpdateWrapper<ProcurementRecordStorage>() |
| | | .in(ProcurementRecordStorage::getProductModelId, productModelIds).set(ProcurementRecordStorage::getIsFrozen, 1); |
| | | |
| | | return update(updateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public boolean thawFinishedQuality(List<Integer> thawIds) { |
| | | if (thawIds == null || thawIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | List<ProductModel> modelList = productModelService.list(new LambdaQueryWrapper<ProductModel>().in(ProductModel::getProductId, thawIds)); |
| | | |
| | | List<Long> productModelIds = modelList.stream() |
| | | .map(ProductModel::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (productModelIds.isEmpty()) { |
| | | return true; |
| | | } |
| | | LambdaUpdateWrapper<ProcurementRecordStorage> updateWrapper = new LambdaUpdateWrapper<ProcurementRecordStorage>() |
| | | .in(ProcurementRecordStorage::getProductModelId, productModelIds).set(ProcurementRecordStorage::getIsFrozen, 0); |
| | | |
| | | return update(updateWrapper); |
| | | } |
| | | |
| | | |
| | | } |