Sfoglia il codice sorgente

1、first commit
2、未完成ws的状态信息创建

clevercsc 5 anni fa
commit
2f28f7e65a

+ 31 - 0
.gitignore

@@ -0,0 +1,31 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**
+!**/src/test/**
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+
+### VS Code ###
+.vscode/

+ 4 - 0
README.md

@@ -0,0 +1,4 @@
+# 工程简介
+
+# 延伸阅读
+

+ 127 - 0
pom.xml

@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>cn.clevercsc</groupId>
+    <artifactId>niuniu-tool</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>niuniu-tool</name>
+    <description>Niu niu you xuan tools</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.72</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.6</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+
+        <!-- util -->
+        <dependency>
+            <groupId>org.jsoup</groupId>
+            <artifactId>jsoup</artifactId>
+            <version>1.13.1</version>
+        </dependency>
+
+        <!-- websocket -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.junit.vintage</groupId>
+                    <artifactId>junit-vintage-engine</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.10.6</version>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.3.7.RELEASE</version>
+                <configuration>
+                    <mainClass>cn.clevercsc.niuniutool.NiuniuToolApplication</mainClass>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 15 - 0
src/main/java/cn/clevercsc/niuniutool/NiuniuToolApplication.java

@@ -0,0 +1,15 @@
+package cn.clevercsc.niuniutool;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@EnableScheduling
+@SpringBootApplication
+public class NiuniuToolApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(NiuniuToolApplication.class, args);
+    }
+
+}

+ 34 - 0
src/main/java/cn/clevercsc/niuniutool/constants/UrlConstant.java

@@ -0,0 +1,34 @@
+package cn.clevercsc.niuniutool.constants;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: UrlConstant
+ * @Description: 牛牛相应接口的api地址
+ * @Date 2021/2/22 0022 上午 10:27
+ */
+public class UrlConstant {
+    /**
+     *服务器地址
+     */
+    public static final String SERVER_URL = "http://niuniu.miaopg.com";
+//    public static final String SERVER_URL = "http://localhost:5000/mock/15";
+
+    public static final String X_Requested_With_URL = "com.niuniuyouxuan.chesi1";
+
+    public static final String Origin_URL = "http://h5niuniu.miaopg.com";
+
+    /**
+     *登录地址
+     */
+    public static final String LONGIN_URL = SERVER_URL + "/api/login";
+
+    /**
+     *用户信息地址
+     */
+    public static final String USER_INFO_URL = SERVER_URL + "/api/userinfo";
+    /**
+     *拼团数据信息地址
+     */
+    public static final String PIN_TUAN_DATA_URL = SERVER_URL + "/api/order/pintuan_data";
+}

+ 34 - 0
src/main/java/cn/clevercsc/niuniutool/controller/NiuniuController.java

@@ -0,0 +1,34 @@
+package cn.clevercsc.niuniutool.controller;
+
+import cn.clevercsc.niuniutool.service.NiuniuService;
+import cn.clevercsc.niuniutool.util.HttpResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: NiuniuController
+ * @Description: 牛牛优选接口类
+ * @Date 2021/2/22 0022 上午 11:02
+ */
+@RestController
+@RequestMapping("api")
+public class NiuniuController {
+    @Autowired
+    private NiuniuService niuniuService;
+
+    @PostMapping("login")
+    public HttpResult login(String account,String password,@RequestParam(required = false) String code){
+
+        return niuniuService.login(account,password,code);
+    }
+
+    @PostMapping("pin_tuan")
+    public HttpResult pinTuan(){
+        return niuniuService.pinTuan();
+    }
+}

+ 20 - 0
src/main/java/cn/clevercsc/niuniutool/dto/DashboardDto.java

@@ -0,0 +1,20 @@
+package cn.clevercsc.niuniutool.dto;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: DashboradDto
+ * @Description: TODO
+ * @Date 2021/2/22 0022 下午 4:34
+ */
+@NoArgsConstructor
+@Data
+public class DashboardDto {
+    private  String account;
+    private PinTuanDto pinTuanDto;
+    private int change;
+    private String brokerage_price;
+}

+ 28 - 0
src/main/java/cn/clevercsc/niuniutool/dto/PinTuanDto.java

