Explorar el Código

fix IpLimitType

deason hace 1 año
padre
commit
f2765214de

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

@@ -1360,7 +1360,7 @@ public class ExamController extends ControllerSupport {
     @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) {
+                                               Long examId, IpLimitType limitType, String ip) {
         return examService.pageIpLimited(curPage, pageSize, examId, limitType, ip);
     }
 
@@ -1456,7 +1456,7 @@ public class ExamController extends ControllerSupport {
                 msg.append("  限制类型不能为空");
                 hasError = true;
             }
-            IpLimitType ipLimitType = IpLimitType.formByName(line[1]);
+            IpLimitType ipLimitType = IpLimitType.formByTitle(line[1]);
             if (ipLimitType == null) {
                 msg.append("  不符合格式的限制类型");
                 hasError = true;
@@ -1493,13 +1493,13 @@ public class ExamController extends ControllerSupport {
 
     @ApiOperation(value = "导出Ip限制", notes = "导出Ip限制")
     @GetMapping("ipLimited/export")
-    public void export(Long examId, Integer limitType, String ip) {
+    public void export(Long examId, IpLimitType limitType, String ip) {
         List<ExamIpLimitEntity> list = examService.findAllIpLimits(examId, limitType, ip);
 
         List<Object[]> datas = Lists.newArrayList();
 
         for (ExamIpLimitEntity cur : list) {
-            String type = cur.getLimitType() == null ? "" : cur.getLimitType().getName();
+            String type = cur.getLimitType() == null ? "" : cur.getLimitType().getTitle();
             datas.add(new Object[]{cur.getIp(), type});
         }
 

+ 12 - 39
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/enums/IpLimitType.java

@@ -12,58 +12,32 @@ public enum IpLimitType {
     /**
      * 允许访问
      */
-    HAS_ACCESS(0, "允许访问"),
+    HAS_ACCESS("允许访问"),
     /**
      * 禁止访问
      */
-    NO_ACCESS(1, "禁止访问");
+    NO_ACCESS("禁止访问");
 
-    private Integer id;
+    private String title;
 
-    private String name;
-
-    private IpLimitType() {
-    }
-
-    private IpLimitType(Integer id, String name) {
-        this.id = id;
-        this.name = name;
-    }
-
-    public Integer getId() {
-        return id;
-    }
-
-    public void setId(Integer id) {
-        this.id = id;
+    IpLimitType(String title) {
+        this.title = title;
     }
 
-    public String getName() {
-        return name;
+    public String getTitle() {
+        return title;
     }
 
-    public void setName(String name) {
-        this.name = name;
+    public void setTitle(String title) {
+        this.title = title;
     }
 
-    public static IpLimitType formById(Integer id) {
-        if (id == null) {
-            return null;
-        }
-        for (IpLimitType iplimitType : IpLimitType.values()) {
-            if (iplimitType.getId().equals(id)) {
-                return iplimitType;
-            }
-        }
-        return null;
-    }
-
-    public static IpLimitType formByName(String name) {
-        if (StringUtils.isBlank(name)) {
+    public static IpLimitType formByTitle(String title) {
+        if (StringUtils.isBlank(title)) {
             return null;
         }
         for (IpLimitType ipLimitType : IpLimitType.values()) {
-            if (ipLimitType.getName().equals(name)) {
+            if (ipLimitType.getTitle().equals(title)) {
                 return ipLimitType;
             }
         }
@@ -71,4 +45,3 @@ public enum IpLimitType {
     }
 
 }
-

+ 3 - 2
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamService.java

@@ -6,6 +6,7 @@ import cn.com.qmth.examcloud.api.commons.security.bean.User;
 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.ExamSpecialSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.enums.IpLimitType;
 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;
@@ -96,7 +97,7 @@ public interface ExamService {
      * @param ip
      * @return PageInfo<ExamIpLimitInfo>
      */
-    PageInfo<ExamIpLimitInfo> pageIpLimited(Integer curPage, Integer pageSize, Long examId, Integer limitType, String ip);
+    PageInfo<ExamIpLimitInfo> pageIpLimited(Integer curPage, Integer pageSize, Long examId, IpLimitType limitType, String ip);
 
     /**
      * Description ip限制列表查询
@@ -106,7 +107,7 @@ public interface ExamService {
      * @param ip
      * @return List<ExamIpLimitEntity>
      */
-    List<ExamIpLimitEntity> findAllIpLimits(Long examId, Integer limitType, String ip);
+    List<ExamIpLimitEntity> findAllIpLimits(Long examId, IpLimitType limitType, String ip);
 
     /***
      * Description 查询当前用户当前考试是否被限制

+ 4 - 4
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamServiceImpl.java

@@ -851,7 +851,7 @@ public class ExamServiceImpl implements ExamService {
     }
 
     @Override
-    public PageInfo<ExamIpLimitInfo> pageIpLimited(Integer curPage, Integer pageSize, Long examId, Integer 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"));
@@ -862,7 +862,7 @@ public class ExamServiceImpl implements ExamService {
         pages.getList().forEach(e -> {
             ExamIpLimitInfo domain = new ExamIpLimitInfo();
             BeanUtils.copyProperties(e, domain);
-            domain.setLimitType(e.getLimitType() == null ? "" : e.getLimitType().getName());
+            domain.setLimitType(e.getLimitType() == null ? "" : e.getLimitType().getTitle());
             Optional<ExamEntity> byId = examRepo.findById(examId);
             byId.ifPresent(examEntity -> domain.setExamName(examEntity.getName()));
             list.add(domain);
@@ -873,7 +873,7 @@ public class ExamServiceImpl implements ExamService {
     }
 
     @Override
-    public List<ExamIpLimitEntity> findAllIpLimits(Long examId, Integer limitType, String ip) {
+    public List<ExamIpLimitEntity> findAllIpLimits(Long examId, IpLimitType limitType, String ip) {
         Specification<ExamIpLimitEntity> spec = getSpec(examId, limitType, ip);
         long count = examIpLimitRepo.count(spec);
         if (100000 < count) {
@@ -1059,7 +1059,7 @@ public class ExamServiceImpl implements ExamService {
                 ? Boolean.valueOf(propertyEntity.getValue()) : defaultValue;
     }
 
-    private Specification<ExamIpLimitEntity> getSpec(Long examId, Integer limitType, String ip) {
+    private Specification<ExamIpLimitEntity> getSpec(Long examId, IpLimitType limitType, String ip) {
         Specification<ExamIpLimitEntity> spec = (root, query, cb) -> {
             List<Predicate> predicates = new ArrayList<>();
             if (examId != null) {