|
@@ -1,9 +1,13 @@
|
|
|
package com.ym.mec.auth.service.impl;
|
|
|
|
|
|
+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.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.authentication.BadCredentialsException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.ym.mec.auth.api.entity.SysUserDevice;
|
|
@@ -34,25 +38,53 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Integer, SysUserDe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean bindDevice(String clientId, Integer userId, String deviceNum) throws Exception {
|
|
|
- //查询设备号是否已存在
|
|
|
- List<SysUserDevice> sysUserDeviceList = sysUserDeviceDao.queryByDeviceNum(clientId, deviceNum);
|
|
|
-
|
|
|
+ public boolean bindDevice(String clientId, Integer userId, String deviceNum) {
|
|
|
+ // 查询设备号是否已存在
|
|
|
+ List<SysUserDevice> sysUserDeviceList = sysUserDeviceDao.queryByDeviceNum(null, deviceNum);
|
|
|
+
|
|
|
if (sysUserDeviceList != null && sysUserDeviceList.size() > 0) {
|
|
|
if (sysUserDeviceList.stream().filter(sud -> sud.getUserId().equals(userId)).count() > 0) {
|
|
|
return true;
|
|
|
- } else {
|
|
|
- throw new Exception("当前设备已绑定账号,请更换设备");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.equals(clientId, "STUDENT")) {
|
|
|
+ if (sysUserDeviceList.stream().filter(sud -> !StringUtils.equalsIgnoreCase(sud.getClientId(), "STUDENT")).count() > 0) {
|
|
|
+ throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
+ sysUserDevice.setUserId(userId);
|
|
|
+ sysUserDevice.setDeviceNum(deviceNum);
|
|
|
+ sysUserDevice.setBindTime(new Date());
|
|
|
+ sysUserDevice.setClientId(clientId);
|
|
|
+ sysUserDeviceDao.insert(sysUserDevice);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
- sysUserDevice.setUserId(userId);
|
|
|
- sysUserDevice.setDeviceNum(deviceNum);
|
|
|
- sysUserDevice.setBindTime(new Date());
|
|
|
- sysUserDevice.setClientId(clientId);
|
|
|
- sysUserDeviceDao.insert(sysUserDevice);
|
|
|
-
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|