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 | 76 +++++++++++++++++++++++++++++++++++++- 1 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/main/java/service/MainService.java b/src/main/java/service/MainService.java index 34b3f24..2e0848f 100644 --- a/src/main/java/service/MainService.java +++ b/src/main/java/service/MainService.java @@ -1,8 +1,20 @@ package service; +import com.alibaba.druid.support.spring.stat.annotation.Stat; +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; import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; /** * CoalService @@ -10,9 +22,69 @@ */ @Service public class MainService { - public Integer load54Data(File f){ + @Autowired + Coal54Mapper coal54Mapper; + /** + * 鍔犺浇54鏁版嵁(鍏ュ簱) + */ + public Integer load54Data(File f) throws IOException { + FileReader fr = new FileReader(f); + BufferedReader reader = new BufferedReader(fr); - return 0; + int rows = 0, cc = 0; + String line = reader.readLine(); + List<Coal54Entity> list = new ArrayList<>(); + while (null != line) { + 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(); + + if (list.size() > 0) { + rows += coal54Mapper.insertBatch(list); + list.clear(); + } + + return rows; + } + + private Coal54Entity getCoal54(String str) { + if (StringHelper.isEmpty(str)) { + return null; + } + + String[] strs = str.split(","); + if (strs.length < StaticData.NINE) { + return null; + } + + // 36240.00000,-69460.00000,634.00000,1280.000,1280.000,128.000,宀╃煶,1,1, + try { + BigDecimal x = new BigDecimal("4" + strs[1].replace("-", "")); + BigDecimal y = new BigDecimal("50" + strs[0]); + BigDecimal top = new BigDecimal(strs[2]); + BigDecimal clong = new BigDecimal(strs[3]); + BigDecimal width = new BigDecimal(strs[4]); + BigDecimal height = new BigDecimal(strs[5]); + String ctype = strs[6]; + BigDecimal density = new BigDecimal(strs[7]); + BigDecimal gangue = new BigDecimal(strs[8]); + + return new Coal54Entity(x, y, top, clong, width, height, ctype, density, gangue); + } catch (Exception ex) { + return null; + } } } -- Gitblit v1.9.3