【8.0】【system】初始化历史密码表

pull/57/head
fengshuonan 2023-10-04 23:33:05 +08:00
parent 2adba4d04b
commit 5ac15fb6f4
9 changed files with 451 additions and 0 deletions

View File

@ -0,0 +1,60 @@
package cn.stylefeng.roses.kernel.sys.modular.security.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
@TableName("sys_user_password_record")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysUserPasswordRecord extends BaseEntity {
/**
*
*/
@TableId(value = "record_id", type = IdType.ASSIGN_ID)
@ChineseDescription("主键")
private Long recordId;
/**
* id
*/
@TableField("user_id")
@ChineseDescription("用户id")
private Long userId;
/**
*
*/
@TableField("history_password")
@ChineseDescription("历史密码记录")
private String historyPassword;
/**
*
*/
@TableField("history_password_salt")
@ChineseDescription("历史密码记录盐值")
private String historyPasswordSalt;
/**
*
*/
@TableField("update_password_time")
@ChineseDescription("修改密码时间")
private Date updatePasswordTime;
}

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.sys.modular.security.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
@Getter
public enum SysUserPasswordRecordExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
SYS_USER_PASSWORD_RECORD_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysUserPasswordRecordExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,28 @@
package cn.stylefeng.roses.kernel.sys.modular.security.mapper;
import cn.stylefeng.roses.kernel.sys.modular.security.entity.SysUserPasswordRecord;
import cn.stylefeng.roses.kernel.sys.modular.security.pojo.request.SysUserPasswordRecordRequest;
import cn.stylefeng.roses.kernel.sys.modular.security.pojo.response.SysUserPasswordRecordVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
public interface SysUserPasswordRecordMapper extends BaseMapper<SysUserPasswordRecord> {
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
List<SysUserPasswordRecordVo> customFindList(@Param("page") Page page, @Param("param")SysUserPasswordRecordRequest request);
}

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.stylefeng.roses.kernel.sys.modular.security.mapper.SysUserPasswordRecordMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.sys.modular.security.entity.SysUserPasswordRecord">
<id column="record_id" property="recordId" />
<result column="user_id" property="userId" />
<result column="history_password" property="historyPassword" />
<result column="history_password_salt" property="historyPasswordSalt" />
<result column="update_password_time" property="updatePasswordTime" />
<result column="create_time" property="createTime" />
<result column="create_user" property="createUser" />
<result column="update_time" property="updateTime" />
<result column="update_user" property="updateUser" />
</resultMap>
<sql id="Base_Column_List">
record_id,user_id,history_password,history_password_salt,update_password_time,create_time,create_user,update_time,update_user
</sql>
<resultMap id="customResultMap" type="cn.stylefeng.roses.kernel.sys.modular.security.pojo.response.SysUserPasswordRecordVo" extends="BaseResultMap">
</resultMap>
<select id="customFindList" resultMap="customResultMap">
SELECT
*
FROM
sys_user_password_record tbl
WHERE
<where>
<if test="param.recordId != null and param.recordId != ''">
and tbl.record_id like concat('%',#{param.recordId},'%')
</if>
<if test="param.userId != null and param.userId != ''">
and tbl.user_id like concat('%',#{param.userId},'%')
</if>
<if test="param.historyPassword != null and param.historyPassword != ''">
and tbl.history_password like concat('%',#{param.historyPassword},'%')
</if>
<if test="param.historyPasswordSalt != null and param.historyPasswordSalt != ''">
and tbl.history_password_salt like concat('%',#{param.historyPasswordSalt},'%')
</if>
<if test="param.updatePasswordTime != null and param.updatePasswordTime != ''">
and tbl.update_password_time like concat('%',#{param.updatePasswordTime},'%')
</if>
<if test="param.createTime != null and param.createTime != ''">
and tbl.create_time like concat('%',#{param.createTime},'%')
</if>
<if test="param.createUser != null and param.createUser != ''">
and tbl.create_user like concat('%',#{param.createUser},'%')
</if>
<if test="param.updateTime != null and param.updateTime != ''">
and tbl.update_time like concat('%',#{param.updateTime},'%')
</if>
<if test="param.updateUser != null and param.updateUser != ''">
and tbl.update_user like concat('%',#{param.updateUser},'%')
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,56 @@
package cn.stylefeng.roses.kernel.sys.modular.security.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserPasswordRecordRequest extends BaseRequest {
/**
*
*/
@NotNull(message = "主键不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键")
private Long recordId;
/**
* id
*/
@NotNull(message = "用户id不能为空", groups = {add.class, edit.class})
@ChineseDescription("用户id")
private Long userId;
/**
*
*/
@NotBlank(message = "历史密码记录不能为空", groups = {add.class, edit.class})
@ChineseDescription("历史密码记录")
private String historyPassword;
/**
*
*/
@NotBlank(message = "历史密码记录盐值不能为空", groups = {add.class, edit.class})
@ChineseDescription("历史密码记录盐值")
private String historyPasswordSalt;
/**
*
*/
@NotNull(message = "修改密码时间不能为空", groups = {add.class, edit.class})
@ChineseDescription("修改密码时间")
private String updatePasswordTime;
}

View File

@ -0,0 +1,17 @@
package cn.stylefeng.roses.kernel.sys.modular.security.pojo.response;
import cn.stylefeng.roses.kernel.sys.modular.security.entity.SysUserPasswordRecord;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserPasswordRecordVo extends SysUserPasswordRecord {
}

View File

@ -0,0 +1,74 @@
package cn.stylefeng.roses.kernel.sys.modular.security.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.modular.security.entity.SysUserPasswordRecord;
import cn.stylefeng.roses.kernel.sys.modular.security.pojo.request.SysUserPasswordRecordRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
public interface SysUserPasswordRecordService extends IService<SysUserPasswordRecord> {
/**
*
*
* @param sysUserPasswordRecordRequest
* @author fengshuonan
* @date 2023/10/04 23:28
*/
void add(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
/**
*
*
* @param sysUserPasswordRecordRequest
* @author fengshuonan
* @date 2023/10/04 23:28
*/
void del(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
/**
*
*
* @param sysUserPasswordRecordRequest
* @author fengshuonan
* @date 2023/10/04 23:28
*/
void edit(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
/**
*
*
* @param sysUserPasswordRecordRequest
* @author fengshuonan
* @date 2023/10/04 23:28
*/
SysUserPasswordRecord detail(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
/**
*
*
* @param sysUserPasswordRecordRequest
* @return List<SysUserPasswordRecord>
* @author fengshuonan
* @date 2023/10/04 23:28
*/
List<SysUserPasswordRecord> findList(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
/**
*
*
* @param sysUserPasswordRecordRequest
* @return PageResult<SysUserPasswordRecord>
* @author fengshuonan
* @date 2023/10/04 23:28
*/
PageResult<SysUserPasswordRecord> findPage(SysUserPasswordRecordRequest sysUserPasswordRecordRequest);
}

View File

@ -0,0 +1,106 @@
package cn.stylefeng.roses.kernel.sys.modular.security.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.sys.modular.security.entity.SysUserPasswordRecord;
import cn.stylefeng.roses.kernel.sys.modular.security.enums.SysUserPasswordRecordExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.security.mapper.SysUserPasswordRecordMapper;
import cn.stylefeng.roses.kernel.sys.modular.security.pojo.request.SysUserPasswordRecordRequest;
import cn.stylefeng.roses.kernel.sys.modular.security.service.SysUserPasswordRecordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
@Service
public class SysUserPasswordRecordServiceImpl extends ServiceImpl<SysUserPasswordRecordMapper, SysUserPasswordRecord> implements SysUserPasswordRecordService {
@Override
public void add(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
SysUserPasswordRecord sysUserPasswordRecord = new SysUserPasswordRecord();
BeanUtil.copyProperties(sysUserPasswordRecordRequest, sysUserPasswordRecord);
this.save(sysUserPasswordRecord);
}
@Override
public void del(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
SysUserPasswordRecord sysUserPasswordRecord = this.querySysUserPasswordRecord(sysUserPasswordRecordRequest);
this.removeById(sysUserPasswordRecord.getRecordId());
}
@Override
public void edit(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
SysUserPasswordRecord sysUserPasswordRecord = this.querySysUserPasswordRecord(sysUserPasswordRecordRequest);
BeanUtil.copyProperties(sysUserPasswordRecordRequest, sysUserPasswordRecord);
this.updateById(sysUserPasswordRecord);
}
@Override
public SysUserPasswordRecord detail(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
return this.querySysUserPasswordRecord(sysUserPasswordRecordRequest);
}
@Override
public PageResult<SysUserPasswordRecord> findPage(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
LambdaQueryWrapper<SysUserPasswordRecord> wrapper = createWrapper(sysUserPasswordRecordRequest);
Page<SysUserPasswordRecord> pageList = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(pageList);
}
@Override
public List<SysUserPasswordRecord> findList(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
LambdaQueryWrapper<SysUserPasswordRecord> wrapper = this.createWrapper(sysUserPasswordRecordRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
private SysUserPasswordRecord querySysUserPasswordRecord(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
SysUserPasswordRecord sysUserPasswordRecord = this.getById(sysUserPasswordRecordRequest.getRecordId());
if (ObjectUtil.isEmpty(sysUserPasswordRecord)) {
throw new ServiceException(SysUserPasswordRecordExceptionEnum.SYS_USER_PASSWORD_RECORD_NOT_EXISTED);
}
return sysUserPasswordRecord;
}
/**
* wrapper
*
* @author fengshuonan
* @date 2023/10/04 23:28
*/
private LambdaQueryWrapper<SysUserPasswordRecord> createWrapper(SysUserPasswordRecordRequest sysUserPasswordRecordRequest) {
LambdaQueryWrapper<SysUserPasswordRecord> queryWrapper = new LambdaQueryWrapper<>();
Long recordId = sysUserPasswordRecordRequest.getRecordId();
Long userId = sysUserPasswordRecordRequest.getUserId();
String historyPassword = sysUserPasswordRecordRequest.getHistoryPassword();
String historyPasswordSalt = sysUserPasswordRecordRequest.getHistoryPasswordSalt();
String updatePasswordTime = sysUserPasswordRecordRequest.getUpdatePasswordTime();
queryWrapper.eq(ObjectUtil.isNotNull(recordId), SysUserPasswordRecord::getRecordId, recordId);
queryWrapper.eq(ObjectUtil.isNotNull(userId), SysUserPasswordRecord::getUserId, userId);
queryWrapper.like(ObjectUtil.isNotEmpty(historyPassword), SysUserPasswordRecord::getHistoryPassword, historyPassword);
queryWrapper.like(ObjectUtil.isNotEmpty(historyPasswordSalt), SysUserPasswordRecord::getHistoryPasswordSalt, historyPasswordSalt);
queryWrapper.eq(ObjectUtil.isNotNull(updatePasswordTime), SysUserPasswordRecord::getUpdatePasswordTime, updatePasswordTime);
return queryWrapper;
}
}

View File

@ -0,0 +1,12 @@
CREATE TABLE `sys_user_password_record` (
`record_id` bigint(0) NOT NULL COMMENT '主键',
`user_id` bigint(0) NOT NULL COMMENT '用户id',
`history_password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '历史密码记录',
`history_password_salt` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '历史密码记录盐值',
`update_password_time` datetime(0) NOT NULL COMMENT '修改密码时间',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`create_user` bigint(0) NULL DEFAULT NULL COMMENT '创建人',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
`update_user` bigint(0) NULL DEFAULT NULL COMMENT '更新人',
PRIMARY KEY (`record_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户历史密码记录' ROW_FORMAT = Dynamic;