|
@ -17,30 +17,43 @@ |
|
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
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.page.PageData; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
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.ArticleDao; |
|
|
|
|
|
import com.epmet.dao.DraftContentDao; |
|
|
|
|
|
import com.epmet.dao.DraftDao; |
|
|
import com.epmet.dto.ArticleDTO; |
|
|
import com.epmet.dto.ArticleDTO; |
|
|
import com.epmet.dto.feign.GovOrgSelfFeignClient; |
|
|
import com.epmet.dto.feign.GovOrgSelfFeignClient; |
|
|
import com.epmet.dto.result.ArticleGridResultDTO; |
|
|
import com.epmet.dto.result.ArticleGridResultDTO; |
|
|
|
|
|
import com.epmet.dto.form.DraftContentFromDTO; |
|
|
import com.epmet.entity.ArticleEntity; |
|
|
import com.epmet.entity.ArticleEntity; |
|
|
|
|
|
import com.epmet.entity.DraftContentEntity; |
|
|
|
|
|
import com.epmet.entity.DraftEntity; |
|
|
import com.epmet.redis.ArticleRedis; |
|
|
import com.epmet.redis.ArticleRedis; |
|
|
import com.epmet.service.ArticleService; |
|
|
import com.epmet.service.ArticleService; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
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.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 文章表 |
|
|
* 文章表 |
|
@ -55,58 +68,68 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit |
|
|
private ArticleRedis articleRedis; |
|
|
private ArticleRedis articleRedis; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private GovOrgSelfFeignClient govOrgSelfFeignClient; |
|
|
private GovOrgSelfFeignClient govOrgSelfFeignClient; |
|
|
|
|
|
private final Log logger = LogFactory.getLog(getClass()); |
|
|
@Override |
|
|
@Autowired |
|
|
public PageData<ArticleDTO> page(Map<String, Object> params) { |
|
|
private ArticleRedis articleRedis; |
|
|
IPage<ArticleEntity> page = baseDao.selectPage( |
|
|
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
@Autowired |
|
|
getWrapper(params) |
|
|
private DraftDao draftDao; |
|
|
); |
|
|
@Autowired |
|
|
return getPageData(page, ArticleDTO.class); |
|
|
private DraftContentDao draftContentDao; |
|
|
} |
|
|
@Autowired |
|
|
|
|
|
private ArticleDao articleDao; |
|
|
@Override |
|
|
|
|
|
public List<ArticleDTO> list(Map<String, Object> params) { |
|
|
@Override |
|
|
List<ArticleEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
public PageData<ArticleDTO> page(Map<String, Object> params) { |
|
|
|
|
|
IPage<ArticleEntity> page = baseDao.selectPage( |
|
|
return ConvertUtils.sourceToTarget(entityList, ArticleDTO.class); |
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
} |
|
|
getWrapper(params) |
|
|
|
|
|
); |
|
|
private QueryWrapper<ArticleEntity> getWrapper(Map<String, Object> params){ |
|
|
return getPageData(page, ArticleDTO.class); |
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
} |
|
|
|
|
|
|
|
|
QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>(); |
|
|
@Override |
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
public List<ArticleDTO> list(Map<String, Object> params) { |
|
|
|
|
|
List<ArticleEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
return wrapper; |
|
|
|
|
|
} |
|
|
return ConvertUtils.sourceToTarget(entityList, ArticleDTO.class); |
|
|
|
|
|
} |
|
|
@Override |
|
|
|
|
|
public ArticleDTO get(String id) { |
|
|
private QueryWrapper<ArticleEntity> getWrapper(Map<String, Object> params) { |
|
|
ArticleEntity entity = baseDao.selectById(id); |
|
|
String id = (String) params.get(FieldConstant.ID_HUMP); |
|
|
return ConvertUtils.sourceToTarget(entity, ArticleDTO.class); |
|
|
|
|
|
} |
|
|
QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
return wrapper; |
|
|
public void save(ArticleDTO dto) { |
|
|
} |
|
|
ArticleEntity entity = ConvertUtils.sourceToTarget(dto, ArticleEntity.class); |
|
|
|
|
|
insert(entity); |
|
|
@Override |
|
|
} |
|
|
public ArticleDTO get(String id) { |
|
|
|
|
|
ArticleEntity entity = baseDao.selectById(id); |
|
|
@Override |
|
|
return ConvertUtils.sourceToTarget(entity, ArticleDTO.class); |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
} |
|
|
public void update(ArticleDTO dto) { |
|
|
|
|
|
ArticleEntity entity = ConvertUtils.sourceToTarget(dto, ArticleEntity.class); |
|
|
@Override |
|
|
updateById(entity); |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
} |
|
|
public void save(ArticleDTO dto) { |
|
|
|
|
|
ArticleEntity entity = ConvertUtils.sourceToTarget(dto, ArticleEntity.class); |
|
|
@Override |
|
|
insert(entity); |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
} |
|
|
public void delete(String[] ids) { |
|
|
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
@Override |
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
@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 |
|
|
* @param tokenDTO |
|
@ -120,4 +143,97 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit |
|
|
return result.getData(); |
|
|
return result.getData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public String saveOrUpdateContent(DraftContentFromDTO fromDTO) { |
|
|
|
|
|
logger.debug("saveOrUpdateContent param:" + JSON.toJSONString(fromDTO)); |
|
|
|
|
|
ValidatorUtils.validateEntity(fromDTO, AddGroup.class, DefaultGroup.class); |
|
|
|
|
|
boolean havePublished = StringUtils.isBlank(fromDTO.getArticleId()) ? false : true; |
|
|
|
|
|
|
|
|
|
|
|
if (havePublished) { |
|
|
|
|
|
//TODO 校验文章是否已下线
|
|
|
|
|
|
//....
|
|
|
|
|
|
Map<String,Object> articleParamMap = new HashMap<>(); |
|
|
|
|
|
articleParamMap.put("ARTICLE_ID", fromDTO.getArticleId()); |
|
|
|
|
|
articleParamMap.put("ARTICLE_ID", fromDTO.getArticleId()); |
|
|
|
|
|
articleDao.selectByMap(articleParamMap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DraftEntity draftEntity = null; |
|
|
|
|
|
List<DraftContentEntity> 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<DraftContentEntity> buildDraftContent(DraftContentFromDTO fromDTO, boolean havePublished) { |
|
|
|
|
|
//如果已发布 则需要校验内容是否更改过 没有更改则 不对审核状态进行重置
|
|
|
|
|
|
List<DraftContentEntity> newContentList = new ArrayList<>(); |
|
|
|
|
|
Map<String, DraftContentEntity> oldContentMap = null; |
|
|
|
|
|
Map<String, Object> draftIdMap = new HashMap<>(); |
|
|
|
|
|
draftIdMap.put("DRAFT_ID", fromDTO.getDraftId()); |
|
|
|
|
|
if (havePublished) { |
|
|
|
|
|
List<DraftContentEntity> oldContentEntities = draftContentDao.selectByMap(draftIdMap); |
|
|
|
|
|
oldContentMap = oldContentEntities.stream().collect(Collectors.toMap(DraftContentEntity::getId, content -> content)); |
|
|
|
|
|
//删掉所有
|
|
|
|
|
|
draftContentDao.deleteByMap(draftIdMap); |
|
|
|
|
|
} |
|
|
|
|
|
List<DraftContentFromDTO.DraftContentDTO> contentList = fromDTO.getContentList(); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, DraftContentEntity> finalOldContentMap = oldContentMap; |
|
|
|
|
|
Set<Integer> 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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |