From 8b7258c9427882bb1798f1502eaa35184c6e374e Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:29:18 +0800
Subject: [PATCH] 短信指定楼栋发送

---
 src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java |   92 ++++++++++++++++++++++++++++------------------
 1 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java b/src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java
index a23c31b..a8588b5 100644
--- a/src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java
+++ b/src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java
@@ -6,6 +6,8 @@
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.plugin.*;
 import org.apache.logging.log4j.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springblade.common.constant.EsTableConstant;
 import org.springblade.common.utils.SQLParseUtils;
 import org.springblade.es.service.ElasticsearchDocumentService;
@@ -13,24 +15,22 @@
 import org.springblade.modules.article.entity.Article;
 import org.springblade.modules.house.entity.HouseEntity;
 import org.springblade.modules.house.entity.HouseholdEntity;
-import org.springblade.modules.house.vo.HouseVO;
-import org.springblade.modules.house.vo.HouseholdVO;
 import org.springblade.modules.place.entity.PlaceEntity;
-import org.springblade.modules.place.vo.PlaceVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
-import java.util.Map;
 import java.util.Properties;
+
 @Component
 @Intercepts({
 	@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
 })
 public class DataSyncInterceptor implements Interceptor {
 
+	private static final Logger logger = LoggerFactory.getLogger(DataSyncInterceptor.class);
 	@Lazy
 	@Autowired
 	private ElasticsearchDocumentService elasticsearchDocumentService;
@@ -71,7 +71,7 @@
 					tableName.equals("jczz_house") ||
 					tableName.equals("jczz_household") ||
 					tableName.equals("jczz_place"))
-				syncDataAfterUpdate(tableName,sqlType,invocation.getArgs()[1]);
+					syncDataAfterUpdate(tableName, sqlType, invocation.getArgs()[1]);
 			}
 		}
 		return res;
@@ -80,54 +80,59 @@
 
 	/**
 	 * 数据同步
+	 *
 	 * @param tableName
 	 * @param sqlType
 	 * @param parameter
 	 */
