|
@@ -16,13 +16,14 @@ import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -57,6 +58,9 @@ public class LoginService implements ILoginService {
|
|
|
@Resource
|
|
|
private IMaintenanceCompanyService maintenanceCompanyService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IMenuService menuService;
|
|
|
+
|
|
|
@Override
|
|
|
public RestResponse register(HttpServletRequest request, UserRequest userRequest) {
|
|
|
//判断手机号是否为空
|
|
@@ -142,7 +146,7 @@ public class LoginService implements ILoginService {
|
|
|
UserResponse userResponse = new UserResponse();
|
|
|
//校验团队信息
|
|
|
MaintenanceCompany maintenanceCompany = maintenanceCompanyService.getById(companyId);
|
|
|
- if(maintenanceCompany == null){
|
|
|
+ if (maintenanceCompany == null) {
|
|
|
return RestResponse.success(ApiConstants.RESULT_SUCCESS, "切换团队不存在");
|
|
|
}
|
|
|
maintenanceCompany.setCurrentTeamFlag(true);
|
|
@@ -192,23 +196,19 @@ public class LoginService implements ILoginService {
|
|
|
private UserResponse initLoginInfo(HttpServletRequest request, Long userId) {
|
|
|
//获取用户信息
|
|
|
UserResponse userResponse = userService.getLoginUserInfo(userId);
|
|
|
- //将当前公司id放入session中
|
|
|
- if (userResponse.getMaintenanceCompany() != null) {
|
|
|
- request.getSession().setAttribute(ApiConstants.CURRENT_COMPANY_ID, userResponse.getMaintenanceCompany().getId());
|
|
|
- }
|
|
|
- //将用户信息放入session中
|
|
|
- request.getSession().setAttribute(ApiConstants.CURRENT_USER_ID, userResponse.getUserId());
|
|
|
- //将用户登录的信息放入redis中,作为缓存处理设置30分钟过期
|
|
|
- redisTemplate.opsForValue().set(userResponse.getToken(), JSONUtil.toJsonPrettyStr(userResponse), 30L, TimeUnit.MINUTES);
|
|
|
+ //将用户登录的手机号放入session中
|
|
|
+ request.getSession().setAttribute(ApiConstants.UserConstants.USER_INFO_MOBILE, userResponse.getMobile());
|
|
|
+ //封装登录用户信息
|
|
|
+ Map<String, Object> currentUserInfoMap = getUserInfoMap(userResponse);
|
|
|
//将手机号对应的用户信息放入redis中,设置过期时间为30分钟
|
|
|
redisTemplate.opsForValue().set(userResponse.getMobile() + ApiConstants.UserConstants.USER_INFO_FIELD,
|
|
|
- JSONUtil.toJsonPrettyStr(userResponse), 30L, TimeUnit.MINUTES);
|
|
|
+ JSONUtil.toJsonPrettyStr(currentUserInfoMap), 30L, TimeUnit.MINUTES);
|
|
|
return userResponse;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RestResponse verifySmsCode(String mobile, String inputSmsCode) {
|
|
|
- Object smsCode = redisTemplate.opsForValue().get(mobile + AliConstants.SmsConstants.SMS_CODE_NAME);
|
|
|
+ Object smsCode = redisTemplate.opsForValue().get(mobile + AliConstants.SmsConstants.SMS_CODE_FIELD);
|
|
|
if (smsCode != null) {
|
|
|
if (!(smsCode.equals(inputSmsCode))) {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "短信验证码输入有误");
|
|
@@ -218,4 +218,33 @@ public class LoginService implements ILoginService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param userResponse 用户信息
|
|
|
+ * @return map 用户信息map
|
|
|
+ * @description 封装放入redis的用户信息
|
|
|
+ * @date 2020-01-16 11:40
|
|
|
+ */
|
|
|
+ private Map<String, Object> getUserInfoMap(UserResponse userResponse) {
|
|
|
+ //封装用户登录信息,并将登录信息放入redis中
|
|
|
+ Map<String, Object> currentUserInfoMap = new HashMap<>();
|
|
|
+ //当前用户id
|
|
|
+ currentUserInfoMap.put(ApiConstants.CURRENT_USER_ID, userResponse.getUserId());
|
|
|
+ //当前用户信息
|
|
|
+ currentUserInfoMap.put(ApiConstants.CURRENT_USER_TYPE, userResponse.getType());
|
|
|
+ //当前公司id
|
|
|
+ MaintenanceCompany maintenanceCompany = userResponse.getMaintenanceCompany();
|
|
|
+ if (maintenanceCompany != null) {
|
|
|
+ currentUserInfoMap.put(ApiConstants.CURRENT_COMPANY_ID, maintenanceCompany.getId());
|
|
|
+ }
|
|
|
+ //当前角色id
|
|
|
+ Role role = userResponse.getRole();
|
|
|
+ if (role != null) {
|
|
|
+ currentUserInfoMap.put(ApiConstants.CURRENT_ROLE_ID, role.getId());
|
|
|
+ }
|
|
|
+ //用户权限信息
|
|
|
+ String permissionUrl = menuService.menuToUrl(userResponse.getMenus());
|
|
|
+ currentUserInfoMap.put(ApiConstants.CURRENT_PERMISSION_URL, permissionUrl);
|
|
|
+ return currentUserInfoMap;
|
|
|
+ }
|
|
|
}
|