重庆用户加解密

This commit is contained in:
mashuai 2024-06-05 13:37:52 +08:00
parent 84299f69af
commit a5f7806154
9 changed files with 144 additions and 31 deletions

View File

@ -8,6 +8,7 @@ import com.bonus.sgzb.auth.service.NwRegisterService;
import com.bonus.sgzb.auth.service.NwUserLoginService; import com.bonus.sgzb.auth.service.NwUserLoginService;
import com.bonus.sgzb.auth.utils.RsaUtil; import com.bonus.sgzb.auth.utils.RsaUtil;
import com.bonus.sgzb.common.core.constant.CacheConstants; import com.bonus.sgzb.common.core.constant.CacheConstants;
import com.bonus.sgzb.common.core.constant.Constants;
import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.redis.service.RedisService; import com.bonus.sgzb.common.redis.service.RedisService;
import com.bonus.sgzb.system.api.RemoteUserService; import com.bonus.sgzb.system.api.RemoteUserService;
@ -35,7 +36,6 @@ import java.util.Map;
@Slf4j @Slf4j
public class TokenController { public class TokenController {
private final String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=";
@Autowired @Autowired
private TokenService tokenService; private TokenService tokenService;
@ -57,7 +57,7 @@ public class TokenController {
//web端登录 //web端登录
@PostMapping("login") @PostMapping("login")
public R<?> login(@RequestBody LoginBody form) throws Exception { public R<?> login(@RequestBody LoginBody form) throws Exception {
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), privateKey); String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), Constants.privateKey);
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData); LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
String uuid = form.getUuid(); String uuid = form.getUuid();

View File

@ -132,4 +132,25 @@ public class Constants
*/ */
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.bonus.sgzb.common.core.utils.file" }; "org.springframework", "org.apache", "com.bonus.sgzb.common.core.utils.file" };
/**
* 系统初始密码
*/
public static final String USER_PASSWORD = "CqCc@2024*";
/**
* 系统初始密码
*/
public static final String CONFIG_KEY = "sys.user.initPassword";
/**
* 加密公钥
*/
public static final String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==";
/**
* 解密私钥
*/
public static final String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=";
} }

View File

@ -17,8 +17,8 @@ public class FieldGenerator {
String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
// 生成UUID并取后4位转换为纯数字类型 // 生成UUID并取后4位转换为纯数字类型
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String uuidLast4Digits = uuid.substring(uuid.length() - 4); String uuidLast4Digits = uuid.substring(uuid.length() - 7);
int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16); int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
return currentDate + "-" + String.format("%04d", uuidLast4DigitsNumeric % 10000); return currentDate + "-" + String.format("%07d", uuidLast4DigitsNumeric % 10000);
} }
} }

View File

@ -45,6 +45,11 @@ public class MachIneDto {
@ApiModelProperty(value = "设备编号") @ApiModelProperty(value = "设备编号")
private String maCode; private String maCode;
/** 二维码 */
@ApiModelProperty(value = "二维码")
private String qrCode;
/** /**
* 类型id * 类型id
*/ */

View File

@ -72,4 +72,6 @@ public interface InventoryAndWarehousingMapper {
* @return * @return
*/ */
int selectTaskNumByMonth(@Param("date") Date nowDate); int selectTaskNumByMonth(@Param("date") Date nowDate);
int selectByCode(String code);
} }

View File

