Browse Source

修改租户用户添加逻辑

newMaster
zzc 3 months ago
parent
commit
99c941a1e7
  1. 4
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysUserController.java
  2. 44
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminDmsUserController.java
  3. 4
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/AdminPmsTreatmentController.java
  4. 4
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ExternalController.java
  5. 4
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/ScreeningController.java
  6. 211
      acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/TaskController.java
  7. 672
      acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController.java
  8. 6
      acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController1.java
  9. 340
      acupuncture-admin/src/main/java/com/acupuncture/web/task/TaskController2.java
  10. 13
      acupuncture-common/src/main/java/com/acupuncture/common/core/domain/entity/SysUser.java
  11. 19
      acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/AdminGlobalDataSourceAspect.java
  12. 3
      acupuncture-framework/src/main/java/com/acupuncture/framework/aspectj/DataSourceAspect.java
  13. 6
      acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/AdminTenantUserDto.java
  14. 2
      acupuncture-system/src/main/java/com/acupuncture/system/domain/dto/FmsFollowupDto.java
  15. 7
      acupuncture-system/src/main/java/com/acupuncture/system/domain/vo/StatisticsVo.java
  16. 7
      acupuncture-system/src/main/java/com/acupuncture/system/persist/dao/FmsFollowupDao.java
  17. 8
      acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java
  18. 1
      acupuncture-system/src/main/java/com/acupuncture/system/service/impl/AdminStatisticsServiceImpl.java
  19. 38
      acupuncture-system/src/main/java/com/acupuncture/system/service/impl/FmsFollowupServiceImpl.java
  20. 48
      acupuncture-system/src/main/java/com/acupuncture/system/service/impl/PmsPatientServiceImpl.java
  21. 8
      acupuncture-system/src/main/java/com/acupuncture/system/service/impl/ScreeningServiceImpl.java
  22. 1
      acupuncture-system/src/main/java/com/acupuncture/system/service/impl/StatisticsServiceImpl.java
  23. 1
      acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml
  24. 12
      acupuncture-system/src/main/resources/mapper/dao/AdminTongjiDao.xml
  25. 43
      acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml
  26. 14
      acupuncture-system/src/main/resources/mapper/dao/StatisticsDao.xml
  27. 6
      acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml

4
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) {
try {
DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey());
}finally {
DynamicDataSourceContextHolder.clearDataSourceType();
}
}
}
}

44
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<Integer> insert(@RequestBody @Validated AdminTenantUserDto.AddDto dto) {
//新增分库数据
//切换到分库数据源
//判定租户及数据源是否存在
DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(dto.getTenantId());
if (dmsTenant != null) {
if (dmsTenant == null) {
return JsonResponse.ok().fail("租户不存在");
}
UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId());
if (umsDataSource != null) {
changeDataSource(umsDataSource.getDataSourceKey());
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();
}
}

4
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) {
try {
DynamicDataSourceContextHolder.setDataSourceType(dataSourceKey);
}finally {
DynamicDataSourceContextHolder.clearDataSourceType();
}
}
// @ApiOperation("导出诊疗档案评估报告")

4
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) {
try {
DynamicDataSourceContextHolder.setDataSourceType(key);
}finally {
DynamicDataSourceContextHolder.clearDataSourceType();
}
}
// @Anonymous

4
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) {
try {
DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey());
}finally {
DynamicDataSourceContextHolder.clearDataSourceType();
}
}
}
}

