@GetMapping("/initData2")
public void init2() {
log.info("初始化数据:{}", DateUtil.date());
iuWorkstationActivityService.initialize2();
log.info("数据统计完毕:{}", DateUtil.date());
}
从新统计表有时间 就走二 没时间走条件一
@Override
public void initialize2() {
// 统计表中最早时间
Date earlestDate = iuWorkstationMapper.queryAscDate();
// 统计表中最早时间
Date queryEarliestDate = iuWorkstationActivityMapper.queryEarliestDate();
UserAnalysisDto userAnalysisDto = new UserAnalysisDto();
log.info("初始化统计数据:{},{}", earlestDate, queryEarliestDate);
// 初始化
if (earlestDate != null && queryEarliestDate == null) {
userAnalysisDto.setQueryEndTime(DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss"));
userAnalysisDto.setQueryStartTime(DateUtil.format(DateUtil.beginOfDay(earlestDate), "yyyy-MM-dd HH:mm:ss"));
userAnalysisDto.setProvinceCode(UserAnalysisConstant.PROVINCE_CODE);
iuWorkstationActivityService.initIuWorkstationActivityDetail(userAnalysisDto);
} else if (queryEarliestDate != null && queryEarliestDate.before(DateUtil.beginOfDay(DateUtil.yesterday()))) {
userAnalysisDto.setQueryEndTime(DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss"));
userAnalysisDto.setQueryStartTime(DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(queryEarliestDate, 1)), "yyyy-MM-dd HH:mm:ss"));
userAnalysisDto.setProvinceCode(UserAnalysisConstant.PROVINCE_CODE);
iuWorkstationActivityService.initIuWorkstationActivityDetail(userAnalysisDto);
}
}
将查询出的数据存在 iuWorkstationActivity类中
@Override
public void initIuWorkstationActivityDetail(UserAnalysisDto userAnalysisDto) {
//根据工作站 查询出医院
List<HrHospitalModel> hospitalModels = queryAllHospitalByWorkStation(userAnalysisDto);
for (HrHospitalModel hospitalModel : hospitalModels) {//拿到工作站id去 每一天的
log.info("将统计医院的数据:{}", hospitalModel);
String hospitalId = hospitalModel.getHospitalId();
this.initStatisticsData(userAnalysisDto, hospitalId, hospitalModel.getHospitalName(), hospitalModel.getProvince(), hospitalModel.getCity(), hospitalModel.getCounty());
}
}
private void initStatisticsData(UserAnalysisDto userAnalysisDto, String hospitalId, String hospitalName, String province, String city, String county) {
//每日工作站量 // 统计表中最早时间
Date earlestDate = iuWorkstationMapper.queryAscDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//格式化成时分秒
String workStartTimeDate = sdf.format(earlestDate); //最开始工作站的时间
List<String> dateList = DateUtils.calDay(userAnalysisDto.getQueryStartTime(), userAnalysisDto.getQueryEndTime());
List<IuWorkstationActivity> iuWorkstationActivityArrayList = new ArrayList<>();
for (String date : dateList) {
IuWorkstationActivity iuWorkstationActivity = new IuWorkstationActivity();
//转换成对应的时间格式 //设置时间格式
String endTimeTemp = sdf.format(DateUtil.parse(date));//作为每日登录 在线的人数的开始时间
String endDate = endTimeTemp.substring(0, 10);
String endTimeDate = endDate + DataTrendConstant.Time_End_Suffix;
//每日登录 在线的人数
Integer loginSumVo = iuOperateMapper.queryDoctorLoginSumDay(OperateTypeEnum.LOGIN.getId(), endTimeTemp, endTimeDate, hospitalId);
iuWorkstationActivity.setWorkstationOnlineSum(loginSumVo);
//当日工作站数量
String yesterdayTime = getYesterdayTime() + DataTrendConstant.Time_End_Suffix;
Integer workSumVo = iuWorkstationMapper.queryWorkDaySumDay(workStartTimeDate, yesterdayTime, hospitalId);
iuWorkstationActivity.setDailyWorkstationVolume(workSumVo);
iuWorkstationActivity.setDayTime(DateUtil.parse(date));
iuWorkstationActivity.setHospitalId(hospitalId);
iuWorkstationActivity.setProvinceCode(province);
iuWorkstationActivity.setCityCode(city);
iuWorkstationActivity.setDistrictCode(county);
iuWorkstationActivityArrayList.add(iuWorkstationActivity);
}
log.info("每个人数量大小:{}", iuWorkstationActivityArrayList.size());
iuWorkstationActivityService.insertData(iuWorkstationActivityArrayList);
}
入表
@Override
@DS("clickhouse")
public void insertData(List<IuWorkstationActivity> iuWorkstationActivityArrayList) {
this.saveBatch(iuWorkstationActivityArrayList);
}