Helius
2022-07-07 ea4120a80f7ef6188a745d9b27238cde1a3f7d74
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
package com.xcong.farmer.cms.modules.core.service.impl;
 
import cn.hutool.core.util.StrUtil;
import com.xcong.farmer.cms.core.template.TemplateConfiguration;
import com.xcong.farmer.cms.modules.core.service.ICmsCoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
 
/**
 * @author wzy
 * @date 2022-07-03
 **/
@Slf4j
@Service
public class CmsCoreServiceImpl implements ICmsCoreService {
 
    @Autowired
    private TemplateConfiguration cfg;
    private final Executor executor = new ThreadPoolExecutor(5, 10, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
 
 
    @Override
    public void articleProcess(Map<String, Object> data, String templateName, String templatePath) {
        data.put("templateType", "article");
        data.put("templatePath", templatePath);
        data.put("templateName", data.get("id"));
        if (StrUtil.isEmpty(templateName)) {
            templateName = "defualt.artile.html";
        }
 
        String finalTemplateName = templateName;
        executor.execute(() -> cfg.process(data, finalTemplateName));
    }
 
    @Override
    public void columnProcess(Map<String, Object> data, String templateName) {
        data.put("templateType", "column");
        data.put("page", 1);
        if (StrUtil.isEmpty(templateName)) {
            templateName = "defualt.list.html";
        }
 
        String finalTemplateName = templateName;
        executor.execute(() -> cfg.process(data, finalTemplateName));
    }
 
    @Override
    public void indexProcess(@NotNull Map<String, Object> data, String templateName) {
        if (StrUtil.isEmpty(templateName)) {
            templateName = "index.html";
        }
 
        String finalTemplateName = templateName;
        executor.execute(() -> cfg.process(data, finalTemplateName));
    }
}