Commit c7557997 by java-李谡

提交测试

parent 9dc0393b
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
#\u7A0B\u5E8F\u8FD0\u884C\u8BB0\u5F55 #\u7A0B\u5E8F\u8FD0\u884C\u8BB0\u5F55
#Mon Sep 04 10:06:34 CST 2017 #Wed Nov 27 12:41:05 CST 2019
push.task.is.running=0 push.task.is.running=0
ods.task.last.time=2016-10-27 17\:53\:32 ods.task.last.time=2016-10-27 17\:53\:32
dynamics.task.is.running=0 dynamics.task.is.running=0
...@@ -9,10 +9,10 @@ dynamics.task.last.time=2017-08-05 16\:59\:20 ...@@ -9,10 +9,10 @@ dynamics.task.last.time=2017-08-05 16\:59\:20
ods.task.is.running=0 ods.task.is.running=0
foc.flight.assignment.page.index=2 foc.flight.assignment.page.index=2
sound.db.task.is.running=0 sound.db.task.is.running=0
sound.task.is.running=0
push.task.last.time=2017-02-23 15\:27\:00 push.task.last.time=2017-02-23 15\:27\:00
sound.task.is.running=0
ods.change.task.last.time=2016-12-22 14\:27\:19 ods.change.task.last.time=2016-12-22 14\:27\:19
sound.task.last.time=2017-09-04 10\:06\:33 sound.task.last.time=2019-11-27 12\:40\:40
assignment.task.last.time=2016-12-03 18\:05\:20 assignment.task.last.time=2016-12-03 18\:05\:20
ods.change.task.is.running=0 ods.change.task.is.running=0
foc.sound.page.index=2 foc.sound.page.index=2
......
...@@ -505,24 +505,28 @@ public class SoundService { ...@@ -505,24 +505,28 @@ public class SoundService {
UserInfo callUser = new UserInfo(); UserInfo callUser = new UserInfo();
if (StringUtils.isNoneBlank(entity.getCallNo())) { if (StringUtils.isNoneBlank(entity.getCallNo())) {
callUser = GetIdByPhone(entity.getCallNo()); callUser = GetIdByPhone(entity.getCallNo());
System.out.println("主叫号码:"+entity.getCallNo());
if (callUser == null) { if (callUser == null) {
System.out.println("未查询到主叫号码用户信息");
callUser = new UserInfo(); callUser = new UserInfo();
callUser.setId("1"); callUser.setId("1");
callUser.setName(entity.getCallNo()); callUser.setName(entity.getCallNo());
} }
System.out.println("主叫号码用户信息:"+callUser.getId());
} else { } else {
return; return;
} }
UserInfo acceptUser = new UserInfo(); UserInfo acceptUser = new UserInfo();
if (StringUtils.isNoneBlank(entity.getAcceptNo())) { if (StringUtils.isNoneBlank(entity.getAcceptNo())) {
System.out.println("被叫号码:"+entity.getAcceptNo());
acceptUser = GetIdByPhone(entity.getAcceptNo()); acceptUser = GetIdByPhone(entity.getAcceptNo());
if (acceptUser == null) { if (acceptUser == null) {
System.out.println("未查询到主叫号码用户信息");
acceptUser = new UserInfo(); acceptUser = new UserInfo();
acceptUser.setId("1"); acceptUser.setId("1");
acceptUser.setName(entity.getAcceptNo()); acceptUser.setName(entity.getAcceptNo());
} }
System.out.println("被叫号码用户信息:"+acceptUser.getId());
} else { } else {
return; return;
} }
...@@ -804,5 +808,7 @@ public class SoundService { ...@@ -804,5 +808,7 @@ public class SoundService {
DBHandler dBHandler = new DBHandler(); DBHandler dBHandler = new DBHandler();
dBHandler.batchInsert(Constants.FOC_CALLSOUND_RECORDS, columnMapList); dBHandler.batchInsert(Constants.FOC_CALLSOUND_RECORDS, columnMapList);
} }
} }
...@@ -228,4 +228,9 @@ public class SoundDbTaskMain { ...@@ -228,4 +228,9 @@ public class SoundDbTaskMain {
} }
return defaultId; return defaultId;
} }
// public static void main(String[] args) {
// SoundService soundService = new SoundService();
// soundService.GetIdByPhone("6136");
// }
} }
package com.foc.util; package com.foc.util;
import java.lang.reflect.Type;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.conf.GConstants; import com.foc.conf.GConstants;
import com.foc.fetcher.FetchEntity;
import com.foc.fetcher.HCFetcher;
import com.foc.fetcher.HttpClientUtil; import com.foc.fetcher.HttpClientUtil;
import com.foc.hrm.entity.User2RoleEntity;
import com.foc.phone.area.PhoneAreaEntity; import com.foc.phone.area.PhoneAreaEntity;
import com.foc.phone.area.PhoneAreaUtil; import com.foc.phone.area.PhoneAreaUtil;
import com.foc.sound.entity.CallPhoneInfoListEntity; import com.google.gson.JsonObject;
import com.foc.sound.entity.UserInfo; import org.apache.commons.lang3.StringUtils;
import com.uc.entity.UserEntity;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
public class Util { public class Util {
public static <T> List<T> arrayApi(String uri, Map<String, Object> contents, Class<T> clazz) { public static <T> List<T> arrayApi(String uri, Map<String, Object> contents, Class<T> clazz) {
try { try {
StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", "http://127.0.0.1:8080/")) StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", "http://127.0.0.1:8080/"))
.append(uri); .append(uri);
System.out.println("请求地址:" + url);
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
content.put("platform", "PC"); content.put("platform", "PC");
content.put("deviceToken", ""); content.put("deviceToken", "");
content.put("appCode", "10001"); content.put("appCode", "10001");
content.put("language", "zh_CN"); content.put("language", "zh_CN");
content.put("versionName", "1.0"); content.put("versionName", "1.0");
for(Entry<String, Object> param:contents.entrySet()){ for (Entry<String, Object> param : contents.entrySet()) {
content.put(param.getKey(), param.getValue()); content.put(param.getKey(), param.getValue());
} }
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("content", JSON.toJSONString(content)); params.put("content", JSON.toJSONString(content));
System.out.println("content:" + JSON.toJSONString(content));
String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content"))); String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content")));
params.put("sign", sign); params.put("sign", sign);
String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8"); String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8");
if(res == null){ System.out.println("请求结果:"+ res);
if (res == null) {
res = HttpClientUtil.doPost(url.toString(), params, "UTF-8"); res = HttpClientUtil.doPost(url.toString(), params, "UTF-8");
if(res == null) if (res == null) {
return null; return null;
}
} }
JSONObject result = JSON.parseObject(res); JSONObject result = JSON.parseObject(res);
if("2000".equals(result.getString("status"))){ if ("2000".equals(result.getString("status"))) {
return JSON.parseArray(result.getString("data"), clazz); return JSON.parseArray(result.getString("data"), clazz);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public static <T> T objectApi(String uri, Map<String, Object> contents, Class<T> clazz) { public static <T> T objectApi(String uri, Map<String, Object> contents, Class<T> clazz) {
try { try {
StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", "http://127.0.0.1:8080/")) StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", "http://127.0.0.1:8080/"))
.append(uri); .append(uri);
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
content.put("platform", "PC"); content.put("platform", "PC");
content.put("deviceToken", ""); content.put("deviceToken", "");
content.put("appCode", "10001"); content.put("appCode", "10001");
content.put("language", "zh_CN"); content.put("language", "zh_CN");
content.put("versionName", "1.0"); content.put("versionName", "1.0");
for(Entry<String, Object> param:contents.entrySet()){ for (Entry<String, Object> param : contents.entrySet()) {
content.put(param.getKey(), param.getValue()); content.put(param.getKey(), param.getValue());
} }
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("content", JSON.toJSONString(content)); params.put("content", JSON.toJSONString(content));
String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content"))); String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content")));
params.put("sign", sign); params.put("sign", sign);
String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8"); String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8");
if(res == null){ if (res == null) {
res = HttpClientUtil.doPost(url.toString(), params, "UTF-8"); res = HttpClientUtil.doPost(url.toString(), params, "UTF-8");
if(res == null) if (res == null)
return null; return null;
} }
if("class com.alibaba.fastjson.JSONObject".equals(clazz.toString())) if ("class com.alibaba.fastjson.JSONObject".equals(clazz.toString()))
return JSON.parseObject(res, clazz); return JSON.parseObject(res, clazz);
if("class java.lang.String".equals(clazz.toString())) if ("class java.lang.String".equals(clazz.toString()))
return JSON.parseObject(res, clazz); return JSON.parseObject(res, clazz);
JSONObject result = JSON.parseObject(res); JSONObject result = JSON.parseObject(res);
if("2000".equals(result.getString("status"))){ if ("2000".equals(result.getString("status"))) {
return JSON.parseObject(result.getString("data"), clazz); return JSON.parseObject(result.getString("data"), clazz);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public static String updateGroupAvatar(String groupId, String userCode) { public static String updateGroupAvatar(String groupId, String userCode) {
try { try {
if (StringUtils.isNotBlank(groupId)) { if (StringUtils.isNotBlank(groupId)) {
StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", "")) StringBuilder url = new StringBuilder(GConstants.getValue("foc.api.url", ""))
.append("/api/im/group/updateGroupAvatar"); .append("/api/im/group/updateGroupAvatar");
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("content", "{\"lang\":\"CN\",\"platform\":\"PC\",\"deviceToken\":\"deviceToken\"," params.put("content", "{\"lang\":\"CN\",\"platform\":\"PC\",\"deviceToken\":\"deviceToken\","
+ "\"appCode\":\"10001\",\"language\":\"zh_CN\",\"versionName\":\"1.0\",\"userCode\":\"" + "\"appCode\":\"10001\",\"language\":\"zh_CN\",\"versionName\":\"1.0\",\"userCode\":\""
+ (StringUtils.isBlank(userCode) ? "123" : userCode) + "\",\"groupId\":\"" + groupId + "\"}"); + (StringUtils.isBlank(userCode) ? "123" : userCode) + "\",\"groupId\":\"" + groupId + "\"}");
String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content"))); String sign = GlobalUtil.getParamsSignStr(GConstants.SIGN_PRIVATE_KEY, String.valueOf(params.get("content")));
params.put("sign", sign); params.put("sign", sign);
String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8"); String res = HttpClientUtil.doPost(url.toString(), params, "UTF-8");
// System.out.println(res); // System.out.println(res);
JSONObject object = JSON.parseObject(res); JSONObject object = JSON.parseObject(res);
if(object != null && object.containsKey("status")){ if (object != null && object.containsKey("status")) {
return object.getString("status"); return object.getString("status");
} }
} }
...@@ -139,68 +130,72 @@ public class Util { ...@@ -139,68 +130,72 @@ public class Util {
} }
return "4001"; return "4001";
} }
/** /**
* 设置图片全名称 * 设置图片全名称
* *
* @author renmb
* @time 2016年12月11日
* @param url * @param url
* @param want * @param want
* @return * @return
* @author renmb
* @time 2016年12月11日
*/ */
public static String getAbsoluteUrl(String url, String want) { public static String getAbsoluteUrl(String url, String want) {
if(StringUtils.isBlank(url)) if (StringUtils.isBlank(url))
return getAbsoluteUrl(want); return getAbsoluteUrl(want);
if(url.startsWith("http://") || url.startsWith("https://"))// 绝对路径 if (url.startsWith("http://") || url.startsWith("https://"))// 绝对路径
return url; return url;
if(GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径 if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径
return GConstants.FILE_PREFIX_URL+url.replaceAll("^/+", ""); return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", "");
return GConstants.FILE_PREFIX_URL+url; return GConstants.FILE_PREFIX_URL + url;
} }
/** /**
* 获取文件的绝对路径 * 获取文件的绝对路径
* *
* @author renmb
* @time 2016年9月1日
* @param url * @param url
* @return * @return
* @author renmb
* @time 2016年9月1日
*/ */
public static String getAbsoluteUrl(String url) { public static String getAbsoluteUrl(String url) {
if(StringUtils.isBlank(url)) if (StringUtils.isBlank(url))
return ""; return "";
if(url.startsWith("http://") || url.startsWith("https://"))// 绝对路径 if (url.startsWith("http://") || url.startsWith("https://"))// 绝对路径
return url; return url;
if(GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径 if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径
return GConstants.FILE_PREFIX_URL+url.replaceAll("^/+", ""); return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", "");
return GConstants.FILE_PREFIX_URL+url; return GConstants.FILE_PREFIX_URL + url;
} }
/** /**
* 获取相对路径地址 * 获取相对路径地址
* *
* @author renmb
* @time 2017年1月13日
* @param url * @param url
* @return * @return
* @author renmb
* @time 2017年1月13日
*/ */
public static String getRelativePath(String url) { public static String getRelativePath(String url) {
if(StringUtils.isBlank(url)) if (StringUtils.isBlank(url))
return ""; return "";
return url.replaceAll(GConstants.FILE_PREFIX_URL, ""); return url.replaceAll(GConstants.FILE_PREFIX_URL, "");
// return url; // return url;
} }
public static Date utc2Local(String utcTime) { public static Date utc2Local(String utcTime) {
try { try {
String pattern = null; String pattern = null;
if("yyyy-MM-dd HH:mm".length() == utcTime.length()){ if ("yyyy-MM-dd HH:mm".length() == utcTime.length()) {
pattern = "yyyy-MM-dd HH:mm"; pattern = "yyyy-MM-dd HH:mm";
} else if("yyyy-MM-dd HH:mm:ss".length() == utcTime.length()){ } else if ("yyyy-MM-dd HH:mm:ss".length() == utcTime.length()) {
pattern = "yyyy-MM-dd HH:mm:ss"; pattern = "yyyy-MM-dd HH:mm:ss";
} else if("yyyy-MM-dd".length() == utcTime.length()){ } else if ("yyyy-MM-dd".length() == utcTime.length()) {
pattern = "yyyy-MM-dd"; pattern = "yyyy-MM-dd";
} }
SimpleDateFormat utcFormater = new SimpleDateFormat(pattern); SimpleDateFormat utcFormater = new SimpleDateFormat(pattern);
...@@ -217,121 +212,123 @@ public class Util { ...@@ -217,121 +212,123 @@ public class Util {
} }
return null; return null;
} }
public static Date utc2Local(Date utcDate) { public static Date utc2Local(Date utcDate) {
try { try {
// TimeZone bjtz = TimeZone.getTimeZone("Asia/Shanghai"); // TimeZone bjtz = TimeZone.getTimeZone("Asia/Shanghai");
// TimeZone bjtz = TimeZone.getDefault(); // TimeZone bjtz = TimeZone.getDefault();
TimeZone oldZone = TimeZone.getTimeZone("UTC"); TimeZone oldZone = TimeZone.getTimeZone("UTC");
TimeZone newZone = TimeZone.getTimeZone("GMT+08:00"); TimeZone newZone = TimeZone.getTimeZone("GMT+08:00");
// int timeOffset = oldZone.getRawOffset() - newZone.getRawOffset(); // int timeOffset = oldZone.getRawOffset() - newZone.getRawOffset();
return changeTimeZone(utcDate, oldZone, newZone); return changeTimeZone(utcDate, oldZone, newZone);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return null; return null;
} }
/** /**
*
*
* @author renmb
* @time 2016年10月1日
* @param date * @param date
* @return * @return
* @author renmb
* @time 2016年10月1日
*/ */
public static Date local2Utc(Date date) { public static Date local2Utc(Date date) {
try { try {
// TimeZone bjtz = TimeZone.getTimeZone("Asia/Shanghai"); // TimeZone bjtz = TimeZone.getTimeZone("Asia/Shanghai");
// TimeZone bjtz = TimeZone.getDefault(); // TimeZone bjtz = TimeZone.getDefault();
TimeZone oldZone = TimeZone.getTimeZone("GMT+08:00"); TimeZone oldZone = TimeZone.getTimeZone("GMT+08:00");
TimeZone newZone = TimeZone.getTimeZone("UTC"); TimeZone newZone = TimeZone.getTimeZone("UTC");
// int timeOffset = oldZone.getRawOffset() - newZone.getRawOffset(); // int timeOffset = oldZone.getRawOffset() - newZone.getRawOffset();
return changeTimeZone(date, oldZone, newZone); return changeTimeZone(date, oldZone, newZone);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return null; return null;
} }
/** /**
* 时区转换 * 时区转换
* *
* @author renmb
* @time 2016年10月1日
* @param date * @param date
* @param oldZone * @param oldZone
* @param newZone * @param newZone
* @return * @return
* @author renmb
* @time 2016年10月1日
*/ */
public static Date changeTimeZone(Date date, TimeZone oldZone, TimeZone newZone) { public static Date changeTimeZone(Date date, TimeZone oldZone, TimeZone newZone) {
try { try {
GregorianCalendar localGregorianCalendar1 = new GregorianCalendar(oldZone); GregorianCalendar localGregorianCalendar1 = new GregorianCalendar(oldZone);
localGregorianCalendar1.setTime(date); localGregorianCalendar1.setTime(date);
GregorianCalendar localGregorianCalendar2 = new GregorianCalendar(newZone); GregorianCalendar localGregorianCalendar2 = new GregorianCalendar(newZone);
localGregorianCalendar2.setTimeInMillis(localGregorianCalendar1.getTimeInMillis()); localGregorianCalendar2.setTimeInMillis(localGregorianCalendar1.getTimeInMillis());
return new Date(localGregorianCalendar2.getTimeInMillis()); return new Date(localGregorianCalendar2.getTimeInMillis());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return null; return null;
} }
public static String getDurationTime(long time){
public static String getDurationTime(long time) {
String buffer = ""; String buffer = "";
buffer = ":"+time%1000+"纳秒"; buffer = ":" + time % 1000 + "纳秒";
time = time/1000;//微秒 time = time / 1000;//微秒
buffer = ":"+time%1000+"微秒"+buffer; buffer = ":" + time % 1000 + "微秒" + buffer;
time = time/1000;//毫秒 time = time / 1000;//毫秒
buffer = ":"+time%1000+"毫秒"+buffer; buffer = ":" + time % 1000 + "毫秒" + buffer;
time = time/1000;//毫秒 time = time / 1000;//毫秒
buffer = ":"+time%60+"秒"+buffer; buffer = ":" + time % 60 + "秒" + buffer;
time = time/60;//秒 time = time / 60;//秒
buffer =time+"分钟"+buffer; buffer = time + "分钟" + buffer;
return buffer; return buffer;
} }
/** /**
* 格式化手机号 * 格式化手机号
* *
* @author renmb
* @time 2016年12月12日
* @param mobile * @param mobile
* @return * @return
* @author renmb
* @time 2016年12月12日
*/ */
public static String formatedMobile(String mobile){ public static String formatedMobile(String mobile) {
if(mobile == null || mobile.length() == 0) if (mobile == null || mobile.length() == 0)
return mobile; return mobile;
try { try {
String[] species = mobile.split("\\s+");// 只使用第一个手机号 String[] species = mobile.split("\\s+");// 只使用第一个手机号
if(species.length>1 && species[0].matches("1\\d+") && species[1].matches("1\\d+")){ if (species.length > 1 && species[0].matches("1\\d+") && species[1].matches("1\\d+")) {
mobile = species[0]; mobile = species[0];
} }
mobile = mobile.replaceAll("+", "+");// 处理错误字符 mobile = mobile.replaceAll("+", "+");// 处理错误字符
mobile = mobile.replaceAll("[^0-9|+]+", "");// 将非电话号码替换为空 mobile = mobile.replaceAll("[^0-9|+]+", "");// 将非电话号码替换为空
// System.out.println("mobile:"+mobile); // System.out.println("mobile:"+mobile);
if(mobile.startsWith("+")){// 国外手机号,前面加拨3个0 if (mobile.startsWith("+")) {// 国外手机号,前面加拨3个0
return "000"+mobile.replace("+", ""); return "000" + mobile.replace("+", "");
} else if(mobile.matches("\\d+")){ } else if (mobile.matches("\\d+")) {
PhoneAreaEntity area = PhoneAreaUtil.get360PhoneArea(mobile); PhoneAreaEntity area = PhoneAreaUtil.get360PhoneArea(mobile);
if(area == null){// 二次请求 if (area == null) {// 二次请求
area = PhoneAreaUtil.get360PhoneArea(mobile); area = PhoneAreaUtil.get360PhoneArea(mobile);
} }
if(area != null && StringUtils.isNotBlank(area.getProvince())){// 能够查到省份信息 if (area != null && StringUtils.isNotBlank(area.getProvince())) {// 能够查到省份信息
if(area.getProvince().contains("北京") if (area.getProvince().contains("北京")
|| (StringUtils.isNotBlank(area.getCity()) || (StringUtils.isNotBlank(area.getCity())
&& area.getCity().contains("北京"))){// 北京前面加拨一个0 && area.getCity().contains("北京"))) {// 北京前面加拨一个0
return "0"+mobile; return "0" + mobile;
} else {// 非北京号码加拨两个0 } else {// 非北京号码加拨两个0
return "00"+mobile; return "00" + mobile;
} }
} }
} }
...@@ -340,16 +337,17 @@ public class Util { ...@@ -340,16 +337,17 @@ public class Util {
} }
return mobile; return mobile;
} }
/** /**
* 格式化座机号 * 格式化座机号
* *
* @author renmb
* @time 2016年12月12日
* @param workPhone * @param workPhone
* @return * @return
* @author renmb
* @time 2016年12月12日
*/ */
public static String formatedWorkPhone(String workPhone){ public static String formatedWorkPhone(String workPhone) {
if(workPhone == null || workPhone.length() == 0) if (workPhone == null || workPhone.length() == 0)
return workPhone; return workPhone;
try { try {
System.out.println(workPhone + ":格式化不匹配,#"); System.out.println(workPhone + ":格式化不匹配,#");
...@@ -358,35 +356,35 @@ public class Util { ...@@ -358,35 +356,35 @@ public class Util {
if (workPhone.matches("0+")) { if (workPhone.matches("0+")) {
workPhone = ""; workPhone = "";
} else if (workPhone.startsWith("0") == false) { } else if (workPhone.startsWith("0") == false) {
if(workPhone.startsWith("1") && workPhone.length() == 11){// 非座机号,是手机号,将号码处理为空 if (workPhone.startsWith("1") && workPhone.length() == 11) {// 非座机号,是手机号,将号码处理为空
workPhone = ""; workPhone = "";
} }
} }
if(workPhone.startsWith("+") == false){// 去掉电话号码中间的加号 if (workPhone.startsWith("+") == false) {// 去掉电话号码中间的加号
workPhone = workPhone.replace("+", ""); workPhone = workPhone.replace("+", "");
} }
if(workPhone.startsWith("0106961")){// 1、010 6961 xxxx -> xxxx 内部号码,直接拨短号 if (workPhone.startsWith("0106961")) {// 1、010 6961 xxxx -> xxxx 内部号码,直接拨短号
workPhone = workPhone.replace("0106961", ""); workPhone = workPhone.replace("0106961", "");
} else if(workPhone.startsWith("06961")){// 2、06961 xxxx -> xxxx 内部号码,直接拨短号 } else if (workPhone.startsWith("06961")) {// 2、06961 xxxx -> xxxx 内部号码,直接拨短号
workPhone = workPhone.replace("06961", ""); workPhone = workPhone.replace("06961", "");
} else if(workPhone.startsWith("6961")){// 2、6961 xxxx -> xxxx 内部号码,直接拨短号 } else if (workPhone.startsWith("6961")) {// 2、6961 xxxx -> xxxx 内部号码,直接拨短号
workPhone = workPhone.replace("6961", ""); workPhone = workPhone.replace("6961", "");
} else if(workPhone.startsWith("010")){// 3、010 xxxx xxxx -> 0 xxxx xxxx 北京号码,去掉区号,加拨0 } else if (workPhone.startsWith("010")) {// 3、010 xxxx xxxx -> 0 xxxx xxxx 北京号码,去掉区号,加拨0
workPhone = workPhone.replace("010", "0"); workPhone = workPhone.replace("010", "0");
} else if(workPhone.startsWith("+")){// 4、+ xxxx xxxx -> 000 xxxx xxxx 北京号码,去掉+号,加拨000 } else if (workPhone.startsWith("+")) {// 4、+ xxxx xxxx -> 000 xxxx xxxx 北京号码,去掉+号,加拨000
workPhone = workPhone.replace("+", "000"); workPhone = workPhone.replace("+", "000");
} else if (workPhone.indexOf(",") == 1 & workPhone.indexOf("#") == 1) { } else if (workPhone.indexOf(",") == 1 & workPhone.indexOf("#") == 1) {
workPhone = workPhone; workPhone = workPhone;
} else { // 5、xxx xxxx xxxx -> 0 xxx xxxx xxxx 国内非北京号码,加拨0 } else { // 5、xxx xxxx xxxx -> 0 xxx xxxx xxxx 国内非北京号码,加拨0
workPhone = "0"+workPhone; workPhone = "0" + workPhone;
} }
return workPhone; return workPhone;
} catch (Exception e) { } catch (Exception e) {
...@@ -394,24 +392,25 @@ public class Util { ...@@ -394,24 +392,25 @@ public class Util {
} }
return workPhone; return workPhone;
} }
/** /**
* 获取堆栈信息 * 获取堆栈信息
* *
* @author renmb
* @time 2016年10月21日
* @param e * @param e
* @return * @return
* @author renmb
* @time 2016年10月21日
*/ */
public static String getStackTrace(Throwable e) { public static String getStackTrace(Throwable e) {
String error = ""; String error = "";
Writer errors = null; Writer errors = null;
PrintWriter printWriter = null; PrintWriter printWriter = null;
try { try {
errors = new StringWriter(); errors = new StringWriter();
printWriter = new PrintWriter(errors); printWriter = new PrintWriter(errors);
e.printStackTrace(printWriter); e.printStackTrace(printWriter);
error = errors.toString(); error = errors.toString();
printWriter.close(); printWriter.close();
...@@ -422,63 +421,64 @@ public class Util { ...@@ -422,63 +421,64 @@ public class Util {
} }
return error; return error;
} }
/** /**
* 获取文件的扩展名称 * 获取文件的扩展名称
*
* @param filename * @param filename
* @return * @return
*/ */
public static String getExtensionName(String filename) { public static String getExtensionName(String filename) {
if(filename == null || filename.length() == 0) if (filename == null || filename.length() == 0)
return null; return null;
if(filename.contains(".")){ if (filename.contains(".")) {
String[] species = filename.split("\\."); String[] species = filename.split("\\.");
return "."+species[species.length-1].toLowerCase(); return "." + species[species.length - 1].toLowerCase();
} }
return null; return null;
} }
/** /**
* 新就版本进行比较,如果新版本比老版本高则返回true,否则返回false * 新就版本进行比较,如果新版本比老版本高则返回true,否则返回false
* *
* @author renmb
* @time 2016年8月3日
* @param oldVersion * @param oldVersion
* @param version * @param version
* @return * @return
* @author renmb
* @time 2016年8月3日
*/ */
public static boolean compareVersion(String oldVersion, String version) { public static boolean compareVersion(String oldVersion, String version) {
if(version != null && oldVersion != null) { if (version != null && oldVersion != null) {
String checkVersion[] = version.split("\\."); String checkVersion[] = version.split("\\.");
String originalVersion[] = oldVersion.split("\\."); String originalVersion[] = oldVersion.split("\\.");
int maxlength = (originalVersion.length >= checkVersion.length)?originalVersion.length:checkVersion.length; int maxlength = (originalVersion.length >= checkVersion.length) ? originalVersion.length : checkVersion.length;
// go through all Version-parts // go through all Version-parts
for(int i= 0; i < maxlength; i++) { for (int i = 0; i < maxlength; i++) {
// if the checked version is too short // if the checked version is too short
if ( checkVersion.length <= i if (checkVersion.length <= i
&& originalVersion[i].equals(0)) && originalVersion[i].equals(0))
return true; return true;
else if (checkVersion.length <= i) else if (checkVersion.length <= i)
return false; return false;
// if the original version is long enough // if the original version is long enough
if(originalVersion.length > i) { if (originalVersion.length > i) {
// convert to integer // convert to integer
try { try {
int originalVersNumber = Integer.valueOf(originalVersion[i]).intValue(); int originalVersNumber = Integer.valueOf(originalVersion[i]).intValue();
int checkVersNumber = Integer.valueOf(checkVersion[i]).intValue(); int checkVersNumber = Integer.valueOf(checkVersion[i]).intValue();
// check the numbers // check the numbers
if(checkVersNumber > originalVersNumber) { if (checkVersNumber > originalVersNumber) {
return true; return true;
} else if(checkVersNumber < originalVersNumber) { } else if (checkVersNumber < originalVersNumber) {
return false; return false;
} }
} catch(Exception e) { } catch (Exception e) {
return false; return false;
} }
} } else {
else {
return true; return true;
} }
} }
...@@ -486,6 +486,7 @@ public class Util { ...@@ -486,6 +486,7 @@ public class Util {
} }
return false; return false;
} }
/** /**
* 生成安全的密码,生成随机的16位salt并经过1024次 sha-1 hash * 生成安全的密码,生成随机的16位salt并经过1024次 sha-1 hash
*/ */
...@@ -494,49 +495,50 @@ public class Util { ...@@ -494,49 +495,50 @@ public class Util {
String plain = Encodes.unescapeHtml(plainPassword); String plain = Encodes.unescapeHtml(plainPassword);
byte[] salt = Digests.generateSalt(GConstants.SALT_SIZE); byte[] salt = Digests.generateSalt(GConstants.SALT_SIZE);
byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, GConstants.HASH_INTERATIONS); byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, GConstants.HASH_INTERATIONS);
return Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword); return Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return null; return null;
} }
/** /**
* 验证密码 * 验证密码
*
* @param plainPassword 明文密码 * @param plainPassword 明文密码
* @param password 密文密码 * @param password 密文密码
* @return 验证成功返回true * @return 验证成功返回true
*/ */
public static boolean validatePassword(String plainPassword, String password) { public static boolean validatePassword(String plainPassword, String password) {
try { try {
String plain = Encodes.unescapeHtml(plainPassword); String plain = Encodes.unescapeHtml(plainPassword);
byte[] salt = Encodes.decodeHex(password.substring(0,16)); byte[] salt = Encodes.decodeHex(password.substring(0, 16));
byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, GConstants.HASH_INTERATIONS); byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, GConstants.HASH_INTERATIONS);
return password.equals(Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword)); return password.equals(Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword));
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return false; return false;
} }
public static String getGenericCode(){ public static String getGenericCode() {
try { try {
return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase(); return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase();
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return null; return null;
} }
public static boolean isrContainValues(JSONArray data, String... values) { public static boolean isrContainValues(JSONArray data, String... values) {
if(data == null || values == null) if (data == null || values == null)
return false; return false;
int count = 0; int count = 0;
int len = data.size(); int len = data.size();
for(String val:values){ for (String val : values) {
for(int j=0;j<len;j++){ for (int j = 0; j < len; j++) {
if(val !=null && val.equals(data.getString(j))){ if (val != null && val.equals(data.getString(j))) {
count++; count++;
if (count == values.length) { if (count == values.length) {
return true; return true;
...@@ -546,52 +548,57 @@ public class Util { ...@@ -546,52 +548,57 @@ public class Util {
} }
return false; return false;
} }
public static boolean isPraramerValue(JSONObject data, String... colums) { public static boolean isPraramerValue(JSONObject data, String... colums) {
if(data == null || colums == null) if (data == null || colums == null)
return false; return false;
for(String colum:colums){ for (String colum : colums) {
if(data.containsKey(colum) == false){ if (data.containsKey(colum) == false) {
return false; return false;
} }
} }
return true; return true;
} }
public static boolean isInValue(String val, String... vals) { public static boolean isInValue(String val, String... vals) {
if(val == null || vals == null) if (val == null || vals == null)
return false; return false;
for(String v:vals){ for (String v : vals) {
if(val.equals(v)){ if (val.equals(v)) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* 生成稳健的随机数 * 生成稳健的随机数
*
* @param min * @param min
* @param max * @param max
* @return * @return
*/ */
public static int getRandom(int min, int max) { public static int getRandom(int min, int max) {
int randomNumber = (int)(Math.random()*(max-min+3)+min); int randomNumber = (int) (Math.random() * (max - min + 3) + min);
while (randomNumber == min || randomNumber == max+2) { while (randomNumber == min || randomNumber == max + 2) {
randomNumber = (int)(Math.random()*(max-min+3)+min); randomNumber = (int) (Math.random() * (max - min + 3) + min);
} }
return randomNumber-1; return randomNumber - 1;
} }
public static double getRandom(double max) { public static double getRandom(double max) {
double randomNumber = Math.random()*(max+2); double randomNumber = Math.random() * (max + 2);
while (randomNumber >= max+1) { while (randomNumber >= max + 1) {
randomNumber = Math.random()*(max+2); randomNumber = Math.random() * (max + 2);
} }
return randomNumber; return randomNumber;
} }
/** /**
* 得到Uc账号,判断规则,如果同时满足前缀,后缀,直接返回该账号。否则按照前缀,后缀规则,添加后返回账号 * 得到Uc账号,判断规则,如果同时满足前缀,后缀,直接返回该账号。否则按照前缀,后缀规则,添加后返回账号
*
* @return * @return
*/ */
public static String getUcAccount(String str) { public static String getUcAccount(String str) {
...@@ -623,12 +630,12 @@ public class Util { ...@@ -623,12 +630,12 @@ public class Util {
// userInfo.setName(info.getName()); // userInfo.setName(info.getName());
// System.out.println(info.getUserId()+"getName"+info.getName()); // System.out.println(info.getUserId()+"getName"+info.getName());
// } // }
// Map<String, Object> contents = new HashMap<String, Object>(); // Map<String, Object> contents = new HashMap<String, Object>();
// contents.put("phoneNumer", "5161"); // contents.put("phoneNumer", "5161");
// JSONObject object = Util.objectApi("/api/call/findPhoneInfo", contents, JSONObject.class); // JSONObject object = Util.objectApi("/api/call/findPhoneInfo", contents, JSONObject.class);
// System.out.println(object); // System.out.println(object);
// List<CallPhoneInfoListEntity> list = Util.arrayApi("/api/call/findPhoneInfo", contents, CallPhoneInfoListEntity.class); // List<CallPhoneInfoListEntity> list = Util.arrayApi("/api/call/findPhoneInfo", contents, CallPhoneInfoListEntity.class);
// for(CallPhoneInfoListEntity l:list){ // for(CallPhoneInfoListEntity l:list){
// //
......
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