@@ -0,0 +1,28 @@
+package cn.clevercsc.niuniutool.dto;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: PinTuanDto
+ * @Description: 拼团信息dto
+ * @Date 2021/2/22 0022 上午 10:37
+ */
+@NoArgsConstructor
+@Data
+public class PinTuanDto {
+
+    /**
+     * inagroup : 1
+     * already_pinzhong : 1
+     * shijian :
+     * not_pinzhong : 26
+     */
+
+    private Integer inagroup;
+    private Integer already_pinzhong;
+    private String shijian;
+    private Integer not_pinzhong;
+}

+ 102 - 0
src/main/java/cn/clevercsc/niuniutool/dto/UserInfoDto.java

@@ -0,0 +1,102 @@
+package cn.clevercsc.niuniutool.dto;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: UserInfoDto
+ * @Description: 牛牛用户信息dto
+ * @Date 2021/2/22 0022 上午 10:33
+ */
+@NoArgsConstructor
+@Data
+public class UserInfoDto {
+
+    /**
+     * uid : 4043
+     * real_name :
+     * birthday : 0
+     * card_id :
+     * partner_id : 0
+     * group_id : 0
+     * nickname : 130****7470
+     * avatar : http://niuniu.miaopg.com//uploads/attach/2021/01/20210116/d58eb120e56dc91f261774171e3496b3.png
+     * phone : 13058397470
+     * now_money : 0.000
+     * goldbean : 0.00
+     * brokerage_price : 26.000
+     * integral : 0.00
+     * sign_num : 0
+     * level : 0
+     * spread_uid : 2865
+     * spread_time : 1613832333
+     * user_type : h5
+     * is_promoter : 1
+     * pay_count : 1
+     * spread_count : 0
+     * addres :
+     * adminid : 0
+     * login_type :
+     * system_cz : 0
+     * is_pinzhong : 0
+     * if_ran : null
+     * parent_str : 1,3,18,25,59,72,73,74,76,82,2845,2865
+     * is_bz : 1
+     * brnk : 0
+     * binding_uid : 0
+     * spreadids : 2865,2845,82,76,74,73,72,59,25,18,3,1,
+     * zj_num : 1
+     * zj_time : 1613889601
+     * pink_num : 27
+     * auto_pt : 0
+     * auto_store_id : null
+     * now_mobilephone : 0
+     * now_phonefragment : 0
+     * now_commodity : 0
+     * commissionCount : 26.000
+     */
+
+    private Integer uid;
+    private String real_name;
+    private Integer birthday;
+    private String card_id;
+    private Integer partner_id;
+    private Integer group_id;
+    private String nickname;
+    private String avatar;
+    private String phone;
+    private String now_money;
+    private String goldbean;
+    private String brokerage_price;
+    private String integral;
+    private Integer sign_num;
+    private Integer level;
+    private Integer spread_uid;
+    private Integer spread_time;
+    private String user_type;
+    private Integer is_promoter;
+    private Integer pay_count;
+    private Integer spread_count;
+    private String addres;
+    private Integer adminid;
+    private String login_type;
+    private Integer system_cz;
+    private Integer is_pinzhong;
+    private Object if_ran;
+    private String parent_str;
+    private Integer is_bz;
+    private String brnk;
+    private Integer binding_uid;
+    private String spreadids;
+    private Integer zj_num;
+    private Integer zj_time;
+    private Integer pink_num;
+    private Integer auto_pt;
+    private Object auto_store_id;
+    private Integer now_mobilephone;
+    private Integer now_phonefragment;
+    private Integer now_commodity;
+    private String commissionCount;
+}

+ 128 - 0
src/main/java/cn/clevercsc/niuniutool/service/NiuniuService.java

