Bladeren bron

feat:产品要素导出格式调整

chenjianhua 1 week geleden
bovenliggende
commit
5d5fd88e17

+ 109 - 47
service-base/src/main/java/com/simuwang/base/common/util/ExcelUtil.java

@@ -16,6 +16,7 @@ import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.*;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
@@ -538,10 +539,10 @@ public class ExcelUtil {
         return localDate.format(formatter);
     }
 
-    public static HSSFWorkbook getProductHSSFWorkbook(List<ProductDataVO> productDataVOList) {
+    public static XSSFWorkbook getProductXSSFWorkbook(List<ProductDataVO> productDataVOList) {
 
         // 第一步,创建一个HSSFWorkbook,对应一个Excel文件
-        HSSFWorkbook  wb = new HSSFWorkbook();
+        XSSFWorkbook  wb = new XSSFWorkbook();
         try {
             createProductInfoSheet(wb,productDataVOList);
             createProductContractSheet(wb,productDataVOList);
@@ -553,28 +554,43 @@ public class ExcelUtil {
         return wb;
     }
 
-    private static void createInvestmentManagerSheet(HSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
+    private static void createInvestmentManagerSheet(XSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
         try{
-            HSSFSheet sheet = wb.createSheet("投资经理信息");
+            XSSFSheet sheet = wb.createSheet("投资经理信息");
             List<String> title = new ArrayList<>();
             title.add("编号");
             title.add("中基协基金编号");
             title.add("投资经理任职起始时间");
             title.add("投资经理任职结束时间");
             title.add("投资经理");
-            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
-            HSSFRow row = sheet.createRow(0);
-            // 第四步,创建单元格,并设置值表头 设置表头居中
-            HSSFCellStyle style = wb.createCellStyle();
+            //创建第一行
+            XSSFRow row1 = sheet.createRow(0);
+            XSSFRow row2 = sheet.createRow(1);
+            for (int i = 0; i < title.size(); i++) {
+                row1.createCell(i);
+                row2.createCell(i);
+            }
+            XSSFCell firstCcell = row1.createCell(0);
+            firstCcell.setCellValue("私募管理人数据推送信息填写(投资经理情况)");
+            XSSFCellStyle style = wb.createCellStyle();
+            Font font = wb.createFont();
+            font.setFontName("微软");//设置字体
+            font.setBold(true);//加粗
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            font.setBold(true);
+            style.setFont(font);//设置单元格字体
             style.setAlignment(HorizontalAlignment.LEFT);
             style.setWrapText(true);
-            sheet.setColumnWidth(0, 1000);
+            firstCcell.setCellStyle(style);
+            sheet.addMergedRegion(new CellRangeAddress(0,1,0,title.size()));
+            XSSFRow row = sheet.createRow(2);
+            sheet.setColumnWidth(0, 3000);
             sheet.setColumnWidth(1, 5000);
-            sheet.setColumnWidth(2, 5000);
+            sheet.setColumnWidth(2, 8000);
             sheet.setColumnWidth(3, 8000);
             sheet.setColumnWidth(4, 10000);
             //声明列对象
-            HSSFCell cell = null;
+            XSSFCell cell = null;
             //创建标题
             for (int i = 0; i < title.size(); i++) {
                 cell = row.createCell(i);
@@ -597,7 +613,7 @@ public class ExcelUtil {
             }
             //创建内容
             for (int i = 0; i < values.size(); i++) {
-                row = sheet.createRow(i + 1);
+                row = sheet.createRow(i + 3);
                 for (int j = 0; j < values.get(i).size(); j++) {
                     //将内容按顺序赋给对应的列对象
                     row.createCell(j).setCellValue(values.get(i).get(j));
@@ -611,9 +627,9 @@ public class ExcelUtil {
         }
     }
 
-    private static void createProductContractSheet(HSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
+    private static void createProductContractSheet(XSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
         try{
-            HSSFSheet sheet = wb.createSheet("产品合同信息");
+            XSSFSheet sheet = wb.createSheet("产品合同信息");
             List<String> title = new ArrayList<>();
             title.add("编号");
             title.add("中基协基金编号");
@@ -626,13 +642,29 @@ public class ExcelUtil {
             title.add("业绩比较基准");
             title.add("业绩报酬计提方式");
             title.add("备注");
-            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
-            HSSFRow row = sheet.createRow(0);
-            // 第四步,创建单元格,并设置值表头 设置表头居中
-            HSSFCellStyle style = wb.createCellStyle();
+            //创建第一行
+            XSSFRow row1 = sheet.createRow(0);
+            XSSFRow row2 = sheet.createRow(1);
+            for (int i = 0; i < title.size(); i++) {
+                row1.createCell(i);
+                row2.createCell(i);
+            }
+            XSSFCell firstCcell = row1.createCell(0);
+            firstCcell.setCellValue("私募管理人数据推送信息填写(其他信息)");
+            XSSFCellStyle style = wb.createCellStyle();
+            Font font = wb.createFont();
+            font.setFontName("微软");//设置字体
+            font.setBold(true);//加粗
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            font.setBold(true);
+            style.setFont(font);//设置单元格字体
             style.setAlignment(HorizontalAlignment.LEFT);
             style.setWrapText(true);
-            sheet.setColumnWidth(0, 1000);
+            firstCcell.setCellStyle(style);
+            sheet.addMergedRegion(new CellRangeAddress(0,1,0,title.size()));
+            XSSFRow row = sheet.createRow(2);
+            // 第四步,创建单元格,并设置值表头 设置表头居中
+            sheet.setColumnWidth(0, 2000);
             sheet.setColumnWidth(1, 5000);
             sheet.setColumnWidth(2, 10000);
             sheet.setColumnWidth(3, 8000);
@@ -641,10 +673,10 @@ public class ExcelUtil {
             sheet.setColumnWidth(6, 5000);
             sheet.setColumnWidth(7, 5000);
             sheet.setColumnWidth(8, 5000);
-            sheet.setColumnWidth(9, 5000);
+            sheet.setColumnWidth(9, 8000);
             sheet.setColumnWidth(10, 5000);
             //声明列对象
-            HSSFCell cell = null;
+            XSSFCell cell = null;
             //创建标题
             for (int i = 0; i < title.size(); i++) {
                 cell = row.createCell(i);
@@ -671,7 +703,7 @@ public class ExcelUtil {
             }
             //创建内容
             for (int i = 0; i < values.size(); i++) {
-                row = sheet.createRow(i + 1);
+                row = sheet.createRow(i + 3);
                 for (int j = 0; j < values.get(i).size(); j++) {
                     //将内容按顺序赋给对应的列对象
                     row.createCell(j).setCellValue(values.get(i).get(j));
@@ -685,9 +717,9 @@ public class ExcelUtil {
         }
     }
 
-    private static void createProductDetailSheet(HSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
+    private static void createProductDetailSheet(XSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
         try{
-            HSSFSheet sheet = wb.createSheet("产品其他信息");
+            XSSFSheet sheet = wb.createSheet("产品其他信息");
             List<String> title = new ArrayList<>();
             title.add("编号");
             title.add("中基协基金编号");
@@ -705,13 +737,28 @@ public class ExcelUtil {
             title.add("管理人费率");
             title.add("托管费率");
             title.add("外包费率");
-            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
-            HSSFRow row = sheet.createRow(0);
-            // 第四步,创建单元格,并设置值表头 设置表头居中
-            HSSFCellStyle style = wb.createCellStyle();
+            //创建第一行
+            XSSFRow row1 = sheet.createRow(0);
+            XSSFRow row2 = sheet.createRow(1);
+            for (int i = 0; i < title.size(); i++) {
+                row1.createCell(i);
+                row2.createCell(i);
+            }
+            XSSFCell firstCcell = row1.createCell(0);
+            firstCcell.setCellValue("私募管理人数据推送信息填写(其他信息)");
+            XSSFCellStyle style = wb.createCellStyle();
+            Font font = wb.createFont();
+            font.setFontName("微软");//设置字体
+            font.setBold(true);//加粗
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            font.setBold(true);
+            style.setFont(font);//设置单元格字体
             style.setAlignment(HorizontalAlignment.LEFT);
             style.setWrapText(true);
-            sheet.setColumnWidth(0, 1000);
+            firstCcell.setCellStyle(style);
+            sheet.addMergedRegion(new CellRangeAddress(0,1,0,title.size()));
+            XSSFRow row = sheet.createRow(2);
+            sheet.setColumnWidth(0, 3000);
             sheet.setColumnWidth(1, 5000);
             sheet.setColumnWidth(2, 10000);
             sheet.setColumnWidth(3, 8000);
@@ -719,16 +766,16 @@ public class ExcelUtil {
             sheet.setColumnWidth(5, 5000);
             sheet.setColumnWidth(6, 5000);
             sheet.setColumnWidth(7, 5000);
-            sheet.setColumnWidth(8, 15000);
-            sheet.setColumnWidth(9, 5000);
-            sheet.setColumnWidth(10, 5000);
+            sheet.setColumnWidth(8, 17000);
+            sheet.setColumnWidth(9, 8000);
+            sheet.setColumnWidth(10, 8000);
             sheet.setColumnWidth(11, 5000);
             sheet.setColumnWidth(12, 5000);
             sheet.setColumnWidth(13, 5000);
             sheet.setColumnWidth(14, 5000);
             sheet.setColumnWidth(15, 5000);
             //声明列对象
-            HSSFCell cell = null;
+            XSSFCell cell = null;
             //创建标题
             for (int i = 0; i < title.size(); i++) {
                 cell = row.createCell(i);
@@ -760,7 +807,7 @@ public class ExcelUtil {
             }
             //创建内容
             for (int i = 0; i < values.size(); i++) {
-                row = sheet.createRow(i + 1);
+                row = sheet.createRow(i + 3);
                 for (int j = 0; j < values.get(i).size(); j++) {
                     //将内容按顺序赋给对应的列对象
                     row.createCell(j).setCellValue(values.get(i).get(j));
@@ -775,9 +822,9 @@ public class ExcelUtil {
     }
 
 
-    private static void createProductInfoSheet(HSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
+    private static void createProductInfoSheet(XSSFWorkbook wb, List<ProductDataVO> productDataVOList) {
        try{
-            HSSFSheet sheet = wb.createSheet("产品基本信息");
+            XSSFSheet sheet = wb.createSheet("产品基本信息");
             List<String> title = new ArrayList<>();
             title.add("编号");
             title.add("中基协基金编号");
@@ -796,31 +843,46 @@ public class ExcelUtil {
             title.add("基金资产净值提供频率");
             title.add("定期报告");
             title.add("备注");
-            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
-            HSSFRow row = sheet.createRow(0);
-            // 第四步,创建单元格,并设置值表头 设置表头居中
-            HSSFCellStyle style = wb.createCellStyle();
+            //创建第一行
+            XSSFRow row1 = sheet.createRow(0);
+            XSSFRow row2 = sheet.createRow(1);
+            for (int i = 0; i < title.size(); i++) {
+                row1.createCell(i);
+                row2.createCell(i);
+            }
+            XSSFCell firstCcell = row1.createCell(0);
+            firstCcell.setCellValue("私募管理人数据推送信息填写(产品基本信息)");
+            XSSFCellStyle style = wb.createCellStyle();
+            Font font = wb.createFont();
+            font.setFontName("微软");//设置字体
+            font.setBold(true);//加粗
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            font.setBold(true);
+            style.setFont(font);//设置单元格字体
             style.setAlignment(HorizontalAlignment.LEFT);
             style.setWrapText(true);
-            sheet.setColumnWidth(0, 1000);
-            sheet.setColumnWidth(1, 5000);
+            firstCcell.setCellStyle(style);
+            sheet.addMergedRegion(new CellRangeAddress(0,1,0,title.size()));
+            XSSFRow row = sheet.createRow(2);
+            sheet.setColumnWidth(0, 3000);
+            sheet.setColumnWidth(1, 10000);
             sheet.setColumnWidth(2, 10000);
             sheet.setColumnWidth(3, 8000);
             sheet.setColumnWidth(4, 8000);
             sheet.setColumnWidth(5, 5000);
-            sheet.setColumnWidth(6, 5000);
+            sheet.setColumnWidth(6, 10000);
             sheet.setColumnWidth(7, 5000);
             sheet.setColumnWidth(8, 5000);
             sheet.setColumnWidth(9, 5000);
             sheet.setColumnWidth(10, 15000);
             sheet.setColumnWidth(11, 5000);
             sheet.setColumnWidth(12, 5000);
-            sheet.setColumnWidth(13, 5000);
-            sheet.setColumnWidth(14, 5000);
+            sheet.setColumnWidth(13, 10000);
+            sheet.setColumnWidth(14, 10000);
             sheet.setColumnWidth(15, 5000);
             sheet.setColumnWidth(16, 5000);
             //声明列对象
-            HSSFCell cell = null;
+            XSSFCell cell = null;
             //创建标题
             for (int i = 0; i < title.size(); i++) {
                 cell = row.createCell(i);
@@ -853,7 +915,7 @@ public class ExcelUtil {
             }
             //创建内容
             for (int i = 0; i < values.size(); i++) {
-                row = sheet.createRow(i + 1);
+                row = sheet.createRow(i + 3);
                 for (int j = 0; j < values.get(i).size(); j++) {
                     //将内容按顺序赋给对应的列对象
                     row.createCell(j).setCellValue(values.get(i).get(j));

+ 10 - 10
service-base/src/main/resources/mapper/daq/ProductInformationMapper.xml

@@ -38,7 +38,7 @@
     select <include refid="Base_Column_List"></include>
     from product_information where isvalid=1
     <if test="productName !=null and productName !=''">
-      and (product_name like concat(#{productName},'%') or register_number like concat(#{productName},'%'))
+      and (product_name like concat('%',#{productName},'%') or register_number like concat('%',#{productName},'%'))
     </if>
     <if test="startInceptionDate !=null and startInceptionDate !=''">
       and inception_date <![CDATA[ >= ]]>  #{startInceptionDate}
@@ -47,16 +47,16 @@
       and inception_date <![CDATA[ <= ]]>  #{endInceptionDate}
     </if>
     <if test="msLabel !=null and msLabel !=''">
-      and ms_label like concat(#{msLabel},'%')
+      and ms_label like concat('%',#{msLabel},'%')
     </if>
     <if test="navFrequency !=null and navFrequency !=''">
-      and nav_frequency like concat(#{navFrequency},'%')
+      and nav_frequency like concat('%',#{navFrequency},'%')
     </if>
     <if test="assetFrequency !=null and assetFrequency !=''">
-      and asset_frequency like concat(#{assetFrequency},'%')
+      and asset_frequency like concat('%',#{assetFrequency},'%')
     </if>
     <if test="reportFrequency !=null and reportFrequency !=''">
-      and report_frequency like concat(#{reportFrequency},'%')
+      and report_frequency like concat('%',#{reportFrequency},'%')
     </if>
     limit #{offset},#{pageSize}
   </select>
@@ -64,7 +64,7 @@
     select count(1)
     from product_information where isvalid=1
     <if test="productName !=null and productName !=''">
-      and (product_name like concat(#{productName},'%') or register_number like concat(#{productName},'%'))
+      and (product_name like concat('%',#{productName},'%') or register_number like concat('%',#{productName},'%'))
     </if>
     <if test="startInceptionDate !=null and startInceptionDate !=''">
       and inception_date <![CDATA[ >= ]]>  #{startInceptionDate}
@@ -73,16 +73,16 @@
       and inception_date <![CDATA[ <= ]]>  #{endInceptionDate}
     </if>
     <if test="msLabel !=null and msLabel !=''">
-      and ms_label like concat(#{msLabel},'%')
+      and ms_label like concat('%',#{msLabel},'%')
     </if>
     <if test="navFrequency !=null and navFrequency !=''">
-      and nav_frequency like concat(#{navFrequency},'%')
+      and nav_frequency like concat('%',#{navFrequency},'%')
     </if>
     <if test="assetFrequency !=null and assetFrequency !=''">
-      and asset_frequency like concat(#{assetFrequency},'%')
+      and asset_frequency like concat('%',#{assetFrequency},'%')
     </if>
     <if test="reportFrequency !=null and reportFrequency !=''">
-      and report_frequency like concat(#{reportFrequency},'%')
+      and report_frequency like concat('%',#{reportFrequency},'%')
     </if>
   </select>
   <select id="selectByNameAndRegisterNumber" resultMap="BaseResultMap">

+ 3 - 2
service-manage/src/main/java/com/simuwang/manage/api/product/ProductController.java

@@ -15,6 +15,7 @@ import com.smppw.common.pojo.ResultVo;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletResponse;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -76,11 +77,11 @@ public class ProductController {
     @PostMapping("/export")
     public void exportProductInfomration(@RequestBody IdListVO idListVO, HttpServletResponse response ) {
         List<ProductDataVO> productDataVOList = productService.selectProuctInformationByIdList(idListVO.getIdList());
-        HSSFWorkbook wb = ExcelUtil.getProductHSSFWorkbook(productDataVOList);
+        XSSFWorkbook wb = ExcelUtil.getProductXSSFWorkbook(productDataVOList);
         try {
             response.setContentType("application/x-xls");
             response.setCharacterEncoding("utf-8");
-            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("产品要素.xls"));
+            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("产品要素.xlsx"));
             ServletOutputStream outputStream = response.getOutputStream();
             wb.write(outputStream);
             outputStream.flush();

+ 3 - 3
service-manage/src/main/java/com/simuwang/manage/service/impl/ProductServiceImpl.java

@@ -450,7 +450,7 @@ public class ProductServiceImpl implements ProductService {
                     productInformationDataList.add(excelData);
                 }
             }
-        })).excelType(ExcelTypeEnum.XLSX).sheet(0).headRowNumber(8).doRead();
+        })).excelType(ExcelTypeEnum.XLSX).sheet(0).headRowNumber(3).doRead();
 
         List<ProductContractData> productContractDataList = new ArrayList<>();
         EasyExcel.read(file, ProductContractData.class, new PageReadListener<ProductContractData>(dataList -> {
@@ -460,7 +460,7 @@ public class ProductServiceImpl implements ProductService {
                     productContractDataList.add(excelData);
                 }
             }
-        })).excelType(ExcelTypeEnum.XLSX).sheet(1).headRowNumber(8).doRead();
+        })).excelType(ExcelTypeEnum.XLSX).sheet(1).headRowNumber(3).doRead();
 
         List<ProductDerivativeData> productDerivativeDataList = new ArrayList<>();
         EasyExcel.read(file, ProductDerivativeData.class, new PageReadListener<ProductDerivativeData>(dataList -> {
@@ -470,7 +470,7 @@ public class ProductServiceImpl implements ProductService {
                     productDerivativeDataList.add(excelData);
                 }
             }
-        })).excelType(ExcelTypeEnum.XLSX).sheet(2).headRowNumber(8).doRead();
+        })).excelType(ExcelTypeEnum.XLSX).sheet(2).headRowNumber(3).doRead();
 
         List<InvestmentManagerData> investmentManagerDataList = new ArrayList<>();
         EasyExcel.read(file, InvestmentManagerData.class, new PageReadListener<InvestmentManagerData>(dataList -> {