From 368c71aaa842e1b6a2d40494a3ed0a559dfa7643 Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Fri, 22 Nov 2024 14:40:19 +0800 Subject: [PATCH 1/3] bugfix --- .../ruoyi/tc/controller/UnitController.java | 20 +++++++++--- .../java/com/ruoyi/tc/mapper/UnitMapper.java | 2 +- .../com/ruoyi/tc/service/UnitService.java | 2 +- .../tc/service/impl/UnitServiceImpl.java | 31 ++++++++++--------- .../resources/mapper/ExamineInfoMapper.xml | 2 +- .../src/main/resources/mapper/UnitMapper.xml | 5 +-- .../main/resources/mapper/UnitOtherConcat.xml | 4 +-- 7 files changed, 37 insertions(+), 29 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java index 65781f9..b5fa17b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java @@ -3,6 +3,9 @@ package com.ruoyi.tc.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.system.service.ISysUserService; import com.ruoyi.tc.entity.Unit; import com.ruoyi.tc.entity.request.UnitRequest; import com.ruoyi.common.enums.BusinessType; @@ -44,6 +47,9 @@ public class UnitController { @Resource private ExamineInfoService examineInfoService; + @Resource + private ISysUserService iSysUserService; + /** * 获取单位列表 */ @@ -130,10 +136,8 @@ public class UnitController { @PutMapping @Transactional(rollbackFor = Exception.class) public AjaxResult edit(@RequestBody Unit x) { - Unit byId = unitService.getById(x.getId()); - if (!byId.getUserName().equals(x.getUserName()) || !byId.getNickName().equals(x.getNickName())) { - throw new ServiceException("不允许修改单位名称和统一信用代码!"); - } + //查询用户表是否存在该用户 + unitService.validUser(x); unitService.updateById(x); if(!x.getOtherConcat().isEmpty()){ x.getOtherConcat().forEach(y->{ @@ -159,7 +163,13 @@ public class UnitController { public AjaxResult remove(@PathVariable Long id) { List userNames = unitService.selectByIds(id); //逻辑删除单位和用户 - unitService.deleteUsers(userNames); + if(!userNames.isEmpty()){ + for (String it : userNames) { + if(it!=null){ + unitService.deleteUsers(it); + } + } + } unitService.deleteUnits(id); unitOtherConcatService.deleteByUnitIds(id); examineInfoService.deleteByUnitIds(id); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java index ce451bb..be381e3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java @@ -44,7 +44,7 @@ public interface UnitMapper extends BaseMapper { /** * 逻辑删除用户 */ - void deleteUsers(List userNames); + void deleteUsers(@Param("userNames") String userNames); /** * 根据id获取详细信息 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java index 20c89e9..ea95e15 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java @@ -50,7 +50,7 @@ public interface UnitService extends IService { /** * 逻辑删除用户 */ - void deleteUsers(List userNames); + void deleteUsers(String userNames); /** * 逻辑删除单位 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java index 714897b..8309910 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java @@ -35,8 +35,6 @@ public class UnitServiceImpl extends ServiceImpl implements Un */ @Override public Page page(Page page, UnitRequest unit) { - - return baseMapper.selectUnitList(page,unit); } @@ -61,21 +59,24 @@ public class UnitServiceImpl extends ServiceImpl implements Un /** - * 检查用户表是否存在该用户 + * 检查用户表是否存在该用户,并做新增和修改 */ @Override public void validUser(Unit x) { - SysUser user = new SysUser(); - user.setUserName(x.getUserName()); - user.setPassword(SecurityUtils.encryptPassword(x.getUserName().substring(x.getUserName().length() - 6))); - user.setNickName(x.getNickName()); - SysUser u = userService.selectUserByUserName(x.getUserName()); - if (StringUtils.isNull(u)) { - userService.insertUser(user); - Long[] roles = new Long[]{100L}; - userService.insertUserAuth(user.getUserId(), roles); - }else { - throw new ServiceException(x.getUserName() + "'已存在单位!"); + if(x.getUserName()!=null && x.getUserName().length()>6){ + SysUser user = new SysUser(); + user.setUserName(x.getUserName()); + user.setPassword(SecurityUtils.encryptPassword(x.getUserName().substring(x.getUserName().length() - 6))); + user.setNickName(x.getNickName()); + SysUser u = userService.selectUserByUserName(x.getUserName()); + if (StringUtils.isNull(u)) { + userService.insertUser(user); + Long[] roles = new Long[]{100L}; + userService.insertUserAuth(user.getUserId(), roles); + }else { + //只修改用户账号,密码,单位名称 + userService.updateUserProfile(user); + } } } @@ -90,7 +91,7 @@ public class UnitServiceImpl extends ServiceImpl implements Un * 逻辑删除用户 */ @Override - public void deleteUsers(List userNames) { + public void deleteUsers(String userNames) { baseMapper.deleteUsers(userNames); } diff --git a/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml b/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml index 1eaf8ff..2085cfb 100644 --- a/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml @@ -2,7 +2,7 @@ - update asset_examine_info set del_flag = '2' where unit_id = #{id} + update unit_examine_info set del_flag = '2' where unit_id = #{id} diff --git a/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml b/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml index f3c666d..2fd51bf 100644 --- a/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml @@ -133,9 +133,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update unit_info set del_flag = '2' where id = #{id} - update sys_user set del_flag = '2' where user_name in - - #{userNames} - + update sys_user set del_flag = '2' where user_name = #{userNames} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml b/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml index 1433925..d6de253 100644 --- a/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml +++ b/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml @@ -5,9 +5,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update asset_supply_chain set del_flag = '2' where unit_id = #{id} + update unit_other_contact set del_flag = '2' where unit_id = #{id} - update asset_supply_chain set del_flag = '2' where asset_id = #{id} + update unit_other_contact set del_flag = '2' where asset_id = #{id} \ No newline at end of file From 683973b64202eca1123c36a6272a183736fdaf4e Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Fri, 22 Nov 2024 15:19:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/tc/controller/UnitController.java | 1 + .../java/com/ruoyi/common/utils/RsaUtils.java | 45 +++++++++++++++++++ .../web/service/SysLoginService.java | 12 ++++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java index b5fa17b..992b0ef 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java @@ -103,6 +103,7 @@ public class UnitController { @ApiOperation(value = "根据用户编号获取详细信息") @GetMapping("/{id}") public AjaxResult getInfo(@PathVariable(value = "id") Long id) { + System.out.println(SecurityUtils.encryptPassword("TcZc@2024")); return AjaxResult.success(unitService.getById(id)); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java new file mode 100644 index 0000000..2541b2a --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java @@ -0,0 +1,45 @@ +package com.ruoyi.common.utils; + +import javax.crypto.Cipher; +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.spec.PKCS8EncodedKeySpec; + +/** + * RSA加密解密 + * + * @author ruoyi + **/ +public class RsaUtils +{ + // Rsa 私钥 + private static final String PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXxtLWRhOIyEhLkxlTbndtzS6RrGsDWV8LOIAEXFCsLZzT20ytAaO4fpXXHah80EwaE4P25Y3+qQBDL8fA5780pSoLDo3Si/qC5KuowNb8F1ncGXSuYzX/3mNMLXF98UW96PvFY198hto8j5snhYtf01WI2L0eZPQFE3Mnh3ZHzos88Jr5vEto+OyHZHa0GRsuRSi33vr1olo8+LA8JkcyS5B6eMdKalYvSiSV6owfwQZfuPoDkD/ghRc8w0owzOSJJGmwgnrkYmYMBudHdldF8LwzNUEEkHrOvk3QXg33Fl8X4lL9jHvbq0K76sDoYMLJPG1D/Ccqk93AU/mdRYJZAgMBAAECggEAG+w3M7aWt25pZoX8fc3v6OJ7s88trOMPSkgtvR+is9p8ZLmOxLFthm67cGUDb1r+9Tkr6QtYcUZ0RugObt3z3mKYdopJ6zdXcidRsW0w4BYHsSd5wO99qsImMIiX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4JOxB1RK8=" + + "CfhCau4K5xqFfYnCDxwN6EfWtl118/RC/H1G6YUH9VZ02hTsIKtcdoz/w3knVDuL/i1uCtKtJDdyejF8osix2IVVA2HNoUPEG+3VH0IJjOoFTZTP76LcuQvgig6pjAtB5+GFPVkkrdxWZc3rn+psCdzYBueVhDRDFatKxfvAQMk90SMNVOLApB8u4aWUdxGju3vOKO5ShBUVutyczTzAOW39hHdzXX5CvGPXNYNv7S55AVAI5ZVdn11dyxgPr6u7n7AuHtc2pvUddHTRM/UczNN5lkpdMvISQy4iHwCw9wGVax3kvRxMzhYiBricSKJWbl4LiAMRV3P15LWkaBwSkw=="; + + /** + * 利用私钥进行解密 + */ + public static String decryptByPrivateKey(String decodeString) throws Exception { + // 将传入的Base64编码字符串解码为字节数组 + byte[] encryptedBytes = java.util.Base64.getDecoder().decode(decodeString); + // 使用私钥解密 + PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(org.apache.commons.codec.binary.Base64.decodeBase64(PRIVATE_KEY)); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec); + byte[] decryptedBytes = decrypt(encryptedBytes, privateKey); + // 返回解密后的字符串 + return new String(decryptedBytes); + } + + /** + * 解密操作 + */ + private static byte[] decrypt(byte[] data, PrivateKey privateKey) throws Exception { + // 获取RSA算法的Cipher实例 + Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); + // 用私钥初始化Cipher实例,设置为解密模式 + cipher.init(Cipher.DECRYPT_MODE, privateKey); + // 执行解密操作,返回解密后的字节数组 + return cipher.doFinal(data); + } +} \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 97abcea..22da3c0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -1,6 +1,8 @@ package com.ruoyi.framework.web.service; import javax.annotation.Resource; + +import com.ruoyi.common.utils.RsaUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; @@ -63,15 +65,21 @@ public class SysLoginService */ public String login(String username, String password, String code, String uuid) { + String strP; + try { + strP = RsaUtils.decryptByPrivateKey(password); + } catch (Exception e) { + throw new RuntimeException(e); + } // 验证码校验 validateCaptcha(username, code, uuid); // 登录前置校验 - loginPreCheck(username, password); + loginPreCheck(username, strP); // 用户验证 Authentication authentication = null; try { - UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, strP); AuthenticationContextHolder.setContext(authenticationToken); // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername authentication = authenticationManager.authenticate(authenticationToken); From 09b1bb62599b26f451c78d01a43839fc396ebc3b Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Fri, 22 Nov 2024 15:50:34 +0800 Subject: [PATCH 3/3] bugfix --- ruoyi-admin/src/main/resources/application.yml | 2 +- ruoyi-admin/src/main/resources/mapper/AssetCurrentMapper.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index e11d951..6aee222 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -52,7 +52,7 @@ spring: # 国际化资源文件路径 basename: i18n/messages profiles: - active: test + active: druid # 文件上传 servlet: multipart: diff --git a/ruoyi-admin/src/main/resources/mapper/AssetCurrentMapper.xml b/ruoyi-admin/src/main/resources/mapper/AssetCurrentMapper.xml index 4349c0f..28febe6 100644 --- a/ruoyi-admin/src/main/resources/mapper/AssetCurrentMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/AssetCurrentMapper.xml @@ -28,6 +28,7 @@ and create_time <= #{req.endTime} + order by create_time desc - update asset_current set del_flag = '2'