|
@@ -26,7 +26,6 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsResp;
|
|
|
import cn.com.qmth.examcloud.core.examwork.api.controller.bean.CopyExamDomain;
|
|
|
import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamDomain;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamIpLimitInfo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamOrgSettingsDomain;
|
|
|
import cn.com.qmth.examcloud.core.examwork.api.controller.bean.StudentSpecialSettingsDomain;
|
|
|
import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
@@ -35,6 +34,7 @@ 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.service.ExamService;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamIpLimitInfo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.cache.ExamSettingsCache;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
|
|
@@ -43,6 +43,7 @@ import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.*;
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeDefine;
|
|
|
import cn.com.qmth.examcloud.support.privilege.PrivilegeManager;
|
|
|
import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
@@ -315,7 +316,7 @@ public class ExamController extends ControllerSupport {
|
|
|
}
|
|
|
|
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
- DynamicEnum ipLimit = manager.getByName("IP_LIMIT");
|
|
|
+ DynamicEnum ipLimit = manager.getByName(ExamProperties.IP_LIMIT.name());
|
|
|
|
|
|
ExamPropertyEntity propertyEntity = examPropertyRepo.findByExamIdAndKeyId(next.getId(), ipLimit.getId());
|
|
|
boolean ipLimited = null != propertyEntity && StringUtils.isNotBlank(propertyEntity.getValue()) && Boolean.parseBoolean(propertyEntity.getValue());
|
|
@@ -1299,140 +1300,43 @@ public class ExamController extends ControllerSupport {
|
|
|
|
|
|
examOrgPropertyRepo.deleteByExamId(examId);
|
|
|
|
|
|
- examSpecialSettingsRepo
|
|
|
- .deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNullAndStudentIdIsNull(examId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param examId
|
|
|
- * @return
|
|
|
- * @author WANGWEI
|
|
|
- */
|
|
|
- @ApiOperation(value = "考试IP限制", notes = "")
|
|
|
- //@GetMapping("ipLimit/{examId}")
|
|
|
- public Map<String, Object> ipLimit(HttpServletRequest request, @PathVariable Long examId) {
|
|
|
- User accessUser = getAccessUser();
|
|
|
- StudentCacheBean studentCache = CacheHelper.getStudent(accessUser.getUserId());
|
|
|
- Long orgId = studentCache.getOrgId();
|
|
|
- ExamPropertyCacheBean ipLimitProperty = CacheHelper.getExamProperty(examId, "IP_LIMIT");
|
|
|
-
|
|
|
- Map<String, Object> map = Maps.newHashMap();
|
|
|
-
|
|
|
- Boolean ipLimit = null;
|
|
|
- if (null != ipLimitProperty) {
|
|
|
- ipLimit = StringUtil.isTrue(ipLimitProperty.getValue());
|
|
|
- }
|
|
|
-
|
|
|
- if (null == ipLimit || !ipLimit) {
|
|
|
- map.put("limited", false);
|
|
|
- map.put("desc", "未配置IP限制");
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- String realIp = request.getHeader("x-forwarded-for");
|
|
|
- if (StringUtils.isBlank(realIp)) {
|
|
|
- realIp = request.getHeader("x-real-ip");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(realIp)) {
|
|
|
- map.put("limited", true);
|
|
|
- map.put("desc", "网络受限");
|
|
|
- return map;
|
|
|
- }
|
|
|
- realIp = realIp.trim();
|
|
|
-
|
|
|
- ExamPropertyCacheBean ipAddressesProperty = CacheHelper.getExamProperty(examId,
|
|
|
- "IP_ADDRESSES");
|
|
|
-
|
|
|
- String ipAddresses = null;
|
|
|
- if (null != ipAddressesProperty) {
|
|
|
- ipAddresses = ipAddressesProperty.getValue();
|
|
|
- }
|
|
|
-
|
|
|
- boolean limited = true;
|
|
|
- if (StringUtils.isNotBlank(ipAddresses)) {
|
|
|
- String[] arr = StringUtils.split(ipAddresses, ';');
|
|
|
-
|
|
|
- for (String cur : arr) {
|
|
|
- String ip = StringUtils.replace(cur.trim(), ".", "\\.");
|
|
|
- ip = StringUtils.replace(ip, "*", "\\w+");
|
|
|
- if (realIp.matches(ip)) {
|
|
|
- limited = false;
|
|
|
- map.put("desc", "IP段配置放行");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (limited) {
|
|
|
- String key = "IP_" + orgId;
|
|
|
- String value = redisClient.get(key, String.class);
|
|
|
- if (null == value) {
|
|
|
- map.put("desc", "无机构管理员登录");
|
|
|
- } else {
|
|
|
- @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)) {
|
|
|
- limited = false;
|
|
|
- map.put("desc", "机构管理员[key=" + userKey + "]登录放行");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- map.put("limited", limited);
|
|
|
-
|
|
|
- return map;
|
|
|
+ examSpecialSettingsRepo.deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNullAndStudentIdIsNull(examId);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "ip限制分页",notes = "ip限制分页")
|
|
|
+ @ApiOperation(value = "ip限制分页", notes = "ip限制分页")
|
|
|
@GetMapping("ipLimited/page/{curPage}/{pageSize}")
|
|
|
public PageInfo<ExamIpLimitInfo> ipLimited(@PathVariable Integer curPage, @PathVariable Integer pageSize,
|
|
|
Long examId, Integer limitType, String ip) {
|
|
|
return examService.pageIpLimited(curPage, pageSize, examId, limitType, ip);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "保存ip限制信息",notes = "保存ip限制")
|
|
|
+ @ApiOperation(value = "保存ip限制信息", notes = "保存ip限制")
|
|
|
@PostMapping("ipLimited")
|
|
|
public void save(String ids, @RequestBody ExamIpLimitEntity entity) {
|
|
|
examService.saveIpLimit(ids, entity);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "根据主键删除ip限制",notes = "删除ip限制")
|
|
|
+ @ApiOperation(value = "根据主键删除ip限制", notes = "删除ip限制")
|
|
|
@DeleteMapping("ipLimited/{ids}")
|
|
|
public void delete(@PathVariable String ids) {
|
|
|
examService.deleteIpLimit(ids);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "根据考试id批量删除ip限制",notes = "删除ip限制")
|
|
|
+ @ApiOperation(value = "根据考试id批量删除ip限制", notes = "删除ip限制")
|
|
|
@DeleteMapping("ipLimited/all/{examId}")
|
|
|
public void delete(@PathVariable Long examId) {
|
|
|
examService.deleteIpLimit(examId);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "查询整体控制和学习中心控制",notes = "查询控制")
|
|
|
+ @ApiOperation(value = "查询整体控制和学习中心控制", notes = "查询控制")
|
|
|
@GetMapping("ipLimited/property/{examId}")
|
|
|
- public Map<String,Boolean> ipLimitedProperty(@PathVariable Long examId) {
|
|
|
+ public Map<String, Boolean> ipLimitedProperty(@PathVariable Long examId) {
|
|
|
return examService.getIpLimitedProperty(examId);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "修改整体控制和学习中心控制",notes = "修改控制")
|
|
|
+ @ApiOperation(value = "修改整体控制和学习中心控制", notes = "修改控制")
|
|
|
@PostMapping("ipLimited/property/{examId}")
|
|
|
- public void ipLimitedProperty(@PathVariable Long examId, @RequestBody Map<String,Object> map) {
|
|
|
+ public void ipLimitedProperty(@PathVariable Long examId, @RequestBody Map<String, Object> map) {
|
|
|
examService.updateIpLimitedProperty(examId, map);
|
|
|
}
|
|
|
|
|
@@ -1446,7 +1350,7 @@ public class ExamController extends ControllerSupport {
|
|
|
@ApiOperation(value = "导入考试ip限制", notes = "导入")
|
|
|
@PostMapping("ipLimited/import/{examId}")
|
|
|
public Map<String, Object> importExamIpLimit(@PathVariable Long examId,
|
|
|
- @RequestParam CommonsMultipartFile file) {
|
|
|
+ @RequestParam CommonsMultipartFile file) {
|
|
|
DiskFileItem item = (DiskFileItem) file.getFileItem();
|
|
|
File storeLocation = item.getStoreLocation();
|
|
|
List<String[]> lineList;
|
|
@@ -1499,7 +1403,7 @@ public class ExamController extends ControllerSupport {
|
|
|
hasError = true;
|
|
|
}
|
|
|
IpLimitType ipLimitType = IpLimitType.formByName(line[1]);
|
|
|
- if(ipLimitType==null){
|
|
|
+ if (ipLimitType == null) {
|
|
|
msg.append(" 不符合格式的限制类型");
|
|
|
hasError = true;
|
|
|
}
|
|
@@ -1511,7 +1415,7 @@ public class ExamController extends ControllerSupport {
|
|
|
|
|
|
if (hasError) {
|
|
|
Map<String, Object> map = Maps.newHashMap();
|
|
|
- map.put("lineNum", i+1);
|
|
|
+ map.put("lineNum", i + 1);
|
|
|
map.put("msg", msg);
|
|
|
failRecords.add(map);
|
|
|
} else {
|
|
@@ -1533,7 +1437,7 @@ public class ExamController extends ControllerSupport {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "导出Ip限制",notes = "导出Ip限制")
|
|
|
+ @ApiOperation(value = "导出Ip限制", notes = "导出Ip限制")
|
|
|
@GetMapping("ipLimited/export")
|
|
|
public void export(Long examId, Integer limitType, String ip) {
|
|
|
List<ExamIpLimitEntity> list = examService.findAllIpLimits(examId, limitType, ip);
|
|
@@ -1569,16 +1473,16 @@ public class ExamController extends ControllerSupport {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "检查是否Ip限制",notes = "检查是否Ip限制")
|
|
|
+ @ApiOperation(value = "检查是否Ip限制", notes = "检查是否Ip限制")
|
|
|
@GetMapping("ipLimit/{examId}")
|
|
|
public Map<String, Object> ipLimited(HttpServletRequest request, @PathVariable Long examId) {
|
|
|
String realIp = getIp(request);
|
|
|
User accessUser = getAccessUser();
|
|
|
boolean ipLimited = examService.getIpLimited(realIp, examId, accessUser);
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("limited",ipLimited);
|
|
|
+ map.put("limited", ipLimited);
|
|
|
if (ipLimited) {
|
|
|
- map.put("desc","该考试当前考生受限");
|
|
|
+ map.put("desc", "该考试当前考生受限");
|
|
|
}
|
|
|
return map;
|
|
|
}
|