211
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<UmsDataSourceVo.Result> query = umsDataSourceDao.query(null);
if (CollectionUtil.isEmpty(query)) {
return;
}
//查询公共队列
List<FmsFollowupVo.FollowupQueueVO> queueResults = fmsFollowupDao.queryCommonQueue(null);
//切换数据源
for (UmsDataSourceVo.Result result : query) {
if ("MASTER".equals(result.getDataSourceKey())) {
continue;
}
changeDataSource(result);
{
//获取随访患者列表,根据患者出院日时间和队列添加工单
//1. 查询队列
List<FmsFollowupVo.FollowupQueueVO> 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<FmsFollowupVo.FollowupPatient> 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<Date> dateList = new ArrayList<>();
try {
CronTriggerImpl cronTrigger = new CronTriggerImpl();
cronTrigger.setCronExpression(frequency);
//TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time);
if (CollectionUtil.isEmpty(dateList)) {
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
//3. 判断随访类型
if (followupQueueVO.getFollowupType() == 0) {
//单次
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();
}
}
}

672
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<UmsDataSourceVo.Result> query = umsDataSourceDao.query(null);
if (CollectionUtil.isEmpty(query)) {
return;
}
//查询公共队列
List<Object> queueResults = redisCache.getCacheList("common_followup_queue");
List<FmsFollowupVo.FollowupQueueVO> followupQueueVOS = new ArrayList<>();
if (CollectionUtil.isEmpty(queueResults)) {
followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null);
}
// List<FmsFollowupVo.FollowupQueueVO> queueResults = fmsFollowupDao.queryCommonQueue(null);
//切换数据源
for (UmsDataSourceVo.Result result : query) {
if ("MASTER".equals(result.getDataSourceKey()) || "SXYFYY".equals(result.getDataSourceKey())) {
continue;
}
changeDataSource(result);
{
//获取随访患者列表,根据患者出院日时间和队列添加工单
//1. 查询队列
List<FmsFollowupVo.FollowupQueueVO> 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<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO);
// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), null, null);
if (CollectionUtil.isEmpty(patientList)) {
continue;
}
//随访总月数
Integer followupMonth = followupQueueVO.getFollowupMonth();
for (FmsFollowupVo.FollowupPatient followupPatient : patientList) {
//获取随访到期时间 出院时间+随访总月数 = 到期时间
Calendar calendar = Calendar.getInstance();
calendar.setTime(followupPatient.getDischargeTime());
calendar.set(Calendar.MONTH, followupMonth);
Date time = calendar.getTime();
//获取队列信息
String frequency = followupQueueVO.getFrequency();
List<Date> dateList = new ArrayList<>();
try {
CronTriggerImpl cronTrigger = new CronTriggerImpl();
cronTrigger.setCronExpression(frequency);
//TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time);
if (CollectionUtil.isEmpty(dateList)) {
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
//3. 判断随访类型
if (followupQueueVO.getFollowupType() == 0) {
//单次
//判断是否已有该次随访
FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
fmsFollowupTaskExample.createCriteria().andTimesEqualTo(1).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
continue;
}
FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
fmsFollowupTask.setName(followupPatient.getName());
fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
fmsFollowupTask.setGender(followupPatient.getGender());
if (followupPatient.getBirthDate() != null) {
fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
}
fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
fmsFollowupTask.setPhone(followupPatient.getPhone());
fmsFollowupTask.setTenantId(followupPatient.getTenantId());
fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
fmsFollowupTask.setIdCard(followupPatient.getIdCard());
fmsFollowupTask.setTimes(1);
fmsFollowupTask.setQueueId(followupQueueVO.getId());
fmsFollowupTask.setPatientId(followupPatient.getId());
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
fmsFollowupTask.setDelFlag((byte) 0);
fmsFollowupTask.setCreateTime(new Date());
fmsFollowupTask.setStatus((byte) 0);
//计算第一次随访的时间
DateComparator dateComparator = getDate(dateList);
if (dateComparator.getDate() != null) {
fmsFollowupTask.setStartTime(dateComparator.getDate());
}else {
Calendar instance = Calendar.getInstance();
instance.setTime(dateList.get(0));
instance.add(Calendar.DATE, -followWindowAdys / 2);
fmsFollowupTask.setStartTime(instance.getTime());
}
Calendar instance1 = Calendar.getInstance();
instance1.setTime(dateList.get(0));
instance1.add(Calendar.DATE, followWindowAdys / 2);
fmsFollowupTask.setEndTime(instance1.getTime());
fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge());
fmsFollowupTask.setFollowupTime(dateList.get(0));
changeDataSource(result);
fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
} else {
//周期
//4. 根据频次和总月数添加
DateComparator dateComparator = getDate(dateList);
if (dateComparator.getDate() == null || dateComparator.getIndex() == null) {
continue;
}
Date date = dateComparator.getDate();
Integer index = dateComparator.getIndex();
//判断是否已有该次随访
FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
continue;
}
FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
fmsFollowupTask.setName(followupPatient.getName());
fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
fmsFollowupTask.setGender(followupPatient.getGender());
if (followupPatient.getBirthDate() != null) {
fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
}
fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
fmsFollowupTask.setTimes(index);
fmsFollowupTask.setPhone(followupPatient.getPhone());
fmsFollowupTask.setTenantId(followupPatient.getTenantId());
fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
fmsFollowupTask.setIdCard(followupPatient.getIdCard());
fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
fmsFollowupTask.setQueueId(followupQueueVO.getId());
fmsFollowupTask.setDelFlag((byte) 0);
fmsFollowupTask.setCreateTime(new Date());
fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
fmsFollowupTask.setStatus((byte) 0);
fmsFollowupTask.setStartTime(date);
Calendar instance = Calendar.getInstance();
instance.setTime(date);
instance.add(Calendar.DATE, followWindowAdys / 2);
fmsFollowupTask.setEndTime(instance.getTime());
changeDataSource(result);
fmsFollowupTask.setPatientId(followupPatient.getId());
fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
}
}
}
}
}
}
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<Date> computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) {
LinkedList<Date> 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<Date> 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<UmsDataSourceVo.Result> query = umsDataSourceDao.query(null);
//// if (CollectionUtil.isEmpty(query)) {
//// return;
//// }
// //查询公共队列
// List<Object> queueResults = redisCache.getCacheList("common_followup_queue");
// List<FmsFollowupVo.FollowupQueueVO> followupQueueVOS = new ArrayList<>();
// if (CollectionUtil.isEmpty(queueResults)) {
//
// followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null);
// }
//// List<FmsFollowupVo.FollowupQueueVO> queueResults = fmsFollowupDao.queryCommonQueue(null);
// //切换数据源
//// for (UmsDataSourceVo.Result result : query) {
//// if ("MASTER".equals(result.getDataSourceKey()) || "PROD_YY".equals(result.getDataSourceKey())) {
//// continue;
//// }
//// changeDataSource(result);
// {
// //获取随访患者列表,根据患者出院日时间和队列添加工单
// //1. 查询队列
// List<FmsFollowupVo.FollowupQueueVO> 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<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupService.queryTaskPatient(followupPatientQueryDTO);
//// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), null, null);
// if (CollectionUtil.isEmpty(patientList)) {
// continue;
// }
// //随访总月数
// Integer followupMonth = followupQueueVO.getFollowupMonth();
// for (FmsFollowupVo.FollowupPatient followupPatient : patientList) {
// //获取随访到期时间 出院时间+随访总月数 = 到期时间
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(followupPatient.getDischargeTime());
// calendar.set(Calendar.MONTH, followupMonth);
// Date time = calendar.getTime();
//
// //获取队列信息
// String frequency = followupQueueVO.getFrequency();
// List<Date> dateList = new ArrayList<>();
// try {
// CronTriggerImpl cronTrigger = new CronTriggerImpl();
// cronTrigger.setCronExpression(frequency);
// //TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
// dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time);
// if (CollectionUtil.isEmpty(dateList)) {
// continue;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// //3. 判断随访类型
// if (followupQueueVO.getFollowupType() == 0) {
// //单次
// //判断是否已有该次随访
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(1).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
// continue;
// }
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setName(followupPatient.getName());
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
// fmsFollowupTask.setGender(followupPatient.getGender());
// if (followupPatient.getBirthDate() != null) {
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
// }
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setPhone(followupPatient.getPhone());
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
// fmsFollowupTask.setTimes(1);
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
// fmsFollowupTask.setPatientId(followupPatient.getId());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setDelFlag((byte) 0);
// fmsFollowupTask.setCreateTime(new Date());
// fmsFollowupTask.setStatus((byte) 0);
//
// //计算第一次随访的时间
// DateComparator dateComparator = getDate(dateList);
// if (dateComparator.getDate() != null) {
// fmsFollowupTask.setStartTime(dateComparator.getDate());
// } else {
// Calendar instance = Calendar.getInstance();
// instance.setTime(dateList.get(0));
// instance.add(Calendar.DATE, -followWindowAdys / 2);
// fmsFollowupTask.setStartTime(instance.getTime());
// }
// Calendar instance1 = Calendar.getInstance();
// instance1.setTime(dateList.get(0));
// instance1.add(Calendar.DATE, followWindowAdys / 2);
// fmsFollowupTask.setEndTime(instance1.getTime());
// fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge());
// fmsFollowupTask.setFollowupTime(dateList.get(0));
//// changeDataSource(result);
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
//
// } else {
// //周期
// //4. 根据频次和总月数添加
// DateComparator dateComparator = getDate(dateList);
// if (dateComparator.getDate() == null || dateComparator.getIndex() == null) {
// continue;
// }
// Date date = dateComparator.getDate();
// Integer index = dateComparator.getIndex();
//
// //判断是否已有该次随访
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
// continue;
// }
//
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setName(followupPatient.getName());
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
// fmsFollowupTask.setGender(followupPatient.getGender());
// if (followupPatient.getBirthDate() != null) {
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
// }
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setTimes(index);
// fmsFollowupTask.setPhone(followupPatient.getPhone());
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
// fmsFollowupTask.setDelFlag((byte) 0);
// fmsFollowupTask.setCreateTime(new Date());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setStatus((byte) 0);
//
// fmsFollowupTask.setStartTime(date);
// Calendar instance = Calendar.getInstance();
// instance.setTime(date);
// instance.add(Calendar.DATE, followWindowAdys / 2);
//
// fmsFollowupTask.setEndTime(instance.getTime());
//// changeDataSource(result);
// fmsFollowupTask.setPatientId(followupPatient.getId());
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
// }
// }
// }
// }
// }
//
// 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<Date> computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) {
// LinkedList<Date> 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<Date> 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;
// }
//}

6
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<UmsDataSourceVo.Result> query = umsDataSourceDao.query();
// List<UmsDataSourceVo.Result> query = umsDataSourceDao.query(null);
// if (CollectionUtil.isEmpty(query)) {
// return;
// }
@ -80,7 +80,7 @@
// {
// //获取随访患者列表,根据患者出院日时间和队列添加工单
// //1. 查询队列
// List<FmsFollowupVo.FollowupQueueVO> queueList = fmsFollowupDao.selectQueueList(null, null, null);
// List<FmsFollowupVo.FollowupQueueVO> 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<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), (byte) 0, null);
// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), (byte) 0, null, followupQueueVO.getTenantId());
// if (CollectionUtil.isEmpty(patientList)) {
// continue;
// }

340
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<UmsDataSourceVo.Result> query = umsDataSourceDao.query(null);
// if (CollectionUtil.isEmpty(query)) {
// return;
// }
// //查询公共队列
// List<Object> queueResults = redisCache.getCacheList("common_followup_queue");
// List<FmsFollowupVo.FollowupQueueVO> followupQueueVOS = new ArrayList<>();
// if (CollectionUtil.isEmpty(queueResults)) {
//
// followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null);
// }
//// List<FmsFollowupVo.FollowupQueueVO> queueResults = fmsFollowupDao.queryCommonQueue(null);
// //切换数据源
// for (UmsDataSourceVo.Result result : query) {
// if ("MASTER".equals(result.getDataSourceKey()) || "PROD_YY".equals(result.getDataSourceKey())) {
// continue;
// }
// changeDataSource(result);
// {
// //获取随访患者列表,根据患者出院日时间和队列添加工单
// //1. 查询队列
// List<FmsFollowupVo.FollowupQueueVO> 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<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupService.queryTaskPatient(followupPatientQueryDTO);
//// List<FmsFollowupVo.FollowupPatient> patientList = fmsFollowupDao.queryPatient(followupQueueVO.getId(), null, null);
// if (CollectionUtil.isEmpty(patientList)) {
// continue;
// }
// //随访总月数
// Integer followupMonth = followupQueueVO.getFollowupMonth();
// for (FmsFollowupVo.FollowupPatient followupPatient : patientList) {
// //获取随访到期时间 出院时间+随访总月数 = 到期时间
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(followupPatient.getDischargeTime());
// calendar.set(Calendar.MONTH, followupMonth);
// Date time = calendar.getTime();
//
// //获取队列信息
// String frequency = followupQueueVO.getFrequency();
// List<Date> dateList = new ArrayList<>();
// try {
// CronTriggerImpl cronTrigger = new CronTriggerImpl();
// cronTrigger.setCronExpression(frequency);
// //TriggerUtils.computeFireTimesBetween(要计算触发时间的触发器对象, 用于计算触发时间的日历对象, 计算触发时间的起始时间点, 计算触发时间的结束时间点);
// dateList = TriggerUtils.computeFireTimesBetween(cronTrigger, null, followupPatient.getDischargeTime(), time);
// if (CollectionUtil.isEmpty(dateList)) {
// continue;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// //3. 判断随访类型
// if (followupQueueVO.getFollowupType() == 0) {
// //单次
// //判断是否已有该次随访
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(1).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
// continue;
// }
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setName(followupPatient.getName());
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
// fmsFollowupTask.setGender(followupPatient.getGender());
// if (followupPatient.getBirthDate() != null) {
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
// }
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setPhone(followupPatient.getPhone());
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
// fmsFollowupTask.setTimes(1);
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
// fmsFollowupTask.setPatientId(followupPatient.getId());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setDelFlag((byte) 0);
// fmsFollowupTask.setCreateTime(new Date());
// fmsFollowupTask.setStatus((byte) 0);
//
// //计算第一次随访的时间
// DateComparator dateComparator = getDate(dateList);
// if (dateComparator.getDate() != null) {
// fmsFollowupTask.setStartTime(dateComparator.getDate());
// }else {
// Calendar instance = Calendar.getInstance();
// instance.setTime(dateList.get(0));
// instance.add(Calendar.DATE, -followWindowAdys / 2);
// fmsFollowupTask.setStartTime(instance.getTime());
// }
// Calendar instance1 = Calendar.getInstance();
// instance1.setTime(dateList.get(0));
// instance1.add(Calendar.DATE, followWindowAdys / 2);
// fmsFollowupTask.setEndTime(instance1.getTime());
// fmsFollowupTask.setFollowuper(followupQueueVO.getPersonInCharge());
// fmsFollowupTask.setFollowupTime(dateList.get(0));
//// changeDataSource(result);
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
//
// } else {
// //周期
// //4. 根据频次和总月数添加
// DateComparator dateComparator = getDate(dateList);
// if (dateComparator.getDate() == null || dateComparator.getIndex() == null) {
// continue;
// }
// Date date = dateComparator.getDate();
// Integer index = dateComparator.getIndex();
//
// //判断是否已有该次随访
// FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample();
// fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId());
// List<FmsFollowupTask> fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample);
// if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) {
// continue;
// }
//
// FmsFollowupTask fmsFollowupTask = new FmsFollowupTask();
// BeanUtil.copyProperties(followupQueueVO, fmsFollowupTask);
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setName(followupPatient.getName());
// fmsFollowupTask.setPinyinFull(followupPatient.getPinyinFull());
// fmsFollowupTask.setPinyinSimple(followupPatient.getPinyinSimple());
// fmsFollowupTask.setGender(followupPatient.getGender());
// if (followupPatient.getBirthDate() != null) {
// fmsFollowupTask.setAge(DateUtil.age(followupPatient.getBirthDate(), new Date()));
// }
// fmsFollowupTask.setEthnicity(followupPatient.getEthnicity());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setTimes(index);
// fmsFollowupTask.setPhone(followupPatient.getPhone());
// fmsFollowupTask.setTenantId(followupPatient.getTenantId());
// fmsFollowupTask.setIdCardType(followupPatient.getIdCardType());
// fmsFollowupTask.setIdCard(followupPatient.getIdCard());
// fmsFollowupTask.setId(IdUtil.getSnowflakeNextId());
// fmsFollowupTask.setQueueId(followupQueueVO.getId());
// fmsFollowupTask.setDelFlag((byte) 0);
// fmsFollowupTask.setCreateTime(new Date());
// fmsFollowupTask.setEducationYears(followupPatient.getEducationYears());
// fmsFollowupTask.setStatus((byte) 0);
//
// fmsFollowupTask.setStartTime(date);
// Calendar instance = Calendar.getInstance();
// instance.setTime(date);
// instance.add(Calendar.DATE, followWindowAdys / 2);
//
// fmsFollowupTask.setEndTime(instance.getTime());
//// changeDataSource(result);
// fmsFollowupTask.setPatientId(followupPatient.getId());
// fmsFollowupTaskMapper.insertSelective(fmsFollowupTask);
// }
// }
// }
//
// }
// }
// }
//
// 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<Date> computeFireTimesBetween(OperableTrigger trigg, org.quartz.Calendar cal, Date from, Date to) {
// LinkedList<Date> 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<Date> 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;
// }
//}

13
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;
}

