Pārlūkot izejas kodu

init: init project step4: biz code support

shc 1 gadu atpakaļ
vecāks
revīzija
909dab8f63

+ 3 - 1
hnqz-auth/src/main/java/com/qunzhixinxi/hnqz/auth/service/HnqzUserDetailsServiceImpl.java

@@ -118,7 +118,9 @@ public class HnqzUserDetailsServiceImpl implements HnqzUserDetailsService {
                 user.getPlatId(),
                 user.getDrugEntId(),
                 info.getRoles(),
-                user.getRealname());
+                user.getRealname(),
+                user.getLatestChangePwdTime());
+
     }
 
 }

+ 3 - 0
hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/entity/BaseEntity.java

@@ -33,4 +33,7 @@ public abstract class BaseEntity implements Serializable {
 	// 创建
 	public @interface Create {
 	}
+
+	public @interface Renew {
+	}
 }

+ 10 - 1
hnqz-common/hnqz-common-security/src/main/java/com/qunzhixinxi/hnqz/common/security/component/HnqzUserAuthenticationConverter.java

@@ -1,6 +1,7 @@
 
 package com.qunzhixinxi.hnqz.common.security.component;
 
+import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
@@ -19,6 +20,8 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -70,6 +73,12 @@ public class HnqzUserAuthenticationConverter implements UserAuthenticationConver
             if (StrUtil.isBlank(realName)) {
                 realName = MapUtil.getStr(map, "realname");
             }
+            String changePwdTime = MapUtil.getStr(map, "latestChangePwdTime", "");
+            LocalDateTime latestChangePwdTime = null;
+            if (StrUtil.isNotBlank(changePwdTime)) {
+                latestChangePwdTime = LocalDateTime.parse(changePwdTime, DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
+
+            }
             Integer id = MapUtil.getInt(map, SecurityConstants.DETAILS_USER_ID);
             Integer deptId = MapUtil.getInt(map, SecurityConstants.DETAILS_DEPT_ID);
             Integer tenantId = MapUtil.getInt(map, SecurityConstants.DETAILS_TENANT_ID);
@@ -80,7 +89,7 @@ public class HnqzUserAuthenticationConverter implements UserAuthenticationConver
 
 
             HnqzUser user = new HnqzUser(id, deptId, phone, avatar, tenantId, username, N_A, true, true, true, true,
-                    authorities, platId, drugEntId, null, realName);
+                    authorities, platId, drugEntId, null, realName, latestChangePwdTime);
             return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
         }
         return null;

+ 9 - 1
hnqz-common/hnqz-common-security/src/main/java/com/qunzhixinxi/hnqz/common/security/service/HnqzUser.java

@@ -6,6 +6,7 @@ import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.SpringSecurityCoreVersion;
 import org.springframework.security.core.userdetails.User;
 
+import java.time.LocalDateTime;
 import java.util.Collection;
 
 /**
@@ -63,6 +64,11 @@ public class HnqzUser extends User {
      */
     private final Integer[] roles;
 
+    /**
+     * 最新更新密码时间
+     */
+    private final LocalDateTime latestChangePwdTime;
+
     /**
      * Construct the <code>User</code> with the details required by
      * {@link DaoAuthenticationProvider}.
@@ -71,6 +77,7 @@ public class HnqzUser extends User {
      * @param deptId                部门ID
      * @param tenantId              租户ID
      * @param realName              真实名称
+     * @param latestChangePwdTime   最新更新密码时间
      * @param username              the username presented to the
      *                              <code>DaoAuthenticationProvider</code>
      * @param password              the password that should be presented to the
@@ -88,7 +95,7 @@ public class HnqzUser extends User {
     public HnqzUser(Integer id, Integer deptId, String phone, String avatar, Integer tenantId, String username,
                     String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired,
                     boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, String platId,
-                    Integer drugEntId, Integer[] roles, String realName) {
+                    Integer drugEntId, Integer[] roles, String realName, LocalDateTime latestChangePwdTime) {
         super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
         this.id = id;
         this.deptId = deptId;
@@ -99,6 +106,7 @@ public class HnqzUser extends User {
         this.drugEntId = drugEntId;
         this.roles = roles;
         this.realName = realName;
+        this.latestChangePwdTime = latestChangePwdTime;
     }
 
 }

+ 3 - 2
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/dto/UserPwd.java

@@ -1,5 +1,6 @@
 package com.qunzhixinxi.hnqz.admin.api.dto;
 
+import com.qunzhixinxi.hnqz.common.core.entity.BaseEntity;
 import lombok.Data;
 
 import javax.validation.constraints.NotEmpty;
@@ -11,10 +12,10 @@ public class UserPwd {
 	@NotEmpty(message = "用户名不能为空")
 	private String userName;
 
-	@NotEmpty(message = "新密码不能为空")
+	@NotEmpty(message = "新密码不能为空", groups = {BaseEntity.Renew.class})
 	private String p1;
 
-	@NotEmpty(message = "新密码不能为空")
+	@NotEmpty(message = "新密码不能为空", groups = {BaseEntity.Renew.class})
 	private String p2;
 
 	@NotEmpty(message = "验证码不能为空")

+ 5 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/entity/SysUser.java

@@ -30,6 +30,11 @@ public class SysUser implements Serializable {
     @TableId(value = "user_id", type = IdType.AUTO)
     private Integer userId;
 
+    /**
+     * 最新更新密码时间
+     */
+    private LocalDateTime latestChangePwdTime;
+
     /**
      * 用户名
      */

