whycxzp
2022-12-07 00e4715a062585ad8e4f9dbaea8910b06e8ff228
流程卡和SOP更新
10个文件已修改
3个文件已添加
335 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/ProcedureDocController.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/WorksheetLinkController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/WorksheetMainController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/WorksheetLinkMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/WorksheetLink.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProcedureDocService.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetLinkService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetMainService.java 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/FileUtil.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/Word2PdfAsposeUtil.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/webSocket/ProcedureDocApprovingSocket.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/license.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/WorksheetLinkMapper.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ProcedureDocController.java
New file
@@ -0,0 +1,37 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.service.ProcedureDocService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
@Api(tags = "流程卡和SOP")
@RequestMapping("procedureDoc")
@RestController
public class ProcedureDocController {
    @Autowired
    private ProcedureDocService service;
    @GetMapping("preview")
    @ApiOperation("文件预览")
    public Response preview(@RequestParam String filePath){
        return service.preview(filePath);
    }
    @GetMapping("download")
    @ApiOperation("文件下载")
    public void download(@RequestParam String filePath, HttpServletResponse response){
        service.download(filePath, response);
    }
}
src/main/java/com/whyc/controller/WorksheetLinkController.java
@@ -40,7 +40,7 @@
    }
    @PutMapping("confirmProductProcedureAndSOP")
    @ApiOperation(value = "流程卡及SOP确认",notes = "id; linkStatus:确认1,拒绝2; dealReason:拒绝时填写处理意见")
    @ApiOperation(tags = "流程卡和SOP",value = "确认过程-流程卡及SOP确认",notes = "id; linkStatus:确认1,拒绝2; dealReason:拒绝时填写处理意见")
    public Response confirmProductProcedureAndSOP(@RequestBody WorksheetLink link) throws IOException {
        return service.confirmProductProcedureAndSOP(link);
    }
src/main/java/com/whyc/controller/WorksheetMainController.java
@@ -17,6 +17,7 @@
import org.springframework.web.multipart.MultipartFile;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@@ -127,14 +128,14 @@
    }
    @GetMapping("handlingListPage")
    @ApiOperation("查看分页-待处理")
    @ApiOperation(tags = "流程卡和SOP",value = "查看分页-待处理")
    public Response<PageInfo<WorksheetMain>> getHandlingListPage(@RequestParam int pageNum, @RequestParam int pageSize){
        DocUser user = ActionUtil.getUser();
        return service.getHandlingListPage(user,pageNum,pageSize);
    }
    @GetMapping("handledListPage")
    @ApiOperation("查看分页-已处理")
    @ApiOperation(tags = "流程卡和SOP",value = "查看分页-已处理")
    public Response<PageInfo<WorksheetMain>> getHandledListPage(@RequestParam int pageNum, @RequestParam int pageSize){
        DocUser user = ActionUtil.getUser();
        return service.getHandledListPage(user,pageNum,pageSize);
@@ -155,7 +156,7 @@
    }
    @GetMapping("myListPage")
    @ApiOperation("我的工单")
    @ApiOperation(tags = "流程卡和SOP",value = "我的工单")
    public Response<PageInfo<WorksheetMain>> getMyList(@RequestParam int pageNum,@RequestParam int pageSize){
        DocUser user = ActionUtil.getUser();
        return service.getMyList(pageNum,pageSize,user);
@@ -169,11 +170,16 @@
     * @throws MessagingException
     */
    @PostMapping("productProcedureAndSOP")
    @ApiOperation(value = "产品流程卡及SOP提交",notes = "type:1-流程卡,2-SOP")
    @ApiOperation(tags = "流程卡和SOP",value = "确认过程-产品流程卡及SOP提交",notes = "type:1-流程卡,2-SOP")
    public Response addProductProcedureAndSOP(@RequestBody ProcedureDocApproving approving) throws IOException, MessagingException {
        DocUser user = ActionUtil.getUser();
        return service.addProductProcedureAndSOP(approving,user);
    }
    @GetMapping("procedurePreview")
    @ApiOperation(tags = "流程卡和SOP",value = "确认过程-预览pdf",notes = "")
    public Response procedurePreview(HttpServletResponse response,@RequestParam int mainId) throws IOException {
        return service.procedurePreview(response,mainId);
    }
}
src/main/java/com/whyc/mapper/WorksheetLinkMapper.java
@@ -15,4 +15,8 @@
    DocUser getApprovingUser(Integer mainId);
    List<WorksheetLink> getProcedureDocApprovingByUserId(Long id);
    List<WorksheetLink> getList(int mainId);
}
src/main/java/com/whyc/pojo/WorksheetLink.java
@@ -62,6 +62,9 @@
    @TableField(exist = false)
    private WorksheetMain main;
    @TableField(exist = false)
    private String dealUsername;
    public Integer getId() {
        return id;
    }
