霍林河露天煤矿生产一体化平台
1
13693261870
2023-04-10 dd50418315218979f8d596f34f185ae4a28adc4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.terra.coal.service;
 
import com.terra.coal.entity.Coal54Entity;
import com.terra.coal.entity.CountEntity;
import com.terra.coal.entity.StaticData;
import com.terra.coal.helper.StringHelper;
import com.terra.coal.mapper.Coal54Mapper;
import com.terra.coal.mapper.MainMapper;
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
 * @author WWW
 */
@Service
public class MainService implements MainMapper {
    @Autowired
    MainMapper mainMapper;
 
    @Autowired
    Coal54Mapper coal54Mapper;
 
    @Override
    public List<CountEntity> countByRange(String wkt, double top, double bottom) {
        return mainMapper.countByRange(wkt, top, bottom);
    }
 
    /**
     * 加载54数据(入库)
     */
    public Integer load54Data(File f) throws IOException {
        FileReader fr = new FileReader(f);
        BufferedReader reader = new BufferedReader(fr);
 
        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;
        }
    }
}