|
@@ -5,7 +5,7 @@ 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.web.WebFeignService;
|
|
|
+import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -21,8 +21,6 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
|
|
|
|
@Autowired
|
|
|
private SysUserDeviceDao sysUserDeviceDao;
|
|
|
- @Autowired
|
|
|
- private WebFeignService webFeignService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, SysUserDevice> getDAO() {
|
|
@@ -41,52 +39,32 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
|
|
|
|
@Override
|
|
|
public boolean bindDevice(String clientId, Integer userId, String deviceNum) {
|
|
|
+ Integer tenantId = TenantContextHolder.getTenantId();
|
|
|
+ String paramName = null;
|
|
|
if (StringUtils.equals(clientId, "STUDENT")) {
|
|
|
- // 检查学生是否绑定了多个设备号
|
|
|
- List<SysUserDevice> studentDeviceList = queryByUserId(clientId, userId);
|
|
|
-
|
|
|
- if (studentDeviceList == null) {
|
|
|
- studentDeviceList = new ArrayList<SysUserDevice>();
|
|
|
- }
|
|
|
-
|
|
|
- List<String> deviceList = studentDeviceList.stream().map(t -> t.getDeviceNum()).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!deviceList.contains(deviceNum)) {
|
|
|
- if (deviceList.size() >= 5) {
|
|
|
- throw new BadCredentialsException("当前账号绑定设备过多,请联系主教老师");
|
|
|
- }
|
|
|
- SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
- sysUserDevice.setUserId(userId);
|
|
|
- sysUserDevice.setDeviceNum(deviceNum);
|
|
|
- sysUserDevice.setBindTime(new Date());
|
|
|
- sysUserDevice.setClientId(clientId);
|
|
|
- sysUserDeviceDao.insert(sysUserDevice);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(StringUtils.equals(clientId, "TEACHER")){
|
|
|
-
|
|
|
- }
|
|
|
- if(StringUtils.equals(clientId, "SYSTEM")){
|
|
|
-
|
|
|
- }
|
|
|
- // 查询设备号是否已存在
|
|
|
- List<SysUserDevice> sysUserDeviceList = sysUserDeviceDao.queryByDeviceNum(null, deviceNum);
|
|
|
-
|
|
|
- if (sysUserDeviceList == null) {
|
|
|
- sysUserDeviceList = new ArrayList<SysUserDevice>();
|
|
|
- }
|
|
|
-
|
|
|
- sysUserDeviceList = sysUserDeviceList.stream().filter(sud -> !StringUtils.equals(sud.getClientId(), "STUDENT")).collect(Collectors.toList());
|
|
|
+ paramName = "student_device_login_num";
|
|
|
+ }else if(StringUtils.equals(clientId, "TEACHER")){
|
|
|
+ paramName = "teacher_device_login_num";
|
|
|
+ }else {
|
|
|
+ paramName = "edu_device_login_num";
|
|
|
+ }
|
|
|
+ String configValue = sysUserDeviceDao.getDeviceConfig(paramName,tenantId);
|
|
|
+ if(StringUtils.isEmpty(configValue)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 检查学生是否绑定了多个设备号
|
|
|
+ List<SysUserDevice> studentDeviceList = queryByUserId(clientId, userId);
|
|
|
|
|
|
- if (sysUserDeviceList != null && sysUserDeviceList.size() > 0) {
|
|
|
- if (sysUserDeviceList.stream().filter(sud -> sud.getUserId().equals(userId)).count() > 0) {
|
|
|
+ if (studentDeviceList == null) {
|
|
|
+ studentDeviceList = new ArrayList<SysUserDevice>();
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
+ List<String> deviceList = studentDeviceList.stream().map(t -> t.getDeviceNum()).collect(Collectors.toList());
|
|
|
|
|
|
- throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+ if (!deviceList.contains(deviceNum)) {
|
|
|
+ if (deviceList.size() >= Integer.parseInt(configValue)) {
|
|
|
+ throw new BadCredentialsException("当前账号绑定设备过多,请联系主教老师");
|
|
|
}
|
|
|
-
|
|
|
SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
sysUserDevice.setUserId(userId);
|
|
|
sysUserDevice.setDeviceNum(deviceNum);
|