|
@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -55,7 +56,7 @@ public class TokenController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RemoteStockService stockService;
|
|
private RemoteStockService stockService;
|
|
|
@Resource
|
|
@Resource
|
|
|
- private RedisTemplate<String,String> redisTemplate;
|
|
|
|
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
|
|
@PostMapping("login")
|
|
@PostMapping("login")
|
|
|
public R<?> login(@RequestBody LoginBody form) {
|
|
public R<?> login(@RequestBody LoginBody form) {
|
|
@@ -63,19 +64,19 @@ public class TokenController {
|
|
|
String authType = form.getAuthType() == null ? BaseConstants.GRANT_TYPE_PASSWORD : form.getAuthType();
|
|
String authType = form.getAuthType() == null ? BaseConstants.GRANT_TYPE_PASSWORD : form.getAuthType();
|
|
|
LoginUser userInfo;
|
|
LoginUser userInfo;
|
|
|
if (Objects.equals(authType, BaseConstants.GRANT_TYPE_MOBILE)) {
|
|
if (Objects.equals(authType, BaseConstants.GRANT_TYPE_MOBILE)) {
|
|
|
- String key = BaseConstants.DEFAULT_CODE_KEY + BaseConstants.GRANT_TYPE_MOBILE + "@" + form.getUsername();
|
|
|
|
|
|
|
+ String key = BaseConstants.DEFAULT_CODE_KEY + BaseConstants.GRANT_TYPE_MOBILE + "@" + form.getUsername();
|
|
|
String code = redisTemplate.opsForValue().get(key);
|
|
String code = redisTemplate.opsForValue().get(key);
|
|
|
- if (form.getPassword().equals(code)){
|
|
|
|
|
|
|
+ if (form.getPassword().equals(code)) {
|
|
|
R<LoginUser> userR = remoteUserService.getUserInfo(form.getUsername(), SecurityConstants.INNER);
|
|
R<LoginUser> userR = remoteUserService.getUserInfo(form.getUsername(), SecurityConstants.INNER);
|
|
|
- if (userR.getCode()== HttpStatus.SUCCESS &&userR.getData()!=null){
|
|
|
|
|
- userInfo=userR.getData();
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ if (userR.getCode() == HttpStatus.SUCCESS && userR.getData() != null) {
|
|
|
|
|
+ userInfo = userR.getData();
|
|
|
|
|
+ } else {
|
|
|
throw new ServiceException("系统异常");
|
|
throw new ServiceException("系统异常");
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
- throw new ServiceException("验证码不正确",503);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new ServiceException("验证码不正确", 503);
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
|
}
|
|
}
|
|
|
userInfo.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
userInfo.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
@@ -93,10 +94,8 @@ public class TokenController {
|
|
|
// 区分大屏用户
|
|
// 区分大屏用户
|
|
|
// 查询大屏链接
|
|
// 查询大屏链接
|
|
|
AjaxResult result = remoteUserService.getRouters(userInfo.getUserid());
|
|
AjaxResult result = remoteUserService.getRouters(userInfo.getUserid());
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
List<Map<String, Object>> routers = (List<Map<String, Object>>) result.get("data");
|
|
List<Map<String, Object>> routers = (List<Map<String, Object>>) result.get("data");
|
|
|
-
|
|
|
|
|
Map<String, Object> dataMenu = routers.stream().filter(
|
|
Map<String, Object> dataMenu = routers.stream().filter(
|
|
|
a -> "https://www.sxitdlc.com".equals(a.get("path") + "")).findFirst().orElse(null);
|
|
a -> "https://www.sxitdlc.com".equals(a.get("path") + "")).findFirst().orElse(null);
|
|
|
if (dataMenu != null) {
|
|
if (dataMenu != null) {
|
|
@@ -147,7 +146,6 @@ public class TokenController {
|
|
|
LoginUser loginUser = new LoginUser();
|
|
LoginUser loginUser = new LoginUser();
|
|
|
BeanUtils.copyProperties(userInfo, loginUser);
|
|
BeanUtils.copyProperties(userInfo, loginUser);
|
|
|
loginUser.setToken(token);
|
|
loginUser.setToken(token);
|
|
|
-
|
|
|
|
|
redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, loginUser);
|
|
redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, loginUser);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -171,25 +169,25 @@ public class TokenController {
|
|
|
public R<?> send(@RequestBody LoginBody form) {
|
|
public R<?> send(@RequestBody LoginBody form) {
|
|
|
String username = form.getUsername();
|
|
String username = form.getUsername();
|
|
|
R<LoginUser> userR = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
R<LoginUser> userR = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
- if (userR.getCode()!=HttpStatus.SUCCESS || userR.getData()==null){
|
|
|
|
|
- throw new ServiceException("登录用户:" + username + " 不存在",530);
|
|
|
|
|
|
|
+ if (userR.getCode() != HttpStatus.SUCCESS || userR.getData() == null) {
|
|
|
|
|
+ throw new ServiceException("登录用户:" + username + " 不存在", 530);
|
|
|
}
|
|
}
|
|
|
- String key = BaseConstants.DEFAULT_CODE_KEY + BaseConstants.GRANT_TYPE_MOBILE + "@" + username;
|
|
|
|
|
|
|
+ String key = BaseConstants.DEFAULT_CODE_KEY + BaseConstants.GRANT_TYPE_MOBILE + "@" + username;
|
|
|
String code = RandomUtil.randomNumbers(6);
|
|
String code = RandomUtil.randomNumbers(6);
|
|
|
- redisTemplate.opsForValue().set(key,code,CODE_EXPIRATION,TimeUnit.MINUTES);
|
|
|
|
|
- logger.info("========================>{}<=========================",code);
|
|
|
|
|
- String countKey = BaseConstants.DEFAULT_CODE_KEY + "@" + username+"_COUNT";
|
|
|
|
|
|
|
+ redisTemplate.opsForValue().set(key, code, CODE_EXPIRATION, TimeUnit.MINUTES);
|
|
|
|
|
+ logger.info("========================>{}<=========================", code);
|
|
|
|
|
+ String countKey = BaseConstants.DEFAULT_CODE_KEY + "@" + username + "_COUNT";
|
|
|
String count = redisTemplate.opsForValue().get(countKey);
|
|
String count = redisTemplate.opsForValue().get(countKey);
|
|
|
- if (StringUtils.isEmpty(count)){
|
|
|
|
|
- redisTemplate.opsForValue().set(countKey,"1",60,TimeUnit.MINUTES);
|
|
|
|
|
- }else {
|
|
|
|
|
- if (count!=null){
|
|
|
|
|
- int i=Integer.parseInt(count);
|
|
|
|
|
- if (i>=5){
|
|
|
|
|
- throw new ServiceException("验证码发送超过限制,请一小时后再试",530);
|
|
|
|
|
|
|
+ if (StringUtils.isEmpty(count)) {
|
|
|
|
|
+ redisTemplate.opsForValue().set(countKey, "1", 60, TimeUnit.MINUTES);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (count != null) {
|
|
|
|
|
+ int i = Integer.parseInt(count);
|
|
|
|
|
+ if (i >= 5) {
|
|
|
|
|
+ throw new ServiceException("验证码发送超过限制,请一小时后再试", 530);
|
|
|
}
|
|
}
|
|
|
i++;
|
|
i++;
|
|
|
- redisTemplate.opsForValue().set(countKey,i+"",60,TimeUnit.MINUTES);
|
|
|
|
|
|
|
+ redisTemplate.opsForValue().set(countKey, i + "", 60, TimeUnit.MINUTES);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return stockService.sendSydSms(code, 2, null, form.getUsername());
|
|
return stockService.sendSydSms(code, 2, null, form.getUsername());
|
|
@@ -203,13 +201,10 @@ public class TokenController {
|
|
|
@PostMapping("/learn/login")
|
|
@PostMapping("/learn/login")
|
|
|
public R<?> learnLogin(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
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 machineCode = params.get("machineCode") == null ? "" : (String) params.get("machineCode");
|
|
|
// 用户登录
|
|
// 用户登录
|
|
|
String username = (String) params.get("userName");
|
|
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);
|
|
logger.error("学习机登录,加密前:" + username + ",设备编码:" + machineCode);
|
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
// TODO 终端传参数据有问题,暂临时后端处理
|
|
// TODO 终端传参数据有问题,暂临时后端处理
|
|
@@ -229,32 +224,24 @@ public class TokenController {
|
|
|
return R.fail("无效卡号或未绑定用户,请联系管理员!");
|
|
return R.fail("无效卡号或未绑定用户,请联系管理员!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
R<SysUser> user = remoteUserService.getUserInfoByCardNum(username, SecurityConstants.INNER);
|
|
R<SysUser> user = remoteUserService.getUserInfoByCardNum(username, SecurityConstants.INNER);
|
|
|
-
|
|
|
|
|
if (R.FAIL == user.getCode()) {
|
|
if (R.FAIL == user.getCode()) {
|
|
|
throw new ServiceException(user.getMsg());
|
|
throw new ServiceException(user.getMsg());
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isNull(user.getData())) {
|
|
if (StringUtils.isNull(user.getData())) {
|
|
|
return R.fail("登录用户不存在!");
|
|
return R.fail("登录用户不存在!");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
R<LoginUser> userResult = remoteUserService.getUserInfo(user.getData().getUserName(), aioType, SecurityConstants.INNER);
|
|
R<LoginUser> userResult = remoteUserService.getUserInfo(user.getData().getUserName(), aioType, SecurityConstants.INNER);
|
|
|
-
|
|
|
|
|
if (R.FAIL == userResult.getCode() || 503 == userResult.getCode()) {
|
|
if (R.FAIL == userResult.getCode() || 503 == userResult.getCode()) {
|
|
|
return R.fail(userResult.getMsg());
|
|
return R.fail(userResult.getMsg());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if (userResult.getData() != null) {
|
|
if (userResult.getData() != null) {
|
|
|
-
|
|
|
|
|
LoginUser userInfo = userResult.getData();
|
|
LoginUser userInfo = userResult.getData();
|
|
|
userInfo.setLoginType(aioType);
|
|
userInfo.setLoginType(aioType);
|
|
|
userInfo.setMachineCode(machineCode);
|
|
userInfo.setMachineCode(machineCode);
|
|
|
if (userInfo.getSysUser() == null) {
|
|
if (userInfo.getSysUser() == null) {
|
|
|
return R.fail("登录用户不存在!");
|
|
return R.fail("登录用户不存在!");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
Map<String, Object> map = null;
|
|
Map<String, Object> map = null;
|
|
|
if (type == 1) {
|
|
if (type == 1) {
|
|
|
// 获取登录token
|
|
// 获取登录token
|
|
@@ -266,9 +253,7 @@ public class TokenController {
|
|
|
// 删除用户缓存记录
|
|
// 删除用户缓存记录
|
|
|
tokenService.delLoginUser(loginUser.getToken());
|
|
tokenService.delLoginUser(loginUser.getToken());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
map = tokenService.createToken(userInfo);
|
|
map = tokenService.createToken(userInfo);
|
|
|
-
|
|
|
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
map.put("positionName", userInfo.getSysUser().getPositionName());
|
|
map.put("positionName", userInfo.getSysUser().getPositionName());
|
|
|
map.put("cabinetLock", userInfo.isCabinetLock());
|
|
map.put("cabinetLock", userInfo.isCabinetLock());
|
|
@@ -284,12 +269,10 @@ public class TokenController {
|
|
|
redisService.setCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId(), userInfo, BaseConstants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
redisService.setCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId(), userInfo, BaseConstants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return R.ok(map);
|
|
return R.ok(map);
|
|
|
} else {
|
|
} else {
|
|
|
return R.fail("登录用户不存在!");
|
|
return R.fail("登录用户不存在!");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -297,7 +280,6 @@ public class TokenController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/learn/loginOut")
|
|
@PostMapping("/learn/loginOut")
|
|
|
public R<?> learnLoginOut(HttpServletRequest request) {
|
|
public R<?> learnLoginOut(HttpServletRequest request) {
|
|
|
-
|
|
|
|
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
SysUser user = loginUser.getSysUser();
|
|
SysUser user = loginUser.getSysUser();
|