xuhy
2023-08-11 1172de622b5e615677918d4fa0f02a9b2766171c
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.OrderPositionMapper;
import com.stylefeng.guns.modular.system.model.OrderPosition;
import com.stylefeng.guns.modular.system.service.IOrderPositionService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class OrderPositionServiceImpl extends ServiceImpl<OrderPositionMapper, OrderPosition> implements IOrderPositionService {
 
    @Resource
    private OrderPositionMapper orderPositionMapper;
 
    @Value("${filePath}")
    private String filePath;
 
 
    /**
     * 获取轨迹数据
     * @param orderId
     * @param orderType
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryTrack(Integer orderId, Integer orderType) throws Exception {
//        return orderPositionMapper.queryTrack(orderId, orderType);
        //将数据存储到文件中
        File file = new File(filePath + orderId + "_" + orderType + ".txt");
        if(!file.exists()){
            return new ArrayList<>();
        }
        //读取文件(字符流)
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
        //循环取出数据
        String str = null;
        StringBuffer sb = new StringBuffer();
        while ((str = in.readLine()) != null) {
            sb.append(str);
        }
        List<OrderPosition> list = JSONArray.parseArray(sb.toString(), OrderPosition.class);
        List<Map<String, Object>> lonlat = new ArrayList<>();
        for(OrderPosition orderPosition : list){
            Map<String, Object> map = new HashMap<>();
            map.put("lon", orderPosition.getLon());
            map.put("lat", orderPosition.getLat());
            lonlat.add(map);
        }
        return lonlat;
    }
 
 
 
    /**
     * 获取坐标文件中的坐标数据
     * @param orderId
     * @param orderType
     * @return
     * @throws Exception
     */
    @Override
    public List<OrderPosition> queryPosition(Integer orderId, Integer orderType) throws Exception{
        //将数据存储到文件中
        File file = new File(filePath + orderId + "_" + orderType + ".txt");
        if(!file.exists()){
            return new ArrayList<>();
        }
        //读取文件(字符流)
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
        //循环取出数据
        String str = null;
        StringBuffer sb = new StringBuffer();
        while ((str = in.readLine()) != null) {
            sb.append(str);
        }
        List<OrderPosition> list = new ArrayList<>();
        if(ToolUtil.isNotEmpty(sb.toString())){
            list = JSONArray.parseArray(sb.toString(), OrderPosition.class);
        }
        System.err.println("坐标:" + sb);
        return list;
    }
}