Helius
2022-07-07 f04b8922283120e2bc4a476ddc302ebd3b0894e4
src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java
@@ -1,12 +1,27 @@
package com.xcong.farmer.cms;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.farmer.cms.common.response.Result;
import com.xcong.farmer.cms.common.utils.FileUtils;
import com.xcong.farmer.cms.configurations.properties.CmsProperties;
import com.xcong.farmer.cms.modules.system.dto.AdminArticleDto;
import com.xcong.farmer.cms.modules.system.dto.WebArticleInPageDto;
import com.xcong.farmer.cms.modules.system.entity.ArticleEntity;
import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity;
import com.xcong.farmer.cms.modules.system.entity.ColumnEntity;
import com.xcong.farmer.cms.modules.system.entity.UserEntity;
import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper;
import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper;
import com.xcong.farmer.cms.modules.system.mapper.ColumnMapper;
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.WebArticleVo;
import com.xcong.farmer.cms.modules.test.dao.TestUserDao;
import com.xcong.farmer.cms.modules.test.entity.TestUserEntity;
import org.jsoup.Jsoup;
@@ -22,7 +37,9 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@SpringBootTest
class KssframeworkApplicationTests {
@@ -90,6 +107,96 @@
        String pathName = FileUtils.path(templatePath, cmsTemplateEntity.getPath());
        System.out.println(templatePath);
        System.out.println(pathName);
        byte[] bytes = new byte[0];
        try {
            bytes = Files.readAllBytes(Paths.get(pathName));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("未找到模板");
        }
        String content = new String(bytes, StandardCharsets.UTF_8);
        System.out.println(content);
    }
    @Autowired
    private ColumnMapper columnMapper;
    @Autowired
    private ArticleMapper articleMapper;
    @Test
    public void articleTest(){
        WebArticleInPageDto webArticleInPageDto = new WebArticleInPageDto();
        webArticleInPageDto.setTimeType("一周内");
        webArticleInPageDto.setPageNum(1);
        webArticleInPageDto.setPageSize(8);
        Long companyId = 24L;
        Page<WebArticleVo> page = new Page<>(webArticleInPageDto.getPageNum(), webArticleInPageDto.getPageSize());
        ArticleEntity articleEntity = new ArticleEntity();
        Long columnId = webArticleInPageDto.getColumnId() == null ? 0L : webArticleInPageDto.getColumnId();
        if(columnId != 0L){
            articleEntity.setColumnId(columnId);
        }
        String author = webArticleInPageDto.getAuthor();
        if(StrUtil.isNotEmpty(author)){
            articleEntity.setAuthor(author);
        }
        String queryKey = webArticleInPageDto.getQueryKey();
        if(StrUtil.isNotEmpty(queryKey)){
            articleEntity.setTitle(queryKey);
        }
        if(UserEntity.USER_BELONG_TOP != companyId){
            articleEntity.setCompanyId(companyId);
        }
        String timeType = webArticleInPageDto.getTimeType();
        if(StrUtil.isNotEmpty(timeType)){
            articleEntity.setTimeType(timeType);
        }
        IPage<WebArticleVo> list = articleMapper.selectWebArticleInPage(page,articleEntity);
        System.out.println(list.getRecords());
    }
    @Test
    public void dateTest(){
        String columnIdStrs = "68,63";
        AdminArticleDto adminArticleDto = new AdminArticleDto();
        adminArticleDto.setColumnIdStr(columnIdStrs);
        adminArticleDto.setPageNum(1);
        adminArticleDto.setPageSize(8);
        Page<AdminArticleVo> page = new Page<>(adminArticleDto.getPageNum(), adminArticleDto.getPageSize());
        ArticleEntity articleEntity = new ArticleEntity();
        String columnIdStr = adminArticleDto.getColumnIdStr();
        if(StrUtil.isNotEmpty(columnIdStr)){
            long[] columnIdLongs = StrUtil.splitToLong(columnIdStr, StrUtil.COMMA);
            List<Long> columnList = new ArrayList<>();
            for(long columnIdLong : columnIdLongs){
                columnList.add(columnIdLong);
            }
            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);
            }
        }
        articleEntity.setCompanyId(24L);
        IPage<AdminArticleVo> list = articleMapper.selectAdminArticleInPage(page,articleEntity);
        System.out.println(list.getRecords());
    }
}