@@ -0,0 +1,128 @@
+package cn.clevercsc.niuniutool.service;
+
+import cn.clevercsc.niuniutool.constants.UrlConstant;
+import cn.clevercsc.niuniutool.dto.DashboardDto;
+import cn.clevercsc.niuniutool.dto.PinTuanDto;
+import cn.clevercsc.niuniutool.dto.UserInfoDto;
+import cn.clevercsc.niuniutool.util.ConnectUtils;
+import cn.clevercsc.niuniutool.util.DateUtils;
+import cn.clevercsc.niuniutool.util.HttpResult;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.jsoup.Connection;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.net.ConnectException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: NiuniuService
+ * @Description: 牛牛优选主要工具类
+ * @Date 2021/2/22 0022 上午 10:44
+ */
+@Component
+@Slf4j
+public class NiuniuService {
+
+    public String accessToken;
+
+    public PinTuanDto lastPintuanDto;
+
+    public DashboardDto dashboardDto;
+
+    public HttpResult login(String account, String password, String code) {
+        Map<String, String> param = new HashMap<>();
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("account", account);
+        bodyParam.put("password", password);
+        bodyParam.put("code", StringUtils.isBlank(code) ? "" : code);
+        HttpResult result = null;
+        try {
+            result = ConnectUtils.connect(UrlConstant.LONGIN_URL, param, bodyParam.toJSONString(), Connection.Method.POST);
+            if (result.getStatus()==200){
+                this.accessToken = JSONObject.parseObject(String.valueOf(result.getData())).getString("token");
+            }
+            if (dashboardDto==null){
+                dashboardDto= new DashboardDto();
+                dashboardDto.setAccount(account);
+            }
+            return result;
+        } catch (ConnectException e) {
+            log.error("帐号{} 登录失败", account, e);
+            return null;
+        }
+    }
+
+    public HttpResult userInfo() {
+        if (StringUtils.isBlank(this.accessToken)){
+            return null;
+        }
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Authori-zation", "Bearer " + this.accessToken);
+        HttpResult result = null;
+        try {
+            result = ConnectUtils.connect(UrlConstant.USER_INFO_URL, headers, Connection.Method.GET);
+            if (result==null){
+                throw new RuntimeException("更新用户信息失败");
+            }
+            UserInfoDto userInfoDto = JSONObject.parseObject(String.valueOf(result.getData()),UserInfoDto.class);
+            if (dashboardDto==null){
+                dashboardDto= new DashboardDto();
+                dashboardDto.setBrokerage_price(userInfoDto.getBrokerage_price());
+            }
+            log.info("{} 更新用户信息:{}", DateUtils.formatDate(new Date()),JSONObject.toJSONString(result));
+            return result;
+        } catch (ConnectException e) {
+            log.error("获取用户信息失败", e);
+            return null;
+        }
+    }
+
+    public HttpResult pinTuan() {
+        if (StringUtils.isBlank(this.accessToken)){
+            return null;
+        }
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Authori-zation", "Bearer " + this.accessToken);
+        HttpResult result = null;
+        try {
+            result = ConnectUtils.connect(UrlConstant.PIN_TUAN_DATA_URL, headers, Connection.Method.GET);
+            if (result==null){
+                throw new RuntimeException("更新拼团信息失败");
+            }
+
+            log.info("{} 更新拼团信息:{}", DateUtils.formatDate(new Date()),JSONObject.toJSONString(result));
+            return result;
+        } catch (ConnectException e) {
+            log.error("获取拼团信息失败", e);
+            return null;
+        }
+    }
+
+    @Scheduled(cron = "12 0/2 * * * ? ")
+    public void updatePinTuan() {
+        HttpResult httpResult =  pinTuan();
+        if (pinTuan()==null){
+            throw new RuntimeException("更新拼团信息失败");
+        }
+        PinTuanDto pinTuanDto = JSONObject.parseObject(String.valueOf(httpResult.getData()),PinTuanDto.class);
+        if (lastPintuanDto==null){
+            lastPintuanDto =pinTuanDto;
+        }
+        if (dashboardDto==null){
+            dashboardDto= new DashboardDto();
+            dashboardDto.setPinTuanDto(pinTuanDto);
+        }
+        if (!pinTuanDto.getAlready_pinzhong().equals(lastPintuanDto.getAlready_pinzhong())){
+            log.info("你拼中了  {}  个商品,请尽快处理",(pinTuanDto.getAlready_pinzhong()-lastPintuanDto.getAlready_pinzhong()));
+            lastPintuanDto=pinTuanDto;
+            dashboardDto.setChange(pinTuanDto.getAlready_pinzhong()-lastPintuanDto.getAlready_pinzhong());
+        }
+    }
+}

+ 57 - 0
src/main/java/cn/clevercsc/niuniutool/util/ConnectUtils.java

