| | |
| | | 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.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper; |
| | | import com.ruoyi.procurementrecord.pojo.CustomStorage; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | 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; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | private final ProcurementRecordOutMapper procurementRecordOutMapper; |
| | | |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private final StockUtils stockUtils; |
| | | private final ProductModelMapper productModelMapper; |
| | | |
| | | @Override |
| | | public List<ProcurementDto> listProcurementBySalesLedgerId(ProcurementDto procurementDto) { |
| | |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | // LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | // procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, 2); |
| | | // List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | // if(CollectionUtils.isEmpty(procurementRecords)){ |
| | | // return procurementPageDtoCopyIPage; |
| | | // } |
| | | // for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) { |
| | | // // 根据采购台账ID筛选对应的出库记录 |
| | | // List<ProcurementRecordOut> collect1 = procurementRecords.stream() |
| | | // .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId())) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // // 如果没有相关的出库记录,跳过该条数据 |
| | | // if(CollectionUtils.isEmpty(collect1)){ |
| | | // dto.setInboundNum0(dto.getInboundNum()); |
| | | // dto.setTotalInboundNum(BigDecimal.ZERO); |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 计算已出库数量总和,并设置待出库数量 |
| | | // BigDecimal totalInboundNum = collect1.stream() |
| | | // .map(ProcurementRecordOut::getInboundNum) |
| | | // .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // // 出库数量 = 总数量 - 待出库数量 |
| | | // dto.setTotalInboundNum(totalInboundNum); |
| | | // // 待出库数量 = 总数量 - 已出库数量 |
| | | // dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | // // 库存价值 |
| | | // if(dto.getUnitPrice() != null){ |
| | | // dto.setTotalPrice(dto.getTotalInboundNum().multiply(dto.getUnitPrice())); |
| | | // } |
| | | // } |
| | | // 1. 查询采购记录已入库的出库记录(按storageId分组) |
| | | LambdaQueryWrapper<ProcurementRecordOut> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | |
| | | Integer salesLedgerProductId = Integer.valueOf(Math.toIntExact(dto.getSalesLedgerProductId())); |
| | | // 获取当前salesLedgerProductId对应的已出库总数(默认0) |
| | | BigDecimal totalInboundNum = storageIdToTotalOutNumMap.getOrDefault(salesLedgerProductId, BigDecimal.ZERO); |
| | | |
| | | // 已出库数量 |
| | | dto.setTotalInboundNum(totalInboundNum); |
| | | // 待出库数量 = 总数量 - 已出库数量(总数量空值则默认0) |
| | | // BigDecimal totalNum = dto.getInboundNum() == null ? BigDecimal.ZERO : dto.getInboundNum(); |
| | | BigDecimal totalNum = storageIdToTotalintNumMap.getOrDefault(salesLedgerProductId, BigDecimal.ZERO); |
| | | dto.setInboundNum(totalNum); |
| | | dto.setInboundNum0(totalNum.subtract(totalInboundNum)); |
| | | // 已出库数量 |
| | | dto.setTotalInboundNum(totalInboundNum); |
| | | |
| | | // 库存价值 = 已出库数量 * 单价(单价空值则默认0) |
| | | BigDecimal unitPrice = dto.getUnitPrice() == null ? BigDecimal.ZERO : dto.getUnitPrice(); |
| | | dto.setTotalPrice(totalInboundNum.multiply(unitPrice)); |
| | |
| | | .createUser(loginUser.getUserId()) |
| | | .updateTime(LocalDateTime.now()) |
| | | .updateUser(loginUser.getUserId()) |
| | | .createBy(procurementDto.getNickName()); |
| | | .createBy(procurementDto.getNickName()) |
| | | .productModelId(detail.getProductModelId()); |
| | | this.save(procurementRecordBuilder.build()); |
| | | // 入库成功减掉采购数量 |
| | | // LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | @Override |
| | | public IPage<ProductModel> listPageProductionStock(Page page) { |
| | | ProductModel productModel = new ProductModel(); |
| | | IPage<ProductModel> iPage = productModelMapper.listPageProductModel(page, productModel); |
| | | iPage.getRecords().forEach(item -> { |
| | | item.setInboundNum(stockUtils.getStockQuantity(item.getId()).get("inboundNum")); |
| | | item.setOutboundNum(stockUtils.getStockQuantity(item.getId()).get("outboundNum")); |
| | | item.setStockQuantity(stockUtils.getStockQuantity(item.getId()).get("stockQuantity")); |
| | | }); |
| | | return iPage; |
| | | } |
| | | |
| | | } |