소스 검색

考点ip登记

xiatian 11 달 전
부모
커밋
bb5e8cd6e4

+ 7 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/OrgIpController.java

@@ -114,4 +114,11 @@ public class OrgIpController extends ControllerSupport {
 		}
 		ExportUtils.exportEXCEL("考点IP登记", OrgIpInfo.class, ret, response);
 	}
+	
+	@ApiOperation(value = "同步到考试")
+	@PostMapping("exam/add")
+	public void examAdd(@RequestParam Long examId) {
+		User user = getAccessUser();
+		orgIpService.examAdd(user.getRootOrgId(),examId);
+	}
 }

+ 2 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamIpLimitRepo.java

@@ -28,4 +28,6 @@ public interface ExamIpLimitRepo extends JpaRepository<ExamIpLimitEntity, Long>,
 
 	int deleteAllByExamId(Long examId);
 
+	List<ExamIpLimitEntity> findByExamIdAndIp(Long examId, String ip);
+
 }

+ 2 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/OrgIpRepo.java

@@ -18,4 +18,6 @@ public interface OrgIpRepo extends JpaRepository<OrgIpEntity, Long>,
     @Modifying
     @Query(value = "delete from ec_e_org_ip  where id in ?1 and root_org_id = ?2 ",nativeQuery = true)
     int delete(List<Long> ids, Long rootOrgId);
+
+	List<OrgIpEntity> findByRootOrgId(Long rootOrgId);
 }

+ 8 - 5
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamService.java

@@ -1,5 +1,10 @@
 package cn.com.qmth.examcloud.core.examwork.service;
 
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import cn.com.qmth.examcloud.api.commons.enums.CURD;
 import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
@@ -10,11 +15,7 @@ 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;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import cn.com.qmth.examcloud.core.examwork.service.bean.orgip.OrgIpInfo;
 
 /**
  * 类注释
@@ -168,4 +169,6 @@ public interface ExamService {
      * @return void
      */
     void saveAllIpLimits(List<ExamIpLimitEntity> list);
+
+	void addIpLimitByOrgIp(Long examId,List<OrgIpInfo> ips);
 }

+ 2 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/OrgIpService.java

@@ -25,4 +25,6 @@ public interface OrgIpService {
 
 	List<OrgIpInfo> listForExport(OrgIpQuery req);
 
+	void examAdd(Long rootOrgId, Long examId);
+
 }

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

@@ -23,7 +23,6 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
@@ -67,6 +66,7 @@ import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
 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.bean.orgip.OrgIpInfo;
 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.support.CacheConstants;
@@ -1089,5 +1089,21 @@ 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);
+        	}
+        }
+    }
 
 }

+ 38 - 9
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/OrgIpServiceImpl.java

@@ -33,8 +33,11 @@ import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
 import cn.com.qmth.examcloud.core.basic.api.request.GetUserReq;
 import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 import cn.com.qmth.examcloud.core.basic.api.response.GetUserResp;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.OrgIpRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.OrgIpEntity;
+import cn.com.qmth.examcloud.core.examwork.service.ExamService;
 import cn.com.qmth.examcloud.core.examwork.service.OrgIpService;
 import cn.com.qmth.examcloud.core.examwork.service.bean.orgip.OrgIpInfo;
 import cn.com.qmth.examcloud.core.examwork.service.bean.orgip.OrgIpQuery;
@@ -50,12 +53,15 @@ public class OrgIpServiceImpl implements OrgIpService {
 	private static final String[] EXCEL_HEADER = new String[] { "IP/IP段", "学习中心代码", "学习中心名称", "备注" };
 	@Autowired
 	private OrgIpRepo orgIpRepo;
-
+	@Autowired
+	private ExamRepo examRepo;
 	@Autowired
 	private UserCloudService userCloudService;
 
 	@Autowired
 	private OrgCloudService orgCloudService;
+	@Autowired
+	private ExamService examService;
 
 	@Override
 	public PageInfo<OrgIpInfo> getPage(OrgIpQuery req) {
@@ -113,8 +119,8 @@ public class OrgIpServiceImpl implements OrgIpService {
 		}
 		checkIp(req.getIp());
 		req.setIp(req.getIp().trim());
-		if (req.getRemark() != null && req.getRemark().length() > 200) {
-			throw new StatusException("备注长度不能超过200");
+		if (req.getRemark() != null && req.getRemark().length() > 100) {
+			throw new StatusException("备注长度不能超过100");
 		}
 		checkIpExists(req);
 		OrgIpEntity e = new OrgIpEntity();
@@ -137,8 +143,8 @@ public class OrgIpServiceImpl implements OrgIpService {
 		}
 		checkIp(req.getIp());
 		req.setIp(req.getIp().trim());
-		if (req.getRemark() != null && req.getRemark().length() > 200) {
-			throw new StatusException("备注长度不能超过200");
+		if (req.getRemark() != null && req.getRemark().length() > 100) {
+			throw new StatusException("备注长度不能超过100");
 		}
 		checkIpExists(req);
 		OrgIpEntity e = GlobalHelper.getPresentEntity(orgIpRepo, req.getId(), OrgIpEntity.class);
@@ -297,8 +303,8 @@ public class OrgIpServiceImpl implements OrgIpService {
 			}
 
 			String remark = trimAndNullIfBlank(line[3]);
-			if (remark != null && remark.length() > 200) {
-				msg.append("  备注长度不能超过200");
+			if (remark != null && remark.length() > 100) {
+				msg.append("  备注长度不能超过100");
 				hasError = true;
 			}
 			info.setRemark(remark);
@@ -337,8 +343,8 @@ public class OrgIpServiceImpl implements OrgIpService {
 			throw new StatusException("学习中心不能为空");
 		}
 		req.setIp(req.getIp().trim());
-		if (req.getRemark() != null && req.getRemark().length() > 200) {
-			throw new StatusException("备注长度不能超过200");
+		if (req.getRemark() != null && req.getRemark().length() > 100) {
+			throw new StatusException("备注长度不能超过100");
 		}
 		try {
 			checkIpExists(req);
@@ -413,4 +419,27 @@ public class OrgIpServiceImpl implements OrgIpService {
 		}
 		return ret;
 	}
+
+	@Transactional
+	@Override
+	public void examAdd(Long rootOrgId, Long examId) {
+		ExamEntity exam = GlobalHelper.getPresentEntity(examRepo, examId, ExamEntity.class);
+		if(!exam.getRootOrgId().equals(rootOrgId)) {
+			throw new StatusException("参数错误,考试id非法");
+		}
+		List<OrgIpEntity> list=orgIpRepo.findByRootOrgId(rootOrgId);
+		if(CollectionUtils.isEmpty(list)) {
+			return;
+		}
+		List<OrgIpInfo> ret = new ArrayList<>();
+		for (OrgIpEntity e : list) {
+			OrgIpInfo info = new OrgIpInfo();
+			ret.add(info);
+			info.setId(e.getId());
+			info.setIp(e.getIp());
+			info.setOrgId(e.getOrgId());
+			info.setRemark(e.getRemark());
+		}
+		examService.addIpLimitByOrgIp(examId, ret);
+	}
 }