fix
Helius
2022-07-12 3dc1ca272294451ba48277e201a22d596d10e645
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.xcong.farmer.cms.modules.core.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.xcong.farmer.cms.core.template.TemplateConfiguration;
import com.xcong.farmer.cms.modules.core.service.ICmsCoreService;
import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper;
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.List;
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;
 
    @Autowired
    private WebSetMapper webSetMapper;
 
 
    @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"));
        globalData(data);
        if (StrUtil.isEmpty(templateName)) {
            templateName = "defualt.article.html";
        }
 
        try {
            cfg.process(data, templateName);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("发布文章出错", e);
        }
    }
 
    @Override
    public void articlesProcess(Map<String, Object> data, List<Long> ids, String templateName, String templatePath) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
 
        for (Long id : ids) {
            data.put("id", id);
            articleProcess(data, templateName, templatePath);
        }
    }
 
    @Override
    public void columnsProcess(Map<String, Object> data, List<Long> ids, String templateName) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
 
        for (Long id : ids) {
            data.put("id", id);
            columnProcess(data, templateName);
        }
    }
 
    @Override
    public void columnProcess(Map<String, Object> data, String templateName) {
        data.put("templateType", "column");
        data.put("page", 1);
        globalData(data);
        if (StrUtil.isEmpty(templateName)) {
            templateName = "defualt.list.html";
        }
 
        try {
            cfg.process(data, templateName);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("发布栏目错误", e);
        }
    }
 
    @Override
    public void indexProcess(@NotNull Map<String, Object> data, String templateName) {
        data.put("templateType", "index");
        globalData(data);
        if (StrUtil.isEmpty(templateName)) {
            templateName = "index.html";
        }
 
        try {
            cfg.process(data, templateName);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("发布首页错误", e);
        }
    }
 
    @Override
    public void process(Map<String, Object> data, String templateType, String templateName) {
        data.put("templateType", templateType);
        globalData(data);
 
        if ("search".equals(templateType) && StrUtil.isBlank(templateName)) {
            templateName = "search.html";
        }
 
        if ("message".equals(templateType) && StrUtil.isBlank(templateName)) {
            templateName = "message.html";
        }
 
        try {
            cfg.process(data, templateName);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("发布错误", e);
        }
    }
 
    private void globalData(Map<String, Object> data) {
        Long companyId = (Long) data.get("companyId");
        Map<String, String> globalSetting = webSetMapper.selectSiteGlobalSetting(companyId);
 
        data.putAll(globalSetting);
    }
}