From 88b5cef5618a06c3893b1f94b055e7a76b837410 Mon Sep 17 00:00:00 2001 From: xiangwbs Date: Thu, 14 Dec 2017 20:37:08 +0800 Subject: [PATCH] demo --- .../java/com/xwbing/service/DemoService.java | 111 ++++-------------- 1 file changed, 23 insertions(+), 88 deletions(-) diff --git a/boot-service/src/main/java/com/xwbing/service/DemoService.java b/boot-service/src/main/java/com/xwbing/service/DemoService.java index 82f0234..2b32598 100644 --- a/boot-service/src/main/java/com/xwbing/service/DemoService.java +++ b/boot-service/src/main/java/com/xwbing/service/DemoService.java @@ -1,99 +1,34 @@ package com.xwbing.service; -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.collections.CollectionUtils; +import com.xwbing.util.RestMessage; import org.apache.commons.lang3.StringUtils; -import org.springframework.scheduling.annotation.Scheduled; - -import java.math.BigDecimal; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; public class DemoService { - private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - private String chacheTime = ""; - - private static Double formate(Double v1) { - BigDecimal bg = new BigDecimal(v1); - return bg.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - } - - private Double hoursBetween(String startDateTime, String endDateTime) { - LocalDateTime sDateTime = LocalDateTime.parse(startDateTime, dateTimeFormatter); - LocalDateTime eDateTime = LocalDateTime.parse(endDateTime, dateTimeFormatter); - Duration duration = Duration.between(sDateTime, eDateTime); - long m = duration.toMinutes(); - return formate((double) m / 60.0); - } - - private List getGpsByUserName(String username, String stime, String etime) { - return null; - } - - private Map hand(List gpsList, String endTime) { - Map map = new HashMap<>(); - //存数据库 - JSONObject obj = gpsList.get(0); - // TODO: 2017/11/22 - //获取下一个时间 - String time = (String) obj.get("time"); - String startTime = LocalDateTime.parse(time, dateTimeFormatter).plusHours(1).format(dateTimeFormatter); - //跟截止时间比较 - if (hoursBetween(time, endTime) > 1) { - //过滤 - gpsList = gpsList.stream().filter(jsonObject -> ((String) jsonObject.get("time")).compareTo(startTime) < 0 ? true : false).collect(Collectors.toList()); - map.put("gpsList", gpsList); - map.put("startTime", startTime); - }else { - map.put("startTime",time); - map.put("startTime",gpsList); - } - return map; - } - - @Scheduled(cron = "0 0 */1 * * ?") // 每小时执行一次 - public void scheduler() { - LocalDateTime now = LocalDateTime.now(); - String endTime = now.format(dateTimeFormatter);//截止时间 - String startTime;//开始时间 - List gpsList = new ArrayList<>();//所有gps数据 - //获取巡更人员 - List list = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(list)) { - //判断开始时间 - if (StringUtils.isNotEmpty(chacheTime)) { - startTime = chacheTime; + void setRemind(String id, String typeName, String remindDate, String type) { + RestMessage one = queryOne(id, typeName); + if (one != null) { + if (StringUtils.isNotEmpty(remindDate)) { + update(); } else { - //从数据库去查 - //数据库无数据 - startTime = LocalDate.now().toString() + " 00:00:00"; + delete(); } - while (hoursBetween(startTime, endTime) > 1) { - if (CollectionUtils.isNotEmpty(gpsList)) { - Map hand = hand(gpsList,endTime); - startTime = (String) hand.get("startTime"); - gpsList = (List) hand.get("hand"); - } else { - for (JSONObject jsonObject : list) { - gpsList.addAll(getGpsByUserName((String) jsonObject.get("tel"), startTime, endTime)); - } - if (CollectionUtils.isNotEmpty(gpsList)) { - //排序 - //获取处理结果 - Map hand = hand(gpsList,endTime); - startTime = (String) hand.get("startTime"); - gpsList = (List) hand.get("hand"); - } - } + } else { + if (StringUtils.isNotEmpty(remindDate)) { + save(); } - chacheTime = startTime; } } + + private RestMessage queryOne(String id, String typeName) { + return new RestMessage(); + } + + private void update() { + } + + private void delete() { + } + + private void save() { + } }