From a51147871c8e862d4882f4087171b8d25e743ebd Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 07 四月 2023 15:07:11 +0800 Subject: [PATCH] 1 --- src/main/java/service/MainService.java | 22 ++++++++++++++++++---- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/service/MainService.java b/src/main/java/service/MainService.java index 8dbf393..2e0848f 100644 --- a/src/main/java/service/MainService.java +++ b/src/main/java/service/MainService.java @@ -4,6 +4,8 @@ import com.terra.coal.entity.Coal54Entity; import com.terra.coal.entity.StaticData; import com.terra.coal.helper.StringHelper; +import com.terra.coal.mapper.Coal54Mapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.BufferedReader; @@ -20,6 +22,9 @@ */ @Service public class MainService { + @Autowired + Coal54Mapper coal54Mapper; + /** * 鍔犺浇54鏁版嵁(鍏ュ簱) */ @@ -27,23 +32,32 @@ FileReader fr = new FileReader(f); BufferedReader reader = new BufferedReader(fr); - int rows = 0; + int rows = 0, cc = 0; String line = reader.readLine(); List<Coal54Entity> list = new ArrayList<>(); while (null != line) { - rows++; - if (rows > 2) { + cc++; + if (cc > 2) { Coal54Entity entity = getCoal54(line); if (null != entity) { list.add(entity); } + } + if (list.size() > 99) { + rows += coal54Mapper.insertBatch(list); + list.clear(); } line = reader.readLine(); } reader.close(); - return 0; + if (list.size() > 0) { + rows += coal54Mapper.insertBatch(list); + list.clear(); + } + + return rows; } private Coal54Entity getCoal54(String str) { -- Gitblit v1.9.3