Commit 18e37ecc authored by eddie.woo's avatar eddie.woo

Merge remote-tracking branch 'remotes/origin/dev' into dev_eddie

parents 21f28b5d 91356e40
package pwc.taxtech.atms.controller; package pwc.taxtech.atms.controller;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.common.ApplicationException;
import pwc.taxtech.atms.dto.TemplateDto; import pwc.taxtech.atms.dto.TemplateDto;
import pwc.taxtech.atms.service.TemplateService; import pwc.taxtech.atms.service.TemplateService;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -41,4 +46,50 @@ public class TemplateController { ...@@ -41,4 +46,50 @@ public class TemplateController {
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@RequestMapping(value = "getTemplateJson", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
void getTemplateBlob(@RequestParam String templateID, HttpServletResponse response) {
String filePath;
File templateFile;
InputStream inputStream = null;
String templatePath = templateService.getTemplatePath(templateID);
if(StringUtils.isEmpty(templateID))
{
return;
}
if (templatePath==null||StringUtils.isEmpty(templatePath)){
return;
}
filePath = this.getClass().getResource("/").getPath();
templateFile = new File(filePath + templateService.getTemplatePath(templateID));
try {
inputStream = new BufferedInputStream(new FileInputStream(templateFile));
//客户端保存的文件名
String customFileName = "template_" + DateTime.now().toString("yyyyMMddHHmmss") + ".xlsx";
response.setHeader("Content-Disposition", String.format("inline; filename=\"" + customFileName + "\""));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
FileCopyUtils.copy(inputStream, response.getOutputStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
logger.error("Error downloading template file template.xlsx", e);
throw new ApplicationException("Error downloading template file template.xlsx", e);
} finally {
try {
templateFile = null;
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
logger.error("Error closing inputStream. ", e);
} finally {
inputStream = null;
}
}
}
} }
...@@ -11,4 +11,6 @@ public interface TemplateService { ...@@ -11,4 +11,6 @@ public interface TemplateService {
* @return 模板DTO 列表 * @return 模板DTO 列表
*/ */
List<TemplateDto> get(String templateGroupID, Integer reportType); List<TemplateDto> get(String templateGroupID, Integer reportType);
String getTemplatePath(String templateID);
} }
...@@ -35,4 +35,19 @@ public class TemplateServiceImpl extends AbstractService implements TemplateServ ...@@ -35,4 +35,19 @@ public class TemplateServiceImpl extends AbstractService implements TemplateServ
} }
return templateDtos; return templateDtos;
} }
@Override
public String getTemplatePath(String templateID) {
String result = "";
Template template = templateMapper.selectByPrimaryKey(templateID);
if (template != null) {
if (template.getPath().startsWith("~")) {
result = template.getPath().substring(1, template.getPath().length() - 1);
} else {
result = template.getPath();
}
}
return result;
}
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment