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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
package com.moral.controller;
 
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.moral.common.bean.ResultBean;
import com.moral.common.exception.WebAuthException;
import com.moral.common.util.*;
import com.moral.common.webAnno.UserLoginToken;
import com.moral.entity.*;
import com.moral.mapper.MapPathMapper;
import com.moral.service.*;
import com.moral.util.DateUtil;
import com.moral.util.LatLngTransformation;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
import static com.moral.common.util.WebUtils.getParametersStartingWith;
 
@RestController
@RequestMapping("/web")
@CrossOrigin(origins = "*", maxAge = 3600)
@SuppressWarnings({"rawtypes", "unchecked", "unused"})
public class WebController {
 
    private static Map<String, Sensor> sensors;
 
    @PostConstruct
    public void init() {
        sensors = new HashMap<>();
        List<Sensor> allSensors = sensorService.getAllSensors();
        for (Sensor sensor : allSensors) {
            sensors.put(sensor.getSensorKey(), sensor);
        }
    }
 
    @Resource
    AccountService accountService;
    @Resource
    DictionaryDataService dictionaryDataService;
    OrganizationService organizationService;
    @Resource
    WebTokenService webTokenService;
    @Resource
    RedisHashUtil redisHashUtil;
    @Resource
    HistoryMinutelyService historyMinutelyService;
    @Resource
    MonitorPointService monitorPointService;
    @Resource
    DeviceService deviceService;
    @Resource
    HistoryFiveMinutelyService historyFiveMinutelyService;
    @Resource
    SensorService sensorService;
    @Resource
    OrganizationSensorsService organizationSensorsService;
    @Resource
    MapPathService mapPathService;
 
 
    @GetMapping("test")
    public ResultBean<List<WebProvince>> add(HttpServletRequest request) {
        String token =  request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if(ObjectUtils.isEmpty(mapPath))
            return new ResultBean<>("获取地图信息失败",ResultBean.FAIL);
        return new ResultBean<>(mapPath);
    }
 
