ScheduleRule1FlatDataToolsImpl.java
4.79 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
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
package com.bsth.service.schedule.datatools;
import com.bsth.service.schedule.exception.ScheduleException;
import com.bsth.service.schedule.utils.DataToolsFile;
import com.bsth.service.schedule.utils.DataToolsProperties;
import com.bsth.service.schedule.utils.DataToolsService;
import com.bsth.util.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* Created by xu on 17/5/16.
*/
@Service(value = "scheduleRule_dataTool")
public class ScheduleRule1FlatDataToolsImpl implements DataToolsService {
/** 日志记录器 */
private final static Logger LOGGER = LoggerFactory.getLogger(ScheduleRule1FlatDataToolsImpl.class);
@Autowired
@Qualifier(value = "dataToolsServiceImpl")
private DataToolsService dataToolsService;
@Autowired
private DataToolsProperties dataToolsProperties;
@Override
public DataToolsFile uploadFile(String filename, byte[] filedata) throws ScheduleException {
return this.dataToolsService.uploadFile(filename, filedata);
}
@Override
public void importData(File file, Map<String, Object> params) throws ScheduleException {
try {
LOGGER.info("//---------------- 导入排版规则信息 start... ----------------//");
// 创建ktr转换所需参数
Map<String, Object> ktrParms = new HashMap<>();
String country = Locale.getDefault().getLanguage();
File ktrFile = null;
if ("zh".equals(country)) {
ktrFile = new File(this.getClass().getResource(
dataToolsProperties.getZhScheduleRuleDataImport()).toURI());
} else if ("en".equals(country)) {
ktrFile = new File(this.getClass().getResource(
dataToolsProperties.getEnScheduleRuleDataImport()).toURI());
} else {
throw new Exception("not found Local[" + country + "] corresponding ktr.");
}
// 通用参数,转换文件路径,excel输入文件路径,错误输出文件路径
ktrParms.put("transpath", ktrFile.getAbsolutePath());
ktrParms.put("filepath", file.getAbsolutePath());
ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir());
ktrParms.putAll(params);
dataToolsService.importData(file, ktrParms);
LOGGER.info("//---------------- 导入排版规则信息 success... ----------------//");
} catch (Exception exp) {
LOGGER.info("//---------------- 导入排版规则信息 failed... ----------------//");
StringWriter sw = new StringWriter();
exp.printStackTrace(new PrintWriter(sw));
LOGGER.info(sw.toString());
throw new ScheduleException(exp.getMessage());
}
}
@Override
public DataToolsFile exportData(Map<String, Object> params) throws ScheduleException {
try {
LOGGER.info("//---------------- 导出排版规则信息 start... ----------------//");
// 创建ktr转换所需参数
Map<String, Object> ktrParms = new HashMap<>();
String country = Locale.getDefault().getLanguage();
File ktrFile = null;
if ("zh".equals(country)) {
ktrFile = new File(this.getClass().getResource(
dataToolsProperties.getZhScheduleRuleDataExport()).toURI());
} else if ("en".equals(country)) {
ktrFile = new File(this.getClass().getResource(
dataToolsProperties.getEnScheduleRuleDataExport()).toURI());
} else {
throw new Exception("not found Local[" + country + "] corresponding ktr.");
}
// 通用参数,转换文件路径,excel输出文件名
ktrParms.put("transpath", ktrFile.getAbsolutePath());
ktrParms.put("filename", I18n.getInstance().getMessage("txt-1836") + "_download-");
ktrParms.putAll(params);
DataToolsFile file = dataToolsService.exportData(ktrParms);
LOGGER.info("//---------------- 导出排版规则信息 success... ----------------//");
return file;
} catch (Exception exp) {
LOGGER.info("//---------------- 导出排版规则信息 failed... ----------------//");
StringWriter sw = new StringWriter();
exp.printStackTrace(new PrintWriter(sw));
LOGGER.info(sw.toString());
throw new ScheduleException(exp.getMessage());
}
}
}