package com.whyc.service;
|
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.ProcedureDocMapper;
|
import com.whyc.pojo.ProcedureDoc;
|
import com.whyc.util.CommonUtil;
|
import com.whyc.util.FileUtil;
|
import com.whyc.util.Word2PdfAsposeUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.File;
|
|
@Service
|
public class ProcedureDocService {
|
|
@Resource
|
private ProcedureDocMapper mapper;
|
|
public void insert(ProcedureDoc procedureDoc) {
|
mapper.insert(procedureDoc);
|
}
|
|
public Response preview(String filePath) {
|
String fileSuffix = filePath.substring(filePath.lastIndexOf(".")+1);
|
String suffixOutFilePath;
|
if(fileSuffix.equals("doc")){
|
suffixOutFilePath = filePath.replace(".doc","-doc.pdf");
|
}else{
|
suffixOutFilePath = filePath.replace(".docx","-docx.pdf");
|
}
|
String projectDir = CommonUtil.getProjectDir();
|
Word2PdfAsposeUtil.doc2pdf(projectDir + File.separator + filePath,
|
projectDir + File.separator + suffixOutFilePath);
|
return new Response().setII(1,suffixOutFilePath);
|
}
|
|
public void download(String filePath, HttpServletResponse response) {
|
String projectDir = CommonUtil.getProjectDir();
|
String absolutePath = projectDir + File.separator + filePath;
|
String filename = filePath.substring(filePath.lastIndexOf(File.separator)+1);
|
FileUtil.download(response,absolutePath,filename);
|
}
|
}
|