Sfoglia il codice sorgente

ocr集成 word模板 签名集成

xiao-xx 1 anno fa
parent
commit
446606c4e3

+ 64 - 6
yinet-admin/src/main/java/com/yinet/web/controller/rlzy/RlzyApplyPrintController.java

@@ -14,15 +14,17 @@ import com.yinet.rlzy.service.IRlzyApplyService;
 import com.yinet.common.core.domain.AjaxResult;
 import com.yinet.selfService.domain.SelfService;
 import com.yinet.selfService.service.ISelfServiceService;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.*;
 
 @Controller
 @RequestMapping("/rlzy/print")
@@ -62,8 +64,7 @@ public class RlzyApplyPrintController extends BaseController {
      */
     @PostMapping("/add")
     @ResponseBody
-    public AjaxResult addSave(RlzyApply rlzyApply)
-    {
+    public AjaxResult addSave(RlzyApply rlzyApply) throws Exception {
         if(StringUtils.isEmpty(rlzyApply.getProperty())){
             return AjaxResult.error("请选择机构性质");
         }
@@ -81,8 +82,65 @@ public class RlzyApplyPrintController extends BaseController {
         RlzyApply apply = addSelf();
         rlzyApply.setLicenseNumber(apply.getLicenseNumber());
         rlzyApply.setLicenseCode(apply.getLicenseCode());
-        return toAjax(rlzyApplyService.insert(rlzyApply));
+        rlzyApply.setChengnuoshu(CreatePrintHtml(rlzyApply,"承诺书","cns.ftl"));
+        rlzyApplyService.insert(rlzyApply);
+        return AjaxResult.success(rlzyApply.getChengnuoshu());
     }
+
+
+
+
+
+    /**
+     *
+     * @param rlzyApply 申请信息
+     * @param clName    材料名称 例:准予通知书
+     * @param templateName  模板名称
+     * @throws Exception
+     */
+    public String CreatePrintHtml( RlzyApply rlzyApply, String clName,String templateName) throws Exception {
+
+        //①创建配置对象
+        Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);//注意:这里需要传递一个版本
+
+        String path = null;
+        String path1 = Global.getProfile();
+        if (System.getProperty("user.dir").indexOf("bin") != -1) {
+            String[] t = System.getProperty("user.dir").split("bin");
+            path = t[0] + "/webapps/ROOT/WEB-INF/classes/templates/";
+        } else {
+            path = System.getProperty("user.dir") + "/yinet-admin/src/main/resources/templates/";
+        }
+        File f = new File(path);
+        File f1 = new File(path1+"/Ytj/");
+        if(!f1.exists()){
+            f1.mkdir();
+        }
+
+        //②读取模板文件夹
+        cfg.setDirectoryForTemplateLoading(f);//设置要加载的模板文件的路径
+        //③设置模板的编码格式
+        cfg.setDefaultEncoding("UTF-8");
+        //④获取模板对象
+        Template template;
+        template  = cfg.getTemplate("wordtemplates/"+templateName);
+        //⑤创建数据模型(这里使用map类型)  --[数据模型可以是List、Map对象 注意:Map类型的key必须是String类型]
+        HashMap<String, Object> map = new HashMap<>();
+//        map.put("selfApply",selfApply);
+        String imageToBase64 = Base64ImgUtils.ImageToBase64(Global.getProfile() + "" + (rlzyApply.getQianming().replace("/profile", "")));
+        rlzyApply.setQianming( imageToBase64.replace("data:image/jpeg;base64,",""));
+
+        map.put("sqsj",DateUtils.dateTime("yyyy年MM月dd日", String.valueOf(rlzyApply.getCreateTime())));
+        map.put("printJson", rlzyApply);
+        String fileName = UUID.randomUUID().toString().replaceAll("-","")+".doc";
+        PrintWriter pw = new PrintWriter(new File(f1,  fileName));
+        template.process(map, pw);//合并  map:数据模型  pw:输出流对象
+        pw.close();//关闭流
+        return  "/profile/Ytj/" + fileName;
+
+    }
+
+
     @GetMapping("/{idcard}")
     public String dyList(@PathVariable String idcard,ModelMap mmap)
     {

+ 3 - 3
yinet-admin/src/main/resources/application.yml

@@ -165,6 +165,6 @@ python:
 saomiao:
   der: E
 baiducloud:
-  appid: 28297291
-  apikey: hDHBt5BAbTa6jicsdS25bOcE
-  secretkey: mPzwPfBQbH1bmovIx8DywbGLlimrZWO7
+  appid: 17793460
+  apikey: jxcWdsiGEkgweUUj6yXW8EVg
+  secretkey: kjccupB9YH8ND0YLIqSK6aEx7CdDdP6e

+ 3 - 3
yinet-admin/src/main/resources/templates/rlzy/apply/edit.html

@@ -133,9 +133,9 @@
                     <div class="form-group">
                         <label class="col-sm-4 control-label">承诺书:</label>
                         <div class="col-sm-8">
-                            <img  style="width: 300px;height: 200px" th:src="*{chengnuoshu}" >
+<!--                            <img  style="width: 300px;height: 200px" th:src="*{chengnuoshu}" >-->
                             <br>
-                            <a th:href="*{chengnuoshu}" style="margin-top: 10px;margin-left: 120px;" target="_blank">点击查看</a>
+                            <a th:href="*{chengnuoshu}" style="margin-top: 10px;margin-left: 120px;" target="_blank">点击下载</a>
                         </div>
                     </div>
                 </div>
@@ -302,4 +302,4 @@
         });
     </script>
 </body>
-</html>
+</html>

+ 194 - 20
yinet-admin/src/main/resources/templates/rlzy/print/apply.html

@@ -93,14 +93,14 @@
                                             <a class="list">营业执照</a>
                                         </td>
                                     </tr>
-                                    <tr class="info" data-id="sqcn" onclick="selTr(this)">
+                                    <!--<tr class="info" data-id="sqcn" onclick="selTr(this)">
                                         <td>
                                             2
                                         </td>
                                         <td>
                                             <a class="list">申请人承诺</a>
                                         </td>
-                                    </tr>
+                                    </tr>-->
 
                                     </tbody>
                                 </table>
@@ -501,7 +501,6 @@
                 />
                 <input
                         id="chengnuoshu"
-                        name="chengnuoshu"
                         type="hidden"
                 />
 
@@ -533,7 +532,13 @@
             </div>
 
         </div>
-
+            <div class="content4">
+                <input id="printFilePath" value="" type="hidden">
+                <a style="    font-size: 25px; font-weight: bolder;">请打印行政许可告知承诺书</a>
+                <button   class="btn btn-lg btn-success" type="button" onclick="printCns()" >
+                    打印行政许可告知承诺书
+                </button>
+            </div>
 
 
     </article>
@@ -576,10 +581,36 @@
             },
             servicePlace: {
                 required: true,
+            },
+            businessScope:{
+                required: true,
             }
         }
     });
 