19
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;

3
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()
{

6
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

2
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

7
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;
}
}

7
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<FmsFollowupVo.FollowupPatient> queryTaskPatient(@Param("id") Long id,
@Param("taskFlag") Byte taskFlag,
@Param("haveQueue")Integer haveQueue,
@Param("tenantId") Long tenantId,
@Param("dataScore") String dataScore);
List<FmsFollowupVo.FollowupPatient> adminQueryPatient(@Param("id") Long id,
@Param("taskFlag") Byte taskFlag,
@Param("haveQueue")Integer haveQueue,

8
acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupService.java

@ -51,6 +51,14 @@ public interface FmsFollowupService {
*/
List<FmsFollowupVo.FollowupPatient> queryPatient(FmsFollowupDto.FollowupPatientQueryDTO dto);
/**
* 查询随访患者
* @param dto
* @return
*/
@DataSource(DataSourceType.MASTER)
List<FmsFollowupVo.FollowupPatient> queryTaskPatient(FmsFollowupDto.FollowupPatientQueryDTO dto);
/**
* 更新随访患者
* @param dto

1
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));

38
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<FmsFollowupVo.FollowupPatient> queryTaskPatient(FmsFollowupDto.FollowupPatientQueryDTO dto) {
List<FmsFollowupVo.FollowupPatient> followupPatients = fmsFollowupDao.queryTaskPatient(dto.getQueueId(), null, dto.getHaveQueue(), dto.getTenantId(), dto.getDataScore());
if (CollectionUtil.isNotEmpty(followupPatients)) {
List<Object> commonFollowupQueue = redisCache.getCacheList("common_followup_queue");
for (FmsFollowupVo.FollowupPatient followupPatient : followupPatients) {
if (CollectionUtil.isNotEmpty(followupPatient.getQueueList())) {
List<PmsTreatmentVo.TreatmentVO.QueueVo> queueVos = fmsFollowupDao.queryQueueListByPatientId(followupPatient.getPatientId());
List<FmsFollowupVo.FollowupPatient.QueueVo> queueVoList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(queueVos)) {
queueVoList = BeanUtil.copyToList(queueVos, FmsFollowupVo.FollowupPatient.QueueVo.class);
Map<Long, FmsFollowupVo.FollowupQueueVO> map = new HashMap<>();
if (CollectionUtil.isNotEmpty(commonFollowupQueue)) {
List<FmsFollowupVo.FollowupQueueVO> 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();

48
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<PmsTreatment> 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<ScrScreeningRecord> 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<FmsPatientQueueRelation> fmsPatientQueueRelations = fmsPatientQueueRelationMapper.selectByExample(fmsPatientQueueRelationExample);
if (CollectionUtil.isNotEmpty(fmsPatientQueueRelations)) {
for (FmsPatientQueueRelation fmsPatientQueueRelation : fmsPatientQueueRelations) {
BeanUtil.copyProperties(dto, fmsPatientQueueRelation, "id");
fmsPatientQueueRelationMapper.updateByPrimaryKeySelective(fmsPatientQueueRelation);
}
}
return i;
}
@Override

8
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<ScrScreeningDetail> scrScreeningDetails = screeningDetailDao.selectByExample(scrScreeningDetailExample);
if (CollectionUtil.isNotEmpty(scrScreeningDetails)) {
Map<String, ScrScreeningDetail> 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());

1
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));

1
acupuncture-system/src/main/resources/mapper/dao/AdminDmsUserDao.xml

@ -34,6 +34,7 @@
AND t.name like concat('%',#{dto.tenantName},'%')
</if>
</where>
order by u.create_time desc
</select>
</mapper>

12
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
<if test="tenantId != null">
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
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>
@ -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
<if test="tenantId != null">
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
<if test="tenantId != null">
@ -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
<if test="tenantId != null">
AND t.tenant_id = #{tenantId}
</if>
@ -275,6 +280,7 @@
WHERE
question_code = 'ZLFA_ZLXG'
AND t.del_flag = 0
and t.status = 2
and r.del_flag = 0
<if test="tenantId != null">
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]+$';
<if test="tenantId != null">
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
<if test="tenantId != null">
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
<if test="tenantId != null">
AND t.tenant_id = #{tenantId}
</if>
@ -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
<if test="tenantId != null">
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
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>
@ -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
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>

43
acupuncture-system/src/main/resources/mapper/dao/FmsFollowupDao.xml

@ -156,6 +156,49 @@
order by r.create_time desc
</select>
<select id="queryTaskPatient" resultMap="BaseResultMap">
select
r.patient_id as id,
r.queue_id as queueId,
r.name,
r.pinyin_full as pinyinFull,
r.pinyin_simple as pinyinSimple,
r.gender,
r.birth_date as birthDate,
r.ethnicity,
r.education_years as educationYears,
r.phone,
r.discharge_time as dischargeTime,
r.id_card_type as idCardType,
r.id_card as idCard,
r.tenant_id as tenantId,
r.create_by as createBy,
r.create_time as createTime,
q.name as queueName,
q.remind_time as remindTime,
q.follow_window_adys as followWindowAdys
FROM
v_fms_patient_queue_relation r
left join
v_fms_followup_queue q
on r.queue_id = q.id or q.id is null
WHERE r.del_flag = 0
<if test="tenantId != null">
AND r.tenant_id = #{tenantId}
</if>
<if test="haveQueue != null">
AND r.queue_id is null
</if>
<if test="id != null">
AND r.queue_id = #{id}
</if>
<if test="taskFlag != null">
AND r.task_flag = #{taskFlag}
</if>
group by r.patient_id, r.tenant_id
order by r.create_time desc
</select>
<select id="adminQueryPatient" resultMap="BaseResultMap">
select
r.patient_id as id,

14
acupuncture-system/src/main/resources/mapper/dao/StatisticsDao.xml

@ -72,11 +72,14 @@
SUM(CASE WHEN FIND_IN_SET ('糖尿病' ,current_illness_history ) THEN 1 ELSE 0 END) AS tnb, -- 糖尿病
SUM(CASE WHEN FIND_IN_SET ('慢性肺系疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS mxfxjb, -- 慢性肺系疾病
SUM(CASE WHEN FIND_IN_SET ('高脂血症' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzxz, -- 高脂血症
SUM(CASE WHEN FIND_IN_SET ('肝脏疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzjb, -- 肝脏疾病
SUM(CASE WHEN FIND_IN_SET ('肝脏疾病(脂肪肝、乙型肝炎、肝硬化等)' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzjb, -- 肝脏疾病
SUM(CASE WHEN FIND_IN_SET ('过敏性疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS gmxjb, -- 过敏性疾病
SUM(CASE WHEN FIND_IN_SET ('关节炎' ,current_illness_history ) THEN 1 ELSE 0 END) AS gjy, -- 关节炎
SUM(CASE WHEN FIND_IN_SET ('痛风' ,current_illness_history ) THEN 1 ELSE 0 END) AS tf, -- 痛风
SUM(CASE WHEN FIND_IN_SET ('肾炎、肾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS sySb, -- 肾炎、肾病
SUM(CASE WHEN FIND_IN_SET ('多囊卵巢综合症' ,current_illness_history ) THEN 1 ELSE 0 END) AS dnlczhz, -- 多囊卵巢综合症
SUM(CASE WHEN FIND_IN_SET ('胰岛素抵抗' ,current_illness_history ) THEN 1 ELSE 0 END) AS ydsdk, -- 胰岛素抵抗
SUM(CASE WHEN FIND_IN_SET ('高尿酸' ,current_illness_history ) THEN 1 ELSE 0 END) AS gns, -- 高尿酸
SUM(CASE WHEN
FIND_IN_SET('高血压' , current_illness_history ) = 0 AND
FIND_IN_SET('脑血管病' , current_illness_history ) = 0 AND
@ -94,7 +97,10 @@
FIND_IN_SET('过敏性疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('关节炎' , current_illness_history ) = 0 AND
FIND_IN_SET('痛风' , current_illness_history ) = 0 AND
FIND_IN_SET('肾炎、肾病' , current_illness_history ) = 0
FIND_IN_SET('肾炎、肾病' , current_illness_history ) = 0 AND
FIND_IN_SET('多囊卵巢综合症' , current_illness_history ) = 0 AND
FIND_IN_SET('胰岛素抵抗' , current_illness_history ) = 0 AND
FIND_IN_SET('高尿酸' , current_illness_history ) = 0
THEN 1 ELSE 0 END) AS other -- 其他
FROM
pms_patient
@ -246,7 +252,7 @@
WHERE
question_code = 'ZLFA_ZLLX'
AND t.del_flag = 0
AND t.del_flag = 0
AND r.del_flag = 0
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>
@ -360,7 +366,7 @@
COUNT(*) AS num, -- 总记录数
SUM(CASE WHEN t.status = 0 THEN 1 ELSE 0 END) AS dsf, -- 待随访
SUM(CASE WHEN t.status = 0 AND followup_time IS NULL AND start_time BETWEEN DATE_SUB(NOW(), INTERVAL 2 DAY) AND DATE_ADD(NOW(), INTERVAL 2 DAY) THEN 1 ELSE 0 END) AS ljsf, -- 临近随访
SUM(CASE WHEN (t.status = 0 AND followup_time IS NULL AND end_time &lt; NOW()) OR (t.status = 1 AND followup_time &gt; end_time) THEN 1 ELSE 0 END) AS cqsf, -- 超期随访
SUM(CASE WHEN (t.status = 1 AND followup_time IS NULL AND end_time &lt; NOW()) OR (t.status = 1 AND followup_time &gt; end_time) THEN 1 ELSE 0 END) AS cqsf, -- 超期随访
SUM(CASE WHEN t.status = 1 AND followup_time &lt;= end_time THEN 1 ELSE 0 END) AS zc -- 正常随访
FROM
fms_followup_task t

6
acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml

@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="slaverAdmin" column="slaver_admin" />
<association property="dept" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
@ -48,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
select u.user_id, u.tenant_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.slaver_admin,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u
@ -167,6 +168,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="slaverAdmin != null ">slaver_admin,</if>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
@ -182,6 +184,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="slaverAdmin != null ">#{slaverAdmin},</if>
sysdate()
)
</insert>
@ -202,6 +205,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="slaverAdmin != null">slaver_admin = #{slaverAdmin},</if>
update_time = sysdate()
</set>
where user_id = #{userId}

Loading…
Cancel
Save