| | |
| | | package com.ruoyi.home.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.approve.mapper.ApproveProcessMapper; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.collaborativeApproval.mapper.NoticeMapper; |
| | | import com.ruoyi.collaborativeApproval.pojo.Notice; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.device.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.device.mapper.DeviceRepairMapper; |
| | |
| | | import com.ruoyi.procurementrecord.pojo.CustomStorage; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.production.dto.ProductOrderDto; |
| | | import com.ruoyi.production.dto.ProductWorkOrderDto; |
| | | import com.ruoyi.production.dto.ProductionProductMainDto; |
| | | import com.ruoyi.production.mapper.ProductOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductionProductMainMapper; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | 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 NoticeMapper noticeMapper; |
| | | @Autowired |
| | | private ProductOrderMapper productOrderMapper; |
| | | @Autowired |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | @Autowired |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | |
| | | @Override |
| | | public HomeBusinessDto business() { |
| | |
| | | // .ge(SalesLedger::getEntryDate, startDate) |
| | | // .lt(SalesLedger::getEntryDate, endDate) |
| | | ); |
| | | BigDecimal receivableMoney = salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal receivableMoney = salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal receivableMoney = sumAmount(salesLedgers, SalesLedger::getContractAmount); |
| | | // 应付 |
| | | List<PurchaseLedger> procurementRecords = purchaseLedgerMapper.selectList(new LambdaQueryWrapper<PurchaseLedger>() |
| | | // .ge(PurchaseLedger::getEntryDate, startDate) |
| | | // .lt(PurchaseLedger::getEntryDate, endDate) |
| | | ); |
| | | BigDecimal payableMoney = procurementRecords.stream().map(PurchaseLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal payableMoney = procurementRecords.stream().map(PurchaseLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal payableMoney = sumAmount(procurementRecords, PurchaseLedger::getContractAmount); |
| | | // 预收 |
| | | List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>() |
| | | // .ge(ReceiptPayment::getReceiptPaymentDate, startDate) |
| | | // .lt(ReceiptPayment::getReceiptPaymentDate, endDate) |
| | | ); |
| | | BigDecimal advanceMoney = receiptPayments.stream().map(ReceiptPayment::getReceiptPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal advanceMoney = receiptPayments.stream().map(ReceiptPayment::getReceiptPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal advanceMoney = sumAmount(receiptPayments, ReceiptPayment::getReceiptPaymentAmount); |
| | | // 预付 |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new LambdaQueryWrapper<PaymentRegistration>() |
| | | // .ge(PaymentRegistration::getPaymentDate, startDate) |
| | | // .lt(PaymentRegistration::getPaymentDate, endDate) |
| | | ); |
| | | BigDecimal prepayMoney = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal prepayMoney = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal prepayMoney = sumAmount(paymentRegistrations, PaymentRegistration::getCurrentPaymentAmount); |
| | | StatisticsReceivablePayableDto statisticsReceivablePayableDto = new StatisticsReceivablePayableDto(); |
| | | statisticsReceivablePayableDto.setPayableMoney(payableMoney.subtract(prepayMoney)); |
| | | statisticsReceivablePayableDto.setReceivableMoney(receivableMoney.subtract(advanceMoney)); |
| | |
| | | |
| | | return statisticsReceivablePayableDto; |
| | | } |
| | | |
| | | public static <T> BigDecimal sumAmount(List<T> list, java.util.function.Function<T, BigDecimal> amountExtractor) { |
| | | return list.stream() |
| | | // 提取金额时,将null替换为BigDecimal.ZERO |
| | | .map(item -> Optional.ofNullable(amountExtractor.apply(item)).orElse(BigDecimal.ZERO)) |
| | | // 累加,初始值为0,避免空流问题 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | @Autowired |
| | | private DeviceRepairMapper deviceRepairMapper; |
| | | |
| | |
| | | // 审批协同待办 |
| | | Long aLong = approveProcessMapper.selectCount(new LambdaQueryWrapper<ApproveProcess>() |
| | | .eq(ApproveProcess::getApproveUserCurrentId, SecurityUtils.getUserId()) |
| | | .eq(ApproveProcess::getApproveDelete, 0) |
| | | .in(ApproveProcess::getApproveStatus, 0, 1, 3)); |
| | | // 设备报修待办 |
| | | Long aLong1 = deviceRepairMapper.selectCount(new LambdaQueryWrapper<DeviceRepair>() |
| | |
| | | put("deviceRepairTodo", aLong1); |
| | | }}; |
| | | } |
| | | |
| | | @Override |
| | | public Long noticesCount() { |
| | | // 查询未过期的通知数量:状态为发布且过期时间大于等于当前日期 |
| | | return noticeMapper.selectCount(new LambdaQueryWrapper<Notice>() |
| | | .eq(Notice::getStatus, 1) // 1表示发布状态 |
| | | .ge(Notice::getExpirationDate, new Date())); // 过期时间大于等于当前日期 |
| | | } |
| | | |
| | | @Override |
| | | public ProductionProgressDto productionProgress() { |
| | | ProductionProgressDto productionProgressDto = new ProductionProgressDto(); |
| | | List<ProductOrder> productOrderList = productOrderMapper.selectList(new LambdaQueryWrapper<ProductOrder>()); |
| | | List<ProductOrderDto> productOrderDtoList = new ArrayList<>(); |
| | | productOrderList.forEach(productOrder -> { |
| | | ProductOrderDto productOrderDto = productOrderMapper.productMainByOrderId(productOrder); |
| | | if (productOrderDto != null && productOrderDto.getPlanQuantity() != null && productOrderDto.getQuantity() != null) { |
| | | productOrderDto.setCompletionStatus(BigDecimal.valueOf(productOrderDto.getPlanQuantity()-productOrderDto.getQuantity()).divide(BigDecimal.valueOf(productOrderDto.getPlanQuantity()), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | productOrderDtoList.add(productOrderDto); |
| | | }); |
| | | productionProgressDto.setCompletedOrderDetails(productOrderDtoList); |
| | | // 1. 查询所有生产订单(可根据需求添加过滤条件,如排除已删除、已取消的订单) |
| | | IPage<ProductOrderDto> productOrderDtoIPage = productOrderMapper.pageProductOrder(new Page<>(1, -1), new ProductOrderDto()); |
| | | |
| | | // 2. 初始化汇总数据 |
| | | int totalCount = productOrderDtoIPage.getRecords().size(); |
| | | int completedCount = (int) productOrderDtoIPage.getRecords().stream().map(productOrderDto -> productOrderMapper.productMainByOrderId(productOrderDto)).filter(productOrderDto1 -> productOrderDto1.getQuantity() != null && productOrderDto1.getQuantity() == 0).count(); |
| | | |
| | | // 6. 赋值汇总数据 |
| | | productionProgressDto.setTotalOrderCount(totalCount); |
| | | productionProgressDto.setCompletedOrderCount(completedCount); |
| | | productionProgressDto.setUncompletedOrderCount(totalCount - completedCount); |
| | | productionProgressDto.setCompletedProgressCount(BigDecimal.valueOf(completedCount).divide(BigDecimal.valueOf(totalCount), 2, RoundingMode.HALF_UP)); |
| | | return productionProgressDto; |
| | | } |
| | | @Override |
| | | public Map<Integer, List<ProductWorkOrderDto>> workInProcessTurnover() { |
| | | List<ProductWorkOrderDto> productWorkOrderDtoList = productWorkOrderMapper.selectProductWorkOrderDtoList(); |
| | | //根据状态区分工单的各个状态 |
| | | Map<Integer, List<ProductWorkOrderDto>> productWorkOrderDtoMap = productWorkOrderDtoList.stream().collect(Collectors.groupingBy(ProductWorkOrderDto::getStatus)); |
| | | |
| | | return productWorkOrderDtoMap; |
| | | |
| | | } |
| | | } |