Commit 420a901e authored by 赵啸非's avatar 赵啸非

同步接口

parent d200201e
Pipeline #2681 canceled with stages
......@@ -8,11 +8,10 @@
package com.mortals.xhx.base.system.user.dao.ibatis;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.framework.model.ParamDto;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import org.springframework.stereotype.Repository;
import java.util.List;
......
package com.mortals.xhx.base.system.user.model;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.user.model.vo.UserVo;
import java.util.Date;
import java.util.Objects;
/**
*
* Description:User
* date: 2021-9-26 16:11:48
*/
public class UserEntity extends UserEntityExt implements IUser {
private static final long serialVersionUID = 1632643908537L;
* 用户信息业务实体对象
*
* @author zxfei
* @date 2022-07-05
*/
public class UserEntity extends UserVo implements IUser {
private static final long serialVersionUID = 1L;
/**
* 登录名
*/
* 登录名
*/
private String loginName;
/**
* 登录密码,使用md5双次加密
*/
* 登录密码,使用md5双次加密
*/
private String loginPwd;
/**
* 最近一次使用密码,使用md5双次加密
*/
private String loginPwd1;
/**
* 最近二次使用密码,使用md5双次加密
*/
private String loginPwd2;
/**
* 最近三次使用密码,使用md5双次加密
*/
private String loginPwd3;
/**
* 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
*/
* 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
*/
private String loginLimitAddress;
/**
* 用户名
*/
* 用户名
*/
private String realName;
/**
* 用户手机号
*/
* 用户手机号
*/
private String mobile;
/**
* 用户联系电话
*/
* 用户联系电话
*/
private String phone;
/**
* 用户邮箱
*/
* 用户邮箱
*/
private String email;
/**
* QQ号码
*/
* QQ号码
*/
private String qq;
/**
* 用户类型,0:系统用户 1:普通用户 2:工作人员,默认2
*/
* 用户类型(0.系统用户,1.普通用户,2.工作人员)
*/
private Integer userType;
/**
* 站点id
*/
private Long siteId;
/**
* 用户状态,0:停用,1:正常,2:冻结,3:销户,4:离职,默认1
*/
private Integer status;
/**
* 客户ID
*/
private Long customerId;
* 所属站点id,多个逗号分隔
*/
private String siteIds;
/**
* 创建时间
*/
private Date createTime;
* 所属区域code,多个逗号分隔
*/
private String areaCodes;
/**
* 创建用户
*/
private Long createUserId;
* 用户状态(0.停用,1.正常,2.冻结,3.销户,4.离职)
*/
private Integer status;
/**
* 创建用户名称
*/
* 创建用户名称
*/
private String createUserName;
/**
* 最后一次登录时间
*/
* 最后一次登录时间
*/
private Date lastLoginTime;
/**
* 最后一次登录地址
*/
* 最后一次登录地址
*/
private String lastLoginAddress;
/**
* 最后修改密码时间
*/
private Date lastModPwdTime;
/**
* 最后修改密码地址
*/
private String lastModPwdAddr;
public UserEntity(){
}
public UserEntity(){}
/**
* 获取 登录名
* @return loginName
*/
public String getLoginName() {
return this.loginName;
* 获取 登录名
* @return String
*/
public String getLoginName(){
return loginName;
}
/**
* 设置 登录名
* @param loginName
*/
public void setLoginName(String loginName) {
* 设置 登录名
* @param loginName
*/
public void setLoginName(String loginName){
this.loginName = loginName;
}
/**
* 获取 登录密码,使用md5双次加密
* @return loginPwd
*/
public String getLoginPwd() {
return this.loginPwd;
* 获取 登录密码,使用md5双次加密
* @return String
*/
public String getLoginPwd(){
return loginPwd;
}
/**
* 设置 登录密码,使用md5双次加密
* @param loginPwd
*/
public void setLoginPwd(String loginPwd) {
* 设置 登录密码,使用md5双次加密
* @param loginPwd
*/
public void setLoginPwd(String loginPwd){
this.loginPwd = loginPwd;
}
/**
* 获取 最近一次使用密码,使用md5双次加密
* @return loginPwd1
*/
public String getLoginPwd1() {
return this.loginPwd1;
}
/**
* 设置 最近一次使用密码,使用md5双次加密
* @param loginPwd1
*/
public void setLoginPwd1(String loginPwd1) {
this.loginPwd1 = loginPwd1;
}
/**
* 获取 最近二次使用密码,使用md5双次加密
* @return loginPwd2
*/
public String getLoginPwd2() {
return this.loginPwd2;
}
/**
* 设置 最近二次使用密码,使用md5双次加密
* @param loginPwd2
*/
public void setLoginPwd2(String loginPwd2) {
this.loginPwd2 = loginPwd2;
* 获取 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
* @return String
*/
public String getLoginLimitAddress(){
return loginLimitAddress;
}
/**
* 获取 最近三次使用密码,使用md5双次加密
* @return loginPwd3
*/
public String getLoginPwd3() {
return this.loginPwd3;
}
/**
* 设置 最近三次使用密码,使用md5双次加密
* @param loginPwd3
*/
public void setLoginPwd3(String loginPwd3) {
this.loginPwd3 = loginPwd3;
}
/**
* 获取 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
* @return loginLimitAddress
*/
public String getLoginLimitAddress() {
return this.loginLimitAddress;
}
/**
* 设置 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
* @param loginLimitAddress
*/
public void setLoginLimitAddress(String loginLimitAddress) {
* 设置 登录限制地址,多个IP地址用逗号分隔,可以使用IP段匹配,如:172.17.*非空:则只能该值内的IP可以登录
* @param loginLimitAddress
*/
public void setLoginLimitAddress(String loginLimitAddress){
this.loginLimitAddress = loginLimitAddress;
}
/**
* 获取 用户名
* @return realName
*/
public String getRealName() {
return this.realName;
* 获取 用户名
* @return String
*/
public String getRealName(){
return realName;
}
@Override
......@@ -236,149 +145,111 @@ public class UserEntity extends UserEntityExt implements IUser {
}
/**
* 设置 用户名
* @param realName
*/
public void setRealName(String realName) {
* 设置 用户名
* @param realName
*/
public void setRealName(String realName){
this.realName = realName;
}
/**
* 获取 用户手机号
* @return mobile
*/
public String getMobile() {
return this.mobile;
* 获取 用户手机号
* @return String
*/
public String getMobile(){
return mobile;
}
/**
* 设置 用户手机号
* @param mobile
*/
public void setMobile(String mobile) {
* 设置 用户手机号
* @param mobile
*/
public void setMobile(String mobile){
this.mobile = mobile;
}
/**
* 获取 用户联系电话
* @return phone
*/
public String getPhone() {
return this.phone;
* 获取 用户联系电话
* @return String
*/
public String getPhone(){
return phone;
}
/**
* 设置 用户联系电话
* @param phone
*/
public void setPhone(String phone) {
* 设置 用户联系电话
* @param phone
*/
public void setPhone(String phone){
this.phone = phone;
}
/**
* 获取 用户邮箱
* @return email
*/
public String getEmail() {
return this.email;
* 获取 用户邮箱
* @return String
*/
public String getEmail(){
return email;
}
/**
* 设置 用户邮箱
* @param email
*/
public void setEmail(String email) {
* 设置 用户邮箱
* @param email
*/
public void setEmail(String email){
this.email = email;
}
/**
* 获取 QQ号码
* @return qq
*/
public String getQq() {
return this.qq;
* 获取 QQ号码
* @return String
*/
public String getQq(){
return qq;
}
/**
* 设置 QQ号码
* @param qq
*/
public void setQq(String qq) {
* 设置 QQ号码
* @param qq
*/
public void setQq(String qq){
this.qq = qq;
}
/**
* 获取 用户类型,0:系统用户 1:普通用户 2:工作人员,默认2
* @return userType
*/
public Integer getUserType() {
return this.userType;
* 获取 用户类型(0.系统用户,1.普通用户,2.工作人员)
* @return Integer
*/
public Integer getUserType(){
return userType;
}
@Override
public String getMenuUrl() {
return null;
}
/**
* 设置 用户类型,0:系统用户 1:普通用户 2:工作人员,默认2
* @param userType
*/
public void setUserType(Integer userType) {
* 设置 用户类型(0.系统用户,1.普通用户,2.工作人员)
* @param userType
*/
public void setUserType(Integer userType){
this.userType = userType;
}
/**
* 获取 站点id
* @return siteId
*/
public Long getSiteId() {
return this.siteId;
}
@Override
public String getSiteIds() {
return super.getSiteIds();
public Long getDeptId() {
return null;
}
@Override
public String getAreaCodes() {
public String getDeptName() {
return null;
}
/**
* 设置 站点id
* @param siteId
*/
public void setSiteId(Long siteId) {
this.siteId = siteId;
}
/**
* 获取 用户状态,0:停用,1:正常,2:冻结,3:销户,4:离职,默认1
* @return status
*/
public Integer getStatus() {
return this.status;
}
/**
* 设置 用户状态,0:停用,1:正常,2:冻结,3:销户,4:离职,默认1
* @param status
*/
public void setStatus(Integer status) {
this.status = status;
}
@Override
public Long getDeptId() {
public Long getCustomerId() {
return null;
}
@Override
public String getDeptName() {
public Long getSiteId() {
return null;
}
/**
* 获取 客户ID
* @return customerId
*/
public Long getCustomerId() {
return this.customerId;
* 获取 所属站点id,多个逗号分隔
* @return String
*/
public String getSiteIds(){
return siteIds;
}
@Override
public Long getCustomerJoinId() {
return null;
......@@ -390,123 +261,96 @@ public class UserEntity extends UserEntityExt implements IUser {
}
/**
* 设置 客户ID
* @param customerId
*/
public void setCustomerId(Long customerId) {
this.customerId = customerId;
* 设置 所属站点id,多个逗号分隔
* @param siteIds
*/
public void setSiteIds(String siteIds){
this.siteIds = siteIds;
}
/**
* 获取 创建时间
* @return createTime
*/
public Date getCreateTime() {
return this.createTime;
* 获取 所属区域code,多个逗号分隔
* @return String
*/
public String getAreaCodes(){
return areaCodes;
}
/**
* 设置 创建时间
* @param createTime
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
* 设置 所属区域code,多个逗号分隔
* @param areaCodes
*/
public void setAreaCodes(String areaCodes){
this.areaCodes = areaCodes;
}
/**
* 获取 创建用户
* @return createUserId
*/
public Long getCreateUserId() {
return this.createUserId;
* 获取 用户状态(0.停用,1.正常,2.冻结,3.销户,4.离职)
* @return Integer
*/
public Integer getStatus(){
return status;
}
/**
* 设置 创建用户
* @param createUserId
*/
public void setCreateUserId(Long createUserId) {
this.createUserId = createUserId;
* 设置 用户状态(0.停用,1.正常,2.冻结,3.销户,4.离职)
* @param status
*/
public void setStatus(Integer status){
this.status = status;
}
/**
* 获取 创建用户名称
* @return createUserName
*/
public String getCreateUserName() {
return this.createUserName;
* 获取 创建用户名称
* @return String
*/
public String getCreateUserName(){
return createUserName;
}
/**
* 设置 创建用户名称
* @param createUserName
*/
public void setCreateUserName(String createUserName) {
* 设置 创建用户名称
* @param createUserName
*/
public void setCreateUserName(String createUserName){
this.createUserName = createUserName;
}
/**
* 获取 最后一次登录时间
* @return lastLoginTime
*/
public Date getLastLoginTime() {
return this.lastLoginTime;
* 获取 最后一次登录时间
* @return Date
*/
public Date getLastLoginTime(){
return lastLoginTime;
}
/**
* 设置 最后一次登录时间
* @param lastLoginTime
*/
public void setLastLoginTime(Date lastLoginTime) {
* 设置 最后一次登录时间
* @param lastLoginTime
*/
public void setLastLoginTime(Date lastLoginTime){
this.lastLoginTime = lastLoginTime;
}
/**
* 获取 最后一次登录地址
* @return lastLoginAddress
*/
public String getLastLoginAddress() {
return this.lastLoginAddress;
* 获取 最后一次登录地址
* @return String
*/
public String getLastLoginAddress(){
return lastLoginAddress;
}
/**
* 设置 最后一次登录地址
* @param lastLoginAddress
*/
public void setLastLoginAddress(String lastLoginAddress) {
* 设置 最后一次登录地址
* @param lastLoginAddress
*/
public void setLastLoginAddress(String lastLoginAddress){
this.lastLoginAddress = lastLoginAddress;
}
/**
* 获取 最后修改密码时间
* @return lastModPwdTime
*/
public Date getLastModPwdTime() {
return this.lastModPwdTime;
}
/**
* 设置 最后修改密码时间
* @param lastModPwdTime
*/
public void setLastModPwdTime(Date lastModPwdTime) {
this.lastModPwdTime = lastModPwdTime;
}
/**
* 获取 最后修改密码地址
* @return lastModPwdAddr
*/
public String getLastModPwdAddr() {
return this.lastModPwdAddr;
}
/**
* 设置 最后修改密码地址
* @param lastModPwdAddr
*/
public void setLastModPwdAddr(String lastModPwdAddr) {
this.lastModPwdAddr = lastModPwdAddr;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), loginName, loginPwd, loginPwd1, loginPwd2, loginPwd3, loginLimitAddress, realName, mobile, phone, email, qq, userType, status, customerId, createTime, createUserId, createUserName, lastLoginTime, lastLoginAddress, lastModPwdTime, lastModPwdAddr);
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == null) return false;
if (obj instanceof UserEntity) {
UserEntity tmp = (UserEntity) obj;
if (this.getId().longValue() == tmp.getId().longValue()) {
if (this.getId() == tmp.getId()) {
return true;
}
}
......@@ -515,56 +359,54 @@ public class UserEntity extends UserEntityExt implements IUser {
public String toString(){
StringBuilder sb = new StringBuilder("");
sb
.append(",id:").append(getId())
.append(",loginName:").append(getLoginName())
.append(",loginPwd:").append(getLoginPwd())
.append(",loginPwd1:").append(getLoginPwd1())
.append(",loginPwd2:").append(getLoginPwd2())
.append(",loginPwd3:").append(getLoginPwd3())
.append(",loginLimitAddress:").append(getLoginLimitAddress())
.append(",realName:").append(getRealName())
.append(",mobile:").append(getMobile())
.append(",phone:").append(getPhone())
.append(",email:").append(getEmail())
.append(",qq:").append(getQq())
.append(",userType:").append(getUserType())
.append(",siteId:").append(getSiteId())
.append(",status:").append(getStatus())
.append(",customerId:").append(getCustomerId())
.append(",createTime:").append(getCreateTime())
.append(",createUserId:").append(getCreateUserId())
.append(",createUserName:").append(getCreateUserName())
.append(",lastLoginTime:").append(getLastLoginTime())
.append(",lastLoginAddress:").append(getLastLoginAddress())
.append(",lastModPwdTime:").append(getLastModPwdTime())
.append(",lastModPwdAddr:").append(getLastModPwdAddr())
;
sb.append(",loginName:").append(getLoginName());
sb.append(",loginPwd:").append(getLoginPwd());
sb.append(",loginLimitAddress:").append(getLoginLimitAddress());
sb.append(",realName:").append(getRealName());
sb.append(",mobile:").append(getMobile());
sb.append(",phone:").append(getPhone());
sb.append(",email:").append(getEmail());
sb.append(",qq:").append(getQq());
sb.append(",userType:").append(getUserType());
sb.append(",siteIds:").append(getSiteIds());
sb.append(",areaCodes:").append(getAreaCodes());
sb.append(",status:").append(getStatus());
sb.append(",createUserName:").append(getCreateUserName());
sb.append(",lastLoginTime:").append(getLastLoginTime());
sb.append(",lastLoginAddress:").append(getLastLoginAddress());
return sb.toString();
}
public void initAttrValue(){
this.loginName = null;
this.loginPwd = null;
this.loginPwd1 = null;
this.loginPwd2 = null;
this.loginPwd3 = null;
this.loginLimitAddress = null;
this.realName = null;
this.mobile = null;
this.phone = null;
this.email = null;
this.qq = null;
this.userType = null;
this.siteId = null;
this.status = 1;
this.customerId = null;
this.createTime = null;
this.createUserId = null;
this.createUserName = null;
this.lastLoginTime = null;
this.lastLoginAddress = null;
this.lastModPwdTime = null;
this.lastModPwdAddr = null;
this.loginName = "";
this.loginPwd = "";
this.loginLimitAddress = "";
this.realName = "";
this.mobile = "";
this.phone = "";
this.email = "";
this.qq = "";
this.userType = null;
this.siteIds = "";
this.areaCodes = "";
this.status = 1;
this.createUserName = "";
this.lastLoginTime = null;
this.lastLoginAddress = "";
}
}
\ No newline at end of file
package com.mortals.xhx.base.system.user.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import java.util.List;
/**
* Description:User
* date: 2021-9-26 16:11:48
*/
@Data
public class UserEntityExt extends BaseEntityLong {
/**
* 唯一标识
*/
@JSONField(serialize = false)
private String token;
/**
* 登录时间
*/
private Long loginTime;
/**
* 过期时间
*/
private Long expireTime;
private String siteName;
private List<Long> roleIds;
private String siteCode;
private String oldPassword;
private String newPassword;
private String siteIds;
/**
* 菜单栏
*/
private String menuUrl;
/**
* 所属区域code,多个逗号分隔
*/
private String areaCodes;
}
\ No newline at end of file
package com.mortals.xhx.base.system.user.model;
import java.util.Date;
import java.util.List;
/**
* 用户信息业务查询对象
......
......@@ -4,9 +4,6 @@ package com.mortals.xhx.base.system.user.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 用户信息业务视图对象
*
......@@ -15,12 +12,13 @@ import java.util.List;
*/
@Data
public class UserVo extends BaseEntityLong {
/**
* 站点名称
*/
private String siteName;
private List<Long> roleIds;
private String roleIds;
/**
* 唯一标识
*/
......@@ -40,7 +38,7 @@ public class UserVo extends BaseEntityLong {
*/
private Long expireTime;
private Long siteId;
private Long customerId;
private String oldPassword;
private String newPassword;
private String siteIds;
}
\ No newline at end of file
......@@ -8,8 +8,8 @@
package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
......@@ -29,16 +29,8 @@ import java.util.Set;
*/
public interface UserService extends ICRUDCacheService<UserEntity,Long> {
/**
* 用户登录
*
* @param loginName 登录用户名
* @param password 登录密码
* @param loginIp 登录IP
* @return
* @throws AppException
*/
public UserEntity doLogin(String loginName, String password, String loginIp) throws AppException;
/**
* 校验用户名与密码是否正确
......@@ -48,16 +40,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return
* @throws AppException
*/
public UserEntity doCheckUser(String loginName, String password) throws AppException;
/**
* 检查用户是否存在
*
* @param loginName 登录用户名
* @param userId 密码
* @return
*/
public boolean existUser(String loginName, Long userId) throws AppException;
UserEntity doCheckUser(String loginName, String password) throws AppException;
/**
* 通过登录用户获取菜单功能权限
......@@ -65,7 +48,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param user
* @return
*/
public List<MenuEntity> findOutlookBarList(IUser user);
List<MenuEntity> findOutlookBarList(IUser user);
/**
* 查询用户所有有权限的菜单ID
......@@ -73,47 +56,9 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userEntity
* @return
*/
public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException;
/**
* 查询用户记录
*
* @param platformId
* @param params
* @param currPage
* @param prePageResult
* @return
* @throws AppException
*/
public Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException;
/**
* 为客户创建用户
*
* @param currUser 当前用户
* @param customerId 客户ID
* @param customerName 客户名称
* @param loginName
* @param password
* @param userName
* @param mobile
* @return
* @throws AppException
*/
public UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password,
String userName, String mobile) throws AppException;
/**
* 用户修改密码
*
* @param loginName
* @param oldPwd
* @param newPwd
* @return
* @throws AppException
*/
public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException;
Rest<Void> refreshUser();
UserDao getUserDao();
......
......@@ -9,11 +9,10 @@
package com.mortals.xhx.base.system.user.service.impl;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.SecurityUtil;
......@@ -22,27 +21,37 @@ import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleUserDao;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>Title: 用户信息</p>
* <p>Description: UserServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
*
* @author
* @version 1.0.0
*/
@Service("userService")
@Slf4j
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
......@@ -50,8 +59,12 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
private MenuService menuService;
@Autowired
private ResourceService resourceService;
@Autowired
private RoleUserService roleUserService;
@Autowired
private RoleUserDao roleUserDao;
private IUserFeign userFeign;
@Override
protected String getExtKey(UserEntity data) {
......@@ -59,147 +72,57 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
@Override
public UserEntity doCheckUser(String loginName, String password) throws AppException {
private void doHandlerUser(UserEntity entity) throws AppException {
if (StringUtils.isNotEmpty(entity.getLoginPwd())) {
try {
entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd()));
} catch (Exception e) {
throw new AppException("密码转换异常");
UserQuery params = new UserQuery();
params.setLoginName(loginName);
UserEntity sysUser = this.selectOne(params);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
return null;
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
return null;
}
} else {
entity.setLoginPwd(null);
} catch (Exception e) {
log.error("查询用户异常,loginName:" + loginName, e);
return null;
}
// if (entity.isSystemUser()) {
// entity.setUserType(UserType.SYSTEM.getValue());
// } else {
// entity.setUserType(UserType.CUSTOMER.getValue());
// }
return sysUser;
}
@Override
protected void saveBefore(UserEntity entity, Context context) throws AppException {
this.doHandlerUser(entity);
}
@Override
protected void saveAfter(UserEntity entity, Context context) throws AppException {
if(CollectionUtils.isNotEmpty(entity.getRoleIds())){
List<RoleUserEntity> roleUserEntityList = new ArrayList<>();
entity.getRoleIds().stream().forEach(item->{
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setUserId(entity.getId());
roleUserEntity.setRoleId(item);
roleUserEntityList.add(roleUserEntity);
});
roleUserDao.insertBatch(roleUserEntityList);
}
}
@Override
protected void updateBefore(UserEntity entity, Context context) throws AppException {
if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) {
throw new AppException("你没有权限执行该操作");
}
this.doHandlerUser(entity);
updateUserRole(entity);
}
@Override
protected void updateAfter(UserEntity entity, Context context) throws AppException {
if(CollectionUtils.isNotEmpty(entity.getRoleIds())){
List<RoleUserEntity> roleUserEntityList = new ArrayList<>();
entity.getRoleIds().stream().forEach(item->{
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setUserId(entity.getId());
roleUserEntity.setRoleId(item);
roleUserEntityList.add(roleUserEntity);
});
RoleUserEntity condition = new RoleUserEntity();
condition.setUserId(entity.getId());
roleUserDao.delete(condition);
roleUserDao.insertBatch(roleUserEntityList);
}
}
@Override
protected UserEntity findBefore(UserEntity params, Context context) throws AppException {
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return super.findBefore(params, context);
}
@Override
protected UserEntity findBefore(UserEntity params, PageInfo pageInfo, Context context) throws AppException {
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return super.findBefore(params, pageInfo, context);
}
@Override
protected void findAfter(UserEntity params, PageInfo pageInfo, Context context, List<UserEntity> list) throws AppException {
if(CollectionUtils.isNotEmpty(list)) {
list.stream().forEach(item->{
RoleUserEntity query = new RoleUserEntity();
query.setUserId(item.getId());
List<RoleUserEntity> roleUserEntityList = roleUserDao.getList(query);
List<Long> roleIds = new ArrayList<>();
roleUserEntityList.stream().forEach(role->{
roleIds.add(role.getRoleId());
});
item.setRoleIds(roleIds);
});
//List<RoleUserEntity> roleUserEntityList =
}
updateUserRole(entity);
}
public UserEntity findByLoginName(String loginName) {
UserQuery params = new UserQuery();
params.setLoginName(loginName);
List<UserEntity> userList = super.dao.getList(params);
if (userList != null && userList.size() > 0) {
return userList.get(0);
private void updateUserRole(UserEntity entity) {
if (!ObjectUtils.isEmpty(entity.getId()) && entity.getId().longValue() != SysConstains.ADMIN_ID && !ObjectUtils.isEmpty(entity.getRoleIds())) {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
roleUserQuery.setRoleIdList(idList);
roleUserService.doDistributionRole(roleUserQuery);
}
return null;
}
@Override
public UserEntity doLogin(String loginName, String password, String loginIp) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("用户名不存在!");
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
throw new AppException("登录密码错误!");
}
} catch (Exception e) {
throw new AppException("密码验认出错!", e);
}
UserEntity update = new UserEntity();
update.setId(sysUser.getId());
update.setLastLoginAddress(loginIp);
update.setLastLoginTime(new Date());
this.dao.update(update);
return sysUser;
protected void findAfter(UserEntity params, PageInfo pageInfo, Context context, List<UserEntity> list) throws AppException {
list.stream().peek(item -> {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(item.getId());
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(","));
item.setRoleIds(roleIds);
}).count();
}
@Override
public UserEntity doCheckUser(String loginName, String password) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
return null;
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
return null;
}
} catch (Exception e) {
return null;
}
return sysUser;
}
@Override
public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException {
......@@ -267,77 +190,83 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
}
@Override
public Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException {
PageInfo pageInfo = new PageInfo(prePageResult);
pageInfo.setCurrPage(currPage);
return super.find(params, pageInfo, null);
}
public Rest<Void> refreshUser() {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
@Override
public UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password,
String userName, String mobile) throws AppException {
try {
UserEntity entity = new UserEntity();
entity.initAttrValue();
entity.setLoginName(loginName);
entity.setRealName(userName);
entity.setCustomerId(customerId);
entity.setLoginPwd(password);
entity.setMobile(mobile);
entity.setUserType(UserType.CUSTOMER.getValue());
entity.setCreateTime(new Date());
if (currUser != null) {
entity.setCreateUser(currUser.getLoginName());
entity.setCreateUserName(currUser.getRealName());
}
this.doHandlerUser(entity);
dao.insert(entity);
return entity;
} catch (Exception e) {
log.error("给客户创建用户异常-->customerId:" + customerId + ",customerName:" + customerName + ",loginName:" + loginName +
"-->原因:" + e.getMessage());
return null;
}
}
List<UserEntity> saveUpdateUserList = newUserList.parallelStream().map(item -> {
UserEntity extCache = this.getExtCache(item.getLoginName());
if (ObjectUtils.isEmpty(extCache)) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
} else {
//更新用户列表
item.setId(extCache.getId());
item.setUpdateUserId(1L);
item.setUpdateUserName("系统管理员");
item.setUpdateTime(new Date());
return item;
}
}).collect(Collectors.toList());
Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
//需要新增的用户
log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
saveUpdateCollect.get(true).stream().forEach(item -> {
this.getUserDao().insert(item);
this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(item.getId());
roleUserQuery.setRoleIdList(Arrays.asList(1L));
roleUserService.doDistributionRole(roleUserQuery);
});
}
@Override
public boolean existUser(String loginName, Long userId) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
boolean bRet = false;
if (sysUser != null) {
if (userId == null || userId == 0 || userId.longValue() != sysUser.getId().longValue()) {
bRet = true;
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(false))) {
//需要新增的用户
log.info("需要更新用户数量:{}", saveUpdateCollect.get(false).size());
saveUpdateCollect.get(false).stream().forEach(item -> {
this.getUserDao().update(item);
this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
});
}
//差集删除
Set<String> collectSet = newUserList.parallelStream().map(x -> x.getLoginName()).collect(Collectors.toSet());
Long[] removeUserIds = this.getCacheList().parallelStream().filter(f -> !collectSet.contains(f.getLoginName())).map(i -> i.getId()).distinct().toArray(Long[]::new);
if (!ObjectUtils.isEmpty(removeUserIds)) {
log.info("需要删除的本地用户数量:{}", removeUserIds.length);
this.remove(removeUserIds, null);
}
}
//查找新增 与更新
}
return bRet;
return Rest.ok();
}
@Override
public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("帐号错误!");
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(oldPwd))) {
throw new AppException("原始密码错误!");
}
} catch (Exception e) {
throw new AppException("密码验认出错!", e);
}
try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
sysUser.setLoginPwd3(sysUser.getLoginPwd2());
sysUser.setLoginPwd2(sysUser.getLoginPwd1());
sysUser.setLoginPwd1(sysUser.getLoginPwd());
sysUser.setLastModPwdTime(new Date());
} catch (Exception e) {
throw new AppException("密码转换异常!", e);
}
dao.update(sysUser);
return true;
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
super.removeAfter(ids, context, result);
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserIdList(Arrays.asList(ids));
Long[] userIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getId).toArray(Long[]::new);
roleUserService.remove(userIds, context);
}
@Override
public UserDao getUserDao() {
return this.getDao();
......
/**
* 文件:UserController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.user.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.framework.annotation.Operlog;
import com.mortals.xhx.base.system.role.model.RoleQuery;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.UserStatus;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 用户信息
*
* @author: zxfei
* @date: 2022/5/7 15:42
* <p>Title: 用户信息</p>
* <p>Description: UserController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
@RestController
@RequestMapping("user")
......@@ -47,91 +42,28 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Autowired
private RoleService roleService;
@Autowired
private RoleUserService roleUserService;
public UserController() {
super.setFormClass(UserForm.class);
super.setModuleDesc("用户信息");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model, "status", UserStatus.getEnumMap());
this.addDict(model, "roleIds", roleService.find(new RoleQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getName())));
}
@Override
protected void doListBefore(UserEntity query, Map<String, Object> model, Context context) throws AppException {
if (!StringUtils.isEmpty(query.getRealName())) {
query.setRealName("%".concat(query.getRealName()).concat("%"));
}
if (!StringUtils.isEmpty(query.getLoginName())) {
query.setLoginName("%".concat(query.getLoginName()).concat("%"));
}
}
@Override
protected int editAfter(Long id, Map<String, Object> model, UserEntity entity, Context context) throws AppException {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
List<Long> roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).collect(Collectors.toList());
entity.setRoleIds(roleIds);
return super.editAfter(id, model, entity, context);
}
@Override
protected int saveAfter(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
if (entity.getId() == getCurUser().getId()) {
// TODO: 2022/8/15 更新redis session信息
//saveCurrUserForSession(request, response, userService.get(form.getEntity().getId(), false));
}
return super.saveAfter(entity, model, context);
}
// @Override
// protected void saveBefore(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
// if (!ObjectUtils.isEmpty(entity.getLoginName()) && service.existUser(entity.getLoginName(), entity.getId())) {
// throw new AppException("登录名已存在!");
// }
// super.saveBefore(entity, model, context);
// }
@RequestMapping(value = "change/password", method = RequestMethod.POST)
@Operlog(msg = "密码修改成功!")
public String changePassword(@RequestParam String oldPwd, @RequestParam String newPwd) {
JSONObject ret = new JSONObject();
try {
service.updateUserPwd(super.getCurUser().getLoginName(), oldPwd, newPwd);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "密码修改成功!");
} catch (Exception e) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
}
return ret.toJSONString();
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model,"status", UserStatus.getEnumMap());
List<RoleEntity> roleList = roleService.find(new RoleEntity());
this.addDict(model,"roleId", roleList.stream().collect(Collectors.toMap(e->e.getId().toString(), e->e.getName())));
super.init(model, context);
}
public static void main(String[] args) {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIzNGE5NDA5ZDVhOTQ3MWNhMzdkYjZkYmMwY2JjZTc5In0.MWyQW40HYDxyUz7PJRf_nRsFPWx3Hr811Ime984nixs";
String secret = "026db82420614469897fcc2dc1b4ce38";
Claims claims = Jwts.parser()
.setSigningKey(Base64.getEncoder().encodeToString(secret.getBytes()))
.parseClaimsJws(token)
.getBody();
String uuid = (String) claims.get("login_user_key");
System.out.println(uuid);
@PostMapping({"refreshUser"})
@UnAuth
public Rest<Object> refreshUser() {
log.info("刷新用户");
this.service.refreshUser();
return Rest.ok("用户同步刷新操作成功");
}
}
\ No newline at end of file
/**
* 文件:UserForm.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.user.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
/**
* <p>Title: 用户信息</p>
* <p>Description: UserForm </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
public class UserForm extends BaseCRUDFormLong<UserEntity> {
private UserEntity entity = new UserEntity();
private UserQuery query = new UserQuery();
public UserForm(){
}
@Override
public UserEntity getEntity() {
return entity;
}
public void setEntity(UserEntity entity) {
this.entity = entity;
}
@Override
public UserQuery getQuery() {
return query;
}
public void setQuery(UserQuery query) {
this.query = query;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment