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

代采搜索判断是否为空

hejq 9 лет назад
Родитель
Сommit
2a5cd6e4b6

+ 38 - 28
search-console-b2b/src/main/java/com/uas/search/console/b2b/util/DocumentToObjectUtils.java

@@ -11,7 +11,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.uas.search.b2b.exception.SearchException;
 import com.uas.search.b2b.service.SearchService.Table_name;
 import com.uas.search.console.b2b.model.BrandSimpleInfo;
-import com.uas.search.console.b2b.model.DeputyOrderItemSimpleInfo;
 import com.uas.search.console.b2b.model.DeputyOrderSimpleInfo;
 import com.uas.search.console.b2b.model.EnterpriseSearchSimpleInfo;
 import com.uas.search.console.b2b.model.EnterpriseSimpleInfo;
@@ -172,40 +171,36 @@ public class DocumentToObjectUtils {
 			depOrder.setVenduseruu(Long.valueOf(document
 					.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.VENDUSERUU_FIELD))));
 		}
-		if (null != document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CODE_FIELD))) {
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CODE_FIELD)))) {
 			depOrder.setCode(
 					document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CODE_FIELD)));
 		}
-		if (null != document
-				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.COMPANYNAME_FIELD))) {
+		if (!StringUtils.isEmpty(document
+				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.COMPANYNAME_FIELD)))) {
 			depOrder.setCompanyname(document
 					.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.COMPANYNAME_FIELD)));
 		}
-		if (null != document
-				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CUSTOMER_FIELD))) {
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CUSTOMER_FIELD)))) {
 			depOrder.setCustomer(
 					document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.CUSTOMER_FIELD)));
 		}
-		if (null != document
-				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.LEGALREPRESENT_FIELD))) {
+		if (!StringUtils.isEmpty(document
+				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.LEGALREPRESENT_FIELD)))) {
 			depOrder.setLegalrepresent(document
 					.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.LEGALREPRESENT_FIELD)));
 		}
-		if (null != document
-				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.TERVENDOR_FIELD))) {
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.TERVENDOR_FIELD)))) {
 			depOrder.setTervendor(document
 					.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.TERVENDOR_FIELD)));
 		}
-		if (null != document
-				.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.VENDUSER_FIELD))) {
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.VENDUSER_FIELD)))) {
 			depOrder.setVenduser(
 					document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.VENDUSER_FIELD)));
 		}
-		if (null != document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.ITEMS_FIELD))) {
-			depOrder.setDeputyOrderItems(toSet(
-					document.get(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.ITEMS_FIELD)),
-					DeputyOrderItemSimpleInfo.class));
-		}
 		return depOrder;
 	}
 
@@ -215,17 +210,32 @@ public class DocumentToObjectUtils {
 		}
 		Table_name tableName = ClassAndTableNameUtils.toTableName(ProductComponentSimpleInfo.class);
 		ProductComponentSimpleInfo prodComp = new ProductComponentSimpleInfo();
-		prodComp.setId(Long.valueOf(
-				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.ID_FIELD))));
-		prodComp.setKindid(Long.valueOf(
-				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.KINDID_FIELD))));
-		prodComp.setCode(
-				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.CODE_FIELD)));
-		prodComp.setUuid(
-				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.UUID_FIELD)));
-		prodComp.setBrand(JSONObject.parseObject(
-				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.BRAND_FIELD)),
-				BrandSimpleInfo.class));
+		if (null != document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.ID_FIELD))) {
+			prodComp.setId(Long.valueOf(
+					document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.ID_FIELD))));
+		}
+		if (null != document
+				.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.KINDID_FIELD))) {
+			prodComp.setKindid(Long.valueOf(document
+					.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.KINDID_FIELD))));
+		}
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.CODE_FIELD)))) {
+			prodComp.setCode(document
+					.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.CODE_FIELD)));
+		}
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.UUID_FIELD)))) {
+			prodComp.setUuid(document
+					.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.UUID_FIELD)));
+		}
+		if (!StringUtils.isEmpty(
+				document.get(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.BRAND_FIELD)))) {
+			prodComp.setBrand(JSONObject.parseObject(
+					document.get(
+							ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.BRAND_FIELD)),
+					BrandSimpleInfo.class));
+		}
 		return prodComp;
 	}
 

+ 25 - 20
search-console-b2b/src/main/java/com/uas/search/console/b2b/util/ObjectToDocumentUtils.java

@@ -1537,21 +1537,31 @@ public class ObjectToDocumentUtils {
 		Document document = new Document();
 		// 不能用LongField,否则后续实时更新索引时,方法updateDocument(new Term("", ""),
 		// doc)无法根据id进行更新
-		document.add(
-				new StringField(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.ID_FIELD),
-						String.valueOf(prodComp.getId()), Store.YES));
-		document.add(
-				new StringField(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.UUID_FIELD),
-						String.valueOf(prodComp.getUuid()), Store.YES));
-		document.add(
-				new StringField(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.CODE_FIELD),
-						String.valueOf(prodComp.getCode()), Store.YES));
-		document.add(new StringField(
-				ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.BRAND_FIELD),
-						JSON.toJSONString(prodComp.getBrand()), Store.YES));
-		document.add(
-				new StringField(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.KINDID_FIELD),
-						String.valueOf(prodComp.getKindid()), Store.YES));
+		if (prodComp.getId() != null) {
+			document.add(
+					new StringField(ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.ID_FIELD),
+							String.valueOf(prodComp.getId()), Store.YES));
+		}
+		if (prodComp.getUuid() != null) {
+			document.add(new StringField(
+					ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.UUID_FIELD),
+					String.valueOf(prodComp.getUuid()), Store.YES));
+		}
+		if (prodComp.getCode() != null) {
+			document.add(new StringField(
+					ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.CODE_FIELD),
+					String.valueOf(prodComp.getCode()), Store.YES));
+		}
+		if (prodComp.getBrand() != null) {
+			document.add(new StringField(
+					ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.BRAND_FIELD),
+					JSON.toJSONString(prodComp.getBrand()), Store.YES));
+		}
+		if (prodComp.getKindid() != null) {
+			document.add(new StringField(
+					ClassAndTableNameUtils.combineField(tableName, ProductComponentSimpleInfo.KINDID_FIELD),
+					String.valueOf(prodComp.getKindid()), Store.YES));
+		}
 		return document;
 	}
 
@@ -1603,11 +1613,6 @@ public class ObjectToDocumentUtils {
 					new StringField(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.ENUU_FIELD),
 							String.valueOf(depOrder.getEnuu()), Store.YES));
 		}
-		if (null != depOrder.getDeputyOrderItems()) {
-			document.add(
-					new TextField(ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.ITEMS_FIELD),
-							String.valueOf(depOrder.getDeputyOrderItems()), Store.YES));
-		}
 		if (null != depOrder.getTervenduu()) {
 			document.add(new StringField(
 					ClassAndTableNameUtils.combineField(tableName, DeputyOrderSimpleInfo.TERVENDUU_FEILD),