|
@@ -13,22 +13,13 @@ import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
|
|
import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
-import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamIpLimitRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamIpLimitEntity;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
|
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.*;
|
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.*;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.enums.IpLimitType;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.enums.IpLimitType;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamService;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamService;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
|
|
import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
|
|
@@ -38,8 +29,8 @@ import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
|
|
import cn.com.qmth.examcloud.core.examwork.service.cache.ExamPropertyCache;
|
|
import cn.com.qmth.examcloud.core.examwork.service.cache.ExamPropertyCache;
|
|
import cn.com.qmth.examcloud.core.examwork.service.cache.ExamSettingsCache;
|
|
import cn.com.qmth.examcloud.core.examwork.service.cache.ExamSettingsCache;
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
-import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
|
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
|
|
import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
|
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeDefine;
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeDefine;
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeManager;
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeManager;
|
|
import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
@@ -65,15 +56,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.Map.Entry;
|
|
import java.util.Map.Entry;
|
|
-import java.util.Optional;
|
|
|
|
-import java.util.Set;
|
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -856,9 +840,9 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
PageInfo<ExamIpLimitInfo> pageInfo = new PageInfo<>();
|
|
PageInfo<ExamIpLimitInfo> pageInfo = new PageInfo<>();
|
|
List<ExamIpLimitInfo> list = new ArrayList<>();
|
|
List<ExamIpLimitInfo> list = new ArrayList<>();
|
|
- pages.getList().forEach(e->{
|
|
|
|
|
|
+ pages.getList().forEach(e -> {
|
|
ExamIpLimitInfo domain = new ExamIpLimitInfo();
|
|
ExamIpLimitInfo domain = new ExamIpLimitInfo();
|
|
- BeanUtils.copyProperties(e,domain);
|
|
|
|
|
|
+ BeanUtils.copyProperties(e, domain);
|
|
domain.setLimitType(e.getLimitType() == null ? "" : e.getLimitType().getName());
|
|
domain.setLimitType(e.getLimitType() == null ? "" : e.getLimitType().getName());
|
|
Optional<ExamEntity> byId = examRepo.findById(examId);
|
|
Optional<ExamEntity> byId = examRepo.findById(examId);
|
|
byId.ifPresent(examEntity -> domain.setExamName(examEntity.getName()));
|
|
byId.ifPresent(examEntity -> domain.setExamName(examEntity.getName()));
|
|
@@ -882,7 +866,7 @@ public class ExamServiceImpl implements ExamService {
|
|
@Override
|
|
@Override
|
|
public boolean getIpLimited(String realIp, Long examId, User accessUser) {
|
|
public boolean getIpLimited(String realIp, Long examId, User accessUser) {
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
- DynamicEnum ipLimit = manager.getByName("IP_LIMIT");
|
|
|
|
|
|
+ DynamicEnum ipLimit = manager.getByName(ExamProperties.IP_LIMIT.name());
|
|
|
|
|
|
//是否开启Ip限制
|
|
//是否开启Ip限制
|
|
Boolean ipLimited = getExamLimitProperty(examId, ipLimit.getId(), false);
|
|
Boolean ipLimited = getExamLimitProperty(examId, ipLimit.getId(), false);
|
|
@@ -892,7 +876,7 @@ public class ExamServiceImpl implements ExamService {
|
|
Boolean totalLimit = getExamLimitProperty(examId, ipTotalLimit.getId(), false);
|
|
Boolean totalLimit = getExamLimitProperty(examId, ipTotalLimit.getId(), false);
|
|
if (totalLimit) {
|
|
if (totalLimit) {
|
|
//在白名单中
|
|
//在白名单中
|
|
- int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(),realIp);
|
|
|
|
|
|
+ int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(), realIp);
|
|
if (count == 0) {
|
|
if (count == 0) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
@@ -901,7 +885,7 @@ public class ExamServiceImpl implements ExamService {
|
|
} else {
|
|
} else {
|
|
//在黑名单中
|
|
//在黑名单中
|
|
int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
- if (count > 0){
|
|
|
|
|
|
+ if (count > 0) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
@@ -915,7 +899,7 @@ public class ExamServiceImpl implements ExamService {
|
|
private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
//学习中心访问控制
|
|
//学习中心访问控制
|
|
DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
- Boolean centerLimit = getExamLimitProperty(examId,ipCenterLimit.getId(), false);
|
|
|
|
|
|
+ Boolean centerLimit = getExamLimitProperty(examId, ipCenterLimit.getId(), false);
|
|
if (centerLimit) {
|
|
if (centerLimit) {
|
|
StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
|
|
StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
|
|
Long orgId = studentCache.getOrgId();
|
|
Long orgId = studentCache.getOrgId();
|
|
@@ -953,25 +937,25 @@ public class ExamServiceImpl implements ExamService {
|
|
//ids不为空,说明是批量设置限制类型
|
|
//ids不为空,说明是批量设置限制类型
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
List<Long> ipIds = getIdsByPath(ids);
|
|
List<Long> ipIds = getIdsByPath(ids);
|
|
- if(entity.getLimitType()!=null){
|
|
|
|
- examIpLimitRepo.updateLimitType(entity.getLimitType(),entity.getExamId(),ipIds);
|
|
|
|
|
|
+ if (entity.getLimitType() != null) {
|
|
|
|
+ examIpLimitRepo.updateLimitType(entity.getLimitType(), entity.getExamId(), ipIds);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
Long id = entity.getId();
|
|
Long id = entity.getId();
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
//新增
|
|
//新增
|
|
- if (id==null) {
|
|
|
|
|
|
+ if (id == null) {
|
|
entity.setCreationTime(now);
|
|
entity.setCreationTime(now);
|
|
examIpLimitRepo.save(entity);
|
|
examIpLimitRepo.save(entity);
|
|
} else {
|
|
} else {
|
|
//更新
|
|
//更新
|
|
Optional<ExamIpLimitEntity> byId = examIpLimitRepo.findById(id);
|
|
Optional<ExamIpLimitEntity> byId = examIpLimitRepo.findById(id);
|
|
- if (byId.isPresent()){
|
|
|
|
|
|
+ if (byId.isPresent()) {
|
|
ExamIpLimitEntity ipLimitEntity = byId.get();
|
|
ExamIpLimitEntity ipLimitEntity = byId.get();
|
|
- if(StringUtils.isNotBlank(entity.getIp())){
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(entity.getIp())) {
|
|
ipLimitEntity.setIp(entity.getIp());
|
|
ipLimitEntity.setIp(entity.getIp());
|
|
}
|
|
}
|
|
- if(entity.getLimitType()!=null){
|
|
|
|
|
|
+ if (entity.getLimitType() != null) {
|
|
ipLimitEntity.setLimitType(entity.getLimitType());
|
|
ipLimitEntity.setLimitType(entity.getLimitType());
|
|
}
|
|
}
|
|
ipLimitEntity.setUpdateTime(now);
|
|
ipLimitEntity.setUpdateTime(now);
|
|
@@ -996,14 +980,14 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Boolean> getIpLimitedProperty(Long examId) {
|
|
public Map<String, Boolean> getIpLimitedProperty(Long examId) {
|
|
- Map<String,Boolean> map = new HashMap<>();
|
|
|
|
|
|
+ Map<String, Boolean> map = new HashMap<>();
|
|
|
|
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
DynamicEnum ipTotalLimit = manager.getByName("IP_TOTAL_LIMIT");
|
|
DynamicEnum ipTotalLimit = manager.getByName("IP_TOTAL_LIMIT");
|
|
DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
|
|
|
|
- map.put("totalLimit", getExamLimitProperty(examId,ipTotalLimit.getId(),false));
|
|
|
|
- map.put("centerLimit",getExamLimitProperty(examId,ipCenterLimit.getId(),false));
|
|
|
|
|
|
+ map.put("totalLimit", getExamLimitProperty(examId, ipTotalLimit.getId(), false));
|
|
|
|
+ map.put("centerLimit", getExamLimitProperty(examId, ipCenterLimit.getId(), false));
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1020,13 +1004,13 @@ public class ExamServiceImpl implements ExamService {
|
|
String totalLimit = map.get("totalLimit").toString();
|
|
String totalLimit = map.get("totalLimit").toString();
|
|
String centerLimit = map.get("centerLimit").toString();
|
|
String centerLimit = map.get("centerLimit").toString();
|
|
|
|
|
|
- saveIpLimitEntity(totalEntity,totalLimit,ipTotalLimit,examId);
|
|
|
|
- saveIpLimitEntity(centerEntity,centerLimit,ipCenterLimit,examId);
|
|
|
|
|
|
+ saveIpLimitEntity(totalEntity, totalLimit, ipTotalLimit, examId);
|
|
|
|
+ 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();
|
|
Date now = new Date();
|
|
- if (propertyEntity!=null) {
|
|
|
|
|
|
+ if (propertyEntity != null) {
|
|
propertyEntity.setValue(limitValue);
|
|
propertyEntity.setValue(limitValue);
|
|
propertyEntity.setUpdateTime(now);
|
|
propertyEntity.setUpdateTime(now);
|
|
examPropertyRepo.save(propertyEntity);
|
|
examPropertyRepo.save(propertyEntity);
|
|
@@ -1051,23 +1035,23 @@ public class ExamServiceImpl implements ExamService {
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- private Boolean getExamLimitProperty(Long examId, Long keyId ,Boolean defaultValue) {
|
|
|
|
|
|
+ private Boolean getExamLimitProperty(Long examId, Long keyId, Boolean defaultValue) {
|
|
ExamPropertyEntity propertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, keyId);
|
|
ExamPropertyEntity propertyEntity = examPropertyRepo.findByExamIdAndKeyId(examId, keyId);
|
|
return propertyEntity != null && StringUtils.isNotBlank(propertyEntity.getValue())
|
|
return propertyEntity != null && StringUtils.isNotBlank(propertyEntity.getValue())
|
|
? Boolean.valueOf(propertyEntity.getValue()) : defaultValue;
|
|
? Boolean.valueOf(propertyEntity.getValue()) : defaultValue;
|
|
}
|
|
}
|
|
|
|
|
|
- private Specification<ExamIpLimitEntity> getSpec(Long examId, Integer limitType, String ip){
|
|
|
|
|
|
+ private Specification<ExamIpLimitEntity> getSpec(Long examId, Integer limitType, String ip) {
|
|
Specification<ExamIpLimitEntity> spec = (root, query, cb) -> {
|
|
Specification<ExamIpLimitEntity> spec = (root, query, cb) -> {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
- if(examId!=null){
|
|
|
|
|
|
+ if (examId != null) {
|
|
predicates.add(cb.equal(root.get("examId"), examId));
|
|
predicates.add(cb.equal(root.get("examId"), examId));
|
|
}
|
|
}
|
|
- if(limitType!=null){
|
|
|
|
|
|
+ if (limitType != null) {
|
|
predicates.add(cb.equal(root.get("limitType"), limitType));
|
|
predicates.add(cb.equal(root.get("limitType"), limitType));
|
|
}
|
|
}
|
|
- if(StringUtils.isNotBlank(ip)){
|
|
|
|
- predicates.add(cb.like(root.get("ip"), "%"+ip+"%"));
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(ip)) {
|
|
|
|
+ predicates.add(cb.like(root.get("ip"), "%" + ip + "%"));
|
|
}
|
|
}
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
};
|
|
};
|