xiatian 11 månader sedan
förälder
incheckning
47a3db6db8

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

@@ -5,6 +5,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -121,4 +122,10 @@ public class OrgIpController extends ControllerSupport {
 		User user = getAccessUser();
 		orgIpService.examAdd(user.getRootOrgId(),examId);
 	}
+	
+	@ApiOperation(value = "获取ip")
+	@PostMapping("show")
+    public String getIp(HttpServletRequest request) {
+        return getIp(request);
+	}
 }

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

@@ -49,7 +49,7 @@ import cn.com.qmth.examcloud.web.jpa.PageUtils;
 
 @Service
 public class OrgIpServiceImpl implements OrgIpService {
-    private static final Logger log = LoggerFactory.getLogger(OrgIpService.class);
+	private static final Logger log = LoggerFactory.getLogger(OrgIpService.class);
 	private static final String[] EXCEL_HEADER = new String[] { "IP/IP段", "学习中心代码", "学习中心名称", "备注" };
 	@Autowired
 	private OrgIpRepo orgIpRepo;
@@ -175,21 +175,23 @@ public class OrgIpServiceImpl implements OrgIpService {
 		if (ss1.length != 4) {
 			throw new StatusException("ip格式错误");
 		}
-		for (String s : ss1) {
-			if (s.indexOf("-") != -1) {
-				String[] ss2 = ip.split("-");
-				if (ss2.length != 2) {
-					throw new StatusException("ip段格式错误");
-				}
-				for (String s2 : ss2) {
-					checkIpNumber(s2);
-				}
-				if (Integer.valueOf(ss2[0]) >= Integer.valueOf(ss2[1])) {
-					throw new StatusException("ip段格式错误,起始数值必须小于截止数值");
-				}
-			} else {
-				checkIpNumber(s);
+		for (int i = 0; i <= 2; i++) {
+			checkIpNumber(ss1[i]);
+		}
+		String s = ss1[3];
+		if (s.indexOf("-") != -1) {
+			String[] ss2 = ip.split("-");
+			if (ss2.length != 2) {
+				throw new StatusException("ip段格式错误");
+			}
+			for (String s2 : ss2) {
+				checkIpNumber(s2);
 			}
+			if (Integer.valueOf(ss2[0]) >= Integer.valueOf(ss2[1])) {
+				throw new StatusException("ip段格式错误,起始数值必须小于截止数值");
+			}
+		} else {
+			checkIpNumber(s);
 		}
 	}
 
@@ -210,9 +212,9 @@ public class OrgIpServiceImpl implements OrgIpService {
 		orgIpRepo.delete(ids, rootOrgId);
 	}
 
-    private String newError(int lineNum, String msg) {
-        return "第"+lineNum+"行 "+msg;
-    }
+	private String newError(int lineNum, String msg) {
+		return "第" + lineNum + "行 " + msg;
+	}
 
 	private String trimAndNullIfBlank(String s) {
 		if (StringUtils.isBlank(s)) {
@@ -328,13 +330,13 @@ public class OrgIpServiceImpl implements OrgIpService {
 			} catch (StatusException e) {
 				failRecords.add(newError(i + 1, e.getDesc()));
 			} catch (Exception e) {
-                failRecords.add(newError(i + 1, "系统异常"));
-                log.error("IP导入系统异常", e);
-            }
+				failRecords.add(newError(i + 1, "系统异常"));
+				log.error("IP导入系统异常", e);
+			}
+		}
+		if (CollectionUtils.isNotEmpty(failRecords)) {
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 		}
-        if (CollectionUtils.isNotEmpty(failRecords)) {
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-        }
 		return failRecords;
 	}
 
@@ -424,11 +426,11 @@ public class OrgIpServiceImpl implements OrgIpService {
 	@Override
 	public void examAdd(Long rootOrgId, Long examId) {
 		ExamEntity exam = GlobalHelper.getPresentEntity(examRepo, examId, ExamEntity.class);
-		if(!exam.getRootOrgId().equals(rootOrgId)) {
+		if (!exam.getRootOrgId().equals(rootOrgId)) {
 			throw new StatusException("参数错误,考试id非法");
 		}
-		List<OrgIpEntity> list=orgIpRepo.findByRootOrgId(rootOrgId);
-		if(CollectionUtils.isEmpty(list)) {
+		List<OrgIpEntity> list = orgIpRepo.findByRootOrgId(rootOrgId);
+		if (CollectionUtils.isEmpty(list)) {
 			return;
 		}
 		List<OrgIpInfo> ret = new ArrayList<>();