SpringBoot實現(xiàn)電子文件簽字+合同系統(tǒng)!

原文:
blog.csdn.net/weixin_44385486/article/details/126481493

一、前言

今天公司領(lǐng)導(dǎo)提出一個功能,說實現(xiàn)一個文件的簽字+蓋章功能,然后自己進行了簡單的學(xué)習,對文檔進行數(shù)字簽名與簽署紙質(zhì)文檔的原因大致相同,數(shù)字簽名通過使用計算機加密來驗證 (身份驗證:驗證人員和產(chǎn)品所聲明的身份是否屬實的過程。例如,通過驗證用于簽名代碼的數(shù)字簽名來確認軟件發(fā)行商的代碼來源和完整性。)數(shù)字信息,如文檔、電子郵件和宏。數(shù)字簽名有助于確保:真實性,完整性,不可否認性。目前市面上的電子簽章產(chǎn)品也是多樣化,但是不管是哪個廠家的產(chǎn)品,在線簽章簡單易用,同時也能保證簽章的有效性,防篡改,防偽造,穩(wěn)定,可靠就是好產(chǎn)品。

此次開源的系統(tǒng)模擬演示了文件在OA系統(tǒng)中的流轉(zhuǎn),主要為辦公系統(tǒng)跨平臺在線處理Office文檔提供了完美的解決方案。Word文檔在線處理的核心環(huán)節(jié),包括:起草文檔、領(lǐng)導(dǎo)審批、核稿、領(lǐng)導(dǎo)蓋章、正式發(fā)文。PageOffice產(chǎn)品支持PC端Word文檔在線處理的所有環(huán)節(jié);MobOffice產(chǎn)品支持了移動端領(lǐng)導(dǎo)審批和領(lǐng)導(dǎo)蓋章的功能。支持PC端和移動端對文檔審批和蓋章的互認。然后此次博客中使用的卓正軟件的電子簽章采用自主知識產(chǎn)權(quán)的核心智能識別驗證技術(shù),確保文檔安全可靠。采用 COM、ActiveX嵌入式技術(shù)開發(fā),確保軟件能夠支持多種應(yīng)用。遵循《中華人民共和國電子簽名法》關(guān)于電子簽名的規(guī)范,同時支持國際通用的 RSA算法,符合國家安全標準。

PageOffice和MobOffice產(chǎn)品結(jié)合使用為跨平臺處理Office文件提供了完美的解決方案,主要功能有word在線編輯保存和留痕,word和pdf文件在線蓋章(電子印章)。

推薦:2022年Java面試題整理 持續(xù)更新中

二、項目源碼及部署

1、項目結(jié)構(gòu)及使用框架

該簽字+蓋章流程系統(tǒng)使用了SpringBoot+thymeleaf實現(xiàn)的,然后jar包依賴使用了maven

  • 控制層
@Controller
@RequestMapping("/mobile")
public class MobileOfficeController {

    @Value("${docpath}")
    private  String docPath;

    @Value("${moblicpath}")
    private  String moblicpath;

    @Autowired
    DocService m_docService;

    /**
     * 添加MobOffice的服務(wù)器端授權(quán)程序Servlet(必須)
     *
     */
    @RequestMapping("/opendoc")
    public void opendoc(HttpServletRequest request, HttpServletResponse response, HttpSession session,String type,String userName)throws  Exception {
        String fileName = "";
        userName= URLDecoder.decode(userName,"utf-8");

        Doc doc=m_docService.getDocById(1);
        if(type.equals("word")){
            fileName = doc.getDocName();
        }else{
            fileName = doc.getPdfName();
        }
        OpenModeType openModeType = OpenModeType.docNormalEdit;

        if (fileName.endsWith(".doc")) {
            openModeType = OpenModeType.docNormalEdit;
        } else if (fileName.endsWith(".pdf")) {
            String mode = request.getParameter("mode");
            if (mode.equals("normal")) {
                openModeType = OpenModeType.pdfNormal;
            } else {
                openModeType = OpenModeType.pdfReadOnly;
            }
        }

        MobOfficeCtrl mobCtrl = new MobOfficeCtrl(request,response);
        mobCtrl.setSysPath(moblicpath);
        mobCtrl.setServerPage("/mobserver.zz");
        //mobCtrl.setZoomSealServer("http://xxx.xxx.xxx.xxx:8080/ZoomSealEnt/enserver.zz");
        mobCtrl.setSaveFilePage("/mobile/savedoc?testid="+Math.random());
        mobCtrl.webOpen("file://"+docPath+fileName,  openModeType , userName);
    }

    @RequestMapping("/savedoc")
    public  void  savedoc(HttpServletRequest request,  HttpServletResponse response){
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(docPath+fs.getFileName());
        fs.close();
    }
}
  • 項目業(yè)務(wù)層源碼
