| | |
| | | import org.springblade.es.vo.EsParam; |
| | | import org.springblade.modules.article.entity.Article; |
| | | import org.springblade.modules.article.service.ArticleService; |
| | | import org.springblade.modules.house.entity.HouseEntity; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.service.IHouseService; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | 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.service.IPlaceService; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Value("${elasticsearch.sync}") |
| | | private boolean elasticsearchSync; |
| | | |
| | | @Value("${elasticsearch.indexName}") |
| | | private String indexName; |
| | | |
| | | /** |
| | | * 检查索引是否已存在 |
| | |
| | | * @return |
| | | */ |
| | | public Object selectDocumentPage(IPage<Object> page, EsParam esParam) { |
| | | if (Strings.isBlank(esParam.getIndexName())){ |
| | | esParam.setIndexName(indexName); |
| | | } |
| | | // 判断索引是否存在 |
| | | if (isIndexExists(esParam.getIndexName())) { |
| | | // 全文搜索 |
| | |
| | | // .type(MultiMatchQueryBuilder.Type.BEST_FIELDS) |
| | | // ); |
| | | BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("content", esParam.getSearchKey())); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("name", esParam.getSearchKey())); |
| | | // boolQueryBuilder.should(QueryBuilders.matchQuery("content", esParam.getSearchKey())); |
| | | // boolQueryBuilder.should(QueryBuilders.matchQuery("name", esParam.getSearchKey())); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("title", esParam.getSearchKey())); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("location", esParam.getSearchKey())); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("phone", esParam.getSearchKey())); |
| | | boolQueryBuilder.should(QueryBuilders.matchQuery("idCard", esParam.getSearchKey())); |
| | | // boolQueryBuilder.should(QueryBuilders.matchQuery("location", esParam.getSearchKey())); |
| | | // boolQueryBuilder.should(QueryBuilders.matchQuery("phone", esParam.getSearchKey())); |
| | | // boolQueryBuilder.should(QueryBuilders.matchQuery("idCard", esParam.getSearchKey())); |
| | | String communityCode = SpringUtils.getRequestParam("communityCode"); |
| | | if (!Strings.isBlank(communityCode)) { |
| | | boolQueryBuilder.must(QueryBuilders.matchQuery("communityCode", communityCode)); |
| | |
| | | * 修改数据 |
| | | */ |
| | | @Async |
| | | public void update(EsParam esParam, T item) { |
| | | public void update(EsParam esParam, T item,List<String> columnList) { |
| | | if (elasticsearchSync) { |
| | | // 创建更新请求 |
| | | UpdateByQueryRequest updateRequest = new UpdateByQueryRequest(esParam.getIndexName()); |
| | |
| | | |
| | | Map<String, Object> data = new HashMap<String, Object>(); |
| | | data.put("tableName", esParam.getTableName()); |
| | | new CommonParamSet<>().setFieldValueByMap(item.getClass(), item, EsTableConstant.articleList, data); |
| | | |
| | | if (esParam.getTableName().equals("jczz_article")){ |
| | | setArticleMap((Article)item,data); |
| | | } |
| | | if (esParam.getTableName().equals("jczz_place")){ |
| | | setPlaceMap((PlaceEntity) item,data); |
| | | } |
| | | if (esParam.getTableName().equals("jczz_house")){ |
| | | setHouseMap((HouseEntity) item,data); |
| | | } |
| | | if (esParam.getTableName().equals("jczz_household")){ |
| | | setHousehouldMap((HouseholdEntity) item,data); |
| | | } |
| | | Map<String, Object> param = new HashMap<String, Object>(); |
| | | param.put("data", data); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置公告map |
| | | * @param item |
| | | * @param data |
| | | */ |
| | | private void setArticleMap(Article item, Map<String, Object> data) { |
| | | data.put("tableId",item.getId()); |
| | | data.put("title",item.getTitle()); |
| | | data.put("type",item.getType()); |
| | | data.put("content",item.getContent()); |
| | | data.put("articleType",item.getArticleType()); |
| | | data.put("communityCode",item.getArticleRange()); |
| | | } |
| | | /** |
| | | * 设置场所map |
| | | * @param item |
| | | * @param data |
| | | */ |
| | | private void setPlaceMap(PlaceEntity item, Map<String, Object> data) { |
| | | data.put("communityCode",placeService.getCommunityCode(item.getId())); |
| | | data.put("tableId",item.getId()); |
| | | data.put("title",item.getPlaceName()); |
| | | data.put("name",item.getPrincipal()); |
| | | data.put("phone",item.getPrincipalPhone()); |
| | | data.put("idCard",item.getPrincipalIdCard()); |
| | | data.put("content",item.getLocation()); |
| | | } |
| | | /** |
| | | * 设置房屋map |
| | | * @param item |
| | | * @param data |
| | | */ |
| | | private void setHouseMap(HouseEntity item, Map<String, Object> data) { |
| | | data.put("communityCode",houseService.getCommunityCode(item.getId())); |
| | | data.put("tableId",item.getId()); |
| | | data.put("title",item.getHouseName()); |
| | | } |
| | | /** |
| | | * 设置住户map |
| | | * @param item |
| | | * @param data |
| | | */ |
| | | private void setHousehouldMap(HouseholdEntity item, Map<String, Object> data) { |
| | | data.put("communityCode",householdService.getCommunityCode(item.getId())); |
| | | data.put("tableId",item.getId()); |
| | | data.put("title",item.getName()); |
| | | data.put("name",item.getName()); |
| | | data.put("phone",item.getPhoneNumber()); |
| | | data.put("idCard",item.getIdCard()); |
| | | data.put("content",item.getCurrentAddress()); |
| | | } |
| | | |
| | | /** |
| | | * 删除数据--根据条件 |
| | | */ |
| | | public boolean removeByQuery(EsParam esParam) { |