wxz 5 years ago
parent
commit
49d7ba83ec
  1. 6
      epmet-commons/epmet-commons-tools/pom.xml
  2. 21
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java
  3. 24
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/ImgScanParamDTO.java
  4. 28
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/ImgTaskDTO.java
  5. 24
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/TextScanParamDTO.java
  6. 28
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/TextTaskDTO.java
  7. 42
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/SyncScanResult.java
  8. 172
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java
  9. 58
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java
  10. 53
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java
  11. 26
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagUseCountsFormDTO.java
  12. 2
      epmet-module/gov-org/gov-org-server/deploy/docker-compose-dev.yml
  13. 2
      epmet-module/gov-org/gov-org-server/pom.xml
  14. 60
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/AddArticleTagsFormDTO.java
  15. 66
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/UpdateGridTagsFormDTO.java
  16. 9
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/GovArticleDetailResultDTO.java
  17. 7
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/PublishedListResultDTO.java
  18. 26
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateCustomerTagCacheDTO.java
  19. 27
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateGridTagCacheDTO.java
  20. 25
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java
  21. 2
      epmet-module/gov-voice/gov-voice-server/Dockerfile
  22. 2
      epmet-module/gov-voice/gov-voice-server/deploy/docker-compose-dev.yml
  23. 15
      epmet-module/gov-voice/gov-voice-server/pom.xml
  24. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/ArticleConstant.java
  25. 6
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java
  26. 71
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  27. 18
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleDao.java
  28. 8
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticlePublishRangeDao.java
  29. 11
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleTagsDao.java
  30. 12
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/DraftContentDao.java
  31. 15
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/DraftCoverDao.java
  32. 11
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java
  33. 11
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagGridDao.java
  34. 52
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  35. 90
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java
  36. 8
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagCustomerService.java
  37. 423
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  38. 9
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/DraftServiceImpl.java
  39. 18
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java
  40. 2
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java
  41. 20
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ModuleConstant.java
  42. 8
      epmet-module/gov-voice/gov-voice-server/src/main/resources/bootstrap.yml
  43. 46
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleDao.xml
  44. 14
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticlePublishRangeDao.xml
  45. 9
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleTagsDao.xml
  46. 17
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/DraftContentDao.xml
  47. 10
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/DraftCoverDao.xml
  48. 20
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml
  49. 14
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagGridDao.xml
  50. 2
      epmet-module/resi-voice/resi-voice-server/Dockerfile
  51. 2
      epmet-module/resi-voice/resi-voice-server/deploy/docker-compose-dev.yml
  52. 4
      epmet-module/resi-voice/resi-voice-server/pom.xml
  53. 11
      epmet-openapi/epmet-openapi-scan/Dockerfile
  54. 4
      epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml
  55. 2
      epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml
  56. 2
      epmet-openapi/epmet-openapi-scan/pom.xml
  57. 15
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java
  58. 1
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java
  59. 48
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java
  60. 45
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java
  61. 46
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java
  62. 17
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/AuthException.java
  63. 23
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java
  64. 171
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java
  65. 68
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java
  66. 55
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java
  67. 152
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/RSASignature.java
  68. 52
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/FastJsonConfiguration.java
  69. 56
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java
  70. 113
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiInterceptor.java
  71. 37
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java
  72. 311
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java
  73. 11
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java
  74. 5
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java
  75. 44
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java
  76. 28
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java
  77. 31
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java
  78. 18
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java
  79. 24
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java
  80. 26
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java
  81. 41
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java
  82. 41
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java
  83. 8
      epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml

6
epmet-commons/epmet-commons-tools/pom.xml

@ -123,6 +123,12 @@
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
<build>

21
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java

@ -9,18 +9,15 @@
package com.epmet.commons.tools.redis;
import com.epmet.commons.tools.constant.NumConstant;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -307,4 +304,16 @@ public class RedisUtils {
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisTemplate.opsForZSet().reverseRangeWithScores(key, start, end);
return typedTuples;
}
/**
* @Description 标签使用数量缓存更新
* @param key
* @param value
* @param delta
* @author zxc
*/
public Double zIncrementScore(String key, Object value, double delta) {
return redisTemplate.opsForZSet().incrementScore(key, value, delta);
}
}

24
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/ImgScanParamDTO.java

@ -0,0 +1,24 @@
package com.epmet.commons.tools.scan.param;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 审查参数
*
* @author jianjun liu
* @date 2020-06-04 21:57
**/
@Data
public class ImgScanParamDTO implements Serializable {
private static final long serialVersionUID = -5982388188212400644L;
/**
* 要检测的内容列表必填
* remark一组任务列表中的taskId不能相同
*/
private List<ImgTaskDTO> tasks;
}

28
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/ImgTaskDTO.java

@ -0,0 +1,28 @@
package com.epmet.commons.tools.scan.param;
import lombok.Data;
import java.io.Serializable;
/**
* 任务参数
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-04 22:13
**/
@Data
public class ImgTaskDTO implements Serializable {
private static final long serialVersionUID = -747206284930578105L;
/**
* 要检测的数据id 非必填
*
* */
private String dataId;
/**
* 图片url 必填
*/
private String url;
}

24
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/TextScanParamDTO.java

@ -0,0 +1,24 @@
package com.epmet.commons.tools.scan.param;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 文本审查参数
*
* @author jianjun liu
* @date 2020-06-05 11:17
**/
@Data
public class TextScanParamDTO implements Serializable {
private static final long serialVersionUID = -6244354240835340471L;
/**
* 要检测的内容列表必填
* remark一组任务列表中的taskId不能相同
*/
private List<TextTaskDTO> tasks;
}

28
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/TextTaskDTO.java

@ -0,0 +1,28 @@
package com.epmet.commons.tools.scan.param;
import lombok.Data;
import java.io.Serializable;
/**
* 任务参数
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-04 22:13
**/
@Data
public class TextTaskDTO implements Serializable {
private static final long serialVersionUID = 6957195274696018630L;
/**
* 要检测的数据id 非必填
*
* */
private String dataId;
/**
* 文本内容 必填 最多不能超过10000
*/
private String content;
}

42
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/SyncScanResult.java

@ -0,0 +1,42 @@
package com.epmet.commons.tools.scan.result;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 检测结果
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:52
**/
@Data
public class SyncScanResult implements Serializable {
/**
* 执行成功的任务Id集合
*/
private List<String> successDataIds = new ArrayList<>();
/**
* 执行失败的任务Id集合
*/
private List<String> failDataIds = new ArrayList<>();
/**
* 本地是否全部通过
*/
private boolean isAllPass;
public boolean isAllPass() {
if (failDataIds.isEmpty() && !successDataIds.isEmpty()) {
return true;
}
return isAllPass;
}
public void setAllPass(boolean allPass) {
isAllPass = allPass;
}
}

172
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java

@ -0,0 +1,172 @@
package com.epmet.commons.tools.utils;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* desc: http 工具类
* date: 2020/6/4 22:27
*
* @author: jianjun liu
*/
@Slf4j
public class HttpClientManager {
private static int connectionTimeout = 3000;// 连接超时时间,毫秒
private static int soTimeout = 10000;// 读取数据超时时间,毫秒
/**
* HttpClient对象
*/
private static CloseableHttpClient httpclient = HttpClients.custom().disableAutomaticRetries().build();
/*** 超时设置 ****/
private static RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(soTimeout)
.setConnectTimeout(connectionTimeout)
.build();//设置请求和传输超时时间
public static HttpClientManager getInstance() {
return SingleClass.instance;
}
private static class SingleClass {
private final static HttpClientManager instance = new HttpClientManager();
}
/**
* desc: 发送json post 请求
* param: url,jsonStrParam
* return: CallResult<String>
* date: 2019/2/21 9:12
*
* @author: jianjun liu
*/
public Result<String> sendPost(String url, Map<String, String> paramsMap) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded charset=utf-8");
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : paramsMap.keySet()) {
list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key))));
}
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8");
httppost.setEntity(urlEncodedFormEntity);
return execute(httppost);
} catch (Exception e) {
e.printStackTrace();
log.error("send exception", e);
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
/**
* desc: 发送json post 请求
* param: url,jsonStrParam
* return: Result<String>
* date: 2019/2/21 9:12
*
* @author: jianjun liu
*/
public Result<String> sendPostByJSON(String url, String jsonStrParam) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
if (StringUtils.isNotEmpty(jsonStrParam)) {
StringEntity se = new StringEntity(jsonStrParam, "utf-8");
httppost.setEntity(se);
}
return execute(httppost);
} catch (Exception e) {
log.error("send exception", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
/**
* desc: 发送get请求
* param:url, params
* return: CallResult<String>
* date: 2019/2/21 9:16
*
* @author: jianjun liu
*/
public Result<String> sendGet(String url, Map<String, Object> params) {
try {
URIBuilder builder = new URIBuilder(url);
if (!CollectionUtils.isEmpty(params)) {
Set<String> set = params.keySet();
for (String key : set) {
builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key)));
}
}
HttpGet httpGet = new HttpGet(builder.build());
httpGet.setConfig(requestConfig);
return execute(httpGet);
} catch (Exception e) {
log.error("sendGet exception", e);
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
private Result<String> execute(HttpRequestBase httpMethod) {
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpMethod);
log.debug("http send response:{}", JSON.toJSONString(response));
if (response != null && response.getStatusLine() != null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String result = EntityUtils.toString(response.getEntity());
return new Result<String>().ok(result);
} else {
log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode());
}
}
} catch (Exception e) {
log.error("execute exception", e);
new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
} finally {
httpMethod.releaseConnection();
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
}
}
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}

58
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java

@ -0,0 +1,58 @@
package com.epmet.commons.tools.utils;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.scan.param.ImgScanParamDTO;
import com.epmet.commons.tools.scan.param.TextScanParamDTO;
import com.epmet.commons.tools.scan.result.SyncScanResult;
import org.apache.commons.lang3.StringUtils;
/**
* 扫描内容工具类
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-08 8:28
**/
public class ScanContentUtils {
/**
* desc:图片同步扫描
*
* @return
*/
public static SyncScanResult imgSyncScan(String url, ImgScanParamDTO param) {
if (StringUtils.isBlank(url) || param == null) {
throw new RenException("参数错误");
}
try {
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(param));
if (result.success()) {
return JSON.parseObject(result.getData(), SyncScanResult.class);
}
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), result.getMsg());
} catch (Exception e) {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage());
}
}
/**
* desc:文字同步扫描
*
* @return
*/
public static SyncScanResult textSyncScan(String url, TextScanParamDTO param) {
if (StringUtils.isBlank(url) || param == null) {
throw new RenException("参数错误");
}
try {
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(param));
if (result.success()) {
return JSON.parseObject(result.getData(), SyncScanResult.class);
}
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), result.getMsg());
} catch (Exception e) {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage());
}
}
}

53
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java

@ -0,0 +1,53 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/6/4 15:12
*/
@Data
public class UpdateTagFormDTO implements Serializable {
private static final long serialVersionUID = 1686362744399106982L;
private String id;
/**
* 客户ID
*/
private String customerId;
/**
* 标签名称
*/
private String tagName;
/**
* 使用计数
*/
private Integer useCount = 1;
/**
* 删除标识 0.未删除 1.已删除
*/
private Integer delFlag = 0;
/**
* 乐观锁
*/
private Integer revision = 0;
/**
* 创建人
*/
private String createdBy;
/**
* 更新人
*/
private String updatedBy;
}

26
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagUseCountsFormDTO.java

@ -0,0 +1,26 @@
package com.epmet.dto.form;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/6/4 15:12
*/
@Data
public class UpdateTagUseCountsFormDTO implements Serializable {
private static final long serialVersionUID = 1686362744399106982L;
/**
* 标签id
*/
private String tagId;
/**
* 标签名称
*/
private String tagName;
}

2
epmet-module/gov-org/gov-org-server/deploy/docker-compose-dev.yml

@ -2,7 +2,7 @@ version: "3.7"
services:
gov-org-server:
container_name: gov-org-server-dev
image: 192.168.1.130:10080/epmet-cloud-dev/gov-org-server:0.3.61
image: 192.168.1.130:10080/epmet-cloud-dev/gov-org-server:0.3.62
ports:
- "8092:8092"
network_mode: host # 使用现有网络

2
epmet-module/gov-org/gov-org-server/pom.xml

@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.3.61</version>
<version>0.3.62</version>
<parent>
<groupId>com.epmet</groupId>
<artifactId>gov-org</artifactId>

60
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/AddArticleTagsFormDTO.java

