| | |
| | | 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.contants.AppContants; |
| | | 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.dto.AdminUpdateArticleDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.ColumnEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserRoleEntity; |
| | | import com.xcong.farmer.cms.modules.system.dto.*; |
| | | import com.xcong.farmer.cms.modules.system.entity.*; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ColumnMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CompanyMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.IArticleService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminArticleVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeArticleInfoVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.WebArticleVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Date; |
| | | |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | @Service |
| | | @Slf4j |
| | |
| | | @Resource |
| | | private ColumnMapper columnMapper; |
| | | |
| | | @Resource |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | |
| | | @Override |
| | | public Result getArticleInPage(AdminArticleDto adminArticleDto) { |
| | |
| | | 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(columnId != 0L){ |
| | | articleEntity.setColumnId(columnId); |
| | | String columnIdStr = adminArticleDto.getColumnId(); |
| | | if(StrUtil.isNotEmpty(columnIdStr)){ |
| | | long[] columnIdLongs = StrUtil.splitToLong(columnIdStr, StrUtil.COMMA); |
| | | List<Long> columnList = new ArrayList<>(); |
| | | for(long columnIdLong : columnIdLongs){ |
| | | columnList.add(columnIdLong); |
| | | } |
| | | articleEntity.setColumnlist(columnList); |
| | | } |
| | | String title = adminArticleDto.getTitle(); |
| | | if(StrUtil.isNotEmpty(title)){ |
| | |
| | | articleEntity.setIsTop(isTop); |
| | | Integer releaseStatus = adminAddArticleDto.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | if(ArticleEntity.RELEASE_STATUS_YES == releaseStatus){ |
| | | articleEntity.setReleaseTime(new Date()); |
| | | } |
| | | String articleDetails = adminAddArticleDto.getArticleDetails(); |
| | | articleEntity.setArticleDetails(articleDetails); |
| | | String uploadFile = adminAddArticleDto.getUploadFile(); |
| | |
| | | } |
| | | Integer isTop = adminUpdateArticleDto.getIsTop(); |
| | | articleEntity.setIsTop(isTop); |
| | | Integer releaseStatus = adminUpdateArticleDto.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | String title = adminUpdateArticleDto.getTitle(); |
| | | articleEntity.setTitle(title); |
| | | String childTitle = adminUpdateArticleDto.getChildTitle(); |
| | |
| | | if(ObjectUtil.isNotEmpty(releaseTime)){ |
| | | articleEntity.setReleaseTime(releaseTime); |
| | | } |
| | | Integer releaseStatus = adminUpdateArticleDto.getReleaseStatus(); |
| | | articleEntity.setReleaseStatus(releaseStatus); |
| | | if(ArticleEntity.RELEASE_STATUS_YES == releaseStatus){ |
| | | articleEntity.setReleaseTime(new Date()); |
| | | } |
| | | String articleDetails = adminUpdateArticleDto.getArticleDetails(); |
| | | articleEntity.setArticleDetails(articleDetails); |
| | | String uploadFile = adminUpdateArticleDto.getUploadFile(); |
| | |
| | | articleEntity.setArticleUrl(adminUpdateArticleDto.getArticleUrl()); |
| | | articleEntity.setType(adminUpdateArticleDto.getType()); |
| | | articleEntity.setContentType(adminUpdateArticleDto.getContentType()); |
| | | String authorBelong = adminUpdateArticleDto.getAuthorBelong(); |
| | | articleEntity.setAuthorBelong(authorBelong); |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result webArticleInPage(HttpServletRequest request, WebArticleInPageDto webArticleInPageDto) { |
| | | String website = request.getHeader(AppContants.WEBSITE_HEADER); |
| | | Long companyId = getCompanyIdFromWebsite(website); |
| | | |
| | | Page<WebArticleVo> page = new Page<>(webArticleInPageDto.getPageNum(), webArticleInPageDto.getPageSize()); |
| | | ArticleEntity articleEntity = new ArticleEntity(); |
| | | Long columnId = webArticleInPageDto.getColumnId() == null ? 0L : webArticleInPageDto.getColumnId(); |
| | | if(columnId != 0L){ |
| | | articleEntity.setColumnId(columnId); |
| | | } |
| | | String author = webArticleInPageDto.getAuthor(); |
| | | if(StrUtil.isNotEmpty(author)){ |
| | | articleEntity.setAuthor(author); |
| | | } |
| | | String queryKey = webArticleInPageDto.getQueryKey(); |
| | | if(StrUtil.isNotEmpty(queryKey)){ |
| | | articleEntity.setTitle(queryKey); |
| | | } |
| | | if(UserEntity.USER_BELONG_TOP != companyId){ |
| | | articleEntity.setCompanyId(companyId); |
| | | } |
| | | IPage<WebArticleVo> list = this.baseMapper.selectWebArticleInPage(page,articleEntity); |
| | | return Result.ok(list); |
| | | } |
| | | |
| | | @Override |
| | | public Result updateStatusOn(Long id) { |
| | | ArticleEntity articleEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | | } |
| | | articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_YES); |
| | | articleEntity.setReleaseTime(new Date()); |
| | | 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()); |
| | | private Long getCompanyIdFromWebsite(String website){ |
| | | List<CompanyEntity> companyEntities = companyMapper.selectList(new QueryWrapper<>()); |
| | | Long companyId = 0L; |
| | | if(CollUtil.isNotEmpty(companyEntities)){ |
| | | for(CompanyEntity companyEntity : companyEntities){ |
| | | boolean contains = StrUtil.contains(website, companyEntity.getWebAddress()); |
| | | if(contains){ |
| | | companyId = companyEntity.getId(); |
| | | } |
| | | } |
| | | } |
| | | return companyId; |
| | | } |
| | | } |