| | |
| | | @Override |
| | | public HomeSummaryDto summaryStatistics() { |
| | | HomeSummaryDto dto = new HomeSummaryDto(); |
| | | LocalDate now = LocalDate.now(); |
| | | YearMonth currentMonth = YearMonth.from(now); |
| | | YearMonth prevMonth = currentMonth.minusMonths(1); |
| | | |
| | | LocalDateTime currentMonthEnd = currentMonth.atEndOfMonth().atTime(23, 59, 59); |
| | | LocalDateTime prevMonthEnd = prevMonth.atEndOfMonth().atTime(23, 59, 59); |
| | | |
| | | // 总工作人员 |
| | | Long currentStaff = countStaff(currentMonthEnd); |
| | | Long prevStaff = countStaff(prevMonthEnd); |
| | | Long currentStaff = 0L; |
| | | dto.setTotalStaff(currentStaff); |
| | | dto.setStaffGrowthRate(calculateMoM(currentStaff, prevStaff)); |
| | | |
| | | // 总客户数 |
| | | Long currentCustomers = countCustomers(currentMonthEnd); |
| | | Long prevCustomers = countCustomers(prevMonthEnd); |
| | | Long currentCustomers = customerMapper.selectCount(null); |
| | | dto.setTotalCustomer(currentCustomers); |
| | | dto.setCustomerGrowthRate(calculateMoM(currentCustomers, prevCustomers)); |
| | | |
| | | // 总供应商数 |
| | | Long currentSuppliers = countSuppliers(currentMonthEnd); |
| | | Long prevSuppliers = countSuppliers(prevMonthEnd); |
| | | Long currentSuppliers = supplierManageMapper.selectCount(null); |
| | | dto.setTotalSupplier(currentSuppliers); |
| | | dto.setSupplierGrowthRate(calculateMoM(currentSuppliers, prevSuppliers)); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | private Long countStaff(LocalDateTime dateTime) { |
| | | Long staffCountItem = staffOnJobMapper.selectCount(new LambdaQueryWrapper<StaffOnJob>() |
| | | .isNotNull(StaffOnJob::getStaffState) |
| | | .eq(StaffOnJob::getStaffState, 1) |
| | | .le(StaffOnJob::getCreateTime, dateTime)); |
| | | return staffCountItem; |
| | | } |
| | | |
| | | private Long countCustomers(LocalDateTime dateTime) { |
| | | return customerMapper.selectCount(new LambdaQueryWrapper<Customer>() |
| | | .le(Customer::getMaintenanceTime, dateTime.toLocalDate())); |
| | | } |
| | | |
| | | private Long countSuppliers(LocalDateTime dateTime) { |
| | | return supplierManageMapper.selectCount(new LambdaQueryWrapper<SupplierManage>() |
| | | .le(SupplierManage::getCreateTime, dateTime)); |
| | | } |
| | | |
| | | private String calculateMoM(Number current, Number prev) { |
| | | BigDecimal curVal = new BigDecimal(current.toString()); |
| | | BigDecimal prevVal = new BigDecimal(prev.toString()); |
| | | if (prevVal.compareTo(BigDecimal.ZERO) == 0) { |
| | | return curVal.compareTo(BigDecimal.ZERO) > 0 ? "100.00" : "0.00"; |
| | | } |
| | | return curVal.subtract(prevVal) |
| | | .divide(prevVal, 4, RoundingMode.HALF_UP) |
| | | .multiply(new BigDecimal("100")) |
| | | .setScale(2, RoundingMode.HALF_UP) |
| | | .toString(); |
| | | } |
| | | |
| | | @Override |
| | | public List<SupplierPurchaseRankingDto> supplierPurchaseRanking(Integer type) { |