| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddArticleDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminArticleDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminArticleVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeArticleInfoVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | @Resource |
| | | private ColumnMapper columnMapper; |
| | | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | @Override |
| | | public Result getArticleInPage(AdminArticleDto adminArticleDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long belongId = userlogin.getBelongId() == null ? 0L : userlogin.getBelongId(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | Page<AdminArticleVo> page = new Page<>(adminArticleDto.getPageNum(), adminArticleDto.getPageSize()); |
| | | ArticleEntity articleEntity = new ArticleEntity(); |
| | | Long columnId = adminArticleDto.getColumnId() == null ? 0L : adminArticleDto.getColumnId(); |
| | |
| | | if(StrUtil.isNotEmpty(title)){ |
| | | articleEntity.setTitle(title); |
| | | } |
| | | articleEntity.setBelongId(belongId); |
| | | if(UserEntity.USER_BELONG_TOP != companyId){ |
| | | articleEntity.setCompanyId(companyId); |
| | | } |
| | | IPage<AdminArticleVo> list = this.baseMapper.selectAdminArticleInPage(page,articleEntity); |
| | | return Result.ok(list); |
| | | } |
| | |
| | | @Transactional |
| | | public Result addArticle(AdminAddArticleDto adminAddArticleDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long belongId = userlogin.getBelongId() == null ? 0L : userlogin.getBelongId(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | ArticleEntity articleEntity = new ArticleEntity(); |
| | | articleEntity.setBelongId(belongId); |
| | | articleEntity.setCompanyId(companyId); |
| | | String title = adminAddArticleDto.getTitle(); |
| | | if(StrUtil.isEmpty(title)){ |
| | | return Result.fail("请输入文章标题"); |
| | | } |
| | | articleEntity.setTitle(title); |
| | | String childTitle = adminAddArticleDto.getChildTitle(); |
| | | if(StrUtil.isNotEmpty(childTitle)){ |
| | | articleEntity.setChildTitle(childTitle); |
| | | } |
| | | String author = adminAddArticleDto.getAuthor(); |
| | | if(StrUtil.isNotEmpty(author)){ |
| | | articleEntity.setAuthor(author); |
| | | } |
| | | String authorBelong = adminAddArticleDto.getAuthorBelong(); |
| | | articleEntity.setAuthorBelong(authorBelong); |
| | | String remark = adminAddArticleDto.getRemark(); |
| | | if(StrUtil.isNotEmpty(remark)){ |
| | | articleEntity.setRemark(remark); |
| | | } |
| | | long columnId = adminAddArticleDto.getColumnId() == null ? 0L : adminAddArticleDto.getColumnId(); |
| | | if(columnId == 0L){ |
| | | return Result.fail("请选择文章栏目"); |
| | | } |
| | | ColumnEntity columnEntity = columnMapper.selectById(columnId); |
| | | if(ObjectUtil.isEmpty(columnEntity)){ |
| | | return Result.fail("请选择文章栏目"); |
| | |
| | | Integer visits = adminAddArticleDto.getVisits() == null ? 0 : adminAddArticleDto.getVisits(); |
| | | articleEntity.setVisits(visits); |
| | | String mainDiagram = adminAddArticleDto.getMainDiagram(); |
| | | if(StrUtil.isNotEmpty(mainDiagram)){ |
| | | articleEntity.setMainDiagram(mainDiagram); |
| | | } |
| | | String atlas = adminAddArticleDto.getAtlas(); |
| | | if(StrUtil.isNotEmpty(atlas)){ |
| | | articleEntity.setAtlas(atlas); |
| | | } |
| | | Date releaseTime = adminAddArticleDto.getReleaseTime(); |
| | | if(ObjectUtil.isNotEmpty(releaseTime)){ |
| | | articleEntity.setReleaseTime(releaseTime); |
| | | } |
| | | Integer isTop = adminAddArticleDto.getIsTop(); |
| | | articleEntity.setIsTop(isTop); |
| | | Integer releaseStatus = adminAddArticleDto.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String articleDetails = adminAddArticleDto.getArticleDetails(); |
| | | if(StrUtil.isNotEmpty(articleDetails)){ |
| | | articleEntity.setArticleDetails(articleDetails); |
| | | } |
| | | |
| | | String uploadFile = adminAddArticleDto.getUploadFile(); |
| | | articleEntity.setUploadFile(uploadFile); |
| | | this.baseMapper.insert(articleEntity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | | } |
| | | articleEntity.getReleaseStatus(); |
| | | Integer isTop = adminUpdateArticleDto.getIsTop(); |
| | | articleEntity.setIsTop(isTop); |
| | | Integer releaseStatus = adminUpdateArticleDto.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String title = adminUpdateArticleDto.getTitle(); |
| | | if(StrUtil.isEmpty(title)){ |
| | | return Result.fail("请输入文章标题"); |
| | | } |
| | | articleEntity.setTitle(title); |
| | | String childTitle = adminUpdateArticleDto.getChildTitle(); |
| | | if(StrUtil.isNotEmpty(childTitle)){ |
| | | articleEntity.setChildTitle(childTitle); |
| | | } |
| | | articleEntity.setChildTitle(childTitle); |
| | | String author = adminUpdateArticleDto.getAuthor(); |
| | | if(StrUtil.isNotEmpty(author)){ |
| | | articleEntity.setAuthor(author); |
| | | } |
| | | articleEntity.setAuthor(author); |
| | | |
| | | String remark = adminUpdateArticleDto.getRemark(); |
| | | if(StrUtil.isNotEmpty(remark)){ |
| | | articleEntity.setRemark(remark); |
| | | } |
| | | articleEntity.setRemark(remark); |
| | | long columnId = adminUpdateArticleDto.getColumnId() == null ? 0L : adminUpdateArticleDto.getColumnId(); |
| | | if(columnId == 0L){ |
| | | return Result.fail("请选择文章栏目"); |
| | | } |
| | | ColumnEntity columnEntity = columnMapper.selectById(columnId); |
| | | if(ObjectUtil.isEmpty(columnEntity)){ |
| | | return Result.fail("请选择文章栏目"); |
| | |
| | | Integer visits = adminUpdateArticleDto.getVisits() == null ? 0 : adminUpdateArticleDto.getVisits(); |
| | | articleEntity.setVisits(visits); |
| | | String mainDiagram = adminUpdateArticleDto.getMainDiagram(); |
| | | if(StrUtil.isNotEmpty(mainDiagram)){ |
| | | articleEntity.setMainDiagram(mainDiagram); |
| | | } |
| | | articleEntity.setMainDiagram(mainDiagram); |
| | | String atlas = adminUpdateArticleDto.getAtlas(); |
| | | articleEntity.setAtlas(atlas); |
| | | Date releaseTime = adminUpdateArticleDto.getReleaseTime(); |
| | | if(ObjectUtil.isNotEmpty(releaseTime)){ |
| | | articleEntity.setReleaseTime(releaseTime); |
| | | } |
| | | Integer releaseStatus = adminUpdateArticleDto.getReleaseStatus(); |
| | | if(!ArticleEntity.RELEASE_STATUS_YES.equals(releaseStatus)){ |
| | | return Result.fail("请先取消文章的发布状态"); |
| | | } |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String articleDetails = adminUpdateArticleDto.getArticleDetails(); |
| | | articleEntity.setArticleDetails(articleDetails); |
| | | String uploadFile = adminUpdateArticleDto.getUploadFile(); |
| | | articleEntity.setUploadFile(uploadFile); |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result updateIstop(Long id) { |
| | | ArticleEntity articleEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | | } |
| | | articleEntity.setIsTop(ArticleEntity.ISTOP_YES); |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result updateIstopOff(Long id) { |
| | | ArticleEntity articleEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | | } |
| | | articleEntity.setIsTop(ArticleEntity.ISTOP_NO); |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result updateStatusOn(Long id) { |
| | | ArticleEntity articleEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public void releaseArticle(Long id) { |
| | | ArticleEntity article = this.baseMapper.selectById(id); |
| | | |
| | | ColumnEntity column = columnMapper.selectById(article.getColumnId()); |
| | | cmsCoreService.articleProcess(article.getId(), column.getArticleTemplate()); |
| | | } |
| | | } |