Explorar o código

类目、品牌、器件实时更新测试通过

sunyj %!s(int64=9) %!d(string=hai) anos
pai
achega
9663d47b23

+ 10 - 12
search-console/src/main/java/com/uas/search/console/dcn/DCNListener.java

@@ -44,7 +44,7 @@ public class DCNListener implements DatabaseChangeListener {
 
 	public DCNListener() {
 		indexService = ContextUtils.getBean(IndexService.class);
-		searchService = ContextUtils.getBean(SearchService.class);
+		searchService = ContextUtils.getApplicationContext().getBean("searchService", SearchService.class);
 		kindDao = ContextUtils.getBean(KindSimpleInfoDao.class);
 		brandDao = ContextUtils.getBean(BrandSimpleInfoDao.class);
 		componentDao = ContextUtils.getBean(ComponentSimpleInfoDao.class);
@@ -54,27 +54,24 @@ public class DCNListener implements DatabaseChangeListener {
 	public void onDatabaseChangeNotification(DatabaseChangeEvent event) {
 		logger.info(event);
 		QueryChangeDescription[] queryChangeDescriptions = event.getQueryChangeDescription();
-		logger.info("q " + queryChangeDescriptions.length);
 		for (QueryChangeDescription description : queryChangeDescriptions) {
 			TableChangeDescription[] tableChangeDescriptions = description.getTableChangeDescription();
-			logger.info("t " + tableChangeDescriptions.length);
 			for (TableChangeDescription tableChangeDescription : tableChangeDescriptions) {
 				String tableName = tableChangeDescription.getTableName();
 				logger.info(tableName);
 				RowChangeDescription[] rowChangeDescriptions = tableChangeDescription.getRowChangeDescription();
-				logger.info("r " + rowChangeDescriptions.length);
 				for (RowChangeDescription rowChangeDescription : rowChangeDescriptions) {
 					RowOperation rowOperation = rowChangeDescription.getRowOperation();
 					logger.info("rowOperation " + rowOperation);
 					ROWID rowid = rowChangeDescription.getRowid();
 					logger.info(rowid);
-					updateIndex(tableName, rowOperation, rowid.stringValue());
+					realTimeUpdateIndex(tableName, rowOperation, rowid.stringValue());
 				}
 			}
 		}
 	}
 
-	private void updateIndex(String tableName, RowOperation rowOperation, String rowid) {
+	private void realTimeUpdateIndex(String tableName, RowOperation rowOperation, String rowid) {
 		if (rowOperation.equals(RowOperation.DELETE)) {
 			indexService.delete(getObject(tableName, rowid));
 		} else if (rowOperation.equals(RowOperation.INSERT)) {
@@ -87,21 +84,22 @@ public class DCNListener implements DatabaseChangeListener {
 	}
 
 	private Object getObject(String tableName, String rowid) {
-		if (tableName.equals(SearchConstants.KIND_TABLE_NAME)) {
+		// tableName可能为 UUPLATFORMDEMO.PRODUCT$COMPONENT
+		if (tableName.contains(SearchConstants.KIND_TABLE_NAME.toUpperCase())) {
 			KindSimpleInfo kind = kindDao.findByRowid(rowid);
 			if (kind == null) {
 				kind = new KindSimpleInfo();
 				kind.setRowid(rowid);
 			}
 			return kind;
-		} else if (tableName.equals(SearchConstants.BRAND_TABLE_NAME)) {
+		} else if (tableName.contains(SearchConstants.BRAND_TABLE_NAME.toUpperCase())) {
 			BrandSimpleInfo brand = brandDao.findByRowid(rowid);
 			if (brand == null) {
 				brand = new BrandSimpleInfo();
 				brand.setRowid(rowid);
 			}
 			return brand;
-		} else if (tableName.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
+		} else if (tableName.contains(SearchConstants.COMPONENT_TABLE_NAME.toUpperCase())) {
 			ComponentSimpleInfo component = componentDao.findByRowid(rowid);
 			if (component == null) {
 				component = new ComponentSimpleInfo();
@@ -110,11 +108,11 @@ public class DCNListener implements DatabaseChangeListener {
 			return component;
 		}
 		// TODO 属性值实时更新还存在问题
-		else if (tableName.equals(SearchConstants.PROPERTYVALUE_TABLE_NAME)) {
+		else if (tableName.contains(SearchConstants.PROPERTYVALUE_TABLE_NAME.toUpperCase())) {
 			// 从本地获取component的rowid
 			String componentRowid = searchService.getComponentRowidByPropertyValueRowid(rowid);
 			if (StringUtils.isEmpty(componentRowid)) {
-				logger.error("未找到属性值rowid " + rowid + " 所对应的器件id");
+				logger.error("未找到属性值rowid: " + rowid + " 所对应的器件id");
 			}
 			ComponentSimpleInfo component = componentDao.findByRowid(componentRowid);
 			if (component == null) {
@@ -123,7 +121,7 @@ public class DCNListener implements DatabaseChangeListener {
 			}
 			return component;
 		} else {
-			logger.error("DCN error: tableName " + tableName + " rowid " + rowid);
+			logger.error("DCN error: tableName: " + tableName + " rowid: " + rowid);
 		}
 		return null;
 	}