@@ -182,4 +185,11 @@
        this.main = main;
    }
    public String getDealUsername() {
        return dealUsername;
    }
    public void setDealUsername(String dealUsername) {
        this.dealUsername = dealUsername;
    }
}
src/main/java/com/whyc/service/ProcedureDocService.java
@@ -1,10 +1,16 @@
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 {
@@ -15,4 +21,25 @@
    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);
    }
}
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -17,6 +17,7 @@
import javax.annotation.Resource;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -613,6 +614,24 @@
                String inFilePath = projectDir + File.separator + fileRelativePath;
                String outFilePath = (projectDir + File.separator + fileRelativePath).replace("_approving","");
                WordUtil.fillValue(inFilePath,outFilePath,Arrays.asList(approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb()));
                //删除之前预览产生的中间文件
                String filename = fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator)+1,fileRelativePath.lastIndexOf("."));
                File approvingDir = new File(projectDir + File.separator + "procedure_approving");
                FilenameFilter filenameFilter = new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        name = name.substring(0,name.lastIndexOf("."));
                        if(name.contains(filename) && !name.equals(filename)){
                            return true;
                        }
                        return false;
                    }
                };
                File[] files = approvingDir.listFiles(filenameFilter);
                for (File file : files) {
                    file.delete();
                }
                //流程文件数据转移
                ProcedureDoc procedureDoc = new ProcedureDoc();
                procedureDoc.setName(approving.getName());
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -14,6 +14,8 @@
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.*;
import com.whyc.util.CommonUtil;
import com.whyc.util.Word2PdfAsposeUtil;
import com.whyc.util.WordUtil;
import com.whyc.util.Zip4jUtil;
import org.aspectj.util.FileUtil;
import org.springframework.beans.BeanUtils;
@@ -25,6 +27,7 @@
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -737,12 +740,13 @@
    public Response addProductProcedureAndSOP(ProcedureDocApproving approving, DocUser user) throws IOException, MessagingException {
        WorksheetMain main = new WorksheetMain();
         //存储上传信息到主表,节点表
        //文件保存在/doc_file/procedure_approving/xxx.doc
        //文件保存在/doc_file/procedure_approving/xxx_时间戳.doc
        MultipartFile multipartFile = approving.getMultipartFile();
        String originalFilename = multipartFile.getOriginalFilename();
        String rootFile = CommonUtil.getRootFile();
        Date date = new Date();
        String suffixFilePath = "procedure_approving" + File.separator + date.getTime() + "_" + originalFilename;
        String filename = originalFilename.replace(".doc","_"+date.getTime()+".doc");
        String suffixFilePath = "procedure_approving" + File.separator + filename;
        String outFilePath = rootFile + suffixFilePath;
        File outFile = new File(outFilePath);
        multipartFile.transferTo(outFile);
@@ -808,4 +812,84 @@
        return new Response().setII(1,"上传完成");
    }
    /**
     * 统计数量:
     *  我的提交
     *  待处理
     *  已处理
     * @param user
     * @return
     */
    public Map<String, Integer> getProcedureDocApprovingStatusStatistic(DocUser user) {
        Map<String,Integer> map = new HashMap<>();
        //我的提交
        QueryWrapper<WorksheetMain> query = Wrappers.query();
        query.eq("create_user_id",user.getId()).in("type",EnumWorksheetType.ProductProcedure.getType(),EnumWorksheetType.SOP.getType());
        List<WorksheetMain> worksheetMains = mainMapper.selectList(query);
        map.put("mySubmit",worksheetMains.size());
        //待处理|已处理
        int handlingCount = 0;
        int handledCount = 0;
        List<WorksheetLink> links = linkMapper.getProcedureDocApprovingByUserId(user.getId());
        for (WorksheetLink link : links) {
            //dealType的值为主表的状态
            if(link.getDealType() == 1 && link.getLinkStatus() == 0){ //未处理且审批未结束
                handlingCount++;
            }else if(link.getLinkStatus() == 1 || link.getLinkStatus() ==2){ //已确认或已拒绝
                handledCount++;
            }
        }
        map.put("handling",handlingCount);
        map.put("handled",handledCount);
        return map;
    }
    public Response procedurePreview(HttpServletResponse response, int mainId) throws IOException {
        //查询当前单据审批人的确认状态
        ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId);
        List<WorksheetLink> linkList = linkMapper.getList(mainId);
        String fzr = linkList.get(0).getLinkStatus() == 1 ? linkList.get(0).getDealUsername():"";
        String bz = linkList.get(1).getLinkStatus() == 1 ? linkList.get(1).getDealUsername():"";
        String zz = linkList.get(2).getLinkStatus() == 1 ? linkList.get(2).getDealUsername():"";
        String pb = linkList.get(3).getLinkStatus() == 1 ? linkList.get(3).getDealUsername():"";
        List<String> list = new LinkedList();
        list.add(fzr);
        list.add(bz);
        list.add(zz);
        list.add(pb);
        //获取word模板具体文件
        long currentTimeMillis = System.currentTimeMillis();
        String projectDir = CommonUtil.getProjectDir();
        String fileRelativePath = approving.getFile();
        String inFilePath = projectDir + File.separator + fileRelativePath;
        String outFilePath = inFilePath.replace(".doc","_"+currentTimeMillis+".doc");
        WordUtil.fillValue(inFilePath,outFilePath,list);
        //pdf带水印的地址 /doc_file/procedure_approving/xxx.doc
        String suffixOutPdfFilePath = "doc_file" + File.separator + "procedure_approving" + File.separator + outFilePath.substring(outFilePath.lastIndexOf(File.separator)+1,outFilePath.lastIndexOf(".")) + ".pdf";
        String outPdfFilePath = projectDir + File.separator + suffixOutPdfFilePath;
        Word2PdfAsposeUtil.doc2pdfWithWaterMark(outFilePath,outPdfFilePath,true);
        return new Response().setII(1,suffixOutPdfFilePath);
        /*try {
            // 转码防止乱码
            //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator+1)), "utf-8"));
            OutputStream out = response.getOutputStream();
            FileInputStream in = new FileInputStream(outFilePath);
            int len=0;
            byte[] buffer =new byte[1024];
            //7. 将缓冲区中的数据输出
            while ((len=in.read(buffer))>0){
                out.write(buffer,0,len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }
}
src/main/java/com/whyc/util/FileUtil.java
@@ -1,6 +1,8 @@
package com.whyc.util;
import java.io.File;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@@ -60,6 +62,28 @@
        return true;
    }
    public static void download(HttpServletResponse resp,String inFilePath,String outFileFullName){
        try {
            // 转码防止乱码
            //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( outFileFullName, "utf-8"));
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(inFilePath);
            int len=0;
            byte[] buffer =new byte[1024];
            //7. 将缓冲区中的数据输出
            while ((len=in.read(buffer))>0){
                out.write(buffer,0,len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207泰州平台");
        List list = new ArrayList<>();
src/main/java/com/whyc/util/Word2PdfAsposeUtil.java
@@ -27,9 +27,9 @@
    }
    public static boolean doc2pdf(String inPath, String outPath) {
        /*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
            return false;
        }*/
        }
        FileOutputStream os = null;
        try {
            File file = new File(outPath); // 新建一个空白pdf文档
@@ -52,7 +52,7 @@
        return true;
    }
    public static boolean doc2pdfWithWaterMark(String inPath, String outPath) {
    public static boolean doc2pdfWithWaterMark(String inPath, String outPath,boolean markable) {
        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
            return false;
        }
@@ -61,7 +61,9 @@
            File file = new File(outPath); // 新建一个空白pdf文档
            os = new FileOutputStream(file);
            Document doc = new Document(inPath); // Address是将要被转化的word文档
            insertWaterMark(doc,"无效签名");
            if(markable) {
                insertWaterMark(doc, "无效签名");
            }
            doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
        } catch (Exception e) {
            e.printStackTrace();
@@ -137,7 +139,7 @@
    public static void main(String[] args) {
        doc2pdfWithWaterMark("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\流程卡和SOP的doc审批注入\\新FBI系列流程卡签字2.doc",
                "C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\流程卡和SOP的doc审批注入\\新FBI系列流程卡签字2-doc.pdf");
                "C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\流程卡和SOP的doc审批注入\\新FBI系列流程卡签字2-doc.pdf",true);
    }
}
src/main/java/com/whyc/webSocket/ProcedureDocApprovingSocket.java
New file
@@ -0,0 +1,74 @@
package com.whyc.webSocket;
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.DocUser;
import com.whyc.service.WorksheetMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.Map;
/**
 * 流程文件的状态统计
 */
