|
@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -98,6 +99,8 @@ public class LoginService implements ILoginService {
|
|
|
@Override
|
|
|
public RestResponse login(HttpServletRequest request, UserRequest userRequest) {
|
|
|
String password = userRequest.getPassword();
|
|
|
+ //登录端类型
|
|
|
+ Integer mobileType = userRequest.getMobileType();
|
|
|
if (StringUtils.isBlank(userRequest.getMobile())) {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "手机号为空无法登录");
|
|
|
}
|
|
@@ -119,8 +122,8 @@ public class LoginService implements ILoginService {
|
|
|
int userType = userAccount.getType() != null ? userAccount.getType() : ApiConstants.UserConstants.TYPE_USER;
|
|
|
if (ApiConstants.UserConstants.PUBLIC_TYPE_USER == userType) {
|
|
|
//物管端用户,查看登录端
|
|
|
- if (ApiConstants.ACCESS_TYPE_APPLETS == userRequest.getMobileType()
|
|
|
- || ApiConstants.ACCESS_TYPE_PC == userRequest.getMobileType()) {
|
|
|
+ if (ApiConstants.ACCESS_TYPE_APPLETS == mobileType
|
|
|
+ || ApiConstants.ACCESS_TYPE_PC == mobileType) {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "没有登录权限");
|
|
|
}
|
|
|
}
|
|
@@ -133,7 +136,20 @@ public class LoginService implements ILoginService {
|
|
|
//登录成功后初始化登录信息
|
|
|
UserResponse userResponse = initLoginInfo(request, userRequest);
|
|
|
//添加登录记录
|
|
|
- userLoginService.saveLoginInfo(request, userAccount.getUserId());
|
|
|
+ if (!userLoginService.saveLoginInfo(request, userAccount.getUserId())) {
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "保存登录记录失败");
|
|
|
+ }
|
|
|
+ //将登录设备类型更新到数据库
|
|
|
+ if (ApiConstants.ACCESS_TYPE_APP == mobileType) {
|
|
|
+ //设备类型: 1.Android 2:IOS
|
|
|
+ userAccount.setDeviceModel(userRequest.getDeviceModel());
|
|
|
+ //设备唯一标识
|
|
|
+ userAccount.setDeviceFlag(userRequest.getDeviceFlag());
|
|
|
+ if (!userAccountService.updateById(userAccount)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "更新设备类型失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
return RestResponse.success(userResponse, ApiConstants.RESULT_SUCCESS, "登录成功");
|
|
|
}
|
|
|
|
|
@@ -145,7 +161,6 @@ public class LoginService implements ILoginService {
|
|
|
public Object getLoginUserInfoFromRedis(UserRequest userRequest) {
|
|
|
Object mobileUserInfo = getUserInfoKeyInRedis(userRequest);
|
|
|
//获取电话是否在redis中存在
|
|
|
- assert mobileUserInfo != null;
|
|
|
return redisTemplate.opsForValue().get(mobileUserInfo);
|
|
|
}
|
|
|
|