UserSignDataToolsImpl.java
2.74 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
package com.bsth.service.logger.impl;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
@EnableConfigurationProperties(DataToolsProperties.class)
@Service(value = "usersign_dataTool")
public class UserSignDataToolsImpl implements DataToolsService {
/** 日志记录器 */
private final static Logger LOGGER = LoggerFactory.getLogger(UserSignDataToolsImpl.class);
@Autowired
@Qualifier(value = "dataToolsServiceImpl")
private DataToolsService dataToolsService;
@Autowired
private DataToolsProperties dataToolsProperties;
@Override
public DataToolsFile uploadFile(String filename, byte[] filedata) throws ScheduleException {
throw new RuntimeException("不支持DataToolsFile!");
}
@Override
public void importData(File file, Map<String, Object> params) throws ScheduleException {
throw new RuntimeException("不支持importData!");
}
@Override
public DataToolsFile exportData(Map<String, Object> params) throws ScheduleException {
try {
LOGGER.info("//---------------- 导出用户登录日志 start... ----------------//");
// 创建ktr转换所需参数
Map<String, Object> ktrParms = new HashMap<>();
File ktrFile = new File(this.getClass().getResource(
dataToolsProperties.getUsersignDataoutputktr()).toURI());
// 通用参数,转换文件路径,excel输出文件名
ktrParms.put("transpath", ktrFile.getAbsolutePath());
ktrParms.put("filename", "用户登录日志_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());
}
}
}