package com.caimei.service.auth.impl; import com.caimei.mapper.cmMapper.ArticleMapper; import com.caimei.mapper.cmMapper.AuthMapper; import com.caimei.model.ResponseJson; import com.caimei.model.po.ArticlePo; import com.caimei.model.vo.ArticleFormVo; import com.caimei.model.vo.ArticleListVo; import com.caimei.model.vo.WxArticleListVo; import com.caimei.service.auth.ArticleService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; import java.util.List; /** * Description * * @author : Aslee * @date : 2021/5/11 */ @Slf4j @Service public class ArticleServiceImpl implements ArticleService { @Resource private ArticleMapper articleMapper; @Resource private AuthMapper authMapper; @Override public ResponseJson> getArticleList(Integer listType, Integer authUserId, String articleTitle, Integer auditStatus, Integer status, Integer pageNum, Integer pageSize) { listType = null == listType ? 1 : listType; PageHelper.startPage(pageNum, pageSize); List articleList = articleMapper.getArticleList(listType, authUserId, articleTitle, auditStatus, status); PageInfo pageData = new PageInfo<>(articleList); return ResponseJson.success(pageData); } @Override public ResponseJson saveArticle(Integer articleId, Integer authUserId, String articleTitle, String articleImage, String articleContent, Integer sort) { if (null == articleId && null == authUserId) { return ResponseJson.error("参数异常,请输入供应商用户id"); } if (StringUtils.isEmpty(articleTitle)) { return ResponseJson.error("参数异常,请输入文章标题"); } if (StringUtils.isEmpty(articleImage)) { return ResponseJson.error("参数异常,请输入文章图片"); } if (StringUtils.isEmpty(articleContent)) { return ResponseJson.error("参数异常,请输入文章内容"); } if (null == sort) { return ResponseJson.error("排序值不能为空"); } boolean insertFlag = null == articleId; ArticleFormVo dbArticle = null; if (!insertFlag) { dbArticle = articleMapper.getArticleForm(articleId); } /* 组装文章数据 */ ArticlePo article = new ArticlePo(); article.setTitle(articleTitle); article.setImage(articleImage); article.setContent(articleContent); article.setSort(sort); // 供应商保存,直接上线;机构保存,需要供应商审核通过后才上线 if (null != dbArticle && 1 != dbArticle.getAuditStatus()) { // 被驳回的数据,编辑后变为待审核状态 article.setStatus(2); article.setAuditStatus(2); } else { article.setStatus(1); article.setAuditStatus(1); } Integer adminUserId = authMapper.getAdminUserId(); article.setAuditBy(adminUserId); article.setAuditTime(new Date()); article.setCheckFlag(0); if (insertFlag) { article.setAuthUserId(authUserId); article.setCreateTime(new Date()); // 插入文章 articleMapper.insertArticle(article); } else { article.setId(articleId); // 更新文章 articleMapper.updateArticleByArticleId(article); } return ResponseJson.success("保存文章成功"); } @Override public ResponseJson updateArticleStatus(Integer articleId, Integer status) { if (null == articleId) { return ResponseJson.error("请输入文章id"); } if (null == status) { return ResponseJson.error("请输入要更新的状态值"); } articleMapper.updateArticleStatusByArticleId(articleId, status); if (0 == status) { return ResponseJson.success("下线文章成功"); } else { return ResponseJson.success("上线文章成功"); } } @Override public ResponseJson deleteArticle(Integer articleId) { if (null == articleId) { return ResponseJson.error("参数异常,请输入文章id"); } // 删除文章 articleMapper.deleteArticleByArticleId(articleId); return ResponseJson.success("删除文章成功"); } @Override public ResponseJson auditArticle(Integer articleId, Integer auditStatus, String invalidReason, Integer auditBy) { if (null == articleId) { return ResponseJson.error("请输入文章id"); } if (null == auditStatus) { return ResponseJson.error("请输入审核结果"); } if (0 == auditStatus && StringUtils.isEmpty(invalidReason)) { return ResponseJson.error("请输入审核不通过的原因"); } if (null == auditBy) { return ResponseJson.error("请输入审核人用户id"); } Date auditTime = new Date(); // 授权状态更新 Integer status = null; if (0 == auditStatus) { // 审核不通过,下线文章 status = 0; } else { // 审核通过,上线文章 status = 1; } articleMapper.updateArticleAuditStatus(articleId, status, auditStatus, invalidReason, auditBy, auditTime); return ResponseJson.success("审核文章成功"); } @Override public ResponseJson getArticleFormData(Integer articleId) { if (null == articleId) { return ResponseJson.error("请输入文章id", null); } ArticleFormVo article = articleMapper.getArticleForm(articleId); if (null == article) { return ResponseJson.error("文章不存在", null); } return ResponseJson.success(article); } @Override public ResponseJson> getWxArticleList(Integer authUserId, String articleTitle, Integer pageNum, Integer pageSize) { if (null == authUserId) { return ResponseJson.error("参数异常,供应商用户id不能为空", null); } PageHelper.startPage(pageNum, pageSize); List articleList = articleMapper.getWxArticleList(authUserId, articleTitle); PageInfo pageData = new PageInfo<>(articleList); return ResponseJson.success(pageData); } @Override public ResponseJson checkArticle(Integer articleId) { articleMapper.checkArticle(articleId); return ResponseJson.success(); } @Override public ResponseJson updateSort(Integer articleId, Integer sort) { articleMapper.updateSort(articleId, sort); return null; } }