+ 168 - 163
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/vo/UserVO.java

@@ -18,168 +18,173 @@ import java.util.List;
 @Data
 public class UserVO implements Serializable {
 
-	private static final long serialVersionUID = 1L;
-
-	/**
-	 * 主键ID
-	 */
-	private Integer userId;
-
-	/**
-	 * 用户名
-	 */
-	private String username;
-
-	/**
-	 * 身份证号
-	 */
-	private String idCardNumber;
-
-	/**
-	 * 密码
-	 */
-	private String password;
-
-	/**
-	 * 随机盐
-	 */
-	private String salt;
-
-	/**
-	 * 微信openid
-	 */
-	private String wxOpenid;
-
-	/**
-	 * QQ openid
-	 */
-	private String qqOpenid;
-
-	/**
-	 * 创建时间
-	 */
-	private LocalDateTime createTime;
-
-	/**
-	 * 修改时间
-	 */
-	private LocalDateTime updateTime;
-
-	/**
-	 * 0-正常,1-删除
-	 */
-	private String delFlag;
-
-	/**
-	 * 锁定标记
-	 */
-	private String lockFlag;
-
-	/**
-	 * 手机号
-	 */
-	@Sensitive(type = SensitiveTypeEnum.MOBILE_PHONE)
-	private String phone;
-
-	/**
-	 * 头像
-	 */
-	private String avatar;
-
-	/**
-	 * 部门ID
-	 */
-	private Integer deptId;
-
-	/**
-	 * 租户ID
-	 */
-	private Integer tenantId;
-
-	/**
-	 * 部门名称
-	 */
-	private String deptName;
-
-	/**
-	 * 用户姓名
-	 */
-	private String realname;
-
-	/**
-	 * 地址
-	 */
-	private String address;
-	/**
-	 * 备用字段1
-	 */
-	private String temp1;
-	/**
-	 * 备用字段2
-	 */
-	private String temp2;
-	/**
-	 * 备用字段3
-	 */
-	private String temp3;
-	/**
-	 * 备用字段4
-	 */
-	private String temp4;
-	/**
-	 * 备用字段5
-	 */
-	private String temp5;
-
-	/**
-	 * 备用字段5
-	 */
-	private String platId;
-
-	/**
-	 * 备用字段5
-	 */
-	private Integer drugEntId;
-
-	/**
-	 * 角色列表
-	 */
-	private List<SysRole> roleList;
-
-	/**
-	 * 备用字段5
-	 */
-	private String w1;
-
-	private String userSign;
-
-
-	/**
-	 * 小程序签署协议信息
-	 */
-	private String signAgreement;
-
-	/**
-	 * 是否提醒年龄超60周岁
-	 */
-	private Boolean ageReminder;
-
-	/**
-	 * 是否已补签协议
-	 */
-	private Integer reSignedAgreement;
-
-	@TableField(exist = false)
-	private List<WmQuizResultModel> quizResult;
-
-	/**
-	 * 上级主管
-	 */
-	private List<Integer> parentIdList;
-
-	/**
-	 * 区域代码
-	 */
-	private List<Long> areaCodes;
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    private Integer userId;
+
+    /**
+     * 用户名
+     */
+    private String username;
+
+    /**
+     * 最近更新密码时间
+     */
+    private LocalDateTime latestChangePwdTime;
+
+    /**
+     * 身份证号
+     */
+    private String idCardNumber;
+
+    /**
+     * 密码
+     */
+    private String password;
+
+    /**
+     * 随机盐
+     */
+    private String salt;
+
+    /**
+     * 微信openid
+     */
+    private String wxOpenid;
+
+    /**
+     * QQ openid
+     */
+    private String qqOpenid;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 修改时间
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 0-正常,1-删除
+     */
+    private String delFlag;
+
+    /**
+     * 锁定标记
+     */
+    private String lockFlag;
+
+    /**
+     * 手机号
+     */
+    @Sensitive(type = SensitiveTypeEnum.MOBILE_PHONE)
+    private String phone;
+
+    /**
+     * 头像
+     */
+    private String avatar;
+
+    /**
+     * 部门ID
+     */
+    private Integer deptId;
+
+    /**
+     * 租户ID
+     */
+    private Integer tenantId;
+
+    /**
+     * 部门名称
+     */
+    private String deptName;
+
+    /**
+     * 用户姓名
+     */
+    private String realname;
+
+    /**
+     * 地址
+     */
+    private String address;
+    /**
+     * 备用字段1
+     */
+    private String temp1;
+    /**
+     * 备用字段2
+     */
+    private String temp2;
+    /**
+     * 备用字段3
+     */
+    private String temp3;
+    /**
+     * 备用字段4
+     */
+    private String temp4;
+    /**
+     * 备用字段5
+     */
+    private String temp5;
+
+    /**
+     * 备用字段5
+     */
+    private String platId;
+
+    /**
+     * 备用字段5
+     */
+    private Integer drugEntId;
+
+    /**
+     * 角色列表
+     */
+    private List<SysRole> roleList;
+
+    /**
+     * 备用字段5
+     */
+    private String w1;
+
+    private String userSign;
+
+
+    /**
+     * 小程序签署协议信息
+     */
+    private String signAgreement;
+
+    /**
+     * 是否提醒年龄超60周岁
+     */
+    private Boolean ageReminder;
+
+    /**
+     * 是否已补签协议
+     */
+    private Integer reSignedAgreement;
+
+    @TableField(exist = false)
+    private List<WmQuizResultModel> quizResult;
+
+    /**
+     * 上级主管
+     */
+    private List<Integer> parentIdList;
+
+    /**
+     * 区域代码
+     */
+    private List<Long> areaCodes;
 
 }

