Ver Fonte

ip限制

qinchao há 4 anos atrás
pai
commit
8945ccb5e4

+ 24 - 19
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -1418,8 +1418,8 @@ public class ExamController extends ControllerSupport {
     }
 
     @ApiOperation(value = "保存ip限制信息",notes = "保存ip限制")
-    @PostMapping("ipLimited/{ids}")
-    public void save(@PathVariable String ids, @RequestBody ExamIpLimitEntity entity) {
+    @PostMapping("ipLimited")
+    public void save(String ids, @RequestBody ExamIpLimitEntity entity) {
 
         //ids不为空,说明是批量设置限制类型
         if (StringUtils.isNotBlank(ids)) {
@@ -1473,24 +1473,30 @@ public class ExamController extends ControllerSupport {
 
     @ApiOperation(value = "查询整体控制和学习中心控制",notes = "查询控制")
     @GetMapping("ipLimited/property/{examId}")
-    public Map<String,Boolean> ipLimitedProperty(@PathVariable Long examId) {
-        Map<String,Boolean> map = new HashMap<>();
+    public Map<String,Integer> ipLimitedProperty(@PathVariable Long examId) {
+        Map<String,Integer> map = new HashMap<>();
         map.put("totalLimit", getExamBooleanProperty(examId,49));
         map.put("centerLimit",getExamBooleanProperty(examId,50));
         return map;
     }
 
     @ApiOperation(value = "修改整体控制和学习中心控制",notes = "修改控制")
-    @PutMapping("ipLimited/property/{examId}")
-    public void ipLimitedProperty(@PathVariable Long examId, @RequestBody Map<String,Boolean> map) {
+    @PostMapping("ipLimited/property/{examId}")
+    public void ipLimitedProperty(@PathVariable Long examId, @RequestBody Map<String,Integer> map) {
         updateExamProperty(examId,49,map.get("totalLimit"));
         updateExamProperty(examId,50,map.get("centerLimit"));
     }
 
     private void updateExamProperty(Long examId, Integer keyId, Object value) {
-        //虚拟摄像头进入待审核,且有虚拟摄像头的
-        String valueSql="update ec_e_exam_prop set value = '"+value+"'where exam_id ="+examId+" AND key_id="+keyId;
-        jdbcTemplate.update(valueSql);
+        String countSql="select count(1) from ec_e_exam_prop where exam_id ="+examId+" AND key_id="+keyId;
+        Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
+        if (count==0){
+            String valueSql="insert into ec_e_exam_prop values (null,NOW(),NOW(),"+examId+","+keyId+","+value+")";
+            jdbcTemplate.update(valueSql);
+        } else {
+            String valueSql="update ec_e_exam_prop set value = '"+value+"'where exam_id ="+examId+" AND key_id="+keyId;
+            jdbcTemplate.update(valueSql);
+        }
     }
 
     @ApiOperation(value = "下载ip限制导入模板", notes = "下载导入模板")
@@ -1501,8 +1507,8 @@ public class ExamController extends ControllerSupport {
     }
 
     @ApiOperation(value = "导入考试ip限制", notes = "导入")
-    @PostMapping("ipLimited/import")
-    public Map<String, Object> importExamIpLimit(@RequestParam Long examId,
+    @PostMapping("ipLimited/import/{examId}")
+    public Map<String, Object> importExamIpLimit(@PathVariable Long examId,
                                   @RequestParam CommonsMultipartFile file) {
         DiskFileItem item = (DiskFileItem) file.getFileItem();
         File storeLocation = item.getStoreLocation();
@@ -1659,14 +1665,14 @@ public class ExamController extends ControllerSupport {
             }
             realIp = realIp.trim();
             //整体控制
-            boolean totalLimit = getExamBooleanProperty(examId,49);
-            if (totalLimit) {
+            Integer totalLimit = getExamBooleanProperty(examId,49);
+            if (totalLimit == 1) {
                 //在白名单中
                 int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId,"0",realIp);
                 if (count>0) {
                     //学习中心访问控制
-                    boolean centerLimit = getExamBooleanProperty(examId,50);
-                    if (centerLimit) {
+                    Integer centerLimit = getExamBooleanProperty(examId,50);
+                    if (centerLimit == 1) {
                         User accessUser = getAccessUser();
                         StudentCacheBean studentCache = CacheHelper.getStudent(accessUser.getUserId());
                         Long orgId = studentCache.getOrgId();
@@ -1704,11 +1710,10 @@ public class ExamController extends ControllerSupport {
         return true;
     }
 
-    private boolean getExamBooleanProperty(Long examId,Integer keyId) {
-        //虚拟摄像头进入待审核,且有虚拟摄像头的
+    private Integer getExamBooleanProperty(Long examId, Integer keyId) {
         String valueSql="SELECT value FROM ec_e_exam_prop WHERE exam_id ="+examId+" AND key_id="+keyId;
-        List<Boolean> list = jdbcTemplate.query(valueSql, (rs, rowNum) -> rs.getBoolean("value"));
-        return !CollectionUtils.isEmpty(list) && list.get(0);
+        List<Integer> list = jdbcTemplate.query(valueSql, (rs, rowNum) -> rs.getInt("value"));
+        return !CollectionUtils.isEmpty(list) ? list.get(0) : 0;
     }
 
     @ApiOperation(value = "是否可以微信作答", notes = "")

+ 3 - 3
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/bean/ExamIpLimitDomain.java

@@ -36,7 +36,7 @@ public class ExamIpLimitDomain implements JsonSerializable {
 	/**
 	 * 限制类型:1禁止访问,0允许访问
 	 */
-	private String limitType;
+	private Integer limitType;
 
 	/**
 	 * 创建时间
@@ -80,11 +80,11 @@ public class ExamIpLimitDomain implements JsonSerializable {
 		this.ip = ip;
 	}
 
-	public String getLimitType() {
+	public Integer getLimitType() {
 		return limitType;
 	}
 
-	public void setLimitType(String limitType) {
+	public void setLimitType(Integer limitType) {
 		this.limitType = limitType;
 	}
 

+ 14 - 6
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamIpLimitRepo.java

@@ -3,8 +3,10 @@ package cn.com.qmth.examcloud.core.examwork.dao;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamIpLimitEntity;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -12,16 +14,22 @@ public interface ExamIpLimitRepo extends JpaRepository<ExamIpLimitEntity, Long>,
 			QueryByExampleExecutor<ExamIpLimitEntity>, JpaSpecificationExecutor<ExamIpLimitEntity> {
 
 	@Query(value = "SELECT count(1) from ec_e_exam_ip_limit t where t.exam_id = ?1 " +
-			"AND t.limit_type = ?2 AND 3? REGEXP t.ip ",nativeQuery = true)
+			"AND t.limit_type = ?2 AND ?3 REGEXP t.ip ",nativeQuery = true)
 	int countByExamIdAndLimitTypeAndIp(Long examId, String limitType, String ip);
 
+	@Transactional
+	@Modifying
 	@Query(value = "delete from ec_e_exam_ip_limit where id in ?1 ",nativeQuery = true)
-    void deleteByIds(List<Long> ipIds);
+    int deleteByIds(List<Long> ipIds);
 
+	@Modifying
+	@Transactional
+	@Query(value = "update ExamIpLimitEntity t set t.limitType = ?1" +
+			" where t.examId = ?2 and t.id in ?3")
+	int updateLimitType(Integer LimitType, Long examId, List<Long> ids);
+
+	@Transactional
+	@Modifying
 	@Query(value = "delete from ec_e_exam_ip_limit where exam_id = ?1 ",nativeQuery = true)
 	void deleteAllByExamId(Long examId);
-
-	@Query(value = "update ec_e_exam_ip_limit t set t.limit_type = ?1" +
-			" where t.exam_id = ?2 and t.id in ?3",nativeQuery = true)
-	void updateLimitType(Integer LimitType, Long examId, List<Long> ids);
 }

+ 2 - 2
examcloud-core-examwork-starter/src/main/resources/exam-properties.xml

@@ -292,12 +292,12 @@
 		<id>49</id>
 		<name>IP_TOTAL_LIMIT</name>
 		<desc>IP访问设置-整体控制</desc>
-		<valueType>BOOLEAN</valueType>
+		<valueType>INTEGER</valueType>
 	</enum>
 	<enum>
 		<id>50</id>
 		<name>IP_CENTER_LIMIT</name>
 		<desc>IP访问设置-学习中心控制</desc>
-		<valueType>BOOLEAN</valueType>
+		<valueType>INTEGER</valueType>
 	</enum>
 </enums>