From 10ac81485cf20ea4a18b80f52b16af1d9ba82af6 Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:46:40 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E7=94=A8=E6=88=B7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/AdminDmsUserController.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) 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..580e64d1 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,28 @@ 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); + + //切换至从库 + DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); + //新增从库数据 SysUser user = BeanUtil.copyProperties(dto, SysUser.class); if (!userService.checkUserNameUnique(user)) { return JsonResponse.ok().fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); @@ -90,17 +104,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); - } + + //销毁切换数据源 + DynamicDataSourceContextHolder.clearDataSourceType(); + return JsonResponse.ok(insert); } @@ -124,11 +131,13 @@ public class AdminDmsUserController { if (CollectionUtil.isNotEmpty(tenantList)) { for (AdminTenantsVo.Result result : tenantList) { //切换数据源 删除分库数据 - changeDataSource(result.getDataSourceKey()); + DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); //修改分库用户 SysUser sysUser = BeanUtil.copyProperties(dto, SysUser.class); sysUser.setPhonenumber(dto.getContactPhone()); userService.updateUser(sysUser); + //销毁切换数据源 + DynamicDataSourceContextHolder.clearDataSourceType(); } } } @@ -154,7 +163,7 @@ public class AdminDmsUserController { if (CollectionUtil.isNotEmpty(tenantList)) { for (AdminTenantsVo.Result result : tenantList) { //切换数据源 删除分库数据 - changeDataSource(result.getDataSourceKey()); + DynamicDataSourceContextHolder.setDataSourceType(result.getDataSourceKey()); //删除分库用户 userService.deleteUserByUsername(dmsUser.getUserName()); } @@ -172,7 +181,4 @@ public class AdminDmsUserController { return JsonResponse.ok(new PageInfo<>(adminTenantUserService.query(dto.getParam()))); } - private static void changeDataSource(String key) { - DynamicDataSourceContextHolder.setDataSourceType(key); - } } From 96c9f3cbd2403185e769e072f5e7e65798eae201 Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:51:08 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=85=B7=E6=9C=89=E5=AE=A1=E6=A0=B8=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/entity/SysUser.java | 12 ++++++++++++ .../system/domain/dto/AdminTenantUserDto.java | 6 ++++++ .../main/resources/mapper/system/SysUserMapper.xml | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) 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..bd8bafcf 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,21 @@ 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-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..672ffa58 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,9 @@ public class AdminTenantUserDto { private String status; private String contactPhone; + + @ApiModelProperty("是否具有审核权限(0不具有; 1具有)") + private Byte slaverAdmin; // // public Long getTenantId() { // return SecurityUtils.getTenantId(); @@ -61,6 +65,8 @@ public class AdminTenantUserDto { private String status; private String contactPhone; + @ApiModelProperty("是否具有审核权限(0不具有; 1具有)") + private Byte slaverAdmin; } @Data diff --git a/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml b/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml index 6fe48291..322dfd54 100644 --- a/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -48,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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" status, create_by, remark, + slaver_admin, create_time )values( #{userId}, @@ -182,6 +184,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{createBy}, #{remark}, + #{slaverAdmin}, sysdate() ) From 900a21a984f63614fc0f0d9d79d8bfade9a8a978 Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:52:14 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7ID=E6=9F=A5=E8=AF=A2=E8=A7=92=E8=89=B2mapper?= =?UTF-8?q?=E7=9A=84=E4=B8=BB=E5=BA=93=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/acupuncture/system/mapper/SysRoleMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/mapper/SysRoleMapper.java b/acupuncture-system/src/main/java/com/acupuncture/system/mapper/SysRoleMapper.java index 688d3324..9acb7743 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/mapper/SysRoleMapper.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/mapper/SysRoleMapper.java @@ -27,7 +27,7 @@ public interface SysRoleMapper * @param userId 用户ID * @return 角色列表 */ - @DataSource(DataSourceType.MASTER) +// @DataSource(DataSourceType.MASTER) public List selectRolePermissionByUserId(Long userId); /** From 4917a1f76ab8076a0d54dac3a6f5665239745ecd Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:53:59 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=AA=8C=E8=AF=81=E7=A0=81=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acupuncture/framework/web/service/WebDmsLoginService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java index 9f65dacb..f5a40b40 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java @@ -62,7 +62,7 @@ public class WebDmsLoginService public String login(String username, String password, String code, String uuid) { // 验证码校验 -// validateCaptcha(username, code, uuid); + validateCaptcha(username, code, uuid); // 登录前置校验 loginPreCheck(username, password); // 用户验证 From ba09c0678c7fc8d7abb65a216fa5f6238766e3fa Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 16:58:12 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=95=B0=E6=8D=AE=E6=BA=90=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysUserController.java | 11 --------- .../web/AdminPmsTreatmentController.java | 23 ++++++------------- .../controller/web/ExternalController.java | 6 +---- .../controller/web/ScreeningController.java | 12 ---------- .../acupuncture/web/task/TaskController.java | 1 - 5 files changed, 8 insertions(+), 45 deletions(-) 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..d251be94 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 @@ -165,7 +165,6 @@ public class SysUserController extends BaseController @PutMapping public AjaxResult edit(@Validated @RequestBody SysUser user) { -// changeDataSource(user.getTenantId()); userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); deptService.checkDeptDataScope(user.getDeptId()); @@ -186,16 +185,6 @@ public class SysUserController extends BaseController return toAjax(userService.updateUser(user)); } - private void changeDataSource(Long tenantId) { - DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(tenantId); - if (dmsTenant != null) { - UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); - if (umsDataSource != null) { - DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); - } - } - } - /** * 删除用户 */ 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..d857e193 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 @@ -67,23 +67,14 @@ public class AdminPmsTreatmentController { treatmentService.adminExportTreatment(response, dto); } - @ApiOperation("修改诊疗档案") - @PostMapping("/upd") - public JsonResponse updateTreatment(@RequestBody @Validated PmsTreatmentDto.TreatmentUpdateDTO dto) { - DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(dto.getTenantId()); - if (dmsTenant != null) { - UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); - if (umsDataSource != null) { - changeDataSource(umsDataSource.getDataSourceKey()); - } - } - treatmentService.updateTreatment(dto); - return JsonResponse.ok(); - } +// @ApiOperation("修改诊疗档案") +// @PostMapping("/upd") +// public JsonResponse updateTreatment(@RequestBody @Validated PmsTreatmentDto.TreatmentUpdateDTO dto) { +// treatmentService.updateTreatment(dto); +// return JsonResponse.ok(); +// } +// - private static void changeDataSource(String dataSourceKey) { - DynamicDataSourceContextHolder.setDataSourceType(dataSourceKey); - } // @ApiOperation("导出诊疗档案评估报告") // @PostMapping("/exportTreatmentPg") 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..404f10fa 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 @@ -80,17 +80,13 @@ public class ExternalController { throw new BaseException("查询不到社区"); } //切换数据源查询 - changeDataSource(dataSourceList.get(0).getDataSourceKey()); + DynamicDataSourceContextHolder.setDataSourceType(dataSourceList.get(0).getDataSourceKey()); }catch (Exception e) { throw new BaseException("UUID错误:{}", from); } } - private static void changeDataSource(String key) { - DynamicDataSourceContextHolder.setDataSourceType(key); - } - // @Anonymous // @ApiOperation("上传数据") // @PostMapping("/http/uploadMemberInfo") 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..7bfe7ebc 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 @@ -82,21 +82,11 @@ public class ScreeningController { @RequestMapping(value = "/createNoToken", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JsonResponse createNoToken(@ApiParam @Validated @RequestBody BaseDto params) throws Exception { log.info("创建筛查详情{}", params); -// changeDataSource(params.getParam().getTenantId()); QuestionnaireVo.DetailInfo detailInfo = screeningService.createDetail(params.getParam(), params.getParam().getUserId(), params.getParam().getTenantId()); log.info("创建筛查详情结束"); return JsonResponse.ok(detailInfo); } - private void changeDataSource(Long tenantId) { - DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(tenantId); - if (dmsTenant != null) { - UmsDataSource umsDataSource = umsDataSourceMapper.selectByPrimaryKey(dmsTenant.getDataSourceId()); - if (umsDataSource != null) { - DynamicDataSourceContextHolder.setDataSourceType(umsDataSource.getDataSourceKey()); - } - } - } @ApiOperation(value = "提交筛查", notes = "") @RequestMapping(value = "/submit", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @@ -111,7 +101,6 @@ public class ScreeningController { @RequestMapping(value = "/submitNoToken", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JsonResponse submitNoToken(@ApiParam @Validated @RequestBody BaseDto params) throws Exception { log.info("提交筛查开始{}", params); -// changeDataSource(params.getParam().getTenantId()); screeningService.submitQuestionnaire(params.getParam(), 0L); return JsonResponse.ok(); } @@ -121,7 +110,6 @@ public class ScreeningController { @RequestMapping(value = "/save", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JsonResponse saveQuestionnaire(@ApiParam @Validated @RequestBody BaseDto params) throws Exception { log.info("保存调查筛查开始{}", params); -// changeDataSource(params.getParam().getTenantId()); screeningService.saveQuestionnaire(params.getParam(), params.getParam().getUserId()); log.info("保存调查筛查结束"); return JsonResponse.ok(); 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..26b6c12c 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 @@ -74,7 +74,6 @@ public class TaskController { //查询租户,根据租户循环切换数据源,定时处理所有医院的随访工单 // UmsDataSourceVo.Result result1 = new UmsDataSourceVo.Result(); // result1.setDataSourceKey("MASTER"); -// changeDataSource(result1); List query = umsDataSourceDao.query(null); if (CollectionUtil.isEmpty(query)) { return; From 45946ecf858957768a5ba8acfd68b892b832db7a Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 17:32:07 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acupuncture/web/task/TaskController.java | 385 ++++++++++-------- .../aspectj/AdminGlobalDataSourceAspect.java | 11 - 2 files changed, 211 insertions(+), 185 deletions(-) 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 26b6c12c..d0a521dc 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 @@ -4,6 +4,7 @@ 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 cn.hutool.core.util.StrUtil; import com.acupuncture.common.annotation.Anonymous; import com.acupuncture.common.core.redis.RedisCache; import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; @@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; /** * @Author zzc @@ -64,6 +66,200 @@ public class TaskController { @Resource private FmsFollowupQueueService fmsFollowupQueueService; + /** + * 处理业务 + * + * @param tenandId 租户用户 + * @param commonQueue 公共队列 + */ + public void doTask(Long tenandId, List commonQueue) { + //查询从库队列 + //1. 查询队列 + List slavelQueueList = fmsFollowupDao.selectQueueList(null, null, null, null); + + //合并公共队列和从库的队列 + slavelQueueList.addAll(commonQueue); + + //查询每个队列的对象 + for (FmsFollowupVo.FollowupQueueVO queue : slavelQueueList) { + FmsFollowupDto.FollowupPatientQueryDTO followupPatientQueryDTO = new FmsFollowupDto.FollowupPatientQueryDTO(); + followupPatientQueryDTO.setQueueId(queue.getId()); + followupPatientQueryDTO.setTenantId(queue.getTenantId()); + List patientList = fmsFollowupService.queryPatient(followupPatientQueryDTO); + log.info("查询每个队列的对象:{}", patientList); + } + + //定时任务 + +// //循环租户 +// for (UmsDataSourceVo.Result tenant : tenantList) { +// if ("MASTER".equals(tenant.getDataSourceKey())) { +// continue; +// } +// changeDataSource(tenant); +// { +// //获取随访患者列表,根据患者出院日时间和队列添加工单 +// //1. 查询队列 +// List queueList = fmsFollowupDao.selectQueueList(null, null, null, null); +// +// if (CollectionUtil.isEmpty(queueList)) { +// queueList = followupQueueVOS; +// } else { +// if (CollectionUtil.isEmpty(followupQueueVOS)) { +// queueList.addAll(followupQueueVOS); +// } +// } +// for (FmsFollowupVo.FollowupQueueVO followupQueueVO : queueList) { +// Integer followWindowAdys = followupQueueVO.getFollowWindowAdys(); +// +// //2. 查询队列随访患者列表 +//// changeDataSource(result); +// FmsFollowupDto.FollowupPatientQueryDTO followupPatientQueryDTO = new FmsFollowupDto.FollowupPatientQueryDTO(); +// followupPatientQueryDTO.setQueueId(followupQueueVO.getId()); +// followupPatientQueryDTO.setTenantId(followupQueueVO.getTenantId()); +// changeDataSource(result); +// +// List 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); +// } +// } +// } +// +// } +// } + } + @ApiOperation("定时任务添加随访工单") @PostMapping("/task") @Scheduled(cron = "0 0 0 * * ?") @@ -72,188 +268,29 @@ public class TaskController { // TODO 生成工单第一次生成之后2周的,往后只生成之后一周。第一次随访时间: ( 患者的出院时间 - 7 + 轮次时间) 到 (患者的出院时间 + 7 + 轮次时间 ) //查询租户,根据租户循环切换数据源,定时处理所有医院的随访工单 -// UmsDataSourceVo.Result result1 = new UmsDataSourceVo.Result(); -// result1.setDataSourceKey("MASTER"); - List query = umsDataSourceDao.query(null); - if (CollectionUtil.isEmpty(query)) { + List tenantList = umsDataSourceDao.query(null); + if (CollectionUtil.isEmpty(tenantList)) { 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); + //过滤掉没有数据源的租户 + tenantList = tenantList.stream().filter(result -> StrUtil.isNotEmpty(result.getDataSourceKey())).collect(Collectors.toList()); - 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(); + //查询公共队列 + List followupQueueVOS = fmsFollowupQueueService.queryCommonQueue(null); - //判断是否已有该次随访 - FmsFollowupTaskExample fmsFollowupTaskExample = new FmsFollowupTaskExample(); - fmsFollowupTaskExample.createCriteria().andTimesEqualTo(index).andPatientIdEqualTo(followupPatient.getPatientId()).andQueueIdEqualTo(followupQueueVO.getId()); - List fmsFollowupTasks = fmsFollowupTaskMapper.selectByExample(fmsFollowupTaskExample); - if (CollectionUtil.isNotEmpty(fmsFollowupTasks)) { - continue; - } + //循环租户 + for (UmsDataSourceVo.Result tenant : tenantList) { + //切换数据源 + DynamicDataSourceContextHolder.setDataSourceType(tenant.getDataSourceKey()); - 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); + //处理从库业务 + doTask(tenant.getTenantId(), followupQueueVOS); - fmsFollowupTask.setStartTime(date); - Calendar instance = Calendar.getInstance(); - instance.setTime(date); - instance.add(Calendar.DATE, followWindowAdys / 2); + //销毁数据源 + DynamicDataSourceContextHolder.clearDataSourceType(); + } - fmsFollowupTask.setEndTime(instance.getTime()); - changeDataSource(result); - fmsFollowupTask.setPatientId(followupPatient.getId()); - fmsFollowupTaskMapper.insertSelective(fmsFollowupTask); - } - } - } - } - } } private static void changeDataSource(UmsDataSourceVo.Result result) { 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..3c130186 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 @@ -70,13 +70,11 @@ public class AdminGlobalDataSourceAspect { // 获取请求携带的令牌 HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - //token为空 Long tenantId; String header = request.getHeader(UserConstants.DEPT); if(StrUtil.isNotEmpty(header)){ tenantId = Long.parseLong(header); }else { -// String deptId = request.getHeader(WebConstant.HEADER_KEY_DEPT_ID); String authHeader = request.getHeader(UserConstants.HEADER_KEY_TOKEN); if (StrUtil.isEmpty(authHeader)) { return null; @@ -86,15 +84,6 @@ public class AdminGlobalDataSourceAspect { return null; } } - - //设置所属医院和数据源 -// SecurityUtils.setCurrentHospitalId(Long.parseLong(deptId)); - -// // 获取当前的用户 -// LoginUser loginUser = SecurityUtils.getLoginUser(); -// if(ObjectUtil.isNull(loginUser) || loginUser.getUser().isAdmin()){ -// return null; -// } //根据组织ID查询数据源 UmsDataSource dataSource = dmsLoginService.getDataSourceByTenantId(tenantId); if (dataSource == null) { From 93181b5fbb436385d1d312300e8dcc61b43d1666 Mon Sep 17 00:00:00 2001 From: zzc Date: Fri, 28 Mar 2025 18:13:11 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 71 ++++++++++++++++--- .../web/AdminDmsUserController.java | 2 + .../controller/web/DmsLoginController.java | 21 ++++++ .../controller/web/FmsFollowupController.java | 3 + .../framework/config/SecurityConfig.java | 2 +- .../web/service/SysLoginService.java | 48 +++++++++++++ .../web/service/WebDmsLoginService.java | 48 +++++++++++++ .../service/FmsFollowupQueueService.java | 1 - .../resources/mapper/system/SysUserMapper.xml | 12 +++- 9 files changed, 194 insertions(+), 14 deletions(-) diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysLoginController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysLoginController.java index 9f9672e4..99e9c126 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysLoginController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/system/SysLoginController.java @@ -3,6 +3,8 @@ package com.acupuncture.web.controller.system; import java.util.List; import java.util.Set; +import com.acupuncture.common.annotation.DataSource; +import com.acupuncture.common.enums.DataSourceType; import com.acupuncture.system.domain.po.DmsTenant; import com.acupuncture.system.persist.mapper.DmsTenantMapper; import com.acupuncture.system.service.ISysUserService; @@ -66,23 +68,41 @@ public class SysLoginController return ajax; } + /** + * 登录方法 + * + * @param loginBody 登录信息 + * @return 结果 + */ + @PostMapping("/loginSimple") + public AjaxResult loginSimple(@RequestBody LoginBody loginBody) + { + AjaxResult ajax = AjaxResult.success(); + // 生成令牌 + String token = loginService.loginSimple(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), + loginBody.getUuid()); + ajax.put(Constants.TOKEN, token); + return ajax; + } + /** * 获取用户信息 - * + * * @return 用户信息 */ @GetMapping("getInfo") public AjaxResult getInfo() { LoginUser loginUser = SecurityUtils.getLoginUser(); - SysUser user = sysUserService.selectUserByTenantId(null, loginUser.getUsername()); - if (user.getTenantId() != null) { - DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(user.getTenantId()); - if (dmsTenant != null) { - user.setTenantName(dmsTenant.getName()); - user.setTenantPhone(dmsTenant.getContactPhone()); - } - } + SysUser user = sysUserService.selectUserById(loginUser.getUser().getUserId()); +// SysUser user = sysUserService.selectUserByTenantId(null, loginUser.getUsername()); +// if (user.getTenantId() != null) { +// DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(user.getTenantId()); +// if (dmsTenant != null) { +// user.setTenantName(dmsTenant.getName()); +// user.setTenantPhone(dmsTenant.getContactPhone()); +// } +// } // 角色集合 Set roles = permissionService.getRolePermission(user); // 权限集合 @@ -99,6 +119,39 @@ public class SysLoginController return ajax; } +// /** +// * 获取用户信息 +// * +// * @return 用户信息 +// */ +// @GetMapping("getInfo") +// public AjaxResult getInfo() +// { +// LoginUser loginUser = SecurityUtils.getLoginUser(); +// SysUser user = sysUserService.selectUserByTenantId(null, loginUser.getUsername()); +// if (user.getTenantId() != null) { +// DmsTenant dmsTenant = dmsTenantMapper.selectByPrimaryKey(user.getTenantId()); +// if (dmsTenant != null) { +// user.setTenantName(dmsTenant.getName()); +// user.setTenantPhone(dmsTenant.getContactPhone()); +// } +// } +// // 角色集合 +// Set roles = permissionService.getRolePermission(user); +// // 权限集合 +// Set permissions = permissionService.getMenuPermission(user); +// if (!loginUser.getPermissions().equals(permissions)) +// { +// loginUser.setPermissions(permissions); +// tokenService.refreshToken(loginUser); +// } +// AjaxResult ajax = AjaxResult.success(); +// ajax.put("user", user); +// ajax.put("roles", roles); +// ajax.put("permissions", permissions); +// return ajax; +// } + /** * 获取路由信息 * 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 580e64d1..6b2f073b 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 @@ -103,6 +103,8 @@ public class AdminDmsUserController { user.setCreateBy(SecurityUtils.getUsername()); user.setPhonenumber(dto.getContactPhone()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + user.setTenantName(dmsTenant.getName()); + user.setTenantPhone(dmsTenant.getContactPhone()); int insert = userService.insertUser(user); //销毁切换数据源 diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/DmsLoginController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/DmsLoginController.java index 91360ec3..73782849 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/DmsLoginController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/DmsLoginController.java @@ -1,5 +1,6 @@ package com.acupuncture.web.controller.web; +import com.acupuncture.common.annotation.DataSource; import com.acupuncture.common.annotation.Log; import com.acupuncture.common.constant.Constants; import com.acupuncture.common.core.domain.AjaxResult; @@ -8,6 +9,7 @@ import com.acupuncture.common.core.domain.entity.SysUser; import com.acupuncture.common.core.domain.model.LoginBody; import com.acupuncture.common.core.domain.model.LoginUser; import com.acupuncture.common.enums.BusinessType; +import com.acupuncture.common.enums.DataSourceType; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.framework.web.service.SysPermissionService; import com.acupuncture.framework.web.service.TokenService; @@ -52,6 +54,7 @@ public class DmsLoginController { * @param loginBody 登录信息 * @return 结果 */ + @DataSource(DataSourceType.MASTER) @PostMapping("/login") public AjaxResult login(@RequestBody LoginBody loginBody) { AjaxResult ajax = AjaxResult.success(); @@ -62,6 +65,24 @@ public class DmsLoginController { return ajax; } + /** + * 登录方法 + * + * @param loginBody 登录信息 + * @return 结果 + */ + @DataSource(DataSourceType.MASTER) + @PostMapping("/loginSimple") + public AjaxResult loginSimple(@RequestBody LoginBody loginBody) { + AjaxResult ajax = AjaxResult.success(); + // 生成令牌 + String token = webDmsLoginService.loginSimple(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), + loginBody.getUuid()); + ajax.put(Constants.TOKEN, token); + return ajax; + } + + /** * 获取用户信息 * diff --git a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/FmsFollowupController.java b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/FmsFollowupController.java index 9cfdff86..ac4e67c3 100644 --- a/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/FmsFollowupController.java +++ b/acupuncture-admin/src/main/java/com/acupuncture/web/controller/web/FmsFollowupController.java @@ -4,8 +4,10 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.IdUtil; import com.acupuncture.common.annotation.Anonymous; +import com.acupuncture.common.annotation.DataSource; import com.acupuncture.common.core.domain.BaseDto; import com.acupuncture.common.core.domain.JsonResponse; +import com.acupuncture.common.enums.DataSourceType; import com.acupuncture.common.utils.SecurityUtils; import com.acupuncture.framework.datasource.DynamicDataSourceContextHolder; import com.acupuncture.system.domain.dto.FmsFollowupDto; @@ -56,6 +58,7 @@ public class FmsFollowupController { @ApiOperation("查询公共队列") @PostMapping("/commonQueue") @Anonymous + @DataSource(DataSourceType.MASTER) public JsonResponse> queryCommonQueue(@RequestBody @Validated BaseDto dto) { if (dto.getPageNum() > 0) { PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/config/SecurityConfig.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/config/SecurityConfig.java index aeb17097..8bc43fea 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/config/SecurityConfig.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/config/SecurityConfig.java @@ -114,7 +114,7 @@ public class SecurityConfig .authorizeHttpRequests((requests) -> { permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll()); // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - requests.antMatchers("/login", "/register", "/captchaImage", "/web/login", "/web/queryTenantById", "/api/http/getUserInfo", "/api/http/addReportImage", "/api/http/uploadMemberInfo", "/task/task").permitAll() + requests.antMatchers("/login", "/register", "/captchaImage", "/web/login", "/web/queryTenantById", "/api/http/getUserInfo", "/api/http/addReportImage", "/api/http/uploadMemberInfo", "/task/task", "/loginSimple").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**", "/static/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/SysLoginService.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/SysLoginService.java index 8efafe15..097e82ac 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/SysLoginService.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/SysLoginService.java @@ -100,6 +100,54 @@ public class SysLoginService return tokenService.createToken(loginUser); } + /** + * 登录验证 + * + * @param username 用户名 + * @param password 密码 + * @param code 验证码 + * @param uuid 唯一标识 + * @return 结果 + */ + public String loginSimple(String username, String password, String code, String uuid) + { + // 验证码校验 +// validateCaptcha(username, code, uuid); + // 登录前置校验 + loginPreCheck(username, password); + // 用户验证 + Authentication authentication = null; + try + { + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); + AuthenticationContextHolder.setContext(authenticationToken); + // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername + authentication = authenticationManager.authenticate(authenticationToken); + } + catch (Exception e) + { + if (e instanceof BadCredentialsException) + { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); + throw new UserPasswordNotMatchException(); + } + else + { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); + throw new ServiceException(e.getMessage()); + } + } + finally + { + AuthenticationContextHolder.clearContext(); + } + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + recordLoginInfo(loginUser.getUserId()); + // 生成token + return tokenService.createToken(loginUser); + } + /** * 登录验证 * diff --git a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java index f5a40b40..b1817e21 100644 --- a/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java +++ b/acupuncture-framework/src/main/java/com/acupuncture/framework/web/service/WebDmsLoginService.java @@ -98,6 +98,54 @@ public class WebDmsLoginService return tokenService.createToken(loginUser); } + /** + * 登录验证 + * + * @param username 用户名 + * @param password 密码 + * @param code 验证码 + * @param uuid 唯一标识 + * @return 结果 + */ + public String loginSimple(String username, String password, String code, String uuid) + { + // 验证码校验 + validateCaptcha(username, code, uuid); + // 登录前置校验 + loginPreCheck(username, password); + // 用户验证 + Authentication authentication = null; + try + { + DmsUserAuthenticationToken authenticationToken = new DmsUserAuthenticationToken(username, password); + AuthenticationContextHolder.setContext(authenticationToken); + // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername + authentication = authenticationManager.authenticate(authenticationToken); + } + catch (Exception e) + { + if (e instanceof BadCredentialsException) + { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); + throw new UserPasswordNotMatchException(); + } + else + { + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); + throw new ServiceException(e.getMessage()); + } + } + finally + { + AuthenticationContextHolder.clearContext(); + } + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + recordLoginInfo(loginUser.getUserId()); + // 生成token + return tokenService.createToken(loginUser); + } + /** * 登录验证 * diff --git a/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupQueueService.java b/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupQueueService.java index 5c4000c6..326b4c74 100644 --- a/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupQueueService.java +++ b/acupuncture-system/src/main/java/com/acupuncture/system/service/FmsFollowupQueueService.java @@ -19,7 +19,6 @@ public interface FmsFollowupQueueService { * 查询公共队列 * @return */ - @DataSource(DataSourceType.MASTER) List queryCommonQueue(String name); } diff --git a/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml b/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml index 322dfd54..1755a8c0 100644 --- a/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/acupuncture-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -25,6 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -49,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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, + 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, u.tenant_name, u.tenant_phone, 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 @@ -168,7 +170,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status, create_by, remark, - slaver_admin, + slaver_admin, + tenant_name, + tenant_phone, create_time )values( #{userId}, @@ -184,7 +188,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{createBy}, #{remark}, - #{slaverAdmin}, + #{slaverAdmin}, + #{tenantName}, + #{tenantPhone}, sysdate() )