@ -0,0 +1,60 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/6/5 17:36
*/
@Data
public class AddArticleTagsFormDTO implements Serializable {
private static final long serialVersionUID = -6009661699565102279L;
/**
* 主键ID
*/
private String id;
/**
* 客户ID
*/
private String customerId;
/**
* 文章ID
*/
private String articleId;
/**
* 标签ID
*/
private String tagId;
/**
* 标签名称
*/
private String tagName;
/**
* 删除标识 0.未删除 1.已删除
*/
private Integer delFlag = 0;
/**
* 乐观锁
*/
private Integer revision = 0;
/**
* 创建人
*/
private String createdBy;
/**
* 更新人
*/
private String updatedBy;
}

66
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/UpdateGridTagsFormDTO.java

@ -0,0 +1,66 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/6/5 10:20
*/
@Data
public class UpdateGridTagsFormDTO implements Serializable {
private static final long serialVersionUID = 2876626163349728237L;
/**
* 主键ID
*/
private String id;
/**
* 客户ID
*/
private String customerId;
/**
* 网格ID
*/
private String gridId;
/**
* 标签ID
*/
private String tagId;
/**
* 标签名称
*/
private String tagName;
/**
* 使用计数
*/
private Integer useCount = 1;
/**
* 删除标识 0.未删除 1.已删除
*/
private Integer delFlag = 0;
/**
* 乐观锁
*/
private Integer revision = 0;
/**
* 创建人
*/
private String createdBy;
/**
* 更新人
*/
private String updatedBy;
}

9
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/GovArticleDetailResultDTO.java

@ -1,6 +1,7 @@
package com.epmet.dto.result;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
@ -48,10 +49,16 @@ public class GovArticleDetailResultDTO implements Serializable {
private String publishRangeDesc;
/**
* 标签字符串
* 标签字符串-已废弃不会返给前端
*/
@JsonIgnore
private String tags;
/**
* 文章关联标签集合
*/
private String[] tagNameList;
/**
* 发布状态 已发布:published已下线offline
*/

7
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/PublishedListResultDTO.java

@ -1,9 +1,11 @@
package com.epmet.dto.result;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @author zhaoqifeng
@ -34,7 +36,12 @@ public class PublishedListResultDTO implements Serializable {
/**
* 文章标签串
*/
@JsonIgnore
private String tags;
/**
* 文章标签列表
*/
private List<String> tagNameList;
/**
* 概要内容
*/

26
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateCustomerTagCacheDTO.java

@ -0,0 +1,26 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author zxc
* @CreateTime 2020/6/5 9:54
*/
@Data
public class UpdateCustomerTagCacheDTO implements Serializable {
private static final long serialVersionUID = -5544311005334312224L;
/**
* 客户id
*/
private String customerId;
/**
* 标签信息集合
*/
private List<UpdateTagUseCountsResultDTO> tagsInfo;
}

27
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateGridTagCacheDTO.java

@ -0,0 +1,27 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author zxc
* @CreateTime 2020/6/5 10:49
*/
@Data
public class UpdateGridTagCacheDTO implements Serializable {
private static final long serialVersionUID = 367220409651119904L;
/**
* 网格id
*/
private String gridId;
/**
* 标签集合
* tagIdtagName
*/
private List<UpdateTagUseCountsResultDTO> tagsInfo;
}

25
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java

@ -0,0 +1,25 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/6/4 17:20
*/
@Data
public class UpdateTagUseCountsResultDTO implements Serializable {
private static final long serialVersionUID = -6331586672885417576L;
/**
* 标签id
*/
private String tagId;
/**
* 标签名称
*/
private String tagName;
}

2
epmet-module/gov-voice/gov-voice-server/Dockerfile

@ -6,6 +6,6 @@ RUN echo 'Asia/Shanghai' > /etc/timezone
COPY ./target/*.jar ./app.jar
EXPOSE 8102
EXPOSE 8105
ENTRYPOINT ["sh", "-c", "$RUN_INSTRUCT"]

2
epmet-module/gov-voice/gov-voice-server/deploy/docker-compose-dev.yml

@ -2,7 +2,7 @@ version: "3.7"
services:
gov-voice-server:
container_name: gov-voice-server-dev
image: 192.168.1.130:10080/epmet-cloud-dev/gov-voice-server:0.3.3
image: 192.168.1.130:10080/epmet-cloud-dev/gov-voice-server:0.3.7
ports:
- "8105:8105"
network_mode: host # 使用现有网络

15
epmet-module/gov-voice/gov-voice-server/pom.xml

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.3.3</version>
<version>0.3.7</version>
<parent>
<artifactId>gov-voice</artifactId>
<groupId>com.epmet</groupId>
@ -34,6 +34,11 @@
<artifactId>epmet-commons-tools</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-message-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-mybatis</artifactId>
@ -71,12 +76,6 @@
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-user-client</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@ -143,7 +142,7 @@
<activeByDefault>true</activeByDefault>
</activation>-->
<properties>
<server.port>8104</server.port>
<server.port>8105</server.port>
<spring.profiles.active>test</spring.profiles.active>
<!-- 数据库配置-->

5
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/ArticleConstant.java

@ -39,4 +39,9 @@ public interface ArticleConstant {
* 下线文章操作记录表文案
*/
String OFF_LINE_ARTICLE_MSG = "%s-%s下线文章【%s】";
/**
* 发布文章操作记录表文案
*/
String PUBLISH_ARTICLE_MSG = "%s-%s发布文章【%s】";
}

6
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java

@ -40,6 +40,12 @@ public interface TagConstant {
*/
String COLON = ":";
String BEGIN_UPDATE = "开始更新标签缓存... ...";
String SUCCESS_UPDATE = "更新标签缓存成功... ...";
String FAILURE_UPDATE = "更新标签缓存失败... ...";
String SELECT_GRIDIDLIST_FAILURE = "查询gridId集合数量为0";
}

71
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java

@ -21,27 +21,21 @@ import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.annotation.RequirePermission;
import com.epmet.commons.tools.enums.RequirePermissionEnum;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.scan.result.SyncScanResult;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.ArticleDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.excel.ArticleExcel;
import com.epmet.service.ArticleOperateRecordService;
import com.epmet.service.ArticleService;
import com.epmet.service.DraftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
@ -61,48 +55,6 @@ public class ArticleController {
@Autowired
private DraftService draftService;
@GetMapping("page")
public Result<PageData<ArticleDTO>> page(@RequestParam Map<String, Object> params){
PageData<ArticleDTO> page = articleService.page(params);
return new Result<PageData<ArticleDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<ArticleDTO> get(@PathVariable("id") String id){
ArticleDTO data = articleService.get(id);
return new Result<ArticleDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody ArticleDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
articleService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody ArticleDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
articleService.update(dto);
return new Result();
}
@DeleteMapping
public Result delete(@RequestBody String[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
articleService.delete(ids);
return new Result();
}
@GetMapping("export")
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<ArticleDTO> list = articleService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, ArticleExcel.class);
}
/**
* @param tokenDTO
* @return
@ -222,9 +174,6 @@ public class ArticleController {
public Result<Boolean> saveDraftAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception {
ValidatorUtils.validateEntity(fromDTO, DefaultGroup.class);
Boolean isSuccess = articleService.saveDraftAttr(tokenDto, fromDTO);
if (isSuccess){
//TODO 异步校验内容
}
return new Result<Boolean>().ok(isSuccess);
}
@ -250,9 +199,24 @@ public class ArticleController {
@RequirePermission(requirePermission = RequirePermissionEnum.WORK_PARTY_VOICE_PUBLISH)
public Result<Boolean> publishArticle(@LoginUser TokenDto tokenDto, String draftId) throws Exception {
Boolean isSuccess = articleService.publish(tokenDto, draftId);
if (isSuccess){
//TODO 异步校验内容
scanContent(tokenDto,draftId);
}
return new Result<Boolean>().ok(isSuccess);
}
@Async
public void scanContent(TokenDto tokenDto,String draftId){
SyncScanResult syncScanResult = articleService.scanContent(tokenDto,draftId);
if (syncScanResult.isAllPass()){
articleService.scanAllPassPublishArticle(tokenDto,draftId);
}else{
articleService.updateAuditStatusFailById(draftId,syncScanResult);
}
}
/**
* 已发布文章列表
@ -363,4 +327,5 @@ public class ArticleController {
DraftDetailResultDTO draftDetailResultDTO = draftService.queryDraftDetail(formDTO);
return new Result<DraftDetailResultDTO>().ok(draftDetailResultDTO);
}
}

18
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleDao.java

@ -68,21 +68,24 @@ public interface ArticleDao extends BaseDao<ArticleEntity> {
* @author zhaoqifeng
* @date 2020/6/2 16:59
* @param customerId
* @param tagIdList
* @return java.util.List<com.epmet.dto.result.PublishedListResultDTO>
*/
@DataFilter(tableAliases = "a")
List<PublishedListResultDTO> selectArticleListForAgency(@Param("customerId") String customerId);
//@DataFilter(tableAliases = "a")
List<PublishedListResultDTO> selectArticleListForAgency(@Param("customerId") String customerId, @Param("tagIdList") List<String> tagIdList);
/**
* 已发布列表---网格工作人员
* @author zhaoqifeng
* @date 2020/6/2 16:59
* @date 2020/6/5 16:35
* @param customerId
* @param tagIdList
* @param gridList
* @return java.util.List<com.epmet.dto.result.PublishedListResultDTO>
*/
@DataFilter(tableAliases = {"a", "apr"}, gridIdArgName = "gridList")
List<PublishedListResultDTO> selectArticleListForGrid(@Param("customerId") String customerId, Set<String> gridList);
List<PublishedListResultDTO> selectArticleListForGrid(@Param("customerId") String customerId,
@Param("tagIdList") List<String> tagIdList, Set<String> gridList);
/**
* 已下线文章列表
@ -134,4 +137,11 @@ public interface ArticleDao extends BaseDao<ArticleEntity> {
* @date 2020.06.03 18:28
**/
ArticleDetailResultDTO selectArticleDetail(@Param("gridId")String gridId,@Param("articleId")String articleId);
/**
* @Description 根据draftId获取文章id
* @param draftId
* @author zxc
*/
String getArticleIdByDraftId(@Param("draftId")String draftId);
}

8
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticlePublishRangeDao.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.ArticlePublishRangeDTO;
import com.epmet.entity.ArticlePublishRangeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -40,4 +41,11 @@ public interface ArticlePublishRangeDao extends BaseDao<ArticlePublishRangeEntit
* @Description 根据文章Id查询发布范围数据
**/
List<ArticlePublishRangeEntity> selectByArticleId(ArticlePublishRangeEntity rangeEntity);
/**
* @Description 根据草稿id查询发布范围id集合
* @param draftId
* @author zxc
*/
List<String> selectGridIdByDraftId(@Param("draftId")String draftId);
}

11
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleTagsDao.java

@ -18,8 +18,12 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.AddArticleTagsFormDTO;
import com.epmet.entity.ArticleTagsEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 文章标签表
@ -29,5 +33,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ArticleTagsDao extends BaseDao<ArticleTagsEntity> {
/**
* @Description 插入文章标签
* @param addArticleTags
* @author zxc
*/
void addArticleTags(@Param("addArticleTags")List<AddArticleTagsFormDTO> addArticleTags);
}

12
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/DraftContentDao.java

@ -18,7 +18,6 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.DraftContentDTO;
import com.epmet.entity.DraftContentEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -42,5 +41,14 @@ public interface DraftContentDao extends BaseDao<DraftContentEntity> {
* @author wangc
* @date 2020.06.05 10:28
**/
List<DraftContentDTO> selectByDraftId(@Param("draftId")String draftId,@Param("auditStatus")String auditStatus);
List<DraftContentEntity> selectByDraftId(@Param("draftId")String draftId,@Param("auditStatus")String auditStatus);
/**
* desc:查询需要审核的内容
* @param draftId
* @return
*/
List<DraftContentEntity> selectScanContentByDraftId(String draftId);
int updateAuditStatusById(@Param("id")String id, @Param("auditStatus")String auditStatus);
}

15
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/DraftCoverDao.java

