| | |
| | | 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.StringUtils; |
| | | 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.nio.charset.StandardCharsets; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private ArticleMapper articleMapper; |
| | | |
| | | |
| | | /** |
| | | * @description 删除文章分类 |
| | | * @author jqs |
| | |
| | | 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 Long editMgtArticle(MgtArticleEditDto mgtArticleEditDto){ |
| | | // 创建Article对象 |
| | | Article article; |
| | | Long oldClassId = null; |
| | | // 根据文章标题查询文章是否存在 |
| | | Article articleSame = this.getOne(new LambdaQueryWrapper<Article>() |
| | | .eq(Article::getDelFlag, 0) |
| | | .eq(Article::getArticleTitle, mgtArticleEditDto.getArticleTitle()), false); |
| | | // 如果文章ID不为空 |
| | | if (mgtArticleEditDto.getArticleId() != null) { |
| | | // 如果存在相同标题的文章并且文章ID不同,则抛出异常 |
| | | if (articleSame != null && !articleSame.getArticleId().equals(mgtArticleEditDto.getArticleId())) { |
| | | throw new ServiceException(AppErrorConstant.ARTICLE_DOUBLE); |
| | | } |
| | | // 根据文章ID获取文章对象 |
| | | article = this.getById(mgtArticleEditDto.getArticleId()); |
| | | oldClassId = article.getClassId(); |
| | | } |
| | | // 如果文章ID为空 |
| | | else { |
| | | // 如果存在相同标题的文章,则抛出异常 |
| | | if (articleSame != null) { |
| | | throw new ServiceException(AppErrorConstant.ARTICLE_DOUBLE); |
| | | } |
| | | // 创建新的文章对象 |
| | | article = new Article(); |
| | | article.setDelFlag(0); |
| | | article.setCreateTime(new Date()); |
| | | article.setCreateUserId(mgtArticleEditDto.getUserId()); |
| | | } |
| | | // 设置文章的类别ID、排序、标题、简介、封面、视频、更新时间和更新用户ID |
| | | article.setClassId(mgtArticleEditDto.getClassId()); |
| | | article.setArticleSort(mgtArticleEditDto.getArticleSort()); |
| | | article.setArticleTitle(mgtArticleEditDto.getArticleTitle()); |
| | | article.setArticleIntroduce(mgtArticleEditDto.getArticleIntroduce()); |
| | | article.setArticleCover(mgtArticleEditDto.getArticleCover()); |
| | | article.setArticleVideo(mgtArticleEditDto.getArticleVideo()); |
| | | article.setUpdateTime(new Date()); |
| | | article.setUpdateUserId(mgtArticleEditDto.getUserId()); |
| | | // 处理文章详情 |
| | | String articleDetail = mgtArticleEditDto.getArticleDetail(); |
| | | if (StringUtils.isNotBlank(articleDetail)) { |
| | | byte[] decodedBytes = Base64.getDecoder().decode(articleDetail); |
| | | articleDetail = new String(decodedBytes, StandardCharsets.UTF_8); |
| | | article.setArticleDetail(articleDetail); |
| | | } |
| | | // 保存或更新文章 |
| | | this.saveOrUpdate(article); |
| | | return oldClassId; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 删除文章 |
| | | * @author jqs |
| | | * @date 2023/6/9 15:06 |
| | | * @param mgtBaseGetDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public Long 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); |
| | | return article.getClassId(); |
| | | } |
| | | |
| | | /** |
| | | * @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; |
| | | } |
| | | } |