2022-08-04

导读:本篇文章讲解 2022-08-04,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

一、List取差集

二、List取交集

三、将String转换为集合

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

四、获取上月初-上月末

		//获取前一个月第一天
		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());

五、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);
}

六、生成逻辑

// 查询所有客户
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);
    }
}

七、按周期生成?

根据参数获取周期

八、8小时之后推送?

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/65572.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!