Helius
2022-07-05 008f79857609c0217a798848a95a4139b73d884e
fix:文章列表解析
2 files added
8 files modified
289 ■■■■■ changed files
src/main/java/com/xcong/farmer/cms/conversion/ArticleConversion.java 24 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/handler/ArticlesDataParserHandler.java 58 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/handler/ColumnDataParserHandler.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/handler/NavDataParserHandler.java 17 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/tag/data/ArticleData.java 124 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/tag/model/Articles.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/entity/ArticleEntity.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ArticleMapper.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/ArticleMapper.xml 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/conversion/ArticleConversion.java
New file
@@ -0,0 +1,24 @@
package com.xcong.farmer.cms.conversion;
import com.xcong.farmer.cms.core.tag.data.ArticleData;
import com.xcong.farmer.cms.modules.system.entity.ArticleEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
 * @author wzy
 * @date 2022-07-05
 **/
@Mapper
public abstract class ArticleConversion {
    public static ArticleConversion INSTANCE = Mappers.getMapper(ArticleConversion.class);
    @Mapping(source = "childTitle", target = "subTitle")
    @Mapping(source = "visits", target = "views")
    @Mapping(source = "mainDiagram", target = "thumb")
    @Mapping(source = "releaseTime", target = "createTime")
    @Mapping(source = "articleDetails", target = "content")
    @Mapping(source = "uploadFile", target = "filePath")
    public abstract ArticleData entityToData(ArticleEntity article);
}
src/main/java/com/xcong/farmer/cms/core/handler/ArticlesDataParserHandler.java
@@ -1,6 +1,17 @@
package com.xcong.farmer.cms.core.handler;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.farmer.cms.conversion.ArticleConversion;
import com.xcong.farmer.cms.core.node.AttrNode;
import com.xcong.farmer.cms.core.tag.data.ArticleData;
import com.xcong.farmer.cms.core.tag.model.Articles;
import com.xcong.farmer.cms.modules.system.entity.ArticleEntity;
import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper;
import com.xcong.farmer.cms.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
@@ -11,23 +22,48 @@
 * @author wzy
 * @date 2022-06-24
 **/
@Slf4j
public class ArticlesDataParserHandler implements DataParserHandler  {
    private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class);
    private String BASE_URL = "http://192.168.0.1";
    @Override
    public void dataParser(AttrNode node) {
        System.out.println("ArticlesDataParserHandler");
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("path", "这是链接1");
        map.put("title", "这是标题1");
        list.add(map);
        log.info("文章列表解析");
        Long companyId = (Long) node.getSystemDataValue("companyId");
        Articles param = (Articles) node.getParam();
        Map<String, Object> map2 = new HashMap<>();
        map2.put("path", "这是链接2");
        map2.put("title", "这是标题2");
        list.add(map2);
        if (StrUtil.isEmpty(param.getColId())) {
            Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit()));
        node.setData(list);
            ArticleEntity article = new ArticleEntity();
            article.setColumnCode(param.getCode());
            article.setCompanyId(companyId);
            IPage<ArticleEntity> listPage = articleMapper.selectArticleInPage(page, article);
            List<ArticleData> list = new ArrayList<>();
            for (ArticleEntity record : listPage.getRecords()) {
                ArticleData articleData = entityToData(record);
                list.add(articleData);
            }
            node.setData(list);
        } else {
        }
    }
    public ArticleData entityToData(ArticleEntity article) {
        ArticleData articleData = ArticleConversion.INSTANCE.entityToData(article);
        if (article.getType() == 2) {
            articleData.setUrl(article.getArticleUrl());
        } else {
            articleData.setUrl(BASE_URL + article.getPath() + "/" + article.getId() + ".html");
        }
        return articleData;
    }
}
src/main/java/com/xcong/farmer/cms/core/handler/ColumnDataParserHandler.java
@@ -25,7 +25,7 @@
    private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class);
    private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class);
    private String BASE_URL = "http://192.168.0.1/";
    private String BASE_URL = "http://192.168.0.1";
    @Override
    public void dataParser(AttrNode attrNode) {
@@ -55,13 +55,14 @@
    public ColumnData columnToData(ColumnEntity column) {
        ColumnData columnData = ColumnConversion.INSTANCE.entityToData(column);
        columnData.setUrl(BASE_URL + columnData.getCode());
        columnData.setUrl(BASE_URL + column.getPath());
        if (column.getType() == 2) {
            if (column.getTargetType() == 1) {
                ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl()));
                columnData.setUrl(BASE_URL + article.getColumnCode() + "/" + article.getId() + ".html");
                columnData.setUrl(BASE_URL + article.getPath() + "/" + article.getId() + ".html");
            } else if (column.getTargetType() == 2) {
                columnData.setUrl(BASE_URL + column.getTargetUrl());
                ColumnEntity columnEntity = this.columnMapper.selectByCodeAndCompanyId(column.getTargetUrl(), column.getCompanyId());
                columnData.setUrl(BASE_URL + columnEntity.getPath());
            } else {
                columnData.setUrl(column.getTargetUrl());
            }
src/main/java/com/xcong/farmer/cms/core/handler/NavDataParserHandler.java
@@ -27,7 +27,7 @@
    private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class);
    private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class);
    private String BASE_URL = "http://192.168.0.1/";
    private String BASE_URL = "http://192.168.0.1";
    @Override
    public void dataParser(AttrNode node) {
        log.info("导航栏解析");
@@ -40,6 +40,13 @@
        }
        List<NavData> list = new ArrayList<>();
        NavData index = new NavData();
        index.setTitle("首页");
        index.setUrl(BASE_URL);
        index.setCode("index");
        list.add(index);
        for (ColumnEntity column : columns) {
            NavData navData = columnToNav(column);
@@ -50,6 +57,7 @@
            }
            list.add(navData);
        }
        node.setData(list);
    }
