| | |
| | | package com.ruoyi.home.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.account.pojo.AccountExpense; |
| | | import com.ruoyi.account.pojo.AccountIncome; |
| | | import com.ruoyi.approve.mapper.ApproveProcessMapper; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.production.mapper.SalesLedgerWorkMapper; |
| | | import com.ruoyi.production.pojo.SalesLedgerWork; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.purchase.mapper.PaymentRegistrationMapper; |
| | |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | @Autowired |
| | | private SalesLedgerWorkMapper salesLedgerWorkMapper;; |
| | | |
| | | @Override |
| | | public HomeBusinessDto business() { |
| | |
| | | .filter(inspect -> inspect.getInspectType().equals(1)) |
| | | .map(QualityInspect::getQuantity) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | factoryNum= factoryNum.add(reduce1); |
| | | processNum= processNum.add(reduce1); |
| | | BigDecimal reduce2 = monthInspects.stream() |
| | | .filter(inspect -> inspect.getInspectType().equals(2)) |
| | | .map(QualityInspect::getQuantity) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | processNum = processNum.add(reduce2); |
| | | factoryNum = factoryNum.add(reduce2); |
| | | |
| | | // 构建当月统计项 |
| | | QualityStatisticsItem item = new QualityStatisticsItem(); |
| | |
| | | |
| | | return qualityProductQualifiedRateDto; |
| | | } |
| | | |
| | | @Override |
| | | public QualityStatisticsDto inventoryStatistics() { |
| | | // 获取近四个月数据(往前推三个月,共4个完整月份) |
| | | LocalDate today = LocalDate.now(); |
| | | // 定义日期格式化器(用于显示“年月”格式) |
| | | DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | |
| | | QualityStatisticsDto qualityStatisticsDto = new QualityStatisticsDto(); |
| | | List<QualityStatisticsItem> qualityStatisticsItems = new ArrayList<>(); |
| | | |
| | | BigDecimal supplierNum = new BigDecimal(0); //入库数量 |
| | | BigDecimal factoryNum = new BigDecimal(0); //出库数量 |
| | | // 循环4次,分别统计近4个月的数据(当前月、前1个月、前2个月、前3个月) |
| | | for (int i = 3; i >= 0; i--) { |
| | | // 计算当前循环对应的月份(i=0:当前月,i=1:前1个月,以此类推) |
| | | LocalDate currentMonth = today.minusMonths(i); |
| | | // 当月的开始日期(每月1号) |
| | | LocalDate monthStart = currentMonth.withDayOfMonth(1); |
| | | // 当月的结束日期(每月最后一天) |
| | | LocalDate monthEnd = currentMonth.withDayOfMonth(currentMonth.lengthOfMonth()); |
| | | |
| | | // 入库数量 |
| | | // 构建当月的查询条件(如果想一次性查全4个月数据再内存筛选,可优化为先查全再循环筛选) |
| | | LambdaQueryWrapper<ProcurementRecordStorage> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.ge(ProcurementRecordStorage::getCreateTime, monthStart) |
| | | .le(ProcurementRecordStorage::getCreateTime, monthEnd); // 筛选当月数据 |
| | | List<ProcurementRecordStorage> monthInspects = procurementRecordStorageMapper.selectList(queryWrapper); |
| | | // 出库数量 |
| | | LambdaQueryWrapper<ProcurementRecordOut> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.ge(ProcurementRecordOut::getCreateTime, monthStart) |
| | | .le(ProcurementRecordOut::getCreateTime, monthEnd); |
| | | List<ProcurementRecordOut> monthInspects1 = procurementRecordOutMapper.selectList(queryWrapper1); |
| | | BigDecimal reduce = monthInspects.stream() |
| | | .map(ProcurementRecordStorage::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | supplierNum = supplierNum.add(reduce); |
| | | BigDecimal reduce1 = monthInspects1.stream() |
| | | .map(ProcurementRecordOut::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | factoryNum= factoryNum.add(reduce1); |
| | | |
| | | // 构建当月统计项 |
| | | QualityStatisticsItem item = new QualityStatisticsItem(); |
| | | item.setDate(monthStart.format(monthFormatter)); // 日期显示为“年月”(如 2025-10) |
| | | |
| | | // 1. 供应商检验(类型0)- 合格数量 |
| | | BigDecimal supplierQualified = monthInspects.stream() |
| | | .map(ProcurementRecordStorage::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | item.setSupplierNum(supplierQualified); |
| | | |
| | | // 3. 工厂检验(类型2)- 合格数量 |
| | | BigDecimal factoryQualified = monthInspects1.stream() |
| | | .map(ProcurementRecordOut::getInboundNum) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | item.setFactoryNum(factoryQualified); |
| | | |
| | | qualityStatisticsItems.add(item); |
| | | } |
| | | // 统计近4个月总数据(所有月份汇总) |
| | | qualityStatisticsDto.setSupplierNum(supplierNum); |
| | | qualityStatisticsDto.setFactoryNum(factoryNum); |
| | | qualityStatisticsDto.setItem(qualityStatisticsItems); |
| | | |
| | | return qualityStatisticsDto; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, List<String>> productionStatistics() { |
| | | // 获取最近四个月(当前月 + 前3个月)的时间范围 |
| | | LocalDate today = LocalDate.now(); |
| | | DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); // 年月格式化器 |
| | | Map<String, List<String>> result = new HashMap<>(); |
| | | List<String> months = new ArrayList<>(); // 存储年月(如 2025-12、2025-11) |
| | | List<String> totalIncomeList = new ArrayList<>(); // 每月总收入 |
| | | List<String> totalExpenseList = new ArrayList<>(); // 每月总支出 |
| | | List<String> netIncomeList = new ArrayList<>(); // 每月净收入(收入-支出) |
| | | |
| | | // 步骤1:计算近4个月的年月列表(当前月、前1月、前2月、前3月) |
| | | List<String> targetMonths = new ArrayList<>(); |
| | | for (int i = 0; i < 4; i++) { |
| | | LocalDate currentMonth = today.minusMonths(i); |
| | | String monthStr = currentMonth.format(monthFormatter); |
| | | targetMonths.add(monthStr); |
| | | } |
| | | // 反转列表,确保顺序为「前3月 → 当前月」(可选,按需求调整顺序) |
| | | Collections.reverse(targetMonths); |
| | | |
| | | // 步骤2:一次性查询近4个月所有收入数据,按“年月”分组汇总 |
| | | LocalDate fourMonthsAgo = today.minusMonths(3).withDayOfMonth(1); // 近4个月起始日(前3月1号) |
| | | LocalDate currentMonthEnd = today.withDayOfMonth(today.lengthOfMonth()); // 当前月结束日 |
| | | ZoneId zoneId = ZoneId.of("Asia/Shanghai"); |
| | | // 查询近4个月所有收入 |
| | | List<SalesLedgerWork> allIncomes = salesLedgerWorkMapper.selectList( |
| | | Wrappers.<SalesLedgerWork>lambdaQuery() |
| | | .ge(SalesLedgerWork::getSchedulingDate, fourMonthsAgo.toString()) // 大于等于起始日 |
| | | .le(SalesLedgerWork::getSchedulingDate, currentMonthEnd.toString()) // 小于等于结束日 |
| | | ); |
| | | |
| | | // 待生产 |
| | | Map<String, BigDecimal> monthlyIncomeMap = allIncomes.stream() |
| | | .filter(income -> income.getSchedulingNum() != null && income.getStatus().equals(1)) // 过滤空金额 |
| | | .collect(Collectors.groupingBy( |
| | | income -> { |
| | | // 将输入时间(字符串)转换为LocalDate,再格式化为年月 |
| | | return income.getSchedulingDate().format(monthFormatter); |
| | | }, |
| | | Collectors.reducing(BigDecimal.ZERO, SalesLedgerWork::getSchedulingNum, BigDecimal::add) |
| | | )); |
| | | |
| | | // 生产中 |
| | | Map<String, BigDecimal> monthlyExpenseMap = allIncomes.stream() |
| | | .filter(income -> income.getSchedulingNum() != null && income.getStatus().equals(2)) // 过滤空金额 |
| | | .collect(Collectors.groupingBy( |
| | | income -> { |
| | | // 将输入时间(字符串)转换为LocalDate,再格式化为年月 |
| | | return income.getSchedulingDate().format(monthFormatter); |
| | | }, |
| | | Collectors.reducing(BigDecimal.ZERO, SalesLedgerWork::getSchedulingNum, BigDecimal::add) |
| | | )); |
| | | |
| | | // 已报工 |
| | | Map<String, BigDecimal> successIncomeMap = allIncomes.stream() |
| | | .filter(income -> income.getSchedulingNum() != null && income.getStatus().equals(3)) // 过滤空金额 |
| | | .collect(Collectors.groupingBy( |
| | | income -> { |
| | | // 将输入时间(字符串)转换为LocalDate,再格式化为年月 |
| | | return income.getSchedulingDate().format(monthFormatter); |
| | | }, |
| | | Collectors.reducing(BigDecimal.ZERO, SalesLedgerWork::getSchedulingNum, BigDecimal::add) |
| | | )); |
| | | |
| | | // 步骤4:循环4个目标月份,填充统计数据(无数据时默认为0) |
| | | for (String month : targetMonths) { |
| | | // 待生产 |
| | | BigDecimal totalIncome = monthlyIncomeMap.getOrDefault(month, BigDecimal.ZERO); |
| | | // 生产中 |
| | | BigDecimal totalExpense = monthlyExpenseMap.getOrDefault(month, BigDecimal.ZERO); |
| | | // 已报工 |
| | | BigDecimal netIncome = successIncomeMap.getOrDefault(month, BigDecimal.ZERO); |
| | | |
| | | // 填充列表 |
| | | months.add(month); |
| | | totalIncomeList.add(totalIncome.toString()); |
| | | totalExpenseList.add(totalExpense.toString()); |
| | | netIncomeList.add(netIncome.toString()); |
| | | } |
| | | |
| | | // 组装结果 |
| | | result.put("days", months); // 年月(如 ["2025-09", "2025-10", "2025-11", "2025-12"]) |
| | | result.put("totalIncome", totalIncomeList); // 待生产 |
| | | result.put("totalExpense", totalExpenseList); // 生产中 |
| | | result.put("netIncome", netIncomeList); // 已报工 |
| | | |
| | | return result; |
| | | } |
| | | } |