Browse Source

上传文件

陈士柏 2 years ago
parent
commit
bce1fcfb48

+ 66 - 0
bigData/src/com/happy/Until/BaijGaoj.java

@@ -0,0 +1,66 @@
+package com.happy.Until;
+
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class BaijGaoj {
+
+    public static double pi = 3.1415926535897932384626;
+
+    public static String bd09_To_Gcj02(String baij) {
+        String[] al = baij.split(",");
+        double bd_lat = Double.parseDouble(al[0]);
+        double bd_lon = Double.parseDouble(al[1]);
+        double x = bd_lon - 0.0065, y = bd_lat - 0.006;
+        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
+        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
+        double gg_lon = z * Math.cos(theta);    //gg_lon 求出高德经度
+        double gg_lat = z * Math.sin(theta);    // gg_lat 求出高德纬度
+        StringBuilder str = new StringBuilder("");
+        str.append(gg_lat).append(",").append(gg_lon);
+        return str.toString();
+    }
+
+    public static void main(String[] args) throws ClassNotFoundException, SQLException {
+        Connection conn = null;
+        try{
+            String url = "jdbc:mysql://6.205.66.5:3306/bigdata?useSSL=FALSE&serverTimezone=UTC";
+            String username = "root";
+            String password = "Ro0!ot_369!";
+            Class.forName("com.mysql.cj.jdbc.Driver");
+            conn = DriverManager.getConnection(url, username, password);
+            System.out.println("连接成功!");
+            String sql = "select * from sm_message where sm_color in ('红码', '黄码')  ";
+            PreparedStatement pst = conn.prepareStatement(sql);
+            ResultSet rs = pst.executeQuery();
+            ArrayList<HashMap> ah = new ArrayList<>();
+            while (rs.next()){
+                HashMap<String,String> hs = new HashMap<>();
+                hs.put("id", String.valueOf(rs.getInt("id")));
+                hs.put("jingwei", rs.getString("jingwei"));
+                ah.add(hs);
+            }
+            String sql2 = "update sm_message set jingwei=? where id=? ";
+            PreparedStatement pst2 = null;
+            ResultSet rs2 = null;
+            try{
+                for (int i=0; i< ah.size(); i++){
+                    pst2 = conn.prepareStatement(sql2);
+                    pst2.setString(1, bd09_To_Gcj02(ah.get(i).get("jingwei").toString()));
+                    pst2.setString(2, ah.get(i).get("id").toString());
+                    pst2.execute();
+                    System.out.println("原:"+ah.get(i).get("jingwei").toString());
+                    System.out.println("新:"+bd09_To_Gcj02(ah.get(i).get("jingwei").toString()));
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            System.out.println(ah);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 65 - 0
bigData/src/com/happy/Until/CreateSign1.java

@@ -0,0 +1,65 @@
+package com.happy.Until;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class CreateSign1 {
+    private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5',
+            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+    public static String MD5(String s) {
+        return MD5(s,"utf-8");
+    }
+
+    public static String MD5(String s, String charset) {
+        try{
+            MessageDigest messagedigest = MessageDigest.getInstance("MD5");
+            messagedigest.reset();
+            byte abyte0[] = messagedigest.digest(s.getBytes(charset));
+            return byteToString(abyte0);
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    private static String byteToString(byte abyte0[]) {
+        int i = abyte0.length;
+        char ac[] = new char[i * 2];
+        int j = 0;
+        for (int k = 0; k < i; k++) {
+            byte byte0 = abyte0[k];
+            ac[j++] = hexDigits[byte0 >>> 4 & 0xf];
+            ac[j++] = hexDigits[byte0 & 0xf];
+        }
+        return new String(ac);
+    }
+
+    public static void main(String[] args) {
+        //密钥由艾停车提供,密钥和车场号一一对应
+        String ukey = "K1DIXZCLWNO0J0WV";
+
+        JSONObject data = new JSONObject(true);
+        data.put("uid","大门入口");
+        data.put("in_time",1611731098);
+        data.put("car_number","赣AE3434");
+        data.put("c_type","临时车");
+        data.put("in_channel_id","大门入口");
+        data.put("order_id","1902");
+        data.put("force_update",1);
+        data.put("empty_plot",879);
+        data.put("car_type","");
+        data.put("source","ist");
+        data.put("pic_addr","http://ist-falcon.oss-cn-shenzhen.aliyuncs.com/order-images/31809/in/1902.jpg?Expires=1611817499&OSSAccessKeyId=LTAIQQrl6GICP0QX&Signature=FnKZNrQ5nkdJlhgVTYp4v7Q3ejY%3D");
+
+        // 生成带签名的字符串并使用MD5生成签名,然后转大写
+        String sign = data.toJSONString()+"key="+ukey;
+        sign = MD5(sign).toUpperCase();
+        System.out.println(sign);//242441AAC1911DB6E47A942A2B6477D5
+    }
+}

+ 296 - 0
bigData/src/com/happy/Until/DBtoExcel.java

@@ -0,0 +1,296 @@
+package com.happy.Until;
+
+import com.happy.Model.User;
+import jxl.Workbook;
+import jxl.write.Label;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+import org.apache.poi.ss.formula.functions.T;
+
+import java.io.File;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+public class DBtoExcel {
+	/**
+	 * 导出Excel表
+	 * 
+	 * @param rs
+	 *            数据库结果集
+	 * @param filePath
+	 *            要保存的路径,文件名为 fileName.xls
+	 * @param sheetName
+	 *            工作簿名称 工作簿名称,本方法目前只支持导出一个Excel工作簿
+	 * @param columnName
+	 *            列名,类型为Vector
+	 */
+	public void WriteExcel(ResultSet rs, String filePath, String sheetName,
+			Vector columnName) {
+		WritableWorkbook workbook = null;
+		WritableSheet sheet = null;
+
+		int rowNum = 1; // 从第2行开始写入
+		try {
+			workbook = Workbook.createWorkbook(new File(filePath)); // 创建Excel文件
+			sheet = workbook.createSheet(sheetName, 0); // 创建名为 sheetName 的工作簿
+
+			this.writeCol(sheet, columnName, 0); // 首先将列名写入第一行
+
+			// 将结果集写入
+			while (rs.next()) {
+				Vector col = new Vector(); // 用以保存一行数据
+
+				for (int i = 1; i <= columnName.size(); i++) { // 将一行内容保存在col中
+					col.add(rs.getString(i));
+				}
+				// 写入Excel
+				this.writeCol(sheet, col, rowNum++);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭
+				workbook.write();
+				workbook.close();
+				rs.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	public void WriteExcel3(List<User> users, String filePath, String sheetName,
+							Vector columnName) {
+		WritableWorkbook workbook = null;
+		WritableSheet sheet = null;
+
+		int rowNum = 1; // 从第2行开始写入
+		try {
+			workbook = Workbook.createWorkbook(new File(filePath)); // 创建Excel文件
+			sheet = workbook.createSheet(sheetName, 0); // 创建名为 sheetName 的工作簿
+
+			this.writeCol(sheet, columnName, 0); // 首先将列名写入第一行
+
+			// 将结果集写入
+			for (int j=0;j<users.size();j++){
+				Vector col = new Vector(); // 用以保存一行数据
+
+				col.add(users.get(j).getSm_name());
+				col.add(users.get(j).getSm_time());
+				col.add(users.get(j).getSm_phone());
+				col.add(users.get(j).getSm_card());
+				col.add(users.get(j).getSm_color());
+				col.add(users.get(j).getProtect_type());
+				col.add(users.get(j).getIshot());
+				col.add(users.get(j).getIskey());
+				col.add(users.get(j).getIstoken());
+				col.add(users.get(j).getHandler_unit());
+				// 写入Excel
+				this.writeCol(sheet, col, rowNum++);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭
+				workbook.write();
+				workbook.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	public void WriteExcel2(ResultSet rs, String filePath, String sheetName,
+						   Vector columnName, String time1, String time2) {
+		WritableWorkbook workbook = null;
+		WritableSheet sheet = null;
+
+		int rowNum = 2; // 从第一行开始写入
+		try {
+			workbook = Workbook.createWorkbook(new File(filePath)); // 创建Excel文件
+			sheet = workbook.createSheet(sheetName, 0); // 创建名为 sheetName 的工作簿
+
+			this.writeCol(sheet, columnName, 1); // 首先将列名写入
+
+			// 写入时间
+			Vector col2 = new Vector(); // 用以保存一行数据
+			col2.add("统计时间-:"+time1+"到"+time2);
+			this.writeCol(sheet, col2, 0);
+			// 将结果集写入
+			while (rs.next()) {
+				Vector col = new Vector(); // 用以保存一行数据
+
+				for (int i = 1; i <= columnName.size(); i++) { // 将一行内容保存在col中
+					col.add(rs.getString(i));
+				}
+				// 写入Excel
+				this.writeCol2(sheet, col, rowNum++);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭
+				workbook.write();
+				workbook.close();
+				rs.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	public void WriteExcel4(ArrayList<ArrayList> aa, String filePath, String sheetName,
+							Vector columnName, String time1, String time2) {
+		WritableWorkbook workbook = null;
+		WritableSheet sheet = null;
+
+		int rowNum = 2; // 从第一行开始写入
+		try {
+			workbook = Workbook.createWorkbook(new File(filePath)); // 创建Excel文件
+			sheet = workbook.createSheet(sheetName, 0); // 创建名为 sheetName 的工作簿
+
+			this.writeCol(sheet, columnName, 1); // 首先将列名写入
+
+			// 写入时间
+			Vector col2 = new Vector(); // 用以保存一行数据
+			col2.add("统计时间-:"+time1+"到"+time2);
+			this.writeCol(sheet, col2, 0);
+			// 将结果集写入
+			for (int i=0; i<aa.size(); i++){
+				Vector col = new Vector(); // 用以保存一行数据
+
+				for (int j = 0; j < aa.get(i).size(); j++) { // 将一行内容保存在col中
+					col.add(aa.get(i).get(j));
+				}
+				// 写入Excel
+				this.writeCol2(sheet, col, rowNum++);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭
+				workbook.write();
+				workbook.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	public void WriteExcel5(ArrayList<ArrayList<String>> aa, ArrayList<String> al, ArrayList<String> al2, ArrayList<String> al_1, String filePath, String sheetName,
+							Vector columnName, String time1, String time2, String place) {
+		WritableWorkbook workbook = null;
+		WritableSheet sheet = null;
+
+		int rowNum = 3; // 从第四行开始写入具体数据
+		try {
+			workbook = Workbook.createWorkbook(new File(filePath)); // 创建Excel文件
+			sheet = workbook.createSheet(sheetName, 0); // 创建名为 sheetName 的工作簿
+
+			this.writeCol(sheet, columnName, 1); // 首先第二行将列名写入
+
+			// 写入时间
+			Vector col2 = new Vector(); // 用以保存一行数据
+			col2.add("统计时间-:"+time1+"到"+time2);
+			col2.add(" ");
+			col2.add(" ");
+			col2.add(" ");
+			col2.add(" ");
+			col2.add("订单号:"+place);
+			this.writeCol(sheet, col2, 0);    // 第一行写入时间、订单号
+			// 将结果集写入
+			for (int i=0; i<aa.size(); i++){
+				Vector col = new Vector(); // 用以保存一行数据
+				for (int j = 0; j < aa.get(i).size(); j++) { // 将一行内容保存在col中
+					col.add(aa.get(i).get(j));
+				}
+				// 写入Excel
+				this.writeCol2(sheet, col, rowNum++);
+			}
+
+			Vector col3 = new Vector();
+			col3.add("-价格");
+			for (int j=0; j<al.size(); j++){
+				col3.add(al.get(j).toString());
+			}
+			this.writeCol2(sheet, col3, 2);
+
+			Vector col4 = new Vector();
+			col4.add("剩余数-");
+			for (int j=0; j<al2.size(); j++){
+				col4.add(al2.get(j).toString());
+			}
+			this.writeCol2(sheet, col4, rowNum+1);
+
+			Vector col5 = new Vector();
+			col5.add("走货数-");
+			for (int j=0; j<al_1.size(); j++){
+				col5.add(al_1.get(j).toString());
+			}
+			this.writeCol2(sheet, col5, rowNum);
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭
+				workbook.write();
+				workbook.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	/***
+	 * 将数组写入工作簿
+	 * 
+	 * @param sheet
+	 *            要写入的工作簿
+	 * @param col
+	 *            要写入的数据数组
+	 * @param rowNum
+	 *            要写入哪一行
+	 * @throws WriteException
+	 * @throws RowsExceededException
+	 */
+	private void writeCol(WritableSheet sheet, Vector col, int rowNum)
+			throws RowsExceededException, WriteException {
+		int size = col.size(); // 获取集合大小
+
+		for (int i = 0; i < size; i++) { // 写入每一列
+			Label label = new Label(i, rowNum, (String) col.get(i));
+			sheet.addCell(label);
+		}
+	}
+
+	// 处理工号和姓名的算法
+	private void writeCol2(WritableSheet sheet, Vector col, int rowNum)
+			throws RowsExceededException, WriteException {
+		int size = col.size(); // 获取集合大小
+
+		for (int i = 0; i < size; i++) { // 写入每一列
+			if(i == 0) {
+				String name1 = (String) col.get(i);
+				int n = name1.indexOf("-");
+				String name2 = name1.substring(0, n);
+				Label label = new Label(i, rowNum, name2);
+				sheet.addCell(label);
+			}else{
+				Label label = new Label(i, rowNum, (String) col.get(i));
+				sheet.addCell(label);
+			}
+		}
+	}
+}

+ 41 - 0
bigData/src/com/happy/Until/GPS.java

@@ -0,0 +1,41 @@
+package com.happy.Until;
+
+import org.json.JSONObject;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GPS {
+
+    public static Map<String, String> getPosition(String lng, String lat) throws IOException {
+//        String lng  = "115.362635"; // 经度
+//        String lat = "28.861296";  // 伟度
+        Map<String,String> map = new HashMap<>();
+        String address = "";
+        String town = "";
+        try {
+            URL url = new URL("http://api.map.baidu.com/geocoder/v2/?ak=wPPxsfCtNFm4PqEV68jbDdjP7U4twstj&callback=renderReverse&location=" + lat + "," + lng + "&output=json&pois=1&extensions_town=true");
+            HttpURLConnection ucon = (HttpURLConnection) url.openConnection();
+            ucon.connect();
+            InputStream in = ucon.getInputStream();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+            String str = reader.readLine();
+            str = str.substring(str.indexOf("(") + 1, str.length() - 1);
+            JSONObject jsonObject = new JSONObject(str);
+            System.out.println(jsonObject.getJSONObject("result").getJSONObject("addressComponent").getString("town"));
+            address = jsonObject.getJSONObject("result").getString("sematic_description");
+            town = jsonObject.getJSONObject("result").getJSONObject("addressComponent").getString("town");
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        map.put("town",town);
+        map.put("address",address);
+        return map;
+    }
+
+}

+ 28 - 0
bigData/src/com/happy/Until/GetHttpParam.java

@@ -0,0 +1,28 @@
+package com.happy.Until;
+
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.Feature;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class GetHttpParam {
+
+    public static JSONObject getHttpParam(HttpServletRequest request){
+        //处理业务业务
+        JSONObject jsonObject = new JSONObject();
+        try {
+            BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
+            StringBuilder responseStrBuilder = new StringBuilder();
+            String inputStr;
+            while ((inputStr = streamReader.readLine()) != null)
+                responseStrBuilder.append(inputStr);
+
+            jsonObject = JSONObject.parseObject(responseStrBuilder.toString(), Feature.OrderedField);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return jsonObject;
+    }
+}

+ 188 - 0
bigData/src/com/happy/Until/HttpUtils.java

@@ -0,0 +1,188 @@
+package com.happy.Until;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.happy.Model.Common.Token;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * http post 提交 和 get请求
+ * 
+ * @author QT-666
+ * 
+ */
+public class HttpUtils {
+	private static RequestConfig requestConfig = RequestConfig.custom()
+			.setSocketTimeout(15000).setConnectTimeout(15000)
+			.setConnectionRequestTimeout(15000).build();
+
+	public static String get(String url, Map<String, String> params) {
+		CloseableHttpClient httpClient = null;
+		HttpGet httpGet = null;
+		String re = "";
+		try {
+			httpClient = HttpClients.createDefault();
+			RequestConfig requestConfig = RequestConfig.custom()
+					.setSocketTimeout(20000).setConnectTimeout(20000).build();
+			String ps = "";
+			for (String pKey : params.keySet()) {
+				if (!"".equals(ps)) {
+					ps = ps + "&";
+				}
+				ps = pKey + "=" + params.get(pKey);
+			}
+			if (!"".equals(ps)) {
+				url = url + "?" + ps;
+			}
+			httpGet = new HttpGet(url);
+			httpGet.setConfig(requestConfig);
+			CloseableHttpResponse response = httpClient.execute(httpGet);
+			HttpEntity httpEntity = response.getEntity();
+			re = EntityUtils.toString(httpEntity, "utf-8");
+		} catch (ClientProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				if (httpGet != null) {
+					httpGet.releaseConnection();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return re;
+	}
+
+	/**
+	 * 发送http post请求
+	 * 
+	 * @param
+	 *
+	 * @param
+	 *
+	 */
+	public static String post(String url, Map<String, String> params) throws IOException {
+		CloseableHttpClient httpClient = null;
+		HttpPost httpPost = null;
+		String re = "";
+		try {
+			httpClient = HttpClients.createDefault();
+			RequestConfig requestConfig = RequestConfig.custom()
+					.setSocketTimeout(20000).setConnectTimeout(20000).build();
+			httpPost = new HttpPost(url);
+			httpPost.setConfig(requestConfig);
+			List<NameValuePair> ps = new ArrayList<NameValuePair>();
+			for (String pKey : params.keySet()) {
+				ps.add(new BasicNameValuePair(pKey, params.get(pKey)));
+			}
+			httpPost.setEntity(new UrlEncodedFormEntity(ps));
+			CloseableHttpResponse response = httpClient.execute(httpPost);
+			HttpEntity httpEntity = response.getEntity();
+			re = EntityUtils.toString(httpEntity, "utf-8");
+		} catch (ClientProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				if (httpPost != null) {
+					httpPost.releaseConnection();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return re;
+	}
+
+	/**
+	 * 发送post请求Https,参数是字符串
+	 *
+	 * @param httpPost
+	 * @return
+	 */
+	public static String post(String url, String body) throws Exception {
+		String str = "";
+		CloseableHttpClient httpClient = null;
+		HttpPost httpPost = null;
+		try {
+			httpClient = HttpClients.createDefault();
+			RequestConfig requestConfig = RequestConfig.custom()
+					.setSocketTimeout(20000).setConnectTimeout(20000).build();
+			httpPost = new HttpPost(url);
+			httpPost.setConfig(requestConfig);
+			httpPost.setEntity(new StringEntity(body, "utf-8"));
+			CloseableHttpResponse response = httpClient.execute(httpPost);
+			HttpEntity httpEntity = response.getEntity();
+			str = EntityUtils.toString(httpEntity, "utf-8");
+
+		} catch (ClientProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				if (httpPost != null) {
+					httpPost.releaseConnection();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return new String(str.getBytes("iso-8859-1"));
+	}
+
+
+
+	public static String get(String strURL) throws Exception {
+		URL url = new URL(strURL);
+		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+		httpConn.setRequestMethod("GET");
+		httpConn.connect();
+
+		BufferedReader reader = new BufferedReader(new InputStreamReader(
+				httpConn.getInputStream(), "utf-8"));
+		String line;
+		StringBuffer buffer = new StringBuffer();
+		while ((line = reader.readLine()) != null) {
+			buffer.append(line);
+		}
+		reader.close();
+		httpConn.disconnect();
+
+		return buffer.toString();
+	}
+
+
+}

+ 49 - 0
bigData/src/com/happy/Until/MD5Utils.java

@@ -0,0 +1,49 @@
+package com.happy.Until;
+
+import java.security.MessageDigest;
+
+public class MD5Utils {
+
+    /***
+     * MD5加码 生成32位md5码
+     */
+    public static String toMD5(String inStr){
+        MessageDigest md5 = null;
+        try{
+            md5 = MessageDigest.getInstance("MD5");
+        }catch (Exception e){
+            System.out.println(e.toString());
+            e.printStackTrace();
+            return "";
+        }
+        char[] charArray = inStr.toCharArray();
+        byte[] byteArray = new byte[charArray.length];
+
+        for (int i = 0; i < charArray.length; i++)
+            byteArray[i] = (byte) charArray[i];
+        byte[] md5Bytes = md5.digest(byteArray);
+        StringBuffer hexValue = new StringBuffer();
+        for (int i = 0; i < md5Bytes.length; i++){
+            int val = ((int) md5Bytes[i]) & 0xff;
+            if (val < 16)
+                hexValue.append("0");
+            hexValue.append(Integer.toHexString(val));
+        }
+        return hexValue.toString();
+
+    }
+
+    /**
+     * 加密解密算法 执行一次加密,两次解密
+     */
+    public static String unlock(String inStr){
+
+        char[] a = inStr.toCharArray();
+        for (int i = 0; i < a.length; i++){
+            a[i] = (char) (a[i] ^ 't');
+        }
+        String s = new String(a);
+        return s;
+
+    }
+}

+ 247 - 0
bigData/src/com/happy/Until/Mijie.java

@@ -0,0 +1,247 @@
+package com.happy.Until;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.happy.Model.Ban.BanSui;
+import com.happy.Model.Ban.Detail;
+import com.happy.Model.Ban.Items;
+import com.happy.Model.Ban.Results;
+import com.happy.Model.Common.Follow;
+import com.happy.Model.Common.FollowData;
+import com.happy.Model.Common.Token;
+import com.happy.Model.Common.Trajectory;
+import com.happy.Model.User;
+import com.happy.common.http.HttpsClient;
+import com.happy.service.UserService;
+import net.sf.json.JSONArray;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class Mijie {
+
+    @Resource
+    public UserService userService;
+
+    public JSONObject query(int id) throws Exception {
+        JSONObject resultJson = new JSONObject();
+        Gson gson = new Gson();
+        Map<String, String> req = new HashMap<>();
+        req.put("client_id", "32f7d83bb4304822b17083ac49a23b15");
+        req.put("client_secret", "59250fe86b674d8bb859a5ccb7164c22");
+        req.put("grant_type", "client_credentials");
+        // http://58.17.73.115:9001
+        String msg = HttpUtils.post("https://app.jxjaly.com/jingan-epana/api/oauth/token", req);
+        Token token = gson.fromJson(msg.toString(), new TypeToken<Token>(){}.getType());
+        String ticket = token.getData().getAccess_token();
+        Map<String, String> req2 = new HashMap<>();
+        List<User> list = userService.queryMById(id);
+        if (list==null){
+            resultJson.put("code", 500);
+            resultJson.put("msg", "id参数异常");
+            return resultJson;
+        }
+        User user = list.get(0);
+        String start_time = user.getSm_time().substring(0, 10)+" 00:00:00";
+        String end_time = user.getSm_time().substring(0,10)+" 24:60:60";
+        req2.put("startTime", start_time);
+        req2.put("endTime", end_time);
+        req2.put("uuid", user.getUuid());
+        req2.put("accessToken", ticket);
+        String mess = HttpUtils.post("https://app.jxjaly.com/jingan-epana/api/streamQuery/selectThirdStreamQuery", req2);
+        HashMap<String,Object> map = gson.fromJson(mess.toString(), new TypeToken<HashMap<String,Object>>(){}.getType());
+        String code = map.get("code").toString();
+        if (code.equals("500.0")){
+            resultJson.put("code", 502);
+            resultJson.put("msg", "未查询伴随人员");
+            return resultJson;
+        }
+        Follow follow = gson.fromJson(mess.toString(), new TypeToken<Follow>(){}.getType());
+        FollowData followData = follow.getFollowData();
+        ArrayList<Trajectory> at = followData.getAt();
+        if (at.size()==0 ){
+            resultJson.put("code", 505);
+            resultJson.put("msg", "未查询到数据");
+            return resultJson;
+        }
+        resultJson.put("code", 200);
+        resultJson.put("msg", "成功");
+        resultJson.put("data", at);
+        return resultJson;
+    }
+
+    public JSONObject queryByZzM(int id) throws Exception {
+        Gson gson = new Gson();
+        JSONObject resultJson = new JSONObject();
+        List<User> list = userService.queryMById(id);
+        if (list==null){
+            resultJson.put("code", 500);
+            resultJson.put("msg", "id参数异常");
+            return resultJson;
+        }
+        User user = list.get(0);
+        System.out.println(user.getSm_time());
+        if (user.getSm_phone().equals("") || user.getSm_phone()==null || user.getSm_phone().indexOf("*")>0){
+            resultJson.put("code", 502);
+            resultJson.put("msg", "未获取正确的手机号");
+            return resultJson;
+        }
+        Integer startTime = TimeExchange.StringToTimestamp(TimeExchange.TimeRangeD(user.getSm_time()));
+        Integer endTime = TimeExchange.StringToTimestamp(TimeExchange.TimeRangeI(user.getSm_time()));
+        JSONObject json = new JSONObject();
+        json.put("str", user.getSm_phone());
+        json.put("type", "2");
+        json.put("threshold", "50");
+        json.put("spanTime", "60");
+        ArrayList<HashMap<String, String>> ah = new ArrayList<>();
+        HashMap<String, String> hs = new HashMap<>();
+        hs.put("startTime", String.valueOf(startTime));
+        hs.put("endTime", String.valueOf(endTime));
+        ah.add(hs);
+        JSONArray jsonArray= JSONArray.fromObject(ah);
+        json.put("timeList", jsonArray);
+        // http://6.205.66.7:8000/rest/analysis/accompany
+        // http://58.17.42.179:8000/rest/analysis/accompany
+        String msg = HttpsClient.sendJson2("http://6.205.66.7:8000/rest/analysis/accompany", json);
+        BanSui bs = gson.fromJson(msg.toString(), new TypeToken<BanSui>(){}.getType());
+        List<Detail> ld = new ArrayList<>();
+        if (bs.getResponseStatus().getStatusCode().equals("0")){
+            Results results = bs.getResults();
+            if (results!=null){
+                ArrayList<Items> items = results.getItems();
+                if (items.size()>0){
+                    for (int i=0;i<items.size();i++){
+                        ArrayList<Detail> details = items.get(i).getDetail();
+                        if (details.size()>0){
+                            if (details.get(0).getTargetStr().length() == 11){
+                                Detail dt = new Detail();
+                                dt.setName("***");
+                                dt.setTargetStr(details.get(0).getTargetStr());
+                                dt.setFullPath(details.get(0).getFullPath());
+                                dt.setTimestamp(TimeExchange.timestampToString(Integer.parseInt(details.get(0).getTimestamp())));
+                                ld.add(dt);
+                            }
+                        }
+                    }
+                }
+            }
+
+        }
+        resultJson.put("code", 200);
+        resultJson.put("data", ld);
+        return resultJson;
+    }
+
+    public JSONObject queryCarByZzM(int id) throws Exception {
+        Gson gson = new Gson();
+        JSONObject resultJson = new JSONObject();
+        List<User> list = userService.queryMById(id);
+        if (list==null){
+            resultJson.put("code", 500);
+            resultJson.put("msg", "id参数异常");
+            return resultJson;
+        }
+        User user = list.get(0);
+        System.out.println(user.getSm_time());
+        if (user.getSm_phone().equals("") || user.getSm_phone()==null || user.getSm_phone().indexOf("*")>0){
+            resultJson.put("code", 502);
+            resultJson.put("msg", "未获取正确的手机号");
+            return resultJson;
+        }
+        Integer startTime = TimeExchange.StringToTimestamp(TimeExchange.TimeRangeD(user.getSm_time()));
+        Integer endTime = TimeExchange.StringToTimestamp(TimeExchange.TimeRangeI(user.getSm_time()));
+        JSONObject json = new JSONObject();
+        json.put("str", user.getSm_phone());
+        System.out.println(user.getSm_phone());
+        json.put("type", "1");
+        json.put("threshold", "50");
+        json.put("spanTime", "60");
+        ArrayList<HashMap<String, String>> ah = new ArrayList<>();
+        HashMap<String, String> hs = new HashMap<>();
+        hs.put("startTime", String.valueOf(startTime));
+        hs.put("endTime", String.valueOf(endTime));
+        ah.add(hs);
+        JSONArray jsonArray= JSONArray.fromObject(ah);
+        json.put("timeList", jsonArray);
+        // http://6.205.66.7:8000/rest/analysis/accompany
+        // http://58.17.42.179:8000/rest/analysis/accompany
+        String msg = HttpsClient.sendJson2("http://6.205.66.7:8000/rest/analysis/accompany", json);
+        BanSui bs = gson.fromJson(msg.toString(), new TypeToken<BanSui>(){}.getType());
+        List<Detail> ld = new ArrayList<>();
+        if (bs.getResponseStatus().getStatusCode().equals("0")){
+            Results results = bs.getResults();
+            if (results!=null){
+                ArrayList<Items> items = results.getItems();
+                if (items.size()>0){
+                    for (int i=0;i<items.size();i++){
+                        ArrayList<Detail> details = items.get(i).getDetail();
+                        if (details.size()>0){
+                            if (details.get(0).getTargetStr().length() == 7){
+                                Detail dt = new Detail();
+                                dt.setName("***");
+                                dt.setTargetStr(details.get(0).getTargetStr());
+                                dt.setFullPath(details.get(0).getFullPath());
+                                dt.setTimestamp(TimeExchange.timestampToString(Integer.parseInt(details.get(0).getTimestamp())));
+                                ld.add(dt);
+                            }
+                        }
+                    }
+                }
+            }
+
+        }
+        resultJson.put("code", 200);
+        resultJson.put("data", ld);
+        return resultJson;
+    }
+
+    public static void main(String[] args) throws Exception {
+        Gson gson = new Gson();
+        JSONObject json = new JSONObject();
+        json.put("str", "19198496653");
+        json.put("type", "1");
+        json.put("threshold", "50");
+        json.put("spanTime", "60");
+        ArrayList<HashMap<String, String>> ah = new ArrayList<>();
+        HashMap<String, String> hs = new HashMap<>();
+        hs.put("startTime", "1642751387");
+        hs.put("endTime", "1642751747");
+        ah.add(hs);
+        JSONArray jsonArray= JSONArray.fromObject(ah);
+        json.put("timeList", jsonArray);
+        // http://6.205.66.7:8000/rest/analysis/accompany
+        // http://58.17.42.179:8000/rest/analysis/accompany
+        String msg = HttpsClient.sendJson2("https://app.jxjaly.com/jingan-epana/rest/analysis/accompany", json);
+        BanSui bs = gson.fromJson(msg.toString(), new TypeToken<BanSui>(){}.getType());
+        List<Detail> ld = new ArrayList<>();
+        if (bs.getResponseStatus().getStatusCode().equals("0")){
+            Results results = bs.getResults();
+            if (results!=null){
+                ArrayList<Items> items = results.getItems();
+                if (items.size()>0){
+                    for (int i=0;i<items.size();i++){
+                        ArrayList<Detail> details = items.get(i).getDetail();
+                        if (details.size()>0){
+                            if (details.get(0).getTargetStr().length() == 7){
+                                Detail dt = new Detail();
+                                dt.setName("***");
+                                dt.setTargetStr(details.get(0).getTargetStr());
+                                dt.setFullPath(details.get(0).getFullPath());
+                                dt.setTimestamp(TimeExchange.timestampToString(Integer.parseInt(details.get(0).getTimestamp())));
+                                ld.add(dt);
+                            }
+                        }
+                    }
+                }
+            }
+
+        }
+        System.out.println(ld);
+    }
+}

+ 62 - 0
bigData/src/com/happy/Until/MyPageList.java

@@ -0,0 +1,62 @@
+package com.happy.Until;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author: codingliang
+ * @Description: 分页结果封装
+ * @Date: 2022-01-11 17:17
+ * @Version: V1.0
+ **/
+public class MyPageList<T> {
+
+    /**
+     * 当前页
+     */
+    private Long page;
+    /**
+     * 总记录数量
+     */
+    private Long totalRows;
+    /**
+     * 总页数
+     */
+    private Long pages;
+    /**
+     * 记录
+     */
+    private List<T> records = new ArrayList();
+
+    public Long getPage() {
+        return page;
+    }
+
+    public void setPage(Long page) {
+        this.page = page;
+    }
+
+    public Long getTotalRows() {
+        return totalRows;
+    }
+
+    public void setTotalRows(Long totalRows) {
+        this.totalRows = totalRows;
+    }
+
+    public Long getPages() {
+        return pages;
+    }
+
+    public void setPages(Long pages) {
+        this.pages = pages;
+    }
+
+    public List<T> getRecords() {
+        return records;
+    }
+
+    public void setRecords(List<T> records) {
+        this.records = records;
+    }
+}

+ 53 - 0
bigData/src/com/happy/Until/ResUtil.java

@@ -0,0 +1,53 @@
+package com.happy.Until;
+
+import org.apache.poi.ss.usermodel.Workbook;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+public class ResUtil {
+
+	public static void write(Object o, HttpServletResponse response)
+			throws Exception {
+		response.setContentType("text/html;charset=utf-8");
+//		response.setHeader("Access-Control-Allow-Origin", "*");
+		PrintWriter out = response.getWriter();
+		out.println(o.toString());
+		out.flush();
+		out.close();
+	}
+
+	public static void write(String o, HttpServletResponse response)
+			throws Exception {
+		response.setContentType("text/html;charset=utf-8");
+		PrintWriter out = response.getWriter();
+		out.println(o.toString());
+		out.flush();
+		out.close();
+	}
+
+	public static void writeJson(HttpServletResponse respone, String result) {
+		respone.setContentType("application/json;charset=utf-8");
+		PrintWriter out;
+		try {
+			out = respone.getWriter();
+			out.print(result);
+			out.flush();
+			out.close();
+		} catch (Exception e) { 
+			// //System.out.println("Comm_Util_writeJson---->" + e);
+		}
+	}
+
+	public static void export(HttpServletResponse response, Workbook wb,
+			String fileName) throws Exception {
+		response.setHeader("Content-Disposition", "attachment;filename="
+				+ new String(fileName.getBytes("utf-8"), "iso8859-1"));
+		response.setContentType("application/ynd.ms-excel;charset=UTF-8");
+		OutputStream out = response.getOutputStream();
+		wb.write(out);
+		out.flush();
+		out.close();
+	}
+}

+ 52 - 0
bigData/src/com/happy/Until/ResponseUtil.java

@@ -0,0 +1,52 @@
+package com.happy.Until;
+
+import org.apache.poi.ss.usermodel.Workbook;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+public class ResponseUtil {
+
+	public static void write(Object o, HttpServletResponse response)
+			throws Exception {
+		response.setContentType("text/html;charset=utf-8");
+		PrintWriter out = response.getWriter();
+		out.println(o.toString());
+		out.flush();
+		out.close();
+	}
+
+	public static void write(String o, HttpServletResponse response)
+			throws Exception {
+		response.setContentType("text/html;charset=utf-8");
+		PrintWriter out = response.getWriter();
+		out.println(o.toString());
+		out.flush();
+		out.close();
+	}
+
+	public static void writeJson(HttpServletResponse respone, String result) {
+		respone.setContentType("application/json;charset=utf-8");
+		PrintWriter out;
+		try {
+			out = respone.getWriter();
+			out.print(result);
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			// //System.out.println("Comm_Util_writeJson---->" + e);
+		}
+	}
+
+	public static void export(HttpServletResponse response, Workbook wb,
+			String fileName) throws Exception {
+		response.setHeader("Content-Disposition", "attachment;filename="
+				+ new String(fileName.getBytes("utf-8"), "iso8859-1"));
+		response.setContentType("application/ynd.ms-excel;charset=UTF-8");
+		OutputStream out = response.getOutputStream();
+		wb.write(out);
+		out.flush();
+		out.close();
+	}
+}

+ 103 - 0
bigData/src/com/happy/Until/ResultUtil.java

@@ -0,0 +1,103 @@
+package com.happy.Until;
+
+import com.happy.constant.ResultStatusCode;
+
+/**
+ * @author yp
+ * @date 2019/10/31 0:02
+ */
+public class ResultUtil {
+    private static final long serialVersionUID = 1L;
+    // 响应状态
+    protected Integer status = 0;
+
+    // 响应消息
+    protected String msg;
+
+    // 响应数据
+    protected Object data;
+
+    public static ResultUtil buildOK() {
+        return new ResultUtil(ResultStatusCode.OK);
+    }
+
+    public static ResultUtil buildOK(Object data) {
+        return ResultUtil.build(ResultStatusCode.OK, data);
+    }
+
+    public static ResultUtil build(ResultStatusCode rsc) {
+        return new ResultUtil(rsc.getStatus(), rsc.getMsg(), null);
+    }
+
+    public static ResultUtil build(ResultStatusCode rsc, Object data) {
+        return new ResultUtil(rsc.getStatus(), rsc.getMsg(), data);
+    }
+
+    public static ResultUtil build(Integer status, String msg, Object data) {
+        return new ResultUtil(status, msg, data);
+    }
+
+    public static ResultUtil ok(Object data) {
+        return new ResultUtil(data);
+    }
+
+    public static ResultUtil ok() {
+        return new ResultUtil(null);
+    }
+
+    public ResultUtil() {
+
+    }
+
+    public static ResultUtil build(Integer status, String msg) {
+        return new ResultUtil(status, msg, null);
+    }
+
+    public ResultUtil(Integer status, String msg, Object data) {
+        this.status = status;
+        this.msg = msg;
+        this.data = data;
+    }
+
+    public ResultUtil(Object data) {
+        this.status = 200;
+        this.msg = "OK";
+        this.data = data;
+    }
+
+    public Boolean isOK() {
+        if (null == this.status) {
+            return false;
+        }
+        return this.status == 200;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return "ResultUtil [status=" + status + ", msg=" + msg + ", data=" + data + "]";
+    }
+}

+ 250 - 0
bigData/src/com/happy/Until/TimeExchange.java

@@ -0,0 +1,250 @@
+package com.happy.Until;
+
+import org.apache.commons.lang.time.DateUtils;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 时间转化工具 date转为时间戳 时间戳转date 互相与String的转换
+ * 所有出现的String time 格式都必须为(yyyy-MM-dd HH:mm:ss),否则出错
+ * @author 赵仁杰
+ *
+ */
+public class TimeExchange {
+
+    /**
+     * String(yyyy-MM-dd HH:mm:ss) 转 Date
+     *
+     * @param time
+     * @return
+     * @throws ParseException
+     */
+    // String date = "2010/05/04 12:34:23";
+    public static Date StringToDate(String time) throws ParseException {
+
+        Date date = new Date();
+        // 注意format的格式要与日期String的格式相匹配
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            date = dateFormat.parse(time);
+            System.out.println(date.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return date;
+    }
+
+    /**
+     * Date转为String(yyyy-MM-dd HH:mm:ss)
+     *
+     * @param time
+     * @return
+     */
+    public static String DateToString(Date time) {
+        String dateStr = "";
+        Date date = new Date();
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH/mm/ss");
+        try {
+            dateStr = dateFormat.format(time);
+            System.out.println(dateStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return dateStr;
+    }
+    /**
+     * String(yyyy-MM-dd HH:mm:ss)转10位时间戳
+     * @param time
+     * @return
+     */
+    public static Integer StringToTimestamp(String time){
+
+        int times = 0;
+        try {
+            times = (int) ((Timestamp.valueOf(time).getTime())/1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if(times==0){
+            System.out.println("String转10位时间戳失败");
+        }
+        return times;
+
+    }
+    /**
+     * 10位int型的时间戳转换为String(yyyy-MM-dd HH:mm:ss)
+     * @param time
+     * @return
+     */
+    public static String timestampToString(Integer time){
+        //int转long时,先进行转型再进行计算,否则会是计算结束后在转型
+        long temp = (long)time*1000;
+        Timestamp ts = new Timestamp(temp);
+        String tsStr = "";
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            //方法一
+            tsStr = dateFormat.format(ts);
+            System.out.println(tsStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return tsStr;
+    }
+    /**
+     * 10位时间戳转Date
+     * @param time
+     * @return
+     */
+    public static Date TimestampToDate(Integer time){
+        long temp = (long)time*1000;
+        Timestamp ts = new Timestamp(temp);
+        Date date = new Date();
+        try {
+            date = ts;
+            //System.out.println(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return date;
+    }
+    /**
+     * Date类型转换为10位时间戳
+     * @param time
+     * @return
+     */
+    public static Integer DateToTimestamp(Date time){
+        Timestamp ts = new Timestamp(time.getTime());
+
+        return (int) ((ts.getTime())/1000);
+    }
+
+    // 当前时间加5分钟
+    public static String TimeRangeI(String time) throws ParseException {
+        // 当前时间+5分钟
+        Date endTime = DateUtils.addMinutes(StringToDate(time), 300);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(endTime);
+    }
+
+    // 当前时间减5分钟
+    public static String TimeRangeD(String time) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(time));
+        nowTime2.add(Calendar.MINUTE, -300);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 获取当前日期
+    public static String getDate(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
+        return sp.format(new Date());
+    }
+
+    // 获取当前时间
+    public static String getTime(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sp.format(new Date());
+    }
+
+    // 获取当前时间
+    public static String getHour(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH");
+        return sp.format(new Date());
+    }
+
+    public static String getYear(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy");
+        return sp.format(new Date());
+    }
+
+    public static String getMonth(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM");
+        return sp.format(new Date());
+    }
+
+    // 获取前面时间
+    public static String getLastHour(int m){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH");
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.HOUR, m);
+        String date = sp.format(calendar.getTime());
+        return date;
+    }
+
+    // 获取昨日日期
+    public static String getYesDate(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.DATE, -1);
+        String date = sp.format(calendar.getTime());
+        return date;
+    }
+
+    // 获取昨日日期
+    public static String getOnlyHour(){
+        SimpleDateFormat sp = new SimpleDateFormat("HH");
+        return sp.format(new Date());
+    }
+
+    /**
+     * 计算两个日期的时间差
+     * @param time1
+     * @param time2
+     * @return
+     */
+    public static double getTimeDifference(String time1, String time2) {
+        SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long t1 = 0L;
+        long t2 = 0L;
+        try {
+            t1 = timeformat.parse(time1).getTime();
+        } catch (ParseException e) {
+        // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        try {
+            t2 = timeformat.parse(time2).getTime();
+        } catch (ParseException e) {
+       // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        //因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
+        double hours=(double) ((t2 - t1)/3600000);
+        double minutes=(double) (((t2 - t1)/1000-hours*3600)/60/60);
+        return hours+minutes;
+    }
+
+    // 获取最近日期
+    public static String getLastDay(Integer m){
+        StringBuilder str = new StringBuilder("");
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        for (int i=0; i>-m; i--){
+            if (i==-(m-1)){
+                Calendar calendar = Calendar.getInstance();
+                calendar.add(Calendar.DATE, i);
+                str.append(simpleDateFormat.format(calendar.getTime()));
+            } else {
+                Calendar calendar = Calendar.getInstance();
+                calendar.add(Calendar.DATE, i);
+                str.append(simpleDateFormat.format(calendar.getTime())).append(",");
+            }
+        }
+        return str.toString();
+    }
+
+    public static void main(String [] args) throws ParseException {
+        System.out.println(getLastHour(-1));
+    }
+
+}
+

+ 21 - 0
bigData/src/com/happy/Until/TokenUtil.java

@@ -0,0 +1,21 @@
+package com.happy.Until;
+
+import org.apache.commons.lang.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class TokenUtil {
+    /**
+     * 获取请求的token
+     */
+    public static String getRequestToken(HttpServletRequest httpRequest) {
+
+        //从header中获取token
+        String token = httpRequest.getHeader("token");
+        //如果header中不存在token,则从参数中获取token
+        if (StringUtils.isBlank(token)) {
+            token = httpRequest.getParameter("token");
+        }
+        return token;
+    }
+}

+ 21 - 0
bigData/src/com/happy/Until/TransactionConfig.java

@@ -0,0 +1,21 @@
+package com.happy.Until;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+
+import javax.sql.DataSource;
+
+@Configuration
+public class TransactionConfig {
+    @Bean
+    public PlatformTransactionManager transactionManager(DataSource dataSource) {
+        // PlatformTransactionManager 类似于一个事务定义的标准
+        // DataSource 也是一个标准 规范数据源
+        DataSourceTransactionManager transactionManager =
+                new DataSourceTransactionManager(dataSource);
+        // transactionManager.setDataSource(dataSource); 二选一即可
+        return transactionManager;
+    }
+}