dongdingding 2 months ago
commit aadf64cb69

@ -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;
/**
*
*/
@ -97,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));
}
@ -130,10 +137,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 +164,13 @@ public class UnitController {
public AjaxResult remove(@PathVariable Long id) {
List<String> 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);

@ -44,7 +44,7 @@ public interface UnitMapper extends BaseMapper<Unit> {
/**
*
*/
void deleteUsers(List<String> userNames);
void deleteUsers(@Param("userNames") String userNames);
/**
* id

@ -50,7 +50,7 @@ public interface UnitService extends IService<Unit> {
/**
*
*/
void deleteUsers(List<String> userNames);
void deleteUsers(String userNames);
/**
*
*/

@ -35,8 +35,6 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
*/
@Override
public Page<Unit> page(Page<Unit> page, UnitRequest unit) {
return baseMapper.selectUnitList(page,unit);
}
@ -61,10 +59,11 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
/**
*
*
*/
@Override
public void validUser(Unit x) {
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)));
@ -75,7 +74,9 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
Long[] roles = new Long[]{100L};
userService.insertUserAuth(user.getUserId(), roles);
}else {
throw new ServiceException(x.getUserName() + "'已存在单位!");
//只修改用户账号,密码,单位名称
userService.updateUserProfile(user);
}
}
}
@ -90,7 +91,7 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
*
*/
@Override
public void deleteUsers(List<String> userNames) {
public void deleteUsers(String userNames) {
baseMapper.deleteUsers(userNames);
}

@ -52,7 +52,7 @@ spring:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: test
active: druid
# 文件上传
servlet:
multipart:

@ -28,6 +28,7 @@
and create_time &lt;= #{req.endTime}
</if>
</where>
order by create_time desc
</select>
<select id="page1" resultType="com.ruoyi.tc.entity.AssetExport">
@ -119,8 +120,8 @@
and a.create_time &lt;= #{req.endTime}
</if>
</where>
order by create_time desc
</select>
<update id="deleteByUnitIds">
update asset_current
set del_flag = '2'

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.tc.mapper.ExamineInfoMapper">
<update id="deleteByUnitIds">
update asset_examine_info set del_flag = '2' where unit_id = #{id}
update unit_examine_info set del_flag = '2' where unit_id = #{id}
</update>
</mapper>

@ -136,9 +136,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update unit_info set del_flag = '2' where id = #{id}
</update>
<update id="deleteUsers">
update sys_user set del_flag = '2' where user_name in
<foreach collection="array" item="userNames" open="(" separator="," close=")">
#{userNames}
</foreach>
update sys_user set del_flag = '2' where user_name = #{userNames}
</update>
</mapper>

@ -5,9 +5,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.ruoyi.tc.mapper.UnitOtherConcatMapper">
<update id="deleteByUnitIds">
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>
<update id="deleteByAssetIds">
update asset_supply_chain set del_flag = '2' where asset_id = #{id}
update unit_other_contact set del_flag = '2' where asset_id = #{id}
</update>
</mapper>

@ -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+w3M7a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eBuJbZsrUTOBVkk66j3Ss4cJvQJ9utcFBnS6msEAUCYU6OuInIb/PMv8I7DC7SrrTZpyD9LXKIB4aYtqPrntZSo+75EAHgXNpRYqUwkpZbCuYSIXebno4JOxB1RK8=" +
"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);
}
}

@ -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);

Loading…
Cancel
Save