@@ -0,0 +1,57 @@
+package cn.clevercsc.niuniutool.util;
+
+import cn.clevercsc.niuniutool.constants.UrlConstant;
+import com.alibaba.fastjson.JSONObject;
+import org.jsoup.Connection;
+import org.jsoup.Jsoup;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.Map;
+
+public class ConnectUtils {
+
+    private ConnectUtils(){
+        throw new IllegalStateException("Utility class");
+    }
+
+    private static final Integer TIME_OUT = 5*1000;
+
+    public static HttpResult connect(String url, Map<String, String> params, String json, Connection.Method method) throws ConnectException {
+        try {
+            Connection.Response response = Jsoup.connect(url)
+                    .ignoreContentType(true)
+                    .timeout(TIME_OUT)
+                    .data(params)
+                    .requestBody(json)
+                    .header("X-Requested-With", UrlConstant.X_Requested_With_URL)
+                    .header("Content-Type", "application/json; charset=UTF-8")
+                    .header("Origin",UrlConstant.Origin_URL)
+                    .method(method)
+                    .execute();
+            System.err.println(response);
+            System.err.println(response.body());
+            return JSONObject.parseObject(response.body(), HttpResult.class);
+        } catch (IOException e) {
+            throw new ConnectException("网络连接超时");
+        }
+    }
+
+    public static HttpResult connect(String url, Map<String, String> headerParams, Connection.Method method) throws ConnectException {
+        try {
+            Connection.Response response = Jsoup.connect(url)
+                    .ignoreContentType(true)
+                    .timeout(TIME_OUT)
+                    .headers(headerParams)
+                    .header("X-Requested-With", UrlConstant.X_Requested_With_URL)
+                    .header("Origin",UrlConstant.Origin_URL)
+                    .header("Content-Type", "application/json; charset=UTF-8")
+                    .method(method)
+                    .execute();
+            return JSONObject.parseObject(response.body(), HttpResult.class);
+        } catch (IOException e) {
+            throw new ConnectException("网络连接超时");
+        }
+    }
+
+}

+ 474 - 0
src/main/java/cn/clevercsc/niuniutool/util/DateUtils.java

