去除多余代码

This commit is contained in:
wangchengjun
2022-04-10 14:29:58 +08:00
parent 3005b527b7
commit af4be96ab4
8 changed files with 357 additions and 3262 deletions
@@ -351,7 +351,7 @@ public class FileSpiltService {
* @param sarFileSplitInfoEO
* @return
*/
public int fileEU(SarFileSplitInfoEO sarFileSplitInfoEO) {
public int fileGSO(SarFileSplitInfoEO sarFileSplitInfoEO) {
// 拆分文件主表中插入数据
if (sarFileSplitInfoEO.getStopNumber()<=0){
sarFileSplitInfoEO.setStopNumber(200);
@@ -699,6 +699,357 @@ public class FileSpiltService {
return treeList.size();
}
/**
*欧洲标准
* @param sarFileSplitInfoEO
* @return
*/
public int fileEU(SarFileSplitInfoEO sarFileSplitInfoEO) {
if (sarFileSplitInfoEO.getStopNumber()<=0){
sarFileSplitInfoEO.setStopNumber(200);
}
if (sarFileSplitInfoEO.getStartNumber()<=0){
sarFileSplitInfoEO.setStartNumber(1);
}
// 拆分文件条款表中最终插入数据
List<SarFileSplitItemsEO> messageList = new ArrayList<>();
int messageNumber = 0;
// 拆分文件目录表中最终插入数据
List<SarFileSplitMenuEO> treeList = new ArrayList<>();
// 拆分文件条款详情表中最终插入数据
List<SarFileSplitItemsValEO> itemValList = new ArrayList<>();
Long treeListDisplay = 1L;
String generalCatalogueId = UUIDUtils.randomUUID20();
SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO();
// SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO(generalCatalogueId,"General catalogue","",sarFileSplitInfoEO.getId(),treeListDisplay++,"");
documentTreeEO.setId(generalCatalogueId);
documentTreeEO.setName("General catalogue");
documentTreeEO.setInfoId(sarFileSplitInfoEO.getId());
documentTreeEO.setDisplaySeq(1L);
documentTreeEO.setDisplaySeq(treeListDisplay++);
documentTreeEO.setValidFlag(0);
treeList.add(documentTreeEO);
List<String> nowStart = new ArrayList<>();
nowStart.add("1.");
// if (sarFileSplitInfoEO.getStartNumber()<4){
// } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// }
try {
//获取文件地址
String connectId = sarFileSplitInfoEO.getConnectId();
if(StringUtils.isEmpty(connectId)){
throw new JeroBootException("当前文件未找到,请重新选择!");
}
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(OSSFile::getConnectId,connectId);
OSSFile ossFile = iossFileService.getOne(queryWrapper);
String readFilePath = ossFile.getUrl();
if(StringUtils.isEmpty(readFilePath)){
throw new JeroBootException("当前文件未找到,请重新选择!");
}
InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is);
Pattern ptest = Pattern.compile("^[\\d.]*$");
Matcher matcher;
// 记录拆分后的每一段文字
List<IBodyElement> elements = doc.getBodyElements();
// 记录word自动生成的编号数据
Map numberMap = new HashMap<String,Integer>();
boolean menuCanAdd = false; // 判断当前目录下是否可以正常填写数据
for (IBodyElement element : elements) {
// 段落
if (element instanceof XWPFParagraph) {
XWPFParagraph p = (XWPFParagraph)element;
// 处理段落生成编号不识别问题
String paragraphString = p.getText();
if (StringUtils.isNotBlank(paragraphString)) {
paragraphString = paragraphString.replace((char) 12288, ' ');
paragraphString = paragraphString.trim();
}
if (StringUtils.isNotEmpty(p.getNumLevelText())&& p.getNumLevelText().indexOf(".")>0) {
String numberParent = p.getNumLevelText().substring(0,p.getNumLevelText().lastIndexOf("."));
if (numberMap.containsKey(numberParent)){
Integer numbernow =(Integer)numberMap.get(numberParent)+1;
if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size()-1).getItemsNum().equals(numberParent + "." + String.valueOf(numbernow))){
numberMap.put(numberParent,numbernow+1);
paragraphString = numberParent + "." + String.valueOf(numbernow+1)+ p.getText();
} else {
numberMap.put(numberParent,numbernow);
paragraphString = numberParent + "." + String.valueOf(numbernow)+ p.getText();
}
} else {
numberMap.put(numberParent,1);
paragraphString = numberParent+".1"+ p.getText();
}
}
//^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
ptest = Pattern.compile("^[\\d.]*$");
boolean hasGoIf = false;
for (int i=0;i<nowStart.size();i++){
if(paragraphString.startsWith(nowStart.get(i))){
if(paragraphString.length()>nowStart.get(i).length()
&& !ptest.matcher(paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+1)).matches()){
// 判断名称,如果大于10位,取十位,
String itemName = paragraphString.substring(nowStart.get(i).length()).length()>10?paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+10):paragraphString.substring(nowStart.get(i).length());
List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(),nowStart.get(i),itemName,clauseContent);
String[] numberStr = nowStart.get(i).split("\\.");
String numberStrTemp = numberStr[0].replace("S", "");
if (Integer.valueOf(numberStrTemp) > sarFileSplitInfoEO.getStopNumber()){
menuCanAdd = false;
} else {
// 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(nowStart.get(i),treeList,generalCatalogueId,sarFileSplitInfoEO ,treeListDisplay++,itemName);
treeList.add(sarFileSplitMenuEO) ;
message.setMenuId(sarFileSplitMenuEO.getId());
addItermsConditionsText(message,itemValList,paragraphString.substring(nowStart.get(i).length()));
messageList.add(message);
nowStart = getNewNowStartUS(nowStart.get(i));
menuCanAdd = true;
}
hasGoIf = true;
break;
}else {
// 判断名称,如果大于10位,取十位,
String itemName = paragraphString.substring(nowStart.get(i).length()).length()>10?paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+10):paragraphString.substring(nowStart.get(i).length());
List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(),nowStart.get(i),itemName,clauseContent);
String[] numberStr = nowStart.get(i).split("\\.");
String numberStrTemp = numberStr[0].replace("S", "");
if (Integer.valueOf(numberStrTemp) > sarFileSplitInfoEO.getStopNumber()){
menuCanAdd = false;
} else {
// 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(nowStart.get(i),treeList,generalCatalogueId,sarFileSplitInfoEO ,treeListDisplay++,itemName);
treeList.add(sarFileSplitMenuEO) ;
message.setMenuId(sarFileSplitMenuEO.getId());
addItermsConditionsText(message,itemValList,paragraphString.substring(nowStart.get(i).length()));
messageList.add(message);
nowStart = getNewNowStartUS(nowStart.get(i));
menuCanAdd = true;
}
hasGoIf = true;
break;
}
}
}
// 判断是否直接跳出所有循环
if (!menuCanAdd && messageList.size()>0) {
break;
}
} else if (element instanceof XWPFTable){
if(messageList != null && !messageList.isEmpty()){
addItermsConditionsOfTable(messageList.get(messageList.size()-1),itemValList,(XWPFTable)element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
if(treeList.size()>0 && messageList.size() > 0){
sarFileSplitMenuEOMapper.insertForeach(treeList);
iSarFileSplitItemsEOService.insertForeach(messageList);
iSarFileSplitItemsValEOService.insertForeach(itemValList);
} else {
return -1;
}
return treeList.size();
}
/**
* 日本标准
* @param sarFileSplitInfoEO
*/
public int fileJapan(SarFileSplitInfoEO sarFileSplitInfoEO) {
if (sarFileSplitInfoEO.getStopNumber()<=0){
sarFileSplitInfoEO.setStopNumber(200);
}
if (sarFileSplitInfoEO.getStartNumber()<=0){
sarFileSplitInfoEO.setStartNumber(1);
}
// 拆分文件条款表中最终插入数据
List<SarFileSplitItemsEO> messageList = new ArrayList<>();
int messageNumber = 0;
// 拆分文件目录表中最终插入数据
List<SarFileSplitMenuEO> treeList = new ArrayList<>();
// 拆分文件条款详情表中最终插入数据
List<SarFileSplitItemsValEO> itemValList = new ArrayList<>();
Long treeListDisplay = 1L;
String generalCatalogueId = UUIDUtils.randomUUID20();
SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO();
// SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO(generalCatalogueId,"General catalogue","",sarFileSplitInfoEO.getId(),treeListDisplay++,"");
documentTreeEO.setId(generalCatalogueId);
documentTreeEO.setName("General catalogue");
documentTreeEO.setInfoId(sarFileSplitInfoEO.getId());
documentTreeEO.setDisplaySeq(1L);
documentTreeEO.setDisplaySeq(treeListDisplay++);
documentTreeEO.setValidFlag(0);
treeList.add(documentTreeEO);
List<String> nowStart = new ArrayList<>();
nowStart.add("S1");
// if (sarFileSplitInfoEO.getStartNumber()<4){
// } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// }
try {
//获取文件地址
String connectId = sarFileSplitInfoEO.getConnectId();
if(StringUtils.isEmpty(connectId)){
throw new JeroBootException("当前文件未找到,请重新选择!");
}
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(OSSFile::getConnectId,connectId);
OSSFile ossFile = iossFileService.getOne(queryWrapper);
String readFilePath = ossFile.getUrl();
if(StringUtils.isEmpty(readFilePath)){
throw new JeroBootException("当前文件未找到,请重新选择!");
}
InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is);
Pattern ptest = Pattern.compile("S^[\\d.]*$");
Matcher matcher;
// 记录拆分后的每一段文字
List<IBodyElement> elements = doc.getBodyElements();
// 记录word自动生成的编号数据
Map numberMap = new HashMap<String,Integer>();
boolean menuCanAdd = false; // 判断当前目录下是否可以正常填写数据
for (IBodyElement element : elements) {
// 段落
if (element instanceof XWPFParagraph) {
XWPFParagraph p = (XWPFParagraph)element;
// 处理段落生成编号不识别问题
String paragraphString = p.getText();
if (StringUtils.isNotBlank(paragraphString)) {
paragraphString = paragraphString.replace((char) 12288, ' ');
paragraphString = paragraphString.trim();
}
if (StringUtils.isNotEmpty(p.getNumLevelText())&& p.getNumLevelText().indexOf(".")>0) {
String numberParent = p.getNumLevelText().substring(0,p.getNumLevelText().lastIndexOf("."));
if (numberMap.containsKey(numberParent)){
Integer numbernow =(Integer)numberMap.get(numberParent)+1;
if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size()-1).getItemsNum().equals(numberParent + "." + String.valueOf(numbernow))){
numberMap.put(numberParent,numbernow+1);
paragraphString = numberParent + "." + String.valueOf(numbernow+1)+ p.getText();
} else {
numberMap.put(numberParent,numbernow);
paragraphString = numberParent + "." + String.valueOf(numbernow)+ p.getText();
}
} else {
numberMap.put(numberParent,1);
paragraphString = numberParent+".1"+ p.getText();
}
}
//^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
ptest = Pattern.compile("S^[\\d.]*$");
boolean hasGoIf = false;
for (int i=0;i<nowStart.size();i++){
if(paragraphString.startsWith(nowStart.get(i))){
if(paragraphString.length()>nowStart.get(i).length()
&& !ptest.matcher(paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+1)).matches()){
// 判断名称,如果大于10位,取十位,
String itemName = paragraphString.substring(nowStart.get(i).length()).length()>10?paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+10):paragraphString.substring(nowStart.get(i).length());
List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(),nowStart.get(i),itemName,clauseContent);
String[] numberStr = nowStart.get(i).split("\\.");
String numberStrTemp = numberStr[0].replace("S", "");
if (Integer.valueOf(numberStrTemp) > sarFileSplitInfoEO.getStopNumber()){
menuCanAdd = false;
} else {
// 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(nowStart.get(i),treeList,generalCatalogueId,sarFileSplitInfoEO ,treeListDisplay++,itemName);
treeList.add(sarFileSplitMenuEO) ;
message.setMenuId(sarFileSplitMenuEO.getId());
addItermsConditionsText(message,itemValList,paragraphString.substring(nowStart.get(i).length()));
messageList.add(message);
nowStart = getNewNowStartUS(nowStart.get(i));
menuCanAdd = true;
}
hasGoIf = true;
break;
}else {
// 判断名称,如果大于10位,取十位,
String itemName = paragraphString.substring(nowStart.get(i).length()).length()>10?paragraphString.substring(nowStart.get(i).length(),nowStart.get(i).length()+10):paragraphString.substring(nowStart.get(i).length());
List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(),nowStart.get(i),itemName,clauseContent);
String[] numberStr = nowStart.get(i).split("\\.");
String numberStrTemp = numberStr[0].replace("S", "");
if (Integer.valueOf(numberStrTemp) > sarFileSplitInfoEO.getStopNumber()){
menuCanAdd = false;
} else {
// 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(nowStart.get(i),treeList,generalCatalogueId,sarFileSplitInfoEO ,treeListDisplay++,itemName);
treeList.add(sarFileSplitMenuEO) ;
message.setMenuId(sarFileSplitMenuEO.getId());
addItermsConditionsText(message,itemValList,paragraphString.substring(nowStart.get(i).length()));
messageList.add(message);
nowStart = getNewNowStartUS(nowStart.get(i));
menuCanAdd = true;
}
hasGoIf = true;
break;
}
}
}
// 判断是否直接跳出所有循环
if (!menuCanAdd && messageList.size()>0) {
break;
}
} else if (element instanceof XWPFTable){
if(messageList != null && !messageList.isEmpty()){
addItermsConditionsOfTable(messageList.get(messageList.size()-1),itemValList,(XWPFTable)element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
if(treeList.size()>0 && messageList.size() > 0){
sarFileSplitMenuEOMapper.insertForeach(treeList);
iSarFileSplitItemsEOService.insertForeach(messageList);
iSarFileSplitItemsValEOService.insertForeach(itemValList);
} else {
return -1;
}
return treeList.size();
}
/**
* 通过传递过来的编号,得出下次可能出现的编号
* @param nowStart
@@ -1065,6 +1416,8 @@ public class FileSpiltService {
return sarFileSplitItemsValEO;
}
// public String addToStandItems(SarFileSplitInfoEO sarFileSplitInfoEO,SarStandardsInfoEO sarStandardsInfoEO ) throws Exception {
// //查询拆分中所有条款信息
// SarFileSplitItemsEOPage splitItemsEOPage = new SarFileSplitItemsEOPage();
@@ -80,14 +80,16 @@ public class SarFileSplitInfoServiceImpl extends ServiceImpl<SarFileSplitInfoMap
fileSpiltService.fileCHN(sarFileSplitInfoEO);
break;
case EU:
fileSpiltService.fileEU(sarFileSplitInfoEO);
break;
case US:
fileSpiltService.fileUSA(sarFileSplitInfoEO);
break;
case GSO:
fileSpiltService.fileEU(sarFileSplitInfoEO);
fileSpiltService.fileGSO(sarFileSplitInfoEO);
break;
case JAPAN:
fileSpiltService.fileJapan(sarFileSplitInfoEO);
break;
case KOREAN:
break;
-63
View File
@@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jero-boot</artifactId>
<groupId>com.jero.boot</groupId>
<version>2.4.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jreo-boot-split</artifactId>
<properties>
<poi.version>4.1.2</poi.version>
<jero.version>2.4.2</jero.version>
</properties>
<dependencies>
<!-- poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jero.boot</groupId>
<artifactId>jero-boot-module-system</artifactId>
<version>${jero.version}</version>
</dependency>
<dependency>
<groupId>com.jero.boot</groupId>
<artifactId>jero-boot-module-demo</artifactId>
<version>${jero.version}</version>
</dependency>
<dependency>
<groupId>com.jero.boot</groupId>
<artifactId>jero-boot-base-generater</artifactId>
<version>${jero.version}</version>
</dependency>
<dependency>
<groupId>com.jero.boot</groupId>
<artifactId>jero-boot-modules</artifactId>
<version>${jero.version}</version>
</dependency>
</dependencies>
</project>
@@ -1,522 +0,0 @@
//package com.jero.modules.entity;
//
//import com.fasterxml.jackson.annotation.JsonFormat;
//
//import java.util.Date;
//import java.util.List;
//
///**
// * <b>功能:</b>SAR_FILE_SPLIT_ITEMS SarFileSplitItemsEOEntity<br>
// * <b>作者:</b>code generator<br>
// * <b>日期:</b> 2020-01-03 <br>
// * <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
// */
//public class SarFileSplitItemsEO {
//
// private String id;
// private String infoId;
// private String itemsNum;
// private String itemsName;
// private String itermsConditions;
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// private Date newcarPutTime;
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// private Date productPutTime;
// private String menuId;
// private String svpps;
// private String applyArctic;
// private String referenceStand;
// private String specialRequest;
// private String relevanceFile;
// private String remarks;
// private Integer validFlag;
// private String creationUser;
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// private Date creationTime;
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// private Date modifyTime;
// private String modifyUser;
// private String[] infoIdList;
// private String[] idList;
//// private List<SarFileSplitItemsValEO> itemValEOList;
// // 前台删除的VAL表条目内容ID
// private String delItemIds;
// private String sMenuId;
// //特殊参数要求
//// private List<SarFileSplitItemsParamsEO> paramsList;
// private String relevanceFileAttid;
//
// //新加字段 SVPPS在前边已经存在
// private String fo;//FO
// private String dutyEngineer;//责任工程师
// private String claimType;//要求类型
// private String busStandCover;//企标覆盖关系
// private String fileType;//文件类型
//
// //新加字段带show
// private String foShow;//FO
// private String dutyEngineerShow;//责任工程师
// private String svppsShow;//SVPPS
// private String claimTypeShow;//要求类型
// private String busStandCoverShow;//企标覆盖关系
// private String fileTypeShow;//文件类型
//
// private String responsibleUnit;//责任部门
// private String responsibleUnitShow;
// /**
// * java字段名转换为原始数据库列名。<b>如果不存在则返回null</b><br>
// * <p>字段列表:</p>
// * <li>id -> id</li>
// * <li>infoId -> info_id</li>
// * <li>itemsNum -> items_num</li>
// * <li>itemsName -> items_name</li>
// * <li>itermsConditions -> iterms_conditions</li>
// * <li>newcarPutTime -> newcar_put_time</li>
// * <li>productPutTime -> product_put_time</li>
// * <li>menuId -> menu_id</li>
// * <li>svpps -> svpps</li>
// * <li>applyArctic -> apply_arctic</li>
// * <li>referenceStand -> reference_stand</li>
// * <li>specialRequest -> special_request</li>
// * <li>relevanceFile -> relevance_file</li>
// * <li>remarks -> remarks</li>
// * <li>validFlag -> valid_flag</li>
// * <li>creationUser -> creation_user</li>
// * <li>creationTime -> creation_time</li>
// * <li>modifyTime -> modify_time</li>
// * <li>modifyUser -> modify_user</li>
// */
// public static String fieldToColumn(String fieldName) {
// if (fieldName == null) return null;
// switch (fieldName) {
// case "id": return "id";
// case "infoId": return "info_id";
// case "itemsNum": return "items_num";
// case "itemsName": return "items_name";
// case "itermsConditions": return "iterms_conditions";
// case "newcarPutTime": return "newcar_put_time";
// case "productPutTime": return "product_put_time";
// case "menuId": return "menu_id";
// case "svpps": return "svpps";
// case "applyArctic": return "apply_arctic";
// case "referenceStand": return "reference_stand";
// case "specialRequest": return "special_request";
// case "relevanceFile": return "relevance_file";
// case "remarks": return "remarks";
// case "validFlag": return "valid_flag";
// case "creationUser": return "creation_user";
// case "creationTime": return "creation_time";
// case "modifyTime": return "modify_time";
// case "modifyUser": return "modify_user";
// default: return null;
// }
// }
//
// /**
// * 原始数据库列名转换为java字段名。<b>如果不存在则返回null</b><br>
// * <p>字段列表:</p>
// * <li>id -> id</li>
// * <li>info_id -> infoId</li>
// * <li>items_num -> itemsNum</li>
// * <li>items_name -> itemsName</li>
// * <li>iterms_conditions -> itermsConditions</li>
// * <li>newcar_put_time -> newcarPutTime</li>
// * <li>product_put_time -> productPutTime</li>
// * <li>menu_id -> menuId</li>
// * <li>svpps -> svpps</li>
// * <li>apply_arctic -> applyArctic</li>
// * <li>reference_stand -> referenceStand</li>
// * <li>special_request -> specialRequest</li>
// * <li>relevance_file -> relevanceFile</li>
// * <li>remarks -> remarks</li>
// * <li>valid_flag -> validFlag</li>
// * <li>creation_user -> creationUser</li>
// * <li>creation_time -> creationTime</li>
// * <li>modify_time -> modifyTime</li>
// * <li>modify_user -> modifyUser</li>
// */
// public static String columnToField(String columnName) {
// if (columnName == null) return null;
// switch (columnName) {
// case "id": return "id";
// case "info_id": return "infoId";
// case "items_num": return "itemsNum";
// case "items_name": return "itemsName";
// case "iterms_conditions": return "itermsConditions";
// case "newcar_put_time": return "newcarPutTime";
// case "product_put_time": return "productPutTime";
// case "menu_id": return "menuId";
// case "svpps": return "svpps";
// case "apply_arctic": return "applyArctic";
// case "reference_stand": return "referenceStand";
// case "special_request": return "specialRequest";
// case "relevance_file": return "relevanceFile";
// case "remarks": return "remarks";
// case "valid_flag": return "validFlag";
// case "creation_user": return "creationUser";
// case "creation_time": return "creationTime";
// case "modify_time": return "modifyTime";
// case "modify_user": return "modifyUser";
// default: return null;
// }
// }
//
// /** **/
// public String getId() {
// return this.id;
// }
//
// /** **/
// public void setId(String id) {
// this.id = id;
// }
//
// /** **/
// public String getInfoId() {
// return this.infoId;
// }
//
// /** **/
// public void setInfoId(String infoId) {
// this.infoId = infoId;
// }
//
// /** **/
// public String getItemsNum() {
// return this.itemsNum;
// }
//
// /** **/
// public void setItemsNum(String itemsNum) {
// this.itemsNum = itemsNum;
// }
//
// /** **/
// public String getItemsName() {
// return this.itemsName;
// }
//
// /** **/
// public void setItemsName(String itemsName) {
// this.itemsName = itemsName;
// }
//
// public String getItermsConditions() {
// return itermsConditions;
// }
//
// public void setItermsConditions(String itermsConditions) {
// this.itermsConditions = itermsConditions;
// }
//
// /** **/
// public Date getNewcarPutTime() {
// return this.newcarPutTime;
// }
//
// /** **/
// public void setNewcarPutTime(Date newcarPutTime) {
// this.newcarPutTime = newcarPutTime;
// }
//
// /** **/
// public Date getProductPutTime() {
// return this.productPutTime;
// }
//
// /** **/
// public void setProductPutTime(Date productPutTime) {
// this.productPutTime = productPutTime;
// }
//
// /** **/
// public String getMenuId() {
// return this.menuId;
// }
//
// /** **/
// public void setMenuId(String menuId) {
// this.menuId = menuId;
// }
//
// /** **/
// public String getSvpps() {
// return this.svpps;
// }
//
// /** **/
// public void setSvpps(String svpps) {
// this.svpps = svpps;
// }
//
// /** **/
// public String getApplyArctic() {
// return this.applyArctic;
// }
//
// /** **/
// public void setApplyArctic(String applyArctic) {
// this.applyArctic = applyArctic;
// }
//
// /** **/
// public String getReferenceStand() {
// return this.referenceStand;
// }
//
// /** **/
// public void setReferenceStand(String referenceStand) {
// this.referenceStand = referenceStand;
// }
//
// /** **/
// public String getSpecialRequest() {
// return this.specialRequest;
// }
//
// /** **/
// public void setSpecialRequest(String specialRequest) {
// this.specialRequest = specialRequest;
// }
//
// /** **/
// public String getRelevanceFile() {
// return this.relevanceFile;
// }
//
// /** **/
// public void setRelevanceFile(String relevanceFile) {
// this.relevanceFile = relevanceFile;
// }
//
// /** **/
// public String getRemarks() {
// return this.remarks;
// }
//
// /** **/
// public void setRemarks(String remarks) {
// this.remarks = remarks;
// }
//
// /** **/
// public Integer getValidFlag() {
// return this.validFlag;
// }
//
// /** **/
// public void setValidFlag(Integer validFlag) {
// this.validFlag = validFlag;
// }
//
// /** **/
// public String getCreationUser() {
// return this.creationUser;
// }
//
// /** **/
// public void setCreationUser(String creationUser) {
// this.creationUser = creationUser;
// }
//
// /** **/
// public Date getCreationTime() {
// return this.creationTime;
// }
//
// /** **/
// public void setCreationTime(Date creationTime) {
// this.creationTime = creationTime;
// }
//
// /** **/
// public Date getModifyTime() {
// return this.modifyTime;
// }
//
// /** **/
// public void setModifyTime(Date modifyTime) {
// this.modifyTime = modifyTime;
// }
//
// /** **/
// public String getModifyUser() {
// return this.modifyUser;
// }
//
// /** **/
// public void setModifyUser(String modifyUser) {
// this.modifyUser = modifyUser;
// }
//
//
// List<String> itemsCondi;
//
// public List<String> getItemsCondi() {
// return itemsCondi;
// }
//
// public void setItemsCondi(List<String> itemsCondi) {
// this.itemsCondi = itemsCondi;
// }
//
// public String[] getInfoIdList() {
// return infoIdList;
// }
//
// public void setInfoIdList(String[] infoIdList) {
// this.infoIdList = infoIdList;
// }
//
// public String[] getIdList() {
// return idList;
// }
//
// public void setIdList(String[] idList) {
// this.idList = idList;
// }
//
//// public List<SarFileSplitItemsValEO> getItemValEOList() {
//// return itemValEOList;
//// }
////
//// public void setItemValEOList(List<SarFileSplitItemsValEO> itemValEOList) {
//// this.itemValEOList = itemValEOList;
//// }
//
// public String getDelItemIds() {
// return delItemIds;
// }
//
// public void setDelItemIds(String delItemIds) {
// this.delItemIds = delItemIds;
// }
//
// public String getsMenuId() {
// return sMenuId;
// }
//
// public void setsMenuId(String sMenuId) {
// this.sMenuId = sMenuId;
// }
//
//// public List<SarFileSplitItemsParamsEO> getParamsList() {
//// return paramsList;
//// }
////
//// public void setParamsList(List<SarFileSplitItemsParamsEO> paramsList) {
//// this.paramsList = paramsList;
//// }
//
// public String getRelevanceFileAttid() {
// return relevanceFileAttid;
// }
//
// public void setRelevanceFileAttid(String relevanceFileAttid) {
// this.relevanceFileAttid = relevanceFileAttid;
// }
//
// public String getFo() {
// return fo;
// }
//
// public void setFo(String fo) {
// this.fo = fo;
// }
//
// public String getDutyEngineer() {
// return dutyEngineer;
// }
//
// public void setDutyEngineer(String dutyEngineer) {
// this.dutyEngineer = dutyEngineer;
// }
//
// public String getClaimType() {
// return claimType;
// }
//
// public void setClaimType(String claimType) {
// this.claimType = claimType;
// }
//
// public String getBusStandCover() {
// return busStandCover;
// }
//
// public void setBusStandCover(String busStandCover) {
// this.busStandCover = busStandCover;
// }
//
// public String getFileType() {
// return fileType;
// }
//
// public void setFileType(String fileType) {
// this.fileType = fileType;
// }
//
// public String getFoShow() {
// return foShow;
// }
//
// public void setFoShow(String foShow) {
// this.foShow = foShow;
// }
//
// public String getDutyEngineerShow() {
// return dutyEngineerShow;
// }
//
// public void setDutyEngineerShow(String dutyEngineerShow) {
// this.dutyEngineerShow = dutyEngineerShow;
// }
//
// public String getSvppsShow() {
// return svppsShow;
// }
//
// public void setSvppsShow(String svppsShow) {
// this.svppsShow = svppsShow;
// }
//
// public String getClaimTypeShow() {
// return claimTypeShow;
// }
//
// public void setClaimTypeShow(String claimTypeShow) {
// this.claimTypeShow = claimTypeShow;
// }
//
// public String getBusStandCoverShow() {
// return busStandCoverShow;
// }
//
// public void setBusStandCoverShow(String busStandCoverShow) {
// this.busStandCoverShow = busStandCoverShow;
// }
//
// public String getFileTypeShow() {
// return fileTypeShow;
// }
//
// public void setFileTypeShow(String fileTypeShow) {
// this.fileTypeShow = fileTypeShow;
// }
//
// public String getResponsibleUnit() {
// return responsibleUnit;
// }
//
// public void setResponsibleUnit(String responsibleUnit) {
// this.responsibleUnit = responsibleUnit;
// }
//
// public String getResponsibleUnitShow() {
// return responsibleUnitShow;
// }
//
// public void setResponsibleUnitShow(String responsibleUnitShow) {
// this.responsibleUnitShow = responsibleUnitShow;
// }
//}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,234 +0,0 @@
package com.jero.modules.utils;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
/**
* @Description:
* @Author: yangxuenan
* date: 2020/2/25 16:58
*/
public class ReadWordTable {
/**
* 保存生成HTML时需要被忽略的单元格
*/
private List<String> omitCellsList = new ArrayList<>();
/**
* 生成忽略的单元格列表中的格式
*
* @param row
* @param col
* @return
*/
public String generateOmitCellStr(int row, int col) {
return row + ":" + col;
}
/**
* 获取当前单元格的colspan(列合并)的列数
*
* @param tcPr 单元格属性
* @return
*/
public int getColspan(CTTcPr tcPr) {
// 判断是否存在列合并
CTDecimalNumber gridSpan = null;
if ((gridSpan = tcPr.getGridSpan()) != null) { // 合并的起始列
// 获取合并的列数
BigInteger num = gridSpan.getVal();
return num.intValue();
} else { // 其他被合并的列或正常列
return 1;
}
}
/**
* 获取当前单元格的rowspan(行合并)的行数
*
* @param table 表格
* @param row 行值
* @param col 列值
* @return
*/
public int getRowspan(XWPFTable table, int row, int col) {
XWPFTableCell cell = table.getRow(row).getCell(col);
// 正常独立单元格
if (!isContinueRow(cell) && !isRestartRow(cell)) {
return 1;
}
// 当前单元格的宽度
int cellWidth = getCellWidth(table, row, col);
// 当前单元格距离左侧边框的距离
int leftWidth = getLeftWidth(table, row, col);
// 用户保存当前单元格行合并的单元格数-1(因为不包含自身)
List<Boolean> list = new ArrayList<>();
getRowspan(table, row, cellWidth, leftWidth, list);
return list.size() + 1;
}
private void getRowspan(XWPFTable table, int row, int cellWidth, int leftWidth,
List<Boolean> list) {
// 已达到最后一行
if (row + 1 >= table.getNumberOfRows()) {
return;
}
row = row + 1;
int colsNum = table.getRow(row).getTableCells().size();
// 因为列合并单元格可能导致行合并的单元格并不在同一列,所以从头遍历列,通过属性、宽度以及距离左边框间距来判断是否是行合并
for (int i = 0; i < colsNum; i++) {
XWPFTableCell testTable = table.getRow(row).getCell(i);
// 是否为合并单元格的中间行(包括结尾行)
if (isContinueRow(testTable)) {
// 是被上一行单元格合并的单元格
if (getCellWidth(table, row, i) == cellWidth
&& getLeftWidth(table, row, i) == leftWidth) {
list.add(true);
// 被合并的单元格在生成html时需要忽略
addOmitCell(row, i);
// 去下一行继续查找
getRowspan(table, row, cellWidth, leftWidth, list);
break;
}
}
}
}
/**
* 判断是否是合并行的起始行单元格
*
* @param tableCell
* @return
*/
public boolean isRestartRow(XWPFTableCell tableCell) {
CTTcPr tcPr = tableCell.getCTTc().getTcPr();
if (tcPr.getVMerge() == null) {
return false;
}
if (tcPr.getVMerge().getVal() == null) {
return false;
}
if (tcPr.getVMerge().getVal().toString().equalsIgnoreCase("restart")) {
return true;
}
return false;
}
/**
* 判断是否是合并行的中间行单元格(包括结尾的最后一行的单元格)
*
* @param tableCell
* @return
*/
public boolean isContinueRow(XWPFTableCell tableCell) {
CTTcPr tcPr = tableCell.getCTTc().getTcPr();
if (tcPr.getVMerge() == null) {
return false;
}
if (tcPr.getVMerge().getVal() == null) {
return true;
}
return false;
}
public int getLeftWidth(XWPFTable table, int row, int col) {
int leftWidth = 0;
for (int i = 0; i < col; i++) {
leftWidth += getCellWidth(table, row, i);
}
return leftWidth;
}
public int getCellWidth(XWPFTable table, int row, int col) {
BigInteger width = table.getRow(row).getCell(col).getCTTc().getTcPr().getTcW().getW();
return width.intValue();
}
/**
* 添加忽略的单元格(被行合并的单元格,生成HTML时需要忽略)
*
* @param row
* @param col
*/
public void addOmitCell(int row, int col) {
String omitCellStr = generateOmitCellStr(row, col);
omitCellsList.add(omitCellStr);
}
public boolean isOmitCell(int row, int col) {
String cellStr = generateOmitCellStr(row, col);
return omitCellsList.contains(cellStr);
}
public String readTable(XWPFTable table) throws IOException {
// 表格行数
int tableRowsSize = table.getRows().size();
StringBuilder tableToHtmlStr = new StringBuilder("<table>");
for (int i = 0; i < tableRowsSize; i++) {
tableToHtmlStr.append("<tr>");
int tableCellsSize = table.getRow(i).getTableCells().size();
for (int j = 0; j < tableCellsSize; j++) {
if (isOmitCell(i, j)) {
continue;
}
XWPFTableCell tableCell = table.getRow(i).getCell(j);
// 获取单元格的属性
CTTcPr tcPr = tableCell.getCTTc().getTcPr();
int colspan = getColspan(tcPr);
if (colspan > 1) { // 合并的列
tableToHtmlStr.append("<td colspan='" + colspan + "'");
} else { // 正常列
tableToHtmlStr.append("<td");
}
int rowspan = getRowspan(table, i, j);
if (rowspan > 1) { // 合并的行
tableToHtmlStr.append(" rowspan='" + rowspan + "'>");
} else {
tableToHtmlStr.append(">");
}
String text = tableCell.getText();
tableToHtmlStr.append(text + "</td>");
}
tableToHtmlStr.append("</tr>");
}
tableToHtmlStr.append("</table>");
clearTableInfo();
return tableToHtmlStr.toString();
}
public void clearTableInfo() {
// System.out.println(omitCellsList);
omitCellsList.clear();
}
// public static void main(String[] args) {
// ReadWordTable readWordTable = new com.adc.da.lawss.common.ReadWordTable();
//
// try (FileInputStream fileInputStream = new FileInputStream("E:\\下载\\table1.docx");
// XWPFDocument document = new XWPFDocument(fileInputStream);) {
// List<XWPFTable> tables = document.getTables();
// for (XWPFTable table : tables) {
// System.out.println(readWordTable.readTable(table));
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}
-1
View File
@@ -54,7 +54,6 @@
<!-- 单体应用启动类 -->
<module>jero-boot-single-startup</module>
<module>jero-boot-modules</module>
<module>jreo-boot-split</module>
<module>jero-boot-center</module>
</modules>