智慧保安后台管理-外网项目备份
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package org.springblade.modules.location.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csvreader.CsvReader;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import liquibase.pro.packaged.E;
import liquibase.pro.packaged.S;
import lombok.AllArgsConstructor;
import net.sf.json.JSONArray;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springblade.common.utils.DowloadZipUtil;
import org.springblade.common.utils.FileZip;
import org.springblade.common.utils.HttpReqUtil;
import org.springblade.common.utils.Md5SignUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.equipage.service.CarService;
import org.springblade.modules.location.entity.Locus;
import org.springblade.modules.location.service.LocusService;
import org.springblade.modules.location.vo.LocusVo;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.service.MyAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
 
import static org.springblade.common.config.FtpConfig.localPath;
 
/**
 * @author zhongrj
 * @time 2021-07-06
 * @desc 轨迹管理控制层
 */
@RestController
@AllArgsConstructor
@RequestMapping("/locus")
public class LocusController {
 
    private final LocusService locusService;
    private final CarService carService;
    private IUserService userService;
    private final MyAsyncService myAsyncService;
 
    /**
     * 自定义分页
     *
     * @param query page,size
     * @param locus 轨迹信息对象
     */
    @GetMapping("/page")
    public R<IPage<LocusVo>> page(LocusVo locus, Query query) {
        IPage<LocusVo> pages = locusService.selectLocusPage(Condition.getPage(query), locus);
        return R.data(pages);
    }
 
    /**
     * 新增
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "传入locus")
    public R save(@RequestBody Locus locus) {
        return R.status(locusService.save(locus));
    }
 
    /**
     * 修改
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/update")
    public R update(@RequestBody Locus locus) {
        return R.status(locusService.updateById(locus));
    }
 
    /**
     * 新增或修改
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/submit")
    public R submit(@RequestBody Locus locus) {
        return R.status(locusService.saveOrUpdate(locus));
    }
 
    /**
     * 删除
     *
     * @param ids 轨迹信息ids 数组
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
        return R.status(locusService.removeByIds(Func.toLongList(ids)));
    }
 
    /**
     * 详情
     *
     * @param locus 轨迹信息对象
     */
    @GetMapping("/detail")
    @ApiOperation(value = "详情", notes = "传入locus")
    public R<LocusVo> detail(Locus locus) {
        LocusVo detail = locusService.selectLocusInfo(locus);
        return R.data(detail);
    }
 