@@ -0,0 +1,474 @@
+package cn.clevercsc.niuniutool.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+public class DateUtils {
+
+	private final static Logger logger = LoggerFactory.getLogger(DateUtils.class);
+
+	public final static String DEFAULT_TIMEZONE = "GMT+8";
+
+	public final static String ISO_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS";
+
+	public final static String ISO_SHORT_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
+
+	public final static String DEFAULT_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+	public final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
+
+	public final static String SHORT_TIME_FORMAT = "yyyy-MM-dd HH:mm";
+
+	public final static String FULL_SEQ_FORMAT = "yyyyMMddHHmmssSSS";
+
+	public final static String[] MULTI_FORMAT = { DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT, ISO_DATE_TIME_FORMAT,
+			ISO_SHORT_DATE_TIME_FORMAT, SHORT_TIME_FORMAT, "yyyy-MM" };
+
+	public final static String FORMAT_YYYY = "yyyy";
+
+	public final static String FORMAT_YYYYMM = "yyyyMM";
+
+	public final static String FORMAT_YYYYMMDD = "yyyyMMdd";
+
+	public final static String FORMAT_YYYYMMDDHH = "yyyyMMddHH";
+
+	public final static String FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
+	public final static String FORMAT_EXCEL = "yyyy/MM/dd HH:mm:ss";
+
+	public static String formatDate(Date date) {
+		if (date == null) {
+			return "";
+		}
+		return new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(date);
+	}
+
+	public static String formatDate(Date date, String format) {
+		if (date == null) {
+			return null;
+		}
+		return new SimpleDateFormat(format).format(date);
+	}
+
+	public static Integer formatDateToInt(Date date, String format) {
+		if (date == null) {
+			return null;
+		}
+		return Integer.valueOf(new SimpleDateFormat(format).format(date));
+	}
+
+	public static Long formatDateToLong(Date date, String format) {
+		if (date == null) {
+			return null;
+		}
+		return Long.valueOf(new SimpleDateFormat(format).format(date));
+	}
+
+	public static String formatTime(Date date) {
+		if (date == null) {
+			return null;
+		}
+		return new SimpleDateFormat(DEFAULT_TIME_FORMAT).format(date);
+	}
+
+	public static String formatShortTime(Date date) {
+		if (date == null) {
+			return null;
+		}
+		return new SimpleDateFormat(SHORT_TIME_FORMAT).format(date);
+	}
+
+	public static String formatDateNow() {
+		return formatDate(DateUtils.currentDate());
+	}
+
+	public static String formatTimeNow() {
+		return formatTime(DateUtils.currentDate());
+	}
+
+	public static Date parseDate(String date, String format) {
+		if (date == null) {
+			return null;
+		}
+		try {
+			return new SimpleDateFormat(format).parse(date);
+		} catch (ParseException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	public static Date parseTime(String date, String format) {
+		if (date == null) {
+			return null;
+		}
+		try {
+			return new SimpleDateFormat(format).parse(date);
+		} catch (ParseException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	public static Date parseDate(String date) {
+		return parseDate(date, DEFAULT_DATE_FORMAT);
+	}
+
+	public static Date parseTime(String date) {
+		return parseTime(date, DEFAULT_TIME_FORMAT);
+	}
+
+	public static String plusOneDay(String date) {
+		DateTime dateTime = new DateTime(parseDate(date).getTime());
+		return formatDate(dateTime.plusDays(1).toDate());
+	}
+
+	public static String plusOneDay(Date date) {
+		DateTime dateTime = new DateTime(date.getTime());
+		return formatDate(dateTime.plusDays(1).toDate());
+	}
+
+	public static String getHumanDisplayForTimediff(Long diffMillis) {
+		if (diffMillis == null) {
+			return "";
+		}
+		long day = diffMillis / (24 * 60 * 60 * 1000);
+		long hour = (diffMillis / (60 * 60 * 1000) - day * 24);
+		long min = ((diffMillis / (60 * 1000)) - day * 24 * 60 - hour * 60);
+		long se = (diffMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
+		StringBuilder sb = new StringBuilder();
+		if (day > 0) {
+			sb.append(day + "D");
+		}
+		DecimalFormat df = new DecimalFormat("00");
+		sb.append(df.format(hour) + ":");
+		sb.append(df.format(min) + ":");
+		sb.append(df.format(se));
+		return sb.toString();
+	}
+
+	/**
+	 * 把类似2014-01-01 ~ 2014-01-30格式的单一字符串转换为两个元素数组
+	 */
+	public static Date[] parseBetweenDates(String date) {
+		if (StringUtils.isBlank(date)) {
+			return null;
+		}
+		date = date.replace("~", "~");
+		Date[] dates = new Date[2];
+		String[] values = date.split("~");
+		dates[0] = parseMultiFormatDate(values[0].trim());
+		dates[1] = parseMultiFormatDate(values[1].trim());
+		return dates;
+	}
+
+	public static Date parseMultiFormatDate(String date) {
+		try {
+			return org.apache.commons.lang3.time.DateUtils.parseDate(date, MULTI_FORMAT);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * @Title:getDiffDay
+	 * @Description:获取日期相差天数
+	 * @param:@param beginDate
+	 *                   字符串类型开始日期
+	 * @param:@param endDate
+	 *                   字符串类型结束日期
+	 * @param:@return
+	 * @return:Long 日期相差天数
+	 * @author:谢
+	 * @thorws:
+	 */
+	public static Long getDiffDay(String beginDate, String endDate) {
+		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+		Long checkday = 0l;
+		// 开始结束相差天数
+		try {
+			checkday = (formatter.parse(endDate).getTime() - formatter.parse(beginDate).getTime())
+					/ (1000 * 24 * 60 * 60);
+		} catch (ParseException e) {
+
+			e.printStackTrace();
+			checkday = null;
+		}
+		return checkday;
+	}
+
+	/**
+	 * @Title:getDiffDay
+	 * @Description:获取日期相差天数
+	 * @param:@param beginDate
+	 *                   Date类型开始日期
+	 * @param:@param endDate
+	 *                   Date类型结束日期
+	 * @param:@return
+	 * @return:Long 相差天数
+	 * @author: 谢
+	 * @thorws:
+	 */
+	public static Long getDiffDay(Date beginDate, Date endDate) {
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		String strBeginDate = format.format(beginDate);
+
+		String strEndDate = format.format(endDate);
+		return getDiffDay(strBeginDate, strEndDate);
+	}
+
+	/**
+	 * N天之后
+	 * 
+	 * @param n
+	 * @param date
+	 * @return
+	 */
+	public static Date nDaysAfter(Integer n, Date date) {
+		Calendar cal = Calendar.getInstance();
+		cal.setTime(date);
+		cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + n);
+		return cal.getTime();
+	}
+
+	/**
+	 * N天之前
+	 * 
+	 * @param n
+	 * @param date
+	 * @return
+	 */
+	public static Date nDaysAgo(Integer n, Date date) {
+		Calendar cal = Calendar.getInstance();
+		cal.setTime(date);
+		cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - n);
+		return cal.getTime();
+	}
+
+	private static Date currentDate;
+
+	public static Date setCurrentDate(Date date) {
+		if (date == null) {
+			currentDate = null;
+		} else {
+			currentDate = date;
+		}
+		return currentDate;
+	}
+
+	/**
+	 * 为了便于在模拟数据程序中控制业务数据获取到的当前时间
+	 * 提供一个帮助类处理当前时间,为了避免误操作,只有在devMode开发模式才允许“篡改”当前时间
+	 * 
+	 * @return
+	 */
+	public static Date currentDate() {
+		if (currentDate == null) {
+			return new Date();
+		}
+		return currentDate;
+	}
+
+	/**
+	 * 获取某段时这里写代码片间内的所有日期
+	 * @param dBegin
+	 * @param dEnd
+	 * @return
+	 */
+	public static List<Date> findDates(Date dBegin, Date dEnd) {
+		List<Date> lDate = new ArrayList<Date>();
+		lDate.add(dBegin);
+		Calendar calBegin = Calendar.getInstance();
+		// 使用给定的 Date 设置此 Calendar 的时间
+		calBegin.setTime(dBegin);
+		Calendar calEnd = Calendar.getInstance();
+		// 使用给定的 Date 设置此 Calendar 的时间
+		calEnd.setTime(dEnd);
+		// 测试此日期是否在指定日期之后
+		while (dEnd.after(calBegin.getTime())) {
+			// 根据日历的规则,为给定的日历字段添加或减去指定的时间量
+			calBegin.add(Calendar.DAY_OF_MONTH, 1);
+			lDate.add(calBegin.getTime());
+		}
+		return lDate;
+	}
+
+	public static Integer getWeekOfYear(Date date) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		String yearString = formatDate(date, FORMAT_YYYY);
+		int weekNum = c.get(Calendar.WEEK_OF_YEAR);
+		if (weekNum < 10) {
+			yearString = StringUtils.rightPad(yearString, 5, "0");
+		}
+		return Integer.valueOf(yearString + weekNum);
+	}
+
+	public static Date formatDate(String time) {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		try {
+			return sdf.parse(time);
+		} catch (ParseException e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	public static Date fromISODate(String time) {
+		if (!time.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z")) {
+			return null;
+		}
+		time = time.replaceFirst("T", " ").replaceFirst(".\\d{3}Z", "");
+		Date date = formatDate(time);
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.HOUR_OF_DAY, 8);
+		return ca.getTime();
+	}
+
+	public static Date fromOBTISODate(String time) {
+		if (StringUtils.isBlank(time) || !time.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}")) {
+			return null;
+		}
+		time = time.replaceFirst("T", " ");
+		Date date = formatDate(time);
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.HOUR_OF_DAY, 8);
+		return ca.getTime();
+	}
+
+	public static boolean isValidDate(String str) {
+		boolean convertSuccess = true;
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		try {
+			format.setLenient(false);
+			format.parse(str);
+		} catch (ParseException e) {
+			// e.printStackTrace();
+			// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
+			convertSuccess = false;
+		}
+		return convertSuccess;
+	}
+
+	public static boolean isValidDate(String str, String formatStr) {
+		boolean convertSuccess = true;
+		SimpleDateFormat format = new SimpleDateFormat(formatStr);
+		try {
+			format.setLenient(false);
+			format.parse(str);
+		} catch (ParseException e) {
+			// e.printStackTrace();
+			// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
+			convertSuccess = false;
+		}
+		return convertSuccess;
+	}
+
+	/**
+	 * 
+	
+	 * @Title:        getDaysOfMonth 
+	
+	 * @Description:  获取某年某月有几天
+	
+	 * @param date
+	 * @return    
+	
+	 * @throws 
+	
+	 * @author        chensc
+	
+	 * @Date          2018年11月2日 下午4:23:39
+	 */
+	public static int getDaysOfMonth(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+	}
+
+	//获取某个日期的开始时间
+
+	public static Date getDayStartTime(Date d) {
+
+		Calendar calendar = Calendar.getInstance();
+
+		if(null != d) calendar.setTime(d);
+
+		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),    calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+
+		calendar.set(Calendar.MILLISECOND, 0);
+
+		return calendar.getTime();
+
+	}
+
+	//获取某个日期的结束时间
+
+	public static Date getDayEndTime(Date d) {
+
+		Calendar calendar = Calendar.getInstance();
+
+		if(null != d) calendar.setTime(d);
+		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),    calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
+
+		calendar.set(Calendar.MILLISECOND, 999);
+
+		return calendar.getTime();
+
+	}
+	//获取一个月的结束时间
+	public static Date getMonthEndTime(Date d) {
+
+		Calendar calendar = Calendar.getInstance();
+
+		if(null != d) calendar.setTime(d);
+
+		calendar.add(Calendar.MONTH, 1);
+		calendar.add(Calendar.MILLISECOND, -1);
+		return calendar.getTime();
+
+	}
+
+	//获取一年的结束时间
+	public static Date getYearEndTime(Date d) {
+
+		Calendar calendar = Calendar.getInstance();
+
+		if(null != d) calendar.setTime(d);
+
+		calendar.add(Calendar.YEAR, 1);
+		calendar.add(Calendar.MILLISECOND, -1);
+		return calendar.getTime();
+
+	}
+
+	public static void main(String[] args) {
+//		System.err.println((parseDate("201910",FORMAT_YYYYMM)));
+//		System.err.println(formatDate((parseDate("201910",FORMAT_YYYYMM))));
+//		System.err.println(formatDate(getDayStartTime(parseDate("201910",FORMAT_YYYYMM)),DEFAULT_TIME_FORMAT));
+//		System.err.println(formatDate(getYearEndTime(parseDate("2019",FORMAT_YYYY)),DEFAULT_TIME_FORMAT));
+//		int len="2019".split("-").length;
+//		System.err.println(	len);
+//		SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
+//		Calendar cal=Calendar.getInstance();
+//		cal.set(Calendar.YEAR, 2006);
+//		cal.set(Calendar.MONTH, 8);
+//		cal.set(Calendar.DAY_OF_MONTH, 3);
+//		cal.add(Calendar.DATE, -4);
+//		Date date=cal.getTime();
+//		System.err.println(cal.get(Calendar.MONTH));
+//		System.out.println(df.format(date));
+		DateUtils.getDayStartTime(DateUtils.parseDate("2019",DateUtils.FORMAT_YYYY));
+	}
+
+}

+ 45 - 0
src/main/java/cn/clevercsc/niuniutool/util/HttpResult.java

@@ -0,0 +1,45 @@
+package cn.clevercsc.niuniutool.util;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/**
+ * Http访问结果封装
+ */
+@Getter
+@Setter
+public class HttpResult implements Serializable {
+
+    /**
+     * 代码
+     */
+    private Integer status;
+
+
+    private String msg;
+
+    /**
+     * 消息
+     */
+    private Object data;
+
+
+
+    public HttpResult(Integer status) {
+        this.status = status;
+    }
+
+    public HttpResult(Integer status, Object data) {
+        this.status = status;
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return JSONObject.toJSONString(this);
+    }
+
+}

+ 44 - 0
src/main/java/cn/clevercsc/niuniutool/ws/DashboardWs.java

@@ -0,0 +1,44 @@
+package cn.clevercsc.niuniutool.ws;
+
+import org.springframework.stereotype.Component;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+
+/**
+ * @author csc
+ * @version V1.0
+ * @ClassName: DashboardWs
+ * @Description: TODO
+ * @Date 2021/2/22 0022 下午 4:48
+ */
+@Component
+@ServerEndpoint("/ws/dashboard")
+public class DashboardWs {
+
+    @OnOpen
+    public void onOpen(Session session) {
+
+
+    }
+
+    @OnClose
+    public void onClose(Session session) throws IOException {
+        session.close();
+    }
+
+    public static void send(Session session, String data) {
+        try {
+            if (session.isOpen()) {
+                session.getAsyncRemote().sendText(data);
+            } else {
+                session.close();
+            }
+        } catch (Exception ignored) {
+            //ignore this exception
+        }
+    }
+}

+ 14 - 0
src/main/resources/application.properties

@@ -0,0 +1,14 @@
+# \u5E94\u7528\u540D\u79F0
+spring.application.name=niuniu-tool
+# Actuator Web \u8BBF\u95EE\u7AEF\u53E3
+management.server.port=8081
+management.endpoints.jmx.exposure.include=*
+management.endpoints.web.exposure.include=*
+management.endpoint.health.show-details=always
+# \u5E94\u7528\u670D\u52A1 WEB \u8BBF\u95EE\u7AEF\u53E3
+server.port=8080
+
+logging.config=classpath:logback-spring.xml
+#\u6B64\u5904\u7684\u914D\u7F6E\u5E94\u5728\u8FD0\u884C\u65F6\u7531\u547D\u4EE4\u884C\u6307\u5B9A\uFF0C\u5982\uFF1Anohup java -jar /mnt/ground_system/scheduler/$type/scheduler_master.jar --logback.loghome=/mnt/ground_system/scheduler/$type/servant.$i --logback.logprefix = servant.$i
+logback.loghome= ./niuniu
+logback.logprefix= test

+ 58 - 0
src/main/resources/logback-spring.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <springProperty scope="context" name="LOG_HOME" source="logback.loghome"/>
+
+    <springProperty scope="context" name="LOG_PREFIX" source="logback.logprefix"/>
+
+<!--    <springProfile name="dev,test">-->
+<!--        &lt;!&ndash;定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径&ndash;&gt;-->
+<!--        <property name="LOG_HOME" value="C:/logs"/>-->
+<!--    </springProfile>-->
+
+<!--    &lt;!&ndash; 生产环境 &ndash;&gt;-->
+<!--    <springProfile name="prod">-->
+<!--        &lt;!&ndash;定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径。对应线上的地址&ndash;&gt;-->
+<!--        <property name="LOG_HOME" value=" usr/local/logs"/>-->
+<!--    </springProfile>-->
+
+
+    <!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
+    <property name="LOG_PATTERN"
+              value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
+    <!-- 定义日志存储的路径,不要配置相对路径 -->
+    <property name="FILE_PATH"
+              value="${LOG_HOME}/${LOG_PREFIX}.%d{yyyy-MM-dd}.%i.log" />
+    <!-- 控制台输出日志 -->
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <!-- 按照上面配置的LOG_PATTERN来打印日志 -->
+            <pattern>${LOG_PATTERN}</pattern>
+        </encoder>
+    </appender>
+    <!--每天生成一个日志文件,保存30天的日志文件。rollingFile是用来切分文件的 -->
+    <appender name="rollingFile"
+              class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <fileNamePattern>
+                ${FILE_PATH}
+            </fileNamePattern>
+            <!-- keep 30 days' worth of history -->
+            <maxHistory>30</maxHistory>
+            <timeBasedFileNamingAndTriggeringPolicy
+                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <!-- 日志文件的最大大小 -->
+                <maxFileSize>10MB</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${LOG_PATTERN}</pattern>
+        </encoder>
+    </appender>
+    <!-- project default level -->
+<!--    <logger name="com.itcodai.demo3" level="INFO" />-->
+    <!-- 日志输出级别 -->
+    <root level="INFO">
+        <appender-ref ref="console" />
+        <appender-ref ref="rollingFile" />
+    </root>
+</configuration>

+ 16 - 0
src/main/resources/rebel.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
+  Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
+-->
+<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
+
+	<id>niuniu-tool</id>
+
+	<classpath>
+		<dir name="D:/resourceCode/IntellijWorkSpace/niuniu-tool/target/classes">
+		</dir>
+	</classpath>
+
+</application>

+ 13 - 0
src/test/java/cn/clevercsc/niuniutool/NiuniuToolApplicationTests.java

@@ -0,0 +1,13 @@
+package cn.clevercsc.niuniutool;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class NiuniuToolApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}