|
|
@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
@@ -55,75 +56,82 @@ public class TokenController {
|
|
|
@PostMapping("login")
|
|
|
public R<?> login(@RequestBody LoginBody form) {
|
|
|
// 用户登录
|
|
|
- LoginUser userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
|
+ String authType = form.getAuthType() == null ? Constants.GRANT_TYPE_PASSWORD : form.getAuthType();
|
|
|
+ LoginUser userInfo;
|
|
|
+ if (Objects.equals(authType, Constants.GRANT_TYPE_MOBILE)) {
|
|
|
+ //TODO 验证码校验过程,用户信息查询
|
|
|
+ userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
|
+ }else {
|
|
|
+ userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
|
+ }
|
|
|
userInfo.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
|
Map<String, Object> data = tokenService.createToken(userInfo);
|
|
|
//这里判断输入的密码,是否和默认配置密码一样,如果一样,需要提示跳转设置密码
|
|
|
AjaxResult resultPassword = remoteUserService.getConfigKey("sys.user.initPassword");
|
|
|
- if((resultPassword.get("code")+"").equals("200")){
|
|
|
+ if ((resultPassword.get("code") + "").equals("200")) {
|
|
|
String defaultPassword = (String) resultPassword.get("msg");
|
|
|
- if(defaultPassword!=null && defaultPassword.equals(form.getPassword())){
|
|
|
+ if (defaultPassword != null && defaultPassword.equals(form.getPassword())) {
|
|
|
data.put("reset_password", true);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
data.put("reset_password", false);
|
|
|
}
|
|
|
}
|
|
|
// 区分大屏用户
|
|
|
- // 查询大屏链接
|
|
|
- AjaxResult result = remoteUserService.getRouters(userInfo.getUserid());
|
|
|
-
|
|
|
- try {
|
|
|
- List<Map<String, Object>> routers = (List<Map<String, Object>>)result.get("data");
|
|
|
-
|
|
|
- Map<String,Object> dataMenu = routers.stream().filter(
|
|
|
- a -> "https://www.sxitdlc.com".equals(a.get("path")+"")).findFirst().orElse(null);
|
|
|
- if(dataMenu != null){
|
|
|
- String tokenKey = "login_screen:";
|
|
|
-
|
|
|
- Integer type;
|
|
|
- if(userInfo.getSysUser().isAdmin()){
|
|
|
- type = 1;
|
|
|
- }else {
|
|
|
- result = remoteUserService.selectAuthUserPower(userInfo.getUserid());
|
|
|
- Map<String, Object> map = (Map<String, Object>) result.get("data");
|
|
|
- type = Integer.parseInt(map.get("type") + "");
|
|
|
- }
|
|
|
-
|
|
|
- if(type == null){
|
|
|
- // 没有大屏权限
|
|
|
- type = 3;
|
|
|
- data.put("screen_token", "");
|
|
|
- }else if(redisService.hasKey(tokenKey + userInfo.getUserid())){
|
|
|
- String token=redisService.getCacheObject(tokenKey + userInfo.getUserid());
|
|
|
- commLogin(userInfo,token);
|
|
|
- data.put("screen_token", token);
|
|
|
- }else {
|
|
|
- String token = IdUtils.fastUUID();
|
|
|
- commLogin(userInfo,token);
|
|
|
- redisService.setCacheObject(tokenKey + userInfo.getUserid(), token);
|
|
|
- // 获取大屏TOKEN
|
|
|
- data.put("screen_token", token);
|
|
|
- }
|
|
|
+ // 查询大屏链接
|
|
|
+ AjaxResult result = remoteUserService.getRouters(userInfo.getUserid());
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<Map<String, Object>> routers = (List<Map<String, Object>>) result.get("data");
|
|
|
+
|
|
|
+ Map<String, Object> dataMenu = routers.stream().filter(
|
|
|
+ a -> "https://www.sxitdlc.com".equals(a.get("path") + "")).findFirst().orElse(null);
|
|
|
+ if (dataMenu != null) {
|
|
|
+ String tokenKey = "login_screen:";
|
|
|
+
|
|
|
+ Integer type;
|
|
|
+ if (userInfo.getSysUser().isAdmin()) {
|
|
|
+ type = 1;
|
|
|
+ } else {
|
|
|
+ result = remoteUserService.selectAuthUserPower(userInfo.getUserid());
|
|
|
+ Map<String, Object> map = (Map<String, Object>) result.get("data");
|
|
|
+ type = Integer.parseInt(map.get("type") + "");
|
|
|
+ }
|
|
|
|
|
|
- data.put("screen_type", type);
|
|
|
- }else {
|
|
|
+ if (type == null) {
|
|
|
// 没有大屏权限
|
|
|
- data.put("screen_type", 3);
|
|
|
+ type = 3;
|
|
|
data.put("screen_token", "");
|
|
|
+ } else if (redisService.hasKey(tokenKey + userInfo.getUserid())) {
|
|
|
+ String token = redisService.getCacheObject(tokenKey + userInfo.getUserid());
|
|
|
+ commLogin(userInfo, token);
|
|
|
+ data.put("screen_token", token);
|
|
|
+ } else {
|
|
|
+ String token = IdUtils.fastUUID();
|
|
|
+ commLogin(userInfo, token);
|
|
|
+ redisService.setCacheObject(tokenKey + userInfo.getUserid(), token);
|
|
|
+ // 获取大屏TOKEN
|
|
|
+ data.put("screen_token", token);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+
|
|
|
+ data.put("screen_type", type);
|
|
|
+ } else {
|
|
|
// 没有大屏权限
|
|
|
data.put("screen_type", 3);
|
|
|
data.put("screen_token", "");
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 没有大屏权限
|
|
|
+ data.put("screen_type", 3);
|
|
|
+ data.put("screen_token", "");
|
|
|
+ }
|
|
|
// 获取登录token
|
|
|
return R.ok(data);
|
|
|
}
|
|
|
|
|
|
//公共登录方法
|
|
|
- private void commLogin(LoginUser userInfo,String token){
|
|
|
+ private void commLogin(LoginUser userInfo, String token) {
|
|
|
LoginUser loginUser = new LoginUser();
|
|
|
- BeanUtils.copyProperties(userInfo,loginUser);
|
|
|
+ BeanUtils.copyProperties(userInfo, loginUser);
|
|
|
loginUser.setToken(token);
|
|
|
|
|
|
redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, loginUser);
|
|
|
@@ -149,16 +157,16 @@ public class TokenController {
|
|
|
*/
|
|
|
@PostMapping("/learn/login")
|
|
|
public R<?> learnLogin(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
- int type = org.apache.commons.lang3.StringUtils.isNotBlank((String)params.get("type")) ? Integer.parseInt((String)params.get("type")) : 1;
|
|
|
+ int type = org.apache.commons.lang3.StringUtils.isNotBlank((String) params.get("type")) ? Integer.parseInt((String) params.get("type")) : 1;
|
|
|
|
|
|
String machineCode = params.get("machineCode") == null ? "" : (String) params.get("machineCode");
|
|
|
// 用户登录
|
|
|
String username = (String) params.get("userName");
|
|
|
|
|
|
- int aioType = params.get("aioType") == null ?UserConstants.USER_LOGIN_AIO : Integer.parseInt(params.get("aioType")+"");
|
|
|
+ int aioType = params.get("aioType") == null ? UserConstants.USER_LOGIN_AIO : Integer.parseInt(params.get("aioType") + "");
|
|
|
|
|
|
logger.error("学习机登录,加密前:" + username + ",设备编码:" + machineCode);
|
|
|
- if(UserConstants.USER_LOGIN_HXP == aioType){
|
|
|
+ if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
// TODO 终端传参数据有问题,暂临时后端处理
|
|
|
// username = username.replaceAll("%00", "")
|
|
|
// .replaceAll("%02", "")
|
|
|
@@ -166,12 +174,12 @@ public class TokenController {
|
|
|
// .replaceAll("%0A", "")
|
|
|
// .replaceAll("%0D", "")
|
|
|
// .trim();
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
// 查询用户信息
|
|
|
- if(StringUtils.isNumeric(username)) {
|
|
|
+ if (StringUtils.isNumeric(username)) {
|
|
|
username = Long.toHexString(Long.parseLong(username)).toUpperCase();
|
|
|
logger.error("学习机登录,加密后:" + username);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
logger.error("通过卡号未找到用户");
|
|
|
return R.fail("无效卡号或未绑定用户,请联系管理员!");
|
|
|
}
|
|
|
@@ -203,10 +211,10 @@ public class TokenController {
|
|
|
}
|
|
|
|
|
|
Map<String, Object> map = null;
|
|
|
- if(type == 1){
|
|
|
+ if (type == 1) {
|
|
|
// 获取登录token
|
|
|
map = tokenService.createToken(userInfo);
|
|
|
- }else if(type == 2){
|
|
|
+ } else if (type == 2) {
|
|
|
// 资源删除
|
|
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
@@ -216,24 +224,24 @@ public class TokenController {
|
|
|
|
|
|
map = tokenService.createToken(userInfo);
|
|
|
|
|
|
- if(UserConstants.USER_LOGIN_HXP == aioType){
|
|
|
+ if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
map.put("positionName", userInfo.getSysUser().getPositionName());
|
|
|
map.put("cabinetLock", userInfo.isCabinetLock());
|
|
|
map.put("airBottle", userInfo.isAirBottle());
|
|
|
- }else if(UserConstants.USER_LOGIN_AIO == aioType){
|
|
|
- if(redisService.hasKey(CacheConstants.LEARN_USER_KEY+userInfo.getSysUser().getUserId())){
|
|
|
- LoginUser userCache = redisService.getCacheObject(CacheConstants.LEARN_USER_KEY+userInfo.getSysUser().getUserId());
|
|
|
- if(!machineCode.equals(userCache.getMachineCode())){
|
|
|
+ } else if (UserConstants.USER_LOGIN_AIO == aioType) {
|
|
|
+ if (redisService.hasKey(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId())) {
|
|
|
+ LoginUser userCache = redisService.getCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId());
|
|
|
+ if (!machineCode.equals(userCache.getMachineCode())) {
|
|
|
return R.fail("签到失败,不能重复签到!");
|
|
|
}
|
|
|
}
|
|
|
// 记录学习一体机用户登录状态
|
|
|
- redisService.setCacheObject(CacheConstants.LEARN_USER_KEY+userInfo.getSysUser().getUserId(), userInfo, Constants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
+ redisService.setCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId(), userInfo, Constants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return R.ok(map);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return R.fail("登录用户不存在!");
|
|
|
}
|
|
|
|
|
|
@@ -253,7 +261,7 @@ public class TokenController {
|
|
|
// 记录用户退出日志
|
|
|
sysLoginService.logout(user);
|
|
|
// 删除一体机登录状态
|
|
|
- redisService.deleteObject(CacheConstants.LEARN_USER_KEY+loginUser.getUserid());
|
|
|
+ redisService.deleteObject(CacheConstants.LEARN_USER_KEY + loginUser.getUserid());
|
|
|
}
|
|
|
return R.ok();
|
|
|
}
|