@Component
@ServerEndpoint(value = "/procedureDocApproving",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class)
public class ProcedureDocApprovingSocket {
    private Session session;
    private Thread thread;
    private static WorksheetMainService mainService;
    @Autowired
    public void setWorksheetMainService(WorksheetMainService mainService) {
        ProcedureDocApprovingSocket.mainService = mainService;
    }
    @OnOpen
    public void onOpen(Session session, EndpointConfig config){
        this.session = session;
        HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    while (!currentThread().isInterrupted()) {
                        Map<String, Integer> statisticMap = mainService.getProcedureDocApprovingStatusStatistic((DocUser) httpSession.getAttribute("user"));
                        session.getBasicRemote().sendObject(new Response().set(1, statisticMap));
                        sleep(2000);
                    }
                } catch (Exception e) {
                    this.interrupt();
                }
            }
        };
        thread.start();
        this.thread = thread;
    }
    @OnClose
    public void onClose(CloseReason closeReason) throws IOException {
        System.err.println("closeReason = " + closeReason);
        this.thread.interrupt();
        if(session.isOpen()){
            session.close();
        }
    }
    @OnError
    public void onError(Throwable error) throws IOException {
        error.printStackTrace();
        this.thread.interrupt();
        if(session.isOpen()){
            session.close();
        }
    }
}
src/main/resources/license.xml
New file
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<License>
    <Data>
        <Products>
            <Product>Aspose.Total for Java</Product>
            <Product>Aspose.Words for Java</Product>
        </Products>
        <EditionType>Enterprise</EditionType>
        <SubscriptionExpiry>20991231</SubscriptionExpiry>
        <LicenseExpiry>20991231</LicenseExpiry>
        <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
    </Data>
    <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