@ -23,8 +23,6 @@ import com.epmet.entity.DraftCoverEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 草稿封面表
*
@ -42,5 +40,16 @@ public interface DraftCoverDao extends BaseDao<DraftCoverEntity> {
* @author wangc
* @date 2020.06.05 10:28
**/
DraftCoverDTO selectByDraftId(@Param("draftId")String draftId,@Param("auditStatus")String auditStatus);
DraftCoverEntity selectByDraftId(@Param("draftId")String draftId,@Param("auditStatus")String auditStatus);
/**
* @Description 通过草稿Id 获取未删除的草稿封面id及地址
* @param draftId
* @return DraftCoverDTO
* @author wangc
* @date 2020.06.05 10:28
**/
DraftCoverDTO selectCoverIdAndUrlByDraftId(@Param("draftId")String draftId);
int updateAuditStatusById(@Param("id")String id, @Param("auditStatus")String auditStatus);
}

11
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java

@ -18,8 +18,10 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.UpdateTagFormDTO;
import com.epmet.entity.TagCustomerEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 客户标签表
@ -29,5 +31,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface TagCustomerDao extends BaseDao<TagCustomerEntity> {
/**
* @Description 校验此标签数据库是否存在 不存在insert 存在update useCount+1 返回id
* @param formDTO
* @author zxc
*/
void checkTagInfo(UpdateTagFormDTO formDTO);
}

11
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagGridDao.java

@ -18,8 +18,12 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.UpdateGridTagsFormDTO;
import com.epmet.entity.TagGridEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 网格标签表
@ -29,5 +33,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface TagGridDao extends BaseDao<TagGridEntity> {
/**
* @Description 更新网格下的标签标签存在使用次数+1插入新数据
* @param gridTags
* @author zxc
*/
void updateGridTag(@Param("gridTags") List<UpdateGridTagsFormDTO> gridTags,@Param("userId")String userId);
}

52
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java

@ -18,6 +18,7 @@
package com.epmet.redis;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.constant.TagConstant;
import com.epmet.dto.form.CorrelationTagListFormDTO;
@ -25,28 +26,34 @@ import com.epmet.dto.form.TagCascadeListFormDTO;
import com.epmet.dto.result.CorrelationTagListResultDTO;
import com.epmet.dto.result.TagInfoResultDTO;
import com.epmet.dto.result.TagRankResultDTO;
import com.epmet.dto.result.UpdateTagUseCountsResultDTO;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.poi.ss.formula.functions.T;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@Component
public class TagRedis {
@Autowired
private RedisUtils redisUtils;
@Autowired
private RedisTemplate redisTemplate;
public void delete(Object[] ids) {
}
public void set(){
}
/**
@ -81,6 +88,7 @@ public class TagRedis {
for (Object object : objects) {
resultList.add(objectToDTO(object,CorrelationTagListResultDTO.class));
}
// resultList = JSONObject.parseArray(objects.toString(), CorrelationTagListResultDTO.class);
//级联标签排序
//1.取出 zset 中的有序标签,根据级联标签,筛选有序标签
List<TagRankResultDTO> resultEquals = new ArrayList<>();
@ -128,6 +136,7 @@ public class TagRedis {
for (Object object : objects) {
result.add(objectToDTO(object,TagInfoResultDTO.class));
}
// List<TagInfoResultDTO> tagInfoResultDTOS = JSONObject.parseArray(objects.toString(), TagInfoResultDTO.class);
return result;
}
@ -224,4 +233,41 @@ public class TagRedis {
return t;
}
/**
* @Description 更新标签使用次数
* @param key
* @param formDTO
* @author zxc
*/
public Double updateTagUseCounts(String key, Object formDTO){
return redisUtils.zIncrementScore(key, formDTO, NumConstant.ONE);
}
/**
* @Description set 更新标签级联
* @param key
* @param value
* @author zxc
*/
public void updateMoreTag(String key, Set<UpdateTagUseCountsResultDTO> value) {
try {
log.info(TagConstant.BEGIN_UPDATE);
redisTemplate.executePipelined(new RedisCallback<Set<UpdateTagUseCountsResultDTO>>() {
@Override
public Set doInRedis(RedisConnection connection) throws DataAccessException {
for (UpdateTagUseCountsResultDTO tag : value) {
connection.sAdd(redisTemplate.getKeySerializer().serialize(key),redisTemplate.getValueSerializer().serialize(tag));
}
return null;
}
});
log.info(TagConstant.SUCCESS_UPDATE);
}catch (Exception e){
log.info(TagConstant.FAILURE_UPDATE);
throw new RenException(TagConstant.FAILURE_UPDATE);
}
}
}

90
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java

@ -19,17 +19,13 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.scan.result.SyncScanResult;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.dto.ArticleDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.dto.form.ArticlePageFormDTO;
import com.epmet.dto.form.CommonArticleListFormDTO;
import com.epmet.entity.ArticleEntity;
import java.util.List;
import java.util.Map;
/**
* 文章表
@ -39,66 +35,6 @@ import java.util.Map;
*/
public interface ArticleService extends BaseService<ArticleEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<ArticleDTO>
* @author generator
* @date 2020-06-02
*/
PageData<ArticleDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<ArticleDTO>
* @author generator
* @date 2020-06-02
*/
List<ArticleDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return ArticleDTO
* @author generator
* @date 2020-06-02
*/
ArticleDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2020-06-02
*/
void save(ArticleDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2020-06-02
*/
void update(ArticleDTO dto);
/**
* 批量删除
*
* @param ids
* @return void
* @author generator
* @date 2020-06-02
*/
void delete(String[] ids);
/**
* @param tokenDTO
* @return
@ -231,12 +167,20 @@ public interface ArticleService extends BaseService<ArticleEntity> {
**/
ArticleDetailResultDTO getArticleDetail(ResiArticleDetailFormDTO articleDetailFormDTO);
/**
* @Description 草稿发布文章
* @param draftId
* @return String 返回新发布文章的Id
* @author wangc
* @date 2020.06.05 09:10
**/
String publishDraftToArticle(String draftId);
/**
* desc:执行审核返回执行结果
* @param tokenDto
* @param draftId
* @return
*/
SyncScanResult scanContent(TokenDto tokenDto, String draftId);
void scanAllPassPublishArticle(TokenDto tokenDto, String draftId);
/**
* desc:修改审核状态为失败
* @param draftId
* @param syncScanResult
*/
void updateAuditStatusFailById(String draftId, SyncScanResult syncScanResult);
}

8
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagCustomerService.java

@ -20,6 +20,7 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.TagCustomerDTO;
import com.epmet.dto.result.UpdateTagUseCountsResultDTO;
import com.epmet.entity.TagCustomerEntity;
import java.util.List;
@ -92,4 +93,11 @@ public interface TagCustomerService extends BaseService<TagCustomerEntity> {
* @date 2020-06-02
*/
void delete(String[] ids);
/**
* @Description 查询标签信息
* @param tagName
* @author zxc
*/
UpdateTagUseCountsResultDTO checkTagInfo(String tagName,String customerId,String userId);
}

423
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java

