Commit c2cb54a3 authored by frank.xa.zhang's avatar frank.xa.zhang

add new files for the spreadjs and template

parent e35b2ede
package pwc.taxtech.atms.controller;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.common.ApplicationException;
import pwc.taxtech.atms.dto.TemplateDto;
import pwc.taxtech.atms.service.TemplateService;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Collections;
import java.util.List;
......@@ -41,4 +46,50 @@ public class TemplateController {
}
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 {
* @return 模板DTO 列表
*/
List<TemplateDto> get(String templateGroupID, Integer reportType);
String getTemplatePath(String templateID);
}
......@@ -35,4 +35,19 @@ public class TemplateServiceImpl extends AbstractService implements TemplateServ
}
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