src/main/resources/mapper/WorksheetLinkMapper.xml
@@ -55,6 +55,7 @@
        <choose>
            <when test="statusExp==0">
                AND link_status = 0
                AND m.status in(1,2)
            </when>
            <otherwise>
                AND link_status in(1,2)
@@ -75,6 +76,7 @@
        <choose>
            <when test="statusExp==0">
                AND link_status = 0
                AND m.status in(1,2)
            </when>
            <otherwise>
                AND link_status in(1,2)
@@ -85,4 +87,10 @@
    <select id="getApprovingUser" resultType="com.whyc.pojo.DocUser">
        SELECT u.* FROM tb_worksheet_link l,tb_doc_user u,tb_doc_depart d where l.deal_user_id = u.id and u.depart_id = d.depart_id and  l.main_id = #{mainId} and link_status = 0
    </select>
    <select id="getProcedureDocApprovingByUserId" resultType="com.whyc.pojo.WorksheetLink">
        SELECT l.type,m.status as dealType FROM tb_worksheet_link l,tb_worksheet_main m where l.main_id=m.id and m.type in(11,12)
    </select>
    <select id="getList" resultType="com.whyc.pojo.WorksheetLink">
        SELECT l.*,u.name as dealUsername FROM tb_worksheet_link l,tb_doc_user u where l.deal_user_id = u.id and main_id = #{mainId}
    </select>
</mapper>