package com.whyc.service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.whyc.constant.UserOperation; import com.whyc.dto.Response; import com.whyc.mapper.ProcedureDocMapper; import com.whyc.pojo.ProcedureDoc; import com.whyc.util.ActionUtil; import com.whyc.util.CommonUtil; import com.whyc.util.FileUtil; import com.whyc.util.Word2PdfAsposeUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.Date; import java.util.List; @Service public class ProcedureDocService { @Resource private ProcedureDocMapper mapper; @Autowired private DocLogService logService; 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, HttpServletRequest req, 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); //记录日志 logService.recordOperationLog(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),req.getRemoteAddr(),filename,absolutePath); } public Response getListPage(ProcedureDoc procedureDoc, int pageNum, int pageSize) { PageHelper.startPage(pageNum,pageSize); List list = mapper.getListPage(procedureDoc); PageInfo pageInfo = new PageInfo<>(list); return new Response().set(1,pageInfo); } }