|
@@ -128,8 +128,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
@Autowired
|
|
|
RedisClient redisClient;
|
|
|
|
|
|
- private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[]{"学习中心ID", "学习中心代码",
|
|
|
- "学习中心名称", "是否可以考试(是/否)", "开始考试时间 yyyy-MM-dd hh:mm:ss", "结束考试时间 yyyy-MM-dd hh:mm:ss"};
|
|
|
+ private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[] { "学习中心ID", "学习中心代码", "学习中心名称",
|
|
|
+ "是否可以考试(是/否)", "开始考试时间 yyyy-MM-dd hh:mm:ss", "结束考试时间 yyyy-MM-dd hh:mm:ss" };
|
|
|
|
|
|
/*
|
|
|
* 实现
|
|
@@ -161,7 +161,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
// 上锁
|
|
|
- Object[] locker = new Object[]{CacheConstants.LOCK_E_EXAM_SAVE, rootOrgId, code};
|
|
|
+ Object[] locker = new Object[] { CacheConstants.LOCK_E_EXAM_SAVE, rootOrgId, code };
|
|
|
SequenceLockHelper.getLock(locker);
|
|
|
|
|
|
GetOrgReq getOrgReq = new GetOrgReq();
|
|
@@ -182,10 +182,14 @@ public class ExamServiceImpl implements ExamService {
|
|
|
throw new StatusException("002001", "code is wrong");
|
|
|
}
|
|
|
realStatus = CURD.UPDATE;
|
|
|
+ if (exam.getArchived()) {
|
|
|
+ throw new StatusException("考试已归档,不能修改");
|
|
|
+ }
|
|
|
}
|
|
|
// 创建
|
|
|
else if (curd.equals(CURD.CREATION)) {
|
|
|
exam = new ExamEntity();
|
|
|
+ exam.setArchived(false);
|
|
|
realStatus = CURD.CREATION;
|
|
|
}
|
|
|
// (根据考试编码)新增或创建
|
|
@@ -195,10 +199,14 @@ public class ExamServiceImpl implements ExamService {
|
|
|
if (null == exam) {
|
|
|
exam = new ExamEntity();
|
|
|
realStatus = CURD.CREATION;
|
|
|
+ exam.setArchived(false);
|
|
|
}
|
|
|
// 更新
|
|
|
else {
|
|
|
realStatus = CURD.UPDATE;
|
|
|
+ if (exam.getArchived()) {
|
|
|
+ throw new StatusException("考试已归档,不能修改");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -277,8 +285,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
DynamicEnum de = entry.getKey();
|
|
|
String value = entry.getValue();
|
|
|
- ExamPropertyEntity entity = examPropertyRepo.findByExamIdAndKeyId(saved.getId(),
|
|
|
- de.getId());
|
|
|
+ ExamPropertyEntity entity = examPropertyRepo.findByExamIdAndKeyId(saved.getId(), de.getId());
|
|
|
if (null == entity) {
|
|
|
entity = new ExamPropertyEntity();
|
|
|
entity.setExamId(saved.getId());
|
|
@@ -300,13 +307,11 @@ public class ExamServiceImpl implements ExamService {
|
|
|
this.saveExamSpecialSettings(examSpecialInfo);
|
|
|
|
|
|
examSpecialSettingsRepo.updateExamEnableByExamId(saved.getId(), saved.getEnable());
|
|
|
- examSpecialSettingsRepo.updateSpecialSettingsEnabledByExamId(saved.getId(),
|
|
|
- saved.getSpecialSettingsEnabled());
|
|
|
+ examSpecialSettingsRepo.updateSpecialSettingsEnabledByExamId(saved.getId(), saved.getSpecialSettingsEnabled());
|
|
|
if (null == saved.getSpecialSettingsType()) {
|
|
|
examSpecialSettingsRepo.updateSpecialSettingsTypeByExamId(saved.getId(), null);
|
|
|
} else {
|
|
|
- examSpecialSettingsRepo.updateSpecialSettingsTypeByExamId(saved.getId(),
|
|
|
- saved.getSpecialSettingsType());
|
|
|
+ examSpecialSettingsRepo.updateSpecialSettingsTypeByExamId(saved.getId(), saved.getSpecialSettingsType());
|
|
|
}
|
|
|
|
|
|
SyncExamReq req = new SyncExamReq();
|
|
@@ -343,8 +348,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
* @return
|
|
|
* @author WANGWEI
|
|
|
*/
|
|
|
- private Map<DynamicEnum, String> checkAndGetExamProperties(Long rootOrgId,
|
|
|
- Map<String, String> properties) {
|
|
|
+ private Map<DynamicEnum, String> checkAndGetExamProperties(Long rootOrgId, Map<String, String> properties) {
|
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
|
|
|
Map<DynamicEnum, String> map = Maps.newHashMap();
|
|
@@ -416,20 +420,17 @@ public class ExamServiceImpl implements ExamService {
|
|
|
Boolean hasFaceCheckFunction = PrivilegeManager.judge(rootOrgId, faceCheck);
|
|
|
String isFaceEnable = properties.get("IS_FACE_ENABLE");
|
|
|
if (!hasFaceCheckFunction) {
|
|
|
- if (StringUtils.isNotBlank(isFaceEnable)
|
|
|
- && isFaceEnable.equalsIgnoreCase(Boolean.toString(true))) {
|
|
|
+ if (StringUtils.isNotBlank(isFaceEnable) && isFaceEnable.equalsIgnoreCase(Boolean.toString(true))) {
|
|
|
throw new StatusException("001002", "人脸识别功能未开放");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 活体检测功能校验
|
|
|
String IdentificationOfLivingBody = PrivilegeDefine.RootOrgFunctions.OnlineExamFunctions.IdentificationOfLivingBody.CODE;
|
|
|
- Boolean hasIdentificationOfLivingBodyFunction = PrivilegeManager.judge(rootOrgId,
|
|
|
- IdentificationOfLivingBody);
|
|
|
+ Boolean hasIdentificationOfLivingBodyFunction = PrivilegeManager.judge(rootOrgId, IdentificationOfLivingBody);
|
|
|
String isFceVerify = properties.get("IS_FACE_VERIFY");
|
|
|
if (!hasIdentificationOfLivingBodyFunction) {
|
|
|
- if (StringUtils.isNotBlank(isFceVerify)
|
|
|
- && isFceVerify.equalsIgnoreCase(Boolean.toString(true))) {
|
|
|
+ if (StringUtils.isNotBlank(isFceVerify) && isFceVerify.equalsIgnoreCase(Boolean.toString(true))) {
|
|
|
throw new StatusException("001002", "活体检测功能未开放");
|
|
|
}
|
|
|
}
|
|
@@ -438,7 +439,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param content 内容
|
|
|
+ * @param content
|
|
|
+ * 内容
|
|
|
* @return 内容中图片文件总大小
|
|
|
*/
|
|
|
private long getImgSizeByBase64String(String content) {
|
|
@@ -474,8 +476,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
* com.qmth.examcloud.core.examwork.service.bean.ExamOrgInfo)
|
|
|
*/
|
|
|
@Override
|
|
|
- public ExamSpecialSettingsEntity saveExamSpecialSettings(
|
|
|
- ExamSpecialSettingsInfo examSpecialInfo) {
|
|
|
+ public ExamSpecialSettingsEntity saveExamSpecialSettings(ExamSpecialSettingsInfo examSpecialInfo) {
|
|
|
|
|
|
ExamSpecialSettingsEntity examSpecialSettingsEntity = null;
|
|
|
|
|
@@ -493,8 +494,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
// 上锁
|
|
|
- Object[] locker = new Object[]{CacheConstants.LOCK_E_EXAM_SPECIAL_SETTINGS, examId, "ORG" + orgId,
|
|
|
- "COURSE" + courseId, "Student" + studentId};
|
|
|
+ Object[] locker = new Object[] { CacheConstants.LOCK_E_EXAM_SPECIAL_SETTINGS, examId, "ORG" + orgId,
|
|
|
+ "COURSE" + courseId, "Student" + studentId };
|
|
|
SequenceLockHelper.getLock(locker);
|
|
|
|
|
|
if (!new Boolean(null == beginTime).equals(new Boolean(null == endTime))) {
|
|
@@ -514,14 +515,13 @@ public class ExamServiceImpl implements ExamService {
|
|
|
// 机构特殊设置
|
|
|
if (null != orgId && null == courseId && null == studentId) {
|
|
|
examSpecialSettingsEntity = examSpecialSettingsRepo
|
|
|
- .findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(
|
|
|
- examSpecialInfo.getExamId(), orgId);
|
|
|
+ .findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(examSpecialInfo.getExamId(), orgId);
|
|
|
}
|
|
|
// 学生特殊设置
|
|
|
else if (null == orgId && null == courseId && null != studentId) {
|
|
|
examSpecialSettingsEntity = examSpecialSettingsRepo
|
|
|
- .findByExamIdAndStudentIdAndOrgIdIsNullAndCourseIdIsNull(
|
|
|
- examSpecialInfo.getExamId(), studentId);
|
|
|
+ .findByExamIdAndStudentIdAndOrgIdIsNullAndCourseIdIsNull(examSpecialInfo.getExamId(),
|
|
|
+ studentId);
|
|
|
}
|
|
|
// 课程特殊设置
|
|
|
else if (null == orgId && null != courseId && null == studentId) {
|
|
@@ -530,8 +530,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
// 考试设置
|
|
|
else if (null == orgId && null == courseId && null == studentId) {
|
|
|
examSpecialSettingsEntity = examSpecialSettingsRepo
|
|
|
- .findAllByExamIdAndOrgIdIsNullAndCourseIdIsNullAndStudentIdIsNull(
|
|
|
- examSpecialInfo.getExamId());
|
|
|
+ .findAllByExamIdAndOrgIdIsNullAndCourseIdIsNullAndStudentIdIsNull(examSpecialInfo.getExamId());
|
|
|
} else {
|
|
|
throw new StatusException("001501", "参数错误");
|
|
|
}
|
|
@@ -544,8 +543,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
examSpecialSettingsEntity.setExamId(examId);
|
|
|
examSpecialSettingsEntity.setExamType(examEntity.getExamType());
|
|
|
examSpecialSettingsEntity.setExamEnable(examEntity.getEnable());
|
|
|
- examSpecialSettingsEntity
|
|
|
- .setSpecialSettingsEnabled(examEntity.getSpecialSettingsEnabled());
|
|
|
+ examSpecialSettingsEntity.setSpecialSettingsEnabled(examEntity.getSpecialSettingsEnabled());
|
|
|
examSpecialSettingsEntity.setSpecialSettingsType(examEntity.getSpecialSettingsType());
|
|
|
|
|
|
examSpecialSettingsEntity.setOrgId(orgId);
|
|
@@ -569,8 +567,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- examSpecialSettingsEntity = GlobalHelper.getEntity(examSpecialSettingsRepo,
|
|
|
- examSpecialInfo.getId(), ExamSpecialSettingsEntity.class);
|
|
|
+ examSpecialSettingsEntity = GlobalHelper.getEntity(examSpecialSettingsRepo, examSpecialInfo.getId(),
|
|
|
+ ExamSpecialSettingsEntity.class);
|
|
|
if (null == examSpecialSettingsEntity) {
|
|
|
throw new StatusException("001101", "id is wrong");
|
|
|
}
|
|
@@ -588,8 +586,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
Map<String, String> props = examSpecialInfo.getProperties();
|
|
|
|
|
|
if (null != props) {
|
|
|
- Map<DynamicEnum, String> map = checkAndGetExamProperties(examEntity.getRootOrgId(),
|
|
|
- props);
|
|
|
+ Map<DynamicEnum, String> map = checkAndGetExamProperties(examEntity.getRootOrgId(), props);
|
|
|
|
|
|
for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
DynamicEnum de = entry.getKey();
|
|
@@ -602,8 +599,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
// 机构特殊设置
|
|
|
if (null != orgId && null == courseId && null == studentId) {
|
|
|
- ExamOrgPropertyEntity entity = examOrgPropertyRepo.findByExamIdAndOrgIdAndKeyId(
|
|
|
- saved.getExamId(), saved.getOrgId(), de.getId());
|
|
|
+ ExamOrgPropertyEntity entity = examOrgPropertyRepo.findByExamIdAndOrgIdAndKeyId(saved.getExamId(),
|
|
|
+ saved.getOrgId(), de.getId());
|
|
|
if (null == entity) {
|
|
|
entity = new ExamOrgPropertyEntity();
|
|
|
entity.setExamId(saved.getExamId());
|
|
@@ -635,15 +632,14 @@ public class ExamServiceImpl implements ExamService {
|
|
|
DynamicEnum de = manager.getByName(key);
|
|
|
|
|
|
if (null != orgId) {
|
|
|
- ExamOrgPropertyEntity examOrgPropertyEntity = examOrgPropertyRepo
|
|
|
- .findByExamIdAndOrgIdAndKeyId(examId, orgId, de.getId());
|
|
|
+ ExamOrgPropertyEntity examOrgPropertyEntity = examOrgPropertyRepo.findByExamIdAndOrgIdAndKeyId(examId,
|
|
|
+ orgId, de.getId());
|
|
|
if (null != examOrgPropertyEntity) {
|
|
|
return examOrgPropertyEntity.getValue();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId,
|
|
|
- de.getId());
|
|
|
+ ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
if (null == examPropertyEntity) {
|
|
|
return null;
|
|
|
}
|
|
@@ -660,8 +656,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
// 待实现
|
|
|
}
|
|
|
|
|
|
- ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId,
|
|
|
- de.getId());
|
|
|
+ ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
if (null == examPropertyEntity) {
|
|
|
return null;
|
|
|
}
|
|
@@ -688,8 +683,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
throw new StatusException("200112", "数据行数不能超过10000");
|
|
|
}
|
|
|
|
|
|
- List<Map<String, Object>> failRecords = Collections
|
|
|
- .synchronizedList(new ArrayList<Map<String, Object>>());
|
|
|
+ List<Map<String, Object>> failRecords = Collections.synchronizedList(new ArrayList<Map<String, Object>>());
|
|
|
List<ExamSpecialSettingsInfo> specialSettingsList = Lists.newArrayList();
|
|
|
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
@@ -721,8 +715,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
OrgBean orgBean = getOrgResp.getOrg();
|
|
|
|
|
|
- if (null == orgBean.getParentId()
|
|
|
- || !orgBean.getRootId().equals(examEntity.getRootOrgId())) {
|
|
|
+ if (null == orgBean.getParentId() || !orgBean.getRootId().equals(examEntity.getRootOrgId())) {
|
|
|
msg.append(" 学习中心ID非法");
|
|
|
hasError = true;
|
|
|
} else {
|
|
@@ -826,8 +819,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
DynamicEnum de = manager.getByName(key);
|
|
|
|
|
|
- ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId,
|
|
|
- de.getId());
|
|
|
+ ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
if (null == examPropertyEntity) {
|
|
|
return null;
|
|
|
}
|
|
@@ -852,7 +844,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageInfo<ExamIpLimitInfo> pageIpLimited(Integer curPage, Integer pageSize, Long examId, IpLimitType limitType, String ip) {
|
|
|
+ public PageInfo<ExamIpLimitInfo> pageIpLimited(Integer curPage, Integer pageSize, Long examId,
|
|
|
+ IpLimitType limitType, String ip) {
|
|
|
Specification<ExamIpLimitEntity> spec = getSpec(examId, limitType, ip);
|
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(curPage, pageSize, Sort.by(Sort.Direction.DESC, "creationTime"));
|
|
@@ -894,124 +887,131 @@ public class ExamServiceImpl implements ExamService {
|
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
DynamicEnum ipLimit = manager.getByName(ExamProperties.IP_LIMIT.name());
|
|
|
|
|
|
- //是否开启Ip限制
|
|
|
+ // 是否开启Ip限制
|
|
|
Boolean ipLimited = getExamLimitProperty(examId, ipLimit.getId(), false);
|
|
|
if (ipLimited) {
|
|
|
- //整体控制
|
|
|
+ // 整体控制
|
|
|
DynamicEnum ipTotalLimit = manager.getByName("IP_TOTAL_LIMIT");
|
|
|
Boolean totalLimit = getExamLimitProperty(examId, ipTotalLimit.getId(), false);
|
|
|
if (totalLimit) {
|
|
|
- //全部白名单模式:不在白名单中,才限制访问
|
|
|
-// int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(), realIp);
|
|
|
-// if (count == 0) {
|
|
|
- if(!checkInIpConfig(realIp, examId, IpLimitType.HAS_ACCESS)) {
|
|
|
+ // 全部白名单模式:不在白名单中,才限制访问
|
|
|
+ // int count =
|
|
|
+ // examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId,
|
|
|
+ // IpLimitType.HAS_ACCESS.name(), realIp);
|
|
|
+ // if (count == 0) {
|
|
|
+ if (!checkInIpConfig(realIp, examId, IpLimitType.HAS_ACCESS)) {
|
|
|
return true;
|
|
|
} else {
|
|
|
- // return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
|
+ // return getCenterLimit(manager, examId,
|
|
|
+ // accessUser.getUserId(), realIp);
|
|
|
}
|
|
|
} else {
|
|
|
- //全部黑名单模式:在黑名单中,才限制访问
|
|
|
-// int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
-// if (count > 0) {
|
|
|
- if(checkInIpConfig(realIp, examId, IpLimitType.NO_ACCESS)) {
|
|
|
+ // 全部黑名单模式:在黑名单中,才限制访问
|
|
|
+ // int count =
|
|
|
+ // examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId,
|
|
|
+ // IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
+ // if (count > 0) {
|
|
|
+ if (checkInIpConfig(realIp, examId, IpLimitType.NO_ACCESS)) {
|
|
|
return true;
|
|
|
} else {
|
|
|
- // return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
|
+ // return getCenterLimit(manager, examId,
|
|
|
+ // accessUser.getUserId(), realIp);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- private boolean checkInIpConfig(String realIp, Long examId,IpLimitType type) {
|
|
|
- List <ExamIpLimitEntity> ips=examIpLimitRepo.findByExamIdAndLimitType(examId, type);
|
|
|
- if(CollectionUtils.isEmpty(ips)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- for(ExamIpLimitEntity ip:ips) {
|
|
|
- if(StringUtils.isNotBlank(ip.getIp())) {
|
|
|
- if(checkIpEq(realIp, ip.getIp())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+
|
|
|
+ private boolean checkInIpConfig(String realIp, Long examId, IpLimitType type) {
|
|
|
+ List<ExamIpLimitEntity> ips = examIpLimitRepo.findByExamIdAndLimitType(examId, type);
|
|
|
+ if (CollectionUtils.isEmpty(ips)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (ExamIpLimitEntity ip : ips) {
|
|
|
+ if (StringUtils.isNotBlank(ip.getIp())) {
|
|
|
+ if (checkIpEq(realIp, ip.getIp())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- private boolean checkIpEq(String realIp,String ipConfig) {
|
|
|
- if(ipConfig.indexOf("-")==-1) {
|
|
|
- return realIp.equals(ipConfig);
|
|
|
- }else {
|
|
|
- String[] ss1=realIp.split("\\.");
|
|
|
- String[] ss2=ipConfig.split("\\.");
|
|
|
- if(ss1.length!=ss2.length) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- for(int i=0;i<=2;i++) {
|
|
|
- if(!ss1[i].equals(ss2[i])) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- String[] ssCon=ss2[3].split("-");
|
|
|
- if(ssCon.length!=2) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- int val=Integer.valueOf(ss1[3]);
|
|
|
- int start=Integer.valueOf(ssCon[0]);
|
|
|
- int end=Integer.valueOf(ssCon[1]);
|
|
|
- if(start<=val&&val<=end) {
|
|
|
- return true;
|
|
|
- }else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ private boolean checkIpEq(String realIp, String ipConfig) {
|
|
|
+ if (ipConfig.indexOf("-") == -1) {
|
|
|
+ return realIp.equals(ipConfig);
|
|
|
+ } else {
|
|
|
+ String[] ss1 = realIp.split("\\.");
|
|
|
+ String[] ss2 = ipConfig.split("\\.");
|
|
|
+ if (ss1.length != ss2.length) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (int i = 0; i <= 2; i++) {
|
|
|
+ if (!ss1[i].equals(ss2[i])) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] ssCon = ss2[3].split("-");
|
|
|
+ if (ssCon.length != 2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ int val = Integer.valueOf(ss1[3]);
|
|
|
+ int start = Integer.valueOf(ssCon[0]);
|
|
|
+ int end = Integer.valueOf(ssCon[1]);
|
|
|
+ if (start <= val && val <= end) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-// private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
|
-// //学习中心访问控制
|
|
|
-// DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
|
-// Boolean centerLimit = getExamLimitProperty(examId, ipCenterLimit.getId(), false);
|
|
|
-// if (centerLimit) {
|
|
|
-// StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
|
|
|
-// Long orgId = studentCache.getOrgId();
|
|
|
-// String key = CacheConstants.CACHE_B_SECURITY_IP + orgId;
|
|
|
-// String value = redisClient.get(key, String.class);
|
|
|
-// //机构是否在时间范围内登陆过
|
|
|
-// if (value != null) {
|
|
|
-// @SuppressWarnings("unchecked")
|
|
|
-// Set<String> userKeyList = JsonUtil.fromJson(value, Set.class);
|
|
|
-//
|
|
|
-// for (String userKey : userKeyList) {
|
|
|
-// User curUser = redisClient.get(userKey, User.class);
|
|
|
-// if (null != curUser) {
|
|
|
-// String clientIp = curUser.getClientIp();
|
|
|
-// if (null != clientIp) {
|
|
|
-// // IP取前三段
|
|
|
-// clientIp = clientIp.substring(0, clientIp.lastIndexOf(".") + 1);
|
|
|
-// if (!realIp.startsWith(clientIp)) {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return false;
|
|
|
-// }
|
|
|
+
|
|
|
+ // private boolean getCenterLimit(DynamicEnumManager manager, Long examId,
|
|
|
+ // Long studentId, String realIp) {
|
|
|
+ // //学习中心访问控制
|
|
|
+ // DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
|
+ // Boolean centerLimit = getExamLimitProperty(examId, ipCenterLimit.getId(),
|
|
|
+ // false);
|
|
|
+ // if (centerLimit) {
|
|
|
+ // StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
|
|
|
+ // Long orgId = studentCache.getOrgId();
|
|
|
+ // String key = CacheConstants.CACHE_B_SECURITY_IP + orgId;
|
|
|
+ // String value = redisClient.get(key, String.class);
|
|
|
+ // //机构是否在时间范围内登陆过
|
|
|
+ // if (value != null) {
|
|
|
+ // @SuppressWarnings("unchecked")
|
|
|
+ // Set<String> userKeyList = JsonUtil.fromJson(value, Set.class);
|
|
|
+ //
|
|
|
+ // for (String userKey : userKeyList) {
|
|
|
+ // User curUser = redisClient.get(userKey, User.class);
|
|
|
+ // if (null != curUser) {
|
|
|
+ // String clientIp = curUser.getClientIp();
|
|
|
+ // if (null != clientIp) {
|
|
|
+ // // IP取前三段
|
|
|
+ // clientIp = clientIp.substring(0, clientIp.lastIndexOf(".") + 1);
|
|
|
+ // if (!realIp.startsWith(clientIp)) {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
|
|
|
@Override
|
|
|
public void saveIpLimit(String ids, ExamIpLimitEntity entity) {
|
|
|
- IpUtil.checkIp(entity.getIp());
|
|
|
- //ids不为空,说明是批量设置限制类型
|
|
|
+ IpUtil.checkIp(entity.getIp());
|
|
|
+ // ids不为空,说明是批量设置限制类型
|
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
|
List<Long> ipIds = getIdsByPath(ids);
|
|
|
if (entity.getLimitType() != null) {
|
|
@@ -1021,16 +1021,16 @@ public class ExamServiceImpl implements ExamService {
|
|
|
Long id = entity.getId();
|
|
|
Date now = new Date();
|
|
|
|
|
|
- if(StringUtils.length(entity.getRemark()) > 30){
|
|
|
+ if (StringUtils.length(entity.getRemark()) > 30) {
|
|
|
throw new StatusException("400", "备注长度不能超过30个字");
|
|
|
}
|
|
|
|
|
|
- //新增
|
|
|
+ // 新增
|
|
|
if (id == null) {
|
|
|
entity.setCreationTime(now);
|
|
|
examIpLimitRepo.save(entity);
|
|
|
} else {
|
|
|
- //更新
|
|
|
+ // 更新
|
|
|
Optional<ExamIpLimitEntity> byId = examIpLimitRepo.findById(id);
|
|
|
if (byId.isPresent()) {
|
|
|
ExamIpLimitEntity ipLimitEntity = byId.get();
|
|
@@ -1093,7 +1093,8 @@ public class ExamServiceImpl implements ExamService {
|
|
|
saveIpLimitEntity(centerEntity, centerLimit, ipCenterLimit, examId);
|
|
|
}
|
|
|
|
|
|
- private void saveIpLimitEntity(ExamPropertyEntity propertyEntity, String limitValue, DynamicEnum dynamicEnum, Long examId) {
|
|
|
+ private void saveIpLimitEntity(ExamPropertyEntity propertyEntity, String limitValue, DynamicEnum dynamicEnum,
|
|
|
+ Long examId) {
|
|
|
Date now = new Date();
|
|
|
if (propertyEntity != null) {
|
|
|
propertyEntity.setValue(limitValue);
|
|
@@ -1116,14 +1117,14 @@ public class ExamServiceImpl implements ExamService {
|
|
|
}
|
|
|
|
|
|
private List<Long> getIdsByPath(String ids) {
|
|
|
- return Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ return Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
private Boolean getExamLimitProperty(Long examId, Long keyId, Boolean defaultValue) {
|
|
|
ExamPropertyEntity propertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, keyId);
|
|
|
return propertyEntity != null && StringUtils.isNotBlank(propertyEntity.getValue())
|
|
|
- ? Boolean.valueOf(propertyEntity.getValue()) : defaultValue;
|
|
|
+ ? Boolean.valueOf(propertyEntity.getValue())
|
|
|
+ : defaultValue;
|
|
|
}
|
|
|
|
|
|
private Specification<ExamIpLimitEntity> getSpec(Long examId, IpLimitType limitType, String ip) {
|
|
@@ -1142,20 +1143,20 @@ public class ExamServiceImpl implements ExamService {
|
|
|
};
|
|
|
return spec;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void addIpLimitByOrgIp(Long examId,List<OrgIpInfo> ips) {
|
|
|
- for(OrgIpInfo ip:ips) {
|
|
|
- List<ExamIpLimitEntity> list=examIpLimitRepo.findByExamIdAndIp(examId,ip.getIp());
|
|
|
- if(CollectionUtils.isEmpty(list)) {
|
|
|
- ExamIpLimitEntity e=new ExamIpLimitEntity();
|
|
|
- e.setExamId(examId);
|
|
|
- e.setIp(ip.getIp());
|
|
|
- e.setLimitType(IpLimitType.HAS_ACCESS);
|
|
|
- e.setRemark(ip.getRemark());
|
|
|
- examIpLimitRepo.save(e);
|
|
|
- }
|
|
|
+ public void addIpLimitByOrgIp(Long examId, List<OrgIpInfo> ips) {
|
|
|
+ for (OrgIpInfo ip : ips) {
|
|
|
+ List<ExamIpLimitEntity> list = examIpLimitRepo.findByExamIdAndIp(examId, ip.getIp());
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ ExamIpLimitEntity e = new ExamIpLimitEntity();
|
|
|
+ e.setExamId(examId);
|
|
|
+ e.setIp(ip.getIp());
|
|
|
+ e.setLimitType(IpLimitType.HAS_ACCESS);
|
|
|
+ e.setRemark(ip.getRemark());
|
|
|
+ examIpLimitRepo.save(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|