这里写目录标题
零、测试健康报告生成
一直都在测试,在message_info表中找不到我生成的数据
原来,数据库可以进行分页。。。
健康报告已经生成了十几条了~我还在默默调试、、、
一、用户名加密解密
调用CustomerService里的个方法
效果如下
按照解密的用户名查询列表
二、时间格式
要求:
报告时间:
LocalDate now = LocalDate.now();
LocalDate lastMonth = now.minusMonths(1);
LocalDate firstDay = lastMonth.with(TemporalAdjusters.firstDayOfMonth());
LocalDate lastDay = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
String first = DateUtil.STANDARD_ONLINE_SETTING_FORMATTER.format(firstDay);
String last = DateUtil.STANDARD_ONLINE_SETTING_FORMATTER.format(lastDay);
healthRecordEntity.setRecordTime(first+" - "+last);
推送时间:
for (HealthRecord healthRecord : iPage.getRecords()) {
Opt<CustomerInfoDetail> customerInfoDetail = customerService.getCustomerById(tenantId, healthRecord.getCustomerId());
String name = customerInfoDetail.getSome().getName();
// 用户名
healthRecord.setCustomerName(name);
if (healthRecord.getPushTime() != null) {
healthRecord.setPushTimeString(DateUtil.STANDARD_YMD_HM_FORMATTER_2.format(healthRecord.getPushTime()));
}
}
时间工具类:
import com.alibaba.fastjson.JSONObject;
import com.lanxi.core.model.enums.MessageTemplateNameEnum;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
public class DateUtil {
public static DateTimeFormatter STANDARD_24H_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static DateTimeFormatter STANDARD_YMD_HM_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
public static DateTimeFormatter STANDARD_YMD_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static DateTimeFormatter STANDARD_DETAIL_FORMATTER = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
public static DateTimeFormatter STANDARD_YMD_CH_FORMATTER = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
public static DateTimeFormatter STANDARD_ONLINE_SETTING_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd");
public static DateTimeFormatter STANDARD_YMD_HM_FORMATTER_2 = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
public static DateTimeFormatter STANDARD_HM_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
private static final LocalDateTime NOW = LocalDateTime.now();
/**
* 计算年龄
* @param year 出生年份
* @deprecated use {@link com.lanxi.util.AgeUtil#calculateAge} instead
* @return int
*/
@Deprecated
public static int getAge(int year) {
return NOW.getYear() - year;
}
/**
* 计算年龄(没过生日那一天不会增加年龄)
* @param birthday 生日
* @return 年龄
*/
public static int getAge(LocalDateTime birthday) {
int year = (int) ChronoUnit.YEARS.between(birthday, LocalDateTime.now());
return year < 1 ? 1 : year;
}
/**
* time1 < time2
*/
public static String getTimeDistance(LocalDateTime time1, LocalDateTime time2) {
Duration duration = Duration.between(time1, time2);
long minutes = duration.toMinutes();
if (minutes <= 10) {
return "刚刚";
} else if (minutes > 10 && minutes <= 59) {
return minutes + "分钟前";
} else {
long hours = duration.toHours();
if (hours >= 1 && hours <= 23) {
return hours + "小时前";
} else {
long days = duration.toDays();
return days + "天前";
}
}
}
/**
* time1 < time2
*/
public static JSONObject getTimeAndHhEnum(LocalDateTime time1, LocalDateTime time2) {
JSONObject jsonObject = new JSONObject();
Duration duration = Duration.between(time1, time2);
long minutes = duration.toMinutes();
if (minutes <= 10) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_NOW_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_NOW_TO_RELATIVES);
} else if (minutes > 10 && minutes <= 59) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_MINUTE_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_MINUTE_TO_RELATIVES);
jsonObject.put("time", String.valueOf(minutes));
} else {
long hours = duration.toHours();
if (hours >= 1 && hours <= 23) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_HOUR_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_HOUR_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
} else {
long days = duration.toDays();
jsonObject.put("customerEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_DAY_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.HH_EXAM_REPORT_DAY_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
}
}
return jsonObject;
}
/**
* time1 < time2
*/
public static JSONObject getTimeAndMeterEnum(LocalDateTime time1, LocalDateTime time2) {
JSONObject jsonObject = new JSONObject();
Duration duration = Duration.between(time1, time2);
long minutes = duration.toMinutes();
if (minutes <= 10) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.METER_MEASUREMENT_NOW_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.METER_MEASUREMENT_NOW_TO_RELATIVES);
} else if (minutes > 10 && minutes <= 59) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.METER_MEASUREMENT_MINUTE_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.METER_MEASUREMENT_MINUTE_TO_RELATIVES);
jsonObject.put("time", String.valueOf(minutes));
} else {
long hours = duration.toHours();
if (hours >= 1 && hours <= 23) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.METER_MEASUREMENT_HOUR_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.METER_MEASUREMENT_HOUR_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
} else {
long days = duration.toDays();
jsonObject.put("customerEnum", MessageTemplateNameEnum.METER_MEASUREMENT_DAY_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.METER_MEASUREMENT_DAY_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
}
}
return jsonObject;
}
/**
* time1 < time2
*/
public static JSONObject getTimeAndAqgEnum(LocalDateTime time1, LocalDateTime time2) {
JSONObject jsonObject = new JSONObject();
Duration duration = Duration.between(time1, time2);
long minutes = duration.toMinutes();
if (minutes <= 10) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_NOW_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_NOW_TO_RELATIVES);
} else if (minutes > 10 && minutes <= 59) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_MINUTE_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_MINUTE_TO_RELATIVES);
jsonObject.put("time", String.valueOf(minutes));
} else {
long hours = duration.toHours();
if (hours >= 1 && hours <= 23) {
jsonObject.put("customerEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_HOUR_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_HOUR_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
} else {
long days = duration.toDays();
jsonObject.put("customerEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_DAY_TO_CUSTOMER);
jsonObject.put("relativesEnum", MessageTemplateNameEnum.AQG_WATCH_WARN_DAY_TO_RELATIVES);
jsonObject.put("time", String.valueOf(hours));
}
}
return jsonObject;
}
/**
* 获取两个时间时间差(秒)
* time1 < time2
* @param time1
* @param time2
* @return
*/
public static long countTimeDistance(LocalDateTime time1, LocalDateTime time2) {
Duration duration = Duration.between(time1, time2);
return duration.getSeconds();
}
}