@ -4,6 +4,7 @@ import com.bonus.sgzb.common.core.utils.DateUtils;
import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.config.ExceptionEnum; import com.bonus.sgzb.material.config.ExceptionEnum;
import com.bonus.sgzb.material.config.FieldGenerator;
import com.bonus.sgzb.material.domain.MachIneDto; import com.bonus.sgzb.material.domain.MachIneDto;
import com.bonus.sgzb.material.domain.PutInStorageBean; import com.bonus.sgzb.material.domain.PutInStorageBean;
import com.bonus.sgzb.material.domain.SavePutInfoDto; import com.bonus.sgzb.material.domain.SavePutInfoDto;
@ -11,6 +12,7 @@ import com.bonus.sgzb.material.mapper.InventoryAndWarehousingMapper;
import com.bonus.sgzb.material.service.InventoryAndWarehousingService; import com.bonus.sgzb.material.service.InventoryAndWarehousingService;
import com.bonus.sgzb.material.vo.GlobalContants; import com.bonus.sgzb.material.vo.GlobalContants;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -18,6 +20,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author hay * @author hay
@ -72,13 +75,23 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
log.info("新增入库盘点入参dto{}", dto); log.info("新增入库盘点入参dto{}", dto);
Long userId = SecurityUtils.getLoginUser().getUserid(); Long userId = SecurityUtils.getLoginUser().getUserid();
dto.setCreator(userId); dto.setCreator(userId);
List<String> codeList = new ArrayList<>();
if (dto.getNum() != null) {
while (codeList.size() < dto.getNum()) {
String code = FieldGenerator.generateField();
int count = selectByCode(code);
if (count == 0 && !codeList.contains(code)) {
codeList.add(code);
}
}
}
String code = genderBackCode(); String code = genderBackCode();
int res; int res;
try { try {
//1. 判断是数量还是编号入库保存到不同表 //1. 判断是数量还是编号入库保存到不同表
//1.1 如果是编号入库 //1.1 如果是编号入库
if (dto.getIsCode()) { if (dto.getIsCode()) {
res = insertMaMachineInfo(dto, code); res = insertMaMachineInfo(dto, codeList, code);
if (res == 0) { if (res == 0) {
log.error("insertMaMachineInfo方法插入异常"); log.error("insertMaMachineInfo方法插入异常");
throw new RuntimeException("insertMaMachineInfo方法插入异常"); throw new RuntimeException("insertMaMachineInfo方法插入异常");
@ -106,17 +119,38 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
return AjaxResult.success(res); return AjaxResult.success(res);
} }
/**
* 根据code从ma_machine表查询是否有数据去重
* @param code
* @return
*/
private int selectByCode(String code) {
return inventoryAndWarehousingMapper.selectByCode(code);
}
/** /**
* 编号新增插入ma_machinema_machine_label和ma_label_bind * 编号新增插入ma_machinema_machine_label和ma_label_bind
* @param dto * @param dto
* @param code * @param code
* @return * @return
*/ */
private int insertMaMachineInfo(SavePutInfoDto dto, String code) { private int insertMaMachineInfo(SavePutInfoDto dto, List<String> codeList, String code) {
int res = 0; int res = 0;
if (dto.getNum() != null) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(0);
machIneDto.setCode(code);
machIneDto.setPutInType(dto.getPutInType());
machIneDto.setCreator(dto.getCreator());
machIneDto.setNum(dto.getNum());
machIneDto.setIsCode(dto.getIsCode());
res += insertInfo(machIneDto);
machIneDto.setInfoId(machIneDto.getId());
}
for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { for (int i = 0; i < dto.getMachIneDtoList().size(); i++) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(i); MachIneDto machIneDto = dto.getMachIneDtoList().get(i);
machIneDto.setCode(code); machIneDto.setCode(code);
String qrCode = codeList.get(i);
machIneDto.setQrCode(qrCode);
machIneDto.setIsCode(dto.getIsCode()); machIneDto.setIsCode(dto.getIsCode());
machIneDto.setTypeId(dto.getTypeId()); machIneDto.setTypeId(dto.getTypeId());
machIneDto.setCreator(dto.getCreator()); machIneDto.setCreator(dto.getCreator());
@ -126,11 +160,17 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
machIneDto.setCheckMan(dto.getCheckMan()); machIneDto.setCheckMan(dto.getCheckMan());
machIneDto.setUnitId(dto.getUnitId()); machIneDto.setUnitId(dto.getUnitId());
machIneDto.setProId(dto.getProId()); machIneDto.setProId(dto.getProId());
machIneDto.setInfoId(dto.getMachIneDtoList().get(0).getInfoId());
res += insertMachineInfo(machIneDto); res += insertMachineInfo(machIneDto);
} }
return res; return res;
} }
//插入ma_type_put_in_storage_info表,返回主键id
private int insertInfo(MachIneDto machIneDto) {
return inventoryAndWarehousingMapper.saveInfo(machIneDto);
}
/** /**
* 方法抽取保持到ma_machinema_machine_label和ma_label_bind * 方法抽取保持到ma_machinema_machine_label和ma_label_bind
* @param machIneDto * @param machIneDto
@ -150,11 +190,8 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
* @return * @return
*/ */
private int insertTypePutInStorageInfo(MachIneDto machIneDto) { private int insertTypePutInStorageInfo(MachIneDto machIneDto) {
//插入ma_type_put_in_storage_info表,返回主键id
int res = inventoryAndWarehousingMapper.saveInfo(machIneDto);
//ma_type_put_in_storage_details表 //ma_type_put_in_storage_details表
res += inventoryAndWarehousingMapper.saveDetails(machIneDto); return inventoryAndWarehousingMapper.saveDetails(machIneDto);
return res;
} }
@ -176,6 +213,20 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
*/ */
private int insertPutInfo(SavePutInfoDto dto, String code) { private int insertPutInfo(SavePutInfoDto dto, String code) {
int res = 0; int res = 0;
Double total = dto.getMachIneDtoList().stream()
.map(MachIneDto::getPutInStoreNum)
.filter(num -> num != null)
.collect(Collectors.summingDouble(Double::doubleValue));
if (CollectionUtils.isNotEmpty(dto.getMachIneDtoList())) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(0);
machIneDto.setCode(code);
machIneDto.setPutInType(dto.getPutInType());
machIneDto.setCreator(dto.getCreator());
machIneDto.setIsCode(dto.getIsCode());
machIneDto.setTotalNum(total);
res += insertInfo(machIneDto);
machIneDto.setInfoId(machIneDto.getId());
}
for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { for (int i = 0; i < dto.getMachIneDtoList().size(); i++) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(i); MachIneDto machIneDto = dto.getMachIneDtoList().get(i);
machIneDto.setCreator(dto.getCreator()); machIneDto.setCreator(dto.getCreator());
@ -184,6 +235,7 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
machIneDto.setUnitId(dto.getUnitId()); machIneDto.setUnitId(dto.getUnitId());
machIneDto.setProId(dto.getProId()); machIneDto.setProId(dto.getProId());
machIneDto.setCode(code); machIneDto.setCode(code);
machIneDto.setInfoId(dto.getMachIneDtoList().get(0).getInfoId());
res += insertTypePutInStorageInfo(machIneDto); res += insertTypePutInStorageInfo(machIneDto);
//根据类型追加ma_type表里面的num //根据类型追加ma_type表里面的num
res += updateMaTypeInfo(machIneDto.getTypeId(), machIneDto.getPutInStoreNum()); res += updateMaTypeInfo(machIneDto.getTypeId(), machIneDto.getPutInStoreNum());

View File

@ -4,9 +4,19 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.material.mapper.InventoryAndWarehousingMapper"> <mapper namespace="com.bonus.sgzb.material.mapper.InventoryAndWarehousingMapper">
<insert id="saveDetails" useGeneratedKeys="true" keyProperty="id"> <insert id="saveDetails" useGeneratedKeys="true" keyProperty="id">
INSERT INTO ma_type_put_in_storage_details (NUM, INSERT INTO ma_type_put_in_storage_details (
<trim prefix="" suffixOverrides=","> <trim prefix="" suffixOverrides=",">
<if test="id != null and id != ''"> <choose>
<when test="isCode and num != null and num != 0">
NUM,
</when>
<otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0">
NUM,
</if>
</otherwise>
</choose>
<if test="infoId != null and infoId != ''">
INFO, INFO,
</if> </if>
<if test="typeId != null and typeId != ''"> <if test="typeId != null and typeId != ''">
@ -23,10 +33,20 @@
</if> </if>
</trim> </trim>
) )
VALUES (1, VALUES (
<choose>
<when test="isCode and num != null and num != 0">
1,
</when>
<otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0">
#{putInStoreNum},
</if>
</otherwise>
</choose>
<trim prefix="" suffixOverrides=","> <trim prefix="" suffixOverrides=",">
<if test="id != null and id != ''"> <if test="infoId != null and infoId != ''">
#{id}, #{infoId},
</if> </if>
<if test="typeId != null and typeId != ''"> <if test="typeId != null and typeId != ''">
#{typeId}, #{typeId},
@ -52,7 +72,7 @@
NUM, NUM,
</when> </when>
<otherwise> <otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0"> <if test="totalNum != null and totalNum != 0">
NUM, NUM,
</if> </if>
</otherwise> </otherwise>
@ -81,8 +101,8 @@
#{num}, #{num},
</when> </when>
<otherwise> <otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0"> <if test="totalNum != null and totalNum != 0">
#{putInStoreNum}, #{totalNum},
</if> </if>
</otherwise> </otherwise>
</choose> </choose>
@ -108,7 +128,7 @@
<if test="typeId != null and typeId != '' ">type_id,</if> <if test="typeId != null and typeId != '' ">type_id,</if>
<if test="maCode != null and maCode != '' ">ma_code,</if> <if test="maCode != null and maCode != '' ">ma_code,</if>
ma_status, ma_status,
<if test="code != null and code != ''">qr_code,</if> <if test="qrCode != null and qrCode != ''">qr_code,</if>
<if test="buyPrice != null and buyPrice != ''">buy_price,</if> <if test="buyPrice != null and buyPrice != ''">buy_price,</if>
<if test="maVender != null and maVender != ''">ma_vender,</if> <if test="maVender != null and maVender != ''">ma_vender,</if>
<if test="checkMan != null and checkMan != ''">check_man,</if> <if test="checkMan != null and checkMan != ''">check_man,</if>
@ -120,7 +140,7 @@
<if test="typeId != null and typeId != ''">#{typeId},</if> <if test="typeId != null and typeId != ''">#{typeId},</if>
<if test="maCode != null and maCode != ''">#{maCode},</if> <if test="maCode != null and maCode != ''">#{maCode},</if>
15, 15,
<if test="code != null and code != ''">#{code},</if> <if test="qrCode != null and qrCode != ''">#{qrCode},</if>
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if> <if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
<if test="maVender != null and maVender != ''">#{maVender},</if> <if test="maVender != null and maVender != ''">#{maVender},</if>
<if test="checkMan != null and checkMan != ''">#{checkMan},</if> <if test="checkMan != null and checkMan != ''">#{checkMan},</if>
@ -133,14 +153,14 @@
<insert id="insertMachineLabel"> <insert id="insertMachineLabel">
insert into ma_machine_label insert into ma_machine_label
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="code != null">label_code,</if> <if test="qrCode != null">label_code,</if>
<if test="maId != null">ma_id,</if> <if test="maId != null">ma_id,</if>
is_bind, is_bind,
label_type, label_type,
create_time create_time
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="code != null">#{code},</if> <if test="qrCode != null">#{qrCode},</if>
<if test="maId != null">#{maId},</if> <if test="maId != null">#{maId},</if>
1, 1,
9, 9,
@ -151,7 +171,7 @@
insert into ma_label_bind insert into ma_label_bind
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="maId != null">ma_id,</if> <if test="maId != null">ma_id,</if>
<if test="code != null">label_code,</if> <if test="qrCode != null">label_code,</if>
<if test="typeId != null">type_id,</if> <if test="typeId != null">type_id,</if>
<if test="creator != null">binder,</if> <if test="creator != null">binder,</if>
label_type, label_type,
@ -160,7 +180,7 @@
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="maId != null">#{maId},</if> <if test="maId != null">#{maId},</if>
<if test="code != null">#{code},</if> <if test="qrCode != null">#{qrCode},</if>
<if test="typeId != null">#{typeId},</if> <if test="typeId != null">#{typeId},</if>
<if test="creator != null">#{creator},</if> <if test="creator != null">#{creator},</if>
9, 9,
@ -211,4 +231,11 @@
<select id="selectTaskNumByMonth" resultType="java.lang.Integer"> <select id="selectTaskNumByMonth" resultType="java.lang.Integer">
select count(*) from ma_type_put_in_storage_info where DATE_FORMAT(CREATE_DATE,'%y%m') = DATE_FORMAT(#{date},'%y%m') select count(*) from ma_type_put_in_storage_info where DATE_FORMAT(CREATE_DATE,'%y%m') = DATE_FORMAT(#{date},'%y%m')
</select> </select>
<select id="selectByCode" resultType="java.lang.Integer">
select count(*)
from ma_machine
<where>
<if test="code != null ">and qr_code = #{code}</if>
</where>
</select>
</mapper> </mapper>

View File

@ -6,9 +6,11 @@ import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.bonus.sgzb.common.core.constant.Constants;
import com.bonus.sgzb.common.core.domain.R; import com.bonus.sgzb.common.core.domain.R;
import com.bonus.sgzb.common.core.utils.DateTimeHelper; import com.bonus.sgzb.common.core.utils.DateTimeHelper;
import com.bonus.sgzb.system.api.domain.SysFile; import com.bonus.sgzb.system.api.domain.SysFile;
import com.bonus.sgzb.system.config.RsaUtil;
import com.bonus.sgzb.system.domain.FileInfo; import com.bonus.sgzb.system.domain.FileInfo;
import com.bonus.sgzb.system.service.SysFileService; import com.bonus.sgzb.system.service.SysFileService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
@ -98,20 +100,22 @@ public class SysProfileController extends BaseController {
*/ */
@Log(title = "个人信息", businessType = BusinessType.UPDATE) @Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd") @PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) { public AjaxResult updatePwd(String oldPassword, String newPassword) throws Exception {
String oldDecrypt = RsaUtil.decryptByPrivateKey(oldPassword, Constants.privateKey);
String newDecrypt = RsaUtil.decryptByPrivateKey(newPassword, Constants.privateKey);
String username = SecurityUtils.getUsername(); String username = SecurityUtils.getUsername();
SysUser user = userService.selectUserByUserName(username); SysUser user = userService.selectUserByUserName(username);
String password = user.getPassword(); String password = user.getPassword();
if (!SecurityUtils.matchesPassword(oldPassword, password)) { if (!SecurityUtils.matchesPassword(oldDecrypt, password)) {
return error("修改密码失败,旧密码错误"); return error("修改密码失败,旧密码错误");
} }
if (SecurityUtils.matchesPassword(newPassword, password)) { if (SecurityUtils.matchesPassword(newDecrypt, password)) {
return error("新密码不能与旧密码相同"); return error("新密码不能与旧密码相同");
} }
if (userService.resetUserPwd(username, SecurityUtils.encryptPassword(newPassword)) > 0) { if (userService.resetUserPwd(username, SecurityUtils.encryptPassword(newDecrypt)) > 0) {
// 更新缓存用户密码 // 更新缓存用户密码
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
loginUser.getSysUser().setPassword(SecurityUtils.encryptPassword(newPassword)); loginUser.getSysUser().setPassword(SecurityUtils.encryptPassword(newDecrypt));
tokenService.setLoginUser(loginUser); tokenService.setLoginUser(loginUser);
return success(); return success();
} }

View File

@ -21,6 +21,7 @@ import com.bonus.sgzb.system.api.domain.SysDept;
import com.bonus.sgzb.system.api.domain.SysRole; import com.bonus.sgzb.system.api.domain.SysRole;
import com.bonus.sgzb.system.api.domain.SysUser; import com.bonus.sgzb.system.api.domain.SysUser;
import com.bonus.sgzb.system.api.model.LoginUser; import com.bonus.sgzb.system.api.model.LoginUser;
import com.bonus.sgzb.system.config.RsaUtil;
import com.bonus.sgzb.system.domain.po.UrgentProcessingUser; import com.bonus.sgzb.system.domain.po.UrgentProcessingUser;
import com.bonus.sgzb.system.service.*; import com.bonus.sgzb.system.service.*;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -264,10 +265,11 @@ public class SysUserController extends BaseController {
@RequiresPermissions("system:user:edit") @RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd") @PutMapping("/resetPwd")
public AjaxResult resetPwd(@RequestBody SysUser user) { public AjaxResult resetPwd(@RequestBody SysUser user) throws Exception {
String decrypt = RsaUtil.decryptByPrivateKey(user.getPassword(), Constants.privateKey);
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(decrypt));
user.setUpdateBy(SecurityUtils.getUsername()); user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.resetPwd(user)); return toAjax(userService.resetPwd(user));
} }