@@ -65,13 +73,14 @@
    public NavData columnToNav(ColumnEntity column) {
        NavData navData = ColumnConversion.INSTANCE.columnToNav(column);
        navData.setUrl(BASE_URL + navData.getCode());
        navData.setUrl(BASE_URL + column.getPath());
        if (column.getType() == 2) {
            if (column.getTargetType() == 1) {
                ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl()));
                navData.setUrl(BASE_URL + article.getColumnCode() + "/" + article.getId() + ".html");
                navData.setUrl(BASE_URL + article.getPath() + "/" + article.getId() + ".html");
            } else if (column.getTargetType() == 2) {
                navData.setUrl(BASE_URL + column.getTargetUrl());
                ColumnEntity columnEntity = this.columnMapper.selectByCodeAndCompanyId(column.getTargetUrl(), column.getCompanyId());
                navData.setUrl(BASE_URL + columnEntity.getPath());
            } else {
                navData.setUrl(column.getTargetUrl());
            }
src/main/java/com/xcong/farmer/cms/core/tag/data/ArticleData.java
New file
@@ -0,0 +1,124 @@
package com.xcong.farmer.cms.core.tag.data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
/**
 * @author wzy
 * @date 2022-07-05
 **/
public class ArticleData {
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    private Long id;
    private String title;
    private String subTitle;
    private String thumb;
    private String content;
    private String author;
    private String views;
    private String filePath;
    private List<String> images;
    private String url;
    public String getFilePath() {
        return filePath;
    }
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getSubTitle() {
        return subTitle;
    }
    public void setSubTitle(String subTitle) {
        this.subTitle = subTitle;
    }
    public String getThumb() {
        return thumb;
    }
    public void setThumb(String thumb) {
        this.thumb = thumb;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public List<String> getImages() {
        return images;
    }
    public void setImages(List<String> images) {
        this.images = images;
    }
    public String getViews() {
        return views;
    }
    public void setViews(String views) {
        this.views = views;
    }
}
src/main/java/com/xcong/farmer/cms/core/tag/model/Articles.java
@@ -6,10 +6,24 @@
 **/
public class Articles {
    /**
     * 栏目ID,可colID=1或者colId=[1,2,3]
     */
    private String colId;
    /**
     * 栏目code, code=lm
     */
    private String code;
    /**
     * 页码
     */
    private String page;
    /**
     * 每页数量
     */
    private String limit;
    private String field;
@@ -38,6 +52,14 @@
        this.limit = limit;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getField() {
        return field;
    }
src/main/java/com/xcong/farmer/cms/modules/system/entity/ArticleEntity.java
@@ -90,4 +90,10 @@
    @TableField(exist = false)
    private String columnName;
    /**
     * 栏目目录
     */
    @TableField(exist = false)
    private String path;
}
src/main/java/com/xcong/farmer/cms/modules/system/mapper/ArticleMapper.java
@@ -9,6 +9,8 @@
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ArticleMapper extends BaseMapper<ArticleEntity> {
    IPage<AdminArticleVo> selectAdminArticleInPage(Page<AdminArticleVo> page, @Param("record")ArticleEntity articleEntity);
@@ -18,4 +20,6 @@
    ArticleEntity selectPrevOrNextArticle(@Param("id") Long id, @Param("columnId") Long columnId, @Param("type") Integer type);
    ArticleEntity selectArticleById(@Param("id") Long id);
    IPage<ArticleEntity> selectArticleInPage(Page<ArticleEntity> page, @Param("record") ArticleEntity article);
}
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ReleaseServiceImpl.java
@@ -44,6 +44,12 @@
        Map<String, Object> map = new HashMap<>();
        map.put("id", columnEntity.getId());
        map.put("code", columnEntity.getColumnCode());
        if (columnEntity.getParentId() == 0L) {
            map.put("parentCode", columnEntity.getColumnCode());
        } else {
            ColumnEntity parent = columnMapper.selectById(columnEntity.getParentId());
            map.put("parentCode", parent.getColumnCode());
        }
        cmsCoreService.columnProcess(map, columnEntity.getListTemplate(), article);
    }
src/main/resources/mapper/ArticleMapper.xml
@@ -52,8 +52,25 @@
    </select>
    <select id="selectArticleById" resultType="com.xcong.farmer.cms.modules.system.entity.ArticleEntity">
        select a.*, b.column_code, b.column_name
        select a.*, b.column_code, b.column_name, b.path
        from t_article a, t_column b
        where a.column_id=b.id and a.id=#{id}
    </select>
    <select id="selectArticleInPage" resultType="com.xcong.farmer.cms.modules.system.entity.ArticleEntity">
        select
            a.*,
            b.column_code,
            b.column_name,
            b.path
        from t_article a
        inner join t_column b on a.column_id=b.id
        inner join t_column c on b.parent_id=c.id or c.id=b.id
        <where>
            a.company_id=#{record.companyId}
            <if test="record.columnCode != null and record.columnCode != ''">
                and c.column_code=#{record.columnCode}
            </if>
        </where>
    </select>
</mapper>