@PostMapping("/download/SddTemplate")
@WoAddUser
@WoAuditLog(value = AuditLogTypeConstant.QUERY)
public void downloadSddTemplate(HttpServletResponse response, @RequestBody @Validated LanguageBody languageBody) {
iSddDataManagementService.downloadSddTemplate(response, languageBody);
}
void downloadSddTemplate(HttpServletResponse response, LanguageBody languageBody);
@Override
public void downloadSddTemplate(HttpServletResponse response, LanguageBody languageBody) {
String filePath = null;
if (EN.equals(languageBody.getLanguage())) {
filePath = "/excelTemplate/" + "sdd_en.xlsx";
} else {
filePath = "/excelTemplate/" + "sdd_cn.xlsx";
}
FileUtil.downloadExcel(response, filePath);
}
public static void downloadExcel(HttpServletResponse response, String filePath) {
OutputStream outputStream = null;
InputStream inputStream = null;
try {
ClassPathResource cpr = new ClassPathResource(filePath);
inputStream = cpr.getInputStream();
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=template.xlsx");
outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
LOG.error("download task excel IOException failed!");
} } finally {
CommonUtils.close(outputStream);
CommonUtils.close(inputStream);
}
}
public static void close(Closeable stream) {
if (null != stream) {
try {
stream.close();
} catch (IOException e) {
LOGGER.error("close stream failed!");
}
}
}