Просмотр исходного кода

【亿道外协厂EIS修改接口:接收SN序列号测试LOG数据调整WIFI,BT支持空和N/A,需要校验是否重复。排除空和N/A校验重复】

xiaost 1 неделя назад
Родитель
Сommit
038ed46d7e

+ 11 - 2
src/main/java/com/uas/eis/entity/SNBindInfoRequest.java

@@ -4,6 +4,7 @@ import org.hibernate.validator.constraints.NotBlank;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
 import javax.validation.constraints.Size;
 import java.util.List;
 
@@ -32,33 +33,41 @@ public class SNBindInfoRequest {
     public static class DetailDTO {
 
         @NotBlank(message = "si_sncode不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_sncode不能为N/A")
         private String si_sncode;
 
         @NotBlank(message = "si_prodcode不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_prodcode不能为N/A")
         private String si_prodcode;
 
         @NotBlank(message = "si_macode不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_macode不能为N/A")
         private String si_macode;
 
         @NotBlank(message = "si_cpu不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_cpu不能为N/A")
         private String si_cpu;
 
-        @NotBlank(message = "si_wifi不能为空")
+        //@NotBlank(message = "si_wifi不能为空")
         private String si_wifi;
 
-        @NotBlank(message = "si_bt不能为空")
+       // @NotBlank(message = "si_bt不能为空")
         private String si_bt;
 
         @NotBlank(message = "si_uuid不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_uuid不能为N/A")
         private String si_uuid;
 
         @NotBlank(message = "si_bios不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_bios不能为N/A")
         private String si_bios;
 
         @NotBlank(message = "si_os不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_os不能为N/A")
         private String si_os;
 
         @NotBlank(message = "si_ec不能为空")
+        @Pattern(regexp = "^(?!N/A$).+", message = "si_ec不能为N/A")
         private String si_ec;
 
         private String si_dp;

+ 66 - 5
src/main/java/com/uas/eis/serviceImpl/MESDataServiceImpl.java

@@ -706,7 +706,6 @@ public class MESDataServiceImpl implements MESDataService {
 		List<String> duplicates = detailList.stream()
 				.map(SNBindMaterialRequest.DetailDTO::getSm_fprodcode)
 				.filter(s -> !set.add(s))
-				.distinct()
 				.collect(Collectors.toList());
 		if (!duplicates.isEmpty()) {
 			return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
@@ -717,7 +716,6 @@ public class MESDataServiceImpl implements MESDataService {
 		duplicates = detailList.stream()
 				.map(SNBindMaterialRequest.DetailDTO::getSm_barcode)
 				.filter(s -> !set1.add(s))
-				.distinct()
 				.collect(Collectors.toList());
 		if (!duplicates.isEmpty()) {
 			return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
@@ -783,7 +781,6 @@ public class MESDataServiceImpl implements MESDataService {
 			//校验是否重复barcode 不重复则插入
 			List<String> barList = detailList.stream()
 					.map(SNBindMaterialRequest.DetailDTO::getSm_barcode)
-					.distinct()
 					.collect(Collectors.toList());
 			String checksql = "select wm_concat(sm_barcode) from SNBINDMATERIAL where sm_barcode IN (%s) and rownum<20";
 			String inClause = String.join(",", Collections.nCopies(barList.size(), "?"));
@@ -802,10 +799,44 @@ public class MESDataServiceImpl implements MESDataService {
 	@Transactional
 	public ApiResult<Map<Object, Object>> executeSNBindInfo(String accessKey, String requestId, SNBindInfoRequest reqData) {
 		List<SNBindInfoRequest.DetailDTO> detailList =  reqData.getData().getDetail();
-		// 1. sncode(去重,避免重复处理)
+
+		Set<String> set = new HashSet<>();
+		List<String> duplicates = detailList.stream()
+				.map(SNBindInfoRequest.DetailDTO::getSi_sncode)
+				.filter(s -> !set.add(s))
+				.collect(Collectors.toList());
+		if (!duplicates.isEmpty()) {
+			return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
+					"本次传参存在重复的si_sncode: " + String.join(", ", duplicates));
+		}
+
+		//绑定值si_bt等必须唯一不能重复 ,也不能与历史数据重复
+		Set<String> set1 = new HashSet<>();
+		duplicates = detailList.stream()
+				.map(SNBindInfoRequest.DetailDTO::getSi_bt)
+				.filter(s -> s != null && !s.isEmpty() && !"N/A".equals(s))  // 排除 null、空字符串、"N/A"
+				.filter(s -> !set1.add(s))
+				.collect(Collectors.toList());
+		if (!duplicates.isEmpty()) {
+			return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
+					"本次传参存在重复的si_bt: " + String.join(", ", duplicates));
+		}
+
+		//绑定值si_wifi等必须唯一不能重复 ,也不能与历史数据重复
+		Set<String> set2 = new HashSet<>();
+		duplicates = detailList.stream()
+				.map(SNBindInfoRequest.DetailDTO::getSi_wifi)
+				.filter(s -> s != null && !s.isEmpty() && !"N/A".equals(s))  // 排除 null、空字符串、"N/A"
+				.filter(s -> !set2.add(s))
+				.collect(Collectors.toList());
+		if (!duplicates.isEmpty()) {
+			return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
+					"本次传参存在重复的si_wifi: " + String.join(", ", duplicates));
+		}
+
+		// 1. sncode
 		List<String> sncodeList = detailList.stream()
 				.map(SNBindInfoRequest.DetailDTO::getSi_sncode)
-				.distinct()
 				.collect(Collectors.toList());
 		// 2. 批量查询已存在的记录(返回 sncode 和 si_id)
 		String selectSql = "SELECT si_id,si_sncode FROM SNBIND_INFO WHERE si_sncode IN (%s)";
@@ -830,6 +861,36 @@ public class MESDataServiceImpl implements MESDataService {
 			String fullDeleteSql = String.format(deleteSql, inClause);
 			baseDao.execute(fullDeleteSql, existSncodes.toArray());
 		}
+
+		List<String> wifiList = detailList.stream()
+				.map(SNBindInfoRequest.DetailDTO::getSi_wifi)
+				.filter(s -> s != null && !s.isEmpty() && !"N/A".equals(s))  // 排除 null、空字符串、"N/A"
+				.collect(Collectors.toList());
+		if(!wifiList.isEmpty()) {
+			String checksql = "select wm_concat(SI_WIFI) from SNBIND_INFO where SI_WIFI IN (%s) and rownum<20";
+			String inClause = String.join(",", Collections.nCopies(wifiList.size(), "?"));
+			checksql = String.format(checksql, inClause);
+			String barr = baseDao.getJdbcTemplate().queryForObject(checksql, String.class, wifiList.toArray());
+			if (null != barr) {
+				return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
+						"si_wifi与历史已有数据表重复: " + barr);
+			}
+		}
+		List<String> btList = detailList.stream()
+				.map(SNBindInfoRequest.DetailDTO::getSi_bt)
+				.filter(s -> s != null && !s.isEmpty() && !"N/A".equals(s))  // 排除 null、空字符串、"N/A"
+				.collect(Collectors.toList());
+		if(!btList.isEmpty()) {
+			String checksql = "select wm_concat(SI_BT) from SNBIND_INFO where SI_BT IN (%s) and rownum<20";
+			String inClause = String.join(",", Collections.nCopies(btList.size(), "?"));
+			checksql = String.format(checksql, inClause);
+			String barr = baseDao.getJdbcTemplate().queryForObject(checksql, String.class, btList.toArray());
+			if (null != barr) {
+				return ApiResponse.failRsp(ErrorMessage.BUSINESS_ILLEGAL.getCode(), requestId,
+						"si_wifi与历史已有数据表重复: " + barr);
+			}
+		}
+
 		// 5. 批量插入新数据
 		String insertSql = "INSERT INTO SNBIND_INFO (SI_ID,SI_SNCODE,SI_PRODCODE,SI_MACODE,SI_CPU,SI_WIFI,SI_BT," +
 				" SI_UUID,SI_BIOS,SI_OS,SI_EC,SI_DP,SI_INDATE) " +