@ -18,33 +18,38 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.scan.param.ImgScanParamDTO;
import com.epmet.commons.tools.scan.param.ImgTaskDTO;
import com.epmet.commons.tools.scan.param.TextScanParamDTO;
import com.epmet.commons.tools.scan.param.TextTaskDTO;
import com.epmet.commons.tools.scan.result.SyncScanResult;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.security.user.LoginUserUtil;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.utils.ScanContentUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.constant.ArticleConstant;
import com.epmet.constant.DraftConstant;
import com.epmet.constant.RoleKeyConstants;
import com.epmet.constant.*;
import com.epmet.dao.*;
import com.epmet.dto.*;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.entity.*;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.redis.ArticleRedis;
import com.epmet.redis.TagRedis;
import com.epmet.service.*;
import com.epmet.utils.ModuleConstant;
import com.github.pagehelper.PageHelper;
@ -52,7 +57,9 @@ import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.helper.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -98,6 +105,27 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
private ArticleContentDao articleContentDao;
@Autowired
private ArticleCoverDao articleCoverDao;
@Autowired
private DraftService draftService;
@Autowired
private TagCustomerService tagCustomerService;
@Autowired
private TagRedis tagRedis;
@Autowired
private TagGridDao tagGridDao;
@Autowired
private ArticleDao articleDao;
@Autowired
private ArticleTagsDao articleTagsDao;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Value("${openapi.scan.server.host}")
private String scanApiHost;
@Value("${openapi.scan.method.imgSyncScan}")
private String imgSyncScanMethod;
@Value("${openapi.scan.method.textSyncScan}")
private String textSyncScanMethod;
private static final String AGENCY = "agency";
private static final String GRID = "grid";
@ -106,58 +134,6 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
@Autowired
private ArticleVisitRecordService articleVisitRecordService;
@Override
public PageData<ArticleDTO> page(Map<String, Object> params) {
IPage<ArticleEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, ArticleDTO.class);
}
@Override
public List<ArticleDTO> list(Map<String, Object> params) {
List<ArticleEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, ArticleDTO.class);
}
private QueryWrapper<ArticleEntity> getWrapper(Map<String, Object> params) {
String id = (String) params.get(FieldConstant.ID_HUMP);
QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
return wrapper;
}
@Override
public ArticleDTO get(String id) {
ArticleEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, ArticleDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(ArticleDTO dto) {
ArticleEntity entity = ConvertUtils.sourceToTarget(dto, ArticleEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ArticleDTO dto) {
ArticleEntity entity = ConvertUtils.sourceToTarget(dto, ArticleEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
baseDao.deleteBatchIds(Arrays.asList(ids));
}
/**
* @param tokenDTO
* @return
@ -268,7 +244,17 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
GovArticleDetailResultDTO articleDetail = baseDao.queryGovArticleDetail(articleId);
if (null != articleDetail) {
List<GovArticleContentDTO> articleContentList = baseDao.queryGovArticleContent(articleId);
articleDetail.setArticleContentList(articleContentList);
if(null!=articleContentList&&articleContentList.size()>0){
articleDetail.setArticleContentList(articleContentList);
}else{
articleDetail.setArticleContentList(new ArrayList<>());
}
if (StringUtils.isNoneBlank(articleDetail.getTags())) {
String[] tagNames = articleDetail.getTags().split("\\|");
articleDetail.setTagNameList(tagNames);
}else{
articleDetail.setTagNameList(new String[0]);
}
}
return articleDetail;
}
@ -408,7 +394,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
coverEntity.setCustomerId(tokenDto.getCustomerId());
coverEntity.setDraftId(fromDTO.getDraftId());
coverEntity.setImgUrl(coverImg);
coverEntity.setAuditStatus("");
coverEntity.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS);
coverEntity.setAuditReason("");
coverEntity.setRevision(0);
coverEntity.setDelFlag(NumConstant.ZERO_STR);
@ -472,6 +458,8 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
entity.setCustomerId(tokenDto.getCustomerId());
entity.setDraftId(fromDTO.getDraftId());
entity.setOrderNum(i + 1);
//默认通过
entity.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS);
newContentList.add(entity);
}
@ -543,11 +531,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
//4:文章操作记录表新增数据
//4.1:调用epmet-user服务,查询工作人员信息
Result<CustomerStaffDTO> resultStaff = epmetUserOpenFeignClient.getCustomerStaff(formDTO.getStaffId());
if (!resultStaff.success() || null == resultStaff.getData()) {
throw new RenException(ArticleConstant.SELECT_STAFF_EXCEPTION);
}
CustomerStaffDTO staffDTO = resultStaff.getData();
CustomerStaffDTO staffDTO = getCustomerStaff(formDTO.getStaffId());
//4.2:查询文章表数据
ArticleEntity articleEntity = baseDao.selectById(formDTO.getArticleId());
//4.3:新增操作表数据
@ -561,6 +545,14 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
articleOperateRecordService.insert(recordEntity);
}
private CustomerStaffDTO getCustomerStaff(String userId) {
Result<CustomerStaffDTO> resultStaff = epmetUserOpenFeignClient.getCustomerStaff(userId);
if (!resultStaff.success() || null == resultStaff.getData()) {
throw new RenException(ArticleConstant.SELECT_STAFF_EXCEPTION);
}
return resultStaff.getData();
}
@Override
public PageData publishedArticleList(TokenDto tokenDto, PublishedListFormDTO formDTO) {
PageHelper.startPage(formDTO.getPageNo(),formDTO.getPageSize());
@ -586,10 +578,16 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
}
}
if (AGENCY.equals(staffLevel)) {
resultList = baseDao.selectArticleListForAgency(tokenDto.getCustomerId());
resultList = baseDao.selectArticleListForAgency(tokenDto.getCustomerId(), formDTO.getTagIdList());
} else {
resultList = baseDao.selectArticleListForGrid(tokenDto.getCustomerId(), userInfo.getGridIdList());
resultList = baseDao.selectArticleListForGrid(tokenDto.getCustomerId(), formDTO.getTagIdList(), userInfo.getGridIdList());
}
resultList.forEach(result -> {
String tags = result.getTags();
List<String> tagList = new ArrayList<>();
tagList= Arrays.asList(tags.split("[|]"));
result.setTagNameList(tagList);
});
PageInfo<PublishedListResultDTO> pageInfo = new PageInfo<>(resultList);
return new PageData<>(resultList, pageInfo.getTotal());
}
@ -828,20 +826,22 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
/**
* @Description 草稿发布文章
* @param draftId
* @param draft
* @return String 返回新发布文章的Id
* @author wangc
* @date 2020.06.05 09:10
**/
@Override
@Transactional(rollbackFor = Exception.class)
public String publishDraftToArticle(String draftId) {
public ArticleEntity publishDraftToArticle(DraftEntity draft) {
//1.查找草稿内容
DraftEntity draft = draftDao.selectById(draftId);
if(null != draft){
draft.setStatusFlag(DraftConstant.PUBLISHED);
draftDao.updateById(draft);
//2.查找草稿内容、封面、发布范围
List<DraftContentDTO> draftContents = draftContentDao.selectByDraftId(draftId,ModuleConstant.AUDIT_STATUS_PASS);
DraftCoverDTO draftCover = draftCoverDao.selectByDraftId(draftId,ModuleConstant.AUDIT_STATUS_PASS);
String draftId = draft.getId();
List<DraftContentEntity> draftContents = draftContentDao.selectByDraftId(draftId,ModuleConstant.AUDIT_STATUS_PASS);
DraftCoverEntity draftCover = draftCoverDao.selectByDraftId(draftId,ModuleConstant.AUDIT_STATUS_PASS);
List<DraftPublishRangeDTO> draftPublishRange = draftPublishRangeDao.selectByDraftId(draftId);
//3.生成文章以及相关记录
@ -857,6 +857,9 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
contentToInsert.setArticleId(article.getId());
contentToInsert.setId(null);
articleContentDao.insert(contentToInsert);
content.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS);
draftContentDao.updateById(content);
});
}
if(null != draftPublishRange && draftPublishRange.size() > NumConstant.ZERO){
@ -871,13 +874,283 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
coverToInsert.setArticleId(article.getId());
coverToInsert.setId(null);
articleCoverDao.insert(coverToInsert);
draftCover.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS);
draftCoverDao.updateById(draftCover);
}
}
return article.getId();
//4.3:新增操作表数据
CustomerStaffDTO staffDTO = getCustomerStaff(loginUserUtil.getLoginUserId());
ArticleOperateRecordEntity recordEntity = new ArticleOperateRecordEntity();
recordEntity.setCustomerId(article.getCustomerId());
recordEntity.setArticleId(article.getId());
recordEntity.setOpUser(article.getPublisherName() + "-" + staffDTO.getRealName());
recordEntity.setContent(String.format(ArticleConstant.PUBLISH_ARTICLE_MSG, article.getPublisherName(), staffDTO.getRealName(), article.getTitle()));
recordEntity.setOpType(ArticleConstant.OFFLINE);
recordEntity.setOpTime(new Date());
articleOperateRecordService.insert(recordEntity);
return article;
}
throw new RenException(String.format(ModuleConstant.SPECIFIED_DRAFT_NOT_FOUNT_EXCEPTION_TEMPLATE,draftId));
throw new RenException(String.format(ModuleConstant.SPECIFIED_DRAFT_NOT_FOUNT_EXCEPTION_TEMPLATE,draft.getId()));
}
@Override
public SyncScanResult scanContent(TokenDto tokenDto, String draftId) {
DraftEntity draftEntity = draftDao.selectById(draftId);
if (draftEntity == null){
log.error("scanContent draftId:{} is not exist",draftId);
return null;
}
if (!DraftConstant.AUDITING.equals(draftEntity.getStatusFlag())){
log.error("scanContent draftId:{} statusFlag:{} is not support 2 modify",draftId,draftEntity.getStatusFlag());
return null;
}
if (!NumConstant.ONE_STR.equals(draftEntity.getDelFlag())){
log.error("scanContent draftId:{} delFlag:{} is not support 2 modify",draftId,draftEntity.getDelFlag());
return null;
}
TextScanParamDTO textScanParamDTO = new TextScanParamDTO();
ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO();
DraftCoverDTO draftCoverDTO = draftCoverDao.selectCoverIdAndUrlByDraftId(draftId);
if (draftCoverDTO != null){
ImgTaskDTO taskDTO = new ImgTaskDTO();
taskDTO.setDataId(ModuleConstant.SCAN_COVER_PREFIX.concat(draftCoverDTO.getId()));
taskDTO.setUrl(draftCoverDTO.getImgUrl());
imgScanParamDTO.getTasks().add(taskDTO);
}
List<DraftContentEntity> contentDTOList = draftContentDao.selectScanContentByDraftId(draftId);
if(!CollectionUtils.isEmpty(contentDTOList)){
contentDTOList.forEach(content->{
String contentType = content.getContentType();
if (DraftConstant.TEXT.equals(contentType)){
//todo 内容叠加审核吧 id拼起来
TextTaskDTO textTaskDTO = new TextTaskDTO();
textTaskDTO.setDataId(content.getId());
textTaskDTO.setContent(content.getContent());
}else if (DraftConstant.IMG.equals(contentType)){
ImgTaskDTO taskDTO = new ImgTaskDTO();
taskDTO.setDataId(content.getId());
taskDTO.setUrl(content.getContent());
imgScanParamDTO.getTasks().add(taskDTO);
}
});
}
//todo 执行审核
SyncScanResult imgSyncScanResult = ScanContentUtils.imgSyncScan(scanApiHost.concat(imgSyncScanMethod),imgScanParamDTO);
SyncScanResult textSyncScanResult = ScanContentUtils.textSyncScan(scanApiHost.concat(textSyncScanMethod),textScanParamDTO);
SyncScanResult result = new SyncScanResult();
if (imgSyncScanResult.isAllPass()){
result.setAllPass(imgSyncScanResult.isAllPass());
result.getSuccessDataIds().addAll(imgSyncScanResult.getSuccessDataIds());
result.getFailDataIds().addAll(imgSyncScanResult.getFailDataIds());
}
if (textSyncScanResult.isAllPass()){
result.setAllPass(result.isAllPass()?textSyncScanResult.isAllPass():false);
result.getSuccessDataIds().addAll(textSyncScanResult.getSuccessDataIds());
result.getFailDataIds().addAll(textSyncScanResult.getFailDataIds());
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void scanAllPassPublishArticle(TokenDto tokenDto, String draftId){
DraftEntity draft = draftDao.selectById(draftId);
if (draft == null){
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(),EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg());
}
try {
//审核通过
ArticleEntity articleEntity = this.publishDraftToArticle(draft);
UpdateCustomerTagCacheDTO updateCustomerTagCacheDTO = this.updateCustomerTag(tokenDto, draftId);
List<UpdateGridTagCacheDTO> updateGridTagCacheDTOS = this.updateGridTag(tokenDto, draftId, updateCustomerTagCacheDTO);
//更新redis
try {
this.updateCacheCustomerTag(updateCustomerTagCacheDTO);
this.updateCacheGridTag(updateGridTagCacheDTOS);
} catch (Exception e) {
log.error("scanAllPassPublishArticle update redis exception", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
} catch (Exception e) {
log.error("scanAllPassPublishArticle update db exception", e);
this.sendMsg(draft.getTitle(), String.format(ModuleConstant.MSG_ARTICLE_PUBLISH_ERROR, draft.getTitle()));
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public void updateAuditStatusFailById(String draftId,SyncScanResult syncScanResult) {
List<String> failDataIds = syncScanResult.getFailDataIds();
failDataIds.forEach(id->{
if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX)>=0){
draftCoverDao.updateAuditStatusById(id,ModuleConstant.AUDIT_STATUS_FAIL);
}else{
draftContentDao.updateAuditStatusById(id,ModuleConstant.AUDIT_STATUS_FAIL);
}
});
}
public Result sendMsg(String title,String content) {
UserMessageFormDTO formDTO = new UserMessageFormDTO();
formDTO.setCustomerId(loginUserUtil.getLoginUserApp());
formDTO.setGridId("");
formDTO.setUserId(loginUserUtil.getLoginUserId());
formDTO.setApp(AppClientConstant.APP_GOV);
formDTO.setTitle(String.format(ModuleConstant.MSG_TITLE,title));
formDTO.setMessageContent(content);
formDTO.setReadFlag(ReadFlagConstant.UN_READ);
return epmetMessageOpenFeignClient.saveUserMessage(formDTO);
}
/**
* @Description 更新DB的标签使用次数 政府端
* @param draftId
* @author zxc
*/
public UpdateCustomerTagCacheDTO updateCustomerTag(TokenDto tokenDto, String draftId){
//获取草稿基本信息
DraftDTO draft = draftService.get(draftId);
String tags = draft.getTags();
String customerId = draft.getCustomerId();
String userId = tokenDto.getUserId();
List<String> tagsList = Arrays.asList(tags.split("\\|"));
List<UpdateTagUseCountsResultDTO> tagsInfo = new ArrayList<>();
//政府端的 标签使用次数 DB
for (String tag : tagsList) {
UpdateTagUseCountsResultDTO updateTagUseCount = tagCustomerService.checkTagInfo(tag, customerId, userId);
tagsInfo.add(updateTagUseCount);
}
UpdateCustomerTagCacheDTO result = new UpdateCustomerTagCacheDTO();
result.setCustomerId(customerId);
result.setTagsInfo(tagsInfo);
return result;
}
/**
* @Description 更新redis 标签使用数量 标签级联 政府端
* @param formDto
* @author zxc
*/
public void updateCacheCustomerTag(UpdateCustomerTagCacheDTO formDto){
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo();
String customerId = formDto.getCustomerId();
//更新缓存标签使用数量
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) {
String customerKey = TagConstant.GOV_TAG_KEY+customerId;
tagRedis.updateTagUseCounts(customerKey,resultDTO);
}
//政府端更新redis的级联标签(set)
List<UpdateTagUseCountsResultDTO> tagsInfoCopy = new ArrayList<>();
for (int i = 0; i < tagsInfo.size(); i++) {
tagsInfoCopy.addAll(tagsInfo);
String key = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagsInfo.get(i).getTagId();
tagsInfoCopy.remove(tagsInfo.get(i));
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(tagsInfoCopy);
tagRedis.updateMoreTag(key,setTag);
tagsInfoCopy.clear();
}
}
/**
* @Description 更新数据库 网格下的标签使用数量 居民端
* @param draftId
* @param formDto
* @author zxc
*/
public List<UpdateGridTagCacheDTO> updateGridTag(TokenDto tokenDto,String draftId,UpdateCustomerTagCacheDTO formDto){
//获取草稿基本信息
DraftDTO draft = draftService.get(draftId);
String customerId = draft.getCustomerId();
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo();
String userId = tokenDto.getUserId();
//根据草稿id查询发布范围id集合
List<String> gridIds = articlePublishRangeDao.selectGridIdByDraftId(draftId);
if (gridIds.size() == NumConstant.ZERO){
throw new RenException(TagConstant.SELECT_GRIDIDLIST_FAILURE);
}
List<UpdateGridTagsFormDTO> gridTags = new ArrayList<>();
List<UpdateGridTagCacheDTO> gridTagCache = new ArrayList<>();
for (String gridId : gridIds) {
UpdateGridTagCacheDTO cache = new UpdateGridTagCacheDTO();
cache.setGridId(gridId);
cache.setTagsInfo(tagsInfo);
gridTagCache.add(cache);
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) {
UpdateGridTagsFormDTO tag = new UpdateGridTagsFormDTO();
BeanUtils.copyProperties(resultDTO,tag);
tag.setCreatedBy(userId);
tag.setUpdatedBy(userId);
tag.setCustomerId(customerId);
tag.setGridId(gridId);
gridTags.add(tag);
}
}
tagGridDao.updateGridTag(gridTags,userId);
return gridTagCache;
}
/**
* @Description 更新redis 网格下的 标签使用数量 级联标签 居民端
* @param gridTagCache
* @author zxc
*/
public void updateCacheGridTag(List<UpdateGridTagCacheDTO> gridTagCache){
//更新 网格下 标签使用数量
List<UpdateTagUseCountsResultDTO> gridTagCacheCopy = new ArrayList<>();
for (UpdateGridTagCacheDTO cacheDTO : gridTagCache) {
String gridId = cacheDTO.getGridId();
String key = TagConstant.GRID_TAG_KEY+gridId;
List<UpdateTagUseCountsResultDTO> tagsInfo = cacheDTO.getTagsInfo();
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) {
tagRedis.updateTagUseCounts(key,resultDTO);
}
//级联
for (int i = 0; i < tagsInfo.size(); i++) {
gridTagCacheCopy.addAll(tagsInfo);
String moreKey = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagsInfo.get(i).getTagId();
gridTagCacheCopy.remove(tagsInfo.get(i));
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(gridTagCacheCopy);
tagRedis.updateMoreTag(moreKey,setTag);
gridTagCacheCopy.clear();
}
}
}
/**
* @Description 给文章挂标签 article_tags
* @param formDto
* @author zxc
*/
@Transactional(rollbackFor = Exception.class)
public void addArticleTags(UpdateCustomerTagCacheDTO formDto,String draftId,TokenDto tokenDto){
List<AddArticleTagsFormDTO> addArticleTags = new ArrayList<>();
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo();
DraftDTO draft = draftService.get(draftId);
String customerId = draft.getCustomerId();
String userId = tokenDto.getUserId();
String articleId = articleDao.getArticleIdByDraftId(draftId);
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) {
AddArticleTagsFormDTO addArticleTag = new AddArticleTagsFormDTO();
addArticleTag.setCreatedBy(userId);
addArticleTag.setUpdatedBy(userId);
addArticleTag.setCustomerId(customerId);
addArticleTag.setArticleId(articleId);
BeanUtils.copyProperties(resultDTO,addArticleTag);
addArticleTags.add(addArticleTag);
}
articleTagsDao.addArticleTags(addArticleTags);
}
}

