Browse Source

下载申请表

lxp 1 year ago
parent
commit
9d8ce8f12b

+ 87 - 0
yinet-admin/src/main/java/com/yinet/web/controller/rlzy/RlzyApplyController.java

@@ -1,6 +1,11 @@
 package com.yinet.web.controller.rlzy;
 
+import java.io.*;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import com.yinet.common.annotation.Log;
 import com.yinet.common.config.Global;
@@ -9,14 +14,22 @@ import com.yinet.common.core.domain.AjaxResult;
 import com.yinet.common.core.page.TableDataInfo;
 import com.yinet.common.enums.BusinessType;
 import com.yinet.common.utils.DateUtils;
+import com.yinet.common.utils.QRCodeUtils;
 import com.yinet.common.utils.poi.ExcelUtil;
 import com.yinet.rlzy.domain.RlzyApply;
 import com.yinet.rlzy.service.IRlzyApplyService;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
 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 org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 
 /**
@@ -127,4 +140,78 @@ public class RlzyApplyController extends BaseController
     {
         return toAjax(rlzyApplyService.deleteRlzyApplyByIds(ids));
     }
+
+    @GetMapping("/toWord")
+    public ModelAndView toWord(@RequestParam("id") Long id , HttpServletRequest request, HttpServletResponse response) throws IOException {
+        RlzyApply rlzyApply = rlzyApplyService.getById(id);
+        Map<String, Object> dataMap = new HashMap<String, Object>();
+        dataMap.put("name",rlzyApply.getName());
+        dataMap.put("creditCode",rlzyApply.getCreditCode());
+        dataMap.put("legalName",rlzyApply.getLegalName());
+        dataMap.put("idcard",rlzyApply.getIdcard());
+        dataMap.put("servicePlace",rlzyApply.getServicePlace());
+        dataMap.put("acreage",rlzyApply.getAcreage());
+        dataMap.put("number",rlzyApply.getNumber());
+        dataMap.put("contacts",rlzyApply.getContacts());
+        dataMap.put("phone",rlzyApply.getPhone());
+        dataMap.put("email",rlzyApply.getEmail());
+        dataMap.put("licenseNumber",rlzyApply.getLicenseNumber());
+        dataMap.put("property",rlzyApply.getProperty());
+        dataMap.put("businessScope",rlzyApply.getBusinessScope());
+        String template = "/templates/wordtemplates/rlzyapply.ftl";  //模板文件的地址
+        String templatePath = template.substring(0, template.lastIndexOf("/"));
+        String templateName = template.substring(template.lastIndexOf("/") + 1);
+        System.err.println("templateName:" + templateName);
+        Configuration configuration = null;
+        if (configuration == null) {
+            configuration = new Configuration(Configuration.VERSION_2_3_23);
+            configuration.setDefaultEncoding("utf-8");
+            configuration.setClassForTemplateLoading(this.getClass(), templatePath);
+        }
+        Template t = null;
+        /* String name = "temp"+(int)(Math.random()*1000)+".doc";*/
+        String name = templateName;
+        System.err.println("name:" + name);
+        File file = new File(name);
+        try {
+            t = configuration.getTemplate(templateName);
+            Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name), StandardCharsets.UTF_8));
+            t.process(dataMap, out);
+            out.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (TemplateException e) {
+            e.printStackTrace();
+        }
+
+        response.setContentType("text/html;charset=utf-8");
+        request.setCharacterEncoding("UTF-8");
+        java.io.BufferedInputStream bis = null;
+        java.io.BufferedOutputStream bos = null;
+        try {
+            long fileLength = file.length();
+            response.setContentType("application/msword");
+            response.setHeader("Content-disposition", "attachment; filename=" +
+                    URLEncoder.encode(rlzyApply.getName() + "申请表.doc", "utf-8"));
+            response.setHeader("Content-Length", String.valueOf(fileLength));
+            bis = new BufferedInputStream(new FileInputStream(file));
+            bos = new BufferedOutputStream(response.getOutputStream());
+            byte[] buff = new byte[2048];
+            int bytesRead;
+            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
+                bos.write(buff, 0, bytesRead);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (bis != null){
+                bis.close();
+            }
+            if (bos != null){
+                bos.close();
+            }
+        }
+        System.err.println("下载完成");
+        return null;
+    }
 }

+ 27 - 1
yinet-admin/src/main/java/com/yinet/web/controller/rlzy/RlzyApplyPrintController.java

@@ -140,13 +140,24 @@ public class RlzyApplyPrintController extends BaseController {
 
     }
 
