| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | 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 ? UserEntity.USER_BELONG_TOP : 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); |
| | | } |
| | | if(UserEntity.USER_BELONG_TOP != belongId){ |
| | | articleEntity.setBelongId(belongId); |
| | | Integer contentType = adminArticleDto.getContentType() == null ? 0 : adminArticleDto.getContentType(); |
| | | if(contentType != 0){ |
| | | QueryWrapper<ColumnEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("content_type",contentType); |
| | | List<ColumnEntity> columnEntities = columnMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(columnEntities)){ |
| | | List<Long> columIds = new ArrayList<>(); |
| | | for(ColumnEntity columnEntity : columnEntities){ |
| | | Long id = columnEntity.getId(); |
| | | columIds.add(id); |
| | | } |
| | | articleEntity.setColumnIds(columIds); |
| | | } |
| | | } |
| | | 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 ? UserEntity.USER_BELONG_TOP : 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(); |
| | | 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(); |
| | | if(StrUtil.isNotEmpty(authorBelong)){ |
| | | articleEntity.setAuthorBelong(authorBelong); |
| | | } |
| | | String remark = adminAddArticleDto.getRemark(); |
| | | if(StrUtil.isNotEmpty(remark)){ |
| | | articleEntity.setRemark(remark); |
| | | } |
| | | long columnId = adminAddArticleDto.getColumnId() == null ? 0L : adminAddArticleDto.getColumnId(); |
| | | ColumnEntity columnEntity = columnMapper.selectById(columnId); |
| | | if(ObjectUtil.isEmpty(columnEntity)){ |
| | |
| | | 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); |
| | | |
| | | articleEntity.setArticleUrl(adminAddArticleDto.getArticleUrl()); |
| | | articleEntity.setType(adminAddArticleDto.getType()); |
| | | articleEntity.setContentType(adminAddArticleDto.getContentType()); |
| | | this.baseMapper.insert(articleEntity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | | } |
| | | Integer isTop = adminUpdateArticleDto.getIsTop(); |
| | | articleEntity.setIsTop(isTop); |
| | | Integer releaseStatus = adminUpdateArticleDto.getReleaseStatus(); |
| | | if(!ArticleEntity.RELEASE_STATUS_YES.equals(releaseStatus)){ |
| | | return Result.fail("请先取消文章的发布状态"); |
| | | } |
| | | articleEntity.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String title = adminUpdateArticleDto.getTitle(); |
| | | articleEntity.setTitle(title); |
| | | String childTitle = adminUpdateArticleDto.getChildTitle(); |
| | |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String articleDetails = adminUpdateArticleDto.getArticleDetails(); |
| | | articleEntity.setArticleDetails(articleDetails); |
| | | String uploadFile = adminUpdateArticleDto.getUploadFile(); |
| | | articleEntity.setUploadFile(uploadFile); |
| | | |
| | | articleEntity.setArticleUrl(adminUpdateArticleDto.getArticleUrl()); |
| | | articleEntity.setType(adminUpdateArticleDto.getType()); |
| | | articleEntity.setContentType(adminUpdateArticleDto.getContentType()); |
| | | 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)){ |