登录优化

master
shijie 4 years ago
parent ce413e665f
commit 53434efcdd
  1. 2
      dq-financial-guarantee/src/main/resources/bootstrap.properties
  2. 2
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java
  3. 9
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java
  4. 5
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java
  5. 6
      dq-financial-hrms-auth/src/main/resources/mapper/hrauth/UserLoginMapper.xml
  6. 2
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java

@ -1,5 +1,5 @@
#服务名称
#spring.application.name=dq-financial-guarantee
spring.application.name=dq-financial-guarantee
##配置中心地址
spring.cloud.nacos.config.server-addr=192.168.31.140:8848
spring.cloud.nacos.config.namespace=58fa89c6-0e23-4530-ac13-95747e873c60

@ -31,4 +31,6 @@ public interface UserLoginDao extends BaseMapper<UserEntity> {
Boolean updateUserLogin(@Param("userId") Long userId, @Param("date") Date date);
Integer countWeChatId(String weChatId);
String getNameByUserId(Long userId);
}

@ -47,6 +47,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private AuthEmployeeRoleDao userRoleMapper;
@Autowired
private HrauthFeignService hrauthFeignService;
@Autowired
private UserLoginDao userLoginDao;
/***
* 根据账号获取用户信息
@ -57,13 +59,20 @@ public class UserDetailsServiceImpl implements UserDetailsService {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 从数据库中取出用户信息
List<UserEntity> userList = userMapper.selectList(new QueryWrapper<UserEntity>().eq("phone_account", username));
List<UserEntity> userList2 = userMapper.selectList(new QueryWrapper<UserEntity>().eq("account", username));
UserEntity user;
String name = null;
// 判断用户是否存在
if (!CollectionUtils.isEmpty(userList)) {
user = userList.get(0);
name = userLoginDao.getNameByUserId(userList.get(0).getId());
} else if(!CollectionUtils.isEmpty(userList2)){
user = userList2.get(0);
name = userLoginDao.getNameByUserId(userList2.get(0).getId());
} else {
throw new UsernameNotFoundException("用户名不存在或已禁用!");
}
user.setAccount(name);
// 返回UserDetails实现类
return new SecurityUser(user, getUserRoles(user.getId().intValue()));
}

@ -117,7 +117,10 @@ public class UserLoginServiceImpl extends ServiceImpl<UserLoginDao, UserEntity>
public ResponseResult login(LoginRequest loginRequest) {
//判断用户登录方式
UserEntity userEntity = baseMapper.login(loginRequest);
String name = null;
if(userEntity != null){
//获取员工name
name = baseMapper.getNameByUserId(userEntity.getId());
//删除redis里面的userEntity
JwtUtils.removeUserEntityByUserId(userEntity.getId());
}
@ -206,7 +209,7 @@ public class UserLoginServiceImpl extends ServiceImpl<UserLoginDao, UserEntity>
//返回用户信息
LoginResponse loginResponse = new LoginResponse();
loginResponse.setAccount(userEntity.getAccount());
loginResponse.setAccount(name);
loginResponse.setToken(token);
if(headImg != null)
loginResponse.setHeadPortaritUrl(headImg);

@ -28,7 +28,7 @@
select id,account,phone_account,password,login_num from hrms_user
where del_or_not = 0 and status = 0
<if test="phone != null and phone != '' ">
and phone_account = #{phone}
and (phone_account = #{phone} or account = #{phone})
</if>
<if test="wechatId != null and wechatId != '' ">
and wechat_id = #{wechatId}
@ -63,4 +63,8 @@
SELECT COUNT(id) FROM hrms_user WHERE wechat_id = #{weChatId}
</select>
<select id="getNameByUserId" parameterType="long" resultType="string">
SELECT `name` FROM hrms_employee WHERE user_id = #{userId}
</select>
</mapper>

@ -8,7 +8,7 @@ public class LoginRequest {
private int id;
@ApiModelProperty(value = "手机号码")
@ApiModelProperty(value = "手机号码/账号")
private String phone;
@ApiModelProperty(value = "登录类型(1:手机号 2:微信登录)")

Loading…
Cancel
Save