From 0ecfecd2b85b71884fcfba8fa6849be963e434fd Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Mon, 11 Jul 2022 16:47:53 +0800 Subject: [PATCH] fix --- src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java | 93 ++++++++++++++++++++++++++++------------------ 1 files changed, 57 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java index db10d13..f6af191 100644 --- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java +++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java @@ -1,11 +1,13 @@ package com.xcong.farmer.cms.modules.system.service.Impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; 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.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.*; @@ -14,6 +16,7 @@ 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.service.IReleaseService; 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; @@ -23,6 +26,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Date; @@ -44,7 +48,7 @@ private CompanyMapper companyMapper; @Autowired - private ICmsCoreService cmsCoreService; + private IReleaseService releaseService; @Override public Result getArticleInPage(AdminArticleDto adminArticleDto) { @@ -52,32 +56,32 @@ 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 columnIdStrs = adminArticleDto.getColumnIdStr(); + if(StrUtil.isNotEmpty(columnIdStrs)){ + String[] columnIdStr = columnIdStrs.split(StringPool.COMMA); + List<Long> columnList = new ArrayList<>(); + for(String columnIdString : columnIdStr){ + columnList.add(Long.valueOf(columnIdString)); + } + articleEntity.setColumnList(columnList); } String title = adminArticleDto.getTitle(); if(StrUtil.isNotEmpty(title)){ articleEntity.setTitle(title); } - 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); + if (CollUtil.isNotEmpty(list.getRecords())) { + for (AdminArticleVo record : list.getRecords()) { + // 站内 + if (record.getType() == 1) { + record.setArticleUrl(record.getBaseUrl() + record.getPath() + "/" + record.getId() + ".html"); + } + } + } return Result.ok(list); } @@ -111,14 +115,14 @@ String atlas = adminAddArticleDto.getAtlas(); articleEntity.setAtlas(atlas); Date releaseTime = adminAddArticleDto.getReleaseTime(); + if (releaseTime == null) { + releaseTime = new Date(); + } articleEntity.setReleaseTime(releaseTime); Integer isTop = adminAddArticleDto.getIsTop(); 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(); @@ -177,7 +181,12 @@ if(ObjectUtil.isEmpty(columnEntity)){ return Result.fail("请选择文章栏目"); } + + if (!articleEntity.getColumnId().equals(columnId) && articleEntity.getBeforeColumnId() == -1) { + articleEntity.setBeforeColumnId(articleEntity.getColumnId()); + } articleEntity.setColumnId(columnId); + Integer visits = adminUpdateArticleDto.getVisits() == null ? 0 : adminUpdateArticleDto.getVisits(); articleEntity.setVisits(visits); String mainDiagram = adminUpdateArticleDto.getMainDiagram(); @@ -190,9 +199,6 @@ } 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(); @@ -201,6 +207,7 @@ articleEntity.setArticleUrl(adminUpdateArticleDto.getArticleUrl()); articleEntity.setType(adminUpdateArticleDto.getType()); articleEntity.setContentType(adminUpdateArticleDto.getContentType()); + String authorBelong = adminUpdateArticleDto.getAuthorBelong(); articleEntity.setAuthorBelong(authorBelong); this.baseMapper.updateById(articleEntity); @@ -231,6 +238,8 @@ } articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_NO); this.baseMapper.updateById(articleEntity); + + releaseService.releaseColumn(articleEntity.getColumnId(), 2, articleEntity.getCompanyId()); return Result.ok("操作成功"); } @@ -258,17 +267,8 @@ @Override public Result webArticleInPage(HttpServletRequest request, WebArticleInPageDto webArticleInPageDto) { - StringBuffer requestURL = request.getRequestURL(); - List<CompanyEntity> companyEntities = companyMapper.selectList(new QueryWrapper<>()); - Long companyId = 0L; - if(CollUtil.isNotEmpty(companyEntities)){ - for(CompanyEntity companyEntity : companyEntities){ - boolean contains = StrUtil.contains(requestURL, companyEntity.getWebAddress()); - if(contains){ - companyId = companyEntity.getId(); - } - } - } + String website = request.getHeader(AppContants.WEBSITE_HEADER); + Long companyId = getCompanyIdFromWebsite(website); Page<WebArticleVo> page = new Page<>(webArticleInPageDto.getPageNum(), webArticleInPageDto.getPageSize()); ArticleEntity articleEntity = new ArticleEntity(); @@ -287,19 +287,40 @@ if(UserEntity.USER_BELONG_TOP != companyId){ articleEntity.setCompanyId(companyId); } + String timeType = webArticleInPageDto.getTimeType(); + if(StrUtil.isNotEmpty(timeType)){ + articleEntity.setTimeType(timeType); + } IPage<WebArticleVo> list = this.baseMapper.selectWebArticleInPage(page,articleEntity); return Result.ok(list); } @Override public Result updateStatusOn(Long id) { + Long companyId = LoginUserUtil.getCompanyId(); ArticleEntity articleEntity = this.baseMapper.selectById(id); if(ObjectUtil.isEmpty(articleEntity)){ return Result.fail("文章不存在"); } articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_YES); - articleEntity.setReleaseTime(new Date()); + articleEntity.setBeforeColumnId(null); this.baseMapper.updateById(articleEntity); + + releaseService.releaseArticle(articleEntity.getId(), companyId); return Result.ok("操作成功"); } + + 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(companyEntity.getWebAddress(), website); + if(contains){ + companyId = companyEntity.getId(); + } + } + } + return companyId; + } } -- Gitblit v1.9.1