| | |
| | | /** |
| | | * 查询报表数据 |
| | | * |
| | | * @param param |
| | | * @author sgj |
| | | * @date 2025/12/19 |
| | | * @param param |
| | | |
| | | */ |
| | | public List<SuperInventoryReportData> listSuperInventoryReportData(SuperInventoryReportParam param) { |
| | | //1.获取查询得起止时间,如果没有则,默认截止时间为当天,起始时间为30天前 |
| | |
| | | //默认库区编码 |
| | | String deptId = ContextUtil.subDeptId(null); |
| | | param.setCompanyId(companyId); |
| | | |
| | | //region 查询条件收储公司和所属库区处理 |
| | | if (StringUtils.isNotEmpty(param.getDeptId()) && StringUtils.isNotEmpty(param.getCustomerId())) { |
| | | String substring = param.getDeptId().substring(0, (param.getDeptId().length() - 3)); |
| | | if (!substring.equals(param.getCustomerId())) { |
| | | return new ArrayList<SuperInventoryReportData>(); |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(param.getDeptId())) { |
| | | param.setDeptId(param.getCustomerId()); |
| | | } |
| | | //收储公司,所属库区查询均为空,则查询默认库区 |
| | | if (StringUtils.isEmpty(param.getCustomerId()) && StringUtils.isEmpty(param.getDeptId())) { |
| | | param.setDeptId(deptId); |
| | | } |
| | | //endregion |
| | | |
| | | //region 初始化需要范围的数据 |
| | | Map<String, SuperInventoryReportData> resultMap = new HashMap<>(); |
| | | Map<String, SuperInventoryReportData> columsMap = new HashMap<>(); |
| | | |
| | | //查询当前用户下属的所有库区 |
| | | List<Dept> deptList = coreDeptService.getDeptData(); |
| | | if (null == deptList || deptList.isEmpty()) { |
| | |
| | | } |
| | | |
| | | //预加载所有部门下的仓库信息,减少重复查询 |
| | | Map<String, Dept> deptCache = new HashMap<>(); |
| | | Map<String, List<Depot>> deptDepotsMap = new HashMap<>(); |
| | | Map<String, Company> companyCache = new HashMap<>(); |
| | | |
| | | for (Dept dept : deptList) { |
| | | deptCache.put(dept.getId(), dept); |
| | | //获取库区下所有仓库 |
| | | List<Depot> depotList = depotService.getData(companyId, dept.getId(), true); |
| | | if (null == depotList || depotList.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | |
| | | //构建结果数据 |
| | | //构建结果数据映射map |
| | | for (Map.Entry<String, List<Depot>> entry : deptDepotsMap.entrySet()) { |
| | | String deptIdKey = entry.getKey(); |
| | | Company company = companyCache.get(deptIdKey.substring(0, deptIdKey.length() - 3)); |
| | | |
| | | Dept dept = deptCache.get(deptIdKey); |
| | | for (Depot depot : entry.getValue()) { |
| | | //库区编码+仓库编码组成唯一键 |
| | | String key = deptIdKey + "_" + depot.getId(); |
| | | SuperInventoryReportData data = new SuperInventoryReportData(); |
| | | |
| | | data.setCustomerName(Optional.ofNullable(company) |
| | | data.setCustomerId(Optional.ofNullable(company) |
| | | .map(Company::getId) |
| | | .orElse("-")); |
| | | data.setCustomerName(Optional.ofNullable(company) |
| | | .map(Company::getDwmc) |
| | | .orElse("-")); |
| | | data.setDeptId(deptIdKey); |
| | | data.setDeptName(dept.getKqmc()); |
| | | data.setDepotId(depot.getId()); |
| | | resultMap.put(key, data); |
| | | data.setDepotName(depot.getName()); |
| | | columsMap.put(key, data); |
| | | } |
| | | } |
| | | //endregion |
| | | |
| | | if (resultMap.isEmpty()) { |
| | | if (columsMap.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | |
| | | .collect(Collectors.groupingBy(record -> record.getDeptId() + "_" + record.getDepotId())); |
| | | |
| | | //4. 根据库区、仓库为唯一键,组装报表数据 |
| | | List<SuperInventoryReportData> result = new ArrayList<>(); |
| | | Date todayZero = DateUtil.getCurZero(new Date()); |
| | | boolean isEndDateBeforeToday = param.getEnd().before(todayZero); |
| | | |
| | | for (SuperInventoryReportData data : resultMap.values()) { |
| | | for (SuperInventoryReportData data : columsMap.values()) { |
| | | String dataKey = data.getDeptId() + "_" + data.getDepotId(); |
| | | |
| | | //获取库存数据 |
| | |
| | | data.setChangeOutWeight(sumStockChangeOut); |
| | | data.setLossWeight(sumLossOver); |
| | | data.setFinalWeight(finalWeight); |
| | | result.add(data); |
| | | } |
| | | |
| | | return new ArrayList<>(resultMap.values()); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | private List<DepotStore> queryDepotStores(SuperInventoryReportParam param) { |
| | | QueryWrapper<DepotStore> depotStoreQueryWrapper = new QueryWrapper<>(); |
| | | depotStoreQueryWrapper.eq("company_id", param.getCompanyId()); |
| | | depotStoreQueryWrapper.eq("dept_id", param.getDeptId()); |
| | | if (StringUtils.isNotBlank(param.getDeptId())) { |
| | | depotStoreQueryWrapper.likeRight("dept_id", param.getDeptId()); |
| | | } |
| | | depotStoreQueryWrapper.between("create_time", param.getStart(), param.getEnd()); |
| | | depotStoreQueryWrapper.orderByAsc("create_time"); |
| | | return depotStoreMapper.selectList(depotStoreQueryWrapper); |
| | |
| | | private List<InoutRecord> queryInoutRecords(SuperInventoryReportParam param) { |
| | | QueryWrapper<InoutRecord> inoutRecordQueryWrapper = new QueryWrapper<>(); |
| | | inoutRecordQueryWrapper.eq("company_id", param.getCompanyId()); |
| | | inoutRecordQueryWrapper.eq("dept_id", param.getDeptId()); |
| | | if (StringUtils.isNotBlank(param.getDeptId())) { |
| | | inoutRecordQueryWrapper.likeRight("dept_id", param.getDeptId()); |
| | | } |
| | | inoutRecordQueryWrapper.between("create_time", param.getStart(), param.getEnd()); |
| | | inoutRecordQueryWrapper.orderByAsc("create_time"); |
| | | return inoutRecordMapper.selectList(inoutRecordQueryWrapper); |
| | |
| | | private List<InoutStockChange> queryInoutStockChanges(SuperInventoryReportParam param) { |
| | | QueryWrapper<InoutStockChange> inoutStockChangeQueryWrapper = new QueryWrapper<>(); |
| | | inoutStockChangeQueryWrapper.eq("company_id", param.getCompanyId()); |
| | | inoutStockChangeQueryWrapper.eq("dept_id", param.getDeptId()); |
| | | if (StringUtils.isNotBlank(param.getDeptId())) { |
| | | inoutStockChangeQueryWrapper.likeRight("dept_id", param.getDeptId()); |
| | | } |
| | | inoutStockChangeQueryWrapper.between("create_time", param.getStart(), param.getEnd()); |
| | | inoutStockChangeQueryWrapper.orderByAsc("create_time"); |
| | | return inoutStockChangeMapper.selectList(inoutStockChangeQueryWrapper); |
| | |
| | | private List<InoutLossOver> queryInoutLossOvers(SuperInventoryReportParam param) { |
| | | QueryWrapper<InoutLossOver> inoutLossOverQueryWrapper = new QueryWrapper<>(); |
| | | inoutLossOverQueryWrapper.eq("company_id", param.getCompanyId()); |
| | | inoutLossOverQueryWrapper.eq("dept_id", param.getDeptId()); |
| | | if (StringUtils.isNotBlank(param.getDeptId())) { |
| | | inoutLossOverQueryWrapper.likeRight("dept_id", param.getDeptId()); |
| | | } |
| | | inoutLossOverQueryWrapper.between("create_time", param.getStart(), param.getEnd()); |
| | | inoutLossOverQueryWrapper.orderByAsc("create_time"); |
| | | return inoutLossOverMapper.selectList(inoutLossOverQueryWrapper); |