|
@ -10,11 +10,11 @@ import cn.hutool.json.JSONUtil; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.ExcelReader; |
|
|
import com.alibaba.excel.ExcelReader; |
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
|
|
import com.alibaba.excel.exception.ExcelAnalysisStopException; |
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
|
|
|
import com.alibaba.excel.read.metadata.holder.ReadRowHolder; |
|
|
import com.alibaba.excel.util.ListUtils; |
|
|
import com.alibaba.excel.util.ListUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.aspose.cells.Cell; |
|
|
import com.aspose.cells.Cell; |
|
|
import com.aspose.cells.Cells; |
|
|
import com.aspose.cells.Cells; |
|
|
import com.aspose.cells.Workbook; |
|
|
import com.aspose.cells.Workbook; |
|
@ -40,20 +40,16 @@ import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper; |
|
|
import org.dromara.easyes.core.core.BaseEsMapper; |
|
|
import org.dromara.easyes.core.core.BaseEsMapper; |
|
|
import org.dromara.easyes.core.core.EsWrappers; |
|
|
import org.dromara.easyes.core.core.EsWrappers; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.StandardCopyOption; |
|
|
import java.nio.file.StandardCopyOption; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.function.Function; |
|
|
import java.util.function.Function; |
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
import org.apache.xmlbeans.XmlException; |
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
@ -234,7 +230,7 @@ public class ImportServiceImpl implements ImportService { |
|
|
* 一个excel里多个人流水,重复表头 |
|
|
* 一个excel里多个人流水,重复表头 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public <T> void readMultiplePersonAndMultipleHeadBankStatement(String excelFileName, int headRowNumber, int sheetNo, Class<T> clazz, BaseEsMapper<T> baseEsMapper, |
|
|
|
|
|
|
|
|
public <T>void readMultiplePersonAndMultipleHeadBankStatement(String excelFileName, int headRowNumber,Integer endRow, int sheetNo, Class<T> clazz, BaseEsMapper<T> baseEsMapper, |
|
|
String cardHolderName, String sourceFile, |
|
|
String cardHolderName, String sourceFile, |
|
|
List<HeadField> headFields) { |
|
|
List<HeadField> headFields) { |
|
|
ReadDto readDto = new ReadDto(); |
|
|
ReadDto readDto = new ReadDto(); |
|
@ -245,7 +241,7 @@ public class ImportServiceImpl implements ImportService { |
|
|
readDto.setEsMapper(baseEsMapper); |
|
|
readDto.setEsMapper(baseEsMapper); |
|
|
readDto.setCardHolderName(cardHolderName); |
|
|
readDto.setCardHolderName(cardHolderName); |
|
|
readDto.setSourceFile(sourceFile); |
|
|
readDto.setSourceFile(sourceFile); |
|
|
|
|
|
|
|
|
|
|
|
readDto.setEndRow(endRow); |
|
|
//过滤中途的表头行 |
|
|
//过滤中途的表头行 |
|
|
readDto.setHeadFields(headFields); |
|
|
readDto.setHeadFields(headFields); |
|
|
readDto.setReadListener(readMultiplePersonAndMultipleHeadBankStatementReadListener(readDto)); |
|
|
readDto.setReadListener(readMultiplePersonAndMultipleHeadBankStatementReadListener(readDto)); |
|
@ -309,9 +305,12 @@ public class ImportServiceImpl implements ImportService { |
|
|
List<T> cacheList = ListUtils.newArrayListWithExpectedSize( Constants.BATCH_SIZE); |
|
|
List<T> cacheList = ListUtils.newArrayListWithExpectedSize( Constants.BATCH_SIZE); |
|
|
BaseEsMapper<T> esMapper = readDto.getEsMapper(); |
|
|
BaseEsMapper<T> esMapper = readDto.getEsMapper(); |
|
|
Class<T> headClass = readDto.getHeadClass(); |
|
|
Class<T> headClass = readDto.getHeadClass(); |
|
|
|
|
|
// int startRow = start; |
|
|
|
|
|
final Integer endRow = readDto.getEndRow(); |
|
|
@Override |
|
|
@Override |
|
|
public void invoke(T data, AnalysisContext context) { |
|
|
public void invoke(T data, AnalysisContext context) { |
|
|
|
|
|
|
|
|
|
|
|
ReadRowHolder readRowHolder = context.readRowHolder(); |
|
|
|
|
|
Integer rowIndex = readRowHolder.getRowIndex();//从0开始 |
|
|
String str = JSONUtil.toJsonStr(data); |
|
|
String str = JSONUtil.toJsonStr(data); |
|
|
JSONObject obj = JSONUtil.parseObj(str); |
|
|
JSONObject obj = JSONUtil.parseObj(str); |
|
|
|
|
|
|
|
@ -332,6 +331,8 @@ public class ImportServiceImpl implements ImportService { |
|
|
if (skip) { |
|
|
if (skip) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(StrUtil.isNotEmpty(readDto.getCardHolderName())){ |
|
|
if(StrUtil.isNotEmpty(readDto.getCardHolderName())){ |
|
|
obj.put("cardHolderName", readDto.getCardHolderName()); |
|
|
obj.put("cardHolderName", readDto.getCardHolderName()); |
|
|
} |
|
|
} |
|
@ -341,6 +342,12 @@ public class ImportServiceImpl implements ImportService { |
|
|
obj.put("id", IdUtil.objectId()); |
|
|
obj.put("id", IdUtil.objectId()); |
|
|
cacheList.add(obj.toBean(headClass)); |
|
|
cacheList.add(obj.toBean(headClass)); |
|
|
|
|
|
|
|
|
|
|
|
if (endRow != null && rowIndex+1 >= endRow) { |
|
|
|
|
|
esMapper.insertBatch(cacheList); |
|
|
|
|
|
cacheList.clear(); |
|
|
|
|
|
throw new ExcelAnalysisStopException("读完一段了"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (cacheList.size() >= Constants.BATCH_SIZE) { |
|
|
if (cacheList.size() >= Constants.BATCH_SIZE) { |
|
|
esMapper.insertBatch(cacheList); |
|
|
esMapper.insertBatch(cacheList); |
|
|
cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE); |
|
|
cacheList = ListUtils.newArrayListWithExpectedSize(Constants.BATCH_SIZE); |
|
|