|
@@ -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;
|
|
|
+ }
|
|
|
}
|