diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java index 5085c4aebe..439997d264 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java @@ -36,7 +36,6 @@ import java.util.Set; * @author: jianjun liu */ @Slf4j -@Component public class HttpClientManager { private static int connectionTimeout = 3000;// 连接超时时间,毫秒 private static int soTimeout = 10000;// 读取数据超时时间,毫秒 diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java index 2302087e72..e8b9506a9a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java @@ -8,7 +8,6 @@ import com.epmet.commons.tools.scan.param.TextScanParamDTO; import com.epmet.commons.tools.scan.result.SyncScanResult; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; /** * 扫描内容工具类 @@ -18,7 +17,6 @@ import org.springframework.stereotype.Component; * @date 2020-06-08 8:28 **/ @Slf4j -@Component public class ScanContentUtils { /** * desc:图片同步扫描 @@ -26,7 +24,7 @@ public class ScanContentUtils { * @return */ public static SyncScanResult imgSyncScan(String url, ImgScanParamDTO param) { - log.debug("imgSyncScan param:",JSON.toJSONString(param)); + log.debug("imgSyncScan param:", JSON.toJSONString(param)); if (StringUtils.isBlank(url) || param == null) { throw new RenException("参数错误"); } @@ -47,7 +45,7 @@ public class ScanContentUtils { * @return */ public static SyncScanResult textSyncScan(String url, TextScanParamDTO param) { - log.debug("textSyncScan param:",JSON.toJSONString(param)); + log.debug("textSyncScan param:", JSON.toJSONString(param)); if (StringUtils.isBlank(url) || param == null) { throw new RenException("参数错误"); } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java index 9c6edf5307..1793b368f4 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java @@ -20,8 +20,6 @@ package com.epmet.controller; 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.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.scan.result.SyncScanResult; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; @@ -32,6 +30,7 @@ import com.epmet.dto.result.*; import com.epmet.service.ArticleOperateRecordService; import com.epmet.service.ArticleService; import com.epmet.service.DraftService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.web.bind.annotation.PostMapping; @@ -48,6 +47,7 @@ import java.util.List; * @author generator generator@elink-cn.com * @since v1.0.0 2020-06-02 */ +@Slf4j @RestController @RequestMapping("article") public class ArticleController { @@ -217,24 +217,23 @@ public class ArticleController { @RequirePermission(requirePermission = RequirePermissionEnum.WORK_PARTY_VOICE_PUBLISH) public Result publishArticle(@LoginUser TokenDto tokenDto, @RequestBody PublishArticleFormDTO formDTO) throws Exception { Boolean isSuccess = articleService.publish(tokenDto, formDTO.getDraftId()); - if (isSuccess){ - scanContent(tokenDto,formDTO.getDraftId()); + if (isSuccess) { + scanContent(tokenDto, formDTO.getDraftId()); } return new Result().ok(isSuccess); } @Async public void scanContent(TokenDto tokenDto,String draftId){ - SyncScanResult syncScanResult = articleService.scanContent(tokenDto,draftId); - if (syncScanResult == null){ - throw new RenException(EpmetErrorCode.ARTICLE_PUBLISH_ERROR.getCode(),EpmetErrorCode.ARTICLE_PUBLISH_ERROR.getMsg()); + SyncScanResult syncScanResult = articleService.scanContent(tokenDto, draftId); + if (syncScanResult == null) { + log.error("scanContent draftId:{} return result null", draftId); } - if (syncScanResult.isAllPass()){ - articleService.scanAllPassPublishArticle(tokenDto,draftId); - }else{ - articleService.updateAuditStatusFailById(draftId,syncScanResult); + if (syncScanResult.isAllPass()) { + articleService.scanAllPassPublishArticle(tokenDto, draftId); + } else { + articleService.updateAuditStatusFailById(draftId, syncScanResult); } - } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java index ebbc37bd9a..6e66fe252a 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java @@ -847,16 +847,16 @@ public class ArticleServiceImpl extends BaseServiceImpl NumConstant.ZERO){ draftContents.forEach(content -> { - content.setOrderNum(order+NumConstant.ONE); + content.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS); + + content.setOrderNum(content.getOrderNum()); ArticleContentEntity contentToInsert = ConvertUtils.sourceToTarget(content,ArticleContentEntity.class); contentToInsert.setArticleId(article.getId()); contentToInsert.setId(null); articleContentDao.insert(contentToInsert); - content.setAuditStatus(ModuleConstant.AUDIT_STATUS_PASS); draftContentDao.updateById(content); }); } @@ -868,12 +868,13 @@ public class ArticleServiceImpl extends BaseServiceImpl 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()); - textScanParamDTO.getTasks().add(textTaskDTO); - }else if (DraftConstant.IMG.equals(contentType)){ - ImgTaskDTO taskDTO = new ImgTaskDTO(); - taskDTO.setDataId(content.getId()); - taskDTO.setUrl(content.getContent()); - imgScanParamDTO.getTasks().add(taskDTO); - } - }); + if (!isOk) { + this.sendMsg(draftEntity.getTitle(), String.format(ModuleConstant.MSG_ARTICLE_PUBLISH_ERROR, draftEntity.getTitle())); + this.updateDraftPublishStatus(draftId, DraftConstant.AUDITFAIL); + return null; } - SyncScanResult imgSyncScanResult = null; - SyncScanResult textSyncScanResult = null; + SyncScanResult result = null; try { + 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 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()); + textScanParamDTO.getTasks().add(textTaskDTO); + } else if (DraftConstant.IMG.equals(contentType)) { + ImgTaskDTO taskDTO = new ImgTaskDTO(); + taskDTO.setDataId(content.getId()); + taskDTO.setUrl(content.getContent()); + imgScanParamDTO.getTasks().add(taskDTO); + } + }); + } + SyncScanResult imgSyncScanResult = null; + SyncScanResult textSyncScanResult = null; + log.info("scanContent imgScanParamDTO:{}", JSON.toJSONString(imgScanParamDTO)); log.info("scanContent textScanParamDTO:{}", JSON.toJSONString(textScanParamDTO)); - imgSyncScanResult = ScanContentUtils.imgSyncScan(scanApiHost.concat(imgSyncScanMethod),imgScanParamDTO); - textSyncScanResult = ScanContentUtils.textSyncScan(scanApiHost.concat(textSyncScanMethod),textScanParamDTO); + imgSyncScanResult = ScanContentUtils.imgSyncScan(scanApiHost.concat(imgSyncScanMethod), imgScanParamDTO); + textSyncScanResult = ScanContentUtils.textSyncScan(scanApiHost.concat(textSyncScanMethod), textScanParamDTO); + + 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()); + } } catch (Exception e) { - log.error("scanContent exception",e); - this.sendMsg(draftEntity.getTitle(),String.format(ModuleConstant.MSG_ARTICLE_PUBLISH_ERROR, draftEntity.getTitle())); - this.updateDraftPublishStatus(draftId,DraftConstant.AUDITFAIL); - } - SyncScanResult result = new SyncScanResult(); - if (imgSyncScanResult.isAllPass()){ - result.setAllPass(imgSyncScanResult.isAllPass()); - result.getSuccessDataIds().addAll(imgSyncScanResult.getSuccessDataIds()); - result.getFailDataIds().addAll(imgSyncScanResult.getFailDataIds()); + log.error("scanContent exception", e); + this.sendMsg(draftEntity.getTitle(), String.format(ModuleConstant.MSG_ARTICLE_PUBLISH_ERROR, draftEntity.getTitle())); + this.updateDraftPublishStatus(draftId, DraftConstant.AUDITFAIL); } - 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()); + if (draft == null) { + log.error("scanAllPassPublishArticle draftId:{} is not exist in db", draftId); + throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); } try { //审核通过 - ArticleEntity articleEntity = this.publishDraftToArticle(draft); + this.publishDraftToArticle(draft); UpdateCustomerTagCacheDTO updateCustomerTagCacheDTO = this.updateCustomerTag(tokenDto, draftId); List updateGridTagCacheDTOS = this.updateGridTag(tokenDto, draftId, updateCustomerTagCacheDTO); - this.addArticleTags(updateCustomerTagCacheDTO,draftId,tokenDto); + this.addArticleTags(updateCustomerTagCacheDTO, draftId, tokenDto); //更新redis try { @@ -990,32 +1001,42 @@ public class ArticleServiceImpl extends BaseServiceImpl 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); - } - }); - List successDataIds = syncScanResult.getSuccessDataIds(); - successDataIds.forEach(id->{ - if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX)>=0){ - draftCoverDao.updateAuditStatusById(id,ModuleConstant.AUDIT_STATUS_PASS); - }else{ - draftContentDao.updateAuditStatusById(id,ModuleConstant.AUDIT_STATUS_PASS); - } - }); + DraftEntity draft = draftDao.selectById(draftId); + if (draft == null) { + log.error("updateAuditStatusFailById draftId:{} is not exist in db", draftId); + throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); + } + try { + List failDataIds = syncScanResult.getFailDataIds(); + failDataIds.forEach(id -> { + if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX) >= NumConstant.ZERO) { + draftCoverDao.updateAuditStatusById(id, ModuleConstant.AUDIT_STATUS_FAIL); + } else { + draftContentDao.updateAuditStatusById(id, ModuleConstant.AUDIT_STATUS_FAIL); + } + }); + List successDataIds = syncScanResult.getSuccessDataIds(); + successDataIds.forEach(id -> { + if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX) >= 0) { + draftCoverDao.updateAuditStatusById(id, ModuleConstant.AUDIT_STATUS_PASS); + } else { + draftContentDao.updateAuditStatusById(id, ModuleConstant.AUDIT_STATUS_PASS); + } + }); + } catch (Exception e) { + log.error("scanAllPassPublishArticle update db exception", e); + this.sendMsg(draft.getTitle(), String.format(ModuleConstant.MSG_ARTICLE_PUBLISH_ERROR, draft.getTitle())); + this.updateDraftPublishStatus(draftId, DraftConstant.AUDITFAIL); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } } @Override @@ -1158,7 +1179,6 @@ public class ArticleServiceImpl extends BaseServiceImpl addArticleTags = new ArrayList<>(); List tagsInfo = formDto.getTagsInfo();