| | |
| | | package com.ruoyi.system.service.impl.config; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.domain.dto.MgtBaseGetDto; |
| | | import com.ruoyi.system.domain.dto.MgtArticleEditDto; |
| | | import com.ruoyi.system.domain.dto.MgtArticlePageDto; |
| | | import com.ruoyi.system.domain.pojo.config.Article; |
| | | import com.ruoyi.system.domain.vo.AppArticleGetVo; |
| | | import com.ruoyi.system.domain.vo.AppArticlePageVo; |
| | | import com.ruoyi.system.domain.vo.MgtArticleGetVo; |
| | | import com.ruoyi.system.domain.vo.MgtArticlePageVo; |
| | | import com.ruoyi.system.mapper.config.ArticleMapper; |
| | | import com.ruoyi.system.service.config.ArticleService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService { |
| | | |
| | | @Resource |
| | | private ArticleMapper articleMapper; |
| | | |
| | | /** |
| | | * @description 删除文章分类 |
| | | * @author jqs |
| | | * @date 2023/6/8 10:40 |
| | | * @param classId |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void deleteArticleClass(Long classId){ |
| | | articleMapper.deleteArticleClass(classId); |
| | | } |
| | | |
| | | /** |
| | | * @description 分页获取文章列表 |
| | | * @author jqs |
| | | * @date 2023/6/9 11:08 |
| | | * @param page |
| | | * @param mgtArticlePageDto |
| | | * @return List<MgtArticlePageVo> |
| | | */ |
| | | @Override |
| | | public List<MgtArticlePageVo> pageArticle(Page page, MgtArticlePageDto mgtArticlePageDto){ |
| | | return articleMapper.pageArticle(page, mgtArticlePageDto); |
| | | } |
| | | |
| | | /** |
| | | * @description 修改文章 |
| | | * @author jqs |
| | | * @date 2023/6/9 11:45 |
| | | * @param mgtArticleEditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void editMgtArticle(MgtArticleEditDto mgtArticleEditDto){ |
| | | Article article; |
| | | Article articleSame = this.getOne(new LambdaQueryWrapper<Article>().eq(Article::getDelFlag,0).eq(Article::getArticleTitle,mgtArticleEditDto.getArticleTitle()),false); |
| | | if(mgtArticleEditDto.getArticleId()!=null){ |
| | | if(articleSame!=null&&!articleSame.getArticleId().equals(mgtArticleEditDto.getArticleId())){ |
| | | throw new ServiceException(AppErrorConstant.ARTICLE_DOUBLE); |
| | | } |
| | | article = this.getById(mgtArticleEditDto.getArticleId()); |
| | | }else{ |
| | | if(articleSame!=null){ |
| | | throw new ServiceException(AppErrorConstant.ARTICLE_DOUBLE); |
| | | } |
| | | article = new Article(); |
| | | article.setDelFlag(0); |
| | | article.setCreateTime(new Date()); |
| | | article.setCreateUserId(mgtArticleEditDto.getUserId()); |
| | | } |
| | | article.setClassId(mgtArticleEditDto.getClassId()); |
| | | article.setArticleSort(mgtArticleEditDto.getArticleSort()); |
| | | article.setArticleTitle(mgtArticleEditDto.getArticleTitle()); |
| | | article.setArticleIntroduce(mgtArticleEditDto.getArticleIntroduce()); |
| | | article.setArticleDetail(mgtArticleEditDto.getArticleDetail()); |
| | | article.setArticleCover(mgtArticleEditDto.getArticleCover()); |
| | | article.setArticleVideo(mgtArticleEditDto.getArticleVideo()); |
| | | article.setUpdateTime(new Date()); |
| | | article.setUpdateUserId(mgtArticleEditDto.getUserId()); |
| | | this.saveOrUpdate(article); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 删除文章 |
| | | * @author jqs |
| | | * @date 2023/6/9 15:06 |
| | | * @param mgtBaseGetDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void deleteArticle(MgtBaseGetDto mgtBaseGetDto){ |
| | | Article article = this.getById(Long.valueOf(mgtBaseGetDto.getId())); |
| | | article.setDelFlag(1); |
| | | article.setUpdateTime(new Date()); |
| | | article.setUpdateUserId(mgtBaseGetDto.getUserId()); |
| | | this.saveOrUpdate(article); |
| | | } |
| | | |
| | | /** |
| | | * @description 获取文章 |
| | | * @author jqs |
| | | * @date 2023/7/13 11:00 |
| | | * @param articleId |
| | | * @return MgtArticleGetVo |
| | | */ |
| | | @Override |
| | | public MgtArticleGetVo getArticle(Long articleId){ |
| | | MgtArticleGetVo mgtArticleGetVo = new MgtArticleGetVo(); |
| | | Article article = this.getById(articleId); |
| | | BeanUtils.copyProperties(article,mgtArticleGetVo); |
| | | return mgtArticleGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 通过分类id获取文章 |
| | | * @author jqs |
| | | * @date 2023/7/13 11:37 |
| | | * @param classId |
| | | * @return List<AppClassListVo> |
| | | */ |
| | | @Override |
| | | public List<AppArticlePageVo> listArticleByClass(Page page, Long classId){ |
| | | return articleMapper.listArticleByClass(page, classId); |
| | | } |
| | | |
| | | /** |
| | | * @description |
| | | * @author jqs |
| | | * @date 2023/7/13 11:57 |
| | | * @param articleId |
| | | * @return AppArticleGetVo |
| | | */ |
| | | @Override |
| | | public AppArticleGetVo getAppArticle (Long articleId){ |
| | | AppArticleGetVo appArticleGetVo = new AppArticleGetVo(); |
| | | Article article = this.getById(articleId); |
| | | BeanUtils.copyProperties(article,appArticleGetVo); |
| | | return appArticleGetVo; |
| | | } |
| | | } |