+ 18 - 3
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/SysUserController.java

@@ -9,7 +9,6 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.nacos.common.utils.Md5Utils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.plugin.excel.annotation.RequestExcel;
@@ -39,6 +38,7 @@ import com.qunzhixinxi.hnqz.admin.service.SysUserService;
 import com.qunzhixinxi.hnqz.admin.service.WmPlatformQuizTestResultService;
 import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
 import com.qunzhixinxi.hnqz.common.core.entity.BaseEntity;
+import com.qunzhixinxi.hnqz.common.core.exception.BizException;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
 import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
@@ -264,7 +264,7 @@ public class SysUserController {
     }
 
     /**
-     * 添加用户
+     * 修改密码
      *
      * @param userPwd 用户信息
      * @return success/false
@@ -272,7 +272,22 @@ public class SysUserController {
     @Inner(value = false)
     @SysLog("修改密码")
     @PostMapping("/upd")
-    public R<?> updatePwd(@RequestBody @Valid UserPwd userPwd) {
+    public R<?> updatePwd(@RequestBody @Validated UserPwd userPwd) {
+
+        return userService.updatePwd(userPwd);
+    }
+
+    /**
+     * 添加用户
+     *
+     * @param userPwd 用户信息
+     * @return success/false
+     */
+    @SysLog("更新密码")
+    @PostMapping("/pwd/renew")
+    public R<?> renewPwd(@RequestBody @Validated(BaseEntity.Renew.class) UserPwd userPwd) {
+
+        userPwd.setUserName(SecurityUtils.getUser().getUsername());
 
         return userService.updatePwd(userPwd);
     }

+ 6 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/SysUserServiceImpl.java

@@ -915,10 +915,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
     @Override
     public R<?> updatePwd(UserPwd userPwd) {
+
         String p1 = userPwd.getP1();
         String p2 = userPwd.getP2();
         String userName = userPwd.getUserName();
+
         List<SysUser> userList = baseMapper.selectList(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userName));
+
         if (CollectionUtils.isEmpty(userList)) {
             return R.failed("用户不存在");
         }
@@ -926,10 +929,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         if (!p1.equals(p2)) {
             return R.failed("两次密码输入不一致");
         }
+        LocalDateTime now = LocalDateTime.now();
         for (SysUser sysUser : userList) {
             sysUser.setUserId(sysUser.getUserId());
             sysUser.setW1(Md5Utils.getMD5(p1.getBytes()));
             sysUser.setPassword(ENCODER.encode(p1));
+            sysUser.setLatestChangePwdTime(now);
+            sysUser.setUpdateTime(now);
             baseMapper.updateById(sysUser);
         }
 

+ 3 - 0
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -6,6 +6,7 @@
         <id column="user_id" property="userId"/>
         <result column="username" property="username"/>
         <result column="password" property="password"/>
+        <result column="latest_change_pwd_time" property="latestChangePwdTime"/>
         <result column="salt" property="salt"/>
         <result column="phone" property="phone"/>
         <result column="id_card_number" property="idCardNumber"/>
@@ -36,6 +37,7 @@
         <id column="user_id" property="userId"/>
         <result column="username" property="username"/>
         <result column="password" property="password"/>
+        <result column="latest_change_pwd_time" property="latestChangePwdTime"/>
         <result column="salt" property="salt"/>
         <result column="phone" property="phone"/>
         <result column="id_card_number" property="idCardNumber"/>
@@ -72,6 +74,7 @@
         <id column="user_id" property="userId"/>
         <result column="username" property="username"/>
         <result column="password" property="password"/>
+        <result column="latest_change_pwd_time" property="latestChangePwdTime"/>
         <result column="salt" property="salt"/>
         <result column="phone" property="phone"/>
         <result column="id_card_number" property="idCardNumber"/>