xiaoyong931011
2022-07-07 f7a43888a4d288b394f38b996b328ab0560b588d
20220606
13 files modified
153 ■■■■ changed files
src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/core/service/ICmsCoreService.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java 36 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/controller/AdminColumnController.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/dto/ReleaseColumnDto.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ArticleMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ColumnMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/IReleaseService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java 41 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/ArticleMapper.xml 13 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/ColumnMapper.xml 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/core/controller/CmsCoreController.java
@@ -34,11 +34,7 @@
    @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");
    }
src/main/java/com/xcong/farmer/cms/modules/core/service/ICmsCoreService.java
@@ -1,5 +1,6 @@
package com.xcong.farmer.cms.modules.core.service;
import java.util.List;
import java.util.Map;
public interface ICmsCoreService {
@@ -7,7 +8,6 @@
    /**
     * 文章编译
     *
     * @param id
     * @param templateName
     */
    void articleProcess(Map<String, Object> data, String templateName, String templatePath);
@@ -16,10 +16,26 @@
     * 栏目编译
     * @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);
}
src/main/java/com/xcong/farmer/cms/modules/core/service/impl/CmsCoreServiceImpl.java
@@ -1,5 +1,6 @@
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;
@@ -9,6 +10,7 @@
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;
@@ -25,7 +27,6 @@
    @Autowired
    private TemplateConfiguration cfg;
    private final Executor executor = new ThreadPoolExecutor(5, 10, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
    @Override
@@ -37,8 +38,31 @@
            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
@@ -49,8 +73,7 @@
            templateName = "defualt.list.html";
        }
        String finalTemplateName = templateName;
        executor.execute(() -> cfg.process(data, finalTemplateName));
        cfg.process(data, templateName);
    }
    @Override
@@ -59,7 +82,6 @@
            templateName = "index.html";
        }
        String finalTemplateName = templateName;
        executor.execute(() -> cfg.process(data, finalTemplateName));
        cfg.process(data, templateName);
    }
}
src/main/java/com/xcong/farmer/cms/modules/system/controller/AdminColumnController.java
@@ -3,6 +3,7 @@
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;
@@ -12,6 +13,7 @@
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;
@@ -26,6 +28,9 @@
    @Resource
    private IColumnService iColumnService;
    @Autowired
    private IReleaseService releaseService;
    @ApiOperation(value = "栏目分页列表", notes = "栏目分页列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = AdminColumnVo.class)})
@@ -70,7 +75,8 @@
    @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("发布成功");
    }
src/main/java/com/xcong/farmer/cms/modules/system/dto/ReleaseColumnDto.java
@@ -4,6 +4,8 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
 * @author wzy
 * @date 2022-07-07
@@ -12,9 +14,11 @@
@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;
}
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ArticleMapper.java
@@ -25,4 +25,6 @@
    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);
}
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ColumnMapper.java
@@ -23,4 +23,6 @@
    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);
}
src/main/java/com/xcong/farmer/cms/modules/system/service/IReleaseService.java
@@ -5,7 +5,7 @@
    void releaseArticle(Long id);
    void releaseColumn(Long id, boolean article);
    void releaseColumn(Long id, int type);
    void releaseIndex();
}
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ArticleServiceImpl.java
@@ -15,6 +15,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;
@@ -46,8 +47,7 @@
    private CompanyMapper companyMapper;
    @Autowired
    private ICmsCoreService cmsCoreService;
    private IReleaseService releaseService;
    @Override
    public Result getArticleInPage(AdminArticleDto adminArticleDto) {
@@ -299,6 +299,8 @@
        articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_YES);
        articleEntity.setReleaseTime(new Date());
        this.baseMapper.updateById(articleEntity);
        releaseService.releaseArticle(articleEntity.getId());
        return Result.ok("操作成功");
    }
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java
@@ -124,7 +124,7 @@
        columnEntity.setIsNav(adminAddColumnDto.getIsNav());
        columnEntity.setContentType(adminAddColumnDto.getContentType());
        this.baseMapper.insert(columnEntity);
        return Result.ok("添加成功");
        return Result.ok("添加成功", columnEntity.getId());
    }
    @Override
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java
@@ -1,5 +1,6 @@
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;
@@ -12,7 +13,12 @@
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
@@ -31,6 +37,8 @@
    @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();
@@ -41,16 +49,18 @@
        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<>();
@@ -65,7 +75,32 @@
        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
src/main/resources/mapper/ArticleMapper.xml
@@ -116,4 +116,17 @@
        </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>
src/main/resources/mapper/ColumnMapper.xml
@@ -61,4 +61,13 @@
        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>