    /**
     * 查询车辆轨迹
     */
    @GetMapping("/locationhistoryTrack")
    public void locationhistoryTrack() {
        String url = "http://dvopenapi.aimap.net.cn/openapi/device/historyTrack";
        String res = null;
        List<Map<Object, Object>> maps = carService.selectCar();
        for (int i = 0; i < maps.size(); i++) {
            Map<String, Object> params = new HashMap<>();
            params.put("imei", maps.get(i).get("code").toString());
            params.put("beginTime", "2021112510");
            params.put("endTime", "2021112511");
            params.put("rectify", 0);
            params.put("callbackUrl", "http://2h3f861221.wicp.vip/locus/SaveUrl");
            params.put("callbackId", maps.get(i).get("carnumber").toString());
            params.put("appId", "PO00000761");
            params.put("timestamp", System.currentTimeMillis());
            String secert = "dXRGb2pRNVdWOGQ3d1ouV29UYzc1MnJaUnBwTzUx";
            String computeSign = "";
            try {
                computeSign = Md5SignUtil.signRequest(params, secert);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            params.put("sign", computeSign);
            try {
                res = HttpReqUtil.getInstance().doPost(url, params, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
    }
 
    /**
     * 轨迹回调
     *
     * @param callbackId
     * @param fileUrl
     */
    @PostMapping("/SaveUrl")
    @ApiOperation(value = "详情", notes = "传入car")
    public void SaveUrl(String callbackId, String fileUrl) throws Exception {
        DowloadZipUtil dowloadZipUtil = new DowloadZipUtil();
        File file = dowloadZipUtil.downloadFile(fileUrl, "/usr/local/nginx/dist/enterprises/car");
        //文件名
        String name = file.getName();
        String substring = name.substring(0, name.length() - 4);
        //解压数据
        FileZip fileZip = new FileZip();
        fileZip.ZipUncompress("/usr/local/nginx/dist/enterprises/car/" + substring + ".zip", "/usr/local/nginx/dist/enterprises/car");
        try {
            // 用来保存数据
            ArrayList<String[]> csvFileList = new ArrayList<String[]>();
            // 定义一个CSV路径
            String csvFilePath = "/usr/local/nginx/dist/enterprises/car/" + substring + ".csv";
            // 创建CSV读对象 例如:CsvReader(文件路径,分隔符,编码格式);
            CsvReader reader = new CsvReader(csvFilePath, ',', Charset.forName("UTF-8"));
            // 跳过表头 如果需要表头的话,这句可以忽略
            reader.readHeaders();
            // 逐行读入除表头的数据
            while (reader.readRecord()) {
                csvFileList.add(reader.getValues());
            }
            reader.close();
            Locus locus = new Locus();
            String s1 = "";
            if (csvFileList.size() != 0) {
                //遍历读取的CSV文件
                for (int row = 0; row < csvFileList.size(); row++) {
                    // 取得第row行第0列的数据
                    String cell = csvFileList.get(row)[0];
                    String cell1 = csvFileList.get(row)[1];
                    String cell2 = csvFileList.get(row)[2];
                    Date date = timeStamp2Date(cell2);
                    locus.setType(2);
                    locus.setLongitude(cell);
                    locus.setLatitude(cell1);
                    locus.setRecordTime(date);
                    locus.setWorkerId(callbackId);
                    locusService.save(locus);
                    //数据推送
                    s1 +=
                        "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) " +
                            "values(" + "'" + locus.getId() + "'" + "," +
                            "'" + locus.getType() + "'" + "," +
                            "'" + locus.getWorkerId() + "'" + "," +
                            "'" + locus.getLongitude() + "'" + "," +
                            "'" + locus.getLatitude() + "'" + "," +
                            "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
                    if (row != csvFileList.size() - 1) {
                        s1 += ";";
                    }
                }
                //FtpUtil.sqlFileUpload(s1);
                myAsyncService.dataSync(s1);
                deletescsv(substring);
            }
            deletescsv(substring);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    public static Date timeStamp2Date(String time) {
        Long timeLong = Long.parseLong(time);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
        Date date;
        try {
            date = sdf.parse(sdf.format(timeLong));
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
 
    }
 
//    @PostMapping("/ss")
//    public void Peog() throws Exception {
//        String url = "http://47.104.104.46/api/client/getgistrack.php";
//        Calendar calendar = Calendar.getInstance();
//        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
//        //查询有押运人员的数据
//        List<Map<String, Object>> list = userService.selectEquipent();
//        for (int i = 0; i < list.size(); i++) {
//            //实时位置实体类
//            Locus locus = new Locus();
//            locus.setType(1);
//            String id = list.get(i).get("id").toString();
//            locus.setWorkerId(id);
//            Map<String, Object> params = new HashMap<>();
//            String equipmentCode = list.get(i).get("code").toString();
//            //设备imei号
//            params.put("number", 7730);
//            params.put("acc", equipmentCode);
//            params.put("startTime", "2021-12-01");
//            params.put("endTime", "2021-12-02");
//            String res = null;
//            res = HttpReqUtil.getInstance().doPost(url, params, null);
//            String a = "[" + res + "]";
//            JSONArray jsonArray = JSONArray.fromObject(a);
//            String track = jsonArray.getJSONObject(0).get("track").toString();
//            JSONArray jsonArray1 = JSONArray.fromObject(track);
//            String s1 = "";
//            for (int j = 0; j < jsonArray1.size(); j++) {
//                String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
//                String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
//                String date = jsonArray1.getJSONObject(j).get("date").toString();
//                SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                try {
//                    //使用SimpleDateFormat的parse()方法生成Date
//                    Date dates = sf.parse(date);
//                    locus.setRecordTime(dates);
//                    //打印Date
//                } catch (ParseException e) {
//                    e.printStackTrace();
//                }
//                locus.setLongitude(gis_jd);
//                locus.setLatitude(gis_wd);
//                locusService.save(locus);
//                //数据推送
//                s1 += "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values" +
//                    " (" + "'" + locus.getId() + "'" + "," +
//                    "'" + locus.getType() + "'" + "," +
//                    "'" + locus.getWorkerId() + "'" + "," +
//                    "'" + locus.getLongitude() + "'" + "," +
//                    "'" + locus.getLatitude() + "'" + "," +
//                    "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
//                if (j != jsonArray1.size() - 1) {
//                    s1 += ";";
//                }
//            }
//            FtpUtil.sqlFileUpload(s1);
//        }
//    }
 
 
    /**
     * 删除本地csv文件
     *
     * @param fileName
     */
    public static void deletescsv(String fileName) {
        File file = new File("D:\\caiji\\" + fileName + ".csv");
        if (file.isFile() && file.exists()) {
            file.delete();
        }
    }
 
 
}