lin
2024-04-10 79f785f405e960b6d646100d592a398abb0fa625
判空处理
1 files modified
46 ■■■■■ changed files
src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/interceptor/DataSyncInterceptor.java
@@ -25,6 +25,7 @@
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})
@@ -71,7 +72,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,39 +81,40 @@
    /**
     * 数据同步
     *
     * @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);
                elasticsearchDocumentService.addPlace(esParam, entity);
            }
            if (tableName.equals("jczz_house")) {
                HouseVO entity = (HouseVO) parameter;
                elasticsearchDocumentService.addHouse(esParam,entity);
                elasticsearchDocumentService.addHouse(esParam, entity);
            }
            if (tableName.equals("jczz_household")) {
                HouseholdVO entity = (HouseholdVO) parameter;
                elasticsearchDocumentService.addHousehold(esParam,entity);
                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()) {
                if (entity != null && entity.getId() != null) {
                    esParam.setTableId(entity.getId().toString());
                    elasticsearchDocumentService.update(esParam, entity, EsTableConstant.articleList);
                }
@@ -120,14 +122,14 @@
            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 +139,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 +156,14 @@
            if (tableName.equals("jczz_household")) {
                HouseholdEntity householdEntity = new HouseholdEntity();
                HouseholdEntity entity = new HouseholdEntity();
                if (parameter instanceof MapperMethod.ParamMap){
                if (parameter instanceof MapperMethod.ParamMap) {
                    entity = (HouseholdEntity) ((MapperMethod.ParamMap) parameter).get("param1");
                    if (null!=entity.getId()) {
                    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,8 +172,8 @@
            }
        }
        // 删除处理
        if(sqlType.equals("DELETE")){
            List<Long> list =(List<Long>) ((MapperMethod.ParamMap) parameter).get("param1");
        if (sqlType.equals("DELETE")) {
            List<Long> list = (List<Long>) ((MapperMethod.ParamMap) parameter).get("param1");
            esParam.setTableId(list.get(0).toString());
            elasticsearchDocumentService.removeByQuery(esParam);
        }
@@ -179,6 +181,7 @@
    /**
     * 场所值复制
     *
     * @param entity
     * @param placeEntity
     */
@@ -190,8 +193,10 @@
        entity.setPrincipalIdCard(placeEntity.getPrincipalIdCard());
        entity.setLocation(placeEntity.getLocation());
    }
    /**
     * 房屋值复制
     *
     * @param entity
     * @param houseEntity
     */
@@ -202,6 +207,7 @@
    /**
     * 住户值复制
     *
     * @param entity
     * @param householdEntity
     */