| | |
| | | @ApiOperation(value = "发布栏目", notes = "发布栏目") |
| | | @PostMapping(value = "releaseColumn/{type}/{id}") |
| | | public Result releaseColumn(@PathVariable("id") Long id, @PathVariable("type") Integer type) { |
| | | boolean article = false; |
| | | if (type == 1) { |
| | | article = true; |
| | | } |
| | | releaseService.releaseColumn(id, article); |
| | | releaseService.releaseColumn(id, type); |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | |
| | | package com.xcong.farmer.cms.modules.core.service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public interface ICmsCoreService { |
| | |
| | | /** |
| | | * 文章编译 |
| | | * |
| | | * @param id |
| | | * @param templateName |
| | | */ |
| | | void articleProcess(Map<String, Object> data, String templateName, String templatePath); |
| | |
| | | * 栏目编译 |
| | | * @param map 栏目页面参数(如: 栏目ID/CODE) |
| | | * @param templateName 模板名称 |
| | | * @param columnOnly 是否只编译当前栏目列表页(如果false,则会编译栏目下所有子栏目或者所有文章) |
| | | */ |
| | | void columnProcess(Map<String, Object> map, String templateName); |
| | | |
| | | /** |
| | | * 批量发布文章 |
| | | * |
| | | * @param data |
| | | * @param templateName |
| | | * @param templatePath |
| | | */ |
| | | void articlesProcess(Map<String, Object> data, List<Long> ids, String templateName, String templatePath); |
| | | |
| | | /** |
| | | * 批量发布栏目 |
| | | * |
| | | * @param map |
| | | * @param templateName |
| | | */ |
| | | void columnsProcess(Map<String, Object> map, List<Long> ids, String templateName); |
| | | |
| | | void indexProcess(Map<String, Object> map, String templateName); |
| | | |
| | | } |
| | |
| | | package com.xcong.farmer.cms.modules.core.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | |
| | | |
| | | @Autowired |
| | | private TemplateConfiguration cfg; |
| | | private final Executor executor = new ThreadPoolExecutor(5, 10, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | |
| | | |
| | | @Override |
| | |
| | | templateName = "defualt.artile.html"; |
| | | } |
| | | |
| | | String finalTemplateName = templateName; |
| | | executor.execute(() -> cfg.process(data, finalTemplateName)); |
| | | cfg.process(data, templateName); |
| | | } |
| | | |
| | | @Override |
| | | public void articlesProcess(Map<String, Object> data, List<Long> ids, String templateName, String templatePath) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | |
| | | for (Long id : ids) { |
| | | data.put("id", id); |
| | | articleProcess(data, templateName, templatePath); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void columnsProcess(Map<String, Object> data, List<Long> ids, String templateName) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | |
| | | for (Long id : ids) { |
| | | data.put("id", id); |
| | | columnProcess(data, templateName); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | templateName = "defualt.list.html"; |
| | | } |
| | | |
| | | String finalTemplateName = templateName; |
| | | executor.execute(() -> cfg.process(data, finalTemplateName)); |
| | | cfg.process(data, templateName); |
| | | } |
| | | |
| | | @Override |
| | |
| | | templateName = "index.html"; |
| | | } |
| | | |
| | | String finalTemplateName = templateName; |
| | | executor.execute(() -> cfg.process(data, finalTemplateName)); |
| | | cfg.process(data, templateName); |
| | | } |
| | | } |
| | |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.*; |
| | | import com.xcong.farmer.cms.modules.system.service.IColumnService; |
| | | import com.xcong.farmer.cms.modules.system.service.IReleaseService; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminColumnVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeColumnInfoVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.WebColumnVo; |
| | |
| | | import io.swagger.annotations.ApiResponses; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private IColumnService iColumnService; |
| | | |
| | | @Autowired |
| | | private IReleaseService releaseService; |
| | | |
| | | @ApiOperation(value = "栏目分页列表", notes = "栏目分页列表") |
| | | @ApiResponses({@ApiResponse(code = 200, message = "ok", response = AdminColumnVo.class)}) |
| | |
| | | |
| | | @ApiOperation(value = "发布栏目", notes = "发布栏目") |
| | | @PostMapping(value = "/release") |
| | | public Result release(@RequestBody ReleaseColumnDto releaseColumnDto) { |
| | | public Result release(@RequestBody @Valid ReleaseColumnDto releaseColumnDto) { |
| | | releaseService.releaseColumn(releaseColumnDto.getId(), releaseColumnDto.getType()); |
| | | return Result.ok("发布成功"); |
| | | } |
| | | |
| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-07 |
| | |
| | | @ApiModel(value = "ReleaseColumnDto", description = "发布栏目接收参数类") |
| | | public class ReleaseColumnDto { |
| | | |
| | | @NotNull(message = "参数不为空") |
| | | @ApiModelProperty(value = "栏目ID", example = "1") |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "是否编译子栏目和栏目下所有文章 1-是 ,2-否", example = "1") |
| | | @NotNull(message = "参数不为空") |
| | | @ApiModelProperty(value = "1-仅发布该栏目 2-发布栏目下已发布文章 3-发布栏目下未发布文章 4-发布栏目下所有", example = "1") |
| | | private Integer type; |
| | | } |
| | |
| | | IPage<ArticleEntity> selectArticleInPage(Page<ArticleEntity> page, @Param("record") ArticleEntity article); |
| | | |
| | | IPage<WebArticleVo> selectWebArticleInPage(Page<WebArticleVo> page, @Param("record")ArticleEntity articleEntity); |
| | | |
| | | List<Long> selectArticleIdsByColumnId(@Param("columnId") Long columnId, @Param("companyId") Long companyId, @Param("type") Integer type); |
| | | } |
| | |
| | | IPage<ColumnEntity> selectColumnInPage(Page<ColumnEntity> page, @Param("record") ColumnEntity column); |
| | | |
| | | List<WebColumnVo> selectWebColumnInListByParentId(@Param("parentId") Long parentidDefault, @Param("companyId") Long companyId); |
| | | |
| | | List<Long> selectColumnIdsByParentId(@Param("parentId") Long parentId, @Param("companyId") Long companyId); |
| | | } |
| | |
| | | |
| | | void releaseArticle(Long id); |
| | | |
| | | void releaseColumn(Long id, boolean article); |
| | | void releaseColumn(Long id, int type); |
| | | |
| | | void releaseIndex(); |
| | | } |
| | |
| | | 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; |
| | |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | private IReleaseService releaseService; |
| | | |
| | | @Override |
| | | public Result getArticleInPage(AdminArticleDto adminArticleDto) { |
| | |
| | | articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_YES); |
| | | articleEntity.setReleaseTime(new Date()); |
| | | this.baseMapper.updateById(articleEntity); |
| | | |
| | | releaseService.releaseArticle(articleEntity.getId()); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | |
| | | columnEntity.setIsNav(adminAddColumnDto.getIsNav()); |
| | | columnEntity.setContentType(adminAddColumnDto.getContentType()); |
| | | this.baseMapper.insert(columnEntity); |
| | | return Result.ok("添加成功"); |
| | | return Result.ok("添加成功", columnEntity.getId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.ColumnEntity; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | private final Executor executor = new ThreadPoolExecutor(5, 10, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | |
| | | @Override |
| | | public void releaseArticle(Long id) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | |
| | | data.put("id", article.getId()); |
| | | data.put("companyId", companyId); |
| | | |
| | | executor.execute(()->{ |
| | | cmsCoreService.articleProcess(data, column.getArticleTemplate(), column.getPath()); |
| | | this.releaseColumn(column.getId(), false); |
| | | this.releaseColumn(column.getId(), 1); |
| | | if (column.getParentId() != 0L) { |
| | | releaseColumn(column.getParentId(), false); |
| | | releaseColumn(column.getParentId(), 1); |
| | | } |
| | | this.releaseIndex(); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void releaseColumn(Long id, boolean article) { |
| | | public void releaseColumn(Long id, int type) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | ColumnEntity columnEntity = columnMapper.selectById(id); |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | map.put("templatePath", columnEntity.getPath()); |
| | | map.put("companyId", companyId); |
| | | |
| | | if (type != 1) { |
| | | executor.execute(() -> { |
| | | if (columnEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(columnEntity.getParentId(), companyId); |
| | | if (CollUtil.isNotEmpty(columns)) { |
| | | for (ColumnEntity column : columns) { |
| | | map.put("id", column.getId()); |
| | | cmsCoreService.columnProcess(map, column.getListTemplate()); |
| | | |
| | | List<Long> ids = articleMapper.selectArticleIdsByColumnId(column.getId(), companyId,type); |
| | | cmsCoreService.articlesProcess(map, ids, column.getArticleTemplate(), column.getPath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<Long> ids = articleMapper.selectArticleIdsByColumnId(columnEntity.getId(), companyId, type); |
| | | cmsCoreService.articlesProcess(map, ids, columnEntity.getArticleTemplate(), columnEntity.getPath()); |
| | | |
| | | releaseIndex(); |
| | | }); |
| | | |
| | | executor.execute(() -> { |
| | | cmsCoreService.columnProcess(map, columnEntity.getListTemplate()); |
| | | releaseIndex(); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | </where> |
| | | order by a.is_top desc,a.create_time desc |
| | | </select> |
| | | |
| | | <select id="selectArticleIdsByColumnId" resultType="java.lang.Long"> |
| | | select * from t_article a |
| | | where a.column_id=#{columnId} and a.company_id=#{companyId} |
| | | <if test="type != 4"> |
| | | <if test="type == 2"> |
| | | and release_status=1 |
| | | </if> |
| | | <if test="type == 3"> |
| | | and release_status=0 |
| | | </if> |
| | | </if> |
| | | </select> |
| | | </mapper> |
| | |
| | | where a.parent_id = #{parentId} and a.company_id = #{companyId} |
| | | order by a.order_num ASC,a.create_time desc |
| | | </select> |
| | | |
| | | <select id="selectColumnIdsByParentId" resultType="java.lang.Long"> |
| | | select |
| | | a.id |
| | | FROM |
| | | t_column a |
| | | where a.parent_id = #{parentId} and a.company_id = #{companyId} |
| | | order by a.id desc |
| | | </select> |
| | | </mapper> |