From 99c941a1e7b5fc26723ce95f3d956e884ffde451 Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=9F=E6=88=B7=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysUserController.java | 6 +- .../web/AdminDmsUserController.java | 48 +- .../web/AdminPmsTreatmentController.java | 6 +- .../controller/web/ExternalController.java | 6 +- .../controller/web/ScreeningController.java | 6 +- .../web/controller/web/TaskController.java | 211 ++++++ .../acupuncture/web/task/TaskController.java | 672 +++++++++--------- .../acupuncture/web/task/TaskController1.java | 6 +- .../acupuncture/web/task/TaskController2.java | 340 +++++++++ .../common/core/domain/entity/SysUser.java | 13 + .../aspectj/AdminGlobalDataSourceAspect.java | 19 +- .../framework/aspectj/DataSourceAspect.java | 3 +- .../system/domain/dto/AdminTenantUserDto.java | 6 + .../system/domain/dto/FmsFollowupDto.java | 2 + .../system/domain/vo/StatisticsVo.java | 7 + .../system/persist/dao/FmsFollowupDao.java | 7 + .../system/service/FmsFollowupService.java | 8 + .../impl/AdminStatisticsServiceImpl.java | 1 + .../service/impl/FmsFollowupServiceImpl.java | 38 + .../service/impl/PmsPatientServiceImpl.java | 48 +- .../service/impl/ScreeningServiceImpl.java | 8 +- .../service/impl/StatisticsServiceImpl.java | 1 + .../resources/mapper/dao/AdminDmsUserDao.xml | 1 + .../resources/mapper/dao/AdminTongjiDao.xml | 12 + .../resources/mapper/dao/FmsFollowupDao.xml | 43 ++ .../resources/mapper/dao/StatisticsDao.xml | 14 +- .../resources/mapper/system/SysUserMapper.xml | 6 +- 27 files changed, 1167 insertions(+), 371 deletions(-) create mode 100644 acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java create mode 100644 acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController2.java diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysUserController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysUserController.java index 2ca06b37..3df129ea 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysUserController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysUserController.java @@ -191,7 +191,11 @@ public class SysUserController extends BaseController if (dmsTenant != null) { UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); if (umsDataSource != null) { - DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); + try { + DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); + }finally { + DynamicDataSourceContextHolder.clearDataSourceType(); + } } } } diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminDmsUserController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminDmsUserController.java index 49193abc..48ac8c36 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminDmsUserController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminDmsUserController.java @@ -2,6 +2,7 @@ package com.acupuncture.web.controller.web; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.acupuncture.common.core.domain.BaseDto; import com.acupuncture.common.core.domain.JsonResponse; import com.acupuncture.common.core.domain.entity.SysUser; @@ -68,15 +69,29 @@ public class AdminDmsUserController { @ApiOperation("添加租户用户") @PostMapping("/add") public JsonResponse insert(@RequestBody @Validated AdminTenantUserDto.AddDto dto) { - //新增分库数据 - //切换到分库数据源 + //判定租户及数据源是否存在 DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(dto.getTenantId()); - if (dmsTenant != null) { - UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); - if (umsDataSource != null) { - changeDataSource(umsDataSource.getDataSourceKey()); - } + if (dmsTenant == null) { + return JsonResponse.ok().fail("租户不存在"); + } + UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); + if (umsDataSource == null || StrUtil.isEmpty(umsDataSource.getDataSourceKey())) { + return JsonResponse.ok().fail("数据源不存在"); + } + + //新增主库租户用户 + if (!dmsLoginService.checkUserNameUnique(dto)) { + return JsonResponse.ok().fail("新增用户'" + dto.getUserName() + "'失败,登录账号已存在"); + } else if (StringUtils.isNotEmpty(dto.getPhonenumber()) && !dmsLoginService.checkPhoneUnique(dto)) { + return JsonResponse.ok().fail("新增用户'" + dto.getUserName() + "'失败,手机号码已存在"); } + dto.setPassword(SecurityUtils.encryptPassword(dto.getPassword())); + adminTenantUserService.insert(dto); + + //切换至从库 + changeDataSource(umsDataSource.getDataSourceKey()); + + //新增从库数据 SysUser user = BeanUtil.copyProperties(dto, SysUser.class); if (!userService.checkUserNameUnique(user)) { return JsonResponse.ok().fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); @@ -90,17 +105,10 @@ public class AdminDmsUserController { user.setPhonenumber(dto.getContactPhone()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); int insert = userService.insertUser(user); - //新增主库 - if (insert > 0) { - DynamicDataSourceContextHolder.setDataSourceType("MASTER"); - if (!dmsLoginService.checkUserNameUnique(dto)) { - return JsonResponse.ok().fail("新增用户'" + dto.getUserName() + "'失败,登录账号已存在"); - } else if (StringUtils.isNotEmpty(dto.getPhonenumber()) && !dmsLoginService.checkPhoneUnique(dto)) { - return JsonResponse.ok().fail("新增用户'" + dto.getUserName() + "'失败,手机号码已存在"); - } - dto.setPassword(user.getPassword()); - adminTenantUserService.insert(dto); - } + + //销毁切换数据源 + removeDataSource(); + return JsonResponse.ok(insert); } @@ -175,4 +183,8 @@ public class AdminDmsUserController { private static void changeDataSource(String key) { DynamicDataSourceContextHolder.setDataSourceType(key); } + + private static void removeDataSource() { + DynamicDataSourceContextHolder.clearDataSourceType(); + } } diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminPmsTreatmentController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminPmsTreatmentController.java index b6dd684b..790e4d1d 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminPmsTreatmentController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminPmsTreatmentController.java @@ -82,7 +82,11 @@ public class AdminPmsTreatmentController { } private static void changeDataSource(String dataSourceKey) { - DynamicDataSourceContextHolder.setDataSourceType(dataSourceKey); + try { + DynamicDataSourceContextHolder.setDataSourceType(dataSourceKey); + }finally { + DynamicDataSourceContextHolder.clearDataSourceType(); + } } // @ApiOperation("导出诊疗档案评估报告") diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ExternalController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ExternalController.java index 67b944c5..57e0476e 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ExternalController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ExternalController.java @@ -88,7 +88,11 @@ public class ExternalController { } private static void changeDataSource(String key) { - DynamicDataSourceContextHolder.setDataSourceType(key); + try { + DynamicDataSourceContextHolder.setDataSourceType(key); + }finally { + DynamicDataSourceContextHolder.clearDataSourceType(); + } } // @Anonymous diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ScreeningController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ScreeningController.java index 7fdcf95b..740d2d5c 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ScreeningController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ScreeningController.java @@ -93,7 +93,11 @@ public class ScreeningController { if (dmsTenant != null) { UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); if (umsDataSource != null) { - DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); + try { + DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); + }finally { + DynamicDataSourceContextHolder.clearDataSourceType(); + } } } } 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 new file mode 100644 index 00000000..1a08d188 --- /dev/null +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java @@ -0,0 +1,211 @@ +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 76f20bed..e063789b 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 @@ -1,329 +1,343 @@ -package com.acupuncture.web.task; - -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.common.core.redis.RedisCache; -import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; -import com.acupuncture.system.domain.dto.FmsFollowupDto; -import com.acupuncture.system.domain.po.FmsFollowupTask; -import com.acupuncture.system.domain.po.FmsFollowupTaskExample; -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 com.acupuncture.system.service.FmsFollowupQueueService; -import com.acupuncture.system.service.FmsFollowupService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.quartz.TriggerUtils; -import org.quartz.impl.triggers.CronTriggerImpl; -import org.quartz.spi.OperableTrigger; -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.*; - -/** - * @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 FmsFollowupService fmsFollowupService; - @Resource - private FmsFollowupTaskMapper fmsFollowupTaskMapper; - @Resource - private UmsDataSourceDao umsDataSourceDao; - @Resource - private FmsPatientQueueRelationMapper fmsPatientQueueRelationMapper; - @Resource - private RedisCache redisCache; - @Resource - private FmsFollowupQueueService fmsFollowupQueueService; - - @ApiOperation("定时任务添加随访工单") - @PostMapping("/task") - @Scheduled(cron = "0 0 0 * * ?") - @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 = redisCache.getCacheList("common_followup_queue"); - List followupQueueVOS = new ArrayList<>(); - if (CollectionUtil.isEmpty(queueResults)) { - followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null); - } -// List queueResults = fmsFollowupDao.queryCommonQueue(null); - //切换数据源 - for (UmsDataSourceVo.Result result : query) { - if ("MASTER".equals(result.getDataSourceKey()) || "SXYFYY".equals(result.getDataSourceKey())) { - continue; - } - changeDataSource(result); - { - //获取随访患者列表,根据患者出院日时间和队列添加工单 - //1. 查询队列 - List queueList = fmsFollowupDao.selectQueueList(null, null, null, null); - - if (CollectionUtil.isEmpty(queueList)) { - if (CollectionUtil.isEmpty(queueResults)) { - queueList = followupQueueVOS; - } - } else { - if (CollectionUtil.isEmpty(queueResults)) { - 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 patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO); -// List 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 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 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 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); - } - } - } - - } - } - } - - private static void changeDataSource(UmsDataSourceVo.Result result) { - DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); - } - - /** - * 法用于计算在指定时间范围内触发器的触发时间点。具体步骤如下: - * 初始化一个空列表 lst 存储触发时间点。 - * 克隆传入的触发器 trigg,并检查其下一个触发时间是否为空。如果为空,则设置开始时间和结束时间,并计算首次触发时间。 - * 使用 while 循环遍历触发器的触发时间点,直到没有更多触发时间或超出指定范围。 - * 如果触发时间在指定范围内,则将其添加到列表中,并更新触发器状态。 - * - * @param trigg cron表达式 - * @param from 患者出院时间 - * @param to 患者出院时间 + 随访总月数 - * @return - */ - public static List computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) { - LinkedList lst = new LinkedList(); - OperableTrigger t = (OperableTrigger) trigg.clone(); - if (t.getNextFireTime() == null) { - t.setStartTime(from); - t.setEndTime(to); - t.computeFirstFireTime(cal); - } - - while (true) { - Date d = t.getNextFireTime(); - if (d == null) { - break; - } - - if (d.before(from)) { - t.triggered(cal); - } else { - if (d.after(to)) { - break; - } - lst.add(d); - t.triggered(cal); - } - } - return Collections.unmodifiableList(lst); - } - - /** - * 返回当前时间之后的第一个date及对应顺序 - * - * @param dateList key 为顺序,value 为时间 - * @return - */ - public static DateComparator getDate(List dateList) { - Date today = new Date(); - DateComparator dateComparator = new DateComparator(); - for (int i = 0; i < dateList.size(); i++) { - Date date = dateList.get(i); - if (date.after(today)) { - dateComparator.setDate(date); - dateComparator.setIndex(i + 1); - return dateComparator; - } - } - return dateComparator; - } - - @Data - public static class DateComparator { - private Date date; - private Integer index; - } -} +//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.common.core.redis.RedisCache; +//import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; +//import com.acupuncture.system.domain.dto.FmsFollowupDto; +//import com.acupuncture.system.domain.po.FmsFollowupTask; +//import com.acupuncture.system.domain.po.FmsFollowupTaskExample; +//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 com.acupuncture.system.service.FmsFollowupQueueService; +//import com.acupuncture.system.service.FmsFollowupService; +//import io.swagger.annotations.Api; +//import io.swagger.annotations.ApiOperation; +//import lombok.Data; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.catalina.connector.Response; +//import org.quartz.TriggerUtils; +//import org.quartz.impl.triggers.CronTriggerImpl; +//import org.quartz.spi.OperableTrigger; +//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 javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.util.*; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +// +///** +// * @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 FmsFollowupService fmsFollowupService; +// @Resource +// private FmsFollowupTaskMapper fmsFollowupTaskMapper; +// @Resource +// private UmsDataSourceDao umsDataSourceDao; +// @Resource +// private RedisCache redisCache; +// @Resource +// private FmsFollowupQueueService fmsFollowupQueueService; +// +// @ApiOperation("定时任务添加随访工单") +// @PostMapping("/task") +// @Scheduled(fixedDelay = 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 = redisCache.getCacheList("common_followup_queue"); +// List followupQueueVOS = new ArrayList<>(); +// if (CollectionUtil.isEmpty(queueResults)) { +// +// followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null); +// } +//// List queueResults = fmsFollowupDao.queryCommonQueue(null); +// //切换数据源 +//// for (UmsDataSourceVo.Result result : query) { +//// if ("MASTER".equals(result.getDataSourceKey()) || "PROD_YY".equals(result.getDataSourceKey())) { +//// continue; +//// } +//// changeDataSource(result); +// { +// //获取随访患者列表,根据患者出院日时间和队列添加工单 +// //1. 查询队列 +// List queueList = fmsFollowupDao.selectQueueList(null, null, null, null); +// +// if (CollectionUtil.isEmpty(queueList)) { +// if (CollectionUtil.isEmpty(queueResults)) { +// queueList = followupQueueVOS; +// } +// } else { +// if (CollectionUtil.isEmpty(queueResults)) { +// 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 patientList = fmsFollowupService.queryTaskPatient(followupPatientQueryDTO); +//// List 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 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 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 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); +// } +// } +// } +// } +// } +// +// private static void changeDataSource(UmsDataSourceVo.Result result) { +// try { +// DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); +// } finally { +// DynamicDataSourceContextHolder.clearDataSourceType(); +// } +// } +// +// public String getName(String url) { +// Pattern pattern = Pattern.compile("jdbc:mysql://[^/]+/([^?]+)"); +// Matcher matcher = pattern.matcher(url); +// if (matcher.find()) { +// String dbName = matcher.group(1); // 输出 acupuncture_yfyy +// System.out.println("数据库名称: " + dbName); +// return dbName; +// } +// return ""; +// } +// +// /** +// * 法用于计算在指定时间范围内触发器的触发时间点。具体步骤如下: +// * 初始化一个空列表 lst 存储触发时间点。 +// * 克隆传入的触发器 trigg,并检查其下一个触发时间是否为空。如果为空,则设置开始时间和结束时间,并计算首次触发时间。 +// * 使用 while 循环遍历触发器的触发时间点,直到没有更多触发时间或超出指定范围。 +// * 如果触发时间在指定范围内,则将其添加到列表中,并更新触发器状态。 +// * +// * @param trigg cron表达式 +// * @param from 患者出院时间 +// * @param to 患者出院时间 + 随访总月数 +// * @return +// */ +// public static List computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) { +// LinkedList lst = new LinkedList(); +// OperableTrigger t = (OperableTrigger) trigg.clone(); +// if (t.getNextFireTime() == null) { +// t.setStartTime(from); +// t.setEndTime(to); +// t.computeFirstFireTime(cal); +// } +// +// while (true) { +// Date d = t.getNextFireTime(); +// if (d == null) { +// break; +// } +// +// if (d.before(from)) { +// t.triggered(cal); +// } else { +// if (d.after(to)) { +// break; +// } +// lst.add(d); +// t.triggered(cal); +// } +// } +// return Collections.unmodifiableList(lst); +// } +// +// /** +// * 返回当前时间之后的第一个date及对应顺序 +// * +// * @param dateList key 为顺序,value 为时间 +// * @return +// */ +// public static DateComparator getDate(List dateList) { +// Date today = new Date(); +// DateComparator dateComparator = new DateComparator(); +// for (int i = 0; i < dateList.size(); i++) { +// Date date = dateList.get(i); +// if (date.after(today)) { +// dateComparator.setDate(date); +// dateComparator.setIndex(i + 1); +// return dateComparator; +// } +// } +// return dateComparator; +// } +// +// @Data +// public static class DateComparator { +// private Date date; +// private Integer index; +// } +//} diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController1.java b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController1.java index 51183752..1cac10d9 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController1.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController1.java @@ -65,7 +65,7 @@ //// UmsDataSourceVo.Result result1 = new UmsDataSourceVo.Result(); //// result1.setDataSourceKey("MASTER"); //// changeDataSource(result1); -// List query = umsDataSourceDao.query(); +// List query = umsDataSourceDao.query(null); // if (CollectionUtil.isEmpty(query)) { // return; // } @@ -80,7 +80,7 @@ // { // //获取随访患者列表,根据患者出院日时间和队列添加工单 // //1. 查询队列 -// List queueList = fmsFollowupDao.selectQueueList(null, null, null); +// List queueList = fmsFollowupDao.selectQueueList(null, null, null, result.getTenantId()); // // if (CollectionUtil.isEmpty(queueList)) { // queueList = queueResults; @@ -89,7 +89,7 @@ // } // for (FmsFollowupVo.FollowupQueueVO followupQueueVO : queueList) { // //2. 查询队列随访患者列表 -// List patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), (byte) 0, null); +// List patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), (byte) 0, null, followupQueueVO.getTenantId()); // if (CollectionUtil.isEmpty(patientList)) { // continue; // } diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController2.java b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController2.java new file mode 100644 index 00000000..5c7f8a16 --- /dev/null +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController2.java @@ -0,0 +1,340 @@ +//package com.acupuncture.web.task; +// +//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.common.core.redis.RedisCache; +//import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; +//import com.acupuncture.system.domain.dto.FmsFollowupDto; +//import com.acupuncture.system.domain.po.FmsFollowupTask; +//import com.acupuncture.system.domain.po.FmsFollowupTaskExample; +//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.service.FmsFollowupQueueService; +//import com.acupuncture.system.service.FmsFollowupService; +//import io.swagger.annotations.Api; +//import io.swagger.annotations.ApiOperation; +//import lombok.Data; +//import lombok.extern.slf4j.Slf4j; +//import org.quartz.TriggerUtils; +//import org.quartz.impl.triggers.CronTriggerImpl; +//import org.quartz.spi.OperableTrigger; +//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.*; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +// +///** +// * @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 FmsFollowupService fmsFollowupService; +// @Resource +// private FmsFollowupTaskMapper fmsFollowupTaskMapper; +// @Resource +// private UmsDataSourceDao umsDataSourceDao; +// @Resource +// private RedisCache redisCache; +// @Resource +// private FmsFollowupQueueService fmsFollowupQueueService; +// +// @ApiOperation("定时任务添加随访工单") +// @PostMapping("/task") +// @Scheduled(fixedDelay = 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 = redisCache.getCacheList("common_followup_queue"); +// List followupQueueVOS = new ArrayList<>(); +// if (CollectionUtil.isEmpty(queueResults)) { +// +// followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null); +// } +//// List queueResults = fmsFollowupDao.queryCommonQueue(null); +// //切换数据源 +// for (UmsDataSourceVo.Result result : query) { +// if ("MASTER".equals(result.getDataSourceKey()) || "PROD_YY".equals(result.getDataSourceKey())) { +// continue; +// } +// changeDataSource(result); +// { +// //获取随访患者列表,根据患者出院日时间和队列添加工单 +// //1. 查询队列 +// List queueList = fmsFollowupDao.selectQueueList(null, null, null, null); +// +// if (CollectionUtil.isEmpty(queueList)) { +// if (CollectionUtil.isEmpty(queueResults)) { +// queueList = followupQueueVOS; +// } +// } else { +// if (CollectionUtil.isEmpty(queueResults)) { +// 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 patientList = fmsFollowupService.queryTaskPatient(followupPatientQueryDTO); +//// List 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 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 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 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); +// } +// } +// } +// +// } +// } +// } +// +// private static void changeDataSource(UmsDataSourceVo.Result result) { +// try { +// DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); +// }finally { +// DynamicDataSourceContextHolder.clearDataSourceType(); +// } +// } +// +// public String getName(String url){ +// Pattern pattern = Pattern.compile("jdbc:mysql://[^/]+/([^?]+)"); +// Matcher matcher = pattern.matcher(url); +// if (matcher.find()) { +// String dbName = matcher.group(1); // 输出 acupuncture_yfyy +// System.out.println("数据库名称: " + dbName); +// return dbName; +// } +// return ""; +// } +// +// /** +// * 法用于计算在指定时间范围内触发器的触发时间点。具体步骤如下: +// * 初始化一个空列表 lst 存储触发时间点。 +// * 克隆传入的触发器 trigg,并检查其下一个触发时间是否为空。如果为空,则设置开始时间和结束时间,并计算首次触发时间。 +// * 使用 while 循环遍历触发器的触发时间点,直到没有更多触发时间或超出指定范围。 +// * 如果触发时间在指定范围内,则将其添加到列表中,并更新触发器状态。 +// * +// * @param trigg cron表达式 +// * @param from 患者出院时间 +// * @param to 患者出院时间 + 随访总月数 +// * @return +// */ +// public static List computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) { +// LinkedList lst = new LinkedList(); +// OperableTrigger t = (OperableTrigger) trigg.clone(); +// if (t.getNextFireTime() == null) { +// t.setStartTime(from); +// t.setEndTime(to); +// t.computeFirstFireTime(cal); +// } +// +// while (true) { +// Date d = t.getNextFireTime(); +// if (d == null) { +// break; +// } +// +// if (d.before(from)) { +// t.triggered(cal); +// } else { +// if (d.after(to)) { +// break; +// } +// lst.add(d); +// t.triggered(cal); +// } +// } +// return Collections.unmodifiableList(lst); +// } +// +// /** +// * 返回当前时间之后的第一个date及对应顺序 +// * +// * @param dateList key 为顺序,value 为时间 +// * @return +// */ +// public static DateComparator getDate(List dateList) { +// Date today = new Date(); +// DateComparator dateComparator = new DateComparator(); +// for (int i = 0; i < dateList.size(); i++) { +// Date date = dateList.get(i); +// if (date.after(today)) { +// dateComparator.setDate(date); +// dateComparator.setIndex(i + 1); +// return dateComparator; +// } +// } +// return dateComparator; +// } +// +// @Data +// public static class DateComparator { +// private Date date; +// private Integer index; +// } +//} diff --git a/acupuncture-common/src/main/java/com/acupuncture/common/core/domain/entity/SysUser.java b/acupuncture-common/src/main/java/com/acupuncture/common/core/domain/entity/SysUser.java index 997b8617..697a56b5 100644 --- a/acupuncture-common/src/main/java/com/acupuncture/common/core/domain/entity/SysUser.java +++ b/acupuncture-common/src/main/java/com/acupuncture/common/core/domain/entity/SysUser.java @@ -3,6 +3,8 @@ package com.acupuncture.common.core.domain.entity; import java.util.Date; import java.util.List; import javax.validation.constraints.*; + +import io.swagger.annotations.ApiModelProperty; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.acupuncture.common.annotation.Excel; @@ -96,11 +98,22 @@ public class SysUser extends BaseEntity private String tenantPhone; private Long scoreId; + @ApiModelProperty("是否具有审核权限(0不具有; 1具有)") + private Byte slaverAdmin; + public SysUser() { } + public Byte getSlaverAdmin() { + return slaverAdmin; + } + + public void setSlaverAdmin(Byte slaverAdmin) { + this.slaverAdmin = slaverAdmin; + } + public String getTenantPhone() { return tenantPhone; } diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/AdminGlobalDataSourceAspect.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/AdminGlobalDataSourceAspect.java index dbe8ad4c..a91afe01 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/AdminGlobalDataSourceAspect.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/AdminGlobalDataSourceAspect.java @@ -1,11 +1,13 @@ package com.acupuncture.framework.aspectj; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.acupuncture.common.constant.UserConstants; import com.acupuncture.common.exception.base.BaseException; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.common.utils.StringUtils; import com.acupuncture.framework.datasource.DataSourceManager; +import com.acupuncture.framework.datasource.DynamicDataSource; import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; import com.acupuncture.system.domain.po.UmsDataSource; import com.acupuncture.system.mapper.SysUserMapper; @@ -42,7 +44,7 @@ public class AdminGlobalDataSourceAspect { private static final String DATASOURCE_NOT_FOUND = "未找到数据源"; - @Pointcut("(execution(* com.acupuncture.web.controller..*.*(..))) && !@annotation(com.acupuncture.common.annotation.DataSource)") + @Pointcut("((execution(* com.acupuncture.web.controller..*.*(..))) && !@annotation(com.acupuncture.common.annotation.DataSource))") public void dsPointCut() { } @@ -68,8 +70,14 @@ public class AdminGlobalDataSourceAspect { */ public String getDataSource(ProceedingJoinPoint point) { // 获取请求携带的令牌 - HttpServletRequest request = ((ServletRequestAttributes) - RequestContextHolder.getRequestAttributes()).getRequest(); + ServletRequestAttributes requestAttributes = (ServletRequestAttributes) + RequestContextHolder.getRequestAttributes(); + HttpServletRequest request; + if (requestAttributes == null) { + DynamicDataSourceContextHolder.getDataSourceType(); + return DynamicDataSourceContextHolder.getDataSourceType(); + } + request = requestAttributes.getRequest(); //token为空 Long tenantId; String header = request.getHeader(UserConstants.DEPT); @@ -87,10 +95,7 @@ public class AdminGlobalDataSourceAspect { } } - //设置所属医院和数据源 -// SecurityUtils.setCurrentHospitalId(Long.parseLong(deptId)); - -// // 获取当前的用户 + //设置所属医院和数据源l // LoginUser loginUser = SecurityUtils.getLoginUser(); // if(ObjectUtil.isNull(loginUser) || loginUser.getUser().isAdmin()){ // return null; 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 1ef9e3fd..df745c47 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,7 +28,8 @@ 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.common.annotation.DataSource)" + + "|| within(com.acupuncture.web.task.TaskController)") public void dsPointCut() { diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/AdminTenantUserDto.java b/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/AdminTenantUserDto.java index ea3dfb94..c61d02ba 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/AdminTenantUserDto.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/AdminTenantUserDto.java @@ -3,6 +3,7 @@ package com.acupuncture.system.domain.dto; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.system.domain.po.DmsUser; import com.acupuncture.system.service.AdminTenantUserService; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; @@ -36,6 +37,8 @@ public class AdminTenantUserDto { private String status; private String contactPhone; + @ApiModelProperty("是否具有审核权限(0不具有; 1具有)") + private Byte slaverAdmin; // // public Long getTenantId() { // return SecurityUtils.getTenantId(); @@ -61,6 +64,9 @@ public class AdminTenantUserDto { private String status; private String contactPhone; + + @ApiModelProperty("是否具有审核权限(0不具有; 1具有)") + private Byte slaverAdmin; } @Data diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/FmsFollowupDto.java b/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/FmsFollowupDto.java index 11cba362..a9edf086 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/FmsFollowupDto.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/FmsFollowupDto.java @@ -128,6 +128,8 @@ public class FmsFollowupDto { private Integer haveQueue; private Long tenantId; + private String dataScore; + } // FollowupTaskQueryDTO.java diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/domain/vo/StatisticsVo.java b/acupuncture-system/src/main/java/com/acupuncture/system/domain/vo/StatisticsVo.java index 0e7bb4f3..15bb9ce5 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/domain/vo/StatisticsVo.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/domain/vo/StatisticsVo.java @@ -97,6 +97,13 @@ public class StatisticsVo { @ApiModelProperty("其他") private Integer other; + @ApiModelProperty("多囊卵巢综合症") + private Integer dnlczhz; + @ApiModelProperty("胰岛素抵抗") + private Integer ydsdk; + @ApiModelProperty("高尿酸") + private Integer gns; + } } diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/FmsFollowupDao.java b/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/FmsFollowupDao.java index 5905ce39..8c5cfaab 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/FmsFollowupDao.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/FmsFollowupDao.java @@ -44,6 +44,13 @@ public interface FmsFollowupDao { @Param("haveQueue")Integer haveQueue, @Param("tenantId") Long tenantId); + @DataSource(DataSourceType.MASTER) + List queryTaskPatient(@Param("id") Long id, + @Param("taskFlag") Byte taskFlag, + @Param("haveQueue")Integer haveQueue, + @Param("tenantId") Long tenantId, + @Param("dataScore") String dataScore); + List adminQueryPatient(@Param("id") Long id, @Param("taskFlag") Byte taskFlag, @Param("haveQueue")Integer haveQueue, diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java index ee6d2cf5..0e32835b 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java @@ -51,6 +51,14 @@ public interface FmsFollowupService { */ List queryPatient(FmsFollowupDto.FollowupPatientQueryDTO dto); + /** + * 查询随访患者 + * @param dto + * @return + */ + @DataSource(DataSourceType.MASTER) + List queryTaskPatient(FmsFollowupDto.FollowupPatientQueryDTO dto); + /** * 更新随访患者 * @param dto diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/AdminStatisticsServiceImpl.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/AdminStatisticsServiceImpl.java index 5fd3ce1a..2319faf4 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/AdminStatisticsServiceImpl.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/AdminStatisticsServiceImpl.java @@ -107,6 +107,7 @@ public class AdminStatisticsServiceImpl implements AdminStatisticsService { txfbVo.setFpx(diseaseCountMap.getOrDefault("肥胖型", 0)); txfbVo.setYxfpz(diseaseCountMap.getOrDefault("隐形肥胖型", 0)); txfbVo.setZfgdx(diseaseCountMap.getOrDefault("脂肪过多型", 0)); + txfbVo.setJkjcx(diseaseCountMap.getOrDefault("健康匀称型", 0)); txfbVo.setDzfx(diseaseCountMap.getOrDefault("低脂肪型", 0)); txfbVo.setYdyx(diseaseCountMap.getOrDefault("运动员型", 0)); txfbVo.setXsx(diseaseCountMap.getOrDefault("消瘦型", 0)); diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/FmsFollowupServiceImpl.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/FmsFollowupServiceImpl.java index 9b6131a4..239cbbdb 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/FmsFollowupServiceImpl.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/FmsFollowupServiceImpl.java @@ -3,7 +3,9 @@ package com.acupuncture.system.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.IdUtil; +import com.acupuncture.common.annotation.DataSource; import com.acupuncture.common.core.redis.RedisCache; +import com.acupuncture.common.enums.DataSourceType; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.system.domain.dto.FmsFollowupDto; import com.acupuncture.system.domain.po.*; @@ -125,6 +127,42 @@ public class FmsFollowupServiceImpl implements FmsFollowupService { return followupPatients; } + + @Override + @DataSource(DataSourceType.MASTER) + public List queryTaskPatient(FmsFollowupDto.FollowupPatientQueryDTO dto) { + List followupPatients = fmsFollowupDao.queryTaskPatient(dto.getQueueId(), null, dto.getHaveQueue(), dto.getTenantId(), dto.getDataScore()); + if (CollectionUtil.isNotEmpty(followupPatients)) { + List commonFollowupQueue = redisCache.getCacheList("common_followup_queue"); + for (FmsFollowupVo.FollowupPatient followupPatient : followupPatients) { + if (CollectionUtil.isNotEmpty(followupPatient.getQueueList())) { + + List queueVos = fmsFollowupDao.queryQueueListByPatientId(followupPatient.getPatientId()); + List queueVoList = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(queueVos)) { + queueVoList = BeanUtil.copyToList(queueVos, FmsFollowupVo.FollowupPatient.QueueVo.class); + Map map = new HashMap<>(); + if (CollectionUtil.isNotEmpty(commonFollowupQueue)) { + List followupQueueVOS1 = BeanUtil.copyToList(commonFollowupQueue, FmsFollowupVo.FollowupQueueVO.class); + map = followupQueueVOS1.stream().collect(Collectors.toMap(FmsFollowupVo.FollowupQueueVO::getId, Function.identity())); + } + for (FmsFollowupVo.FollowupPatient.QueueVo queueVo : queueVoList) { + if (queueVo == null || queueVo.getQueueId() == null) { + continue; + } + FmsFollowupVo.FollowupQueueVO followupQueueVO = map.get(queueVo.getQueueId()); + if (followupQueueVO != null) { + queueVo.setQueueName(followupQueueVO.getName()); + } + } + } + followupPatient.setQueueList(queueVoList); + } + } + } + return followupPatients; + } + @Override public Integer updPatient(FmsFollowupDto.UpdPatient dto) { FmsPatientQueueRelationExample fmsPatientQueueRelationExample = new FmsPatientQueueRelationExample(); diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/PmsPatientServiceImpl.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/PmsPatientServiceImpl.java index 06a526c9..e765fdbe 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/PmsPatientServiceImpl.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/PmsPatientServiceImpl.java @@ -14,11 +14,13 @@ import com.acupuncture.common.exception.base.BaseException; import com.acupuncture.common.utils.ExceptionUtil; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.system.domain.dto.PmsPatientDto; -import com.acupuncture.system.domain.po.PmsPatient; -import com.acupuncture.system.domain.po.PmsPatientExample; +import com.acupuncture.system.domain.po.*; import com.acupuncture.system.domain.vo.PmsPatientVo; import com.acupuncture.system.persist.dao.PmsPatientDao; +import com.acupuncture.system.persist.mapper.FmsPatientQueueRelationMapper; import com.acupuncture.system.persist.mapper.PmsPatientMapper; +import com.acupuncture.system.persist.mapper.PmsTreatmentMapper; +import com.acupuncture.system.persist.mapper.ScrScreeningRecordMapper; import com.acupuncture.system.service.PmsPatientService; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -49,6 +51,12 @@ public class PmsPatientServiceImpl implements PmsPatientService { private PmsPatientMapper pmsPatientMapper; @Resource private PmsPatientDao pmsPatientDao; + @Resource + private PmsTreatmentMapper pmsTreatmentMapper; + @Resource + private ScrScreeningRecordMapper scrScreeningRecordMapper; + @Resource + private FmsPatientQueueRelationMapper fmsPatientQueueRelationMapper; @Value("${file.PatientTemplate}") private String patientTemplate; @@ -88,7 +96,41 @@ public class PmsPatientServiceImpl implements PmsPatientService { pmsPatient.setUpdateTime(new Date()); pmsPatient.setPinyinFull(PinyinUtil.getPinyin(dto.getName(), "")); pmsPatient.setPinyinSimple(PinyinUtil.getFirstLetter(dto.getName(), "")); - return pmsPatientMapper.updateByPrimaryKeySelective(pmsPatient); + int i = pmsPatientMapper.updateByPrimaryKeySelective(pmsPatient); + + //修改诊疗档案基本信息 + PmsTreatmentExample pmsTreatmentExample = new PmsTreatmentExample(); + pmsTreatmentExample.createCriteria().andPatientIdEqualTo(pmsPatient.getId()).andDelFlagEqualTo((byte) 0); + List pmsTreatments = pmsTreatmentMapper.selectByExample(pmsTreatmentExample); + if (CollectionUtil.isNotEmpty(pmsTreatments)) { + for (PmsTreatment pmsTreatment : pmsTreatments) { + BeanUtil.copyProperties(dto, pmsTreatment, "id"); + pmsTreatmentMapper.updateByPrimaryKeySelective(pmsTreatment); + } + } +// //修改筛查对象基本信息 +// ScrScreeningRecordExample scrScreeningRecordExample = new ScrScreeningRecordExample(); +// scrScreeningRecordExample.createCriteria().andNameEqualTo(dto.getName()).andPhoneEqualTo(dto.getPhone()).andDelFlagEqualTo((byte) 0); +// List scrScreeningRecords = scrScreeningRecordMapper.selectByExample(scrScreeningRecordExample); +// if (CollectionUtil.isNotEmpty(scrScreeningRecords)) { +// for (ScrScreeningRecord scrScreeningRecord : scrScreeningRecords) { +// BeanUtil.copyProperties(dto, scrScreeningRecord, "id"); +// scrScreeningRecordMapper.updateByPrimaryKeySelective(scrScreeningRecord); +// } +// } + + //修改随访队列基本信息 + FmsPatientQueueRelationExample fmsPatientQueueRelationExample = new FmsPatientQueueRelationExample(); + fmsPatientQueueRelationExample.createCriteria().andPatientIdEqualTo(pmsPatient.getId()).andDelFlagEqualTo((byte) 0); + List fmsPatientQueueRelations = fmsPatientQueueRelationMapper.selectByExample(fmsPatientQueueRelationExample); + if (CollectionUtil.isNotEmpty(fmsPatientQueueRelations)) { + for (FmsPatientQueueRelation fmsPatientQueueRelation : fmsPatientQueueRelations) { + BeanUtil.copyProperties(dto, fmsPatientQueueRelation, "id"); + fmsPatientQueueRelationMapper.updateByPrimaryKeySelective(fmsPatientQueueRelation); + } + } + + return i; } @Override diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/ScreeningServiceImpl.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/ScreeningServiceImpl.java index 17610c69..e0c2c4ca 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/ScreeningServiceImpl.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/ScreeningServiceImpl.java @@ -422,7 +422,7 @@ public class ScreeningServiceImpl implements IScreeningService { ScrScreeningDetailExample scrScreeningDetailExample = new ScrScreeningDetailExample(); scrScreeningDetailExample.createCriteria().andDelFlagEqualTo((byte) 0).andRecordIdEqualTo(param.getDetailId()) .andQuestionCodeIn(CollectionUtil.newArrayList("SCWJ-NAME", "SCWJ-SEX", "SCWJ-BIRTH", - "SCWJ-AGE", "SCWJ-PHONE")); + "SCWJ-AGE", "SCWJ-PHONE", "SCWJ-XBS")); List scrScreeningDetails = screeningDetailDao.selectByExample(scrScreeningDetailExample); if (CollectionUtil.isNotEmpty(scrScreeningDetails)) { Map map = scrScreeningDetails.stream().collect(Collectors.toMap(ScrScreeningDetail::getQuestionCode, Function.identity())); @@ -448,6 +448,12 @@ public class ScreeningServiceImpl implements IScreeningService { pmsPatient.setTenantId(detail.getTenantId()); pmsPatient.setPinyinSimple(PinyinUtil.getFirstLetter(pmsPatient.getName(), "")); pmsPatient.setPinyinFull(PinyinUtil.getPinyin(pmsPatient.getName())); + if (ObjectUtil.isNotNull(map.get("SCWJ-XBS"))) { + pmsPatient.setCurrentIllnessHistory(map.get("SCWJ-XBS").getAnswer()); + } + if (ObjectUtil.isNotNull(map.get("SCWJ-XBS-QT"))) { + pmsPatient.setCurrentIllnessHistory(map.get("SCWJ-XBS-QT").getAnswer()); + } pmsPatient.setSource((byte) 0); pmsPatient.setDelFlag((byte) 0); pmsPatient.setCreateTime(new Date()); diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/StatisticsServiceImpl.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/StatisticsServiceImpl.java index 869299fc..14db889a 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/StatisticsServiceImpl.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/impl/StatisticsServiceImpl.java @@ -92,6 +92,7 @@ public class StatisticsServiceImpl implements StatisticsService { txfbVo.setCzjrx(diseaseCountMap.getOrDefault("超重肌肉型", 0)); txfbVo.setJrbzx(diseaseCountMap.getOrDefault("肌肉不足型", 0)); txfbVo.setFpx(diseaseCountMap.getOrDefault("肥胖型", 0)); + txfbVo.setJkjcx(diseaseCountMap.getOrDefault("健康匀称型", 0)); txfbVo.setYxfpz(diseaseCountMap.getOrDefault("隐形肥胖型", 0)); txfbVo.setZfgdx(diseaseCountMap.getOrDefault("脂肪过多型", 0)); txfbVo.setDzfx(diseaseCountMap.getOrDefault("低脂肪型", 0)); diff --git a/acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml b/acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml index ac387340..401a1d14 100644 --- a/acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml +++ b/acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml @@ -34,6 +34,7 @@ AND t.name like concat('%',#{dto.tenantName},'%') +order by u.create_time desc diff --git a/acupuncture-system/src/main/resources/mapper/dao/AdminTongjiDao.xml b/acupuncture-system/src/main/resources/mapper/dao/AdminTongjiDao.xml index 0737bc21..f8e27163 100644 --- a/acupuncture-system/src/main/resources/mapper/dao/AdminTongjiDao.xml +++ b/acupuncture-system/src/main/resources/mapper/dao/AdminTongjiDao.xml @@ -124,6 +124,7 @@ r.question_code = 'JBXX_ZYZD' and r.del_flag = 0 + and t.status = 2 and t.del_flag = 0 AND t.tenant_id = #{tenantId} @@ -174,6 +175,7 @@ question_code = 'PG_RTCF_TXLX' AND r.del_flag = 0 and t.del_flag = 0 + and t.status = 2 AND tenant_id = #{tenantId} @@ -203,6 +205,7 @@ v_pms_treatment_record r on t.id = r.treatment_id WHERE question_code = 'PG_TZBS_ZYTZ' + and t.status = 2 AND r.del_flag = 0 and t.del_flag = 0 AND t.tenant_id = #{tenantId} @@ -224,6 +227,7 @@ LEFT JOIN v_pms_treatment_record r ON t.id = r.treatment_id WHERE question_code = 'ZLFA_ZLLX' + and t.status = 2 AND t.del_flag = 0 AND t.del_flag = 0 @@ -251,6 +255,7 @@ WHERE question_code IN ( 'ZLFA_XWXLGY', 'ZLFA_YDGY', 'ZLFA_LCYYZL', 'ZLFA_ZJ', 'ZLFA_ZL' ) AND r.del_flag = 0 + and t.status = 2 AND t.tenant_id = #{tenantId} @@ -275,6 +280,7 @@ WHERE question_code = 'ZLFA_ZLXG' AND t.del_flag = 0 + and t.status = 2 and r.del_flag = 0 AND t.tenant_id = #{tenantId} @@ -301,6 +307,7 @@ question_code = 'ZLFA_ZTFY' AND t.del_flag = 0 and r.del_flag = 0 + and t.status = 2 AND answer REGEXP '^[0-9]+$'; AND t.tenant_id = #{tenantId} @@ -376,6 +383,7 @@ v_pms_treatment_record r on t.id = r.treatment_id WHERE question_code = 'PG_TT_TAPS_DF' + and t.status = 2 AND t.del_flag = 0 and r.del_flag = 0 AND t.tenant_id = #{tenantId} @@ -400,6 +408,7 @@ WHERE question_code = 'PG_SM_PHQ-9_DF' AND t.del_flag = 0 and r.del_flag = 0 + and t.status = 2 AND t.tenant_id = #{tenantId} @@ -421,6 +430,7 @@ v_pms_treatment_record r on t.id = r.treatment_id WHERE question_code = 'PG_JL_HAMD-24_DF' AND t.del_flag = 0 + and t.status = 2 and r.del_flag = 0 AND t.tenant_id = #{tenantId} @@ -446,6 +456,7 @@ WHERE question_code IN ( 'ZLFA_XWXLGY', 'ZLFA_YDGY', 'ZLFA_LCYYZL', 'ZLFA_ZJ', 'ZLFA_ZL' ) AND r.del_flag = 0 + and t.status = 2 AND tenant_id = #{tenantId} @@ -466,6 +477,7 @@ WHERE r.question_code = 'PG_RTCF_TXLX' and t.del_flag = 0 and r.del_flag = 0 + and t.status = 2 AND tenant_id = #{tenantId} diff --git a/acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml b/acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml index a05ab2e6..2f113010 100644 --- a/acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml +++ b/acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml @@ -156,6 +156,49 @@ order by r.create_time desc + +