From ba370d8391b7970303072d58d6820fbb75bdd591 Mon Sep 17 00:00:00 2001 From: zzc Date: Mon, 31 Mar 2025 09:42:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtask=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=87=E6=8D=A2=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/web/TaskController.java | 211 ------------------ .../acupuncture/web/task/TaskController.java | 22 +- .../src/main/resources/application.yml | 5 + .../framework/aspectj/DataSourceAspect.java | 3 +- .../system/persist/dao/UmsDataSourceDao.java | 2 + .../resources/mapper/dao/UmsDataSourceDao.xml | 26 +++ 6 files changed, 48 insertions(+), 221 deletions(-) delete mode 100644 acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java deleted file mode 100644 index b612a4ac..00000000 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java +++ /dev/null @@ -1,211 +0,0 @@ -//package com.acupuncture.web.controller.web; -// -//import cn.hutool.core.bean.BeanUtil; -//import cn.hutool.core.collection.CollectionUtil; -//import cn.hutool.core.date.DateUtil; -//import cn.hutool.core.util.IdUtil; -//import com.acupuncture.common.annotation.Anonymous; -//import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; -//import com.acupuncture.system.domain.po.FmsFollowupTask; -//import com.acupuncture.system.domain.po.FmsPatientQueueRelation; -//import com.acupuncture.system.domain.vo.FmsFollowupVo; -//import com.acupuncture.system.domain.vo.UmsDataSourceVo; -//import com.acupuncture.system.persist.dao.FmsFollowupDao; -//import com.acupuncture.system.persist.dao.UmsDataSourceDao; -//import com.acupuncture.system.persist.mapper.FmsFollowupTaskMapper; -//import com.acupuncture.system.persist.mapper.FmsPatientQueueRelationMapper; -//import io.swagger.annotations.Api; -//import io.swagger.annotations.ApiOperation; -//import lombok.extern.slf4j.Slf4j; -//import org.quartz.TriggerUtils; -//import org.quartz.impl.triggers.CronTriggerImpl; -//import org.springframework.scheduling.annotation.Scheduled; -//import org.springframework.transaction.annotation.Propagation; -//import org.springframework.transaction.annotation.Transactional; -//import org.springframework.web.bind.annotation.PostMapping; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -// -//import javax.annotation.Resource; -//import java.util.ArrayList; -//import java.util.Calendar; -//import java.util.Date; -//import java.util.List; -// -///** -// * @Author zzc -// * @Package com.acupuncture.web.controller.web -// * @Date 2025/2/13 8:50 -// * @description: -// */ -//@Slf4j -//@Api(tags = "定时任务相关") -//@RestController -//@RequestMapping("/task") -//@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) -//public class TaskController { -// -// @Resource -// private FmsFollowupDao fmsFollowupDao; -// @Resource -// private FmsFollowupTaskMapper fmsFollowupTaskMapper; -// @Resource -// private UmsDataSourceDao umsDataSourceDao; -// @Resource -// private FmsPatientQueueRelationMapper fmsPatientQueueRelationMapper; -// -// @ApiOperation("定时任务添加随访工单") -// @PostMapping("/task") -//// @Scheduled(fixedRate = 10000) -// @Anonymous -// public void task() { -// // TODO 生成工单第一次生成之后2周的,往后只生成之后一周。第一次随访时间: ( 患者的出院时间 - 7 + 轮次时间) 到 (患者的出院时间 + 7 + 轮次时间 ) -// -// //查询租户,根据租户循环切换数据源,定时处理所有医院的随访工单 -//// UmsDataSourceVo.Result result1 = new UmsDataSourceVo.Result(); -//// result1.setDataSourceKey("MASTER"); -//// changeDataSource(result1); -// List query = umsDataSourceDao.query(null); -// if (CollectionUtil.isEmpty(query)) { -// return; -// } -// //查询公共队列 -// List queueResults = fmsFollowupDao.queryCommonQueue(null); -// //切换数据源 -// for (UmsDataSourceVo.Result result : query) { -// if ("MASTER".equals(result.getDataSourceKey())) { -// continue; -// } -// changeDataSource(result); -// { -// //获取随访患者列表,根据患者出院日时间和队列添加工单 -// //1. 查询队列 -// List queueList = fmsFollowupDao.selectQueueList(null, null, null, result.getTenantId()); -// -// if (CollectionUtil.isEmpty(queueList)) { -// queueList = queueResults; -// } else { -// queueList.addAll(queueResults); -// } -// for (FmsFollowupVo.FollowupQueueVO followupQueueVO : queueList) { -// //2. 查询队列随访患者列表 -// List patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), (byte) 0, null, followupQueueVO.getTenantId()); -// 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 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) { -// //单次 -// 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); -// fmsFollowupTask.setStartTime(dateList.get(0)); -// fmsFollowupTask.setEndTime(dateList.get(0)); -// fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge()); -// fmsFollowupTask.setFollowupTime(dateList.get(0)); -// changeDataSource(result); -// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask); -// -// } else { -// //周期 -// //4. 根据频次和总月数添加 -// int i = 0; -// for (Date date : dateList) { -// i+=1; -// //单次 -// 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(i); -// 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); -// fmsFollowupTask.setEndTime(date); -// fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge()); -// fmsFollowupTask.setFollowupTime(date); -// changeDataSource(result); -// fmsFollowupTask.setPatientId(followupPatient.getId()); -// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask); -// } -// } -// changeDataSource(result); -// //将患者设置为已生成工单 -// FmsPatientQueueRelation fmsPatientQueueRelation = BeanUtil.copyProperties(followupPatient, FmsPatientQueueRelation.class); -// fmsPatientQueueRelation.setTaskFlag((byte) 1); -// fmsPatientQueueRelation.setPatientId(followupPatient.getId()); -// fmsPatientQueueRelationMapper.updateByPrimaryKeySelective(fmsPatientQueueRelation); -// } -// } -// -// } -// } -// } -// -// private static void changeDataSource(UmsDataSourceVo.Result result) { -// try { -// DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); -// }finally { -// DynamicDataSourceContextHolder.clearDataSourceType(); -// } -// } -//} diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController.java index 56005541..2cdbabb2 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController.java @@ -6,7 +6,9 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.acupuncture.common.annotation.Anonymous; +import com.acupuncture.common.annotation.DataSource; import com.acupuncture.common.core.redis.RedisCache; +import com.acupuncture.common.enums.DataSourceType; import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; import com.acupuncture.system.domain.dto.FmsFollowupDto; import com.acupuncture.system.domain.po.FmsFollowupTask; @@ -48,7 +50,7 @@ import java.util.stream.Collectors; @Api(tags = "定时任务相关") @RestController @RequestMapping("/task") -@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) +//@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class TaskController { @Resource @@ -76,8 +78,8 @@ public class TaskController { //查询从库队列 //1. 查询队列 List slavelQueueList = fmsFollowupDao.selectQueueList(null, null, null, null); - - //合并公共队列和从库的队列 + log.info("sa:{}", slavelQueueList); +// //合并公共队列和从库的队列 slavelQueueList.addAll(commonQueue); //查询每个队列的对象 @@ -87,10 +89,13 @@ public class TaskController { followupPatientQueryDTO.setTenantId(queue.getTenantId()); List patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO); log.info("查询每个队列的对象:{}", patientList); + if (CollectionUtil.isEmpty(patientList)) { + continue; + } } - - //定时任务 - +// +//// //定时任务 +// // //循环租户 // for (UmsDataSourceVo.Result tenant : tenantList) { // if ("MASTER".equals(tenant.getDataSourceKey())) { @@ -255,11 +260,12 @@ public class TaskController { // } // } // } -// + // } // } } + @DataSource(DataSourceType.MASTER) @ApiOperation("定时任务添加随访工单") @PostMapping("/task") @Scheduled(cron = "0 0 0 * * ?") @@ -268,7 +274,7 @@ public class TaskController { // TODO 生成工单第一次生成之后2周的,往后只生成之后一周。第一次随访时间: ( 患者的出院时间 - 7 + 轮次时间) 到 (患者的出院时间 + 7 + 轮次时间 ) //查询租户,根据租户循环切换数据源,定时处理所有医院的随访工单 - List tenantList = umsDataSourceDao.query(null); + List tenantList = umsDataSourceDao.query1(null); if (CollectionUtil.isEmpty(tenantList)) { return; } diff --git a/acupuncture-admin/src/main/resources/application.yml b/acupuncture-admin/src/main/resources/application.yml index 7a586722..40a39b86 100644 --- a/acupuncture-admin/src/main/resources/application.yml +++ b/acupuncture-admin/src/main/resources/application.yml @@ -48,6 +48,11 @@ user: # Spring配置 spring: + jpa: + show-sql: true + properties: + hibernate: + format_sql: true # 资源信息 messages: # 国际化资源文件路径 diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/DataSourceAspect.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/DataSourceAspect.java index df745c47..1ef9e3fd 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/DataSourceAspect.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/DataSourceAspect.java @@ -28,8 +28,7 @@ public class DataSourceAspect protected Logger logger = LoggerFactory.getLogger(getClass()); @Pointcut("@annotation(com.acupuncture.common.annotation.DataSource)" - + "|| @within(com.acupuncture.common.annotation.DataSource)" + - "|| within(com.acupuncture.web.task.TaskController)") + + "|| @within(com.acupuncture.common.annotation.DataSource)") public void dsPointCut() { diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/UmsDataSourceDao.java b/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/UmsDataSourceDao.java index cc576581..819262ba 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/UmsDataSourceDao.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/UmsDataSourceDao.java @@ -18,4 +18,6 @@ public interface UmsDataSourceDao { @DataSource(DataSourceType.MASTER) List query(@Param("tenantId") Long tenantId); + List query1(@Param("tenantId") Long tenantId); + } diff --git a/acupuncture-system/src/main/resources/mapper/dao/UmsDataSourceDao.xml b/acupuncture-system/src/main/resources/mapper/dao/UmsDataSourceDao.xml index dad69113..e8af55f3 100644 --- a/acupuncture-system/src/main/resources/mapper/dao/UmsDataSourceDao.xml +++ b/acupuncture-system/src/main/resources/mapper/dao/UmsDataSourceDao.xml @@ -28,4 +28,30 @@ t.id + +