From 3ee5e65b2052ca20801ef7bb1a60ecc496766ee4 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Tue, 09 Aug 2022 15:19:41 +0800 Subject: [PATCH] 20220809 最大上传150 --- src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 101 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java b/src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java index 03a4448..888ee4a 100644 --- a/src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java +++ b/src/test/java/com/xcong/farmer/cms/KssframeworkApplicationTests.java @@ -1,7 +1,11 @@ package com.xcong.farmer.cms; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.file.FileWriter; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -11,15 +15,14 @@ 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.entity.*; 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.mapper.CompanyMapper; 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; @@ -32,6 +35,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -48,6 +53,32 @@ @Resource private CmsTemplateMapper cmsTemplateMapper; + @Test + public void testFileWrite(){ + Long companyId = 24L; + Long id = 38L; + CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectByIdAndCompanyId(id,companyId); + String name = cmsTemplateEntity.getName(); + Integer type = cmsTemplateEntity.getType(); + String templatePath = "D:\\cmshtml"; + String path = cmsTemplateEntity.getPath(); + + cmsTemplateMapper.delete(id,companyId); + String pathNew = FileUtils.path(templatePath, path); + File file = new File(pathNew); + FileUtil.touch(file); + + //文件写入,直接覆盖 + FileWriter writer = new FileWriter(file); + writer.write("测试121634964949", false); + + CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); + cmsTemplate.setCompanyId(companyId); + cmsTemplate.setType(type); + cmsTemplate.setName(name); + cmsTemplate.setPath(path); + cmsTemplateMapper.insert(cmsTemplate); + } @Test public void testUserInsert() { for(int i = 0; i < 20; i++) { @@ -77,7 +108,7 @@ public void viewTemplateInfo() { Long id = 4L; CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectById(id); - String htmlUrl = cmsProperties.getBaseUrl() + cmsProperties.getTemplatePath(); + String htmlUrl = "" + cmsProperties.getTemplatePath(); File uploadDir = new File(htmlUrl); if (!uploadDir.isDirectory()) { uploadDir.mkdir(); @@ -123,17 +154,80 @@ @Autowired private ArticleMapper articleMapper; + @Autowired + private CompanyMapper companyMapper; + + @Test + public void testCompanyId(){ + String website = "127.0.0.1"; + Long companyIdFromWebsite = getCompanyIdFromWebsite(website); + System.out.print(companyIdFromWebsite); + } + + private Long getCompanyIdFromWebsite(String website){ + List<CompanyEntity> companyEntities = companyMapper.selectList(new QueryWrapper<>()); + Long companyId = 0L; + if(CollUtil.isNotEmpty(companyEntities)){ + for(CompanyEntity companyEntity : companyEntities){ + boolean contains = StrUtil.contains(companyEntity.getWebAddress(), website); + if(contains){ + companyId = companyEntity.getId(); + } + } + } + return companyId; + } + + public static void main(String[] args) { + for(int i=0;i<10;i++){ + BigDecimal partnerIncomeNum = RandomUtil.randomBigDecimal(new BigDecimal("5000.001"), new BigDecimal("10000.0001")).setScale(6, RoundingMode.HALF_DOWN); + System.out.println(partnerIncomeNum); + } + } + + @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.setColumnId(columnIdStrs); + 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.getColumnId(); + String columnIdStr = adminArticleDto.getColumnIdStr(); if(StrUtil.isNotEmpty(columnIdStr)){ long[] columnIdLongs = StrUtil.splitToLong(columnIdStr, StrUtil.COMMA); List<Long> columnList = new ArrayList<>(); -- Gitblit v1.9.1