From cdfa7cab510433d26a454a6bc2b35484ee27aace Mon Sep 17 00:00:00 2001 From: coral Date: Mon, 30 Oct 2023 14:24:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=E5=BD=93=E6=96=87=E7=AB=A0=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=96=B0=E5=A2=9E=E5=8F=8A=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E6=96=B0=E5=A2=9E=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=87=B3es.=202.=E6=96=87=E7=AB=A0=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=B8=8B=E7=BA=BF=E6=97=B6=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E4=B8=8B=E7=BA=BF=E8=8C=83=E5=9B=B4=E9=80=89=E6=8B=A9=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=95=B0=E6=8D=AE=E6=88=96=E5=88=A0=E9=99=A4es?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/service/ActWithoutProofService.java | 4 +- .../service/impl/ArticleServiceImpl.java | 74 ++++++++++ .../epmet/utils/ElasticsearchArticleDTO.java | 59 ++++++++ .../com/epmet/utils/ElasticsearchUtils.java | 129 ++++++++++++++++++ 4 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ElasticsearchArticleDTO.java create mode 100644 code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ElasticsearchUtils.java diff --git a/code/smart-community/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java b/code/smart-community/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java index 245331b5..d6d4fc66 100644 --- a/code/smart-community/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java +++ b/code/smart-community/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/ActWithoutProofService.java @@ -27,7 +27,6 @@ public interface ActWithoutProofService { /** * 根据居民身份证获取证明 * - * @param token * @param idCard 身份证号码 * @param certType 证件类型 001:身份证 002:统一信用代码证 * @param qrcode 营业执照必填 @@ -39,7 +38,6 @@ public interface ActWithoutProofService { /** * 重新开具证明 * - * @param token * @param idCard * @param zmtaskguid * @return @@ -53,5 +51,5 @@ public interface ActWithoutProofService { * @param refresh 是否刷新token(true刷新false不刷新) * @return */ - String getToken(Boolean refresh) throws IOException;; + String getToken(Boolean refresh) throws IOException; } diff --git a/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java b/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java index f6b7db3a..662bd99f 100644 --- a/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java +++ b/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java @@ -55,6 +55,8 @@ import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.redis.TagRedis; import com.epmet.service.*; +import com.epmet.utils.ElasticsearchArticleDTO; +import com.epmet.utils.ElasticsearchUtils; import com.epmet.utils.ModuleConstant; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -130,6 +132,8 @@ public class ArticleServiceImpl extends BaseServiceImpl NumConstant.ZERO ? StrConstant.COMMA_ZH : ""); publishRangeDesc.append(range.getAgencyGridName()); }); + //文章下线后范围为空,删除es中的文章 + try { + if (elasticsearchUtils.deleteArticle(Integer.parseInt(articleEntity.getId()))){ + //删除成功 + log.info("文章添加,更新es成功"); + }else{ + //删除失败 + log.info("文章添加,更新es失败"); + } + }catch (Exception e) { + log.error("scanAllPassPublishArticle delete es exception", e); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } + + + } else { publishedList.forEach(pub -> { publishRangeDesc.append(publishRangeDesc.length() > NumConstant.ZERO ? StrConstant.COMMA_ZH : ""); publishRangeDesc.append(pub.getAgencyGridName()); }); + //文章下线后范围不为空,更新es中的文章的范围 + try { + ArticleCoverEntity articleCoverEntity = articleCoverDao.selectByArticleId(formDTO.getArticleId()); + ArticleContentEntity articleContentEntity = articleContentDao.selectByArticleId(formDTO.getArticleId()); + ElasticsearchArticleDTO elasticsearchArticleDTO = ElasticsearchArticleDTO.builder().id(articleEntity.getId()).author(articleEntity.getPublisherName()) + .abstracts(articleEntity.getPreviewContent()).category("ARTICLE").title(articleEntity.getTitle()) + .content(articleContentEntity.getContent()).source(articleEntity.getPublisherName()).updateDate(String.valueOf(articleEntity.getUpdatedTime())) + .thumbnail(articleCoverEntity.getImgUrl()).uri("/aritcle/"+articleEntity.getId()).gridIdList(formDTO.getGridIdList()).build(); + if (elasticsearchUtils.addArticle(elasticsearchArticleDTO)){ + //删除成功 + log.info("文章添加,更新es成功"); + }else{ + //删除失败 + log.info("文章添加,更新es失败"); + } + } catch (Exception e) { + log.error("scanAllPassPublishArticle update es exception", e); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } + } entity.setPublishRangeDesc(publishRangeDesc.toString()); baseDao.updateById(entity); @@ -1613,6 +1653,23 @@ public class ArticleServiceImpl extends BaseServiceImpl gridIdList; + +} diff --git a/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ElasticsearchUtils.java b/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ElasticsearchUtils.java new file mode 100644 index 00000000..0580af99 --- /dev/null +++ b/code/smart-community/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ElasticsearchUtils.java @@ -0,0 +1,129 @@ +package com.epmet.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class ElasticsearchUtils { + private static final String ElasticsearchTestURL = "http://172.16.9.20:9000"; + private static final String ElasticsearchProdURL = "http://172.16.9.20:9000"; + private static final String ElasticsearchURL = ElasticsearchTestURL; + + private static final String ElasticsearchArticleDelete = "/SysElasticsearch/article/delete/"; + private static final String ElasticsearchArticleAdd = "/SysElasticsearch/article/add"; + private static final String ElasticsearchArticleUpdate = "/SysElasticsearch/article/update"; + + + @SneakyThrows + public Boolean addArticle(ElasticsearchArticleDTO bean) { + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(bean); + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json); + Request request = new Request.Builder() + .url(ElasticsearchURL+ElasticsearchArticleAdd) + .method("POST", body) + .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + .addHeader("Content-Type", "application/json") + .build(); + Response response = client.newCall(request).execute(); + ResponseBody responseBody = response.body(); + // 获取响应的状态码 + int statusCode = response.code(); + + if (response.isSuccessful()) { + // 请求成功,状态码为2xx + if (responseBody != null) { + // 处理响应内容 + String responseString = responseBody.string(); + log.info("接口请求成功,响应内容:" + responseString); + responseBody.close(); + return true; + } + } else { + // 请求失败,状态码不是2xx + log.info("接口请求失败,状态码:" + statusCode); + return false; + } + return false; + } + + @SneakyThrows + public Boolean updateArticle(ElasticsearchArticleDTO bean) { + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(bean); + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json); + Request request = new Request.Builder() + .url(ElasticsearchURL+ElasticsearchArticleUpdate) + .method("POST", body) + .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + .addHeader("Content-Type", "application/json") + .build(); + Response response = client.newCall(request).execute(); + ResponseBody responseBody = response.body(); + // 获取响应的状态码 + int statusCode = response.code(); + + if (response.isSuccessful()) { + // 请求成功,状态码为2xx + if (responseBody != null) { + // 处理响应内容 + String responseString = responseBody.string(); + log.info("接口请求成功,响应内容:" + responseString); + responseBody.close(); + return true; + } + } else { + // 请求失败,状态码不是2xx + log.info("接口请求失败,状态码:" + statusCode); + return false; + } + return false; + } + + @SneakyThrows + public Boolean deleteArticle(int id) { + + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("text/plain"); + RequestBody body = RequestBody.create(mediaType, ""); + Request request = new Request.Builder() + .url(ElasticsearchURL+ElasticsearchArticleDelete+id) + .method("DELETE", body) + .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + .build(); + Response response = client.newCall(request).execute(); + ResponseBody responseBody = response.body(); + // 获取响应的状态码 + int statusCode = response.code(); + + if (response.isSuccessful()) { + // 请求成功,状态码为2xx + if (responseBody != null) { + // 处理响应内容 + String responseString = responseBody.string(); + log.info("接口请求成功,响应内容:" + responseString); + responseBody.close(); + return true; + } + } else { + // 请求失败,状态码不是2xx + log.info("接口请求失败,状态码:" + statusCode); + return false; + } + return false; + } +}