@Service
public class DocServiceImpl implements DocService {
    @Autowired
    DocMapper docMapper;
    @Override
    public Doc getDocById(int id) throws Exception {
        Doc  doc=docMapper.getDocById(id);
        //如果doc為null的話,頁面所有doc.屬性都報錯
        if(doc==null) {
            doc=new Doc();
        }
        return doc;
    }

    @Override
    public Integer addDoc(Doc doc) throws Exception {
       int id=docMapper.addDoc(doc);
        return id;
    }

    @Override
    public Integer updateStatusForDocById(Doc doc) throws Exception {
        int id=docMapper.updateStatusForDocById(doc);
        return id;
    }

    @Override
    public Integer updateDocNameForDocById(Doc doc) throws Exception {
        int id=docMapper.updateDocNameForDocById(doc);
        return id;
    }

    @Override
    public Integer updatePdfNameForDocById(Doc doc) throws Exception {
        int id=docMapper.updatePdfNameForDocById(doc);
        return id;
    }
}
  • 拷貝文件
public class CopyFileUtil {
  //拷貝文件
  public static boolean copyFile(String oldPath, String newPath) throws Exception {
      boolean copyStatus=false;

      int bytesum = 0;
      int byteread = 0;
      File oldfile = new File(oldPath);
      if (oldfile.exists()) { //文件存在時
          InputStream inStream = new FileInputStream(oldPath); //讀入原文件
          FileOutputStream fs = new FileOutputStream(newPath);

          byte[] buffer = new byte[1444];
          int length;
          while ((byteread = inStream.read(buffer)) != -1) {
              bytesum += byteread; //字節(jié)數(shù) 文件大小
              //System.out.println(bytesum);
              fs.write(buffer, 0, byteread);
          }
          fs.close();
          inStream.close();
          copyStatus=true;
      }else{
          copyStatus=false;
      }
      return copyStatus;
  }
}
  • 二維碼源碼
public class QRCodeUtil {
    private String codeText;//二維碼內(nèi)容
    private BarcodeFormat barcodeFormat;//二維碼類型
    private int width;//圖片寬度
    private int height;//圖片高度
    private String imageformat;//圖片格式
    private int backColorRGB;//背景色,顏色RGB的數(shù)值既可以用十進制表示,也可以用十六進制表示
    private int codeColorRGB;//二維碼顏色
    private ErrorCorrectionLevel errorCorrectionLevel;//二維碼糾錯能力
    private String encodeType;

    public QRCodeUtil() {
        codeText = "www.zhuozhengsoft.com";
        barcodeFormat = BarcodeFormat.PDF_417;
        width = 400;
        height = 400;
        imageformat = "png";
        backColorRGB = 0xFFFFFFFF;
        codeColorRGB = 0xFF000000;
        errorCorrectionLevel = ErrorCorrectionLevel.H;
        encodeType = "UTF-8";
    }
    public QRCodeUtil(String text) {
        codeText = text;
        barcodeFormat = BarcodeFormat.PDF_417;
        width = 400;
        height = 400;
        imageformat = "png";
        backColorRGB = 0xFFFFFFFF;
        codeColorRGB = 0xFF000000;
        errorCorrectionLevel = ErrorCorrectionLevel.H;
        encodeType = "UTF-8";
    }

    public String getCodeText() {
        return codeText;
    }

    public void setCodeText(String codeText) {
        this.codeText = codeText;
    }

    public BarcodeFormat getBarcodeFormat() {
        return barcodeFormat;
    }

