| | |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut; |
| | | import com.ruoyi.procurementrecord.service.ProcurementRecordService; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void export(HttpServletResponse response) { |
| | | List<ProcurementPageDto> list =procurementRecordMapper.list(); |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = list.stream().map(ProcurementPageDto::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class); |
| | | util.exportExcel(response, list, "入库台账"); |
| | | return; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class); |
| | | util.exportExcel(response, list, "入库台账"); |
| | | return; |
| | | } |
| | | for (ProcurementPageDto dto : list) { |
| | | // 根据采购台账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)); |
| | | } |
| | | ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class); |
| | | util.exportExcel(response, list, "入库台账"); |
| | | } |
| | | |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public int updateManagement(ProcurementManagementUpdateDto procurementDto) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | SysUser sysUser = sysUserMapper.selectUserById(procurementDto.getCreateUser()); |
| | | 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"; |
| | | ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId()); |
| | | procurementRecordStorageById.setCreateBy(sysUser.getNickName()); |
| | | procurementRecordStorageById.setCreateUser(sysUser.getUserId()); |
| | | procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr,df)); |
| | | procurementRecordStorageById.setUpdateUser(loginUser.getUserId()); |
| | | procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr,df)); |
| | | procurementRecordMapper.updateById(procurementRecordStorageById); |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public void exportCopy(HttpServletResponse response) { |
| | | List<ProcurementPageDtoCopy> list =procurementRecordMapper.listCopy(); |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = list.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper); |
| | | if(CollectionUtils.isEmpty( procurementRecords)){ |
| | | ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | return; |
| | | } |
| | | for (ProcurementPageDtoCopy dto : list) { |
| | | // 根据采购台账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)); |
| | | } |
| | | ExcelUtil<ProcurementPageDtoCopy> util = new ExcelUtil<ProcurementPageDtoCopy>(ProcurementPageDtoCopy.class); |
| | | util.exportExcel(response, list, "库存管理"); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getReportList(Page page, ProcurementPageDto procurementDto) { |
| | | // 构建报表数据结构 |
| | | Map<String, Object> reportData = new HashMap<>(); |
| | | // 2. 构建图表数据 |
| | | Map<String, Object> chartData = new HashMap<>(); |
| | | |
| | | IPage<ProcurementPageDtoCopy> procurementPageDtoCopyIPage = procurementRecordMapper.listPageCopy(page, procurementDto); |
| | | List<ProcurementPageDtoCopy> procurementPageDtoCopyList = procurementPageDtoCopyIPage.getRecords(); |
| | | // 计算待入库数量 |
| | | reportData.put("tableData", procurementPageDtoCopyList); |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | 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; |
| | | } |
| | | 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<>(); |
| | | List<Integer> inValues = new ArrayList<>(); |
| | | List<Integer> outValues = new ArrayList<>(); |
| | | // 定义日期格式化器,指定为yyyy-MM-dd格式 |
| | | DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE; |
| | | for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) { |
| | | dates.add(dto.getCreateTime().format(dateFormatter)); |
| | | comparisonDates.add(dto.getCreateTime().format(dateFormatter)); |
| | | |
| | | // 根据采购台账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)); |
| | | |
| | | // 计算总入库数量 |
| | | totalIn += dto.getInboundNum().intValue(); |
| | | inValues.add(totalIn); |
| | | // 计算总出库数量 |
| | | totalOut += totalInboundNum.intValue(); |
| | | outValues.add(totalOut); |
| | | // 计算当前库存 |
| | | currentStock += dto.getInboundNum().intValue() - totalInboundNum.intValue(); |
| | | values.add(currentStock); |
| | | // 计算周转率 |
| | | if(totalIn > 0){ |
| | | turnoverRate = totalOut * 100 / totalIn; |
| | | } |
| | | } |
| | | |
| | | |
| | | // 1. 构建汇总数据 |
| | | Map<String, Object> summary = new HashMap<>(); |
| | | summary.put("totalIn", totalIn); // 总入库量,实际应从数据计算 |
| | | summary.put("totalOut", totalOut); // 总出库量,实际应从数据计算 |
| | | summary.put("currentStock", currentStock); // 当前库存量,实际应从数据计算 |
| | | summary.put("turnoverRate", turnoverRate); // 周转率,实际应从数据计算 |
| | | reportData.put("summary", summary); |
| | | |
| | | // 2. 构建图表数据 |
| | | // Map<String, Object> chartData = new HashMap<>(); |
| | | // List<String> dates = Arrays.asList("2025-09-15", "2025-09-16", "2025-09-17", "2025-09-18", "2025-09-19"); |
| | | // List<Integer> values = Arrays.asList(300, 350, 400, 380, 420); |
| | | |
| | | chartData.put("dates", dates); |
| | | chartData.put("values", values); |
| | | chartData.put("comparisonDates", comparisonDates); // 实际应从数据计算 |
| | | chartData.put("inValues", inValues); // 实际应从数据计算 |
| | | chartData.put("outValues", outValues); // 实际应从数据计算 |
| | | reportData.put("chartData", chartData); |
| | | |
| | | // 3. 设置表格数据 |
| | | reportData.put("tableData", procurementPageDtoCopyList); |
| | | |
| | | return reportData; |
| | | } |
| | | |
| | | @Override |
| | |
| | | .createUser(loginUser.getUserId()) |
| | | .updateTime(LocalDateTime.now()) |
| | | .updateUser(loginUser.getUserId()) |
| | | .tenantId(loginUser.getTenantId()) |
| | | .createBy(procurementDto.getNickName()); |
| | | this.save(procurementRecordBuilder.build()); |
| | | // 入库成功减掉采购数量 |
| | |
| | | return procurementPageDtoIPage; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProcurementPageDtoCopy> listPageCopy(Page page, ProcurementPageDto procurementDto) { |
| | | IPage<ProcurementPageDtoCopy> procurementPageDtoCopyIPage = procurementRecordMapper.listPageCopy(page, procurementDto); |
| | | List<ProcurementPageDtoCopy> procurementPageDtoCopyList = procurementPageDtoCopyIPage.getRecords(); |
| | | // 计算待入库数量 |
| | | // 查询采购记录已入库数量 |
| | | List<Integer> collect = procurementPageDtoCopyList.stream().map(ProcurementPageDtoCopy::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty( collect)){ |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect); |
| | | 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()); |
| | | continue; |
| | | } |
| | | |
| | | // 计算已出库数量总和,并设置待出库数量 |
| | | BigDecimal totalInboundNum = collect1.stream() |
| | | .map(ProcurementRecordOut::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 待出库数量 = 总数量 - 已出库数量 |
| | | dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum)); |
| | | } |
| | | return procurementPageDtoCopyIPage; |
| | | } |
| | | |
| | | } |