|  | @@ -5,6 +5,7 @@ import java.util.Date;
 | 
											
												
													
														|  |  import java.util.List;
 |  |  import java.util.List;
 | 
											
												
													
														|  |  import java.util.stream.Collectors;
 |  |  import java.util.stream.Collectors;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.auth.dal.dao.SysConfigDao;
 | 
											
												
													
														|  |  import com.yonge.toolset.mybatis.service.impl.BaseServiceImpl;
 |  |  import com.yonge.toolset.mybatis.service.impl.BaseServiceImpl;
 | 
											
												
													
														|  |  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;
 | 
											
										
											
												
													
														|  | @@ -21,6 +22,8 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Long, SysUserDevic
 | 
											
												
													
														|  |  	
 |  |  	
 | 
											
												
													
														|  |  	@Autowired
 |  |  	@Autowired
 | 
											
												
													
														|  |  	private SysUserDeviceDao sysUserDeviceDao;
 |  |  	private SysUserDeviceDao sysUserDeviceDao;
 | 
											
												
													
														|  | 
 |  | +	@Autowired
 | 
											
												
													
														|  | 
 |  | +	private SysConfigDao sysConfigDao;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	@Override
 |  |  	@Override
 | 
											
												
													
														|  |  	public BaseDAO<Long, SysUserDevice> getDAO() {
 |  |  	public BaseDAO<Long, SysUserDevice> getDAO() {
 | 
											
										
											
												
													
														|  | @@ -39,48 +42,23 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Long, SysUserDevic
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	@Override
 |  |  	@Override
 | 
											
												
													
														|  |  	public boolean bindDevice(String clientId, Long userId, String deviceNum) {
 |  |  	public boolean bindDevice(String clientId, Long userId, String deviceNum) {
 | 
											
												
													
														|  | 
 |  | +		String configValue = sysConfigDao.findConfigValue("user_device_login_num");
 | 
											
												
													
														|  | 
 |  | +		if(StringUtils.isEmpty(configValue)){
 | 
											
												
													
														|  | 
 |  | +			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>();
 |  | 
 | 
											
												
													
														|  | -			}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -			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 {
 |  | 
 | 
											
												
													
														|  | -			// 查询设备号是否已存在
 |  | 
 | 
											
												
													
														|  | -			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());
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -			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 sysUserDevice = new SysUserDevice();
 | 
											
												
													
														|  |  			sysUserDevice.setUserId(userId);
 |  |  			sysUserDevice.setUserId(userId);
 | 
											
												
													
														|  |  			sysUserDevice.setDeviceNum(deviceNum);
 |  |  			sysUserDevice.setDeviceNum(deviceNum);
 | 
											
										
											
												
													
														|  | @@ -88,7 +66,6 @@ public class SysUserDeviceServiceImpl extends BaseServiceImpl<Long, SysUserDevic
 | 
											
												
													
														|  |  			sysUserDevice.setClientId(clientId);
 |  |  			sysUserDevice.setClientId(clientId);
 | 
											
												
													
														|  |  			sysUserDeviceDao.insert(sysUserDevice);
 |  |  			sysUserDeviceDao.insert(sysUserDevice);
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  		return true;
 |  |  		return true;
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 |