    public void setBarcodeFormat(BarcodeFormat barcodeFormat) {
        this.barcodeFormat = barcodeFormat;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getImageformat() {
        return imageformat;
    }

    public void setImageformat(String imageformat) {
        this.imageformat = imageformat;
    }

    public int getBackColorRGB() {
        return backColorRGB;
    }

    public void setBackColorRGB(int backColorRGB) {
        this.backColorRGB = backColorRGB;
    }

    public int getCodeColorRGB() {
        return codeColorRGB;
    }

    public void setCodeColorRGB(int codeColorRGB) {
        this.codeColorRGB = codeColorRGB;
    }

    public ErrorCorrectionLevel getErrorCorrectionLevel() {
        return errorCorrectionLevel;
    }

    public void setErrorCorrectionLevel(ErrorCorrectionLevel errorCorrectionLevel) {
        this.errorCorrectionLevel = errorCorrectionLevel;
    }

    private BufferedImage toBufferedImage(BitMatrix bitMatrix) {
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                image.setRGB(x, y, bitMatrix.get(x, y) ? this.codeColorRGB: this.backColorRGB);
            }
        }
        return image;
    }

    private byte[] writeToBytes(BitMatrix bitMatrix)
            throws IOException {

        try {
            BufferedImage bufferedimage = toBufferedImage(bitMatrix);

            //將圖片保存到臨時路徑中
            File file = java.io.File.createTempFile("~pic","."+ this.imageformat);
            //System.out.println("臨時圖片路徑:"+file.getPath());
            ImageIO.write(bufferedimage,this.imageformat,file);

            //獲取圖片轉(zhuǎn)換成的二進制數(shù)組
            FileInputStream fis = new FileInputStream(file);
            int fileSize = fis.available();
            byte[] imageBytes = new byte[fileSize];
            fis.read(imageBytes);
            fis.close();

            //刪除臨時文件
            if (file.exists()) {
                file.delete();
            }

            return imageBytes;
        } catch (Exception e) {
            System.out.println(" Image err :" + e.getMessage());
            return null;
        }

    }

    //獲取二維碼圖片的字節(jié)數(shù)組
    public byte[] getQRCodeBytes()
            throws IOException {

        try {
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();

            //設(shè)置二維碼參數(shù)
            Map hints = new HashMap();
            if (this.errorCorrectionLevel != null) {
                //設(shè)置二維碼的糾錯級別
                hints.put(EncodeHintType.ERROR_CORRECTION, this.errorCorrectionLevel);
            }

            if (this.encodeType!=null && this.encodeType.trim().length() > 0) {
                //設(shè)置編碼方式
                hints.put(EncodeHintType.CHARACTER_SET, this.encodeType);
            }

            BitMatrix bitMatrix = multiFormatWriter.encode(this.codeText, BarcodeFormat.QR_CODE, this.width, this.height, hints);
            byte[] bytes = writeToBytes(bitMatrix);

            return bytes;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

2、項目下載及部署

  • 將項目slndemo下的slndemodata.zip壓縮包拷貝到本地D盤根目錄下并解壓
  • 點擊啟動項目

三、功能展示

1、項目啟動后登錄首頁

  • 項目地址:http://localhost:8888/pc/login
  • 賬戶:張三 密碼:123456

2、系統(tǒng)首頁功能簡介

這是一個簡單的Demo項目,模擬Word文件在辦公系統(tǒng)中的主要流轉(zhuǎn)環(huán)節(jié),并不意味著PageOffice產(chǎn)品只能支持這樣的文檔處理流程。PageOffice產(chǎn)品只提供文檔在線處理的功能,包括:打開、編輯、保存、動態(tài)填充、文檔合并、套紅、留痕、蓋章等上百項功能(詳細請參考PageOffice產(chǎn)品開發(fā)包中的示例),不提供流程控制功能,所以不管開發(fā)什么樣的Web系統(tǒng),只要是需要在線處理Office文檔,都可以根據(jù)自己的項目需要,調(diào)用PageOffice產(chǎn)品相應(yīng)的功能即可。「注意:為了簡化代碼邏輯,此演示程序只能創(chuàng)建一個文檔進行流轉(zhuǎn)?!?/strong>

3、點擊起草文檔

  • 點擊起草文檔,點擊提交
  • 點擊代辦文檔,然后點擊編輯,當你點擊編輯時你沒有下載PageOffice,他會提醒你安裝,你點擊安裝之后,關(guān)閉瀏覽器,重新打開瀏覽器就能編輯了!
  • 我們使用了PageOffice企業(yè)版,必須要注冊序列化
  • 版 本:PageOffice企業(yè)版5(試用)
  • 序列號:35N8V-2YUC-LY77-W14XL
  • 當我們注冊成功以后,就可以編輯發(fā)布的文件或者公告了
  • 編輯好以后點擊保存
  • 點擊審批

4、審批

  • 登錄李總審批
  • 退出系統(tǒng),然后輸入李總
  • 然后點擊批閱,下一步
  • 登錄趙六進行審核稿子

5、審稿

  • 審稿
  • 審核然后到蓋章環(huán)節(jié)
  • 使用王總登錄進行蓋章

6、蓋章和簽字的實現(xiàn)

  • 王總登錄
  • 點擊蓋章
  • 點擊加蓋印章
  • 我們蓋章前需要輸入姓名+密碼,需要輸入錯誤報錯
  • 正確的賬戶密碼是:
  • 賬戶:王五
  • 密碼:123456
  • 登錄成功后有選擇王五的個人章進行簽字
  • 簽字成功
  • 公司蓋章,重復(fù)以上步驟
  • 簽字蓋章成功

7、完整簽字蓋章文件

  • 保存之后發(fā)布文件
  • 公司文件展示
  • 蓋章簽字后的文件
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容