|
@@ -3,15 +3,16 @@ package com.galaxis.manatee.Test.zzx;
|
|
|
import com.galaxis.manatee.entity.chuanyun.data.object.Handbook;
|
|
|
import com.galaxis.manatee.entity.chuanyun.data.object.MyExcelData;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
@@ -24,64 +25,47 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
@Slf4j
|
|
|
@SpringBootTest
|
|
|
/**
|
|
|
- * 读取excel文件
|
|
|
+ * 分权手册(h2人员信息)更新
|
|
|
*/
|
|
|
public class ProjectTest2 {
|
|
|
public static void main(String[] args) {
|
|
|
- List<List<Object>> excel1 = getExcel("C:\\Users\\mayn\\Desktop\\分权手册2022_09_20_16_31_58.xlsx");
|
|
|
- List<List<Object>> excel2 = getExcel("C:\\Users\\mayn\\Desktop\\凯捷--2022年度分级授权手册20220920更新了花名册.xls");
|
|
|
+ List<List<Object>> excel1 = getExcel("C:\\Users\\86186\\Desktop\\分权手册2022_09_21_16_33_42.xlsx");
|
|
|
+ List<List<Object>> excel2 = getExcel("C:\\Users\\86186\\Desktop\\凯捷--2022年度分级授权手册20220920更新了花名册.xls");
|
|
|
|
|
|
- //最新的h2分权手册
|
|
|
+ // 最新的h2分权手册
|
|
|
List<MyExcelData> excelDataList = new ArrayList<>();
|
|
|
for (int j = 0; j < excel2.size(); j++) {
|
|
|
- List<Object> objects2 = excel2.get(j);
|
|
|
- // System.err.println(objects2);
|
|
|
+ List<Object> newH2 = excel2.get(j);
|
|
|
if (j > 1) {
|
|
|
- //System.err.println(objects2);
|
|
|
- String objects2Sub = objects2.toString().substring(1, objects2.toString().length() - 1);
|
|
|
- String[] splitArr2 = objects2Sub.split(",");
|
|
|
- // splitArr数组:7-一级领导,8-二级领导,9-三级领导,10-总经理,11-集团分管领导
|
|
|
+ // System.err.println(newH2);
|
|
|
+ // System.err.println("newH2[1]:" + newH2.get(1));
|
|
|
+ // splitArr数组:6-一级领导,7-二级领导,8-三级领导,9-总经理,10-集团分管领导
|
|
|
MyExcelData myExcelData = new MyExcelData();
|
|
|
- myExcelData.setName(splitArr2[1]);
|
|
|
- myExcelData.setFirstName(splitArr2[7]);
|
|
|
- myExcelData.setSecondName(splitArr2[8]);
|
|
|
- myExcelData.setThirdName(splitArr2[9]);
|
|
|
- myExcelData.setManager(splitArr2[10]);
|
|
|
- myExcelData.setGroupChargeLeader(splitArr2[11]);
|
|
|
+ myExcelData.setName(newH2.get(1).toString());
|
|
|
+ myExcelData.setCompany(newH2.get(2).toString());
|
|
|
+ myExcelData.setFirstName(newH2.get(6).toString());
|
|
|
+ myExcelData.setSecondName(newH2.get(7).toString());
|
|
|
+ myExcelData.setThirdName(newH2.get(8).toString());
|
|
|
+ myExcelData.setManager(newH2.get(9).toString());
|
|
|
+ myExcelData.setGroupChargeLeader(newH2.get(10).toString());
|
|
|
excelDataList.add(myExcelData);
|
|
|
}
|
|
|
}
|
|
|
+ // System.err.println(excelDataList.toString());
|
|
|
|
|
|
// 集团所有人的信息
|
|
|
List<Handbook> handbookList = new ArrayList<>();
|
|
|
for (int i = 0; i < excel1.size(); i++) {
|
|
|
List<Object> objects1 = excel1.get(i);
|
|
|
if (i > 1) {
|
|
|
- // System.err.println(objects.toString());
|
|
|
- String objects1Sub = objects1.toString().substring(1, objects1.toString().length() - 1);
|
|
|
- String[] splitArr1 = objects1Sub.split(",");
|
|
|
- // System.err.println("姓名:" + splitArr1[1] + ",一级领导:" + splitArr1[9]);
|
|
|
+ // System.err.println(objects1.toString());
|
|
|
// splitArr数组:9-一级领导,10-二级领导,11-三级领导,13-分公司总经理,14-集团分管领导
|
|
|
Handbook handbook = new Handbook();
|
|
|
- handbook.setObjectId(splitArr1[0]);
|
|
|
- handbook.setName(splitArr1[1]);
|
|
|
- handbook.setCreatedBy(splitArr1[2]);
|
|
|
- handbook.setOwnerId(splitArr1[3]);
|
|
|
- handbook.setOwnerDeptId(splitArr1[4]);
|
|
|
- handbook.setCreatedTime(splitArr1[5]);
|
|
|
- handbook.setModifiedTime(splitArr1[6]);
|
|
|
- handbook.setF0000001(splitArr1[7]);
|
|
|
- handbook.setF0000002(splitArr1[8]);
|
|
|
- handbook.setF0000003(splitArr1[9]);
|
|
|
- handbook.setF0000004(splitArr1[10]);
|
|
|
- handbook.setF0000005(splitArr1[11]);
|
|
|
- handbook.setF0000011(splitArr1[12]);
|
|
|
- handbook.setF0000006(splitArr1[13]);
|
|
|
- handbook.setF0000007(splitArr1[14]);
|
|
|
- handbook.setF0000009(splitArr1[15]);
|
|
|
- handbook.setF0000008(splitArr1[16]);
|
|
|
- handbook.setF0000010(splitArr1[17]);
|
|
|
- handbook.setF0000012(splitArr1[18]);
|
|
|
+ handbook.setObjectId(objects1.get(0).toString());
|
|
|
+ handbook.setName(objects1.get(1).toString());
|
|
|
+ handbook.setOwnerId(objects1.get(3).toString());
|
|
|
+ handbook.setOwnerDeptId(objects1.get(4).toString());
|
|
|
+ handbook.setF0000001(objects1.get(7).toString());
|
|
|
|
|
|
for (int k = 0; k < excelDataList.size(); k++) {
|
|
|
MyExcelData myExcelData = excelDataList.get(k);
|
|
@@ -92,15 +76,157 @@ public class ProjectTest2 {
|
|
|
handbook.setF0000005(myExcelData.getThirdName());
|
|
|
handbook.setF0000006(myExcelData.getManager());
|
|
|
handbook.setF0000007(myExcelData.getGroupChargeLeader());
|
|
|
+ handbook.setF0000012(myExcelData.getCompany());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ handbook.setCreatedBy(objects1.get(2).toString());
|
|
|
+ handbook.setCreatedTime(objects1.get(5).toString());
|
|
|
+ handbook.setModifiedTime(objects1.get(6).toString());
|
|
|
+ handbook.setF0000002(objects1.get(8).toString());
|
|
|
+ handbook.setF0000011(objects1.get(12).toString());
|
|
|
+ handbook.setF0000009(objects1.get(15).toString());
|
|
|
+ handbook.setF0000008(objects1.get(16).toString());
|
|
|
+ handbook.setF0000010(objects1.get(17).toString());
|
|
|
+
|
|
|
handbookList.add(handbook);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // System.err.println(handbookList.toString());
|
|
|
- System.err.println(handbookList.get(607)); //陈中彬
|
|
|
+ // System.err.println(handbookList.toString());
|
|
|
+ // System.err.println(handbookList.get(609)); //刘东升
|
|
|
+
|
|
|
+ toTxt(handbookList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将List导出成Excel
|
|
|
+ public static void toExcel(List<Handbook> handbookList) {
|
|
|
+ //创建一个Excel文件
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+
|
|
|
+ //创建一个sheet
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd");
|
|
|
+ HSSFSheet sheet = workbook.createSheet("更新过后的分权手册" + simpleDateFormat.format(new Date()));
|
|
|
+
|
|
|
+ //在sheet表中添加0行
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+
|
|
|
+ //创建单元格,设置表头
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
+ cell.setCellValue("ObjectId");
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue("Name");
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue("CreatedBy");
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue("OwnerId");
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellValue("OwnerDeptId");
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellValue("CreatedTime");
|
|
|
+
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellValue("ModifiedTime");
|
|
|
+
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellValue("F0000001");
|
|
|
+
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellValue("F0000002");
|
|
|
+
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellValue("F0000003");
|
|
|
+
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellValue("F0000004");
|
|
|
+
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellValue("F0000005");
|
|
|
+
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellValue("F0000011");
|
|
|
+
|
|
|
+ cell = row.createCell(13);
|
|
|
+ cell.setCellValue("F0000006");
|
|
|
+
|
|
|
+ cell = row.createCell(14);
|
|
|
+ cell.setCellValue("F0000007");
|
|
|
+
|
|
|
+ cell = row.createCell(15);
|
|
|
+ cell.setCellValue("F0000009");
|
|
|
+
|
|
|
+ cell = row.createCell(16);
|
|
|
+ cell.setCellValue("F0000008");
|
|
|
+
|
|
|
+ cell = row.createCell(17);
|
|
|
+ cell.setCellValue("F0000010");
|
|
|
+
|
|
|
+ cell = row.createCell(18);
|
|
|
+ cell.setCellValue("F0000012");
|
|
|
+
|
|
|
+ for (int i = 0; i < handbookList.size(); i++) {
|
|
|
+ //创建行
|
|
|
+ HSSFRow row1 = sheet.createRow(i + 1);
|
|
|
+ Handbook handbook = handbookList.get(i);
|
|
|
+
|
|
|
+ //为单元格写入值,从0开始
|
|
|
+ row1.createCell(0).setCellValue(handbook.getObjectId());
|
|
|
+ row1.createCell(1).setCellValue(handbook.getName());
|
|
|
+ row1.createCell(2).setCellValue(handbook.getCreatedBy());
|
|
|
+ row1.createCell(3).setCellValue(handbook.getOwnerId());
|
|
|
+ row1.createCell(4).setCellValue(handbook.getOwnerDeptId());
|
|
|
+ row1.createCell(5).setCellValue(handbook.getCreatedTime());
|
|
|
+ row1.createCell(6).setCellValue(handbook.getModifiedTime());
|
|
|
+ row1.createCell(7).setCellValue(handbook.getF0000001());
|
|
|
+ row1.createCell(8).setCellValue(handbook.getF0000002());
|
|
|
+ row1.createCell(9).setCellValue(handbook.getF0000003());
|
|
|
+ row1.createCell(10).setCellValue(handbook.getF0000004());
|
|
|
+ row1.createCell(11).setCellValue(handbook.getF0000005());
|
|
|
+ row1.createCell(12).setCellValue(handbook.getF0000011());
|
|
|
+ row1.createCell(13).setCellValue(handbook.getF0000006());
|
|
|
+ row1.createCell(14).setCellValue(handbook.getF0000007());
|
|
|
+ row1.createCell(15).setCellValue(handbook.getF0000009());
|
|
|
+ row1.createCell(16).setCellValue(handbook.getF0000008());
|
|
|
+ row1.createCell(17).setCellValue(handbook.getF0000010());
|
|
|
+ row1.createCell(18).setCellValue(handbook.getF0000012());
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File("C:/Users/86186/Desktop/test.txt");
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ //将文件保存到指定的位置
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+// workbook.write(file);
|
|
|
+ System.out.println("导出到成功");
|
|
|
+ System.out.println("默认位置:C:/Users/86186/Desktop/test.txt");
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //将List导出成Txt
|
|
|
+ public static void toTxt(List<Handbook> handbookList) {
|
|
|
+ BufferedWriter bw;
|
|
|
+ try {
|
|
|
+ bw = new BufferedWriter(new FileWriter("C:/Users/86186/Desktop/test.txt"));
|
|
|
+ for (int j = 0; j < handbookList.size(); j++) {
|
|
|
+ bw.write(handbookList.get(j).toString());
|
|
|
+ bw.newLine();
|
|
|
+ bw.flush();
|
|
|
+ }
|
|
|
+ bw.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static List<List<Object>> getExcel(String filePath) {
|
|
@@ -108,7 +234,6 @@ public class ProjectTest2 {
|
|
|
Sheet sheet = null;
|
|
|
Row row = null;
|
|
|
|
|
|
- // String filePath1 = "C:\\Users\\86186\\Desktop\\分权手册2022_09_20_16_31_58.xlsx";
|
|
|
wb = readExcel(filePath);
|
|
|
|
|
|
List<List<List<Object>>> list = new ArrayList<>();
|
|
@@ -197,4 +322,9 @@ public class ProjectTest2 {
|
|
|
}
|
|
|
return cellvalue;
|
|
|
}
|
|
|
+
|
|
|
+ public static Boolean isNotNull(List<Object> objects, int index) {
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|