|
|
@ -83,192 +83,154 @@ public class TaskController { |
|
|
|
slavelQueueList.addAll(commonQueue); |
|
|
|
|
|
|
|
//查询每个队列的对象
|
|
|
|
for (FmsFollowupVo.FollowupQueueVO queue : slavelQueueList) { |
|
|
|
for (FmsFollowupVo.FollowupQueueVO followupQueueVO : slavelQueueList) { |
|
|
|
FmsFollowupDto.FollowupPatientQueryDTO followupPatientQueryDTO = new FmsFollowupDto.FollowupPatientQueryDTO(); |
|
|
|
followupPatientQueryDTO.setQueueId(queue.getId()); |
|
|
|
followupPatientQueryDTO.setTenantId(queue.getTenantId()); |
|
|
|
followupPatientQueryDTO.setQueueId(followupQueueVO.getId()); |
|
|
|
followupPatientQueryDTO.setTenantId(followupQueueVO.getTenantId()); |
|
|
|
List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO); |
|
|
|
log.info("查询每个队列的对象:{}", patientList); |
|
|
|
if (CollectionUtil.isEmpty(patientList)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
//
|
|
|
|
//// //定时任务
|
|
|
|
//
|
|
|
|
// //循环租户
|
|
|
|
// for (UmsDataSourceVo.Result tenant : tenantList) {
|
|
|
|
// if ("MASTER".equals(tenant.getDataSourceKey())) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// changeDataSource(tenant);
|
|
|
|
// {
|
|
|
|
// //获取随访患者列表,根据患者出院日时间和队列添加工单
|
|
|
|
// //1. 查询队列
|
|
|
|
// List<FmsFollowupVo.FollowupQueueVO> queueList = fmsFollowupDao.selectQueueList(null, null, null, null);
|
|
|
|
//
|
|
|
|
// if (CollectionUtil.isEmpty(queueList)) {
|
|
|
|
// queueList = followupQueueVOS;
|
|
|
|
// } else {
|
|
|
|
// if (CollectionUtil.isEmpty(followupQueueVOS)) {
|
|
|
|
// queueList.addAll(followupQueueVOS);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// for (FmsFollowupVo.FollowupQueueVO followupQueueVO : queueList) {
|
|
|
|
// Integer followWindowAdys = followupQueueVO.getFollowWindowAdys();
|
|
|
|
//
|
|
|
|
// //2. 查询队列随访患者列表
|
|
|
|
//// changeDataSource(result);
|
|
|
|
// FmsFollowupDto.FollowupPatientQueryDTO followupPatientQueryDTO = new FmsFollowupDto.FollowupPatientQueryDTO();
|
|
|
|
// followupPatientQueryDTO.setQueueId(followupQueueVO.getId());
|
|
|
|
// followupPatientQueryDTO.setTenantId(followupQueueVO.getTenantId());
|
|
|
|
// changeDataSource(result);
|
|
|
|
//
|
|
|
|
// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO);
|
|
|
|
//// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), null, null);
|
|
|
|
// if (CollectionUtil.isEmpty(patientList)) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// //随访总月数
|
|
|
|
// Integer followupMonth = followupQueueVO.getFollowupMonth();
|
|
|
|
// for (FmsFollowupVo.FollowupPatient followupPatient : patientList) {
|
|
|
|
// //获取随访到期时间 出院时间+随访总月数 = 到期时间
|
|
|
|
// Calendar calendar = Calendar.getInstance();
|
|
|
|
// calendar.setTime(followupPatient.getDischargeTime());
|
|
|
|
// calendar.set(Calendar.MONTH, followupMonth);
|
|
|
|
// Date time = calendar.getTime();
|
|
|
|
//
|
|
|
|
// //获取队列信息
|
|
|
|
// String frequency = followupQueueVO.getFrequency();
|
|
|
|
// List<Date> dateList = new ArrayList<>();
|
|
|
|
// try {
|
|
|
|
// CronTriggerImpl cronTrigger = new CronTriggerImpl();
|
|
|
|
// cronTrigger.setCronExpression(frequency);
|
|
|
|
// //TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
|
|
|
|
// dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time);
|
|
|
|
// if (CollectionUtil.isEmpty(dateList)) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// //3. 判断随访类型
|
|
|
|
// if (followupQueueVO.getFollowupType() == 0) {
|
|
|
|
// //单次
|
|
|
|
//
|
|
|
|
// //判断是否已有该次随访
|
|
|
|
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
|
|
|
|
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(1).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
|
|
|
|
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
|
|
|
|
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
|
|
|
|
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
|
|
|
|
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
// fmsFollowupTask.setName(followupPatient.getName());
|
|
|
|
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
|
|
|
|
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
|
|
|
|
// fmsFollowupTask.setGender(followupPatient.getGender());
|
|
|
|
// if (followupPatient.getBirthDate() != null) {
|
|
|
|
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
|
|
|
|
// }
|
|
|
|
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
|
|
|
|
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
|
|
|
|
// fmsFollowupTask.setPhone(followupPatient.getPhone());
|
|
|
|
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
|
|
|
|
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
|
|
|
|
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
|
|
|
|
// fmsFollowupTask.setTimes(1);
|
|
|
|
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
|
|
|
|
// fmsFollowupTask.setPatientId(followupPatient.getId());
|
|
|
|
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
|
|
|
|
// fmsFollowupTask.setDelFlag((byte) 0);
|
|
|
|
// fmsFollowupTask.setCreateTime(new Date());
|
|
|
|
// fmsFollowupTask.setStatus((byte) 0);
|
|
|
|
//
|
|
|
|
// //计算第一次随访的时间
|
|
|
|
// DateComparator dateComparator = getDate(dateList);
|
|
|
|
// if (dateComparator.getDate() != null) {
|
|
|
|
// fmsFollowupTask.setStartTime(dateComparator.getDate());
|
|
|
|
// } else {
|
|
|
|
// Calendar instance = Calendar.getInstance();
|
|
|
|
// instance.setTime(dateList.get(0));
|
|
|
|
// instance.add(Calendar.DATE, -followWindowAdys / 2);
|
|
|
|
// fmsFollowupTask.setStartTime(instance.getTime());
|
|
|
|
// }
|
|
|
|
// Calendar instance1 = Calendar.getInstance();
|
|
|
|
// instance1.setTime(dateList.get(0));
|
|
|
|
// instance1.add(Calendar.DATE, followWindowAdys / 2);
|
|
|
|
// fmsFollowupTask.setEndTime(instance1.getTime());
|
|
|
|
// fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge());
|
|
|
|
// fmsFollowupTask.setFollowupTime(dateList.get(0));
|
|
|
|
// changeDataSource(result);
|
|
|
|
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
|
|
|
|
//
|
|
|
|
// } else {
|
|
|
|
// //周期
|
|
|
|
// //4. 根据频次和总月数添加
|
|
|
|
// DateComparator dateComparator = getDate(dateList);
|
|
|
|
// if (dateComparator.getDate() == null || dateComparator.getIndex() == null) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// Date date = dateComparator.getDate();
|
|
|
|
// Integer index = dateComparator.getIndex();
|
|
|
|
//
|
|
|
|
// //判断是否已有该次随访
|
|
|
|
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
|
|
|
|
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
|
|
|
|
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
|
|
|
|
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
|
|
|
|
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
|
|
|
|
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
// fmsFollowupTask.setName(followupPatient.getName());
|
|
|
|
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
|
|
|
|
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
|
|
|
|
// fmsFollowupTask.setGender(followupPatient.getGender());
|
|
|
|
// if (followupPatient.getBirthDate() != null) {
|
|
|
|
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
|
|
|
|
// }
|
|
|
|
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
|
|
|
|
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
|
|
|
|
// fmsFollowupTask.setTimes(index);
|
|
|
|
// fmsFollowupTask.setPhone(followupPatient.getPhone());
|
|
|
|
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
|
|
|
|
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
|
|
|
|
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
|
|
|
|
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
|
|
|
|
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
|
|
|
|
// fmsFollowupTask.setDelFlag((byte) 0);
|
|
|
|
// fmsFollowupTask.setCreateTime(new Date());
|
|
|
|
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
|
|
|
|
// fmsFollowupTask.setStatus((byte) 0);
|
|
|
|
//
|
|
|
|
// fmsFollowupTask.setStartTime(date);
|
|
|
|
// Calendar instance = Calendar.getInstance();
|
|
|
|
// instance.setTime(date);
|
|
|
|
// instance.add(Calendar.DATE, followWindowAdys / 2);
|
|
|
|
//
|
|
|
|
// fmsFollowupTask.setEndTime(instance.getTime());
|
|
|
|
// changeDataSource(result);
|
|
|
|
// fmsFollowupTask.setPatientId(followupPatient.getId());
|
|
|
|
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
Integer followWindowAdys = followupQueueVO.getFollowWindowAdys(); |
|
|
|
//随访总月数
|
|
|
|
Integer followupMonth = followupQueueVO.getFollowupMonth(); |
|
|
|
for (FmsFollowupVo.FollowupPatient followupPatient : patientList) { |
|
|
|
//获取随访到期时间 出院时间+随访总月数 = 到期时间
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.setTime(followupPatient.getDischargeTime()); |
|
|
|
calendar.set(Calendar.MONTH, followupMonth); |
|
|
|
Date time = calendar.getTime(); |
|
|
|
|
|
|
|
//获取队列信息
|
|
|
|
String frequency = followupQueueVO.getFrequency(); |
|
|
|
List<Date> dateList = new ArrayList<>(); |
|
|
|
try { |
|
|
|
CronTriggerImpl cronTrigger = new CronTriggerImpl(); |
|
|
|
cronTrigger.setCronExpression(frequency); |
|
|
|
//TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
|
|
|
|
dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time); |
|
|
|
if (CollectionUtil.isEmpty(dateList)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
}finally { |
|
|
|
if (CollectionUtil.isEmpty(dateList)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
//3. 判断随访类型
|
|
|
|
if (followupQueueVO.getFollowupType() == 0) { |
|
|
|
//单次
|
|
|
|
|
|
|
|
//判断是否已有该次随访
|
|
|
|
FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample(); |
|
|
|
fmsFollowupTaskExample.createCriteria().andTimesEqualTo(1).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId()); |
|
|
|
List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample); |
|
|
|
if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
FmsFollowupTask fmsFollowupTask = new FmsFollowupTask(); |
|
|
|
BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask); |
|
|
|
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId()); |
|
|
|
fmsFollowupTask.setName(followupPatient.getName()); |
|
|
|
fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull()); |
|
|
|
fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple()); |
|
|
|
fmsFollowupTask.setGender(followupPatient.getGender()); |
|
|
|
if (followupPatient.getBirthDate() != null) { |
|
|
|
fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date())); |
|
|
|
} |
|
|
|
fmsFollowupTask.setEthnicity(followupPatient.getEthnicity()); |
|
|
|
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears()); |
|
|
|
fmsFollowupTask.setPhone(followupPatient.getPhone()); |
|
|
|
fmsFollowupTask.setTenantId(followupPatient.getTenantId()); |
|
|
|
fmsFollowupTask.setIdCardType(followupPatient.getIdCardType()); |
|
|
|
fmsFollowupTask.setIdCard(followupPatient.getIdCard()); |
|
|
|
fmsFollowupTask.setTimes(1); |
|
|
|
fmsFollowupTask.setQueueId(followupQueueVO.getId()); |
|
|
|
fmsFollowupTask.setPatientId(followupPatient.getId()); |
|
|
|
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears()); |
|
|
|
fmsFollowupTask.setDelFlag((byte) 0); |
|
|
|
fmsFollowupTask.setCreateTime(new Date()); |
|
|
|
fmsFollowupTask.setStatus((byte) 0); |
|
|
|
|
|
|
|
//计算第一次随访的时间
|
|
|
|
DateComparator dateComparator = getDate(dateList); |
|
|
|
if (dateComparator.getDate() != null) { |
|
|
|
fmsFollowupTask.setStartTime(dateComparator.getDate()); |
|
|
|
} else { |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(dateList.get(0)); |
|
|
|
instance.add(Calendar.DATE, -followWindowAdys / 2); |
|
|
|
fmsFollowupTask.setStartTime(instance.getTime()); |
|
|
|
} |
|
|
|
Calendar instance1 = Calendar.getInstance(); |
|
|
|
instance1.setTime(dateList.get(0)); |
|
|
|
instance1.add(Calendar.DATE, followWindowAdys / 2); |
|
|
|
fmsFollowupTask.setEndTime(instance1.getTime()); |
|
|
|
fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge()); |
|
|
|
fmsFollowupTask.setFollowupTime(dateList.get(0)); |
|
|
|
fmsFollowupTaskMapper.insertSelective(fmsFollowupTask); |
|
|
|
} else { |
|
|
|
//周期
|
|
|
|
//4. 根据频次和总月数添加
|
|
|
|
DateComparator dateComparator = getDate(dateList); |
|
|
|
if (dateComparator.getDate() == null || dateComparator.getIndex() == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
Date date = dateComparator.getDate(); |
|
|
|
Integer index = dateComparator.getIndex(); |
|
|
|
|
|
|
|
//判断是否已有该次随访
|
|
|
|
FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample(); |
|
|
|
fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId()); |
|
|
|
List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample); |
|
|
|
if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
FmsFollowupTask fmsFollowupTask = new FmsFollowupTask(); |
|
|
|
BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask); |
|
|
|
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId()); |
|
|
|
fmsFollowupTask.setName(followupPatient.getName()); |
|
|
|
fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull()); |
|
|
|
fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple()); |
|
|
|
fmsFollowupTask.setGender(followupPatient.getGender()); |
|
|
|
if (followupPatient.getBirthDate() != null) { |
|
|
|
fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date())); |
|
|
|
} |
|
|
|
fmsFollowupTask.setEthnicity(followupPatient.getEthnicity()); |
|
|
|
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears()); |
|
|
|
fmsFollowupTask.setTimes(index); |
|
|
|
fmsFollowupTask.setPhone(followupPatient.getPhone()); |
|
|
|
fmsFollowupTask.setTenantId(followupPatient.getTenantId()); |
|
|
|
fmsFollowupTask.setIdCardType(followupPatient.getIdCardType()); |
|
|
|
fmsFollowupTask.setIdCard(followupPatient.getIdCard()); |
|
|
|
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId()); |
|
|
|
fmsFollowupTask.setQueueId(followupQueueVO.getId()); |
|
|
|
fmsFollowupTask.setDelFlag((byte) 0); |
|
|
|
fmsFollowupTask.setCreateTime(new Date()); |
|
|
|
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears()); |
|
|
|
fmsFollowupTask.setStatus((byte) 0); |
|
|
|
|
|
|
|
fmsFollowupTask.setStartTime(date); |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(date); |
|
|
|
instance.add(Calendar.DATE, followWindowAdys / 2); |
|
|
|
|
|
|
|
fmsFollowupTask.setEndTime(instance.getTime()); |
|
|
|
fmsFollowupTask.setPatientId(followupPatient.getId()); |
|
|
|
fmsFollowupTaskMapper.insertSelective(fmsFollowupTask); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@DataSource(DataSourceType.MASTER) |
|
|
|
@ApiOperation("定时任务添加随访工单") |
|
|
|
@PostMapping("/task") |
|
|
|
@Scheduled(cron = "0 0 0 * * ?") |
|
|
|
@Scheduled(cron = "0 0 0 * * 1") |
|
|
|
@Anonymous |
|
|
|
public void task() { |
|
|
|
// TODO 生成工单第一次生成之后2周的,往后只生成之后一周。第一次随访时间: ( 患者的出院时间 - 7 + 轮次时间) 到 (患者的出院时间 + 7 + 轮次时间 )
|
|
|
|