@ -67,7 +67,6 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
} catch ( InterruptedException e ) {
} catch ( InterruptedException e ) {
Thread . currentThread ( ) . interrupt ( ) ;
Thread . currentThread ( ) . interrupt ( ) ;
log . info ( "线程池中断异常" ) ;
log . info ( "线程池中断异常" ) ;
/ / 中断异常先不做处理
}
}
}
}
@ -167,7 +166,6 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
/ / 创建一个list用来存储所有的txt文件路径
/ / 创建一个list用来存储所有的txt文件路径
List < String > txtName = new ArrayList < > ( ) ;
List < String > txtName = new ArrayList < > ( ) ;
for ( String file : excelFiles ) {
for ( String file : excelFiles ) {
/ / 找到 . 的索引
/ / 找到 . 的索引
int dotIndex = file . lastIndexOf ( "." ) ;
int dotIndex = file . lastIndexOf ( "." ) ;
String s = file . substring ( dotIndex + 1 ) ;
String s = file . substring ( dotIndex + 1 ) ;
@ -204,7 +202,8 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
/ / txt ( tff ) 不为空就做新增
/ / txt ( tff ) 不为空就做新增
if ( CollectionUtils . isNotEmpty ( tffName ) ) {
if ( CollectionUtils . isNotEmpty ( tffName ) ) {
List < EquipmentDataDetail > equipmentDataDetails = saveTxt ( tffName , excel , batchNo ) ;
String timestamp1 = String . valueOf ( System . currentTimeMillis ( ) ) ;
List < EquipmentDataDetail > equipmentDataDetails = saveTxt ( tffName , excel , batchNo , timestamp1 ) ;
/ / 新增数据
/ / 新增数据
saveInformation ( equipmentDataDetails ) ;
saveInformation ( equipmentDataDetails ) ;
for ( String s : tffName ) {
for ( String s : tffName ) {
@ -212,21 +211,22 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
/ / 找到 \ \ 的最后索引
/ / 找到 \ \ 的最后索引
int dotIndex = s . lastIndexOf ( "\\" ) ;
int dotIndex = s . lastIndexOf ( "\\" ) ;
String name = s . substring ( dotIndex + 1 ) ;
String name = s . substring ( dotIndex + 1 ) ;
String timestamp1 = String . valueOf ( System . currentTimeMillis ( ) ) ;
deleteBypath ( s , excel . getBackupFolderPath ( ) , index + timestamp1 + "$" + name ) ;
deleteBypath ( s , excel . getBackupFolderPath ( ) , index + timestamp1 + "$" + name ) ;
index + + ;
index + + ;
}
}
}
}
/ / txt文件不为空就做新增
/ / txt文件不为空就做新增
if ( CollectionUtils . isNotEmpty ( txtName ) ) {
if ( CollectionUtils . isNotEmpty ( txtName ) ) {
List < EquipmentDataDetail > equipmentDataDetails1 = saveTxtFile ( txtName , excel , batchNo ) ;
String timestamp1 = String . valueOf ( System . currentTimeMillis ( ) ) ;
List < EquipmentDataDetail > equipmentDataDetails1 = saveTxtFile ( txtName , excel , batchNo , timestamp1 ) ;
saveInformation ( equipmentDataDetails1 ) ;
saveInformation ( equipmentDataDetails1 ) ;
for ( String s : txtName ) {
for ( String s : txtName ) {
int index = 1 ;
/ / 找到 \ \ 的最后索引
/ / 找到 \ \ 的最后索引
int dotIndex = s . lastIndexOf ( "\\" ) ;
int dotIndex = s . lastIndexOf ( "\\" ) ;
String name = s . substring ( dotIndex + 1 ) ;
String name = s . substring ( dotIndex + 1 ) ;
String timestamp1 = String . valueOf ( System . currentTimeMillis ( ) ) ;
deleteBypath ( s , excel . getBackupFolderPath ( ) , timestamp1 + "$" + name ) ;
deleteBypath ( s , excel . getBackupFolderPath ( ) , index + timestamp1 + "$" + name ) ;
index + + ;
}
}
}
}
}
}
@ -267,16 +267,10 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
/ / 对tff文件进行操作
/ / 对tff文件进行操作
private List < EquipmentDataDetail > saveTxt ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo ) {
private List < EquipmentDataDetail > saveTxt ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo , String timestamp1 ) {
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
/ / / / 查询EquipmentFolderDetail表 , 判断是否对添加的值进行校验判断是否insert
/ / LambdaQueryWrapper < EquipmentFolderDetailEntity > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
/ / lambdaQueryWrapper . eq ( EquipmentFolderDetailEntity : : getBuNo , excel . getBuNo ( ) )
/ / . eq ( EquipmentFolderDetailEntity : : getSite , excel . getSite ( ) )
/ / . eq ( EquipmentFolderDetailEntity : : getEquipmentNo , excel . getEquipmentNo ( ) ) ;
/ / List < EquipmentFolderDetailEntity > entityList = equipmentFolderDetailService . list ( lambdaQueryWrapper ) ;
int index = 1 ;
int index = 1 ;
int group = 1 ;
for ( String s : fileName ) {
for ( String s : fileName ) {
int startLine = 15 ; / / 第一次读取开始的行数
int startLine = 15 ; / / 第一次读取开始的行数
int firstReadLines = 41 ;
int firstReadLines = 41 ;
@ -317,6 +311,14 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
}
}
/ / 获取复制之后的文件路径
/ / 找到 \ \ 的最后索引
int num = 1 ;
int dotIndex = s . lastIndexOf ( "\\" ) ;
String name = s . substring ( dotIndex + 1 ) ;
String file = excel . getBackupFolderPath ( ) + "\\" + num + timestamp1 + "$" + name ;
num + + ;
/ / 对数据进行切割封装
/ / 对数据进行切割封装
for ( String info : list ) {
for ( String info : list ) {
String [ ] data = info . split ( "\t" ) ;
String [ ] data = info . split ( "\t" ) ;
@ -329,6 +331,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
equipmentDataDetail . setFileNo ( excel . getFileNo ( ) ) ;
equipmentDataDetail . setFileNo ( excel . getFileNo ( ) ) ;
equipmentDataDetail . setCreateDate ( new Date ( ) ) ;
equipmentDataDetail . setCreateDate ( new Date ( ) ) ;
equipmentDataDetail . setValue0 ( data [ 0 ] ) ;
equipmentDataDetail . setValue0 ( data [ 0 ] ) ;
if ( data . length > 1 ) {
if ( data . length > 1 ) {
equipmentDataDetail . setValue1 ( data [ 1 ] ) ;
equipmentDataDetail . setValue1 ( data [ 1 ] ) ;
}
}
@ -356,7 +359,13 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
if ( data . length > 9 ) {
if ( data . length > 9 ) {
equipmentDataDetail . setValue9 ( data [ 9 ] ) ;
equipmentDataDetail . setValue9 ( data [ 9 ] ) ;
}
}
equipmentDataDetail . setGroupValue ( group ) ;
if ( StringUtils . equals ( data [ 0 ] , "1000.000" ) ) {
group + + ;
}
equipmentDataDetail . setNum ( index ) ;
equipmentDataDetail . setNum ( index ) ;
equipmentDataDetail . setFileValue1 ( file ) ;
equipmentDataDetails . add ( equipmentDataDetail ) ;
equipmentDataDetails . add ( equipmentDataDetail ) ;
index + + ;
index + + ;
}
}
@ -586,13 +595,6 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
/ / 对excel ( csv ) 文件进行操作
/ / 对excel ( csv ) 文件进行操作
public List < EquipmentDataDetail > saveExcel ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo , String timestamp1 ) {
public List < EquipmentDataDetail > saveExcel ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo , String timestamp1 ) {
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
/ / 查询EquipmentFolderDetail表 , 判断是否对添加的值进行校验判断是否insert
LambdaQueryWrapper < EquipmentFolderDetailEntity > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . eq ( EquipmentFolderDetailEntity : : getBuNo , excel . getBuNo ( ) )
. eq ( EquipmentFolderDetailEntity : : getSite , excel . getSite ( ) )
. eq ( EquipmentFolderDetailEntity : : getEquipmentNo , excel . getEquipmentNo ( ) ) ;
List < EquipmentFolderDetailEntity > entityList = equipmentFolderDetailService . list ( lambdaQueryWrapper ) ;
/ / 获取每个excel下的所有关于Test的两个值并保存
/ / 获取每个excel下的所有关于Test的两个值并保存
int index = 1 ;
int index = 1 ;
for ( String s : fileName ) {
for ( String s : fileName ) {
@ -686,7 +688,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
/ / 对txt文件进行操作
/ / 对txt文件进行操作
public List < EquipmentDataDetail > saveTxtFile ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo ) {
public List < EquipmentDataDetail > saveTxtFile ( List < String > fileName , EquipmentFolderLocation excel , Integer batchNo , String timestamp1 ) {
int index = 1 ;
int index = 1 ;
List < EquipmentDataDetail > detailList = new ArrayList < > ( ) ;
List < EquipmentDataDetail > detailList = new ArrayList < > ( ) ;
/ / 查询EquipmentFolderDetail表 , 判断是否对添加的值进行校验判断是否insert
/ / 查询EquipmentFolderDetail表 , 判断是否对添加的值进行校验判断是否insert
@ -712,6 +714,13 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
}
}
/ / 获取复制之后的文件路径
/ / 找到 \ \ 的最后索引
int num = 1 ;
int dotIndex = name . lastIndexOf ( "\\" ) ;
String byName = name . substring ( dotIndex + 1 ) ;
String file = excel . getBackupFolderPath ( ) + "\\" + num + timestamp1 + "$" + byName ;
num + + ;
for ( String s : list ) {
for ( String s : list ) {
EquipmentDataDetail equipmentDataDetail = new EquipmentDataDetail ( ) ;
EquipmentDataDetail equipmentDataDetail = new EquipmentDataDetail ( ) ;
@ -733,9 +742,8 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
if ( data . length > 3 ) {
if ( data . length > 3 ) {
equipmentDataDetail . setValue3 ( data [ 3 ] ) ;
equipmentDataDetail . setValue3 ( data [ 3 ] ) ;
}
}
equipmentDataDetail . setNum ( index ) ;
equipmentDataDetail . setNum ( index ) ;
equipmentDataDetail . setFileValue1 ( file ) ;
detailList . add ( equipmentDataDetail ) ;
detailList . add ( equipmentDataDetail ) ;
index + + ;
index + + ;
}
}
@ -856,9 +864,9 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
} else {
} else {
/ / 创建一个固定大小的线程池 , 这里假设有10个线程
/ / 创建一个固定大小的线程池 , 这里假设有10个线程
ExecutorService executor = Executors . newFixedThreadPool ( equipmentDataDetails . size ( ) / 10 0) ;
ExecutorService executor = Executors . newFixedThreadPool ( equipmentDataDetails . size ( ) / 8 0) ;
int startList = 0 ;
int startList = 0 ;
int endList = 10 0;
int endList = 8 0;
for ( int i = startList ; i < equipmentDataDetails . size ( ) ; i = startList ) {
for ( int i = startList ; i < equipmentDataDetails . size ( ) ; i = startList ) {
if ( endList > equipmentDataDetails . size ( ) ) {
if ( endList > equipmentDataDetails . size ( ) ) {
@ -869,8 +877,8 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
/ / 批量新增
/ / 批量新增
getInformationForExcelMapper . saveByExcels ( details ) ;
getInformationForExcelMapper . saveByExcels ( details ) ;
} ) ;
} ) ;
startList = startList + 10 0;
endList = endList + 10 0;
startList = startList + 8 0;
endList = endList + 8 0;
}
}
executor . shutdown ( ) ;
executor . shutdown ( ) ;
try {
try {