| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.dsh.course.feignClient.account.*; |
| | | import com.dsh.course.feignClient.account.model.CityManager; |
| | | import com.dsh.course.feignClient.account.model.QueryDataFee; |
| | | import com.dsh.course.feignClient.account.model.TAppUser; |
| | | import com.dsh.course.feignClient.account.model.VipPayment; |
| | | import com.dsh.course.feignClient.account.model.*; |
| | | import com.dsh.course.feignClient.activity.PointMercharsClient; |
| | | import com.dsh.course.feignClient.competition.CompetitionClient; |
| | | import com.dsh.course.feignClient.competition.model.Competition; |
| | |
| | | */ |
| | | @RequestMapping(value = "/getIncomeData") |
| | | @ResponseBody |
| | | public Object getIncomeData(Integer type) { |
| | | public Object getIncomeData(Integer operatorId,Integer storeId) { |
| | | // 充值记录查询query |
| | | RechargeRecordsQuery rechargeRecordsQuery = new RechargeRecordsQuery(); |
| | | // 报名课程查询query |
| | |
| | | // 场地预约记录查询query |
| | | SiteBookingQuery siteBookingQuery = new SiteBookingQuery(); |
| | | Integer roleType = UserExt.getUser().getObjectType(); |
| | | rechargeRecordsQuery.setInsertType(roleType); |
| | | query.setInsertType(roleType); |
| | | competitionQuery.setInsertType(roleType); |
| | | incomeQuery.setInsertType(roleType); |
| | | incomeQuery.setInsertType(roleType); |
| | | |
| | | IncomeVO incomeVO = new IncomeVO(); |
| | | List<IncomeVO> incomeVOS = new ArrayList<>(); |
| | | // 会员支付记录 |
| | |
| | | } |
| | | // 充值记录 |
| | | List<RechargeRecordsVO> rechargeRecordsVOS = financeClient.rechargeList(rechargeRecordsQuery); |
| | | List<RechargeRecords> rechargeRecords = financeClient.rechargeList1(rechargeRecordsQuery); |
| | | for (RechargeRecordsVO rechargeRecordsVO : rechargeRecordsVOS) { |
| | | IncomeVO temp = new IncomeVO(); |
| | | temp.setInsertTime(rechargeRecordsVO.getInsertTime()); |
| | |
| | | // 累加到总金额 |
| | | totalAmount1 = totalAmount1.add(total); |
| | | |
| | | Date insertTime = incomeVO1.getInsertTime(); // 假设有一个方法用于获取 insertTime |
| | | BigDecimal amount1 = incomeVO1.getAmount(); // 假设有一个方法用于获取 amount |
| | | Date insertTime = incomeVO1.getInsertTime(); |
| | | BigDecimal amount1 = incomeVO1.getAmount(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(insertTime); |
| | | int year = calendar.get(Calendar.YEAR); // 获取年份 |
| | |
| | | Collections.sort(sortedYears); |
| | | // 创建一个新的 IncomeVO 列表,包含按年份累计的 amount |
| | | List<Object> resultIncomeVOS = new ArrayList<>(); |
| | | // 循环遍历2023年到2028年的年份 |
| | | for (int year = 2023; year <= 2028; year++) { |
| | | // 当前年往前推十年 |
| | | List<Integer> integers1 = new ArrayList<>(); |
| | | int years = DateUtil.year(new Date()); |
| | | for (int i = 0; i < 10; i++) { |
| | | integers1.add(years-i); |
| | | } |
| | | for (int year = integers1.get(0); year >= integers1.get(integers1.size()-1); year++) { |
| | | BigDecimal totalAmount = yearToTotalAmountMap.getOrDefault(year, BigDecimal.ZERO); |
| | | // 创建一个新的 IncomeVO 对象,并设置年份和累计金额 |
| | | IncomeVO resultIncomeVO = new IncomeVO(); |
| | |
| | | int currentMonth = currentDate.getMonthValue(); |
| | | // 初始化一个长度为当前月份的天数的列表,并将每一天的金额初始化为零 |
| | | int daysInCurrentMonth = currentDate.lengthOfMonth(); |
| | | List<BigDecimal> weekAmount = new ArrayList<>(daysInCurrentMonth); |
| | | for (int i = 0; i < daysInCurrentMonth; i++) { |
| | | weekAmount.add(BigDecimal.ZERO); |
| | | } |
| | | List<BigDecimal> weekAmount = new ArrayList<>(); |
| | | |
| | | // 获取最近四周 |
| | | LocalDateTime minNow = LocalDateTime.now().with(LocalTime.MIN); |
| | | LocalDateTime maxNow = LocalDateTime.now().with(LocalTime.MAX); |
| | | // 周度数据 |
| | | LocalDateTime week1Start = minNow.minusDays(6); |
| | | LocalDateTime week1End = maxNow; |
| | | |
| | | LocalDateTime week2Start = minNow.minusDays(13); |
| | | LocalDateTime week2End = minNow.minusDays(7); |
| | | |
| | | LocalDateTime week3Start = minNow.minusDays(20); |
| | | LocalDateTime week3End = minNow.minusDays(14); |
| | | |
| | | LocalDateTime week4Start = minNow.minusDays(27); |
| | | LocalDateTime week4End = minNow.minusDays(21); |
| | | // 用于存放四个周的数据 |
| | | List<Object> objects1 = new ArrayList<>(); |
| | | // 计算每个周的amount总和 |
| | | BigDecimal tAmount1 = BigDecimal.ZERO; |
| | | BigDecimal tAmount2 = BigDecimal.ZERO; |
| | | BigDecimal tAmount3 = BigDecimal.ZERO; |
| | | BigDecimal tAmount4 = BigDecimal.ZERO; |
| | | for (IncomeVO incomeVO1 : incomeVOS) { |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String string = dateFormat.format(incomeVO1.getInsertTime()); |
| | | LocalDate insertDate = LocalDate.parse(string, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | if (insertDate.getMonthValue() == currentMonth) { |
| | | int dayOfMonth = insertDate.getDayOfMonth(); |
| | | BigDecimal currentAmount = weekAmount.get(dayOfMonth - 1); // 列表索引从0开始 |
| | | weekAmount.set(dayOfMonth - 1, currentAmount.add(incomeVO1.getAmount())); |
| | | Date insertTime = incomeVO1.getInsertTime(); |
| | | // 将Date转换为LocalDateTime |
| | | Instant instant = insertTime.toInstant(); |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | LocalDateTime dateTime = instant.atZone(zoneId).toLocalDateTime(); |
| | | // 判断该数据属于哪个周 |
| | | if (dateTime.isAfter(week1Start) && dateTime.isBefore(week1End)) { |
| | | BigDecimal amount1 = incomeVO1.getAmount(); |
| | | tAmount1=tAmount1.add(amount1); |
| | | } else if (dateTime.isAfter(week2Start) && dateTime.isBefore(week2End)) { |
| | | BigDecimal amount1 = incomeVO1.getAmount(); |
| | | tAmount2=tAmount2.add(amount1); |
| | | } else if (dateTime.isAfter(week3Start) && dateTime.isBefore(week3End)) { |
| | | BigDecimal amount1 = incomeVO1.getAmount(); |
| | | tAmount4=tAmount3.add(amount1); |
| | | } else if (dateTime.isAfter(week4Start) && dateTime.isBefore(week4End)) { |
| | | BigDecimal amount1 = incomeVO1.getAmount(); |
| | | tAmount4=tAmount4.add(amount1); |
| | | } |
| | | } |
| | | weekAmount.add(tAmount1); |
| | | weekAmount.add(tAmount2); |
| | | weekAmount.add(tAmount3); |
| | | weekAmount.add(tAmount4); |
| | | monthlyData.put("weekIncome", Collections.singletonList(weekAmount)); |
| | | |
| | | LocalDateTime currentDateTime = LocalDateTime.now(); |
| | |
| | | } |
| | | |
| | | monthlyData.put("dayIncome", Collections.singletonList(amountByDay)); |
| | | // 创建一个 Map 用于存储今年本周的累计 amount |
| | | Map<Integer, BigDecimal> dayToTotalAmountMap = new HashMap<>(); |
| | | BigDecimal yearAmount = BigDecimal.ZERO; // 初始化累加变量为0 |
| | | BigDecimal monthAmount = BigDecimal.ZERO; // 初始化累加变量为0 |
| | | BigDecimal todayAmount = BigDecimal.ZERO; // 初始化累加变量为0 |
| | | // 获取当前日期和时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 今年的起始日期和结束日期 |