    /**
     * @Description: 登陆接口
     * @Param: [parameters]
     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @PostMapping("login")
    public Map<String, Object> login(@RequestBody Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
            resultMap.put("msg", "用户名及密码不允许为空!");
            resultMap.put("accountId", -1);
        } else {
            resultMap = accountService.bsWebLogin(parameters);
            String accountId = String.valueOf(resultMap.get("accountId"));
            if (!accountId.equals("-1")) {
                redisHashUtil.deleteMapVal("webToken", accountId);
                resultMap.put("token", webTokenService.getToken(accountId));
            }
        }
        return resultMap;
    }
 
    /**
     * @Description: 退出接口
     * @Param: [request]
     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @UserLoginToken
    @PostMapping("logout")
    public Map<String, Object> logout(HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<>();
        String token = request.getHeader("token");
        String id = WebTokenUtils.getIdBytoken(token);
        redisHashUtil.addMapOne("webToken", String.valueOf(id), token);
        resultMap.put("msg", "退出成功!");
        return resultMap;
    }
 
    /**
     * @Description:
     * @Param: [request]
     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @UserLoginToken
    @GetMapping("getAccountInfo")
    public Map<String, Object> getAccountInfo(HttpServletRequest request) {
        String token = request.getHeader("token");
        String id = "";
        try {
            id = WebTokenUtils.getIdBytoken(token);
        } catch (JWTDecodeException e) {
            throw new WebAuthException("401,token无效");
        }
        Map<String, Object> resultMap = accountService.getAccountInfoById(id);
        Object orgId = resultMap.get("orgId");
        if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) {
            StringBuilder areaNamesBuilder = new StringBuilder("中国");
            //判断是否为本公司开发者
            if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) {
                //不是本公司开发者则获取用户所属地区
                Organization organization = organizationService.getOrganizationById((Integer) orgId);
                if (organization.getAreaNames() != null) {
                    Map<String, String> areaNameMap = BeanUtils.beanToMap(organization.getAreaNames());
                    List<String> names = areaNameMap.entrySet().stream().filter(item -> {
                        return item.getValue() != null;
                    }).map(item -> {
                        return item.getValue();
                    }).collect(Collectors.toList());
                    AreaNames areaNames = organization.getAreaNames();
                    areaNamesBuilder.append("/");
                    areaNamesBuilder.append(String.join("/", names));
                }
                // 企业用户
                if (organization.getRank() != null && organization.getRank() == 0) {
                    resultMap.put("type", "enterprise");
                } else {
                    resultMap.put("type", "government");
                }
                Number mapAreaCode = null;
                if (organization.getVillageCode() != null) {
                    mapAreaCode = organization.getVillageCode();
                } else if (organization.getTownCode() != null) {
                    mapAreaCode = organization.getTownCode();
                } else if (organization.getAreaCode() != null) {
                    mapAreaCode = organization.getAreaCode();
                } else if (organization.getCityCode() != null) {
                    mapAreaCode = organization.getCityCode();
                } else if (organization.getProvinceCode() != null) {
                    mapAreaCode = organization.getProvinceCode();
                }
                resultMap.put("mapAreaCode", mapAreaCode.toString());
            }
            resultMap.put("mapPath", areaNamesBuilder.toString());
            String accountId = String.valueOf(resultMap.get("accountId"));
            resultMap.put("token", webTokenService.getToken(accountId));
        }
        return resultMap;
    }
 
 
    /**
     * @Description: 获取传感器平均值
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               java.util.Map               <               java.lang.String               ,               java.lang.Object>>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @UserLoginToken
    @GetMapping("report_avg_datas")
    public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request)
            throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        //该方法用于判断时间是具体到年月日
        ParameterUtils.getTimeType4Time(parameters);
        Object sensorKey = parameters.remove("sensorKey");
        parameters.put("sensors", Arrays.asList(sensorKey));
        List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
        for (Map<String, Object> map : list) {
            String time = map.get("time").toString();
            time = time.substring(time.length() - 2);
            map.put("time", Integer.valueOf(time));
            if (parameters.get("type").equals("day")) {
                map.put("time", Integer.valueOf(time) + 1);
            }
            map.put("value", map.remove(sensorKey));
        }
        return new ResultBean<List<Map<String, Object>>>(list);
    }
 
    /**
     * @Description: 获取某个站点设备信息
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               com.moral.entity.MonitorPoint>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @UserLoginToken
    @GetMapping("monitorpoints-devices")
    public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request)
            throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters);
        return new ResultBean<List<MonitorPoint>>(monitorPoints);
    }
 
    /**
     * @Description: 获取坐标接口,前端用于建点
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               com.moral.entity.Device>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    /* @UserLoginToken*/
    @GetMapping("coordinates")
    public ResultBean<List<Device>> getDeviceCoordinatesAndState(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        ParameterUtils.getRegionType4RegionCode(parameters);
        return new ResultBean<List<Device>>(deviceService.queryDevice(parameters));
    }
 
