|
@@ -0,0 +1,518 @@
|
|
|
+package com.shkpr.service.alambizplugin.commtools;
|
|
|
+
|
|
|
+import com.global.base.component.SnowFlakeEx;
|
|
|
+import com.global.base.tools.*;
|
|
|
+import com.shkpr.service.alambizplugin.constants.CommDefine;
|
|
|
+import com.shkpr.service.alambizplugin.dto.LatLngBean;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.awt.geom.Path2D;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+public class CommTool {
|
|
|
+ public static final char[] HEX_DIGITS;
|
|
|
+ static {
|
|
|
+ HEX_DIGITS = "0123456789ABCDEF".toCharArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getPlatformByAgent(String strClientType, String strUserAgent){
|
|
|
+ return getPlatformByAgent(!StringUtils.isEmpty(strClientType)?strClientType:strUserAgent);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getPlatformByAgent(String strUserAgent){
|
|
|
+ String type = "pc";
|
|
|
+ if (StringUtils.isEmpty(strUserAgent))
|
|
|
+ return type;
|
|
|
+
|
|
|
+ String lowerAgent = strUserAgent.toLowerCase();
|
|
|
+ if(lowerAgent.contains("android") || lowerAgent.contains("linux")) {
|
|
|
+ type = "apk";
|
|
|
+ } else if (lowerAgent.contains("iphone") || lowerAgent.contains("ios") || lowerAgent.contains("ipad")){
|
|
|
+ type = "ios";
|
|
|
+ } else if (lowerAgent.indexOf("micromessenger") > -1){
|
|
|
+ type = "wx";
|
|
|
+ } else if (lowerAgent.indexOf("cs") > -1){
|
|
|
+ type = "cs";
|
|
|
+ } else if (lowerAgent.indexOf("windows") > -1){
|
|
|
+ type = "pc";
|
|
|
+ } else if (lowerAgent.contains("tri.")){
|
|
|
+ type = strUserAgent;
|
|
|
+ }
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isMobilePlatform(String platform){
|
|
|
+ return ("apk".equals(platform) || "ios".equals(platform) || "wx".equals(platform));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isTheThisFormatMatch(final String strFormatFilter, String strDesData){
|
|
|
+ if (!StringUtils.isEmpty(strFormatFilter) && !StringUtils.isEmpty(strDesData)) {
|
|
|
+ //正则表达式的模式
|
|
|
+ Pattern p = Pattern.compile(strFormatFilter);
|
|
|
+ //正则表达式的匹配器
|
|
|
+ Matcher m = p.matcher(strDesData);
|
|
|
+ //进行正则匹配
|
|
|
+ return m.matches();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int listSize(List<? extends Object> listSrc){
|
|
|
+ return (listSrc==null)?0:listSrc.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int collectionSize(Collection<? extends Object> cc){
|
|
|
+ return (cc==null)?0:cc.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int mapSize(Map<? extends Object, ? extends Object> mapSrc){
|
|
|
+ return (mapSrc==null)?0:mapSrc.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int lenString(String strSrc) {
|
|
|
+ if (StringUtils.isEmpty(strSrc))
|
|
|
+ return 0;
|
|
|
+ return strSrc.length();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean strBetweenLen(String strSrc, int nMinLen, int nMaxLen){
|
|
|
+ if (strSrc == null || nMinLen > nMaxLen)
|
|
|
+ return false;
|
|
|
+ return strSrc.length() >= nMinLen && strSrc.length() <= nMaxLen;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genAppApisID(){
|
|
|
+ return (new StringBuilder("AA")).append(SnowFlakeEx.getInstance().nextHexStrId(2)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genApisCaseID(){
|
|
|
+ return (new StringBuilder("AC")).append(SnowFlakeEx.getInstance().nextHexStrId(2)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genNotifyEventID(){
|
|
|
+ return (new StringBuilder("PNE")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genGisTotalTempID(){
|
|
|
+ return (new StringBuilder("PGT")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genElementApplyID(){
|
|
|
+ return (new StringBuilder("EPY")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genPublishBatchNo(){
|
|
|
+ return (new StringBuilder("PN")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genDeviceSN(){
|
|
|
+ StringBuilder tmp = new StringBuilder("GSM");
|
|
|
+ tmp.append(TimeTool.convertUTC2DateStr(System.currentTimeMillis(), TimeTool.TIMESTAMP_FORMAT_EX2).substring(2));
|
|
|
+ tmp.append(EncryptionUtil.MD5Hash(UUID.randomUUID().toString()).toUpperCase().substring(10, 21));
|
|
|
+ return tmp.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String list2QueryIn(List<? extends Object> listSrc){
|
|
|
+ StringBuilder str = new StringBuilder("");
|
|
|
+ if (listSrc != null && listSrc.size() > 0){
|
|
|
+ str.append("(");
|
|
|
+ int nStart = 0;
|
|
|
+ for (Object item:listSrc){
|
|
|
+ if (nStart++ > 0)
|
|
|
+ str.append(",");
|
|
|
+ if (item instanceof String){
|
|
|
+ str.append("'"+item+"'");
|
|
|
+ }else{
|
|
|
+ str.append(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str.append(")");
|
|
|
+ }
|
|
|
+ return str.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int totalCharCountsInStr(String srcStr, char chDes){
|
|
|
+ int nums = 0;
|
|
|
+ if (StringUtils.isEmpty(srcStr))
|
|
|
+ return nums;
|
|
|
+
|
|
|
+ char[] arr = srcStr.toCharArray();
|
|
|
+ for (char ch:arr){
|
|
|
+ if (ch == chDes)
|
|
|
+ nums++;
|
|
|
+ }
|
|
|
+ return nums;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int forceConvertToInt(Object oldObj, int defaultV){
|
|
|
+ if (oldObj != null){
|
|
|
+ if (oldObj.getClass().getSimpleName().equals("Double"))
|
|
|
+ return Double.valueOf((double)oldObj).intValue();
|
|
|
+ else if (oldObj.getClass().getSimpleName().equals("Float"))
|
|
|
+ return Float.valueOf((float)oldObj).intValue();
|
|
|
+ else
|
|
|
+ return CastUtil.castInt(oldObj, defaultV);
|
|
|
+ }
|
|
|
+ return defaultV;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String escapeInHex(final String src) {
|
|
|
+ StringBuilder tmp = new StringBuilder("");
|
|
|
+ if (StringUtils.isEmpty(src))
|
|
|
+ return tmp.toString();
|
|
|
+
|
|
|
+ int i;
|
|
|
+ char j;
|
|
|
+ tmp.ensureCapacity(src.length() * 6);
|
|
|
+ for (i = 0; i < src.length(); i++) {
|
|
|
+ j = src.charAt(i);
|
|
|
+ if (Character.isDigit(j) || Character.isLowerCase(j) || Character.isUpperCase(j))
|
|
|
+ tmp.append(j);
|
|
|
+ else if (j < 256) {
|
|
|
+ tmp.append(j);
|
|
|
+ /*tmp.append("%");
|
|
|
+ if (j < 16)
|
|
|
+ tmp.append("0");
|
|
|
+ tmp.append(Integer.toString(j, 16));
|
|
|
+ */
|
|
|
+ } else {
|
|
|
+ //tmp.append("%u");
|
|
|
+ //tmp.append(Integer.toString(j, 16));
|
|
|
+ tmp.append("&#x");
|
|
|
+ tmp.append(Integer.toString(j, 16));
|
|
|
+ tmp.append(";");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tmp.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String PHONE_MATCH_FILTER = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
|
|
|
+ public static String adjustMobilePhone(String phone){
|
|
|
+ if (!StringUtils.isEmpty(phone)
|
|
|
+ && phone.length() == 11
|
|
|
+ && isTheThisFormatMatch(PHONE_MATCH_FILTER, phone)){
|
|
|
+ return phone;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String exchangeMD5(String md5){
|
|
|
+ StringBuilder res = new StringBuilder("");
|
|
|
+ int len = md5.length()/2;
|
|
|
+ for (int i=0; i<len; i++){
|
|
|
+ int index = i*2;
|
|
|
+ res.append(Integer.toHexString((Integer.parseInt(String.valueOf(md5.charAt(index+1)), 16)<<4 | Integer.parseInt(String.valueOf(md5.charAt(index)), 16)) % 16).toUpperCase());
|
|
|
+ }
|
|
|
+ //for (int i = 0,j = md5.length()-1; i<=j; i++,j--){
|
|
|
+ // res.append(Integer.toHexString(((0x0F & md5.charAt(i)) ^ (0x0F & md5.charAt(j)))).toUpperCase());
|
|
|
+ //}
|
|
|
+ return res.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genUserUid(String account, String extend){
|
|
|
+ return "UUD" + exchangeMD5(EncryptionUtil.MD5Hash(account+extend));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String likeMap2LikeStr(Map<String, String> mapLikes, Set<String> filterKey){
|
|
|
+ StringBuilder strLikes = new StringBuilder("");
|
|
|
+ if (mapLikes != null && mapLikes.size() > 0){
|
|
|
+ int nStart = 0;
|
|
|
+ for(Map.Entry<String, String> entry:mapLikes.entrySet()){
|
|
|
+ String key = entry.getKey();
|
|
|
+ String data = entry.getValue();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(data) || !filterKey.contains(key)) //likes条件暂时只支持有限字段
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (nStart++ > 0)
|
|
|
+ strLikes.append(" or ");
|
|
|
+ strLikes.append(StringUtil.lower2UnLine(key)+" like '%"+data+"%' ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return strLikes.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取不规则多边形重心点
|
|
|
+ * @param mPoints
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static LatLngBean getCenterOfGravityPoint(List<LatLngBean> mPoints) {
|
|
|
+ double area = 0.0; //多边形面积
|
|
|
+ double Gx = 0.0, Gy = 0.0;// 重心的x、y
|
|
|
+ int pointSize = CommTool.listSize(mPoints);
|
|
|
+ if (pointSize >= 2){
|
|
|
+ for (int i = 1; i <= mPoints.size(); i++) {
|
|
|
+ double iLat = mPoints.get(i % pointSize).lat;
|
|
|
+ double iLng = mPoints.get(i % pointSize).lng;
|
|
|
+ double nextLat = mPoints.get(i - 1).lat;
|
|
|
+ double nextLng = mPoints.get(i - 1).lng;
|
|
|
+ double temp = (iLat * nextLng - iLng * nextLat) / 2.0;
|
|
|
+ area += temp;
|
|
|
+ Gx += temp * (iLat + nextLat) / 3.0;
|
|
|
+ Gy += temp * (iLng + nextLng) / 3.0;
|
|
|
+ }
|
|
|
+ Gx = Gx / area;
|
|
|
+ Gy = Gy / area;
|
|
|
+ }else if (pointSize == 1)
|
|
|
+ return mPoints.get(0);
|
|
|
+ return new LatLngBean(Gx, Gy);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定gis点是否在指定区域内
|
|
|
+ * @param areaGis
|
|
|
+ * @param lng
|
|
|
+ * @param lat
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isGisPointInArea(List<LatLngBean> areaGis, double lng, double lat){
|
|
|
+ if (listSize(areaGis) <= 2)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ Path2D.Double generalPath = new Path2D.Double();
|
|
|
+ LatLngBean firstPoint = areaGis.get(0);
|
|
|
+ if (firstPoint == null)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ generalPath.moveTo(firstPoint.getLng(), firstPoint.getLat());
|
|
|
+ for (int i=1;i<areaGis.size();i++){
|
|
|
+ LatLngBean nextPoint = areaGis.get(i);
|
|
|
+ if (nextPoint == null)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ generalPath.lineTo(nextPoint.getLng(), nextPoint.getLat());
|
|
|
+ }
|
|
|
+ generalPath.lineTo(firstPoint.getLng(), firstPoint.getLat());
|
|
|
+ generalPath.closePath();
|
|
|
+ return generalPath.contains(lng, lat);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定的点是否在线所属的bbox区域内
|
|
|
+ * @param lineBegin
|
|
|
+ * @param lineEnd
|
|
|
+ * @param lng
|
|
|
+ * @param lat
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isGisPointInLineArea(LatLngBean lineBegin, LatLngBean lineEnd, double lng, double lat){
|
|
|
+ List<LatLngBean> areaGis = new ArrayList<>();
|
|
|
+ double mixBoxLng = Double.min(lineBegin.getLng(), lineEnd.getLng());
|
|
|
+ double mixBoxLat = Double.min(lineBegin.getLat(), lineEnd.getLat());
|
|
|
+ double maxBoxLng = Double.max(lineBegin.getLng(), lineEnd.getLng());
|
|
|
+ double maxBoxLat = Double.max(lineBegin.getLat(), lineEnd.getLat());
|
|
|
+
|
|
|
+ if ((new BigDecimal(mixBoxLng).compareTo(new BigDecimal(lineBegin.getLng())) == 0
|
|
|
+ && new BigDecimal(mixBoxLat).compareTo(new BigDecimal(lineBegin.getLat())) == 0)
|
|
|
+ || (new BigDecimal(mixBoxLng).compareTo(new BigDecimal(lineEnd.getLng())) == 0
|
|
|
+ && new BigDecimal(mixBoxLat).compareTo(new BigDecimal(lineEnd.getLat())) == 0)){
|
|
|
+ areaGis.add(new LatLngBean(mixBoxLat, mixBoxLng));
|
|
|
+ areaGis.add(new LatLngBean(maxBoxLat, mixBoxLng));
|
|
|
+ areaGis.add(new LatLngBean(maxBoxLat, maxBoxLng));
|
|
|
+ areaGis.add(new LatLngBean(mixBoxLat, maxBoxLng));
|
|
|
+ }else {
|
|
|
+ areaGis.add(new LatLngBean(mixBoxLat, mixBoxLng));
|
|
|
+ areaGis.add(new LatLngBean(lineBegin.getLat(), lineBegin.getLng()));
|
|
|
+ areaGis.add(new LatLngBean(maxBoxLat, maxBoxLng));
|
|
|
+ areaGis.add(new LatLngBean(lineEnd.getLat(), lineEnd.getLng()));
|
|
|
+ }
|
|
|
+ return isGisPointInArea(areaGis, lng, lat);
|
|
|
+ }
|
|
|
+
|
|
|
+ //WGS84标准参考椭球中的地球长半径(单位:米)
|
|
|
+ private static final double EARTH_RADIUS = 6378137; //地球半径:米
|
|
|
+ /**
|
|
|
+ * 根据经纬度,计算两点间的距离
|
|
|
+ *
|
|
|
+ * @param lng1 第一个点的经度
|
|
|
+ * @param lat1 第一个点的纬度
|
|
|
+ * @param lng2 第二个点的经度
|
|
|
+ * @param lat2 第二个点的纬度
|
|
|
+ * @return 返回距离 单位:米
|
|
|
+ */
|
|
|
+ public static long getGisDistance(double lng1, double lat1, double lng2, double lat2) {
|
|
|
+ lat1 = Math.toRadians(lat1);
|
|
|
+ lat2 = Math.toRadians(lat2);
|
|
|
+ lng1 = Math.toRadians(lng1);
|
|
|
+ lng2 = Math.toRadians(lng2);
|
|
|
+
|
|
|
+ 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 Math.round(s * 10000) / 10000;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double getGisDistanceEx(double lng1, double lat1, double lng2, double lat2) {
|
|
|
+ lat1 = Math.toRadians(lat1);
|
|
|
+ lat2 = Math.toRadians(lat2);
|
|
|
+ lng1 = Math.toRadians(lng1);
|
|
|
+ lng2 = Math.toRadians(lng2);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定两个gis点是否在指定的距离内
|
|
|
+ * @param from 起始点
|
|
|
+ * @param to 终止点
|
|
|
+ * @param maxDistance 指定的最大距离(单位:米)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isGisPointNearPoint(LatLngBean from, LatLngBean to, long maxDistance){
|
|
|
+ return getGisDistance(from.getLng(), from.getLat(), to.getLng(), to.getLat()) <= maxDistance;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * gis点到gis线是否在指定的距离内
|
|
|
+ * @param fromPoint 起始gis点
|
|
|
+ * @param toLineGis 终止gis线
|
|
|
+ * @param maxDistance 指定的最大距离(单位:米)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isGisPointNearLine(LatLngBean fromPoint, List<LatLngBean> toLineGis, long maxDistance){
|
|
|
+ int nPointSize = CommTool.listSize(toLineGis);
|
|
|
+ if (nPointSize <= 0)
|
|
|
+ return false;
|
|
|
+ if (nPointSize <= 1)
|
|
|
+ return isGisPointNearPoint(fromPoint, toLineGis.get(0), maxDistance);
|
|
|
+ else {//直线或折线,注:是折线时需将其拆分成多条直线
|
|
|
+ for (int i=0;i<=toLineGis.size()-2;i++){
|
|
|
+ LatLngBean pointA = fromPoint;
|
|
|
+ LatLngBean pointB = toLineGis.get(i);
|
|
|
+ LatLngBean pointC = toLineGis.get(i+1);
|
|
|
+
|
|
|
+ long b = getGisDistance(pointA.getLng(), pointA.getLat(), pointC.getLng(), pointC.getLat());
|
|
|
+ if (b <= 0 || b <= maxDistance)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ long c = getGisDistance(pointA.getLng(), pointA.getLat(), pointB.getLng(), pointB.getLat());
|
|
|
+ if (c <= 0 || c <= maxDistance)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ long a = getGisDistance(pointB.getLng(), pointB.getLat(), pointC.getLng(), pointC.getLat());
|
|
|
+ if (a <= 0)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ long cosABC = (a*a + c*c - b*b)/(2*a*c);
|
|
|
+ if (cosABC <= 0){//直角或钝角
|
|
|
+ if (c <= maxDistance)
|
|
|
+ return true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ long cosACB = (a*a + b*b - c*c)/(2*a*b);
|
|
|
+ if (cosACB <= 0){//直角或钝角
|
|
|
+ if (b <= maxDistance)
|
|
|
+ return true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ long pp = (a+b+c)/2;
|
|
|
+ long ss = Math.round(10000*Math.sqrt(pp*(pp-a)*(pp-b)*(pp-c)))/10000;
|
|
|
+ long shortA2BC = 2*ss/a;
|
|
|
+ if (shortA2BC <= maxDistance)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }/*else if (nPointSize == 2){
|
|
|
+ if (isGisPointNearPoint(fromPoint, toLineGis.get(0), maxDistance))//指定点到直线一端的距离
|
|
|
+ return true;
|
|
|
+ if (isGisPointNearPoint(fromPoint, toLineGis.get(1), maxDistance))//指定点到直线另一端的距离
|
|
|
+ return true;
|
|
|
+ return getGisDistance(fromPoint.getLng()//指定点到直线中心点的距离
|
|
|
+ , fromPoint.getLat()
|
|
|
+ , (toLineGis.get(0).getLng()+toLineGis.get(1).getLng())/2
|
|
|
+ , (toLineGis.get(0).getLat()+toLineGis.get(1).getLat())/2) <= maxDistance;
|
|
|
+ }else {//折线
|
|
|
+ if (isGisPointInArea(toLineGis, fromPoint.getLng(), fromPoint.getLat()))//是否在折线的封闭区域内
|
|
|
+ return true;
|
|
|
+ return isGisPointNearPoint(fromPoint, getCenterOfGravityPoint(toLineGis), maxDistance);//指定点到折线封闭区域的重心距离
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genFileAttachmentId(String fileName, int type, String strExtend){
|
|
|
+ String time = TimeTool.convertUTC2DateStr(System.currentTimeMillis(), TimeTool.TIMESTAMP_FORMAT_EX2);
|
|
|
+ String fileNameHash = (StringUtils.isEmpty(fileName))? RandomUtil.getDigitalRandomStr(4):EncryptionUtil.MD5Hash(fileName).substring(0,4);
|
|
|
+ String extend = (StringUtils.isEmpty(strExtend))?RandomUtil.getDigitalRandomStr(4):strExtend;
|
|
|
+ return (new StringBuilder("FT"))
|
|
|
+ .append(time==null?"":time)
|
|
|
+ .append(String.format("%02d",type%100))
|
|
|
+ .append(fileNameHash==null?"":fileNameHash)
|
|
|
+ .append(extend==null?"":extend).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List safeList(List<? extends Object> listSrc){
|
|
|
+ if (listSrc == null)
|
|
|
+ return new ArrayList();
|
|
|
+ else
|
|
|
+ return listSrc;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isRootAdminID(String userId){
|
|
|
+ return CommDefine.ADMIN_USER_ID.equals(userId)
|
|
|
+ || CommDefine.INTERNAL_OPERATOR_ID.equals(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //84坐标系转2000坐标系
|
|
|
+ public static double[] convert84To2000(double latitude, double longitude) {
|
|
|
+ double x = 0.0, y = 0.0, z = 0.0;
|
|
|
+ double a = EARTH_RADIUS;
|
|
|
+ double f = 1.0 / 298.257223563;
|
|
|
+ double b = (1 - f) * a;
|
|
|
+ double e = Math.sqrt((a * a - b * b) / (a * a));
|
|
|
+ double E = Math.atan2(z, Math.sqrt(x * x + y * y));
|
|
|
+ double r = Math.sqrt(x * x + y * y + z * z);
|
|
|
+ double latitude1 = Math.atan2(z + e * e * b * Math.pow(Math.sin(E), 3), r - a * Math.pow(e, 2) * Math.pow(Math.cos(E), 3));
|
|
|
+ double longitude1 = Math.atan2(y, x);
|
|
|
+ double N = a / Math.sqrt(1 - Math.pow(e * Math.sin(latitude1), 2));
|
|
|
+ double h = r / Math.cos(latitude1) - N;
|
|
|
+ double X = (N + h) * Math.cos(latitude1) * Math.cos(longitude1);
|
|
|
+ double Y = (N + h) * Math.cos(latitude1) * Math.sin(longitude1);
|
|
|
+ double Z = (N * (1 - Math.pow(e, 2)) + h) * Math.sin(latitude1);
|
|
|
+ double k = 1.0000648438897;
|
|
|
+ double dx = -24.9;
|
|
|
+ double dy = 140.8;
|
|
|
+ double dz = 76.3;
|
|
|
+ double X1 = k * (X + dx);
|
|
|
+ double Y1 = k * (Y + dy);
|
|
|
+ double Z1 = k * (Z + dz);
|
|
|
+ return new double[]{X1, Y1, Z1};
|
|
|
+ }
|
|
|
+
|
|
|
+ //已知点A、B、C,求夹角<ABC
|
|
|
+ public static double angleBFromGis(LatLngBean pointA, LatLngBean pointB, LatLngBean pointC){
|
|
|
+ double side_c = getGisDistanceEx(pointA.getLng(), pointA.getLat(), pointB.getLng(), pointB.getLat());
|
|
|
+ double side_a = getGisDistanceEx(pointB.getLng(), pointB.getLat(), pointC.getLng(), pointC.getLat());
|
|
|
+ double side_b = getGisDistanceEx(pointA.getLng(), pointA.getLat(), pointC.getLng(), pointC.getLat());
|
|
|
+ return angleBFromSide(side_a, side_b, side_c);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double angleBFromSide(double a, double b, double c){
|
|
|
+ if (c + a < b)
|
|
|
+ return -1.0;
|
|
|
+ if (c + a == b)
|
|
|
+ return 180.0;
|
|
|
+ return Math.toDegrees(Math.acos((a*a + c*c - b*b) / (2*a*c)));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genSurveyProjID(){
|
|
|
+ return (new StringBuilder("GSP")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String genSurveyJobID(){
|
|
|
+ return (new StringBuilder("GJB")).append(SnowFlakeEx.getInstance().nextHexStrId(4)).toString();
|
|
|
+ }
|
|
|
+}
|