9
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/DraftServiceImpl.java

@ -44,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -161,10 +162,16 @@ public class DraftServiceImpl extends BaseServiceImpl<DraftDao, DraftEntity> imp
DraftDetailResultDTO draftDetailResultDTO=baseDao.selectDraftDetail(formDTO.getDraftId());
if(null!=draftDetailResultDTO){
List<GovDraftContentDTO> articleContentList=baseDao.selectDraftContentList(formDTO.getDraftId());
draftDetailResultDTO.setArticleContentList(articleContentList);
if (null != articleContentList && articleContentList.size() > 0) {
draftDetailResultDTO.setArticleContentList(articleContentList);
} else {
draftDetailResultDTO.setArticleContentList(new ArrayList<>());
}
if (StringUtils.isNoneBlank(draftDetailResultDTO.getTags())) {
String[] tagNames = draftDetailResultDTO.getTags().split("\\|");
draftDetailResultDTO.setTagNameList(tagNames);
}else{
draftDetailResultDTO.setTagNameList(new String[0]);
}
}
return draftDetailResultDTO;

18
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java

@ -25,6 +25,8 @@ import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.dao.TagCustomerDao;
import com.epmet.dto.TagCustomerDTO;
import com.epmet.dto.form.UpdateTagFormDTO;
import com.epmet.dto.result.UpdateTagUseCountsResultDTO;
import com.epmet.entity.TagCustomerEntity;
import com.epmet.redis.TagCustomerRedis;
import com.epmet.service.TagCustomerService;
@ -101,4 +103,20 @@ public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagC
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Override
@Transactional(rollbackFor = Exception.class)
public UpdateTagUseCountsResultDTO checkTagInfo(String tagName,String customerId,String userId) {
UpdateTagFormDTO formDTO = new UpdateTagFormDTO();
formDTO.setCreatedBy(userId);
formDTO.setCustomerId(customerId);
formDTO.setUpdatedBy(userId);
formDTO.setTagName(tagName);
baseDao.checkTagInfo(formDTO);
UpdateTagUseCountsResultDTO resultDTO = new UpdateTagUseCountsResultDTO();
resultDTO.setTagId(formDTO.getId());
resultDTO.setTagName(tagName);
return resultDTO;
}
}

2
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java