    /**
     * @Description: 根据monitorId获取该站点下每一台设备具体传感器的五分钟平均值
     * @Param: []
     * @return: com.moral.common.bean.ResultBean<java.util.Map               <               java.lang.String               ,               java.lang.Object>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
 
    @GetMapping("fiveMinuteAvgData")
    public ResultBean<Map<String,Object>> getSensorFiveMinuteAvgData(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
            return ResultBean.fail("参数为null");
        String sensorKey = (String) parameters.get("sensorKey");
        Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId"));
 
        //根据monitorpointId获取该站点下所有设备mac集合
        List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        if (ObjectUtils.isEmpty(devices))
            return ResultBean.fail("站点下无设备或monitorPointId错误");
        List<String> macs = new ArrayList<>();
        devices.forEach(p -> {
            macs.add(p.getMac());
        });
 
        //根据时间和mac号集合以及传感器参数查询五分钟平均数据
        Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData();
        String time = (String) timeAndYearMonth.get("time");
        String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth");
        parameters.put("time", time);
        parameters.put("yearAndMonth", yearAndMonth);
        parameters.put("macs", macs);
        List<Map<String, Object>> datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
 
        //如果当前五分钟数据还没有插入,则提取前五分钟数据返回
        if (ObjectUtils.isEmpty(datas)) {
            time = getFiveMinuteAgoTime(time);
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
        }
        datas = insertDeviceInfo(datas, devices);
 
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer orgId = monitorPoint.getOrganizationId();
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId);
        monitorPoints.forEach(value->{
            if("国控站".equals(value.getDescription())) {
                List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude());
                Map<String,Object> controlStation = new HashMap<>();
                controlStation.put("name",value.getName());
                controlStation.put("longitude", list.get(0));
                controlStation.put("latitude", list.get(1));
                coordinate.add(controlStation);
            }
        });
 
        Map<String,Object> datasMap = new HashMap<>();
        datasMap.put("coordinate",coordinate);
        datasMap.put("device",datas);
 
        return new ResultBean<Map<String,Object>>(datasMap);
    }
 
    @GetMapping("cangzhouMIdGetAllDevice")
    public ResultBean<Map<String,Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
            return ResultBean.fail("参数为null");
        String sensorKey = (String) parameters.get("sensorKey");
        Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId"));
        MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer code = mPoint.getCityCode();
        List<Device> devices = null;
        if (code == 130900){
             devices = deviceService.getDeviceByCode();
        }else {
             devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        }
        //根据monitorpointId获取该站点下所有设备mac集合
        if (ObjectUtils.isEmpty(devices))
            return ResultBean.fail("站点下无设备或monitorPointId错误");
        List<String> macs = new ArrayList<>();
        devices.forEach(p -> {
            macs.add(p.getMac());
        });
 
        //根据时间和mac号集合以及传感器参数查询五分钟平均数据
        Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData();
        String time = (String) timeAndYearMonth.get("time");
        String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth");
        parameters.put("time", time);
        parameters.put("yearAndMonth", yearAndMonth);
        parameters.put("macs", macs);
        List<Map<String, Object>> datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
 
        //如果当前五分钟数据还没有插入,则提取前五分钟数据返回
        if (ObjectUtils.isEmpty(datas)) {
            time = getFiveMinuteAgoTime(time);
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
        }
        datas = insertDeviceInfo(datas, devices);
 
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer orgId = monitorPoint.getOrganizationId();
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId);
        monitorPoints.forEach(value->{
            if("国控站".equals(value.getDescription())) {
                List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude());
                Map<String,Object> controlStation = new HashMap<>();
                controlStation.put("name",value.getName());
                controlStation.put("longitude", list.get(0));
                controlStation.put("latitude", list.get(1));
                coordinate.add(controlStation);
            }
        });
 
        Map<String,Object> datasMap = new HashMap<>();
        datasMap.put("coordinate",coordinate);
        datasMap.put("device",datas);
 
        return new ResultBean<Map<String,Object>>(datasMap);
    }
 
    /** 
    * @Description: 根据mac号获取单台设备信息,特殊客户只显示客户需要的传感器信息
            * @Param: [request]
            * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>>
            * @Author: 下雨听风
            * @Date: 2020/10/22
            */ 
    @GetMapping("fiveMinuteAvgDataByMac")
    public ResultBean<Map<String, Object>> fiveMinuteAvgDataByMac(HttpServletRequest request) {
        //获取参数,mac号
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("mac")))
            return ResultBean.fail("参数为null");
        String mac = (String) parameters.get("mac");
 
        //根据mac获取orgId
        String orgId = monitorPointService.getOrgIdByMac(mac);
 
        //判断是否特殊定制客户,如果为特殊定制客户则选取特定参数
        Map<String, Object> specialSensors = organizationSensorsService.getSensorsByOrgId(orgId);
 
        if (ObjectUtils.isEmpty(specialSensors)) {
            List<String> sensorKeys = sensorService.getSensorKeys();
            parameters.put("sensorKeys", sensorKeys);
        } else {
            String sensorKeys = (String) specialSensors.get("sensors");
            sensorKeys.trim();
            sensorKeys = sensorKeys.substring(1, sensorKeys.length() - 1);
            parameters.put("sensorKeys", Arrays.asList(sensorKeys.split(",")));
        }
 
        //设置查询参数
        Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData();
        String time = (String) timeAndYearMonth.get("time");
        String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth");
        parameters.put("time", time);
        parameters.put("yearAndMonth", yearAndMonth);
        parameters.put("mac", mac);
 
        Map<String, Object> datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters);
 
        //如果当前五分钟数据还没有插入,则提取前五分钟数据返回
        if (ObjectUtils.isEmpty(datas)) {
            time = getFiveMinuteAgoTime(time);
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters);
        }
 
 
        //去除无效参数
        datas.values().removeIf((value) -> {
            return ObjectUtils.isEmpty(value) || value.equals("[0, 0, 0]");
        });
 
        //添加设备名称
        Map<String, Object> sortDatas = new LinkedHashMap<>();//排序后的数据,用于发送前端
        Device device = deviceService.getDeviceByMac(mac, true);
        sortDatas.put("名称", device.getName());
 
        //参数转换中文
        datas.forEach((key, value) -> {
            Sensor sensor = sensors.get(key);
            if (!ObjectUtils.isEmpty(sensor)) {
                String unit = ObjectUtils.isEmpty(sensor.getUnit()) ? "" : (String) sensor.getUnit();
                String str = (String) value;
                str.trim();
                str = str.substring(1, str.length() - 1);
                sortDatas.put(sensor.getName(), Arrays.asList(str.split(",")).get(0) + unit);
            }
        });
 
        sortDatas.put("时间", time);
 
        return new ResultBean<Map<String, Object>>(sortDatas);
    }
 
    @GetMapping("mapPath")
    public ResultBean<List<WebProvince>> mapPath(HttpServletRequest request) {
        String token =  request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if(ObjectUtils.isEmpty(mapPath))
            return new ResultBean<>("获取地图信息失败",ResultBean.FAIL);
        return new ResultBean<>(mapPath);
    }
 
 
 
 
    /**
     * @Description: 返回结果添加设备经纬度以及state
     * @Param: [datas, devices]
     * @return: java.util.List<java.util.Map               <               java.lang.String               ,               java.lang.Object>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    private List<Map<String, Object>> insertDeviceInfo(List<Map<String, Object>> datas, List<Device> devices) {
        Map<String, Device> map = new HashMap<>();
        devices.forEach(p -> {
            map.put(p.getMac(), p);
        });
 
        datas.forEach(p -> {
            String mac = (String) p.get("mac");
            Device device = map.get(mac);
            List list = LatLngTransformation.Convert_BD09_To_GCJ02(device.getLatitude(), device.getLongitude());
            p.put("longitude", list.get(0));
            p.put("latitude", list.get(1));
            p.put("state", device.getState());
        });
        return datas;
    }
 
    /**
     * @Description: 根据当前时间判断要获取五分钟平均数据在数据库中的时间
     * @Param: []
     * @return: java.lang.String
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    private Map<String, Object> getTimeAndYearMonthForFiveMinuteData() {
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String minute = DateUtil.getMinute(date);
        String year = "";
        String month = "";
        String yearAndMonth = "";
        String startTime = "";
        Integer endMinute = Integer.parseInt(String.valueOf(minute.charAt(minute.length() - 1)));
        if (endMinute >= 6 || endMinute == 0) {//分钟结尾如果是 6 7 8 9 0   比如12:16,12:20进入, 则获取12:10-12:15的数据
            date = DateUtil.rollMinute(date, -1);
            StringBuilder time = new StringBuilder(sdf.format(date));
            startTime = time.replace(15, 19, "5:00").toString();
        } else {// 分钟结尾如果是1 2 3 4 5 则获取上个五分钟数据 比如12:11分钟进入 则获取12:05-12:10的数据
            StringBuilder time = new StringBuilder(sdf.format(date));
            startTime = time.replace(15, 19, "0:00").toString();
        }
 
        year = DateUtil.getYear(date);
        month = DateUtil.getMonth(date);
        yearAndMonth = year + month;
        map.put("time", startTime);
        map.put("yearAndMonth", yearAndMonth);
        return map;
    }
 
 
    /**
     * @Description: 根据传入时间获取五分钟前的数据并且格式化
     * @Param: [time]
     * @return: java.lang.String
     * @Author: 下雨听风
     * @Date: 2020/10/20
     */
    private String getFiveMinuteAgoTime(String time) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(time);
            date = DateUtil.rollMinute(date, -5);
            time = sdf.format(date);
            return time;
        } catch (ParseException e) {
            return null;
        }
    }
 
 
}