whyclxw
2 天以前 12154b62b42df29173cdc54d7fd35d02d9a6422b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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<ProcedureDoc> list = mapper.getListPage(procedureDoc);
        PageInfo<ProcedureDoc> pageInfo = new PageInfo<>(list);
        return new Response().set(1,pageInfo);
    }
}