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

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

一、前言

今天公司領導提出一個功能莺戒,說實現(xiàn)一個文件的簽字+蓋章功能伴嗡,然后自己進行了簡單的學習,對文檔進行數(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é)梗掰,包括:起草文檔嵌言、領導審批、核稿及穗、領導蓋章摧茴、正式發(fā)文。PageOffice產(chǎn)品支持PC端Word文檔在線處理的所有環(huán)節(jié)埂陆;MobOffice產(chǎn)品支持了移動端領導審批和領導蓋章的功能苛白。支持PC端和移動端對文檔審批和蓋章的互認娃豹。然后此次博客中使用的卓正軟件的電子簽章采用自主知識產(chǎn)權的核心智能識別驗證技術,確保文檔安全可靠购裙。采用 COM懂版、ActiveX嵌入式技術開發(fā),確保軟件能夠支持多種應用躏率。遵循《中華人民共和國電子簽名法》關于電子簽名的規(guī)范躯畴,同時支持國際通用的 RSA算法后控,符合國家安全標準稠炬。

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

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

二嚷缭、項目源碼及部署

1、項目結構及使用框架

該簽字+蓋章流程系統(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的服務器端授權程序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è)務層源碼
@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ù)
            Map hints = new HashMap();
            if (this.errorCorrectionLevel != null) {
                //設置二維碼的糾錯級別
                hints.put(EncodeHintType.ERROR_CORRECTION, this.errorCorrectionLevel);
            }

            if (this.encodeType!=null && this.encodeType.trim().length() > 0) {
                //設置編碼方式
                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)品相應的功能即可舟肉。「注意:為了簡化代碼邏輯修噪,此演示程序只能創(chuàng)建一個文檔進行流轉(zhuǎn)÷访模」

3割按、點擊起草文檔

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

4强法、審批

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

5饮怯、審稿

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

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

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

7库倘、完整簽字蓋章文件

  • 保存之后發(fā)布文件
  • 公司文件展示
  • 蓋章簽字后的文件
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市论矾,隨后出現(xiàn)的幾起案子教翩,更是在濱河造成了極大的恐慌,老刑警劉巖贪壳,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件饱亿,死亡現(xiàn)場離奇詭異,居然都是意外死亡闰靴,警方通過查閱死者的電腦和手機彪笼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來传黄,“玉大人杰扫,你說我怎么就攤上這事队寇”礻” “怎么了?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長识埋。 經(jīng)常有香客問我凡伊,道長,這世上最難降的妖魔是什么窒舟? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任系忙,我火速辦了婚禮,結果婚禮上惠豺,老公的妹妹穿的比我還像新娘银还。我一直安慰自己,他們只是感情好洁墙,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布蛹疯。 她就那樣靜靜地躺著,像睡著了一般热监。 火紅的嫁衣襯著肌膚如雪捺弦。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天孝扛,我揣著相機與錄音列吼,去河邊找鬼。 笑死苦始,一個胖子當著我的面吹牛寞钥,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播陌选,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼凑耻,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了柠贤?” 一聲冷哼從身側響起香浩,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎臼勉,沒想到半個月后邻吭,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡宴霸,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年囱晴,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片瓢谢。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡畸写,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出氓扛,到底是詐尸還是另有隱情枯芬,我是刑警寧澤论笔,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站千所,受9級特大地震影響狂魔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜淫痰,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一最楷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧待错,春花似錦籽孙、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至烛占,卻和暖如春胎挎,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背忆家。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工犹菇, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人芽卿。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓揭芍,卻偏偏與公主長得像,于是被迫代替她去往敵國和親卸例。 傳聞我的和親對象是個殘疾皇子称杨,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355

推薦閱讀更多精彩內(nèi)容