fix
Helius
2022-07-07 07326eeadfd578b7f9e19305b6ecdde992efaea7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.xcong.farmer.cms;
 
import cn.hutool.core.util.ObjectUtil;
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.WebArticleInPageDto;
import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity;
import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper;
import com.xcong.farmer.cms.modules.system.util.LoginUserUtil;
import com.xcong.farmer.cms.modules.test.dao.TestUserDao;
import com.xcong.farmer.cms.modules.test.entity.TestUserEntity;
import org.jsoup.Jsoup;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
 
@SpringBootTest
class KssframeworkApplicationTests {
 
    @Resource
    private TestUserDao testUserDao;
 
    @Resource
    private CmsTemplateMapper cmsTemplateMapper;
 
    @Test
    public void testUserInsert() {
        for(int i = 0; i < 20; i++) {
            TestUserEntity testUser = new TestUserEntity();
            testUser.setCreateBy("123");
            testUser.setCreateTime(new Date());
            testUser.setUpdateBy("123");
            testUser.setUpdateTime(new Date());
            testUser.setAccount("12345" + i);
            testUser.setName("hehe" + i);
            testUser.setPassword("33333");
            testUserDao.insert(testUser);
        }
 
    }
 
    @Test
    public void start() {
        System.out.println(1);
    }
 
 
    @Autowired
    private CmsProperties cmsProperties;
 
    @Test
    public void viewTemplateInfo() {
        Long id = 4L;
        CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectById(id);
        String htmlUrl = cmsProperties.getBaseUrl() + cmsProperties.getTemplatePath();
        File uploadDir = new File(htmlUrl);
        if (!uploadDir.isDirectory()) {
            uploadDir.mkdir();
        }
        htmlUrl = "D:\\cmshtml";
        String pathName = htmlUrl+"\\"+cmsTemplateEntity.getPath();
        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);
    }
 
    @Test
    public void path(){
        Long id = 6L;
        CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectById(id);
        String templatePath = cmsProperties.getTemplatePath();
        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);
    }
 
    @Test
    public void dateTest(){
        WebArticleInPageDto webArticleInPageDto = new WebArticleInPageDto();
        webArticleInPageDto.setTimeType("一周内");
        System.out.println(webArticleInPageDto.getTimeType());
    }
 
}