-	private void syncDataAfterUpdate(String tableName,String sqlType,Object parameter) {
+	private void syncDataAfterUpdate(String tableName, String sqlType, Object parameter) {
 		EsParam esParam = new EsParam();
 		esParam.setIndexName(indexName);
 		esParam.setTableName(tableName);
 		// 判断操作类型
-		if (sqlType.equals("INSERT")){
+		if (sqlType.equals("INSERT")) {
 			//insert 可用直接拦截到实体类
 			if (tableName.equals("jczz_article")) {
 				Article entity = (Article) parameter;
-				elasticsearchDocumentService.addArticle(esParam,entity);
+				elasticsearchDocumentService.addArticle(esParam, entity);
 			}
 			if (tableName.equals("jczz_place")) {
-				PlaceVO entity = (PlaceVO) parameter;
-				elasticsearchDocumentService.addPlace(esParam,entity);
+				PlaceEntity entity = (PlaceEntity) parameter;
+				elasticsearchDocumentService.addPlace(esParam, entity);
 			}
 			if (tableName.equals("jczz_house")) {
-				HouseVO entity = (HouseVO) parameter;
-				elasticsearchDocumentService.addHouse(esParam,entity);
+				HouseEntity entity = (HouseEntity) parameter;
+				elasticsearchDocumentService.addHouse(esParam, entity);
 			}
 			if (tableName.equals("jczz_household")) {
-				HouseholdVO entity = (HouseholdVO) parameter;
-				elasticsearchDocumentService.addHousehold(esParam,entity);
+				HouseholdEntity entity = (HouseholdEntity) parameter;
+				elasticsearchDocumentService.addHousehold(esParam, entity);
 			}
 		}
-		if(sqlType.equals("UPDATE")){
+		if (sqlType.equals("UPDATE")) {
 			//update 方法需要特殊处理
 			if (tableName.equals("jczz_article")) {
-				Article entity = (Article) ((MapperMethod.ParamMap) parameter).get("param1");
-				if (null!=entity.getId()) {
-					esParam.setTableId(entity.getId().toString());
-					elasticsearchDocumentService.update(esParam, entity, EsTableConstant.articleList);
+				try {
+					Article entity = (Article) ((MapperMethod.ParamMap) parameter).get("param1");
+					if (entity != null && entity.getId() != null) {
+						esParam.setTableId(entity.getId().toString());
+						elasticsearchDocumentService.update(esParam, entity, EsTableConstant.articleList);
+					}
+				} catch (Exception e) {
+					logger.error("jczz_article 更新失败!", e);
 				}
 			}
 			if (tableName.equals("jczz_place")) {
 				PlaceEntity entity = new PlaceEntity();
 				PlaceEntity placeEntity = new PlaceEntity();
-				if (parameter instanceof MapperMethod.ParamMap){
+				if (parameter instanceof MapperMethod.ParamMap) {
 					placeEntity = (PlaceEntity) ((MapperMethod.ParamMap) parameter).get("param1");
-					if (null!=placeEntity.getId()) {
+					if (placeEntity != null && null != placeEntity.getId()) {
 						setPlaceInfo(entity, placeEntity);
 						esParam.setTableId(entity.getId().toString());
 						elasticsearchDocumentService.update(esParam, entity, EsTableConstant.placeList);
 					}
-				}else {
+				} else {
 					placeEntity = (PlaceEntity) parameter;
 					// 删除
 					esParam.setTableId(placeEntity.getId().toString());
@@ -137,14 +142,14 @@
 			if (tableName.equals("jczz_house")) {
 				HouseEntity houseEntity = new HouseEntity();
 				HouseEntity entity = new HouseEntity();
-				if (parameter instanceof MapperMethod.ParamMap){
+				if (parameter instanceof MapperMethod.ParamMap) {
 					entity = (HouseEntity) ((MapperMethod.ParamMap) parameter).get("param1");
-					if (null!=entity.getId()) {
+					if (entity != null && entity.getId() != null) {
 						setHouseInfo(houseEntity, entity);
 						esParam.setTableId(entity.getId().toString());
 						elasticsearchDocumentService.update(esParam, entity, EsTableConstant.houseList);
 					}
-				}else {
+				} else {
 					entity = (HouseEntity) parameter;
 					// 删除
 					esParam.setTableId(entity.getId().toString());
@@ -154,14 +159,23 @@
 			if (tableName.equals("jczz_household")) {
 				HouseholdEntity householdEntity = new HouseholdEntity();
 				HouseholdEntity entity = new HouseholdEntity();
-				if (parameter instanceof MapperMethod.ParamMap){
-					entity = (HouseholdEntity) ((MapperMethod.ParamMap) parameter).get("param1");
-					if (null!=entity.getId()) {
-						setHouseholdInfo(householdEntity, entity);
-						esParam.setTableId(entity.getId().toString());
-						elasticsearchDocumentService.update(esParam, entity, EsTableConstant.householdList);
+				if (parameter instanceof MapperMethod.ParamMap) {
+					try {
+						entity = (HouseholdEntity) ((MapperMethod.ParamMap) parameter).get("param1");
+						if (entity != null && entity.getId() != null) {
+							setHouseholdInfo(householdEntity, entity);
+							esParam.setTableId(entity.getId().toString());
+							elasticsearchDocumentService.update(esParam, entity, EsTableConstant.householdList);
+						}
+					} catch (Exception e) {
+						entity = (HouseholdEntity) ((MapperMethod.ParamMap) parameter).get("et");
+						if (entity != null && entity.getId() != null) {
+							setHouseholdInfo(householdEntity, entity);
+							esParam.setTableId(entity.getId().toString());
+							elasticsearchDocumentService.update(esParam, entity, EsTableConstant.householdList);
+						}
 					}
-				}else {
+				} else {
 					entity = (HouseholdEntity) parameter;
 					// 删除
 					esParam.setTableId(entity.getId().toString());
@@ -170,15 +184,18 @@
 			}
 		}
 		// 删除处理
-		if(sqlType.equals("DELETE")){
-			List<Long> list =(List<Long>) ((MapperMethod.ParamMap) parameter).get("param1");
-			esParam.setTableId(list.get(0).toString());
-			elasticsearchDocumentService.removeByQuery(esParam);
+		if (sqlType.equals("DELETE")) {
+			if (parameter instanceof MapperMethod.ParamMap) {
+				List<Long> list = (List<Long>) ((MapperMethod.ParamMap) parameter).get("param1");
+				esParam.setTableId(list.get(0).toString());
+				elasticsearchDocumentService.removeByQuery(esParam);
+			}
 		}
 	}
 
 	/**
 	 * 场所值复制
+	 *
 	 * @param entity
 	 * @param placeEntity
 	 */
@@ -190,8 +207,10 @@
 		entity.setPrincipalIdCard(placeEntity.getPrincipalIdCard());
 		entity.setLocation(placeEntity.getLocation());
 	}
+
 	/**
 	 * 房屋值复制
+	 *
 	 * @param entity
 	 * @param houseEntity
 	 */
@@ -202,6 +221,7 @@
 
 	/**
 	 * 住户值复制
+	 *
 	 * @param entity
 	 * @param householdEntity
 	 */

--
Gitblit v1.9.3