Commit 07602a7b authored by kang.nie@inzymeits.com's avatar kang.nie@inzymeits.com
Browse files

提交代码

parent e0c7be76
package com.ssi.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
/**
* @author SunnyHotz
* @PackageName:com.ssi.task
* @ClassName:Test
* @Description:
* @date 2022/7/18 18:17
*/
public class AESUtil {
private static SecretKeySpec secretKey;
private static IvParameterSpec initVectorKey;
private static byte[] key ;
private static String decryptedString;
private static String encryptedString;
public static void setKey(String myKey,String ivKey){
MessageDigest sha = null;
try {
key = myKey.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16); // use only first 128 bit
secretKey = new SecretKeySpec(key, "AES");
byte[] ivKeyBytes = ivKey.getBytes("UTF-8");
ivKeyBytes = Arrays.copyOf(ivKeyBytes, 16);
initVectorKey = new IvParameterSpec(ivKeyBytes);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String getDecryptedString() {
return decryptedString;
}
public static void setDecryptedString(String decryptedString) {
AESUtil.decryptedString = decryptedString;
}
public static String getEncryptedString() {
return encryptedString;
}
public static void setEncryptedString(String encryptedString) {
AESUtil.encryptedString = encryptedString;
}
public static String encrypt(String strToEncrypt)
{
try
{
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey,initVectorKey);
setEncryptedString(Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes("UTF-8"))));
}
catch (Exception e)
{
System.out.println("Error while encrypting: "+e.toString());
}
return encryptedString;
}
public static String decrypt(String strToDecrypt)
{
try
{
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey,initVectorKey);
setDecryptedString(new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt))));
}
catch (Exception e)
{
System.out.println("Error while decrypting: "+e.toString());
}
return decryptedString;
}
public static void main(String args[])
{
final String strToEncrypt = "{\"OperatorID\":\"123456789\",\"OperatorSecret\":\"1234567890abcdef\"}";
final String strPssword = "1234567890abcdef";
AESUtil.setKey(strPssword,strPssword);
AESUtil.encrypt(strToEncrypt.trim());
System.out.println("String to Encrypt: " + strToEncrypt);
System.out.println("Encrypted: " + AESUtil.getEncryptedString());
final String strToDecrypt = AESUtil.getEncryptedString();
AESUtil.decrypt(strToDecrypt);
System.out.println("String To Decrypt : " + strToDecrypt);
System.out.println("Decrypted : " + AESUtil.getDecryptedString());
}
}
package com.ssi.utils;
import com.alibaba.fastjson.JSONObject;
import com.ssi.constant.VehicleConstant;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @author ZhangLiYao
* @version 1.0
* @date 2020/3/4 10:52
*/
public class AuthorizationUtils {
/**
* 获取请求的token
*/
public static String getRequestToken() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//从header中获取token
String token = request.getHeader("Authorization");
//如果header中不存在token,则从参数中获取token
if (org.apache.commons.lang.StringUtils.isBlank(token)) {
token = request.getParameter("Authorization");
}
return token;
}
/**
* 获取当前用户
*/
public static JSONObject getCurUser() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
HttpSession httpSession = request.getSession();
JSONObject jsonObject = (JSONObject) httpSession.getAttribute(VehicleConstant.LOGIN_USER_KEY);
return jsonObject;
}
}
package com.ssi.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 贝位方法相关工具类
*/
public class BayNumUtil {
private static final double EARTH_RADIUS = 6378.137;
/**
* 根据经纬度,计算两点间的距离
*
* @param longitude1 第一个点的经度
* @param latitude1 第一个点的纬度
* @param longitude2 第二个点的经度
* @param latitude2 第二个点的纬度
* @return 返回距离 单位千米
*/
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
// 纬度
double lat1 = Math.toRadians(latitude1);
double lat2 = Math.toRadians(latitude2);
// 经度
double lng1 = Math.toRadians(longitude1);
double lng2 = Math.toRadians(longitude2);
// 纬度之差
double a = lat1 - lat2;
// 经度之差
double b = lng1 - lng2;
// 计算两点距离的公式
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
// 弧长乘地球半径, 返回单位: 千米
s = s * EARTH_RADIUS;
return s;
}
public static void main(String[] args) {
//获取四个经纬点换算出的中心点
bayNumUtil("C:\\Users\\hekai\\Desktop\\采集定位点\\BayNum.json");
//locationTrans("D:\\locationTrans.geojson");
}
/**
* 根据四个点换算出经纬度
* @param path 本地文件
*/
public static void bayNumUtil(String path) {
//[[[117.96810563174562,24.45700681481371],
// [117.96810435443824,24.457001924664915],
// [117.96811146404536,24.45700069948276],
// [117.96811260436358,24.457005485843936],
// [117.96810563174562,24.45700681481371]]]}
// double lng=117.96810563174562;
// double lat=24.45700681481371;
// double lng1=117.96810435443824;
// double lat1=24.457001924664915;
// double lng2=117.96811146404536;
// double lat2=24.45700069948276;
// double lng3=117.96811260436358;
// double lat3=24.457005485843936;
// double totleLng=(lng+lng1+lng2 +lng3)/4;
// double totleLat=(lat+lat1+lat2 +lat3)/4;
// System.out.println((totleLng+0.00000435));
// System.out.println((totleLat+0.0000185));
String s = readJsonFile(path);
JSONObject jobj = JSON.parseObject(s);
JSONArray features = jobj.getJSONArray("features");
for (int i = 0; i < features.size(); i++) {
JSONObject key1 = (JSONObject) features.get(i);
JSONObject geometry = key1.getJSONObject("geometry");
JSONObject properties = key1.getJSONObject("properties");
String Yard = (String) properties.get("Yard");
String Num = (String) properties.get("Num");
if (Yard.equals("617")) {
JSONArray jsonArray = geometry.getJSONArray("coordinates");
JSONArray jsonArray2 = jsonArray.getJSONArray(0);
double lng = 0;
double lat = 0;
double lng1 = 0;
double lat1 = 0;
double lng2 = 0;
double lat2 = 0;
double lng3 = 0;
double lat3 = 0;
for (int j = 0; j < jsonArray2.size(); j++) {
if (j == 0) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(0);
for (int k = 0; k < jsonArray1.size(); k++) {
lng = Double.parseDouble(jsonArray1.get(0).toString());
lat = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 1) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(1);
for (int k = 0; k < jsonArray1.size(); k++) {
lng1 = Double.parseDouble(jsonArray1.get(0).toString());
lat1 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 2) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(2);
for (int k = 0; k < jsonArray1.size(); k++) {
lng2 = Double.parseDouble(jsonArray1.get(0).toString());
lat2 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 3) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(3);
for (int k = 0; k < jsonArray1.size(); k++) {
lng3 = Double.parseDouble(jsonArray1.get(0).toString());
lat3 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
}
double totleLng = (lng + lng1 + lng2 + lng3) / 4;
double totleLat = (lat + lat1 + lat2 + lat3) / 4;
//向上是用减去对应的距离
System.out.println("经度 : " + new BigDecimal(totleLng - 0.00000435).setScale(8,BigDecimal.ROUND_HALF_UP)
+" ,纬度 : " + new BigDecimal(totleLat - 0.0000185).setScale(8,BigDecimal.ROUND_HALF_UP)
+ " ,"+ "Yard : " + Yard + " ,Num : " + Num);
}
if (Yard.equals("604")) {
JSONArray jsonArray = geometry.getJSONArray("coordinates");
JSONArray jsonArray2 = jsonArray.getJSONArray(0);
double lng = 0;
double lat = 0;
double lng1 = 0;
double lat1 = 0;
double lng2 = 0;
double lat2 = 0;
double lng3 = 0;
double lat3 = 0;
for (int j = 0; j < jsonArray2.size(); j++) {
if (j == 0) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(0);
for (int k = 0; k < jsonArray1.size(); k++) {
lng = Double.parseDouble(jsonArray1.get(0).toString());
lat = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 1) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(1);
for (int k = 0; k < jsonArray1.size(); k++) {
lng1 = Double.parseDouble(jsonArray1.get(0).toString());
lat1 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 2) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(2);
for (int k = 0; k < jsonArray1.size(); k++) {
lng2 = Double.parseDouble(jsonArray1.get(0).toString());
lat2 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
if (j == 3) {
JSONArray jsonArray1 = jsonArray2.getJSONArray(3);
for (int k = 0; k < jsonArray1.size(); k++) {
lng3 = Double.parseDouble(jsonArray1.get(0).toString());
lat3 = Double.parseDouble(jsonArray1.get(1).toString());
}
}
}
double totleLng =(lng + lng1 + lng2 + lng3) / 4;
double totleLat = (lat + lat1 + lat2 + lat3) / 4;
//向下是用加上对应的距离
System.out.println("经度 : "+ new BigDecimal(totleLng + 0.00000435).setScale(8,BigDecimal.ROUND_HALF_UP)
+ " ,纬度 : "+ new BigDecimal(totleLat + 0.0000185).setScale(8,BigDecimal.ROUND_HALF_UP)
+ " ,Yard : " + Yard + " ,Num : " + Num );
}
}
}
/**
* 根据文件换算出重复的贝位点重新排序
* @param path
*/
public static void locationTrans(String path){
String s = readJsonFile(path);
JSONObject jobj = JSON.parseObject(s);
JSONArray features = jobj.getJSONArray("features");
Integer num = 0;
String lats="0.0000065";//纬度差距
String lngs="0.000031";//经纬差距
Integer type=0;
Integer eType=0;
Integer eType01=0;
Integer eType03=0;
Integer eType04=0;
Integer eType05=0;
Integer eType06=0;
Integer eType07=0;
Integer eType08=0;
Integer eType09=0;
Integer dType03=0;
Integer dType05=0;
Integer dType07=0;
Integer dType09=0;
Integer dType001=0;
Integer dType003=0;
for (int i = 0; i < features.size(); i++) {
JSONObject key1 = (JSONObject)features.get(i);
JSONObject properties=key1.getJSONObject("properties");
String stockDumpNum = (String)properties.get("堆场编号");
String stockDumpRanking = (String)properties.get("堆场排位");
String bayNum=(String)properties.get("贝位编号");
//A区
// if (
// (stockDumpNum.contains("A01") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A02") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A03") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A04") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A05") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A06") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A07") && stockDumpRanking.equals("01"))||
// (stockDumpNum.contains("A08") && stockDumpRanking.equals("01"))
// ){
// if (bayNum.contains("04")){
// if (type==0){
// properties.put("贝位编号","61");
// String longitudes=(String)properties.get("贝位中心点");
// String lons[]=longitudes.split(",");
// String lat=lons[0];//经度
// String lng=lons[1];//纬度
// properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
// type=1;
// }else{
// properties.put("贝位编号","63");
// String longitudes=(String)properties.get("贝位中心点");
// String lons[]=longitudes.split(",");
// Integer fid=(Integer)properties.get("FID");
// properties.put("FID",fid+12580);
// key1.put("id",fid+12580);
// String lat=lons[0];//经度
// String lng=lons[1];//纬度
// properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
// type=0;
// }
// }else{
// if(!bayNum.equals("001")&&!bayNum.equals("003")) {
// num = Integer.parseInt(bayNum) + 4;
// if (num < 10) {
// properties.put("贝位编号", "0" + num.toString());
// } else {
// properties.put("贝位编号", num.toString());
// }
// }
// }
// if(bayNum.contains("001")){
// properties.put("贝位编号","01");
// String longitudes=(String)properties.get("贝位中心点");
// String lons[]=longitudes.split(",");
// String lat=lons[0];//经度
// String lng=lons[1];//纬度
// properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
// }
// if(bayNum.contains("003")){
// properties.put("贝位编号","03");
// Integer fid=(Integer)properties.get("FID");
// properties.put("FID",fid+12580);
// key1.put("id",fid+12580);
// String longitudes=(String)properties.get("贝位中心点");
// String lons[]=longitudes.split(",");
// String lat=lons[0];//经度
// String lng=lons[1];//纬度
// properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
// }
// }
//B区
if (
stockDumpNum.contains("B01") && stockDumpRanking.equals("01")
){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","65");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
//C区
if (
(stockDumpNum.contains("C01") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C02") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C03") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C04") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C05") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C06") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C07") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C08") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("C09") && stockDumpRanking.equals("01"))
){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","65");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","67");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
//D区
if (
(stockDumpNum.contains("D01") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D02") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D03") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D04") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D05") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D06") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D07") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D08") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D09") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D13") && stockDumpRanking.equals("01"))||
(stockDumpNum.contains("D14") && stockDumpRanking.equals("01"))
){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","65");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","67");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("D12") && stockDumpRanking.equals("01")){
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (bayNum.equals("03")){
if(dType03==0){
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
dType03=1;
}else{
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}else if(bayNum.equals("05")){
if(dType05==0){
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
dType05=1;
}else{
num = Integer.parseInt(bayNum) + 8;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}else if(bayNum.equals("07")){
if(dType07==0){
num = Integer.parseInt(bayNum) + 8;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
dType07=1;
}else{
num = Integer.parseInt(bayNum) + 10;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}else if(bayNum.equals("09")){
if(dType09==0){
num = Integer.parseInt(bayNum) + 10;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
dType09=1;
}else{
num = Integer.parseInt(bayNum) + 12;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}else{
if (bayNum.equals("01")){
num = Integer.parseInt(bayNum) + 4;
}else{
num = Integer.parseInt(bayNum) + 12;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("D11") && stockDumpRanking.equals("01")){
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
num = Integer.parseInt(bayNum) + 8;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
if(bayNum.contains("001")){
if (dType001==0){
properties.put("贝位编号","01");
dType001=1;
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}else{
properties.put("贝位编号","03");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if(bayNum.contains("003")){
if (dType003==0){
properties.put("贝位编号","05");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
dType003=1;
}else{
properties.put("贝位编号","07");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
}
///////////////E区
if (stockDumpNum.contains("E01") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType01 == 0) {
num = Integer.parseInt(bayNum) + 6;
eType01 = 1;
} else {
num = Integer.parseInt(bayNum) + 4;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E02") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType == 0) {
num = Integer.parseInt(bayNum) + 4;
eType = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E03") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType03 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType03 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E04") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType04 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType04 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E05") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType05 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType05 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E06") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType06 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType06 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E07") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType07 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType07 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E08") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType08 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType08 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E09") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
if (Integer.parseInt(bayNum) < 17) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else if (Integer.parseInt(bayNum) == 17) {
if (eType09 == 0) {
num = Integer.parseInt(bayNum) + 4;
eType09 = 1;
} else {
num = Integer.parseInt(bayNum) + 6;
}
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
} else {
num = Integer.parseInt(bayNum) + 6;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E12") && stockDumpRanking.equals("01")){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")) {
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E14") && stockDumpRanking.equals("01")){
if(bayNum.contains("01") ){
num = Integer.parseInt(bayNum) + 4;
if (num < 10) {
properties.put("贝位编号", "29");
} else {
properties.put("贝位编号", num.toString());
}
}else if (bayNum.contains("03")){
properties.put("贝位编号", "31");
}else{
if (!bayNum.contains("001")||!bayNum.contains("003")){
num = Integer.parseInt(bayNum) + 1;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
if (stockDumpNum.contains("E15") && stockDumpRanking.equals("01")){
if(Integer.parseInt(bayNum)%2==1 && !bayNum.contains("001") && !bayNum.contains("003")){
// num = Integer.parseInt(bayNum) + 4;
// if (num < 10) {
// properties.put("贝位编号", "0" + num.toString());
// } else {
// properties.put("贝位编号", num.toString());
// }
}else{
num = Integer.parseInt(bayNum) + 21;
if (num < 10) {
properties.put("贝位编号", "0" + num.toString());
} else {
properties.put("贝位编号", num.toString());
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","21");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","23");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
//F区
if ((stockDumpNum.contains("F01") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F02") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F03") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F04") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F05") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F06") && stockDumpRanking.equals("01")) ||
(stockDumpNum.contains("F07") && stockDumpRanking.equals("01"))
){
if (bayNum.contains("04")){
if (type==0){
properties.put("贝位编号","61");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
type=1;
}else{
properties.put("贝位编号","63");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
type=0;
}
}else{
if(!bayNum.equals("001")&&!bayNum.equals("003")){
num=Integer.parseInt(bayNum)+4;
if (num<10){
properties.put("贝位编号","0"+num.toString());
}else {
properties.put("贝位编号",num.toString());
}
}
}
if(bayNum.contains("001")){
properties.put("贝位编号","01");
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).add(new BigDecimal(lats))+","+new BigDecimal(lng).subtract(new BigDecimal(lngs)));
}
if(bayNum.contains("003")){
properties.put("贝位编号","03");
Integer fid=(Integer)properties.get("FID");
properties.put("FID",fid+12580);
key1.put("id",fid+12580);
String longitudes=(String)properties.get("贝位中心点");
String lons[]=longitudes.split(",");
String lat=lons[0];//经度
String lng=lons[1];//纬度
properties.put("贝位中心点",new BigDecimal(lat).subtract(new BigDecimal(lats))+","+new BigDecimal(lng).add(new BigDecimal(lngs)));
}
}
}
num=0;
for (int i = 0; i < features.size(); i++) {
JSONObject key1 = (JSONObject)features.get(i);
JSONObject properties=key1.getJSONObject("properties");
String stockDumpNum = (String)properties.get("堆场编号");
String stockDumpRanking = (String)properties.get("堆场排位");
String bayNum=(String)properties.get("贝位编号");
String longitudes=(String)properties.get("贝位中心点");
Integer fid=(Integer)properties.get("FID");
//E15,E14双数
if (stockDumpNum.contains("E01") && stockDumpRanking.equals("01")){
num=num+1;
System.out.println(" 堆场编号:"+stockDumpNum+" 堆场排位:"+stockDumpRanking+" 贝位编号:"+bayNum+" 贝位中心点:"+longitudes+" FID:"+fid+" num:"+num);
}
}
BufferedWriter writer = null;
File file = new File("d:\\test.geojson");
//如果文件不存在,则新建一个
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
//写入
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8"));
writer.write(JSONObject.toJSONString(jobj));
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(writer != null){
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("文件写入成功!");
}
public static String readJsonFile(String fileName) {
String jsonStr = "";
try {
File jsonFile = new File(fileName);
FileReader fileReader = new FileReader(jsonFile);
Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
package com.ssi.utils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Getter
@Setter
public class ChargeDailyTimeUtil {
private Date day;
private List<ChargeDailyTimeHourBean> dailyTimeBeanList = new ArrayList<>();
public ChargeDailyTimeUtil(Date date) {
this.day = date;
this.init();
}
private void init() {
for (int i = 0; i < 24; i++) {
ChargeDailyTimeHourBean dailyTimeBean = new ChargeDailyTimeHourBean(day, i);
dailyTimeBeanList.add(dailyTimeBean);
}
}
public void add(long startTime, long endTime, double energy) {
for (int i = 0; i < dailyTimeBeanList.size(); i++) {
ChargeDailyTimeHourBean dailyTimeBean = dailyTimeBeanList.get(i);
long rangeStartTime = dailyTimeBean.getRangeStartTime();
long rangeEndTime = dailyTimeBean.getRangeEndTime();
long s = startTime >= rangeStartTime ? startTime : rangeStartTime;
long e = endTime <= rangeEndTime ? endTime : rangeEndTime;
if (e > s) {
dailyTimeBean.addDuration((double) (e - s) / 1000 / 3600);
dailyTimeBean.addEnergy((double) (e - s) / (endTime - startTime) * energy);
}
}
}
public void finish(int pileNum) {
for (int i = 0; i < dailyTimeBeanList.size(); i++) {
ChargeDailyTimeHourBean dailyTimeHourBean = dailyTimeBeanList.get(i);
dailyTimeHourBean.chargingPileUseRate = new BigDecimal(
dailyTimeHourBean.getDuration() / pileNum)
.setScale(4, RoundingMode.HALF_UP).doubleValue();
}
}
@Getter
@Setter
public class ChargeDailyTimeHourBean {
private Date date;
private int hour;
@JsonIgnore
private long rangeStartTime;
@JsonIgnore
private long rangeEndTime;
private double duration;
private double chargingPileUseRate;
private double chargingEnergy;
public ChargeDailyTimeHourBean(Date date, int hour) {
this.date = date;
this.hour = hour;
long dayStartTime = date.getTime();
this.rangeStartTime = dayStartTime + hour * 3600 * 1000;
this.rangeEndTime = dayStartTime + (hour + 1) * 3600 * 1000;
}
public void addDuration(double value) {
this.duration = duration + value;
}
public void addEnergy(double value) {
this.chargingEnergy = chargingEnergy + value;
}
}
}
package com.ssi.utils;
import com.alibaba.fastjson.JSON;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map;
/**
* Description:
*
* @author LiXiaoCong
* @version 2018/1/15 19:00
*/
public class ConfigUtils {
private final Logger logger = LogManager.getLogger(ConfigUtils.class);
private ConfigUtils() {
}
public static <T> T getAs(Map config, Object key) {
return getAsWithDefault(config, key, null);
}
public static <T> T getAsWithKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
return value == null ? null : (T) value;
}
public static <T> T getAsWithDefault(Map config, Object key, T defaultValue) {
Object o = config.get(key);
return (o == null) ? defaultValue : (T) o;
}
public static String getAsStringWithDefault(Map config, Object key, String defaultValue) {
Object o = config.get(key);
if (o == null) {
return defaultValue;
} else {
return String.valueOf(o);
}
}
public static String getAsString(Map config, Object key) {
return getAsStringWithDefault(config, key, null);
}
public static String getAsStringByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return String.valueOf(value);
}
}
public static String getAsJSonStringByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return JSON.toJSONString(value);
}
}
public static Object getAsByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return value;
}
}
public static Integer getAsIntegerWithDefault(Map config, Object key, Integer defaultValue) {
Object o = config.get(key);
if (o == null) {
return defaultValue;
} else {
return Integer.parseInt(String.valueOf(o));
}
}
public static Integer getAsIntegerByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return Integer.parseInt(String.valueOf(value));
}
}
public static Integer getAsInteger(Map config, Object key) {
return getAsIntegerWithDefault(config, key, null);
}
public static Long getAsLongWithDefault(Map config, Object key, Long defaultValue) {
Object o = config.get(key);
if (o == null) {
return defaultValue;
} else {
return Long.parseLong(String.valueOf(o));
}
}
public static Long getAsLongByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return Long.parseLong(String.valueOf(value));
}
}
public static Long getAsLong(Map config, Object key) {
return getAsLongWithDefault(config, key, null);
}
public static Float getAsFloatWithDefault(Map config, Object key, Float defaultValue) {
Object o = config.get(key);
if (o == null) {
return defaultValue;
} else {
return Float.parseFloat(String.valueOf(o));
}
}
public static Float getAsFloatByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return Float.parseFloat(String.valueOf(value));
}
}
public static Float getAsFloat(Map config, Object key) {
return getAsFloatWithDefault(config, key, null);
}
public static Double getAsDoubleWithDefault(Map config, Object key, Double defaultValue) {
Object o = config.get(key);
if (o == null) {
return defaultValue;
} else {
return Double.parseDouble(String.valueOf(o));
}
}
public static Double getAsDoubleByKeys(Map config, Object... keys) {
Object value = getByKeys(config, keys);
if (value == null) {
return null;
} else {
return Double.parseDouble(String.valueOf(value));
}
}
public static Double getAsDouble(Map config, Object key) {
return getAsDoubleWithDefault(config, key, null);
}
private static Object getByKeys(Map config, Object[] keys) {
Object value = null;
for (Object key : keys) {
value = config.get(key);
if (value != null) {
break;
}
}
return value;
}
}
package com.ssi.utils;
import com.alibaba.fastjson.JSONObject;
import com.ssi.constant.enums.Status;
import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author ZhangLiYao
* @version 1.0
* @date 2020/3/3 9:44
*/
@Service
public class DataPermissionUtils {
@Value("${login-check-url}")
private String loginCheckUrl;
@Value("${data-permission-check-url}")
private String dataPermissionCheckUrl;
public String getRoleDataPermission() {
String result = RestTemplateUtil.get(dataPermissionCheckUrl,
AuthorizationUtils.getRequestToken());
JSONObject resultObj = JSONObject.parseObject(result);
String applySql = null;
if ((int) resultObj.get("code") == Status.SUCCESS.getCode()) {
applySql = resultObj.getJSONObject("data").getString("applySql");
} else if ((int) resultObj.get("code") == Status.ERROR.getCode()) {
applySql = " create_user_id = " + resultObj.get("userId");
} else {
throw new UnauthenticatedException();
}
return applySql;
}
public JSONObject getRoleDataPermissionOriginal() {
String result = RestTemplateUtil.get(dataPermissionCheckUrl,
AuthorizationUtils.getRequestToken());
JSONObject resultObj = JSONObject.parseObject(result);
if ((int) resultObj.get("code") == Status.UNAUTHORIZED.getCode()) {
throw new UnauthenticatedException();
}
return resultObj;
}
}
package com.ssi.utils;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* 日期处理
*/
public class DateUtils {
/**
* 时间格式(yyyy-MM-dd)
*/
public final static String DATE_PATTERN = "yyyy-MM-dd";
/**
* 年份格式
*/
public static final String DATE_PATTERN_yyyy = "yyyy";
/**
* 时间格式(yyyy-MM-dd HH:mm:ss)
*/
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
private static final ZoneId zone = ZoneId.systemDefault();
public static String format(Date date, int flag) {
if (flag == 1) {
return format(date, DATE_PATTERN);
} else if (flag == 2) {
return format(date, DATE_TIME_PATTERN);
}
return null;
}
public static String format(Date date, String pattern) {
if (date != null) {
SimpleDateFormat df = new SimpleDateFormat(pattern);
return df.format(date);
}
return null;
}
/**
* 将时间戳转换为 LocalDateTime
* @param timestamp
* @return
*/
public static LocalDateTime parseLocalDateTime(Long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
return LocalDateTime.ofInstant(instant, zone);
}
/**
* 获取年份数据
* @param timestamp
* @return
*/
public static String getYear(Long timestamp) {
return parseLocalDateTime(timestamp).format(DateTimeFormatter.ofPattern(DATE_PATTERN_yyyy));
}
}
package com.ssi.utils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import java.util.*;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
/**
* Description:
*
* @author LiXiaoCong
* @version 2018/4/27 8:30
*/
@Slf4j
public class ElasticSearchUtil {
private final static DateTimeZone TIME_ZONE = DateTimeZone.forID("Asia/Shanghai");
private ElasticSearchUtil() {
}
public static boolean isExistsIndex(TransportClient client,
String indexName) {
if (StringUtils.isNotBlank(indexName)) {
IndicesExistsResponse response =
client.admin().indices().exists(
new IndicesExistsRequest().indices(new String[]{indexName})).actionGet();
return response.isExists();
}
return false;
}
public static boolean isExistsType(TransportClient client,
String indexName,
String indexType) {
if (StringUtils.isNotBlank(indexName) && StringUtils.isNotBlank(indexType)) {
TypesExistsResponse response =
client.admin().indices()
.typesExists(new TypesExistsRequest(
new String[]{indexName}, indexType)).actionGet();
return response.isExists();
}
return false;
}
public static List<String> getIndices(TransportClient client) {
ImmutableOpenMap<String, IndexMetaData> indexMap = client.admin()
.cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices();
Iterator<String> keysIt = indexMap.keysIt();
return Lists.newArrayList(keysIt);
}
public static List<Map<String, Object>> selectItem(SearchHits searchHits) {
SearchHit[] hits = searchHits.getHits();
List<Map<String, Object>> resList = Lists.newLinkedList();
for (SearchHit hit : hits) {
resList.add(hit.getSourceAsMap());
}
return resList;
}
public static List<Map<String, Object>> selectItemWithLocationTypeChange(SearchHits searchHits,
String toType) {
SearchHit[] hits = searchHits.getHits();
List<Map<String, Object>> resList = Lists.newLinkedList();
Map<String, Object> sourceAsMap;
for (SearchHit hit : hits) {
sourceAsMap = hit.getSourceAsMap();
locationTypeChange(sourceAsMap, toType);
resList.add(sourceAsMap);
}
return resList;
}
public static RangeQueryBuilder createRangeQueryBuilder(String field,
Long startTime,
Long endTime) {
RangeQueryBuilder rangeQueryBuilder = null;
if (startTime != null || endTime != null) {
rangeQueryBuilder = QueryBuilders.rangeQuery(field);
if (startTime != null) {
rangeQueryBuilder.gte(startTime);
}
if (endTime != null) {
rangeQueryBuilder.lte(endTime);
}
}
return rangeQueryBuilder;
}
/**
* 将map中的经纬度 进行高德地图纠偏
*/
public static void locationTypeChange(Map<String, Object> sourceAsMap, String toType) {
if (sourceAsMap != null && toType != null) {
Object longitudeObj = sourceAsMap.get("longitude");
Object latitudeObj = sourceAsMap.get("latitude");
if (latitudeObj != null && longitudeObj != null) {
double longitude = (double) longitudeObj;
double latitude = (double) latitudeObj;
double[] doubles = null;
switch (toType) {
//高德
case "gcj02":
doubles = GeoPosTransformUtil.wgs84togcj02(longitude, latitude);
break;
//百度
case "bd09":
doubles = GeoPosTransformUtil.wgs84tobd09(longitude, latitude);
break;
}
if (doubles != null) {
sourceAsMap.put("longitude", doubles[0]);
sourceAsMap.put("latitude", doubles[1]);
}
}
}
}
public static boolean chinaLocationTypeChange(Map<String, Object> sourceAsMap, String toType) {
boolean status = true;
if (sourceAsMap != null && toType != null) {
Object longitudeObj = sourceAsMap.get("longitude");
Object latitudeObj = sourceAsMap.get("latitude");
if (latitudeObj != null && longitudeObj != null) {
double longitude = (double) longitudeObj;
double latitude = (double) latitudeObj;
boolean inChina = isInChina(longitude, latitude);
if (inChina) {
double[] doubles = null;
switch (toType) {
//高德
case "gcj02":
doubles = GeoPosTransformUtil.wgs84togcj02(longitude, latitude);
break;
//百度
case "bd09":
doubles = GeoPosTransformUtil.wgs84tobd09(longitude, latitude);
break;
}
if (doubles != null) {
sourceAsMap.put("longitude", doubles[0]);
sourceAsMap.put("latitude", doubles[1]);
}
} else {
status = false;
}
}
}
return status;
}
public static boolean isInChina(double longitude, double latitude) {
return (longitude >= 73 && longitude <= 135 && latitude >= 4 && latitude <= 53);
}
/**
* 构建搜索查询
*/
public static SearchQuery buildSearchQuery(ElasticsearchTemplate elasticsearchTemplate,
List<String> indexList, String typeName, String[] searchFields, String sortField,
SortOrder order, BoolQueryBuilder boolQueryBuilder, int page, int pageSize) {
String[] indexArray = indexList.stream().filter(elasticsearchTemplate::indexExists)
.toArray(String[]::new);
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder()
.withIndices(indexArray)
.withTypes(typeName)
.withQuery(boolQueryBuilder)
.withFields(searchFields)
.withSort(new FieldSortBuilder(sortField).order(order));
SearchQuery searchQuery = null;
if (pageSize == 0) {
searchQuery = nativeSearchQueryBuilder.build();
} else {
searchQuery = nativeSearchQueryBuilder
.withPageable(PageRequest.of(page, pageSize))
.build();
}
return searchQuery;
}
/**
* 查询语句构建
*
* @param termMap 单值精确查询参数
* @param termsMap 多值精确查询参数
* @param longRangeMap long类型范围查询参数
* @param doubleRangeMap double类型范围查询参数
*/
public static BoolQueryBuilder getQueryBuilder(Map<String, String> termMap,
Map<String, List<Integer>> termsMap, String timeField, long startTime, long endTime,
Map<String, Long[]> longRangeMap, Map<String, Double[]> doubleRangeMap) {
BoolQueryBuilder boolQueryBuilder = boolQuery();
if (termMap != null && termMap.size() > 0) {
for (Map.Entry<String, String> entry : termMap.entrySet()) {
boolQueryBuilder.must(QueryBuilders.termQuery(entry.getKey(), entry.getValue()));
}
}
if (termsMap != null && termsMap.size() > 0) {
for (Map.Entry<String, List<Integer>> entry : termsMap.entrySet()) {
boolQueryBuilder.must(QueryBuilders.termsQuery(entry.getKey(), entry.getValue()));
}
}
Long[] timeRange = {startTime, endTime};
if (longRangeMap == null) {
longRangeMap = new HashMap<String, Long[]>();
}
longRangeMap.put(timeField, timeRange);
if (longRangeMap != null && longRangeMap.size() > 0) {
for (Map.Entry<String, Long[]> entry : longRangeMap.entrySet()) {
boolQueryBuilder.must(QueryBuilders.rangeQuery(entry.getKey())
.gte(entry.getValue()[0])
.lte(entry.getValue()[1]));
}
}
if (doubleRangeMap != null && doubleRangeMap.size() > 0) {
for (Map.Entry<String, Double[]> entry : doubleRangeMap.entrySet()) {
boolQueryBuilder.must(QueryBuilders.rangeQuery(entry.getKey())
.gte(entry.getValue()[0])
.lte(entry.getValue()[1]));
}
}
return boolQueryBuilder;
}
public static BoolQueryBuilder getQueryBuilder(String key, String value, String timeField,
long startTime, long endTime) {
Map<String, String> termMap = new HashMap<>();
termMap.put(key, value);
Map<String, Double[]> doubleRangeMap = new HashMap<String, Double[]>();
Double[] latLonRange = {1d, 360d};
doubleRangeMap.put("latitude", latLonRange);
doubleRangeMap.put("longitude", latLonRange);
return getQueryBuilder(termMap, null, timeField, startTime, endTime, null, doubleRangeMap);
}
public static String[] getIndexs(Long startTime,
Long stopTime,
String indexBase,
int defaultDayPeriod,
boolean defaultContainsToday,
String indexRule) {
if (indexRule == null) {
return new String[]{indexBase};
}
DateTime stopDate;
if (stopTime == null) {
DateTime now = DateTime.now(TIME_ZONE);
if (defaultContainsToday) {
stopDate = now;
} else {
stopDate = now.minusDays(1);
}
} else {
stopDate = new DateTime(stopTime.longValue(), TIME_ZONE);
}
DateTime startDate = (startTime == null ? stopDate.minusDays(defaultDayPeriod)
: new DateTime(startTime.longValue(), TIME_ZONE));
List<String> indexList = new ArrayList<>();
String[] indexs;
int days = Days.daysBetween(startDate, stopDate).getDays();
Set<String> indexSet = new HashSet<>();
if (days >= 0) {
for (int i = 0; i <= days; i++) {
try {
switch (indexRule.toLowerCase()) {
//按年分区
case "year":
indexSet.add(String.format("%s_%s*",
indexBase, startDate.plusDays(i).toString("yyyy")));
break;
//按月分区
case "month":
indexSet.add(String.format("%s_%s*",
indexBase, startDate.plusDays(i).toString("yyyyMM")));
break;
//按天分区
case "day":
indexList.add(String.format("%s_%s*",
indexBase, startDate.plusDays(i).toString("yyyyMMdd")));
break;
default:
indexSet.add(indexBase);
}
} catch (Exception e) {
}
}
indexList.addAll(indexSet);
indexs = indexList.toArray(new String[indexList.size()]);
} else {
indexs = new String[0];
}
log.info("查询索引有:indexs = " + Lists.newArrayList(indexs).toString());
return indexs;
}
}
package com.ssi.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
public class FTPUtil {
private String ip;
private int port;
private String user;
private String pwd;
private FTPClient ftpClient;
//省略get set
private static final Logger logger = LoggerFactory.getLogger(FTPUtil.class);
//获取配置文件中的配置参数
// private static String ftpIp = PropertiesUtil.getProperty("ftp.ip");
// private static String ftpUser = PropertiesUtil.getProperty("ftp.user");
// private static String ftpPwd = PropertiesUtil.getProperty("ftp.password");
// private static int ftpPort = Integer.valueOf(PropertiesUtil.getProperty("ftp.port")).intValue();
//构造方法,赋值value
public FTPUtil(String ip, int port, String user, String pwd) {
this.ip = ip;
this.port = port;
this.user = user;
this.pwd = pwd;
}
//外部调用方法
// public static boolean uploadFile(List<File> files) throws IOException {
// FTPUtil ftpUtil = new FTPUtil(ftpIp,ftpPort,ftpUser,ftpPwd);
// logger.info("开始连接ftp服务器!");
// //当天的年月日作为目录名称
// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// String catalogue = sdf.format(new Date());
// boolean result = ftpUtil.uploadFile(catalogue,files);
// logger.info("开始连接ftp服务器,结束上传,上传结果:{}",result);
// return result;
// }
//外部调用方法
public static boolean uploadFile(List<MultipartFile> files, String ip, int port, String user,
String password, String remotePath, List<String> fileNames) throws IOException {
FTPUtil ftpUtil = new FTPUtil(ip, port, user, password);
logger.info("开始连接ftp服务器!");
//当天的年月日作为目录名称
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String catalogue = sdf.format(new Date());*/
boolean result = ftpUtil.uploadFiles(remotePath, files, fileNames);
logger.info("开始连接ftp服务器,结束上传,上传结果:{}", result);
return result;
}
//外部调用方法
public static boolean uploadSingleFile(MultipartFile file, String ip, int port, String user,
String password, String remotePath, String fileName) throws IOException {
FTPUtil ftpUtil = new FTPUtil(ip, port, user, password);
logger.info("开始连接ftp服务器!");
//当天的年月日作为目录名称
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String catalogue = sdf.format(new Date());*/
boolean result = ftpUtil.uploadSingleFile(remotePath, file, fileName);
logger.info("开始连接ftp服务器,结束上传,上传结果:{}", result);
return result;
}
//外部调用方法
public static Map uploadFileForAPK(List<MultipartFile> files, String ip, int port, String user,
String password, String remotePath, List<String> fileNames) throws IOException {
FTPUtil ftpUtil = new FTPUtil(ip, port, user, password);
logger.info("开始连接ftp服务器!");
//当天的年月日作为目录名称
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String catalogue = sdf.format(new Date());*/
Map map = ftpUtil.uploadFilesForAPK(remotePath, files, fileNames);
logger.info("开始连接ftp服务器,结束上传,上传结果:{}", map.get("uploaded"));
return map;
}
//内部调用方法,连接ftp
private boolean uploadFile(String remotePath, List<File> files) throws IOException {
boolean uploaded = true;
FileInputStream fis = null;
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
try {
//判断这个目录是否存在,不存在则进行创建
ftpClient.makeDirectory(remotePath);
//切换到remodePath目录
ftpClient.changeWorkingDirectory(remotePath);
//设置1m缓冲
ftpClient.setBufferSize(1024);
//设置编码
ftpClient.setControlEncoding("UTF-8");
//设置文件类型:二进制文件
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//被动模式
ftpClient.enterLocalPassiveMode();
for (File file : files) {
fis = new FileInputStream(file);
ftpClient.storeFile(file.getName(), fis);
}
} catch (IOException e) {
logger.error("上传文件异常", e);
uploaded = false;
} finally {
if (fis != null) {
fis.close();
}
ftpClient.disconnect();
}
}
return uploaded;
}
//内部调用方法,连接ftp
public boolean uploadFile(String remotePath, String fileHttpPath) throws IOException {
boolean uploaded = true;
FileInputStream fis = null;
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
try {
//切换到remodePath目录
boolean flag4 = ftpClient.changeWorkingDirectory(remotePath);
// boolean flag5 = ftpClient.changeWorkingDirectory("/PicHouse/LFWADRJF011002346/samplePic/");
//设置1m缓冲
ftpClient.setBufferSize(1024);
//设置编码
ftpClient.setControlEncoding("UTF-8");
//设置文件类型:二进制文件
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//被动模式
ftpClient.enterLocalPassiveMode();
String imgAddress = fileHttpPath;
URL url = new URL(imgAddress);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置连接超时时间
conn.setConnectTimeout(3000);
InputStream inputStream = null;
// 正常响应时获取输入流, 在这里也就是图片对应的字节流
if (conn.getResponseCode() == 200) {
inputStream = conn.getInputStream();
}
String[] path = fileHttpPath.split("/");
uploaded = ftpClient.storeFile(path[path.length - 1], inputStream);
} catch (IOException e) {
logger.error("上传文件异常", e);
uploaded = false;
} finally {
if (fis != null) {
fis.close();
}
ftpClient.disconnect();
}
}
return uploaded;
}
private boolean uploadFiles(String remotePath, List<MultipartFile> files, List<String> fileNames)
throws IOException {
boolean uploaded = true;
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
try {
//判断这个目录是否存在,不存在则进行创建
ftpClient.makeDirectory(remotePath);
//切换到remodePath目录
ftpClient.changeWorkingDirectory(remotePath);
//设置1m缓冲
ftpClient.setBufferSize(10240);
//设置编码
ftpClient.setControlEncoding("UTF-8");
//设置文件类型:二进制文件
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//被动模式
ftpClient.enterLocalPassiveMode();
for (int i = 0; i < files.size(); i++) {
MultipartFile file = files.get(i);
if (StringUtils.isBlank(file.getOriginalFilename())) {
continue;
}
ftpClient.storeFile(fileNames.get(i), file.getInputStream());
}
return true;
} catch (IOException e) {
logger.error("上传文件异常", e);
uploaded = false;
} finally {
ftpClient.disconnect();
}
}
return uploaded;
}
private boolean uploadSingleFile(String remotePath, MultipartFile file, String fileName)
throws IOException {
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
try {
//判断这个目录是否存在,不存在则进行创建
ftpClient.makeDirectory(remotePath);
//切换到remodePath目录
ftpClient.changeWorkingDirectory(remotePath);
//设置1m缓冲
ftpClient.setBufferSize(10240);
//设置编码
ftpClient.setControlEncoding("UTF-8");
//设置文件类型:二进制文件
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//被动模式
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile(fileName, file.getInputStream());
return true;
} catch (IOException e) {
logger.error("上传文件异常", e);
return false;
} finally {
ftpClient.disconnect();
}
} else {
return false;
}
}
private Map uploadFilesForAPK(String remotePath, List<MultipartFile> files,
List<String> fileNames) throws IOException {
Map<String, Object> resultMap = new HashMap<>();
boolean uploaded = true;
String name = null;
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
try {
//判断这个目录是否存在,不存在则进行创建
ftpClient.makeDirectory(remotePath);
//切换到remodePath目录
ftpClient.changeWorkingDirectory(remotePath);
//设置1m缓冲
ftpClient.setBufferSize(10240);
//设置编码
ftpClient.setControlEncoding("UTF-8");
//设置文件类型:二进制文件
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//被动模式
ftpClient.enterLocalPassiveMode();
for (MultipartFile file : files) {
if (StringUtils.isBlank(file.getOriginalFilename())) {
continue;
}
name = UUID.randomUUID().toString().replace("-", "");
// name = name + "." + file.getOriginalFilename().split("\\.")[1];
name = name + file.getOriginalFilename()
.substring(file.getOriginalFilename().lastIndexOf("."));
fileNames.add(name);
ftpClient.storeFile(name, file.getInputStream());
}
resultMap.put("uploaded", uploaded);
resultMap.put("name", name);
return resultMap;
} catch (IOException e) {
logger.error("上传文件异常", e);
uploaded = false;
} finally {
ftpClient.disconnect();
}
}
resultMap.put("uploaded", uploaded);
resultMap.put("name", name);
return resultMap;
}
//连接ftp服务器
private boolean connectServer(String ip, int port, String user, String pwd) {
boolean isSuccess = false;
ftpClient = new FTPClient();
ftpClient.setDataTimeout(5000);
try {
ftpClient.connect(ip, port);
isSuccess = ftpClient.login(user, pwd);
} catch (IOException e) {
logger.error("连接FTP服务器异常", e);
}
return isSuccess;
}
public static String upload(MultipartFile file, String path) {
logger.info("upload的绝对地址:{}", path);
//获取文件名
String fileName = file.getOriginalFilename();
//获取文件名的扩展名
String fileExtensionName = fileName.substring(fileName.lastIndexOf(".") + 1);
//创建一个新名称,等下用于上传文件的名称
String uploadFileName = UUID.randomUUID().toString() + "." + fileExtensionName;
logger.info("开始上传文件,上传文件的文件名:{},上传的路径:{},新文件名:{}", fileName, path, uploadFileName);
File fileDir = new File(path);
//如果目录不存在,则创建该目录
if (!fileDir.exists()) {
//获取权限
fileDir.setWritable(true);
//创建目录
fileDir.mkdirs();
}
//把上传路径和新文件名传入新file对象
File targetFile = new File(fileDir.getAbsoluteFile(), uploadFileName);
try {
//文件写入传入的目录中
file.transferTo(targetFile);
} catch (IOException e) {
logger.error("上传文件异常", e);
return null;
}
return targetFile.getName();
}
/**
* 方法描述:检验指定路径的文件是否存在ftp服务器中
*
* @param filePath 指定绝对路径的文件 127.0.0.1:21/TEST/20161010/test_20161010.zip
* @return 存在返回true,不存在返回false
* @author guoxk
* @createTime 2017年5月11日 上午11:26:44
*/
public boolean isFTPFileExist(String filePath) {
try {
if (connectServer(this.ip, this.port, this.user, this.pwd)) {
// 检验登陆操作的返回码是否正确
if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
ftpClient.disconnect();
return false;
}
ftpClient.enterLocalPassiveMode(); //开启本地被动模式--Linux,windowns开启主动enterLocalActiveMode
// 设置文件类型为二进制,与ASCII有区别
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
// 设置编码格式
ftpClient.setControlEncoding("GBK");
// 提取绝对地址的目录以及文件名
filePath = filePath.replace(ip + ":" + port + "/", "");
String dir = filePath.substring(0, filePath.lastIndexOf("/"));
String file = filePath.substring(filePath.lastIndexOf("/") + 1);
// 进入文件所在目录,注意编码格式,以能够正确识别中文目录
ftpClient.changeWorkingDirectory(new String(dir.getBytes("GBK"),
FTP.DEFAULT_CONTROL_ENCODING));
// 检验文件是否存在
InputStream is = ftpClient.retrieveFileStream(new String(file
.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
if (is == null || ftpClient.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
return false;
}
if (is != null) {
is.close();
ftpClient.completePendingCommand();
}
return true;
}
} catch (Exception e) {
//logger.error(e.getMessage());
} finally {
if (ftpClient != null) {
try {
ftpClient.disconnect();
} catch (IOException e) {
//logger.error(e.getMessage());
}
}
}
return false;
}
public static void main(String[] args) {
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
System.out.println(sd.format(new Date()));
}
}
package com.ssi.utils;
import com.ssi.entity.dto.Point;
public class FieldUtil {
/**
* 判断定位是否在经6路、经7路
* @return
*/
public static boolean isPortraitField(Point p) {
//充电区;;;;
Point cd1 = new Point(117.97163122456793,24.455426987401832);
Point cd2 = new Point(117.97166816778609,24.455588722342444);
Point cd3 = new Point(117.97124526051918,24.455677956127246);
Point cd4 = new Point(117.97121096277587,24.455527779060223);
if(IsPointInMatrix( cd1, cd2, cd3, cd4, p)){
return true;
}
//缓冲区;;;117.96715747858048,24.456003179914283;
Point c1 = new Point(117.97193044526601,24.455010904663794);
Point c2 = new Point(117.97196656233528,24.455148519793937);
Point c3 = new Point(117.96718924997575,24.45613767506783);
Point c4 = new Point(117.96715747858048,24.456003179914283);
if(IsPointInMatrix( c1, c2, c3, c4, p)){
return true;
}
//经7路
Point p1 = new Point(117.96745516911625,24.456285150995694);
Point p2 = new Point(117.96722963864319,24.45633305190644);
Point p3 = new Point(117.9682919984703,24.46062945506166);
Point p4 = new Point(117.96851301505286,24.460582634893385);
if(IsPointInMatrix( p1, p2, p3, p4, p)){
return true;
}
//经6路
Point p5 = new Point(117.96973859766143,24.4558102383949);
Point p6 = new Point(117.96950663612938,24.455859992961166);
Point p7 = new Point(117.97007395507599,24.458186866236495);
Point p8 = new Point(117.97031504895666,24.458137985137117);
if(IsPointInMatrix( p5, p6, p7, p8, p)){
return true;
}
//经5路
Point p9 = new Point(117.9720085361832,24.455339155931817);
Point p10 = new Point(117.97255752668187,24.457597729119605);
Point p11 = new Point(117.9723652609296,24.45763829777378);
Point p12 = new Point(117.97179183279854,24.455384882947587);
return IsPointInMatrix( p9, p10, p11, p12, p);
}
/**
* 判断定位是否是特殊区域
* @param p
* @return
*/
public static boolean isSpecialArea(Point p) {
//经7路
/* Point p1 = new Point(117.96745516911625,24.456285150995694);
Point p2 = new Point(117.96722963864319,24.45633305190644);
Point p3 = new Point(117.9682919984703,24.46062945506166);
Point p4 = new Point(117.96851301505286,24.460582634893385);
if(IsPointInMatrix( p1, p2, p3, p4, p)){
return true;
}*/
//经6路 117.96981969750728,24.45572105409198;117.96987953817745,24.455960215952967;117.96962261948379,24.45601442484349;117.9695362599941,24.455778948377557
// Point p5 = new Point(117.96973859766143,24.4558102383949);
// Point p6 = new Point(117.96950663612938,24.455859992961166);
// Point p7 = new Point(117.97007395507599,24.458186866236495);
// Point p8 = new Point(117.97031504895666,24.458137985137117);
Point p5 = new Point(117.96981969750728,24.45572105409198);
Point p6 = new Point(117.96987953817745,24.455960215952967);
Point p7 = new Point(117.96962261948379,24.45601442484349);
Point p8 = new Point(117.9695362599941,24.455778948377557);
/* if(IsPointInMatrix( p5, p6, p7, p8, p)){
return true;
}*/
return IsPointInMatrix( p5, p6, p7, p8, p);
/* //经5路
Point p9 = new Point(117.9720085361832,24.455339155931817);
Point p10 = new Point(117.97255752668187,24.457597729119605);
Point p11 = new Point(117.9723652609296,24.45763829777378);
Point p12 = new Point(117.97179183279854,24.455384882947587);
return IsPointInMatrix( p9, p10, p11, p12, p);*/
}
/**
* 判断定位是否是特殊区域
* @param p
* @return
*/
public static boolean isCrossArea(Point p) {
//经7路
Point p1 = new Point(117.96957640997283,24.45619917084264);
Point p2 = new Point(117.96930599763748,24.45625250882359);
Point p3 = new Point(117.96925235023933,24.455977482144537);
Point p4 = new Point(117.96951436870557,24.455922199445954);
if(IsPointInMatrix( p1, p2, p3, p4, p)){
return true;
}
return false;
}
//判断点p是否在p1p2p3p4的正方形内
public static boolean IsPointInMatrix(Point p1,Point p2,Point p3,Point p4,Point p) {
boolean isPointIn = GetCross(p1, p2, p) * GetCross(p3, p4, p) >= 0 && GetCross(p2, p3, p) * GetCross(p4, p1, p) >= 0;
if (isPointIn){
return true;
}
return false;
}
public static double GetCross(Point p1, Point p2, Point p) {
return (p2.x - p1.x) * (p.y - p1.y) - (p.x - p1.x) * (p2.y - p1.y);
}
}
package com.ssi.utils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class FileUtils {
/**
* 获取文件后缀
*/
public static String getSuffix(String fileName) {
return fileName.substring(fileName.lastIndexOf("."));
}
/**
* 生成新的文件名
*
* @param fileOriginName 源文件名
*/
public static String getFileName(String fileOriginName) {
return UUID.randomUUID() + getSuffix(fileOriginName);
}
/**
* @param file 文件
* @param path 文件存放路径
* @param fileName 原文件名
*/
public static String upload(MultipartFile file, String path, String fileName) {
String newFileName = getFileName(fileName);
// 生成新的文件名
String realPath = path + "/" + newFileName;
File dest = new File(realPath);
//判断文件父目录是否存在
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdir();
}
try {
//保存文件
file.transferTo(dest);
return newFileName;
} catch (IOException e) {
return null;
}
}
}
package com.ssi.utils;
import java.text.DecimalFormat;
/**
* Description:
*
* @author LiXiaoCong
* @version 2018/5/3 14:43
*/
public class GeoPosTransformUtil {
private GeoPosTransformUtil() {
}
static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
// π
static double pi = 3.1415926535897932384626;
// 长半轴
static double a = 6378245.0;
// 扁率
static double ee = 0.00669342162296594323;
/** 地球半径 **/
private static final double R = 6371e3;
/** 180° **/
private static final DecimalFormat df = new DecimalFormat("0.000000");
/** 地图角度修正系数,原北向为0,实际东向为0*/
private static final double deltAngle = 114.1;
/**
* 百度坐标系(BD-09)转WGS坐标
*
* @param lng 百度坐标纬度
* @param lat 百度坐标经度
* @return WGS84坐标数组
*/
public static double[] bd09towgs84(double lng, double lat) {
double[] gcj = bd09togcj02(lng, lat);
double[] wgs84 = gcj02towgs84(gcj[0], gcj[1]);
return wgs84;
}
/**
* WGS坐标转百度坐标系(BD-09)
*
* @param lng WGS84坐标系的经度
* @param lat WGS84坐标系的纬度
* @return 百度坐标数组
*/
public static double[] wgs84tobd09(double lng, double lat) {
double[] gcj = wgs84togcj02(lng, lat);
double[] bd09 = gcj02tobd09(gcj[0], gcj[1]);
return bd09;
}
/**
* 火星坐标系(GCJ-02)转百度坐标系(BD-09)
*
* @param lng 火星坐标经度
* @param lat 火星坐标纬度
* @return 百度坐标数组
* @see 谷歌、高德——>百度
*/
public static double[] gcj02tobd09(double lng, double lat) {
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
double bd_lng = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return new double[]{bd_lng, bd_lat};
}
/**
* 百度坐标系(BD-09)转火星坐标系(GCJ-02)
*
* @param lng 百度坐标纬度
* @param lat 百度坐标经度
* @return 火星坐标数组
* @see 百度——>谷歌、高德
*/
public static double[] bd09togcj02(double bd_lon, double bd_lat) {
double x = bd_lon - 0.0065;
double y = bd_lat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
double gg_lng = z * Math.cos(theta);
double gg_lat = z * Math.sin(theta);
return new double[]{gg_lng, gg_lat};
}
/**
* WGS84转GCJ02(火星坐标系)
*
* @param lng WGS84坐标系的经度
* @param lat WGS84坐标系的纬度
* @return 火星坐标数组
*/
public static double[] wgs84togcj02(double lng, double lat) {
if (out_of_china(lng, lat)) {
return new double[]{lng, lat};
}
double dlat = transformlat(lng - 105.0, lat - 35.0);
double dlng = transformlng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * pi;
double magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi);
double mglat = lat + dlat;
double mglng = lng + dlng;
return new double[]{mglng, mglat};
}
/**
* GCJ02(火星坐标系)转GPS84
*
* @param lng 火星坐标系的经度
* @param lat 火星坐标系纬度
* @return WGS84坐标数组
*/
public static double[] gcj02towgs84(double lng, double lat) {
if (out_of_china(lng, lat)) {
return new double[]{lng, lat};
}
double dlat = transformlat(lng - 105.0, lat - 35.0);
double dlng = transformlng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * pi;
double magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi);
double mglat = lat + dlat;
double mglng = lng + dlng;
return new double[]{lng * 2 - mglng, lat * 2 - mglat};
}
/**
* 纬度转换
*/
public static double transformlat(double lng, double lat) {
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat
+ 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * pi) + 40.0 * Math.sin(lat / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * pi) + 320 * Math.sin(lat * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
/**
* 经度转换
*/
public static double transformlng(double lng, double lat) {
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(
Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * pi) + 40.0 * Math.sin(lng / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * pi) + 300.0 * Math.sin(lng / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
/**
* 判断是否在国内,不在国内不做偏移
*/
public static boolean out_of_china(double lng, double lat) {
if (lng < 72.004 || lng > 137.8347) {
return true;
} else if (lat < 0.8293 || lat > 55.8271) {
return true;
}
return false;
}
/**
* 根据一点的坐标与距离,以及方向,计算另外一点的位置
* @param angle 角度,从正北顺时针方向开始计算
* @param startLong 起始点经度
* @param startLat 起始点纬度
* @param distance 距离,单位m
* @return
*/
public static String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong,double startLat, double distance){
String[] result = new String[2];
//将距离转换成经度的计算公式
double δ = distance/R;
// 转换为radian,否则结果会不正确
angle = Math.toRadians(angle+deltAngle);
startLong = Math.toRadians(startLong);
startLat = Math.toRadians(startLat);
double lat = Math.asin(Math.sin(startLat)*Math.cos(δ)+Math.cos(startLat)*Math.sin(δ)*Math.cos(angle));
double lon = startLong + Math.atan2(Math.sin(angle)*Math.sin(δ)*Math.cos(startLat),Math.cos(δ)-Math.sin(startLat)*Math.sin(lat));
// 转为正常的10进制经纬度
lon = Math.toDegrees(lon);
lat = Math.toDegrees(lat);
result[0] = df.format(lon);
result[1] = df.format(lat);
return result;
}
}
package com.ssi.utils;
public class GpsUtil {
private static final double EARTH_RADIUS = 6378.137;
private static double rad(double d) {
return d * Math.PI / 180.0;
}
// public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
// double radLat1 = rad(lat1);
// double radLat2 = rad(lat2);
// double a = radLat1 - radLat2;
// double b = rad(lng1) - rad(lng2);
// double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
// Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
// s = s * EARTH_RADIUS;
// s = Math.round(s * 10000) / 10000;
//
// return s;
// }
public static double getDistance(double latitude1, double longitude1, double latitude2,
double longitude2) {
// 纬度
double lat1 = Math.toRadians(latitude1);
double lat2 = Math.toRadians(latitude2);
// 经度
double lng1 = Math.toRadians(longitude1);
double lng2 = Math.toRadians(longitude2);
// 纬度之差
double a = lat1 - lat2;
// 经度之差
double b = lng1 - lng2;
// 计算两点距离的公式
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
// 弧长乘地球半径, 返回单位: 千米
s = s * EARTH_RADIUS;
return s;
}
}
package com.ssi.utils;
/**
* @author SunnyHotz
* @PackageName:com.ssi.utils
* @ClassName:HexUtils
* @Description:
* @date 2022/7/19 11:43
*/
public class HexUtils {
/**
* bytes2HexString.
* 字节数组转16进制字符串.
* @param bs 字节数组.
* @return 16进制字符串.
*/
public static String bytes2HexString(byte[] bs) {
StringBuilder result = new StringBuilder();
for (byte b1 : bs) {
result.append(String.format("%02X", b1));
}
return result.toString();
}
/**
* 字节数组转大写16进制字符串.
* @param bs 字节数组.
* @return 16进制字符串.
*/
public static String bytes2UpperCaseHexString(byte[] bs) {
return bytes2HexString(bs).toUpperCase();
}
/**
* 字节数组转小写16进制字符串.
* @param bs 字节数组.
* @return 16进制字符串.
*/
public static String bytes2LowerCaseHexString(byte[] bs) {
return bytes2HexString(bs).toLowerCase();
}
/**
* bytes2HexString.
* 字节数组转16进制字符串.
* @param bs 字节数组.
* @return 16进制字符串.
*/
public static String bytes2HexString(byte[] bs, int offset, int length) {
StringBuilder result = new StringBuilder();
for (int i=0; i<length; i++) {
byte b1 = bs[offset+i];
result.append(String.format("%02X", b1));
}
return result.toString();
}
/**
* hexString2Bytes.
* 16进制字符串转字节数组.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static byte[] hexString2Bytes(String src) {
int l = src.length() / 2;
byte[] ret = new byte[l];
for (int i = 0; i < l; i++) {
ret[i] = Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
}
return ret;
}
/**
* string2HexUTF8.
* 字符UTF8串转16进制字符串.
* @param strPart 字符串.
* @return 16进制字符串.
*
*/
public static String string2HexUTF8(String strPart) {
return string2HexString(strPart,"UTF-8");
}
/**
* string2HexUTF8.
* 字符UTF-16LE串转16进制字符串,此UTF-16LE等同于C#中的Unicode
* @param strPart 字符串.
* @return 16进制字符串.
*
*/
public static String string2HexUTF16LE(String strPart) {
return string2HexString(strPart,"UTF-16LE");
}
/**
* string2HexUnicode.
* 字符Unicode串转16进制字符串.
* @param strPart 字符串.
* @return 16进制字符串.
*
*/
public static String string2HexUnicode(String strPart) {
return string2HexString(strPart,"Unicode");
}
/**
* string2HexGBK.
* 字符GBK串转16进制字符串.
* @param strPart 字符串.
* @return 16进制字符串.
*
*/
public static String string2HexGBK(String strPart) {
return string2HexString(strPart,"GBK");
}
/**
* string2HexString.
* 字符串转16进制字符串.
* @param strPart 字符串.
* @param tochartype hex目标编码.
* @return 16进制字符串.
*
*/
public static String string2HexString(String strPart,String tochartype) {
try{
return bytes2HexString(strPart.getBytes(tochartype));
}catch (Exception e){
return "";
}
}
/**
* hexUTF82String.
* 16进制UTF-8字符串转字符串.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static String hexUTF82String(String src) {
return hexString2String(src,"UTF-8","UTF-8");
}
/**
* hexUTF16LE2String.
* 16进制UTF-8字符串转字符串,,此UTF-16LE等同于C#中的Unicode.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static String hexUTF16LE2String(String src) {
return hexString2String(src,"UTF-16LE","UTF-8");
}
/**
* hexGBK2String.
* 16进制GBK字符串转字符串.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static String hexGBK2String(String src) {
return hexString2String(src,"GBK","UTF-8");
}
/**
* hexUnicode2String.
* 16进制Unicode字符串转字符串.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static String hexUnicode2String(String src) {
return hexString2String(src,"Unicode","UTF-8");
}
/**
* hexString2String 16进制字符串转字符串.
* @param src 16进制字符串.
* @return 字节数组.
*
*/
public static String hexString2String(String src,String oldchartype, String chartype) {
byte[] bts=hexString2Bytes(src);
try{if(oldchartype.equals(chartype))
return new String(bts,oldchartype);
else
return new String(new String(bts,oldchartype).getBytes(),chartype);
}
catch (Exception e){
return"";
}
}
}
package com.ssi.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
@Slf4j
public class JsonUtil {
public static Map<String, Object> jsonToMap(String json) {
int disableDecimalFeature = JSON.DEFAULT_PARSER_FEATURE & ~Feature.UseBigDecimal.getMask();
Map<String, Object> record = null;
try {
record = JSON.parseObject(json,
new TypeReference<Map<String, Object>>() {
}.getType(), disableDecimalFeature, Feature.OrderedField);
} catch (Exception e) {
log.error("json数据转换失败:%s\n %s", e.getMessage(), json);
}
return record;
}
}
package com.ssi.utils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author SunnyHotz
* @PackageName:com.ssi.utils
* @ClassName:MD5Util
* @Description:
* @date 2022/7/19 11:39
*/
public class MD5Util {
/**
* 字符串的md5.
* @param plainText 输入字符串.
* @return md5(utf8编码).
*/
public static String md5(String plainText) {
return md5(plainText, StandardCharsets.UTF_8);
}
/**
* 字符串的md5.
* @param plainText 输入字符串.
* @param encode 字符集.
* @return md5.
* @see #md5(String, Charset)
*/
@Deprecated
public static String md5(String plainText, String encode) {
try {
return md5(plainText.getBytes(encode));
} catch (UnsupportedEncodingException e) {
return "";
}
}
/**
* 字符串的md5.
* @param plainText 输入字符串.
* @param charset 字符集.
* @return md5.
*/
public static String md5(String plainText, Charset charset) {
return md5(plainText.getBytes(charset));
}
/**
* 字符串的md5.
* @param plainText 输入字符串.
* @return md5(utf8编码).
*/
public static String md5_16(String plainText) {
return md5_16(plainText, StandardCharsets.UTF_8);
}
/**
* 字符串的md5.
* @param plainText 输入字符串.
* @param encode 字符集.
* @return md5.
* @see #md5(String, Charset)
*/
@Deprecated
public static String md5_16(String plainText, String encode) {
try {
return md5(plainText.getBytes(encode)).substring(8,24);
} catch (UnsupportedEncodingException e) {
return "";
}
}
/**
* 字符串的16位md5.
* @param plainText 输入字符串.
* @param charset 字符集.
* @return md5.
*/
public static String md5_16(String plainText, Charset charset){
return md5(plainText, charset).substring(8,24);
}
/**
* 数据的md5.
* @param data 输入字符串.
* @return md5.
*/
public static byte[] md5Bytes(byte[] data) {
try {
// 生成一个MD5加密计算摘要
MessageDigest md = MessageDigest.getInstance("MD5");
//对字符串进行加密
md.update(data);
//获得加密后的数据
return md.digest();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("没有md5这个算法");
}
}
/**
* 数据的md5.
* @param data 输入字符串.
* @return md5.
*/
public static String md5(byte[] data) {
return HexUtils.bytes2HexString(md5Bytes(data));
}
}
package com.ssi.utils;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义List分页工具
*
* @author ZhangLiYao
* @version 1.0
* @date 2020/5/12 10:29
*/
public class PageUtil {
/**
* 开始分页
*
* @param pageNum 页码
* @param pageSize 每页多少条数据
*/
public static List startPage(List list, Integer pageNum,
Integer pageSize) {
if (list == null) {
return null;
}
if (list.size() == 0) {
return null;
}
Integer count = list.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (pageNum != pageCount) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
if (fromIndex >= count) {
return new ArrayList();
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}
package com.ssi.utils;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.handler.inter.IExcelDataHandler;
import com.ssi.exception.CustomizeException;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* Created by csq on 2018/8/18.
*/
public class PoiUtils {
public static final String[] EXCEL_EXT = {"xls", "xlsx"};
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass,
String fileName, boolean isCreateHeader, HttpServletResponse response) {
ExportParams exportParams = new ExportParams(title, sheetName);
exportParams.setCreateHeadRows(isCreateHeader);
defaultExport(list, pojoClass, fileName, response, exportParams);
}
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass,
String fileName, HttpServletResponse response) {
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
}
/**
* 一个excel 创建多个sheet
*
* @param list 多个Map key title 对应表格Title key entity 对应表格对应实体 key data Collection 数据
*/
public static void exportExcel(List<Map<String, Object>> list, String fileName,
HttpServletResponse response) {
defaultExport(list, fileName, response);
}
/**
* 用poi导出Excel文件的静态方法
*
* @param list 数据:只能是List<Map<String, Object>>类型
* @param sheetname Excel的sheet名字
*/
public static void exportExcel(List<Map<String, Object>> list, String sheetname, String fileName,
HttpServletResponse response) throws IOException {
//新建工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
//创建Excel的sheet
HSSFSheet sheet = workbook.createSheet(sheetname);
//从list任意一个Map对象里获取标题(字段名或属性名)放到sheet的第一行上,若第一条记录某字段值没有,则会没有该字段
Map<String, Object> map = list.get(0);
int num = 0;
HSSFRow first = sheet.createRow(0);//创建sheet的第一行
for (String key : map.keySet()) {
first.createCell(num).setCellValue(key);//创建num+1行并在第num+1列上赋值(字段名)
num++;
}
//从list取第一行到最后一行的内容并放到对应的Excel里,若记录里某字段值没有会有问题
int rownum = 1;//行数
for (Map<String, Object> data : list) {
HSSFRow row = sheet.createRow(rownum);//创建sheet的第rownum+1行
int n = 0;//列数
for (String key : data.keySet()) {
row.createCell(n).setCellValue(data.get(key).toString());//创建n+1行并在第n+1列上赋值
n++;
}
rownum++;
}
downLoadExcel(fileName, response, workbook);
}
private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName,
HttpServletResponse response, ExportParams exportParams) {
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
if (workbook != null)
;
downLoadExcel(fileName, response, workbook);
}
public static void downLoadExcel(String fileName, HttpServletResponse response,
Workbook workbook) {
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
} catch (IOException e) {
throw new CustomizeException(e.getMessage());
}
}
/**
* 一个excel 创建多个sheet
*
* @param list 多个Map key title 对应表格Title key entity 对应表格对应实体 key data Collection 数据
*/
private static void defaultExport(List<Map<String, Object>> list, String fileName,
HttpServletResponse response) {
Workbook workbook = ExcelExportUtil.exportExcel(list, ExcelType.HSSF);
if (workbook != null)
;
downLoadExcel(fileName, response, workbook);
}
public static <T> List<T> importExcel(String filePath, Integer titleRows, Integer headerRows,
Class<T> pojoClass) {
if (StringUtils.isBlank(filePath)) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
List<T> list = null;
try {
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
} catch (NoSuchElementException e) {
throw new CustomizeException("模板不能为空");
} catch (Exception e) {
e.printStackTrace();
throw new CustomizeException(e.getMessage());
}
return list;
}
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows,
Class<T> pojoClass) {
if (file == null) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
List<T> list = null;
try {
list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
} catch (NoSuchElementException e) {
throw new CustomizeException("excel文件不能为空");
} catch (Exception e) {
throw new CustomizeException(e.getMessage());
}
return list;
}
/**
* 检查文件名是否符合要求
*
* @param fileName 待监测文件名
* @param exts 后缀名集合
*/
public static boolean checkExt(String fileName, String[] exts) {
if (StringUtils.isBlank(fileName)) {
throw new CustomizeException("待校验文件名不能为空");
}
if (exts == null || exts.length == 0) {
throw new CustomizeException("文件后缀名数组不能为空");
}
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
for (int i = 0; i < exts.length; i++) {
if (ext.equals(exts[i])) {
return true;
}
}
return false;
}
public static void exportExcel(IExcelDataHandler<?> handler, List<?> list, String title,
String sheetName, Class<?> pojoClass, String fileName, boolean isCreateHeader,
HttpServletResponse response) {
ExportParams exportParams = new ExportParams(title, sheetName);
exportParams.setDataHandler(handler);
exportParams.setCreateHeadRows(isCreateHeader);
defaultExport(list, pojoClass, fileName, response, exportParams);
}
}
package com.ssi.utils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/**
* 查询参数
*/
public class QueryUtils<T> {
public IPage<T> getPage(Map<String, Object> params) {
return this.getPage(params, null, false);
}
public IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) {
//分页参数
int curPage = 1;
int limit = 10;
if (params.get("pageIndex") != null) {
curPage = (int) params.get("pageIndex");
}
if (params.get("pageSize") != null) {
limit = (int) params.get("pageSize");
}
//分页对象
Page<T> page = new Page<>(curPage, limit);
//分页参数
params.put("page", page);
//排序字段
String order = (String) params.get("order");
//没有排序字段,则不排序
if (StringUtils.isBlank(defaultOrderField)) {
return page;
}
//默认排序
if (isAsc) {
page.addOrder(OrderItem.asc(defaultOrderField));
} else {
page.addOrder(OrderItem.desc(defaultOrderField));
}
return page;
}
}
package com.ssi.utils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* @author ZhangLiYao
* @version 1.0
* @date 2020/3/4 10:54
*/
public class RestTemplateUtil {
private static class SingletonRestTemplate {
static final RestTemplate INSTANCE = new RestTemplate();
}
private RestTemplateUtil() {
}
public static RestTemplate getInstance() {
return SingletonRestTemplate.INSTANCE;
}
/**
* post 请求
*
* @param url 请求路径
* @param data body数据
* @param token JWT所需的Token,不需要的可去掉
*/
public static String post(String url, String data, String token) {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Encoding", "UTF-8");
headers.add("Content-Type", "application/json; charset=UTF-8");
if (token != null) {
headers.add("Authorization", token);
}
HttpEntity<String> requestEntity = new HttpEntity<>(data, headers);
return RestTemplateUtil.getInstance().postForObject(url, requestEntity, String.class);
}
/**
* get 请求
*
* @param url 请求路径
* @param token JWT所需的Token,不需要的可去掉
*/
public static String get(String url, String token) {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Encoding", "UTF-8");
headers.add("Content-Type", "application/json; charset=UTF-8");
if (token != null) {
headers.add("Authorization", token);
}
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
ResponseEntity<String> response = RestTemplateUtil.getInstance()
.exchange(url, HttpMethod.GET, requestEntity, String.class);
String responseBody = response.getBody();
return responseBody;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment