From fa37ceb80096054392897ce0454ceac45f4751ac Mon Sep 17 00:00:00 2001 From: zt Date: Fri, 21 Mar 2025 15:55:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/bgt/AppBgtUserController.java | 12 ++- .../controller/common/AppLoginController.java | 11 +++ .../common/UploadZipController.java | 55 ++++++----- .../com/ruoyi/common/utils/SecurityUtils.java | 29 +++++- .../framework/config/SecurityConfig.java | 4 +- .../BgtProjectRecruitApplyServiceImpl.java | 6 ++ .../impl/WgzAttendanceServiceImpl.java | 8 +- .../wgz/service/impl/WgzLeaveServiceImpl.java | 92 ++++++++++--------- .../bgt/BgtProjectRecruitApplyMapper.xml | 1 + 9 files changed, 140 insertions(+), 78 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/bgt/AppBgtUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/bgt/AppBgtUserController.java index 8375674..3b3cbfc 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/bgt/AppBgtUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/bgt/AppBgtUserController.java @@ -8,6 +8,8 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.BgtUser; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.web.service.TokenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -31,6 +33,8 @@ public class AppBgtUserController extends BaseController { private final IBgtUserService iBgtUserService; + @Autowired + private TokenService tokenService; /** * 实名认证 */ @@ -39,7 +43,13 @@ public class AppBgtUserController extends BaseController { @RepeatSubmit @PutMapping public AjaxResult realNameAuthentication(@Validated @RequestBody UserRealNameAuthenticationDTO dto) { - return AjaxResult.success(iBgtUserService.realNameAuthentication(dto)); + Boolean b = iBgtUserService.realNameAuthentication(dto); + if(b){ + //更新上下文和缓存 + SecurityUtils.updateUsername(dto.getUsername()); + tokenService.refreshToken(SecurityUtils.getLoginUser()); + } + return AjaxResult.success(b); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/AppLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/AppLoginController.java index d538c6c..27ece82 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/AppLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/AppLoginController.java @@ -10,6 +10,7 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.BgtLoginBody; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.util.DataUtil; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.framework.web.service.AppLoginService; import com.ruoyi.framework.web.service.SysPermissionService; @@ -133,6 +134,16 @@ public class AppLoginController return AjaxResult.success(data); } + @GetMapping(value = "/test") + public void test(String name) + { + System.out.println(SecurityUtils.getUsername()); + SecurityUtils.updateUsername(name); + tokenService.refreshToken(SecurityUtils.getLoginUser()); + System.out.println(SecurityUtils.getUsername()); + } + + // /** // * 获取用户信息 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/UploadZipController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/UploadZipController.java index 100a2b3..68f692d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/UploadZipController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/UploadZipController.java @@ -296,7 +296,7 @@ public class UploadZipController { } } - private void moveFilesToRecordDirRecursively(File source, File destination, String timeStamp, List annexRecordList, Long recruitId,String username,Long userId) throws IOException { + private void moveFilesToRecordDirRecursively(File source, File destination, String timeStamp, List annexRecordList, Long recruitId, String username, Long userId) throws IOException { if (source.isDirectory()) { String folderName = source.getName(); String[] parts = folderName.split("_"); @@ -305,24 +305,30 @@ public class UploadZipController { File[] files = source.listFiles(); if (files != null) { for (File file : files) { - moveFilesToRecordDirRecursively(file, destination, timeStamp, annexRecordList, recruitId,username,userId); + moveFilesToRecordDirRecursively(file, destination, timeStamp, annexRecordList, recruitId, username, userId); } } } else { - if (parts.length > 1) { - folderName = folderName + "_" + timeStamp; - } File newDir = new File(destination, folderName); ensureDirectoryExists(newDir); File[] files = source.listFiles(); if (files != null) { for (File file : files) { - moveFilesToRecordDirRecursively(file, newDir, timeStamp, annexRecordList, recruitId,username,userId); + moveFilesToRecordDirRecursively(file, newDir, timeStamp, annexRecordList, recruitId, username, userId); } } } } else { - File destFile = new File(destination, source.getName()); + // 获取文件名和扩展名 + String fileName = source.getName(); + int dotIndex = fileName.lastIndexOf('.'); + String nameWithoutExtension = dotIndex == -1 ? fileName : fileName.substring(0, dotIndex); + String extension = dotIndex == -1 ? "" : fileName.substring(dotIndex); + + // 在文件名后面添加时间戳 + String newFileName = nameWithoutExtension + "_" + timeStamp + extension; + File destFile = new File(destination, newFileName); + ensureDirectoryExists(destFile.getParentFile()); try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(destFile)) { @@ -332,19 +338,17 @@ public class UploadZipController { out.write(buffer, 0, length); } } - String relativePath = RECORD_DIR + File.separator +timeStamp+ getRelativePath(source, new File(TEMP_DIR)); - relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile"); - System.out.println("文件在记录目录里的相对目录: " + relativePath); - // 存到数据库作为记录 + // 记录文件信息到数据库 + String relativePath = RECORD_DIR + File.separator + getRelativePath(destFile, new File(RECORD_DIR)); + relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile"); + String parentName = destination.getParentFile().getName(); - System.out.println("上上一级文件名: " + parentName); String[] split = parentName.split("_"); String card = split[1]; WgzUser wgzUser = wgzUserService.findByIdentityCard(card); String name = destination.getName(); - System.out.println("上一级文件名: " + name); String type = ""; if ("保险".equals(name)) { type = "2"; @@ -352,18 +356,19 @@ public class UploadZipController { if ("劳务合同".equals(name)) { type = "1"; } - AnnexRecord annex = new AnnexRecord(); - annex.setAnnexName(destFile.getName()); - annex.setAnnexUrl(relativePath); - annex.setAnnexType(type); - annex.setUserType(Constants.WGZ); - annex.setUserId(wgzUser.getUserId()); - annex.setRecruitId(recruitId); - annex.setCreateBy(username); - annex.setUpdateBy(username); - annex.setCreateUserId(userId); - annex.setCreateUserType(Constants.BGT); - annexRecordList.add(annex); + + AnnexRecord annexRecord = new AnnexRecord(); + annexRecord.setAnnexName(newFileName); + annexRecord.setAnnexUrl(relativePath); + annexRecord.setAnnexType(type); + annexRecord.setUserType(Constants.WGZ); + annexRecord.setUserId(wgzUser.getUserId()); + annexRecord.setRecruitId(recruitId); + annexRecord.setCreateBy(username); + annexRecord.setUpdateBy(username); + annexRecord.setCreateUserId(userId); + annexRecord.setCreateUserType(Constants.BGT); + annexRecordList.add(annexRecord); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java index 8632e35..9af8393 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java @@ -1,11 +1,13 @@ package com.ruoyi.common.utils; import cn.hutool.http.HttpStatus; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.exception.CustomException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.exception.CustomException; /** * 安全服务工具类 @@ -102,4 +104,27 @@ public class SecurityUtils { return userId != null && 1L == userId; } + + + /** + * 更新已登录用户的用户名 + * @param newUsername 新的用户名 + */ + public static void updateUsername(String newUsername) { + Authentication currentAuth = getAuthentication(); + LoginUser loginUser = getLoginUser(); + SysUser user = loginUser.getUser(); + // 更新 LoginUser 中的用户名 + user.setUserName(newUsername); + + // 创建新的认证对象 + UsernamePasswordAuthenticationToken newAuth = new UsernamePasswordAuthenticationToken( + loginUser, + currentAuth.getCredentials(), + currentAuth.getAuthorities() + ); + + // 更新安全上下文 + SecurityContextHolder.getContext().setAuthentication(newAuth); + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 154663a..3e19102 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -111,8 +111,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter "/**/*.js" ).permitAll() .antMatchers("/profile/**").anonymous() - .antMatchers("/common/download**").anonymous() - .antMatchers("/common/download/resource**").anonymous() + .antMatchers("/common/download**").permitAll() + .antMatchers("/common/download/resource**").permitAll() .antMatchers("/doc.html").anonymous() .antMatchers("/swagger-resources/**").anonymous() .antMatchers("/webjars/**").anonymous() diff --git a/ruoyi-system/src/main/java/com/ruoyi/bgt/service/impl/BgtProjectRecruitApplyServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/bgt/service/impl/BgtProjectRecruitApplyServiceImpl.java index b3a7938..ebea762 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/bgt/service/impl/BgtProjectRecruitApplyServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/bgt/service/impl/BgtProjectRecruitApplyServiceImpl.java @@ -443,6 +443,12 @@ public class BgtProjectRecruitApplyServiceImpl extends ServicePlusImpl bgtProjectRecruits = iBgtProjectRecruitService.getBaseMapper().selectList(Wrappers.lambdaQuery() .eq(BgtProjectRecruit::getTaskId, dto.getTaskId())); @@ -505,6 +502,11 @@ public class WgzAttendanceServiceImpl extends ServicePlusImpl mp = new HashMap<>(); - mp.put("projectName",recruit.getRecruitName()); - mp.put("auditor",SecurityUtils.getUsername()); - Map map = bgtMessage(mp, BGT_TYPE_LEAVE, AuditStatus.PASS.getCode().equals(dto.getAuditorType())); - WgzMessage wgzMessage = new WgzMessage() - .setSenderType(USERTYPE_BGT) - .setSenderId(SecurityUtils.getAppUserId()) - .setRecipientType(USERTYPE_WGZ) - .setRecipientId(wgzLeave.getUserId()) - .setHeadline(map.get(HEADLINE)) - .setSubheading(map.get(SUBHEADING)) - .setTableId(wgzLeave.getId()) - .setTableName(SqlHelper.table(WgzLeave.class).getTableName()) - .setMessageLargeType(LARGE_OTHER) - .setMessageSmallType(SMALL_LEAVE); - iWgzMessageService.sendAMessage(wgzMessage); + if(AuditStatus.getAudit().contains(dto.getAuditorType())){ + wgzLeave.setAuditorTime(LocalDateTime.now()); + BgtProjectRecruit recruit = iBgtProjectRecruitService.getById(wgzLeave.getRecruitId()); - if(AuditStatus.PASS.getCode().equals(dto.getAuditorType())){ - //考勤信息 - List list = attendanceService.list(Wrappers.lambdaQuery() - .eq(WgzAttendance::getRecruitId, recruit.getId()) - .eq(WgzAttendance::getUserId, wgzLeave.getUserId()) - .eq(WgzAttendance::getDate, wgzLeave.getStartTime().toLocalDate())); - if(CollectionUtil.isNotEmpty(list)){ - WgzAttendance wgzAttendance = list.get(0); - wgzAttendance.setLeaveMarkId(wgzLeave.getId()); - wgzAttendance.setExceptionType("7"); - attendanceService.updateById(wgzAttendance); - }else { - WgzAttendance wgzAttendance = new WgzAttendance(); - wgzAttendance.setRecruitId(recruit.getId()); - wgzAttendance.setUserId(wgzLeave.getUserId()); - wgzAttendance.setLeaveMarkId(wgzLeave.getId()); - wgzAttendance.setDailyWage(recruit.getRecruitAmount()); - wgzAttendance.setDate(wgzLeave.getStartTime().toLocalDate()); - wgzAttendance.setExceptionType("7"); - attendanceService.save(wgzAttendance); + //发消息 + HashMap mp = new HashMap<>(); + mp.put("projectName",recruit.getRecruitName()); + mp.put("auditor",SecurityUtils.getUsername()); + Map map = bgtMessage(mp, BGT_TYPE_LEAVE, AuditStatus.PASS.getCode().equals(dto.getAuditorType())); + WgzMessage wgzMessage = new WgzMessage() + .setSenderType(USERTYPE_BGT) + .setSenderId(SecurityUtils.getAppUserId()) + .setRecipientType(USERTYPE_WGZ) + .setRecipientId(wgzLeave.getUserId()) + .setHeadline(map.get(HEADLINE)) + .setSubheading(map.get(SUBHEADING)) + .setTableId(wgzLeave.getId()) + .setTableName(SqlHelper.table(WgzLeave.class).getTableName()) + .setMessageLargeType(LARGE_OTHER) + .setMessageSmallType(SMALL_LEAVE); + iWgzMessageService.sendAMessage(wgzMessage); + + //处理消息 + iBgtMessageService.operation(USERTYPE_WGZ, wgzLeave.getUserId(), USERTYPE_BGT, SecurityUtils.getAppUserId(), wgzLeave.getId(),SqlHelper.table(WgzLeave.class).getTableName()); + + if(AuditStatus.PASS.getCode().equals(dto.getAuditorType())){ + //考勤信息 + List list = attendanceService.list(Wrappers.lambdaQuery() + .eq(WgzAttendance::getRecruitId, recruit.getId()) + .eq(WgzAttendance::getUserId, wgzLeave.getUserId()) + .eq(WgzAttendance::getDate, wgzLeave.getStartTime().toLocalDate())); + if(CollectionUtil.isNotEmpty(list)){ + WgzAttendance wgzAttendance = list.get(0); + wgzAttendance.setLeaveMarkId(wgzLeave.getId()); + wgzAttendance.setExceptionType("7"); + attendanceService.updateById(wgzAttendance); + }else { + WgzAttendance wgzAttendance = new WgzAttendance(); + wgzAttendance.setRecruitId(recruit.getId()); + wgzAttendance.setUserId(wgzLeave.getUserId()); + wgzAttendance.setLeaveMarkId(wgzLeave.getId()); + wgzAttendance.setDailyWage(recruit.getRecruitAmount()); + wgzAttendance.setDate(wgzLeave.getStartTime().toLocalDate()); + wgzAttendance.setExceptionType("7"); + attendanceService.save(wgzAttendance); + } } } - if(AuditStatus.getAudit().contains(dto.getAuditorType())){{ - //处理消息 - iBgtMessageService.operation(USERTYPE_WGZ, wgzLeave.getUserId(), USERTYPE_BGT, SecurityUtils.getAppUserId(), wgzLeave.getId(),SqlHelper.table(WgzLeave.class).getTableName()); - }} return updateById(wgzLeave); } diff --git a/ruoyi-system/src/main/resources/mapper/bgt/BgtProjectRecruitApplyMapper.xml b/ruoyi-system/src/main/resources/mapper/bgt/BgtProjectRecruitApplyMapper.xml index 901dfd4..8174783 100644 --- a/ruoyi-system/src/main/resources/mapper/bgt/BgtProjectRecruitApplyMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/bgt/BgtProjectRecruitApplyMapper.xml @@ -112,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" wu.identity_card, bpr.recruit_name, fpt.task_name, + bpra.status, bpra.task_id, bpra.recruit_id, CASE