| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | |
| | | String startTime = query.getStartTime(); |
| | | String endTime = query.getEndTime(); |
| | | if (startTime == null || endTime == null) { |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | if (!StringUtils.hasLength(startTime) || !StringUtils.hasLength(endTime)) { |
| | | if(Objects.isNull(query.getType())){ |
| | | return R.fail("请选择时间"); |
| | | } |
| | | switch (query.getType()){ |
| | | case 1: |
| | | startTime = DateUtils.getYearDate(new Date()).get("first").toString(); |
| | | endTime = DateUtils.getYearDate(new Date()).get("last").toString(); |
| | | Date startDate = DateUtils.getYearDate(new Date()).get("first"); |
| | | Date endDate = DateUtils.getYearDate(new Date()).get("last"); |
| | | startTime = format.format(startDate); |
| | | endTime = format.format(endDate); |
| | | break; |
| | | case 2: |
| | | startTime = DateUtils.getMonthDate(new Date()).get("first").toString(); |
| | | endTime = DateUtils.getMonthDate(new Date()).get("last").toString(); |
| | | Date startDate1 = DateUtils.getMonthDate(new Date()).get("first"); |
| | | Date endDate1 = DateUtils.getMonthDate(new Date()).get("last"); |
| | | startTime = format.format(startDate1); |
| | | endTime = format.format(endDate1); |
| | | break; |
| | | } |
| | | }else { |
| | |
| | | List<YcFinancialManagement> lastMonth = new ArrayList<>(); |
| | | List<YcFinancialManagement> lastYearMonth = new ArrayList<>(); |
| | | // 如果选择的是本月 |
| | | if(query.getType() == 2){ |
| | | if(Objects.nonNull(query.getType()) && query.getType() == 2){ |
| | | // 获取上个月的数据 |
| | | LocalDateTime localDateTime = DateUtils.dateToLocalDateTime(new Date()).minusMonths(1); |
| | | Date date = DateUtils.localDateTimeToDate(localDateTime); |
| | | startTime = DateUtils.getMonthDate(date).get("first").toString(); |
| | | endTime = DateUtils.getMonthDate(date).get("last").toString(); |
| | | |
| | | Date monthStartDate1 = DateUtils.getMonthDate(date).get("first"); |
| | | Date monthEndDate1 = DateUtils.getMonthDate(date).get("last"); |
| | | |
| | | startTime = format.format(monthStartDate1); |
| | | endTime = format.format(monthEndDate1); |
| | | lastMonth = ycFinancialManagementService.list(Wrappers.lambdaQuery(YcFinancialManagement.class) |
| | | .between(YcFinancialManagement::getPayTime, startTime, endTime)); |
| | | // 获取去年本月的数据 |
| | | LocalDateTime localDateTimeYear = DateUtils.dateToLocalDateTime(new Date()).minusYears(1); |
| | | Date dateYear = DateUtils.localDateTimeToDate(localDateTimeYear); |
| | | startTime = DateUtils.getMonthDate(dateYear).get("first").toString(); |
| | | endTime = DateUtils.getMonthDate(dateYear).get("last").toString(); |
| | | |
| | | Date monthStartDate2 = DateUtils.getMonthDate(dateYear).get("first"); |
| | | Date monthEndDate2 = DateUtils.getMonthDate(dateYear).get("last"); |
| | | |
| | | startTime = format.format(monthStartDate2); |
| | | endTime = format.format(monthEndDate2); |
| | | lastYearMonth = ycFinancialManagementService.list(Wrappers.lambdaQuery(YcFinancialManagement.class) |
| | | .between(YcFinancialManagement::getPayTime, startTime, endTime)); |
| | | |
| | |
| | | // 环比 |
| | | BigDecimal lastMonthMoney = lastMonth.stream().filter(item -> item.getRevenueType() == 1).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal subtract = incomeSum.subtract(lastMonthMoney); |
| | | topDataStatisticsVO.setChain(subtract.divide(incomeSum, 2, RoundingMode.HALF_UP)); |
| | | if(lastMonthMoney.compareTo(BigDecimal.ZERO) == 0){ |
| | | topDataStatisticsVO.setChain(subtract.multiply(new BigDecimal(100))); |
| | | }else { |
| | | topDataStatisticsVO.setChain(subtract.divide(lastMonthMoney, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100))); |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(lastYearMonth)){ |
| | | // 同比 |
| | | BigDecimal lastYearMonthMoney = lastYearMonth.stream().filter(item -> item.getRevenueType() == 1).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal subtract = incomeSum.subtract(lastYearMonthMoney); |
| | | topDataStatisticsVO.setProportion(subtract.divide(incomeSum, 2, RoundingMode.HALF_UP)); |
| | | if(lastYearMonthMoney.compareTo(BigDecimal.ZERO) == 0){ |
| | | topDataStatisticsVO.setProportion(subtract.multiply(new BigDecimal(100))); |
| | | }else { |
| | | topDataStatisticsVO.setProportion(subtract.divide(lastYearMonthMoney, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100))); |
| | | } |
| | | } |
| | | |
| | | topDataStatisticsVOList.add(topDataStatisticsVO); |
| | |
| | | // 环比 |
| | | BigDecimal lastMonthMoney = lastMonth.stream().filter(item -> item.getRevenueType() == 2).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal subtract = expensesSum.subtract(lastMonthMoney); |
| | | topDataStatisticsVO.setChain(subtract.divide(expensesSum, 2, RoundingMode.HALF_UP).negate()); |
| | | if(lastMonthMoney.compareTo(BigDecimal.ZERO) == 0){ |
| | | topDataStatisticsVO.setChain(subtract.multiply(new BigDecimal(100))); |
| | | }else { |
| | | topDataStatisticsVO.setChain(subtract.divide(lastMonthMoney, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100))); |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(lastYearMonth)){ |
| | | // 同比 |
| | | BigDecimal lastYearMonthMoney = lastYearMonth.stream().filter(item -> item.getRevenueType() == 2).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal subtract = expensesSum.subtract(lastYearMonthMoney); |
| | | topDataStatisticsVO.setProportion(subtract.divide(expensesSum, 2, RoundingMode.HALF_UP).negate()); |
| | | if(lastYearMonthMoney.compareTo(BigDecimal.ZERO) == 0){ |
| | | topDataStatisticsVO.setProportion(subtract.multiply(new BigDecimal(100))); |
| | | }else { |
| | | topDataStatisticsVO.setProportion(subtract.divide(lastYearMonthMoney, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100))); |
| | | } |
| | | } |
| | | topDataStatisticsVOList.add(topDataStatisticsVO); |
| | | |
| | |
| | | topDataStatisticsVO = new TopDataStatisticsVO(); |
| | | topDataStatisticsVO.setType(3); |
| | | topDataStatisticsVO.setAmount(profitSum); |
| | | if(!CollectionUtils.isEmpty(lastMonth) && !CollectionUtils.isEmpty(lastYearMonth)){ |
| | | if(!CollectionUtils.isEmpty(lastMonth) || !CollectionUtils.isEmpty(lastYearMonth)){ |
| | | // 环比 |
| | | BigDecimal lastMonthMoneyIncome = lastMonth.stream().filter(item -> item.getRevenueType() == 1).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal lastMonthMoneyExpenses = lastMonth.stream().filter(item -> item.getRevenueType() == 2).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal monthProfitSum = lastMonthMoneyIncome.subtract(lastMonthMoneyExpenses); |
| | | BigDecimal chain = profitSum.subtract(monthProfitSum).divide(profitSum, 2, RoundingMode.HALF_UP); |
| | | BigDecimal chain; |
| | | if(monthProfitSum.compareTo(BigDecimal.ZERO) == 0){ |
| | | chain = profitSum.subtract(monthProfitSum).multiply(new BigDecimal(100)); |
| | | }else { |
| | | chain = profitSum.subtract(monthProfitSum).divide(monthProfitSum, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
| | | } |
| | | topDataStatisticsVO.setChain(chain); |
| | | // 同比 |
| | | BigDecimal lastYearMonthMoneyIncome = lastYearMonth.stream().filter(item -> item.getRevenueType() == 1).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal lastYearMonthMoneyExpenses = lastYearMonth.stream().filter(item -> item.getRevenueType() == 2).map(YcFinancialManagement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal yearMonthProfitSum = lastYearMonthMoneyIncome.subtract(lastYearMonthMoneyExpenses); |
| | | BigDecimal proportion = profitSum.subtract(yearMonthProfitSum).divide(profitSum, 2, RoundingMode.HALF_UP); |
| | | BigDecimal proportion; |
| | | if(yearMonthProfitSum.compareTo(BigDecimal.ZERO) == 0){ |
| | | proportion = profitSum.subtract(yearMonthProfitSum).multiply(new BigDecimal(100)); |
| | | }else { |
| | | proportion = profitSum.subtract(yearMonthProfitSum).divide(yearMonthProfitSum, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
| | | } |
| | | topDataStatisticsVO.setProportion(proportion); |
| | | |
| | | } |
| | |
| | | public R<ExpensesIncomeStatisticsVO> expensesIncomeStatistics(@RequestBody DataStatisticsQuery query) { |
| | | String startTime = query.getStartTime(); |
| | | String endTime = query.getEndTime(); |
| | | if (startTime == null || endTime == null) { |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | if (!StringUtils.hasLength(startTime) || !StringUtils.hasLength(endTime)) { |
| | | if(Objects.isNull(query.getType())){ |
| | | return R.fail("请选择时间"); |
| | | } |
| | | switch (query.getType()){ |
| | | case 1: |
| | | startTime = DateUtils.getYearDate(new Date()).get("first").toString(); |
| | | endTime = DateUtils.getYearDate(new Date()).get("last").toString(); |
| | | Date startDate = DateUtils.getYearDate(new Date()).get("first"); |
| | | Date endDate = DateUtils.getYearDate(new Date()).get("last"); |
| | | startTime = format.format(startDate); |
| | | endTime = format.format(endDate); |
| | | break; |
| | | case 2: |
| | | startTime = DateUtils.getMonthDate(new Date()).get("first").toString(); |
| | | endTime = DateUtils.getMonthDate(new Date()).get("last").toString(); |
| | | Date startDate1 = DateUtils.getMonthDate(new Date()).get("first"); |
| | | Date endDate1 = DateUtils.getMonthDate(new Date()).get("last"); |
| | | startTime = format.format(startDate1); |
| | | endTime = format.format(endDate1); |
| | | break; |
| | | } |
| | | } |