|
@@ -1,20 +1,20 @@
|
|
package com.ym.mec.auth.service.impl;
|
|
package com.ym.mec.auth.service.impl;
|
|
|
|
|
|
-import com.ym.mec.auth.api.entity.SysUserDevice;
|
|
|
|
-import com.ym.mec.auth.dal.dao.SysUserDeviceDao;
|
|
|
|
-import com.ym.mec.auth.service.SysUserDeviceService;
|
|
|
|
-import com.ym.mec.common.dal.BaseDAO;
|
|
|
|
-import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
|
-import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.ym.mec.auth.api.entity.SysUserDevice;
|
|
|
|
+import com.ym.mec.auth.dal.dao.SysUserDeviceDao;
|
|
|
|
+import com.ym.mec.auth.service.SysUserDeviceService;
|
|
|
|
+import com.ym.mec.common.dal.BaseDAO;
|
|
|
|
+import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDevice> implements SysUserDeviceService {
|
|
public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDevice> implements SysUserDeviceService {
|
|
@@ -38,8 +38,7 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean bindDevice(String clientId, Integer userId, String deviceNum) {
|
|
|
|
- Integer tenantId = TenantContextHolder.getTenantId();
|
|
|
|
|
|
+ public boolean bindDevice(String clientId, Integer userId, String deviceNum, Integer tenantId) {
|
|
String paramName = null;
|
|
String paramName = null;
|
|
if (StringUtils.equals(clientId, "STUDENT")) {
|
|
if (StringUtils.equals(clientId, "STUDENT")) {
|
|
paramName = "student_device_login_num";
|
|
paramName = "student_device_login_num";
|
|
@@ -52,19 +51,52 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
if(StringUtils.isEmpty(configValue)){
|
|
if(StringUtils.isEmpty(configValue)){
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- // 检查学生是否绑定了多个设备号
|
|
|
|
- List<SysUserDevice> studentDeviceList = queryByUserId(clientId, userId);
|
|
|
|
|
|
+
|
|
|
|
+ if (StringUtils.equals(clientId, "STUDENT")) {
|
|
|
|
+ // 检查学生是否绑定了多个设备号
|
|
|
|
+ List<SysUserDevice> studentDeviceList = queryByUserId(clientId, userId);
|
|
|
|
|
|
- if (studentDeviceList == null) {
|
|
|
|
- studentDeviceList = new ArrayList<SysUserDevice>();
|
|
|
|
- }
|
|
|
|
|
|
+ if (studentDeviceList == null) {
|
|
|
|
+ studentDeviceList = new ArrayList<SysUserDevice>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> deviceList = studentDeviceList.stream().map(t -> t.getDeviceNum()).collect(Collectors.toList());
|
|
|
|
|
|
- List<String> deviceList = studentDeviceList.stream().map(t -> t.getDeviceNum()).collect(Collectors.toList());
|
|
|
|
|
|
+ if (!deviceList.contains(deviceNum)) {
|
|
|
|
+ if (deviceList.size() >= Integer.parseInt(configValue)) {
|
|
|
|
+ throw new BadCredentialsException("当前账号绑定设备过多,请联系主教老师");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
|
+ sysUserDevice.setUserId(userId);
|
|
|
|
+ sysUserDevice.setDeviceNum(deviceNum);
|
|
|
|
+ sysUserDevice.setBindTime(new Date());
|
|
|
|
+ sysUserDevice.setClientId(clientId);
|
|
|
|
+ sysUserDevice.setTenantId(tenantId);
|
|
|
|
+ sysUserDeviceDao.insert(sysUserDevice);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 查询设备号是否已存在
|
|
|
|
+ List<SysUserDevice> sysUserDeviceList = sysUserDeviceDao.queryByDeviceNum(null, deviceNum);
|
|
|
|
|
|
- if (!deviceList.contains(deviceNum)) {
|
|
|
|
- if (deviceList.size() >= Integer.parseInt(configValue)) {
|
|
|
|
- throw new BadCredentialsException("当前账号绑定设备过多,请联系主教老师");
|
|
|
|
|
|
+ if (sysUserDeviceList == null) {
|
|
|
|
+ sysUserDeviceList = new ArrayList<SysUserDevice>();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ sysUserDeviceList = sysUserDeviceList.stream().filter(sud -> !StringUtils.equals(sud.getClientId(), "STUDENT")).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (sysUserDeviceList != null && sysUserDeviceList.size() > 0) {
|
|
|
|
+ boolean isBinded = sysUserDeviceList.stream().filter(sud -> sud.getUserId().equals(userId)).count() > 0;
|
|
|
|
+ if (isBinded) {
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sysUserDeviceList.size() >= Integer.parseInt(configValue)) {
|
|
|
|
+ throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
SysUserDevice sysUserDevice = new SysUserDevice();
|
|
SysUserDevice sysUserDevice = new SysUserDevice();
|
|
sysUserDevice.setUserId(userId);
|
|
sysUserDevice.setUserId(userId);
|
|
sysUserDevice.setDeviceNum(deviceNum);
|
|
sysUserDevice.setDeviceNum(deviceNum);
|
|
@@ -72,7 +104,7 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
sysUserDevice.setClientId(clientId);
|
|
sysUserDevice.setClientId(clientId);
|
|
sysUserDeviceDao.insert(sysUserDevice);
|
|
sysUserDeviceDao.insert(sysUserDevice);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|