fix
Helius
2022-07-11 249f6a8da667a1cfe019ce9c647492da9562dd1a
src/main/java/com/xcong/farmer/cms/core/handler/PageDataParserHandler.java
@@ -31,58 +31,60 @@
    @Override
    public void dataParser(AttrNode attrNode) {
        log.info("分页解析");
        Template.HAS_PAGING = true;
        synchronized (this) {
            Template.HAS_PAGING = true;
        Long companyId = (Long) attrNode.getSystemDataValue("companyId");
        Pagination param = (Pagination) attrNode.getParam();
            Long companyId = (Long) attrNode.getSystemDataValue("companyId");
            Pagination param = (Pagination) attrNode.getParam();
        Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit()));
        ArticleEntity article = new ArticleEntity();
        article.setColumnCode(param.getCode());
        article.setCompanyId(companyId);
        IPage<ArticleEntity> pageList = articleMapper.selectArticleInPage(page, article);
            Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit()));
            ArticleEntity article = new ArticleEntity();
            article.setColumnCode(param.getCode());
            article.setCompanyId(companyId);
            IPage<ArticleEntity> pageList = articleMapper.selectArticleInPage(page, article);
        PageData pageData = new PageData();
        pageData.setTotalPage((int) pageList.getPages());
        pageData.setIndex(Integer.parseInt(param.getPage()));
        pageData.setTotalCnt((int) pageList.getSize());
            PageData pageData = new PageData();
            pageData.setTotalPage((int) pageList.getPages());
            pageData.setIndex(Integer.parseInt(param.getPage()));
            pageData.setTotalCnt((int) pageList.getSize());
        if (CollUtil.isNotEmpty(pageList.getRecords())) {
            String path = cmsProperties.getBaseUrl() + "/" + param.getCode();
            String filename = "index_{}.html";
            if (CollUtil.isNotEmpty(pageList.getRecords())) {
                String path = cmsProperties.getBaseUrl() + "/" + param.getCode();
                String filename = "index_{}.html";
            List<PageChildData> list = new ArrayList<>();
            int pageNo = Integer.parseInt(param.getPage());
                List<PageChildData> list = new ArrayList<>();
                int pageNo = Integer.parseInt(param.getPage());
            // 计算出页面显示分页的最大和最小值
            int[] startAndEnd = pageStartAndEnd(pageNo, (int) pageList.getPages(), Integer.parseInt(param.getSize()));
            for (int i = startAndEnd[0]; i <= startAndEnd[1] ; i++) {
                PageChildData child = new PageChildData();
                child.setIndex(i);
                if (pageNo == 1) {
                    child.setPath(path + "/index.html");
                } else {
                    child.setPath(path + "/" + StrUtil.format(filename, i));
                // 计算出页面显示分页的最大和最小值
                int[] startAndEnd = pageStartAndEnd(pageNo, (int) pageList.getPages(), Integer.parseInt(param.getSize()));
                for (int i = startAndEnd[0]; i <= startAndEnd[1]; i++) {
                    PageChildData child = new PageChildData();
                    child.setIndex(i);
                    if (pageNo == 1) {
                        child.setPath(path + "/index.html");
                    } else {
                        child.setPath(path + "/" + StrUtil.format(filename, i));
                    }
                    list.add(child);
                }
                list.add(child);
                pageData.setChildren(list);
            } else {
                pageData.setNext("javascript:void(0)");
                pageData.setPrev("javascript:void(0)");
            }
            pageData.setChildren(list);
        } else {
            pageData.setNext("javascript:void(0)");
            pageData.setPrev("javascript:void(0)");
        }
            if (Integer.parseInt(param.getPage()) >= pageList.getPages()) {
                Template.HAS_PAGING = false;
            }
        if (Integer.parseInt(param.getPage()) == pageList.getPages()) {
            Template.HAS_PAGING = false;
            attrNode.setData(pageData);
        }
        attrNode.setData(pageData);
    }
    /**
     * (x + y)/2 = index
     * y - x= size  解二元一次方程
     * y - x= size  解二元一次方程 x-起点 y-终点
     *
     * @param index 当前页码
     * @param totalPage 总页数