From 5983474cf4f5d21b27b81c4be601de2c9304822a Mon Sep 17 00:00:00 2001 From: dx <1242347652@qq.com> Date: Tue, 25 Feb 2025 17:38:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/taskinfo/TaskInfoController.java | 5 +- .../controller/admin/user/UserController.java | 9 +++ .../mysql/enterprise/EnterpriseMapper.java | 1 + .../dal/mysql/user/AdminUserMapper.java | 6 ++ .../system/job/TaskSendStartMessageJob.java | 7 +- .../EnterpriseInspectionsServiceImpl.java | 9 --- .../system/service/user/AdminUserService.java | 2 + .../service/user/AdminUserServiceImpl.java | 65 +++++++++++++++++++ 8 files changed, 92 insertions(+), 12 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java index 451ae55..b558b99 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java @@ -189,7 +189,10 @@ public class TaskInfoController { pageResult.getList().forEach(item->{ item.setPublishDep(dep.getName()); - item.setCreateName(adminUserService.getUser(Long.valueOf(item.getCreator())).getRealName()); + final AdminUserDO user1 = adminUserService.getUser(Long.valueOf(item.getCreator())); + if (user1 != null) { + item.setCreateName(user1.getRealName()); + } enterpriseInspectionsPageReqVO.setTaskId(item.getId()); List enterpriseInspectionsides=enterpriseInspectionsService.getEnterpriseInspectionsList(enterpriseInspectionsPageReqVO); EnterprisePageReqVO enterprisePageReqVO=new EnterprisePageReqVO(); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java index f14ac09..68ec662 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java @@ -77,6 +77,15 @@ public class UserController { return success(true); } + @DeleteMapping("/test_delete") + @Operation(summary = "测试时,删除用户所有信息") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('system:user:delete')") + public CommonResult testDeleteUser(@RequestParam("id") Long id) { + userService.testDeleteUser(id); + return success(true); + } + @PutMapping("/update-password") @Operation(summary = "重置用户密码") @PreAuthorize("@ss.hasPermission('system:user:update-password')") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java index 5a60ee5..a4ea297 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java @@ -73,4 +73,5 @@ public interface EnterpriseMapper extends BaseMapperX { } IPage getAppPage(Page page, @Param("params") EnterprisePageReqVO pageReqVO); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java index bd4dcd1..950a1a8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -50,4 +51,9 @@ public interface AdminUserMapper extends BaseMapperX { return selectList(AdminUserDO::getDeptId, deptIds); } + @Delete("delete from system_oauth2_access_token where user_id = #{userId}") + Long deleteOauth2AccessAuth(Long userId); + + @Delete("delete from system_oauth2_refresh_token where user_id = #{userId}") + Long deleteOauth2RefreshAuth(Long userId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java index e972608..2f1c69f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java @@ -76,7 +76,7 @@ public class TaskSendStartMessageJob implements JobHandler { //执法任务更改状态 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(EnterpriseInspectionsDO::getTaskId, x.getId()); + wrapper.eq(EnterpriseInspectionsDO::getTaskId, x.getTaskId()); List enterpriseInspectionsDOList = enterpriseInspectionsMapper.selectList(wrapper); if(enterpriseInspectionsDOList!=null && enterpriseInspectionsDOList.size() > 0) { List list = new ArrayList<>(); @@ -88,8 +88,11 @@ public class TaskSendStartMessageJob implements JobHandler { Map templateParams = new HashMap<>(); templateParams.put("title", beforeTaskInfo.getTitle()); templateParams.put("startTime", beforeTaskInfo.getStartDate()); + templateParams.put("endTime", beforeTaskInfo.getEndDate()); + templateParams.put("url", "sub/task/detail?taskId="+ enterpriseInspectionsDO.getTaskId()); + notifyMessage.setTemplateParams(templateParams); - notifyMessageSendApi.sendSingleMessageToAdmin(notifyMessage); + notifyMessageSendApi.sendSingleMessageToMember(notifyMessage); enterpriseInspectionsDO.setStatus(2); list.add(enterpriseInspectionsDO); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterpriseinspections/EnterpriseInspectionsServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterpriseinspections/EnterpriseInspectionsServiceImpl.java index 78b7293..e16f018 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterpriseinspections/EnterpriseInspectionsServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterpriseinspections/EnterpriseInspectionsServiceImpl.java @@ -193,15 +193,6 @@ public class EnterpriseInspectionsServiceImpl implements EnterpriseInspectionsSe } } -// if ("queue".equals(typeVO.getRoleName())) { -// pageReqVO.setDepartmentId(typeVO.getValue()); -// final List adminUserDOS = adminUserMapper.selectList(new QueryWrapper().eq("dept_id", typeVO.getValue())); -// if (adminUserDOS != null || adminUserDOS.size() > 0) { -// final List collect = adminUserDOS.stream().map(item -> item.getId()).collect(Collectors.toList()); -// pageReqVO.setUserIds(collect); -// } -// } - //按照部门查询 if (pageReqVO.getDepartmentId() != null) { final List adminUserDOS = adminUserMapper.selectList(new QueryWrapper().eq("dept_id", pageReqVO.getDepartmentId())); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java index 89dad96..1b53fb7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java @@ -230,4 +230,6 @@ public interface AdminUserService { List getSimpleUserZGList(); List getSimpleEnterpriseUserList(Integer type); + + void testDeleteUser(Long id); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 5383bc0..5c78025 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -23,12 +23,19 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; import cn.iocoder.yudao.module.system.controller.admin.userAuditlog.vo.UserAuditLogSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; +import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO; +import cn.iocoder.yudao.module.system.dal.dataobject.enterpriseinspections.EnterpriseInspectionsDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; +import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.userAuditlog.UserAuditLogDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper; +import cn.iocoder.yudao.module.system.dal.mysql.enterprise.EnterpriseMapper; +import cn.iocoder.yudao.module.system.dal.mysql.enterpriseinspections.EnterpriseInspectionsMapper; import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper; +import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; +import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.userAuditlog.UserAuditLogMapper; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; @@ -38,6 +45,7 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; import cn.iocoder.yudao.module.system.service.userAuditlog.UserAuditLogService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.annotations.VisibleForTesting; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.service.impl.DiffParseFunction; @@ -100,6 +108,15 @@ public class AdminUserServiceImpl implements AdminUserService { private AdminUserMapper adminUserMapper; @Resource private UserRoleMapper userRoleMapper; + @Resource + private SocialUserBindMapper socialUserBindMapper; + @Resource + private SocialUserMapper socialUserMapper; + @Resource + private EnterpriseMapper enterpriseMapper; + @Resource + private EnterpriseInspectionsMapper enterpriseInspectionsMapper; + @Override @Transactional(rollbackFor = Exception.class) @@ -288,6 +305,23 @@ public class AdminUserServiceImpl implements AdminUserService { permissionService.processUserDeleted(id); // 2.2 删除用户岗位 userPostMapper.deleteByUserId(id); + // 2.3 删除社交用户 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("user_id", id); + final SocialUserBindDO socialUserBindDO = socialUserBindMapper.selectById(wrapper); + socialUserMapper.deleteById(socialUserBindDO.getSocialUserId()); + socialUserBindMapper.deleteById(socialUserBindDO.getId()); + //2.4 删除 token 数据 + adminUserMapper.deleteOauth2AccessAuth(id); + adminUserMapper.deleteOauth2RefreshAuth(id); + //2.5 删除 企业 + QueryWrapper enterpriseDOQueryWrapper = new QueryWrapper<>(); + enterpriseDOQueryWrapper.eq("user_id", id); + enterpriseMapper.delete(enterpriseDOQueryWrapper); + //2.6 执法 + QueryWrapper inspectionsDOQueryWrapper = new QueryWrapper<>(); + inspectionsDOQueryWrapper.eq("user_id", id); + enterpriseInspectionsMapper.delete(inspectionsDOQueryWrapper); // 3. 记录操作日志上下文 LogRecordContext.putVariable("user", user); @@ -622,6 +656,37 @@ public class AdminUserServiceImpl implements AdminUserService { return adminUserMapper.selectList(wrapper); } + @Override + public void testDeleteUser(Long id) { + // 1. 校验用户存在 + AdminUserDO user = validateUserExists(id); + // 2.1 删除用户 + userMapper.deleteById(id); + // 2.2 删除用户关联数据 + permissionService.processUserDeleted(id); + // 2.2 删除用户岗位 + userPostMapper.deleteByUserId(id); + // 2.3 删除社交用户 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("user_id", id); + final SocialUserBindDO socialUserBindDO = socialUserBindMapper.selectOne(wrapper); + socialUserMapper.deleteById(socialUserBindDO.getSocialUserId()); + socialUserBindMapper.deleteById(socialUserBindDO.getId()); + //2.4 删除 token 数据 + adminUserMapper.deleteOauth2AccessAuth(id); + adminUserMapper.deleteOauth2RefreshAuth(id); + //2.5 删除 企业 + QueryWrapper enterpriseDOQueryWrapper = new QueryWrapper<>(); + enterpriseDOQueryWrapper.eq("user_id", id); + enterpriseMapper.delete(enterpriseDOQueryWrapper); + //2.6 执法 + QueryWrapper inspectionsDOQueryWrapper = new QueryWrapper<>(); + inspectionsDOQueryWrapper.eq("user_id", id); + enterpriseInspectionsMapper.delete(inspectionsDOQueryWrapper); + // 3. 记录操作日志上下文 + LogRecordContext.putVariable("user", user); + } + public void bindSocialUser(Long userId, AuthUser authUser) { // SocialUserDO socialUser = new SocialUserDO(); // socialUser.setUserId(userId);