Generator.java
2.99 KB
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
package com.viontech.storage.entity;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.viontech.storage.model.Caption;
import com.viontech.storage.model.PicConfig;
import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.CaptionService;
import com.viontech.storage.service.PicConfigService;
import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.CaptionVo;
import com.viontech.storage.vo.PicConfigVo;
import com.viontech.storage.vo.StorageConfigVo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
public class Generator {
private static final String ROOT_ELEMENT_NAME = "StorageConfig";
private static final String FILE_VERSION = "001-012-000-000";
private static final TimedCache<Long, String> STORAGE_CONFIG_ID_RESULT_CACHE = CacheUtil.newTimedCache(20 * 1000);
private StorageConfigVo storageConfigVo;
/** key: picConfigVoId */
private Map<Long, PicConfigVo> picConfigVoMap;
/** key: captionSetId */
private Map<Long, List<CaptionVo>> captionMap;
public Generator create(Long storageConfigId) {
StorageConfigService storageConfigService = SpringUtil.getBean(StorageConfigService.class);
PicConfigService picConfigService = SpringUtil.getBean(PicConfigService.class);
CaptionService captionService = SpringUtil.getBean(CaptionService.class);
StorageConfig storageConfig0 = storageConfigService.getById(storageConfigId);
this.storageConfigVo = StorageConfigVo.copy(storageConfig0);
List<Long> picConfigIds = storageConfigVo.getContexts().stream().map(Context::getPicConfigId).collect(Collectors.toList());
List<PicConfig> picConfigs = picConfigService.listByIds(picConfigIds);
this.picConfigVoMap = new HashMap<>(picConfigs.size());
ArrayList<Long> captionSetIds = new ArrayList<>();
for (PicConfig item : picConfigs) {
PicConfigVo copy = PicConfigVo.copy(item);
picConfigVoMap.put(copy.getId(), copy);
captionSetIds.add(copy.getCaptionSetId());
}
List<Caption> captions = captionService.list(
captionService.query().in("caption_set_id", captionSetIds)
);
this.captionMap = captions.stream().map(CaptionVo::copy).collect(Collectors.groupingBy(CaptionVo::getCaptionSetId, Collectors.toList()));
return this;
}
public String build() {
Document root = XmlUtil.createXml("StorageConfig");
Element fileVersion = root.createElement("FileVersion");
fileVersion.setTextContent(FILE_VERSION);
Element standard = root.createElement("Standard");
return XmlUtil.toStr(root, "GBK", false);
}
}