@ -43,7 +43,7 @@ public class TagServiceImpl implements TagService {
*/
@Override
public List<TagInfoResultDTO> resiTagList(ResiTagListFormDTO formDto) {
//校验 在本网格是否发布过文章
//校验 客户在本网格是否发布过文章
Integer articleCounts = articleDao.checkPublishArticle(formDto);
if (articleCounts== NumConstant.ZERO){
return new ArrayList<>();

20
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ModuleConstant.java

@ -64,4 +64,24 @@ public interface ModuleConstant {
* */
String SPECIFIED_DRAFT_NOT_FOUNT_EXCEPTION_TEMPLATE = "未找到指定草稿,草稿Id:【%s】";
/**
* 内容审核 封面图片前缀用于标识这个Id是封面图片
* */
String SCAN_COVER_PREFIX = "cover_";
/**
* 文章站内消息标题
* */
String MSG_TITLE = "您有一条文章【%s】的消息";
/**
* 文章未审核通过 消息内容模版
* */
String MSG_AUDIT_CONTENT = "您好,您发布的【%s】文章%s审核未通过,请重新编辑后发布,谢谢。";
/**
* 文章发布失败 内部错误导致
* */
String MSG_ARTICLE_PUBLISH_ERROR = "您好,你发布的【%s】文章由于网络错误未发布成功,请重新发布,谢谢。";
}

8
epmet-module/gov-voice/gov-voice-server/src/main/resources/bootstrap.yml

@ -102,3 +102,11 @@ hystrix:
ribbon:
ReadTimeout: 300000
ConnectTimeout: 300000
openapi:
scan:
server:
host: http://localhost:8107/epmetscan/api
mehod:
imgSyncScan: /imgSyncScan
textSyncScan: /textSyncScan

46
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleDao.xml

@ -34,16 +34,17 @@
ORDER BY
ac.ORDER_NUM ASC
</select>
<!-- 校验 客户在本网格是否发布过文章 -->
<select id="checkPublishArticle" resultType="integer" parameterType="com.epmet.dto.form.ResiTagListFormDTO">
SELECT
COUNT(*) AS articleCounts
FROM
article
article_publish_range
WHERE
del_flag = 0
AND grid_id = #{gridId}
AND customer_id = #{customerId}
AND created_by = #{userId}
</select>
<select id="selectArticleListForAgency" resultType="com.epmet.dto.result.PublishedListResultDTO">
@ -58,6 +59,20 @@
WHERE a.DEL_FLAG = '0'
AND a.STATUS_FLAG = 'published'
AND a.CUSTOMER_ID = #{customerId}
<if test="tagIdList !=null and tagIdList.size() > 0">
AND EXISTS (
SELECT DISTINCT
at.ARTICLE_ID
FROM article_tags at
WHERE at.DEL_FLAG = '0'
AND at.ARTICLE_ID = a.ID
<foreach item="tagId" collection="tagIdList" open="AND (" separator="or" close=")" index="">
at.TAG_ID = #{tagId}
</foreach>
)
</if>
ORDER BY PUBLISH_DATE DESC, UPDATED_TIME DESC
</select>
<select id="selectArticleListForGrid" resultType="com.epmet.dto.result.PublishedListResultDTO">
@ -95,6 +110,18 @@
WHERE aa.DEL_FLAG = '0'
AND aa.STATUS_FLAG = 'published'
AND aa.CUSTOMER_ID = #{customerId}) t
<if test="tagIdList !=null and tagIdList.size() > 0">
AND EXISTS (
SELECT DISTINCT
at.ARTICLE_ID
FROM article_tags at
WHERE at.DEL_FLAG = '0'
AND at.ARTICLE_ID = t.articleId
<foreach item="tagId" collection="tagIdList" open="AND (" separator="or" close=")" index="">
at.TAG_ID = #{tagId}
</foreach>
)
</if>
ORDER BY publishDate DESC, UPDATED_TIME DESC
</select>
@ -287,4 +314,19 @@
AND art.ID = #{articleId}
ORDER BY content2.ORDER_NUM ASC
</select>
<!-- 根据draftId获取文章id -->
<select id="getArticleIdByDraftId" resultType="java.lang.String">
SELECT
a.id AS id
FROM
article a
LEFT JOIN draft d ON d.id = a.draft_id
WHERE
a.del_flag = 0
AND d.del_flag =0
AND d.status_flag = 'published'
AND a.draft_id = #{draftId}
</select>
</mapper>

14
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticlePublishRangeDao.xml

@ -18,4 +18,18 @@
</if>
ORDER BY created_time ASC
</select>
<!-- 根据草稿id查询发布范围id集合 -->
<select id="selectGridIdByDraftId" resultType="java.lang.String">
SELECT
apr.grid_id AS gridId
FROM
article_publish_range apr
LEFT JOIN article a ON a.id = apr.article_id
WHERE
a.del_flag = 0
AND apr.del_flag = 0
AND a.draft_id = #{draftId}
AND publish_status = "published"
</select>
</mapper>

9
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleTagsDao.xml

@ -3,5 +3,14 @@
<mapper namespace="com.epmet.dao.ArticleTagsDao">
<!-- 插入文章标签 -->
<select id="addArticleTags">
INSERT INTO article_tags ( ID, CUSTOMER_ID, ARTICLE_ID, TAG_ID, TAG_NAME, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
<foreach collection="addArticleTags" item="tag" separator=",">
( REPLACE ( UUID(), '-', '' ),#{tag.customerId}, #{tag.articleId}, #{tag.tagId}, #{tag.tagName}, #{tag.delFlag},
#{tag.revision}, #{tag.createdBy}, NOW(),#{tag.updatedBy}, NOW())
</foreach>
</select>
</mapper>

17
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/DraftContentDao.xml

@ -4,7 +4,7 @@
<mapper namespace="com.epmet.dao.DraftContentDao">
<!-- 通过草稿Id获取草稿内容并按照orderNum排序,默认拿取所有状态 -->
<select id="selectByDraftId" resultType="com.epmet.dto.DraftContentDTO">
<select id="selectByDraftId" resultType="com.epmet.entity.DraftContentEntity">
SELECT
CUSTOMER_ID,
CONTENT,
@ -16,7 +16,7 @@
DRAFT_CONTENT
<where>
DRAFT_ID = #{draftId}
AND DEL_FLAG = '0'
AND DEL_FLAG = 0
<if test='null != auditStatus and "" != auditStatus'>
AND AUDIT_STATUS = #{auditStatus}
</if>
@ -24,5 +24,18 @@
ORDER BY
ORDER_NUM
</select>
<select id="selectScanContentByDraftId" resultType="com.epmet.entity.DraftContentEntity">
SELECT
ID,
CONTENT,
CONTENT_TYPE
FROM
DRAFT_CONTENT
WHERE
DEL_FLAG = 0 AND DRAFT_ID = #{draftId,jdbcType=VARCHAR}
</select>
<update id="updateAuditStatusById">
UPDATE DRAFT_CONTENT SET AUDIT_STATUS = #{auditStatus,jdbcType=VARCHAR} WHERE ID = #{id,jdbcType=VARCHAR}
</update>
</mapper>

10
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/DraftCoverDao.xml

@ -4,7 +4,7 @@
<mapper namespace="com.epmet.dao.DraftCoverDao">
<!-- 通过草稿Id获取草稿封面且创建时间是为最新的 -->
<select id="selectByDraftId" resultType="com.epmet.dto.DraftCoverDTO">
<select id="selectByDraftId" resultType="com.epmet.entity.DraftCoverEntity">
SELECT
cover.CUSTOMER_ID,
cover.IMG_URL,
@ -14,12 +14,18 @@
DRAFT_COVER cover
<where>
cover.DRAFT_ID = #{draftId}
AND cover.DEL_FLAG = '0'
AND cover.DEL_FLAG = 0
<if test = 'null != auditStatus and "" != auditStatus'>
AND cover.AUDIT_STATUS = #{auditStatus}
</if>
AND NOT EXISTS ( SELECT 1 FROM DRAFT_COVER WHERE cover.CREATED_TIME <![CDATA[ < ]]> CREATED_TIME )
</where>
</select>
<select id="selectCoverIdAndUrlByDraftId" resultType="com.epmet.dto.DraftCoverDTO">
SELECT ID,IMG_URL FROM DRAFT_COVER WHERE DEL_FLAG = 0 AND DRAFT_ID = #{draftId,jdbcType=VARCHAR}
</select>
<update id="updateAuditStatusById">
UPDATE DRAFT_COVER SET AUDIT_STATUS = #{auditStatus,jdbcType=VARCHAR} WHERE ID = #{id,jdbcType=VARCHAR}
</update>
</mapper>

20
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml

@ -3,5 +3,25 @@
<mapper namespace="com.epmet.dao.TagCustomerDao">
<insert id="checkTagInfo" parameterType="com.epmet.dto.form.UpdateTagFormDTO">
<selectKey keyProperty="id" order="AFTER" resultType="String">
select id from tag_customer where tag_name = #{tagName}
</selectKey>
INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
(REPLACE ( UUID(), '-', '' ),
#{customerId},
#{tagName},
#{useCount},
#{delFlag},
#{revision},
#{createdBy},
NOW(),
#{updatedBy},
NOW())
ON DUPLICATE KEY UPDATE USE_COUNT = ( USE_COUNT + 1 ),
UPDATED_TIME = NOW(),
UPDATED_BY = #{updatedBy};
</insert>
</mapper>

14
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagGridDao.xml

@ -3,5 +3,19 @@
<mapper namespace="com.epmet.dao.TagGridDao">
<!-- 更新网格下的标签,标签存在?使用次数+1:插入 -->
<insert id="updateGridTag">
INSERT INTO tag_grid ( ID, CUSTOMER_ID, GRID_ID, TAG_ID, TAG_NAME, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
<foreach collection="gridTags" item="tag" separator=",">
( REPLACE ( UUID(), '-', '' ),#{tag.customerId}, #{tag.gridId}, #{tag.tagId}, #{tag.tagName}, #{
tag.useCount}, #{tag.delFlag},
#{tag.revision}, #{tag.createdBy}, NOW(),#{tag.updatedBy}, NOW())
</foreach>
ON DUPLICATE KEY UPDATE
USE_COUNT = ( USE_COUNT + 1 ),
UPDATED_TIME = NOW(),
UPDATED_BY = #{userId}
</insert>
</mapper>

2
epmet-module/resi-voice/resi-voice-server/Dockerfile

@ -6,6 +6,6 @@ RUN echo 'Asia/Shanghai' > /etc/timezone
COPY ./target/*.jar ./app.jar
EXPOSE 8102
EXPOSE 8106
ENTRYPOINT ["sh", "-c", "$RUN_INSTRUCT"]

2
epmet-module/resi-voice/resi-voice-server/deploy/docker-compose-dev.yml

@ -2,7 +2,7 @@ version: "3.7"
services:
resi-voice-server:
container_name: resi-voice-server-dev
image: 192.168.1.130:10080/epmet-cloud-dev/resi-voice-server:0.3.3
image: 192.168.1.130:10080/epmet-cloud-dev/resi-voice-server:0.3.5
ports:
- "8106:8106"
network_mode: host # 使用现有网络

4
epmet-module/resi-voice/resi-voice-server/pom.xml

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.3.3</version>
<version>0.3.5</version>
<parent>
<artifactId>resi-voice</artifactId>
<groupId>com.epmet</groupId>
@ -113,7 +113,7 @@
<activeByDefault>true</activeByDefault>
</activation>-->
<properties>
<server.port>8104</server.port>
<server.port>8106</server.port>
<spring.profiles.active>test</spring.profiles.active>
<!-- redis配置 -->

11
epmet-openapi/epmet-openapi-scan/Dockerfile

@ -0,0 +1,11 @@
FROM java:8
RUN export LANG="zh_CN.UTF-8"
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone
COPY ./target/*.jar ./app.jar
EXPOSE 8107
ENTRYPOINT ["sh", "-c", "$RUN_INSTRUCT"]

4
epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml

@ -1,8 +1,8 @@
version: "3.7"
services:
epmet-user-server:
epmet-openapi-scan:
container_name: epmet-openapi-scan-dev
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-scan:0.3.1
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-scan:0.3.3
ports:
- "8107:8107"
network_mode: host # 不会创建新的网络

2
epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml

@ -1,6 +1,6 @@
version: "3.7"
services:
epmet-user-server:
epmet-openapi-scan:
container_name: epmet-openapi-scan-test
image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-user-scan:0.3.1
ports:

2
epmet-openapi/epmet-openapi-scan/pom.xml

@ -8,7 +8,7 @@
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>0.3.1</version>
<version>0.3.3</version>
<artifactId>epmet-openapi-scan</artifactId>
<packaging>jar</packaging>
<dependencies>

15
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java

@ -0,0 +1,15 @@
package com.epmet.openapi.scan.common.constant;
/**
* 系统常量
*
* @author jianjun liu
* @date 2020-06-05 10:42
**/
public class SysConstant {
public static final String UTF8 = "utf-8";
public static final Integer MAX_TEXT_TASKS = 100;
public static final Integer MAX_IMG_TASKS = 10;
}

1
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* desc:图片检测场景
* @author jianjun liu
* @date 2020-06-04 21:39
**/

48
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java

@ -0,0 +1,48 @@
package com.epmet.openapi.scan.common.enu;
import java.util.ArrayList;
import java.util.List;
/**
* desc:文本检测建议
* @author jianjun liu
* @date 2020-06-04 21:39
**/
public enum SuggestionEnum {
PASS("pass", "正常"),
REVIEW("review", "需要人工审核"),
BLOCK("block", "文本违规");
private String code;
private String desc;
SuggestionEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static List<String> getImgSceneList() {
List<String> result = new ArrayList<>();
SuggestionEnum[] values = SuggestionEnum.values();
for (SuggestionEnum v : values) {
result.add(v.getCode());
}
return result;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

45
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java

@ -0,0 +1,45 @@
package com.epmet.openapi.scan.common.enu;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-04 21:39
**/
public enum SysResponseEnum {
/**
*
* 业务代码枚举类
*
* 编码样式CCCBBOOXX
* 编码示例说明
* CCC 中心编码&业务系统 (110-内容扫描服务中心服务)
* BB 业务类型00-默认
* OO 操作类型00-默认
* XX 具体编码00-成功,01-失败,02-参数错误,10-异常 99-系统错误
*
*/
/*通用枚举 */
EXCEPTION(10001,"系统异常"),
AUTH_FAIL(10002,"验签失败"),
/*审核内容 业务 01*/
SCAN_TASK_LIST_PARAM_ERROR(110010001,"任务列表不能为空"),
SCAN_PARAM_ERROR(110010002,"参数格式不正确"),
;
private Integer code;
private String msg;
SysResponseEnum(Integer code, String msg){
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
}

46
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java

@ -0,0 +1,46 @@
package com.epmet.openapi.scan.common.enu;
import java.util.ArrayList;
import java.util.List;
/**
* desc:文本检测场景
* @author jianjun liu
* @date 2020-06-04 21:39
**/
public enum TextSceneEnum {
ANTISPAM("antispam", "文本垃圾内容检测");
private String code;
private String desc;
TextSceneEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static List<String> getTextSceneList() {
List<String> result = new ArrayList<>();
TextSceneEnum[] values = TextSceneEnum.values();
for (TextSceneEnum v : values) {
result.add(v.getCode());
}
return result;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

17
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/AuthException.java

@ -0,0 +1,17 @@
package com.epmet.openapi.scan.common.exception;
import com.epmet.openapi.scan.common.enu.SysResponseEnum;
/**
* @author jianjun liu
* @date 2020-06-05 10:31
**/
public class AuthException extends RuntimeException {
private int code;
private String msg;
public AuthException() {
this.code = SysResponseEnum.AUTH_FAIL.getCode();
this.msg = SysResponseEnum.AUTH_FAIL.getMsg();
}
}

23
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java

@ -0,0 +1,23 @@
package com.epmet.openapi.scan.common.exception;
import com.epmet.commons.tools.utils.MessageUtils;
import com.epmet.openapi.scan.common.enu.SysResponseEnum;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:31
**/
public class ExeCuteHttpException extends RuntimeException {
private int code;
private String msg;
public ExeCuteHttpException(String msg) {
this(SysResponseEnum.EXCEPTION.getCode(), msg);
}
public ExeCuteHttpException(int code, String... params) {
this.code = code;
this.msg = MessageUtils.getMessage(code, params);
}
}

171
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java

@ -0,0 +1,171 @@
package com.epmet.openapi.scan.common.util;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* desc: http 工具类
* date: 2020/6/4 22:27
*
* @author: jianjun liu
*/
@Slf4j
public class HttpClientManager {
private static int connectionTimeout = 3000;// 连接超时时间,毫秒
private static int soTimeout = 10000;// 读取数据超时时间,毫秒
/**
* HttpClient对象
*/
private static CloseableHttpClient httpclient = HttpClients.custom().disableAutomaticRetries().build();
/*** 超时设置 ****/
private static RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(soTimeout)
.setConnectTimeout(connectionTimeout)
.build();//设置请求和传输超时时间
public static HttpClientManager getInstance() {
return SingleClass.instance;
}
private static class SingleClass {
private final static HttpClientManager instance = new HttpClientManager();
}
/**
* desc: 发送json post 请求
* param: url,jsonStrParam
* return: CallResult<String>
* date: 2019/2/21 9:12
*
* @author: jianjun liu
*/
public Result<String> sendPost(String url, Map<String, String> paramsMap) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded charset=utf-8");
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : paramsMap.keySet()) {
list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key))));
}
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8");
httppost.setEntity(urlEncodedFormEntity);
return execute(httppost);
} catch (Exception e) {
e.printStackTrace();
log.error("send exception", e);
return new Result<String>().error(8000, e.getMessage());
}
}
/**
* desc: 发送json post 请求
* param: url,jsonStrParam
* return: CallResult<String>
* date: 2019/2/21 9:12
*
* @author: jianjun liu
*/
public Result<String> sendPostByJSON(String url, String jsonStrParam) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
if (StringUtils.isNotEmpty(jsonStrParam)) {
StringEntity se = new StringEntity(jsonStrParam, "utf-8");
httppost.setEntity(se);
}
return execute(httppost);
} catch (Exception e) {
e.printStackTrace();
log.error("send exception", e);
return new Result<String>().error(8000, e.getMessage());
}
}
/**
* desc: 发送get请求
* param:url, params
* return: CallResult<String>
* date: 2019/2/21 9:16
*
* @author: jianjun liu
*/
public Result<String> sendGet(String url, Map<String, Object> params) {
try {
URIBuilder builder = new URIBuilder(url);
if (!CollectionUtils.isEmpty(params)) {
Set<String> set = params.keySet();
for (String key : set) {
builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key)));
}
}
HttpGet httpGet = new HttpGet(builder.build());
httpGet.setConfig(requestConfig);
return execute(httpGet);
} catch (Exception e) {
log.error("sendGet exception", e);
return new Result<String>().error(8000, e.getMessage());
}
}
private Result<String> execute(HttpRequestBase httpMethod) {
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpMethod);
log.debug("http send response:{}", JSON.toJSONString(response));
if (response != null && response.getStatusLine() != null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String result = EntityUtils.toString(response.getEntity());
return new Result<String>().ok(result);
} else {
log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode());
}
}
} catch (Exception e) {
log.error("execute exception", e);
} finally {
httpMethod.releaseConnection();
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
}
}
return new Result<String>().error(8000, "系统异常");
}
}

68
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java

@ -0,0 +1,68 @@
package com.epmet.openapi.scan.common.util;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:03
**/
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.epmet.openapi.scan.common.enu.RegionIdEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Slf4j
@Component
public class IAcsClientUtil {
private static String accessKeyId;
private static String secret;
private static String product = "Green";
private static String regionId;
private static String endpointName = "";
private static IClientProfile profile;
@PostConstruct
private void initProFile() {
profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
try {
DefaultProfile.addEndpoint(endpointName, regionId, product, RegionIdEnum.getDoMain(regionId));
} catch (ClientException e) {
log.error("initProFile exception", e.getMessage());
}
}
public static IAcsClient getIAcsClient() {
return new DefaultAcsClient(profile);
}
@Value("${aliyun.green.accessKeyId}")
public void setAccessKeyId(String accessKeyId) {
IAcsClientUtil.accessKeyId = accessKeyId;
}
@Value("${aliyun.green.accessKeySecret}")
public void setSecret(String secret) {
IAcsClientUtil.secret = secret;
}
@Value("${aliyun.green.regionId}")
public void setRegionId(String regionId) {
IAcsClientUtil.regionId = regionId;
}
@Value("${aliyun.green.regionId}")
public void setEndpointName(String endpointName) {
IAcsClientUtil.endpointName = endpointName;
}
}

55
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java