-
+    /**
+     * 打印列表
+     * @param idcard
+     * @param mmap
+     * @return
+     */
     @GetMapping("/{idcard}")
     public String dyList(@PathVariable String idcard,ModelMap mmap)
     {
         mmap.addAttribute("idcard",idcard);
         return prefix+"/dylist";
     }
+
+    /**
+     * 根据身份证查询证照信息
+     * @param idcard
+     * @return
+     */
     @GetMapping("/getByIdcard/{idcard}")
     @ResponseBody
     public AjaxResult getByIdcard(@PathVariable String idcard)
@@ -156,6 +167,14 @@ public class RlzyApplyPrintController extends BaseController {
         List<RlzyApply> rlzyApplies = rlzyApplyService.selectList(rlzy);
         return AjaxResult.success(rlzyApplies);
     }
+
+    /**
+     * 打印正副本
+     * @param id
+     * @param type
+     * @param map
+     * @return
+     */
     @GetMapping("/getApplyById/{id}/{type}")
     public String getApplyById(@PathVariable("id") String id,@PathVariable("type") String type,ModelMap map)
     {
@@ -212,16 +231,23 @@ public class RlzyApplyPrintController extends BaseController {
         return  AjaxResult.success(rlzyApplyService.updateById(build));
     }
 
+    /**
+     * 编号自增
+     * @return
+     */
     public RlzyApply addSelf(){
+        //查询最后一条申请信息
         RlzyApply rlzyApply = rlzyApplyService.selectLastRlzyApply();
         int licenseNumber = 0;
         int licenseCode = 0;
+        //编号字符串转换成数字格式
         if(rlzyApply != null){
             licenseNumber = Integer.valueOf(rlzyApply.getLicenseNumber()).intValue();
             licenseCode = Integer.valueOf(rlzyApply.getLicenseCode()).intValue();
         }else{
             rlzyApply = new RlzyApply();
         }
+        //编号自增
         if(licenseNumber / 1000 <1){
             String format1 = String.format("%03d", licenseNumber + 1);
             rlzyApply.setLicenseNumber(format1);

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

@@ -236,6 +236,10 @@
                 </div>
             </div>
         </form>
+        <div class="form-group" style="text-align: center">
+            <button type=button class="btn btn-info" id="updataBtn" th:onclick="dayin([[${rlzyApply.idcard}]])">打印证照</button>
+            <button type=button class="btn btn-info" th:onclick="download([[${rlzyApply.id}]])">下载申请表</button>
+        </div>
     </div>
 
     <th:block th:include="include :: footer" />
@@ -300,6 +304,12 @@
             minView: "month",
             autoclose: true
         });
+        function dayin(idcard){
+            window.location.href="/rlzy/print/"+idcard;
+        }
+        function download(id){
+            window.location.href=prefix+"/toWord?id="+id;
+        }
     </script>
 </body>
 </html>

+ 1 - 1
yinet-admin/src/main/resources/templates/rlzy/print/dylist.html

@@ -237,7 +237,7 @@
 		}
 
         function datalist(){
-        	var card=getCookie("cardno")
+        	var card=[[${idcard}]]
             $.ajax({
                 url: "/rlzy/print/getByIdcard/"+card,
                 type: "get",

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


+ 20 - 0
yinet-common/src/main/java/com/yinet/common/utils/QRCodeUtils.java

@@ -5,6 +5,7 @@ import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.Hashtable;
+import java.util.Objects;
 import javax.imageio.ImageIO;
 
 import com.github.pagehelper.util.StringUtil;
@@ -152,4 +153,23 @@ public class QRCodeUtils {
         QRCodeUtils.Base64ToImage(strNetImageToBase64, path);
         return url;
     }
+    public static String  ImageToBase64(String imgPath) {
+        byte[] data = null;
+        // 读取图片字节数组
+        try {
+            InputStream in = new FileInputStream(imgPath);
+            data = new byte[in.available()];
+            in.read(data);
+            in.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        // 对字节数组Base64编码
+        BASE64Encoder encoder = new BASE64Encoder();
+        // 返回Base64编码过的字节数组字符串
+        String imgbase64=encoder.encode(Objects.requireNonNull(data));
+//        File file =new File(imgPath);
+//        file.delete();
+        return imgbase64;
+    }
 }

+ 4 - 0
yinet-system/src/main/java/com/yinet/rlzy/service/IRlzyApplyService.java

@@ -32,6 +32,10 @@ public interface IRlzyApplyService extends BaseService<RlzyApply>
 
     List<RlzyApply> selectList(RlzyApply rlzy);
 
+    /**
+     * 查询最后一条申请信息
+     * @return
+     */
     RlzyApply selectLastRlzyApply();
 
     Map startOcrTemplate(String fileBase64,String templateId);