From 36067a43ee1a89a21a4d7beb751a7146135d416c Mon Sep 17 00:00:00 2001 From: dhy1725534722 <1725534722@qq.com> Date: Fri, 12 Apr 2024 09:27:35 +0800 Subject: [PATCH] bugfix --- .../ApprovalDeclarationRecordsQueryDto.java | 3 + .../vo/ApprovalDeclarationRecordsQueryVo.java | 3 + .../BmsDeclarationRecordsServiceImpl.java | 38 +++---- .../BmsDeclarationRecordsMapper.xml | 1 + .../ruoyi/framework/aspectj/LogAspect.java | 2 +- .../framework/config/MyMetaObjectHandler.java | 44 ++++++++ .../web/service/SysLoginService.java | 100 ++++++++---------- .../web/service/SysPasswordService.java | 46 ++++---- .../com/ruoyi/system/domain/SysOperLog.java | 22 ++-- .../mapper/system/SysOperLogMapper.xml | 9 +- 10 files changed, 139 insertions(+), 129 deletions(-) create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyMetaObjectHandler.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/dto/ApprovalDeclarationRecordsQueryDto.java b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/dto/ApprovalDeclarationRecordsQueryDto.java index 5389f27..5452587 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/dto/ApprovalDeclarationRecordsQueryDto.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/dto/ApprovalDeclarationRecordsQueryDto.java @@ -33,6 +33,9 @@ public class ApprovalDeclarationRecordsQueryDto implements Serializable { @ApiModelProperty(value = "申报单位") private String enterpriseName; + @ApiModelProperty(value = "申报单位ID") + private Long enterpriseId; + @ApiModelProperty(value = "扶持方式") private Integer supportMethods; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/vo/ApprovalDeclarationRecordsQueryVo.java b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/vo/ApprovalDeclarationRecordsQueryVo.java index 27d938c..1f5e863 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/vo/ApprovalDeclarationRecordsQueryVo.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/entity/vo/ApprovalDeclarationRecordsQueryVo.java @@ -37,6 +37,9 @@ public class ApprovalDeclarationRecordsQueryVo implements Serializable { @ApiModelProperty(value = "申报单位") private String enterpriseName; + @ApiModelProperty(value = "申报单位Id") + private Long enterpriseId; + @ApiModelProperty(value = "扶持方式") private Integer supportMethods; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsDeclarationRecordsServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsDeclarationRecordsServiceImpl.java index b6f401b..c184ad8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsDeclarationRecordsServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsDeclarationRecordsServiceImpl.java @@ -6,33 +6,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.context.SecurityContextHolder; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.jjh.declaration.entity.BmsApprovalInfo; -import com.ruoyi.jjh.declaration.entity.BmsDeclarationRecords; -import com.ruoyi.jjh.declaration.entity.BmsEnterpriseBasicInfo; -import com.ruoyi.jjh.declaration.entity.BmsFieldInfo; -import com.ruoyi.jjh.declaration.entity.BmsFileInfo; -import com.ruoyi.jjh.declaration.entity.BmsProcessInfo; -import com.ruoyi.jjh.declaration.entity.dto.ApprovalDeclarationRecordsQueryDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsApprovalInfoUpdateDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsDeclarationRecordsAddDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsDeclarationRecordsDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsFieldInfoAddDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsFileInfoAddDto; -import com.ruoyi.jjh.declaration.entity.dto.BmsMunicipalBureauReviewQueryDto; -import com.ruoyi.jjh.declaration.entity.dto.MunicipalReviewDto; -import com.ruoyi.jjh.declaration.entity.dto.MunicipalReviewInfoDto; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.jjh.declaration.entity.*; +import com.ruoyi.jjh.declaration.entity.dto.*; import com.ruoyi.jjh.declaration.entity.vo.ApprovalDeclarationRecordsQueryVo; import com.ruoyi.jjh.declaration.entity.vo.BmsDeclarationRecordsQueryVo; import com.ruoyi.jjh.declaration.entity.vo.BmsMunicipalBureauReviewQueryVo; import com.ruoyi.jjh.declaration.entity.vo.DeclarationRecordsVo; import com.ruoyi.jjh.declaration.mapper.BmsDeclarationRecordsMapper; -import com.ruoyi.jjh.declaration.service.IBmsApprovalInfoService; -import com.ruoyi.jjh.declaration.service.IBmsDeclarationRecordsService; -import com.ruoyi.jjh.declaration.service.IBmsEnterpriseBasicInfoService; -import com.ruoyi.jjh.declaration.service.IBmsFieldInfoService; -import com.ruoyi.jjh.declaration.service.IBmsFileInfoService; -import com.ruoyi.jjh.declaration.service.IBmsProcessInfoService; -import com.ruoyi.jjh.declaration.service.ICommonService; +import com.ruoyi.jjh.declaration.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -134,7 +116,12 @@ public class BmsDeclarationRecordsServiceImpl extends ServiceImpl approvalList(ApprovalDeclarationRecordsQueryDto approvalDeclarationRecordsQueryDto) { // approvalDeclarationRecordsQueryDto.setUserIds(iCommonService.getUserIds(SecurityContextHolder.getUserId())); - approvalDeclarationRecordsQueryDto.setApprovalById(SecurityContextHolder.getUserId()); + if (SecurityUtils.getUserId().equals(1L)) { + approvalDeclarationRecordsQueryDto.setApprovalById(null); + } else { + // todo SecurityContextHolder.getUserId()失效换成SecurityUtils.getUserId() + approvalDeclarationRecordsQueryDto.setApprovalById(SecurityUtils.getUserId()); + } return baseMapper.approvalList(approvalDeclarationRecordsQueryDto); } @@ -176,7 +163,7 @@ public class BmsDeclarationRecordsServiceImpl extends ServiceImpl bmsProcessInfoList = iBmsProcessInfoService.lambdaQuery().eq(BmsProcessInfo::getApprovalType, 0).list(); BmsProcessInfo bmsProcessInfo = new BmsProcessInfo(); bmsProcessInfoList.forEach(x -> { - boolean flag = Arrays.asList(x.getApprovalByIds().split(",")).contains(String.valueOf(SecurityContextHolder.getUserId())); + boolean flag = Arrays.asList(x.getApprovalByIds().split(",")).contains(String.valueOf(SecurityUtils.getUserId())); if (flag) { BeanUtil.copyProperties(x, bmsProcessInfo); } @@ -193,7 +180,7 @@ public class BmsDeclarationRecordsServiceImpl extends ServiceImpl login(String username, String password, String code, String uuid,String userType) - { + public Map login(String username, String password, String code, String uuid, String userType) { // 验证码校验 validateCaptcha(username, code, uuid); // 登录前置校验 loginPreCheck(username, password); // 用户验证 Authentication authentication = null; - try - { + try { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); AuthenticationContextHolder.setContext(authenticationToken); // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername authentication = authenticationManager.authenticate(authenticationToken); - } - catch (Exception e) - { - if (e instanceof BadCredentialsException) - { + } 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 - { + } else { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); throw new ServiceException(e.getMessage()); } - } - finally - { + } finally { AuthenticationContextHolder.clearContext(); } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); @@ -118,8 +107,8 @@ public class SysLoginService SysUser user = loginUser.getUser(); // 判断用户类型 - if (!"admin".equals(username)){ - if (!userType.equals(user.getUserType())){ + if (!"admin".equals(username)) { + if (!userType.equals(user.getUserType())) { throw new ServiceException("该用户类型错误"); } } @@ -132,7 +121,7 @@ public class SysLoginService addRecord(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); throw new ServiceException("对不起,您的账号:" + username + " 已停用"); } - sysPasswordService.validate(user); +// sysPasswordService.validate(user); addRecord(username, Constants.LOGIN_SUCCESS, "登录成功"); // 生成token return tokenService.createToken(loginUser); @@ -140,27 +129,23 @@ public class SysLoginService /** * 校验验证码 - * + * * @param username 用户名 - * @param code 验证码 - * @param uuid 唯一标识 + * @param code 验证码 + * @param uuid 唯一标识 * @return 结果 */ - public void validateCaptcha(String username, String code, String uuid) - { + public void validateCaptcha(String username, String code, String uuid) { boolean captchaEnabled = configService.selectCaptchaEnabled(); - if (captchaEnabled) - { + if (captchaEnabled) { String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String captcha = redisCache.getCacheObject(verifyKey); redisCache.deleteObject(verifyKey); - if (captcha == null) - { + if (captcha == null) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); throw new CaptchaExpireException(); } - if (!code.equalsIgnoreCase(captcha)) - { + if (!code.equalsIgnoreCase(captcha)) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); throw new CaptchaException(); } @@ -169,11 +154,11 @@ public class SysLoginService /** * 登录前置校验 + * * @param username 用户名 * @param password 用户密码 */ - public void loginPreCheck(String username, String password) - { + public void loginPreCheck(String username, String password) { // 用户名或密码为空 错误 if (StringUtils.isAnyBlank(username, password)) { this.addRecord(username, Constants.LOGIN_FAIL, "用户/密码必须填写"); @@ -206,8 +191,7 @@ public class SysLoginService * * @param userId 用户ID */ - public void recordLoginInfo(Long userId) - { + public void recordLoginInfo(Long userId) { SysUser sysUser = new SysUser(); sysUser.setUserId(userId); sysUser.setLoginIp(IpUtils.getIpAddr()); @@ -219,8 +203,8 @@ public class SysLoginService * 记录登录信息 * * @param username 用户名 - * @param status 状态 - * @param message 消息内容 + * @param status 状态 + * @param message 消息内容 * @return */ public void addRecord(String username, String status, String message) { diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java index 6728c7b..a42a08a 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java @@ -1,10 +1,5 @@ package com.ruoyi.framework.web.service; -import java.util.concurrent.TimeUnit; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.redis.RedisCache; @@ -12,15 +7,20 @@ import com.ruoyi.common.exception.user.UserPasswordNotMatchException; import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.security.context.AuthenticationContextHolder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; /** * 登录密码方法 - * + * * @author ruoyi */ @Component -public class SysPasswordService -{ +public class SysPasswordService { @Autowired private RedisCache redisCache; @@ -32,54 +32,44 @@ public class SysPasswordService /** * 登录账户密码错误次数缓存键名 - * + * * @param username 用户名 * @return 缓存键key */ - private String getCacheKey(String username) - { + private String getCacheKey(String username) { return CacheConstants.PWD_ERR_CNT_KEY + username; } - public void validate(SysUser user) - { + public void validate(SysUser user) { Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext(); String username = usernamePasswordAuthenticationToken.getName(); String password = usernamePasswordAuthenticationToken.getCredentials().toString(); Integer retryCount = redisCache.getCacheObject(getCacheKey(username)); - if (retryCount == null) - { + if (retryCount == null) { retryCount = 0; } - if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) - { + if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) { throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime); } - if (!matches(user, password)) - { + if (!matches(user, password)) { retryCount = retryCount + 1; redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); throw new UserPasswordNotMatchException(); - } - else - { + } else { clearLoginRecordCache(username); } } - public boolean matches(SysUser user, String rawPassword) - { + public boolean matches(SysUser user, String rawPassword) { return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); } - public void clearLoginRecordCache(String loginName) - { - if (redisCache.hasKey(getCacheKey(loginName))) - { + public void clearLoginRecordCache(String loginName) { + if (redisCache.hasKey(getCacheKey(loginName))) { redisCache.deleteObject(getCacheKey(loginName)); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java index f6761df..16cdc99 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java @@ -83,9 +83,9 @@ public class SysOperLog extends BaseEntity @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date operTime; - /** 消耗时间 */ - @Excel(name = "消耗时间", suffix = "毫秒") - private Long costTime; +// /** 消耗时间 */ +// @Excel(name = "消耗时间", suffix = "毫秒") +// private Long costTime; public Long getOperId() { @@ -257,13 +257,13 @@ public class SysOperLog extends BaseEntity this.operTime = operTime; } - public Long getCostTime() - { - return costTime; - } +// public Long getCostTime() +// { +// return costTime; +// } - public void setCostTime(Long costTime) - { - this.costTime = costTime; - } +// public void setCostTime(Long costTime) +// { +// this.costTime = costTime; +// } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml index 0241d65..b40dd5e 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml @@ -21,7 +21,7 @@ - + @@ -40,18 +40,17 @@ json_result, status, error_msg, - oper_time, - cost_time + oper_time from sys_oper_log insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, - cost_time, oper_time) + oper_time) values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, - #{costTime}, sysdate()) + sysdate())