+    function printCns() {
+
+        $.modal.loading("等待打印中");
+        window.setTimeout(function(){
+            $.modal.closeLoading()
+        },4000)
+        //开始打印
+        var Url = getRootPath_web();
+        console.log(Url+$("#printFilePath").val())
+        Toast('', '打印指定网页文件');
+        Toast('打印指定网页文件.....');
+        module_printer.print_webpage2(
+            Url+$("#printFilePath").val(),
+            1,     //打印数量
+            0,     //打印纸盒选择(0:使用默认纸盒,1:使用纸盒1,2:使用纸盒2,5:使用手动纸盒)
+            0,       //打印纸张选择(0:A4,1:A3,2:A5)
+            1,      //是否彩色打印(0:黑白打印,1:彩色打印)
+            1,     //是否横向打印(0:纵向,1:横向)
+            0     //是否需要返回实际打印结果(0:不需要,1:需要
+        );
+
+
+    }
     function toQianming() {
         $("#content1").hide()
         $("#content3").show()
@@ -589,22 +620,22 @@
         $("#content1").show()
     }
     function toSaomiao() {
-            $("#content1").hide()
-            $("#content2").show()
-            cl_openidA4photos(0, 1);
-            open_light()
+        $("#content1").hide()
+        $("#content2").show()
+        cl_openidA4photos(0, 1);
+        open_light()
     }
 
     function goBackStep() {
 
-         if($("input[name='file").val()==""){
-         alert("请拍摄营业执照材料")
-         return false;
+        if($("input[name='file").val()==""){
+            alert("请拍摄营业执照材料")
+            return false;
         }
-        if($("input[name='chengnuoshu").val()==""){
+        /*if($("input[name='chengnuoshu").val()==""){
             alert("请拍摄承诺书材料")
             return false;
-        }
+        }*/
 
         $.ajax({
             url: prefix+"/getOcrJson",
@@ -618,10 +649,10 @@
                 console.log(res)
                 $.modal.closeLoading()
                 if(res.code=="0"){
-                    $("#input[name='name']").val()
-                    $("#input[name='creditCode']").val()
-                    $("#input[name='legalName']").val()
-                    $("#input[name='servicePlace']").val()
+                    $("input[name='name']").val(res.data['名称'])
+                    $("input[name='creditCode']").val(res.data['社会信用代码'])
+                    $("input[name='legalName']").val(res.data['法定代表人'])
+                    $("input[name='servicePlace']").val(res.data['住所'])
                     $("#content1").show()
                     $("#content2").hide()
                 }
@@ -644,7 +675,7 @@
     function submitinfo() {
         if ($.validate.form()) {
             var qmData=""
-            qmData= getFileFromBase64($("#qianming").val().replace("data:image/jpeg;base64,",""), "qm.jpg");
+            qmData= getFileFromBase64($("#qianming").val().replace("data:image/png;base64,",""), "qm.jpg");
             $.ajax({
                 type: "post",
                 url: ctx + "common/upload",
@@ -665,9 +696,9 @@
                         data: $('#form-file-add').serialize(),
                         success: function (res) {
                             if(res.code=="0"){
-                                cl_closeidA4photos();
+                                $("#printFilePath").val(res.data)
                                 alert("提交成功")
-                                window.location.href = "/zhuxiao/index"
+
                             }else {
                                 alert(res.msg)
                             }
@@ -897,6 +928,149 @@
                         Toast('err', '拍照失败:' + code);
                     }
                 });
+
+                window.module_printer = channel.objects.printer;
+                module_printer.sig_printer_status.connect(
+                    function (status_code, code_info) {
+                        console.log("获取打印机状态结果:" + status_code + " " + code_info);
+                        if (status_code >= 0) {
+                            Toast('', code_info);
+                            return;
+                        }
+                        switch (status_code) {
+                            case -1:
+                                message = "获取失败";
+                                break;
+                            case -8:
+                                message = "初始化异常";
+                                break;
+                            case -65535:
+                                message = "程序未初始化";
+                                break;
+                            default:
+                                message = "未知" + "\t" + status_code;
+                                break;
+                        }
+                    });
+
+
+                module_printer.sig_printer_info.connect(
+                    function (json_info) {
+                        console.log(json_info)
+                        var data = JSON.parse(json_info);
+                        if (data.code == 0) {
+                            Toast('res', '打印机信息获取成功');
+                            console.log('打印机信息获取成功');
+                            var print_info = data.status.code_info;
+                            //打印机状态
+                            console.log('打印机状态:' + print_info);
+
+                            //墨粉量
+                            var toner = '';
+                            if (data.toner.status == 100) {
+                                for (var i = 0; i < data.toner.toners.length; i++) {
+                                    toner += data.toner.toners[i].color + ':' + data.toner.toners[i].remaining + '%; ';
+                                }
+                            } else if (data.toner.status == 200) {
+                                toner = data.toner.msg;
+                            }
+                            console.log('墨粉量:' + toner);
+
+                            //纸张总量
+                            if (data.statistics.code == 0) {
+                                console.log('打印总量:' + data.statistics.print_sum);
+                            } else if (data.printsum.status == 200) {
+                                console.log('获取打印总量失败');
+                            }
+
+                            //纸盘信息
+                            for (var i = 0; i < data.papertray.papertrays.length; i++) {
+                                var paper;
+                                var tray;
+                                var item = data.papertray.papertrays[i]
+                                if (item.trayid != 5) {
+                                    switch (item.state) {
+                                        case 0:
+                                            paper = "没有纸张";
+                                            break;
+                                        case 1:
+                                            paper = "纸张数量较低";
+                                            break;
+                                        case 2:
+                                            paper = "纸量充足";
+                                            break;
+                                    }
+                                    tray = item.trayid + '号纸盘';
+                                } else {
+                                    switch (item.state) {
+                                        case 0:
+                                            paper = "没有纸张";
+                                            break;
+                                        case 1:
+                                            paper = "有纸";
+                                            break;
+                                    }
+                                    tray = "手动送纸盘";
+                                }
+
+                            }
+                        } else {
+                            Toast('err', '打印机信息获取失败:' + data.msg);
+                        }
+                    }
+
+                )
+
+                module_printer.sig_print_state_change.connect(function (code, print_state, message) {
+                    var info
+                    switch (code) {
+                        case 0:
+                            info = "文件成功发送到打印机"
+                            break;
+                        case 1:
+                            info = "下载文件成功,开始打印"
+                            break;
+                        case 2:
+                            info = "打印机完成打印"
+
+                            break;
+                        case -1:
+                            info = "打印失败:" + message;
+                            break;
+                        case -2:
+                            info = "不支持的文件格式";
+                            break;
+                        case -3:
+                            info = "下载文件失败";
+                            break;
+                        case -4:
+                            info = "文件不存在";
+                            break;
+                        case -5:
+                            info = "图片数据无效";
+                            break;
+                        case -6:
+                            info = "组件连接异常";
+                            break;
+                        case -8:
+                            info = "初始化异常";
+                            break;
+                        case -65535:
+                            info = "程序未初始化";
+                            break;
+                        default:
+                            info = "未知状态:" + "\t" + code;
+                            break;
+                    }
+                    if(code=='0'){
+                        $.modal.loading("开始打印");
+                        window.setTimeout(function(){
+                            $.modal.closeLoading()
+                        },2000)
+                    }
+                    console.log(info)
+                });
+
                 cl_openidA4photos(0, 1);
                 open_light()
             });

File diff suppressed because it is too large
+ 4371 - 0
yinet-admin/src/main/resources/templates/wordtemplates/cns.ftl