• 2022-08-04


    一、List取差集

    二、List取交集

    三、将String转换为集合

    String params = serviceItemDao.getById(c.getServiceTeamId()).getParams();
    Map<String, String> paramsMap = JSONObject.parseObject(params.toString(), Map.class);
    
    • 1
    • 2

    四、获取上月初-上月末

    		//获取前一个月第一天
    		Calendar calendar1 = Calendar.getInstance();
    		calendar1.add(Calendar.MONTH, -1);
    		calendar1.set(Calendar.DAY_OF_MONTH,1);
    		String firstDay = sdf.format(calendar1.getTime());
    		//获取前一个月最后一天
    		Calendar calendar2 = Calendar.getInstance();
    		calendar2.set(Calendar.DAY_OF_MONTH, 0);
    		String lastDay = sdf.format(calendar2.getTime());
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    五、localDate获取上一周、上一个月、上一季度、上一年

    if (monthValue >= 1 && monthValue <= 3){
           LocalDate lastYear = now.minusYears(1); // 当前年份减1
           LocalDate firstDay = LocalDate.of(lastYear.getYear(), 10,1); // 获取前一年最后季度的第一天
           LocalDate lastDay = LocalDate.of(lastYear.getYear(), 12,31); // 获取前一年最后季度的最后一天
           healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
       } else if(monthValue >= 4 && monthValue <= 6){
           LocalDate firstDay = LocalDate.of(now.getYear(), 1,1); // 获取前一年最后季度的第一天
           LocalDate lastDay = LocalDate.of(now.getYear(), 3,31); // 获取前一年最后季度的最后一天
           healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
       } else if(monthValue >= 7 && monthValue <= 9){
           LocalDate firstDay = LocalDate.of(now.getYear(), 4,1); // 获取前一年最后季度的第一天
           LocalDate lastDay = LocalDate.of(now.getYear(), 6,30); // 获取前一年最后季度的最后一天
           healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
       } else if(monthValue >= 10 && monthValue <= 12){
           LocalDate firstDay = LocalDate.of(now.getYear(), 7,1); // 获取前一年最后季度的第一天
           LocalDate lastDay = LocalDate.of(now.getYear(), 9,30); // 获取前一年最后季度的最后一天
           healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
       }
    
    } else if (cycle.equals("year")) {
       healthRecordEntity.setPushCycle(3);
       LocalDate now = LocalDate.now();
       LocalDate lastYear = now.minusYears(1); // 当前年份减1
       LocalDate firstDay = lastYear.with(TemporalAdjusters.firstDayOfYear()); // 获取前一年的第一天
       LocalDate lastDay = lastYear.with(TemporalAdjusters.lastDayOfYear()); // 获取前一年的最后一天
       healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    六、生成逻辑

    // 查询所有客户
    List<CustomerEntity> customersAll = customerDao.list();
    List<CustomerPackageEntity> customerPackageEntities = customerPackageDao.list().stream().collect(
            Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getCustomerId()))), ArrayList::new));
    
    List<CustomerEntity> customers = new ArrayList<>();
    for (CustomerPackageEntity cus : customerPackageEntities){
        // 绑定了套餐的客户 - 按服务套餐生成
        customers.add(customerDao.getById(cus.getCustomerId()));
    }
    // 未绑定套餐的客户
    customersAll.removeAll(customers);
    
    List<CustomerEntity> customersB = new ArrayList<>();
    // 查询检测次数大于等于15(times:15)次的客户
    List<CustomerBodyMetricsEntity> customerBodyMatterList = customerBodyMetricsDao.listCount15();
    for (CustomerBodyMetricsEntity cbm : customerBodyMatterList){
        CustomerEntity customer = customerDao.getById(cbm.getCustomerId());
        customersB.add(customer);
    }
    // 未绑定套餐的客户 且 次数大于15的客户 - 默认生成
    customersB.removeAll(customersAll);
    
    // 1. 默认生成
    for(CustomerEntity ce : customersB){
        HealthRecordEntity hre = new HealthRecordEntity();
        hre.setCustomerId(ce.getId());
        hre.setTeamId(ce.getServiceTeamId());
        hre.setPushCycle(1);
        // 报告时间
        LocalDate now = LocalDate.now();
        LocalDate lastMonth = now.minusMonths(1); // 当前月份减1
        LocalDate firstDay = lastMonth.with(TemporalAdjusters.firstDayOfMonth()); // 获取前月的第一天
        LocalDate lastDay = lastMonth.with(TemporalAdjusters.lastDayOfMonth()); // 获取前月的最后一天
        hre.setRecordTime(firstDay+" - "+lastDay);
    
        hre.setHrType(0);
        // 生成之后,八点推送
        hre.setPushStatus(0);
        // 推送时间为生成当天的8:00
        // hre.setPushTime("");
        // 生成
        healthRecordDao.save(hre);
    }
    
    // 2. 按服务套餐生成
    for(CustomerEntity c : customers){
        List<CustomerPackageDetailEntity> customerPackageDetailEntityList = new ArrayList<>();
        // 查询此用户绑定的套餐列表
        LambdaQueryWrapper<CustomerPackageEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CustomerPackageEntity::getCustomerId, c.getId());
        List<CustomerPackageEntity> list = customerPackageDao.list(wrapper);
        for (CustomerPackageEntity cp : list){
            // 根据套餐列表查询服务项目列表
            LambdaQueryWrapper<CustomerPackageDetailEntity> wrapper1 = new LambdaQueryWrapper<>();
            // 根据 客户套餐ID 进行查询
            wrapper1.eq(CustomerPackageDetailEntity::getCustomerPackageId, cp.getId());
            // 根据 服务项目ID 进行去重
            // customerPackageDetailEntityList是去重后的list
            customerPackageDetailEntityList = customerPackageDetailDao.list(wrapper1).stream().collect(
                    Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getServiceItemId()))), ArrayList::new));
        }
        for (CustomerPackageDetailEntity cpd : customerPackageDetailEntityList){
            HealthRecordEntity healthRecordEntity = new HealthRecordEntity();
            healthRecordEntity.setCustomerId(c.getId());
            healthRecordEntity.setTeamId(c.getServiceTeamId());
            // 上传周期(0周、1月、2季、3年)
            String params = serviceItemDao.getById(c.getServiceTeamId()).getParams();
            Map<String, String> paramsMap = JSONObject.parseObject(params.toString(), Map.class);
            String cycle = paramsMap.get("cycle");
            if (cycle.equals("week")){
                healthRecordEntity.setPushCycle(0);
                LocalDate now = LocalDate.now();
                LocalDate todayOfLastWeek = now.minusDays(7);
                LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
                LocalDate sunday = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
                healthRecordEntity.setRecordTime(monday+" - "+sunday);
            } else if (cycle.equals("month")) {
                healthRecordEntity.setPushCycle(1);
                LocalDate now = LocalDate.now();
                LocalDate lastMonth = now.minusMonths(1); // 当前月份减1
                LocalDate firstDay = lastMonth.with(TemporalAdjusters.firstDayOfMonth()); // 获取前月的第一天
                LocalDate lastDay = lastMonth.with(TemporalAdjusters.lastDayOfMonth()); // 获取前月的最后一天
                healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
            } else if (cycle.equals("quarter")) {
                healthRecordEntity.setPushCycle(2);
                LocalDate now = LocalDate.now();
                int monthValue = now.getMonthValue();
                int quarter = 0;
                if (monthValue >= 1 && monthValue <= 3){
                    LocalDate lastYear = now.minusYears(1); // 当前年份减1
                    LocalDate firstDay = LocalDate.of(lastYear.getYear(), 10,1); // 获取前一年最后季度的第一天
                    LocalDate lastDay = LocalDate.of(lastYear.getYear(), 12,31); // 获取前一年最后季度的最后一天
                    healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
                } else if(monthValue >= 4 && monthValue <= 6){
                    LocalDate firstDay = LocalDate.of(now.getYear(), 1,1); // 获取前一年最后季度的第一天
                    LocalDate lastDay = LocalDate.of(now.getYear(), 3,31); // 获取前一年最后季度的最后一天
                    healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
                } else if(monthValue >= 7 && monthValue <= 9){
                    LocalDate firstDay = LocalDate.of(now.getYear(), 4,1); // 获取前一年最后季度的第一天
                    LocalDate lastDay = LocalDate.of(now.getYear(), 6,30); // 获取前一年最后季度的最后一天
                    healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
                } else if(monthValue >= 10 && monthValue <= 12){
                    LocalDate firstDay = LocalDate.of(now.getYear(), 7,1); // 获取前一年最后季度的第一天
                    LocalDate lastDay = LocalDate.of(now.getYear(), 9,30); // 获取前一年最后季度的最后一天
                    healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
                }
    
            } else if (cycle.equals("year")) {
                healthRecordEntity.setPushCycle(3);
                LocalDate now = LocalDate.now();
                LocalDate lastYear = now.minusYears(1); // 当前年份减1
                LocalDate firstDay = lastYear.with(TemporalAdjusters.firstDayOfYear()); // 获取前一年的第一天
                LocalDate lastDay = lastYear.with(TemporalAdjusters.lastDayOfYear()); // 获取前一年的最后一天
                healthRecordEntity.setRecordTime(firstDay+" - "+lastDay);
            }
            healthRecordEntity.setHrType(0);
            // 生成之后,八点推送
            healthRecordEntity.setPushStatus(0);
            // 推送时间为生成时间的八点
            // hre.setPushTime("");
            // 生成
            healthRecordDao.save(healthRecordEntity);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125

    七、按周期生成?

    根据参数获取周期

    八、8小时之后推送?

    存放到mq中
    在这里插入图片描述

    九、idea中git在push后怎么回滚

  • 相关阅读:
    [附源码]java毕业设计社区空巢老人关爱服务平台
    Spring中如何在一个Bean中注入一个内部Bean呢?
    数据结构初阶--双向循环链表(讲解+类模板实现)
    【Linux is not Unix】Linux前言
    将Windows文件复制,改装成游戏
    记录一次线上kafka故障及处理方式
    PyTorch实战 | 文本情感分类任务 | LSTM与LSTM+Attention
    SpringBoot3.x中spring.factories功能被移除的解决方案
    mybatis核心配置文件
    一道面试题:JVM老年代空间担保机制
  • 原文地址:https://blog.csdn.net/HRX98/article/details/126154119