From d3c982088fe7fd6f58775e4e2daf702c7e924d18 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 2 Jun 2020 16:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9publisherType=E7=B1=BB=E5=9E=8B;=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=86=85=E5=AE=B9=E6=8E=A5=E5=8F=A3=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/dto/ArticleDTO.java | 5 +- .../src/main/java/com/epmet/dto/DraftDTO.java | 5 +- .../epmet/dto/form/DraftContentFromDTO.java | 98 ++++++++ .../epmet/controller/ArticleController.java | 14 +- .../controller/DraftContentController.java | 2 +- .../java/com/epmet/entity/ArticleEntity.java | 2 +- .../java/com/epmet/entity/DraftEntity.java | 2 +- .../java/com/epmet/excel/ArticleExcel.java | 2 +- .../main/java/com/epmet/excel/DraftExcel.java | 2 +- .../com/epmet/service/ArticleService.java | 8 + .../service/impl/ArticleServiceImpl.java | 226 +++++++++++++----- 11 files changed, 301 insertions(+), 65 deletions(-) create mode 100644 epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftContentFromDTO.java diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/ArticleDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/ArticleDTO.java index 79cb1bb2bd..4c72866e27 100644 --- a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/ArticleDTO.java +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/ArticleDTO.java @@ -17,9 +17,10 @@ package com.epmet.dto; +import lombok.Data; + import java.io.Serializable; import java.util.Date; -import lombok.Data; /** @@ -81,7 +82,7 @@ public class ArticleDTO implements Serializable { /** * 发布单位类型 机关:agency;部门:department;网格:grid */ - private Integer publisherType; + private String publisherType; /** * 发布时间 diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/DraftDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/DraftDTO.java index 0e4ebd954b..c7a383a56d 100644 --- a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/DraftDTO.java +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/DraftDTO.java @@ -17,9 +17,10 @@ package com.epmet.dto; +import lombok.Data; + import java.io.Serializable; import java.util.Date; -import lombok.Data; /** @@ -76,7 +77,7 @@ public class DraftDTO implements Serializable { /** * 发布单位类型 机关:agency;部门:department;网格:grid */ - private Integer publisherType; + private String publisherType; /** * 发布时间 diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftContentFromDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftContentFromDTO.java new file mode 100644 index 0000000000..81d39fa698 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftContentFromDTO.java @@ -0,0 +1,98 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + + +/** + * 保存文章内容form + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-06-02 + */ +@Data +public class DraftContentFromDTO implements Serializable { + + + private static final long serialVersionUID = -4206020151361420221L; + /** + * 文章ID 重新编辑时必填 + */ + private String articleId; + + /** + * 客户ID + */ + private String customerId; + + /** + * 草稿ID + */ + private String draftId; + + /** + * 文章标题 + */ + @NotBlank(message = "文章标题不能为空") + private String title; + + /** + * 内容列表 + */ + private List contentList; + + @Data + public static class DraftContentDTO { + public DraftContentDTO() { + } + + /** + * 内容Id + */ + private String draftId; + /** + * 内容 + */ + private String content; + + /** + * 内容类型 图片:img;文字:text + */ + private String contentType; + + /** + * 审核状态 通过:pass;失败:fail; + */ + private String auditStatus; + + /** + * 审核理由 + */ + private String auditReason; + + /** + * 内容顺序 从1开始 + */ + private Integer orderNum; + } +} \ No newline at end of file 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 ed34ef585d..e72213a34d 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 @@ -25,12 +25,13 @@ 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.UpdateGroup; 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.LatestListFormDTO; import com.epmet.dto.result.ArticleGridResultDTO; import com.epmet.dto.result.LatestListResultDTO; +import com.epmet.dto.form.DraftContentFromDTO; import com.epmet.excel.ArticleExcel; import com.epmet.service.ArticleService; import org.springframework.beans.factory.annotation.Autowired; @@ -107,4 +108,15 @@ public class ArticleController { return new Result().ok(articleService.agencyGridList(tokenDTO)); } + /** + * desc:保存或修改文章内容 + * @param fromDTO + * @throws Exception + */ + @GetMapping("savecontent") + public Result savecontent(@RequestBody DraftContentFromDTO fromDTO) throws Exception { + String draftId = articleService.saveOrUpdateContent(fromDTO); + return new Result().ok(draftId); + } + } \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/DraftContentController.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/DraftContentController.java index c05fda4cc7..82243e0e48 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/DraftContentController.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/DraftContentController.java @@ -23,8 +23,8 @@ 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.UpdateGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.DraftContentDTO; import com.epmet.excel.DraftContentExcel; import com.epmet.service.DraftContentService; diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleEntity.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleEntity.java index 5768366568..eb2b026fb7 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleEntity.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleEntity.java @@ -81,7 +81,7 @@ public class ArticleEntity extends BaseEpmetEntity { /** * 发布单位类型 机关:agency;部门:department;网格:grid */ - private Integer publisherType; + private String publisherType; /** * 发布时间 diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/DraftEntity.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/DraftEntity.java index d7fd299501..b3c7fd96b6 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/DraftEntity.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/DraftEntity.java @@ -76,7 +76,7 @@ public class DraftEntity extends BaseEpmetEntity { /** * 发布单位类型 机关:agency;部门:department;网格:grid */ - private Integer publisherType; + private String publisherType; /** * 发布时间 diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/ArticleExcel.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/ArticleExcel.java index d1c47ccefb..a5f28f84a3 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/ArticleExcel.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/ArticleExcel.java @@ -59,7 +59,7 @@ public class ArticleExcel { private String publisherName; @Excel(name = "发布单位类型 机关:agency;部门:department;网格:grid") - private Integer publisherType; + private String publisherType; @Excel(name = "发布时间") private Date publishDate; diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/DraftExcel.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/DraftExcel.java index 55cc07b78c..6f913525d7 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/DraftExcel.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/excel/DraftExcel.java @@ -56,7 +56,7 @@ public class DraftExcel { private String publisherName; @Excel(name = "发布单位类型 机关:agency;部门:department;网格:grid") - private Integer publisherType; + private String publisherType; @Excel(name = "发布时间") private Date publishDate; diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java index 10d6d9adb9..9cae7ed196 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java @@ -22,6 +22,7 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.dto.ArticleDTO; import com.epmet.dto.result.ArticleGridResultDTO; +import com.epmet.dto.form.DraftContentFromDTO; import com.epmet.entity.ArticleEntity; import java.util.List; @@ -102,4 +103,11 @@ public interface ArticleService extends BaseService { * @Description 党建声音-政府端-可选发布范围 **/ ArticleGridResultDTO agencyGridList(TokenDto tokenDTO); + + /** + * desc:保存或修改文章内容 + * @param fromDTO + * @return + */ + String saveOrUpdateContent(DraftContentFromDTO fromDTO); } \ No newline at end of file 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 f1ea163a90..3b082d2776 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 @@ -17,30 +17,43 @@ 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.FieldConstant; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.utils.Result; +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.dao.ArticleDao; +import com.epmet.dao.DraftContentDao; +import com.epmet.dao.DraftDao; import com.epmet.dto.ArticleDTO; import com.epmet.dto.feign.GovOrgSelfFeignClient; import com.epmet.dto.result.ArticleGridResultDTO; +import com.epmet.dto.form.DraftContentFromDTO; import com.epmet.entity.ArticleEntity; +import com.epmet.entity.DraftContentEntity; +import com.epmet.entity.DraftEntity; import com.epmet.redis.ArticleRedis; import com.epmet.service.ArticleService; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.util.CollectionUtils; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * 文章表 @@ -55,58 +68,68 @@ public class ArticleServiceImpl extends BaseServiceImpl page(Map params) { - IPage page = baseDao.selectPage( - getPage(params, FieldConstant.CREATED_TIME, false), - getWrapper(params) - ); - return getPageData(page, ArticleDTO.class); - } - - @Override - public List list(Map params) { - List entityList = baseDao.selectList(getWrapper(params)); - - return ConvertUtils.sourceToTarget(entityList, ArticleDTO.class); - } - - private QueryWrapper getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); - - QueryWrapper 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)); - } + private final Log logger = LogFactory.getLog(getClass()); + @Autowired + private ArticleRedis articleRedis; + + @Autowired + private DraftDao draftDao; + @Autowired + private DraftContentDao draftContentDao; + @Autowired + private ArticleDao articleDao; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, ArticleDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, ArticleDTO.class); + } + + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); + + QueryWrapper 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 @@ -120,4 +143,97 @@ public class ArticleServiceImpl extends BaseServiceImpl articleParamMap = new HashMap<>(); + articleParamMap.put("ARTICLE_ID", fromDTO.getArticleId()); + articleParamMap.put("ARTICLE_ID", fromDTO.getArticleId()); + articleDao.selectByMap(articleParamMap); + } + + DraftEntity draftEntity = null; + List draftContentList = null; + if (StringUtils.isNotBlank(fromDTO.getDraftId())) { + //TODO + + draftEntity = draftDao.selectById(fromDTO.getDraftId()); + if (draftEntity == null) { + logger.warn("saveOrUpdateContent draftId is not exist in db"); + throw new RenException("参数错误"); + } + draftEntity.setTitle(draftEntity.getTitle()); + draftEntity.setUpdatedTime(new Date()); + draftDao.updateById(draftEntity); + + } else { + draftEntity = new DraftEntity(); + draftEntity.setTitle(fromDTO.getTitle()); + draftDao.insert(draftEntity); + } + + if (CollectionUtils.isEmpty(draftContentList)) { + logger.warn("saveOrUpdateContent contentList is empty"); + throw new RenException("参数错误"); + } + draftContentList = buildDraftContent(fromDTO, havePublished); + //TODO 改为批量插入 + draftContentList.forEach(content -> draftContentDao.insert(content)); + + String draftId = draftEntity.getId(); + + + return null; + } + + /** + * desc:构建 内容对象 + * + * @param fromDTO + * @param havePublished + * @return + */ + private List buildDraftContent(DraftContentFromDTO fromDTO, boolean havePublished) { + //如果已发布 则需要校验内容是否更改过 没有更改则 不对审核状态进行重置 + List newContentList = new ArrayList<>(); + Map oldContentMap = null; + Map draftIdMap = new HashMap<>(); + draftIdMap.put("DRAFT_ID", fromDTO.getDraftId()); + if (havePublished) { + List oldContentEntities = draftContentDao.selectByMap(draftIdMap); + oldContentMap = oldContentEntities.stream().collect(Collectors.toMap(DraftContentEntity::getId, content -> content)); + //删掉所有 + draftContentDao.deleteByMap(draftIdMap); + } + List contentList = fromDTO.getContentList(); + + Map finalOldContentMap = oldContentMap; + Set orderNumSet = new HashSet<>(); + contentList.forEach(content -> { + if (finalOldContentMap != null && finalOldContentMap.get(content.getDraftId()) != null) { + DraftContentEntity oldContent = finalOldContentMap.get(content.getDraftId()); + if (oldContent.getContent().equals(content.getContent())) { + content.setAuditReason(oldContent.getAuditReason()); + content.setAuditStatus(oldContent.getAuditStatus()); + } + } + DraftContentEntity entity = ConvertUtils.sourceToTarget(content, DraftContentEntity.class); + entity.setId(content.getDraftId()); + orderNumSet.add(content.getOrderNum()); + newContentList.add(entity); + }); + if (orderNumSet.size() != newContentList.size()) { + logger.warn("saveOrUpdateContent contentList orderNum is repeat"); + throw new RenException("参数错误"); + } + return newContentList; + } + } \ No newline at end of file