| | |
| | | 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.api.domain.dto.MgtClassNumDto; |
| | | 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.MgtArticlePageVo; |
| | | import com.ruoyi.system.mapper.config.ArticleMapper; |
| | | import com.ruoyi.system.service.config.ArticleService; |
| | | import com.ruoyi.system.service.config.SysClassificationService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private ArticleMapper articleMapper; |
| | | |
| | | @Resource |
| | | private SysClassificationService sysClassificationService; |
| | | |
| | | /** |
| | | * @description 删除文章分类 |
| | |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void editMgtArticle(MgtArticleEditDto mgtArticleEditDto){ |
| | | // 创建MgtClassNumDto对象 |
| | | MgtClassNumDto mgtClassNumDto = new MgtClassNumDto(); |
| | | public Long editMgtArticle(MgtArticleEditDto mgtArticleEditDto){ |
| | | // 创建Article对象 |
| | | Article article; |
| | | Long oldClassId = null; |
| | | // 根据文章标题查询文章是否存在 |
| | | Article articleSame = this.getOne(new LambdaQueryWrapper<Article>() |
| | | .eq(Article::getDelFlag, 0) |
| | |
| | | } |
| | | // 根据文章ID获取文章对象 |
| | | article = this.getById(mgtArticleEditDto.getArticleId()); |
| | | // 如果类别ID不为空并且文章的类别ID不为空并且类别ID不同,则设置子类别ID和新增类别ID |
| | | if (mgtArticleEditDto.getClassId() != null && article.getClassId() != null |
| | | && !mgtArticleEditDto.getClassId().equals(article.getClassId())) { |
| | | mgtClassNumDto.setSubClassId(article.getClassId()); |
| | | mgtClassNumDto.setAddClassId(mgtArticleEditDto.getClassId()); |
| | | } |
| | | // 如果类别ID不为空并且文章的类别ID为空,则设置新增类别ID |
| | | else if (mgtArticleEditDto.getClassId() != null && article.getClassId() == null) { |
| | | mgtClassNumDto.setAddClassId(mgtArticleEditDto.getClassId()); |
| | | } |
| | | oldClassId = article.getClassId(); |
| | | } |
| | | // 如果文章ID为空 |
| | | else { |
| | |
| | | article.setDelFlag(0); |
| | | article.setCreateTime(new Date()); |
| | | article.setCreateUserId(mgtArticleEditDto.getUserId()); |
| | | mgtClassNumDto.setAddClassId(mgtArticleEditDto.getClassId()); |
| | | } |
| | | // 设置文章的类别ID、排序、标题、简介、封面、视频、更新时间和更新用户ID |
| | | article.setClassId(mgtArticleEditDto.getClassId()); |
| | |
| | | } |
| | | // 保存或更新文章 |
| | | this.saveOrUpdate(article); |
| | | // 更新类别数量 |
| | | sysClassificationService.changeClassNum(mgtClassNumDto); |
| | | return oldClassId; |
| | | } |
| | | |
| | | |
| | |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void deleteArticle(MgtBaseGetDto mgtBaseGetDto){ |
| | | 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); |
| | | if(article.getClassId()!=null){ |
| | | MgtClassNumDto mgtClassNumDto = new MgtClassNumDto(); |
| | | mgtClassNumDto.setSubClassId(article.getClassId()); |
| | | sysClassificationService.changeClassNum(mgtClassNumDto); |
| | | } |
| | | |
| | | return article.getClassId(); |
| | | } |
| | | |
| | | /** |