@ -0,0 +1,55 @@
package com.epmet.openapi.scan.common.util;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author jianjun liu
* @date 2020-06-05 16:44
**/
public class MapUtil {
/**
* 将url参数转换成map
*
* @param param aa=11&bb=22&cc=33
* @return
*/
public static Map<String, Object> getUrlParams(String param) {
Map<String, Object> map = new HashMap<>(0);
if (StringUtils.isBlank(param)) {
return map;
}
String[] params = param.split("&");
for (int i = 0; i < params.length; i++) {
String[] p = params[i].split("=");
if (p.length == 2) {
map.put(p[0], p[1]);
}
}
return map;
}
/**
* 将map转换成url
*
* @param map
* @return
*/
public static String getUrlParamsByMap(Map<String, Object> map) {
if (map == null) {
return "";
}
StringBuffer sb = new StringBuffer();
for (Map.Entry<String, Object> entry : map.entrySet()) {
sb.append(entry.getKey() + "=" + entry.getValue());
sb.append("&");
}
String s = sb.toString();
if (s.endsWith("&")) {
s = StringUtils.substringBeforeLast(s, "&");
}
return s;
}
}

152
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/RSASignature.java

@ -0,0 +1,152 @@
package com.epmet.openapi.scan.common.util;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.util.encoders.UrlBase64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Cipher;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
/**
* @author jianjun liu
* @date 2020-06-05 16:48
**/
public class RSASignature {
private static final Logger LOGGER = LoggerFactory.getLogger(RSASignature.class);
public static final String KEY_ALGORITHM = "RSA";
public static final String SIGNATURE_ALGORITHM = "SHA1WithRSA";
public static final String ENCODING = "utf-8";
public static final String X509 = "X.509";
/**
* 获取私钥
*
* @param key
* @return
* @throws Exception
*/
public static PrivateKey getPrivateKey(String key) throws Exception {
byte[] keyBytes = Base64.decodeBase64(key.getBytes(ENCODING));
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
return privateKey;
}
/**
* 获取公钥
*
* @param key
* @return
* @throws Exception
*/
public static PublicKey getPublicKey(String key) throws Exception {
byte[] keyBytes = Base64.decodeBase64(key.getBytes(ENCODING));
CertificateFactory certificateFactory = CertificateFactory.getInstance(X509);
InputStream in = new ByteArrayInputStream(keyBytes);
Certificate certificate = certificateFactory.generateCertificate(in);
PublicKey publicKey = certificate.getPublicKey();
return publicKey;
}
/**
* 使用公钥对明文进行加密返回BASE64编码的字符串
*
* @param publicKey
* @param plainText
* @return
*/
public static String encrypt(String publicKey, String plainText) {
try {
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
byte[] encodedKey = Base64.decodeBase64(publicKey.getBytes(ENCODING));
PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
Cipher cipher = Cipher.getInstance(KEY_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
byte[] enBytes = cipher.doFinal(plainText.getBytes());
return new String(Base64.encodeBase64(enBytes));
} catch (Exception e) {
LOGGER.error("rsa encrypt exception: {}", e.getMessage(), e);
}
return null;
}
/**
* 使用私钥对明文密文进行解密
*
* @param privateKey
* @param enStr
* @return
*/
public static String decrypt(String privateKey, String enStr) {
try {
PrivateKey priKey = getPrivateKey(privateKey);
Cipher cipher = Cipher.getInstance(KEY_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, priKey);
byte[] deBytes = cipher.doFinal(Base64.decodeBase64(enStr));
return new String(deBytes);
} catch (Exception e) {
LOGGER.error("rsa decrypt exception: {}", e.getMessage(), e);
}
return null;
}
/**
* RSA私钥签名
*
* @param content 待签名数据
* @param privateKey 私钥
* @return 签名值
*/
public static String signByPrivateKey(String content, String privateKey) {
try {
PrivateKey priKey = getPrivateKey(privateKey);
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initSign(priKey);
signature.update(content.getBytes(ENCODING));
byte[] signed = signature.sign();
return new String(UrlBase64.encode(signed), ENCODING);
} catch (Exception e) {
LOGGER.error("sign error, content: {}", content, e);
}
return null;
}
/**
* 公钥验签
*
* @param content
* @param sign
* @param publicKey
* @return
*/
public static boolean verifySignByPublicKey(String content, String sign, String publicKey) {
try {
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
byte[] encodedKey = Base64.decodeBase64(publicKey.getBytes(ENCODING));
PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initVerify(pubKey);
signature.update(content.getBytes(ENCODING));
return signature.verify(UrlBase64.decode(sign.getBytes(ENCODING)));
} catch (Exception e) {
LOGGER.error("verify sign error, content: {}, sign: {}", content, sign, e);
}
return false;
}
}

52
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/FastJsonConfiguration.java

@ -0,0 +1,52 @@
package com.epmet.openapi.scan.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 14:14
**/
@Configuration
public class FastJsonConfiguration {
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
List<MediaType> fastMediaTypes = new ArrayList<>();
// 处理中文乱码问题
fastJsonConfig.setCharset(Charset.forName("UTF-8"));
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
// 设置时间格式
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
// 在转换器中添加配置信息
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter converter = fastJsonHttpMessageConverter;
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
stringConverter.setDefaultCharset(Charset.forName("UTF-8"));
stringConverter.setSupportedMediaTypes(fastMediaTypes);
return new HttpMessageConverters(stringConverter, converter);
}
}

56
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java

@ -0,0 +1,56 @@
package com.epmet.openapi.scan.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.openapi.scan.service.impl.ScanService;
import com.epmet.openapi.scan.support.param.ImgScanParam;
import com.epmet.openapi.scan.support.param.TextScanParam;
import com.epmet.openapi.scan.support.result.ImgAsyncScanResult;
import com.epmet.openapi.scan.support.result.SyncScanResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:39
**/
@RestController
@RequestMapping("api")
public class ScanController {
@Autowired
private ScanService scanService;
/**
* desc:图片同步检测接口
*
* @param param
* @return
*/
@RequestMapping("imgSyncScan")
public Result<SyncScanResult> ImgSyncScan(@RequestBody ImgScanParam param) {
Result<SyncScanResult> scanResultResult = scanService.sendSyncImgScan(param);
return scanResultResult;
}
/**
* desc:文本同步检测接口
*
* @param param
* @return
*/
@RequestMapping("textSyncScan")
public Result<SyncScanResult> textSyncScan(@RequestBody TextScanParam param) {
Result<SyncScanResult> scanResultResult = scanService.sendTextScan(param);
return scanResultResult;
}
@RequestMapping("imgAsyncScan")
public Result<ImgAsyncScanResult> ImgAsyncScan(@RequestBody ImgScanParam param) {
Result<ImgAsyncScanResult> scanResultResult = scanService.sendASyncImgScan(param);
return scanResultResult;
}
}

113
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiInterceptor.java

