From 282b35c0e4831e56af8e436bda3702eb900d9626 Mon Sep 17 00:00:00 2001 From: liuwu <975499773@qq.com> Date: Thu, 14 Sep 2023 11:40:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=92=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TAmentPartyAffairsController.java | 67 +++++++++++++++++++ .../base/mapper/TAmentPartyAffairsMapper.java | 2 + .../service/ITAmentPartyAffairsService.java | 2 + .../impl/TAmentPartyAffairsServiceImpl.java | 5 ++ .../mapper/base/TAmentPartyAffairsMapper.xml | 27 ++++++++ 5 files changed, 103 insertions(+) diff --git a/cyx-admin/src/main/java/com/cyx/web/base/controller/TAmentPartyAffairsController.java b/cyx-admin/src/main/java/com/cyx/web/base/controller/TAmentPartyAffairsController.java index 01080fc..b7e0c56 100644 --- a/cyx-admin/src/main/java/com/cyx/web/base/controller/TAmentPartyAffairsController.java +++ b/cyx-admin/src/main/java/com/cyx/web/base/controller/TAmentPartyAffairsController.java @@ -1,5 +1,11 @@ package com.cyx.web.base.controller; +import java.io.*; + +import com.cyx.common.config.RuoYiConfig; +import com.itextpdf.text.*; + +import java.nio.file.Files; import java.util.Date; import java.util.List; import java.util.Map; @@ -16,6 +22,15 @@ import com.cyx.common.utils.poi.ExcelUtil; import com.cyx.system.service.ISysDeptService; import com.cyx.web.base.domain.*; import com.cyx.web.base.service.*; +import com.itextpdf.text.pdf.PdfPCell; +import com.itextpdf.text.pdf.PdfPTable; +import com.itextpdf.text.pdf.PdfWriter; +import org.apache.commons.io.FileUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,6 +41,9 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + /** * 党务Controller * @@ -104,6 +122,37 @@ public class TAmentPartyAffairsController extends BaseController return prefix + "/viewFiles"; } + @GetMapping("getFiles") + public void getFiles(String path, HttpServletResponse response,String filename) { + File inputFile = new File("D:\\ruoyi\\uploadPath\\upload\\2023\\08\\31\\牛舍管理查询导出_20230831105444A002.xlsx"); + try { + + InputStream inputStream = Files.newInputStream(inputFile.toPath()); + Document document = new Document(); + PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); + document.open(); + PdfPTable table = new PdfPTable(1); // 创建一个表格,每行一个单元格 + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = reader.readLine()) != null) { + table.addCell(new PdfPCell(new Phrase(line))); // 将每一行内容添加到表格中 + } + document.add(table); // 将表格添加到PDF文档中 + document.close(); + response.setCharacterEncoding("UTF-8"); + // attachment是以附件的形式下载,inline是浏览器打开 + response.setHeader("Content-Disposition", "inline;filename="+filename+".pdf"); + response.setContentType("text/plain;UTF-8"); + // 把二进制流放入到响应体中 + ServletOutputStream os = response.getOutputStream(); + byte[] bytes = FileUtils.readFileToByteArray(inputFile); + os.write(bytes); + os.flush(); + os.close(); + }catch (Exception e){ + e.printStackTrace(); + } + } /** * @@ -280,6 +329,24 @@ public class TAmentPartyAffairsController extends BaseController return array; } + @GetMapping("/zhiwuTree") + @ResponseBody + public Object zhiwuTree(TAmentPartyAffairs tAmentPartyAffairs) + { + JSONArray array =new JSONArray(); + List> list = tAmentPartyAffairsService.zhiwuTree(tAmentPartyAffairs); + list.forEach(l->{ + JSONArray array1 = JSONArray.parseArray("["+l.get("json")+"]"); + array1.forEach(a->{ + JSONObject o = (JSONObject) a; + o.put("pId",l.get("id")); + o.put("type",l.get("type")); + array.add(o); + }); + }); + return array; + } + /** * 查询党务列表 */ diff --git a/cyx-admin/src/main/java/com/cyx/web/base/mapper/TAmentPartyAffairsMapper.java b/cyx-admin/src/main/java/com/cyx/web/base/mapper/TAmentPartyAffairsMapper.java index eb484e3..259e00e 100644 --- a/cyx-admin/src/main/java/com/cyx/web/base/mapper/TAmentPartyAffairsMapper.java +++ b/cyx-admin/src/main/java/com/cyx/web/base/mapper/TAmentPartyAffairsMapper.java @@ -85,4 +85,6 @@ public interface TAmentPartyAffairsMapper List> importantWork(TAmentPartyAffairs tAmentPartyAffairs); List> labelTotal(TAmentPartyAffairs tAmentPartyAffairs); + + List> zhiwuTree(TAmentPartyAffairs tAmentPartyAffairs); } diff --git a/cyx-admin/src/main/java/com/cyx/web/base/service/ITAmentPartyAffairsService.java b/cyx-admin/src/main/java/com/cyx/web/base/service/ITAmentPartyAffairsService.java index 3fbe730..bc590aa 100644 --- a/cyx-admin/src/main/java/com/cyx/web/base/service/ITAmentPartyAffairsService.java +++ b/cyx-admin/src/main/java/com/cyx/web/base/service/ITAmentPartyAffairsService.java @@ -85,4 +85,6 @@ public interface ITAmentPartyAffairsService List> importantWork(TAmentPartyAffairs tAmentPartyAffairs); List> labelTotal(TAmentPartyAffairs tAmentPartyAffairs); + + List> zhiwuTree(TAmentPartyAffairs tAmentPartyAffairs); } diff --git a/cyx-admin/src/main/java/com/cyx/web/base/service/impl/TAmentPartyAffairsServiceImpl.java b/cyx-admin/src/main/java/com/cyx/web/base/service/impl/TAmentPartyAffairsServiceImpl.java index c35543e..d5ff747 100644 --- a/cyx-admin/src/main/java/com/cyx/web/base/service/impl/TAmentPartyAffairsServiceImpl.java +++ b/cyx-admin/src/main/java/com/cyx/web/base/service/impl/TAmentPartyAffairsServiceImpl.java @@ -67,6 +67,11 @@ public class TAmentPartyAffairsServiceImpl implements ITAmentPartyAffairsService return tAmentPartyAffairsMapper.deptTree(tAmentPartyAffairs); } + @Override + public List> zhiwuTree(TAmentPartyAffairs tAmentPartyAffairs){ + return tAmentPartyAffairsMapper.zhiwuTree(tAmentPartyAffairs); + } + @Override public List> importantWork(TAmentPartyAffairs tAmentPartyAffairs){ return tAmentPartyAffairsMapper.importantWork(tAmentPartyAffairs); diff --git a/cyx-system/src/main/resources/mapper/base/TAmentPartyAffairsMapper.xml b/cyx-system/src/main/resources/mapper/base/TAmentPartyAffairsMapper.xml index 702c25f..111a978 100644 --- a/cyx-system/src/main/resources/mapper/base/TAmentPartyAffairsMapper.xml +++ b/cyx-system/src/main/resources/mapper/base/TAmentPartyAffairsMapper.xml @@ -158,6 +158,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" f.type + + - SELECT f.id, f.type,