@ -2,6 +2,7 @@ package com.xujie.sys.modules.reader.service.impl;
import com.alibaba.excel.EasyExcel ;
import com.alibaba.excel.support.ExcelTypeEnum ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.xujie.sys.modules.reader.dao.GetInformationForExcelMapper ;
import com.xujie.sys.modules.reader.entity.EquipmentDataDetail ;
@ -59,16 +60,36 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
private void saveInformation ( String folderFiler , EquipmentFolderLocation excel ) {
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
/ / 获取文件夹下所有文件
List < File > files = getExcelFiles ( folderFiler ) ;
if ( CollectionUtils . isEmpty ( files ) ) {
return ;
}
/ / 判断这个批次号应该是多少
LambdaQueryWrapper < EquipmentDataDetail > queryWrapper = new LambdaQueryWrapper < > ( ) ;
queryWrapper . eq ( EquipmentDataDetail : : getBuNo , excel . getBuNo ( ) ) ;
queryWrapper . eq ( EquipmentDataDetail : : getSite , excel . getSite ( ) ) ;
queryWrapper . eq ( EquipmentDataDetail : : getFileNo , excel . getFileNo ( ) ) ;
List < EquipmentDataDetail > equipments = this . list ( queryWrapper ) ;
/ / 定义批次号
Integer batchNo ;
if ( CollectionUtils . isEmpty ( equipments ) ) {
batchNo = 1 ;
} else {
batchNo = equipments . get ( equipments . size ( ) - 1 ) . getBatchNo ( ) + 1 ;
}
List < EquipmentDataDetail > equipmentDataDetails = new ArrayList < > ( ) ;
/ / 创建一个list用来存储所有的的excel文件路径
List < String > fileName = new ArrayList < > ( ) ;
for ( File file : files ) {
fileName . add ( folderFiler + "\\" + file . getName ( ) ) ;
/ / 找到 . 的索引
int dotIndex = file . getName ( ) . lastIndexOf ( "." ) ;
String s = file . getName ( ) . substring ( dotIndex + 1 ) ;
if ( s . equals ( "csv" ) ) {
fileName . add ( folderFiler + "\\" + file . getName ( ) ) ;
}
}
/ / 获取每个excel下的所有关于Test的两个值并保存
for ( String s : fileName ) {
@ -90,7 +111,9 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
equipmentDataDetail . setEquipmentNo ( excel . getEquipmentNo ( ) ) ;
equipmentDataDetail . setBuNo ( excel . getBuNo ( ) ) ;
equipmentDataDetail . setSite ( excel . getSite ( ) ) ;
equipmentDataDetail . setBatchNo ( batchNo ) ;
equipmentDataDetail . setItemNo ( excel . getItemNo ( ) ) ;
equipmentDataDetail . setFileNo ( excel . getFileNo ( ) ) ;
equipmentDataDetail . setValue0 ( list . get ( i ) . get ( 1 ) ) ;
equipmentDataDetail . setValue1 ( list . get ( i ) . get ( 3 ) ) ;
equipmentDataDetails . add ( equipmentDataDetail ) ;
@ -107,7 +130,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
/ / 获取本地文件夹下所有excel表格
File [ ] files = file . listFiles ( ) ;
List < File > excelFiles = new ArrayList < > ( ) ;
if ( file ! = null ) {
if ( file ! = null ) {
for ( File file1 : files ) {
if ( file1 . isFile ( ) ) {
excelFiles . add ( file1 ) ;