@ -0,0 +1,113 @@
package com.epmet.openapi.scan.interceptor;
import com.epmet.openapi.scan.common.exception.AuthException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 16:36
**/
public class ScanApiInterceptor implements HandlerInterceptor {
private static final Logger log = LoggerFactory.getLogger(ScanApiInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
Map parameterMap = request.getParameterMap();
String requestUrl = request.getServletPath();
log.info(" 请求地址为: " + requestUrl + " 请求参数为: " + gson.toJson(parameterMap));
try {
String timestamp = "";
String appkey = "";
String sign = "";
if (parameterMap.containsKey("timestamp")) {
timestamp = parameterMap.get("timestamp").toString();
//验证时间戳
Long timestampL = new Long(timestamp);
Calendar timestampCalendar = Calendar.getInstance();
timestampCalendar.setTimeInMillis(timestampL * 1000L);
//设置过期时间
timestampCalendar.add(Calendar.MINUTE, 10);
Date timestampDate = timestampCalendar.getTime();
Date nowDate = new Date();
if (timestampDate.compareTo(nowDate) < 0) {
throw new AuthException();
}
} else {
throw new AuthException();
}
if (parameterMap.containsKey("appkey")) {
appkey = parameterMap.get("appkey").toString();
} else {
throw new AuthException();
}
if (parameterMap.containsKey("sign")) {
sign = parameterMap.get("sign").toString();
} else {
throw new AuthException();
}
Map map2 = new HashMap();
map2.putAll(parameterMap);
map2.remove("sign");
/*String urls = MapUtil.getUrlParamsByMap(map2);
urls += "&appsecret=" + OakConfig.getApiAppSecret();
String newSign = MD5Util.md5(urls);
//log.info("拼接urls参数为:" + urls + " 服务器端签名sign为:" + newSign);
if (!sign.equals(newSign)) {
throw new AuthException();
return false;
}*/
return true;
} catch (Exception e) {
log.error(e.toString());
throw new AuthException();
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
}
private void responseJson(HttpServletResponse response, String json) throws Exception {
PrintWriter writer = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("text/json; charset=utf-8");
try {
writer = response.getWriter();
writer.print(json);
} catch (IOException e) {
log.error(e.toString());
} finally {
if (writer != null) {
writer.close();
}
}
}
}

37
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java

@ -0,0 +1,37 @@
package com.epmet.openapi.scan.service.impl;
import com.epmet.commons.tools.utils.Result;
import com.epmet.openapi.scan.support.param.ImgScanParam;
import com.epmet.openapi.scan.support.param.TextScanParam;
import com.epmet.openapi.scan.support.result.ImgAsyncScanResult;
import com.epmet.openapi.scan.support.result.SyncScanResult;
/**
* desc:内容扫描接口
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 13:12
**/
public interface ScanService {
/**
* desc:扫描文本内容 同步
* @param textScanParam
* @return ImgAsyncScanResult
*/
public Result<SyncScanResult> sendTextScan(TextScanParam textScanParam);
/**
* desc:扫描图片内容 同步
* @param imgScanParam
* @return
*/
public Result<SyncScanResult> sendSyncImgScan(ImgScanParam imgScanParam);
/**
* desc:扫描图片内容 异步
* @param imgScanParam
* @return
*/
public Result<ImgAsyncScanResult> sendASyncImgScan(ImgScanParam imgScanParam);
}

311
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java

@ -0,0 +1,311 @@
package com.epmet.openapi.scan.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.AcsRequest;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.ImageAsyncScanRequest;
import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest;
import com.aliyuncs.green.model.v20180509.TextScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.epmet.commons.tools.utils.Result;
import com.epmet.openapi.scan.common.constant.SysConstant;
import com.epmet.openapi.scan.common.enu.ImgSceneEnum;
import com.epmet.openapi.scan.common.enu.SuggestionEnum;
import com.epmet.openapi.scan.common.enu.SysResponseEnum;
import com.epmet.openapi.scan.common.enu.TextSceneEnum;
import com.epmet.openapi.scan.common.exception.ExeCuteHttpException;
import com.epmet.openapi.scan.common.util.IAcsClientUtil;
import com.epmet.openapi.scan.support.param.ImgScanParam;
import com.epmet.openapi.scan.support.param.ImgTask;
import com.epmet.openapi.scan.support.param.TextScanParam;
import com.epmet.openapi.scan.support.param.TextTask;
import com.epmet.openapi.scan.support.result.BaseScanResult;
import com.epmet.openapi.scan.support.result.ImgAsyncScanResult;
import com.epmet.openapi.scan.support.result.ScanTaskResult;
import com.epmet.openapi.scan.support.result.SyncScanResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.UnsupportedEncodingException;
import java.util.List;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 13:16
**/
@Slf4j
@Service
public class ScanServiceImpl implements ScanService {
@Value("${aliyun.green.regionId}")
private String regionId;
@Value("${aliyun.green.bizType}")
private String bizType;
@Override
public Result<SyncScanResult> sendTextScan(TextScanParam textScanParam) {
//默认参数
// 鉴黄 暴恐涉政
textScanParam.setScenes(TextSceneEnum.getTextSceneList());
textScanParam.setBizType(bizType);
List<TextTask> textTasks = textScanParam.getTasks();
if (CollectionUtils.isEmpty(textTasks) || textTasks.size() > SysConstant.MAX_TEXT_TASKS) {
return new Result<SyncScanResult>().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg());
}
TextScanRequest textScanRequest = new TextScanRequest();
textScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
textScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
textScanRequest.setEncoding(SysConstant.UTF8);
textScanRequest.setRegionId(regionId);
try {
textScanRequest.setHttpContent(JSON.toJSONString(textScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON);
} catch (UnsupportedEncodingException e) {
log.error("sendTextScan exception", e.getMessage());
}
/**
* 请务必设置超时时间
*/
textScanRequest.setConnectTimeout(3000);
textScanRequest.setReadTimeout(6000);
try {
SyncScanResult textScanResult = executeSyncText(textScanRequest);
return new Result<SyncScanResult>().ok(textScanResult);
} catch (Exception e) {
log.error("sendTextScan exception", e);
throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg());
}
}
@Override
public Result<SyncScanResult> sendSyncImgScan(ImgScanParam imgScanParam) {
ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest();
imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
imageSyncScanRequest.setEncoding(SysConstant.UTF8);
imageSyncScanRequest.setRegionId(regionId);
//默认参数
// 鉴黄 暴恐涉政
imgScanParam.setScenes(ImgSceneEnum.getImgSceneList());
imgScanParam.setBizType(bizType);
List<ImgTask> imgTasks = imgScanParam.getTasks();
if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_IMG_TASKS) {
return new Result<SyncScanResult>().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg());
}
try {
imageSyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON);
} catch (UnsupportedEncodingException e) {
log.error("sendSyncImgScan exception", e.getMessage());
return new Result<SyncScanResult>().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg());
}
/**
* 请务必设置超时时间
*/
imageSyncScanRequest.setConnectTimeout(3000);
imageSyncScanRequest.setReadTimeout(6000);
try {
SyncScanResult scanResult = executeSyncImg(imageSyncScanRequest);
return new Result<SyncScanResult>().ok(scanResult);
} catch (Exception e) {
log.error("sendImgScan execute Exception", e);
return new Result<SyncScanResult>().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg());
}
}
@Override
public Result<ImgAsyncScanResult> sendASyncImgScan(ImgScanParam imgScanParam) {
ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest();
imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
imageAsyncScanRequest.setEncoding(SysConstant.UTF8);
imageAsyncScanRequest.setRegionId(regionId);
//默认参数
// 鉴黄 暴恐涉政
imgScanParam.setScenes(ImgSceneEnum.getImgSceneList());
imgScanParam.setBizType(bizType);
List<ImgTask> imgTasks = imgScanParam.getTasks();
if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_IMG_TASKS) {
return new Result<ImgAsyncScanResult>().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg());
}
try {
imageAsyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON);
} catch (UnsupportedEncodingException e) {
log.error("sendASyncImgScan exception", e.getMessage());
return new Result<ImgAsyncScanResult>().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg());
}
/**
* 请务必设置超时时间
*/
imageAsyncScanRequest.setConnectTimeout(3000);
imageAsyncScanRequest.setReadTimeout(6000);
try {
ImgAsyncScanResult scanResult = executeAsyncImg(imageAsyncScanRequest);
return new Result<ImgAsyncScanResult>().ok(scanResult);
} catch (Exception e) {
log.error("sendImgScan execute Exception", e);
return new Result<ImgAsyncScanResult>().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg());
}
}
public SyncScanResult executeSyncText(AcsRequest<?> textScanRequest) {
SyncScanResult result = new SyncScanResult();
try {
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(textScanRequest);
if (httpResponse.isSuccess()) {
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8));
System.out.println(JSON.toJSONString(scrResponse, true));
if (200 == scrResponse.getInteger("code")) {
//任务 列表
List<ScanTaskResult> scanTaskResults = scrResponse.getJSONArray("data").toJavaList(ScanTaskResult.class);
for (ScanTaskResult taskResult : scanTaskResults) {
//又根据场景不同
if (200 == taskResult.getCode()) {
//如果是多个场景 则为对个 BaseScanResult
List<BaseScanResult> sceneResults = taskResult.getResults();
//是文本检测 目前就一种场景
for (BaseScanResult sceneResult : sceneResults) {
String scene = sceneResult.getScene();
String suggestion = sceneResult.getSuggestion();
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) {
result.getFailDataIds().add(taskResult.getDataId());
} else {
result.getSuccessDataIds().add(taskResult.getDataId());
}
}
} else {
log.warn("executeSyncText task process fail:code:{},msg:{}", taskResult.getCode(), taskResult.getMsg());
throw new ExeCuteHttpException(" executeSyncTexttask process fail:code:" + taskResult.getCode() + ",msg:" + taskResult.getMsg());
}
}
return result;
} else {
throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger("code"));
}
} else {
log.warn("executeSyncText response not success. status:" + httpResponse.getStatus());
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus());
}
} catch (Exception e) {
log.warn("executeSyncImg exception", e);
throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg());
}
}
/**
* desc:异步 检查图片 TODO 结果处理
*
* @param request
* @return
*/
private ImgAsyncScanResult executeAsyncImg(AcsRequest<?> request) {
ImgAsyncScanResult result = new ImgAsyncScanResult();
try {
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request);
if (httpResponse.isSuccess()) {
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
System.out.println(JSON.toJSONString(scrResponse, true));
if (200 == scrResponse.getInteger("code")) {
JSONArray taskResults = scrResponse.getJSONArray("data");
for (Object taskResult : taskResults) {
if (200 == ((JSONObject) taskResult).getInteger("code")) {
String taskId = ((JSONObject) taskResult).getString("taskId");
// 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest
System.out.println("args = [" + taskId + "]");
result.getSuccessTaskIds().add(taskId);
} else {
//TODO 细化失败结果 属性 code等
String taskId = ((JSONObject) taskResult).getString("taskId");
result.getFailTaskIds().add(taskId);
log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger("code"));
throw new ExeCuteHttpException("task process fail:" + ((JSONObject) taskResult).getInteger("code"));
}
}
return result;
} else {
System.out.println("detect not success. code:" + scrResponse.getInteger("code"));
throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("code"));
}
} else {
System.out.println("response not success. status:" + httpResponse.getStatus());
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus());
}
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
private SyncScanResult executeSyncImg(AcsRequest<?> request) {
SyncScanResult result = new SyncScanResult();
try {
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request);
if (httpResponse.isSuccess()) {
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
System.out.println(JSON.toJSONString(scrResponse, true));
if (200 == scrResponse.getInteger("code")) {
JSONArray taskResults = scrResponse.getJSONArray("data");
List<ScanTaskResult> scanTaskResults = taskResults.toJavaList(ScanTaskResult.class);
for (ScanTaskResult taskResult : scanTaskResults) {
//如果是多个场景 则为对个 BaseScanResult
List<BaseScanResult> sceneResults = taskResult.getResults();
//是文本检测 目前就一种场景
for (BaseScanResult sceneResult : sceneResults) {
String scene = sceneResult.getScene();
String suggestion = sceneResult.getSuggestion();
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) {
if (result.getFailDataIds().contains(taskResult.getDataId())) {
continue;
}
result.getFailDataIds().add(taskResult.getDataId());
} else {
if (result.getSuccessDataIds().contains(taskResult.getDataId())) {
continue;
}
result.getSuccessDataIds().add(taskResult.getDataId());
}
}
}
return result;
} else {
log.warn("executeSyncImg detect not success. code:", scrResponse.getInteger("code"));
throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("code"));
}
} else {
log.warn("executeSyncImg response not success. status:" + httpResponse.getStatus());
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus());
}
} catch (Exception e) {
log.warn("executeSyncImg exception", e);
throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg());
}
}
}

11
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ScanParam.java → epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java

@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.param;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
@ -11,7 +12,13 @@ import java.util.List;
* @date 2020-06-04 21:57
**/
@Data
public class ScanParam {
public class ImgScanParam implements Serializable {
private static final long serialVersionUID = 958801658335909745L;
/**
* 业务类型
*/
private String bizType;
/**
* 场景 必填
*
@ -23,7 +30,7 @@ public class ScanParam {
* 要检测的内容列表必填
* remark一组任务列表中的taskId不能相同
*/
private List<Task> tasks;
private List<ImgTask> tasks;
/**
* 异步检测结果回调地址,执行异步审查内容时 必填

5
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/Task.java → epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java

@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param;
import lombok.Data;
import java.io.Serializable;
/**
* 任务参数
*
@ -10,8 +12,9 @@ import lombok.Data;
* @date 2020-06-04 22:13
**/
@Data
public class Task {
public class ImgTask implements Serializable {
private static final long serialVersionUID = -747206284930578105L;
/**
* 要检测的数据id 非必填
*

44
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java

@ -0,0 +1,44 @@
package com.epmet.openapi.scan.support.param;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 文本审查参数
*
* @author jianjun liu
* @date 2020-06-05 11:17
**/
@Data
public class TextScanParam implements Serializable {
private static final long serialVersionUID = -3568903097975113166L;
/**
* 业务类型
*/
private String bizType;
/**
* 场景 必填
*
* @see com.epmet.openapi.scan.common.enu.ImgSceneEnum;
*/
private List<String> scenes;
/**
* 要检测的内容列表必填
* remark一组任务列表中的taskId不能相同
*/
private List<TextTask> tasks;
/**
* 异步检测结果回调地址,执行异步审查内容时 必填
*/
private String callback;
/**
* 随机字符串该值用于回调通知请求中的签名使用callback时 必填
*/
private String seed;
}

28
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java

@ -0,0 +1,28 @@
package com.epmet.openapi.scan.support.param;
import lombok.Data;
import java.io.Serializable;
/**
* 任务参数
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-04 22:13
**/
@Data
public class TextTask implements Serializable {
private static final long serialVersionUID = 6957195274696018630L;
/**
* 要检测的数据id 非必填
*
* */
private String dataId;
/**
* 文本内容 必填 最多不能超过10000
*/
private String content;
}

31
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java

@ -0,0 +1,31 @@
package com.epmet.openapi.scan.support.result;
import lombok.Data;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 14:24
**/
@Data
public class BaseScanResult {
/**
* 结果为该分类的概率
*/
private Double rate;
/**
* 建议用户执行的操作
*/
private String suggestion;
/**
* 场景
*/
private String scene;
/**
* 标签
*/
private String label;
}

18
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java

@ -0,0 +1,18 @@
package com.epmet.openapi.scan.support.result;
import com.aliyuncs.AcsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.transform.UnmarshallerContext;
/**
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:24
**/
public class ImgAcsReponse extends AcsResponse {
@Override
public AcsResponse getInstance(UnmarshallerContext context) throws ClientException, ServerException {
return null;
}
}

24
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java

@ -0,0 +1,24 @@
package com.epmet.openapi.scan.support.result;
import lombok.Data;
import java.util.List;
/**
* 检测结果
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:52
**/
@Data
public class ImgAsyncScanResult {
/**
* 执行成功的任务Id集合
*/
private List<String> successTaskIds;
/**
* 执行失败的任务Id集合
*/
private List<String> failTaskIds;
}

26
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java

@ -0,0 +1,26 @@
package com.epmet.openapi.scan.support.result;
import lombok.Data;
import java.util.List;
/**
* desc:文本检测返回结果
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 14:24
**/
@Data
public class ScanTaskResult {
private Integer code;
private String msg;
private String dataId;
private List<BaseScanResult> results;
}

41
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java

@ -0,0 +1,41 @@
package com.epmet.openapi.scan.support.result;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 检测结果
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:52
**/
@Data
public class SyncScanResult {
/**
* 执行成功的任务Id集合
*/
private List<String> successDataIds = new ArrayList<>();
/**
* 执行失败的任务Id集合
*/
private List<String> failDataIds = new ArrayList<>();
/**
* 本地是否全部通过
*/
private boolean isAllPass;
public boolean isAllPass() {
if (failDataIds.isEmpty() && !successDataIds.isEmpty()) {
return true;
}
return isAllPass;
}
public void setAllPass(boolean allPass) {
isAllPass = allPass;
}
}

41
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java

@ -0,0 +1,41 @@
package com.epmet.openapi.scan.support.result;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 检测结果
*
* @author jianjun liu
* @email liujianjun@yunzongnet.com
* @date 2020-06-05 10:52
**/
@Data
public class TextScanResult {
/**
* 执行成功的任务Id集合
*/
private List<String> successDataIds = new ArrayList<>();
/**
* 执行失败的任务Id集合
*/
private List<String> failDataIds = new ArrayList<>();
/**
* 本地是否全部通过
*/
private boolean isAllPass;
public boolean isAllPass() {
if (failDataIds.isEmpty() && !successDataIds.isEmpty()) {
return true;
}
return isAllPass;
}
public void setAllPass(boolean allPass) {
isAllPass = allPass;
}
}

8
epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml

@ -72,6 +72,8 @@ ribbon:
aliyun:
green:
accessKeyId: 123
accessKeySecret: 456
regionId: cn-shanghai
accessKeyId: LTAI4G6Fv6uTzQbpsayATHq4
accessKeySecret: QevMw1RYCwQUG3RSMPq1J6EAfmSblo
regionId: cn-shanghai
bizType: epmet_img_text

Loading…
Cancel
Save