Commit ebcdb997 by java-李谡

使用阿里代码规范插件扫描后修改

parent fe67d18c
...@@ -37,7 +37,6 @@ public class AnkeDateMiIdMain { ...@@ -37,7 +37,6 @@ public class AnkeDateMiIdMain {
String password = GConstants.getValue("anke.database.password", "123@abc"); String password = GConstants.getValue("anke.database.password", "123@abc");
String tableName = "dbo.cdr"; String tableName = "dbo.cdr";
// args = new String[]{"2011-1212-"};
Connection conn = null; Connection conn = null;
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
......
package com.foc.task; package com.foc.task;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
import com.foc.TaskTemplate; import com.foc.TaskTemplate;
...@@ -19,6 +10,9 @@ import com.foc.flightdynamics.FlightDynamicsTask; ...@@ -19,6 +10,9 @@ import com.foc.flightdynamics.FlightDynamicsTask;
import com.foc.flightdynamics.service.FlightDynamicsService; import com.foc.flightdynamics.service.FlightDynamicsService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.*;
/** /**
* 每天定时同步昨天和今天的数据 * 每天定时同步昨天和今天的数据
* 只同步航班动态数据 * 只同步航班动态数据
...@@ -26,21 +20,25 @@ import com.foc.util.DateUtil; ...@@ -26,21 +20,25 @@ import com.foc.util.DateUtil;
* *#1 4-23 * * * root bash /mnt/foc/project/task/rundyntask.sh * *#1 4-23 * * * root bash /mnt/foc/project/task/rundyntask.sh
* *#1 0-2 * * * root bash /mnt/foc/project/task/rundyntask.sh * *#1 0-2 * * * root bash /mnt/foc/project/task/rundyntask.sh
* 导出文件名称:jd-task-dynamics-2.0.jar * 导出文件名称:jd-task-dynamics-2.0.jar
* *
* @team IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2016年10月3日 * @team IT Team
* @time 2016年10月3日
*/ */
public class DynamicsTaskMain { public class DynamicsTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
// Logger logger = Logger.getLogger(BefBasicArchiveMain.class);
final String key = "dynamics.task.is.running"; final String key = "dynamics.task.is.running";
final String stringValue = "F";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
final int intValue2 = 2;
final int intValue3 = 3;
final long startTime = System.nanoTime(); final long startTime = System.nanoTime();
try { try {
boolean isForce = false; boolean isForce = false;
if((args.length >= 3 && "F".equals((args[2])))){ if ((args.length >= intValue3 && stringValue.equals((args[intValue2])))) {
System.out.println("[DynamicsTaskMain]强制模式"); System.out.println("[DynamicsTaskMain]强制模式");
isForce = true; isForce = true;
} }
...@@ -48,60 +46,53 @@ public class DynamicsTaskMain { ...@@ -48,60 +46,53 @@ public class DynamicsTaskMain {
System.out.println("[DynamicsTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[DynamicsTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (!isForce && HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (!isForce && HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[DynamicsTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[DynamicsTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[DynamicsTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[DynamicsTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("dynamics.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("dynamics.task.last.time", DateUtil.getDateTime());
HistoryConfig.put(key, "1"); HistoryConfig.put(key, "1");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
// args = new String[]{"0", "0"}; // args = new String[]{"0", "0"};
// 一个参数: 参数为向后加几天 // 一个参数: 参数为向后加几天
// 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天 // 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天
if(args.length == 1){ if (args.length == 1) {
args = new String[]{"-1", args[0]}; args = new String[]{"-1", args[0]};
} else if(args.length > 1){ } else if (args.length > 1) {
args = new String[]{args[0], args[1]}; args = new String[]{args[0], args[1]};
} else { } else {
args = new String[]{"-1", "1"}; args = new String[]{"-1", "1"};
} }
// args = new String[]{"2", "2"}; // 开始日期位移天数
// Calendar calendar = Calendar.getInstance(); final int start = Integer.valueOf(args[0]);
// int hour = calendar.get(Calendar.HOUR_OF_DAY); // 结束日期位移天数
// int timeOffset = GConstants.getIntValue("start.time.offset.hour", 8); final int days = Integer.valueOf(args[1]);
// if(hour>timeOffset){
// if("-1".equals(args[0])){
// args[0] = "0";
// }
// }
final int start = Integer.valueOf(args[0]);// 开始日期位移天数
final int days = Integer.valueOf(args[1]);// 结束日期位移天数
String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT); String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT);
String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT); String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT);
System.out.println("[DynamicsTaskMain]统计时间段["+dateFrom+" 00:00:00]TO["+dateTo+" 23:59:59]"); System.out.println("[DynamicsTaskMain]统计时间段[" + dateFrom + " 00:00:00]TO[" + dateTo + " 23:59:59]");
// final Date modified = new Date();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// System.out.println("[DynamicsTaskMain][修改时间]"+sdf.format(modified));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[DynamicsTaskMain][修改时间]"+modified); System.out.println("[DynamicsTaskMain][修改时间]" + modified);
boolean dailyFlag = false; boolean dailyFlag = false;
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY); int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE); int minute = calendar.get(Calendar.MINUTE);
if(hour == 22 && minute >= 30 && minute < 45){// 晚上10点半同步一份原始的计划数据 // 晚上10点半同步一份原始的计划数据
int hourValue = 22;
int minuteValueL = 30;
int minuteValueM = 45;
if (hour == hourValue && minute >= minuteValueL && minute < minuteValueM) {
dailyFlag = true; dailyFlag = true;
} }
...@@ -113,77 +104,23 @@ public class DynamicsTaskMain { ...@@ -113,77 +104,23 @@ public class DynamicsTaskMain {
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("[DynamicsTaskMain]结束["+DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT)+"]"); System.out.println("[DynamicsTaskMain]结束[" + DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT) + "]");
System.out.println("执行总共用时:" + duration + "纳秒"); System.out.println("执行总共用时:" + duration + "纳秒");
System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0"); HistoryConfig.put(key, "0");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
} }
/*
// TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool();
threadPool.execute(new Runnable() {// 5.3 航班动态接口
@Override
public void run() {
boolean dailyFlag = false;
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
if(hour == 22 && minute >= 30 && minute < 45){// 晚上10点半同步一份原始的计划数据
dailyFlag = true;
}
startFlightDynamicsTask(threadPool, start, days, dailyFlag, modified);
// if(0>=start && 0<= days){// 优先同步今天的数据
//
// startFlightDynamicsTask(threadPool, 0);
// }
// for (int i = start; i <= days; i++) {// 航班动态 插入或更新从今天开始往后30天的数据
// if(i != 0){
//
// startFlightDynamicsTask(threadPool, i);
// }
// }
}
});
threadPool.shutdown();
while (true) {
if (threadPool.isTerminated()) {
System.out.println("线程池结束了!");
HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("[DynamicsTaskMain]结束["+DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT)+"]");
System.out.println("执行总共用时:" + duration + "纳秒");
System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0");
HistoryConfig.saveHistory();
System.exit(0);
break;
}
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
*/
} }
private static void startFlightDynamicsTask(final int start, final int end, final boolean dailyFlag, final String modified) { private static void startFlightDynamicsTask(final int start, final int end, final boolean dailyFlag, final String modified) {
/** /**
* 航班动态 * 航班动态
*/ */
FlightDynamicsTask flightDynamicsTask = new FlightDynamicsTask(new TaskSupporter() { FlightDynamicsTask flightDynamicsTask = new FlightDynamicsTask(new TaskSupporter() {
private Map<String, String> flightDates = new HashMap<String, String>(); private Map<String, String> flightDates = new HashMap<String, String>(3);
private FlightDynamicsService flightDynamicsService = new FlightDynamicsService(); private FlightDynamicsService flightDynamicsService = new FlightDynamicsService();
@Override @Override
public String setBaseUrl(TaskTemplate taskTemplate) { public String setBaseUrl(TaskTemplate taskTemplate) {
...@@ -195,15 +132,15 @@ public class DynamicsTaskMain { ...@@ -195,15 +132,15 @@ public class DynamicsTaskMain {
public Map<String, String> setParams() { public Map<String, String> setParams() {
Map<String, String> params = new TreeMap<String, String>(); Map<String, String> params = new TreeMap<String, String>();
params.put("stdStart", DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT)+" 00:00:00"); params.put("stdStart", DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT) + " 00:00:00");
params.put("stdEnd", DateUtil.dateToStr(DateUtil.offsetDate(new Date(), end), DateUtil.DATE_FORMAT)+" 23:59:59"); params.put("stdEnd", DateUtil.dateToStr(DateUtil.offsetDate(new Date(), end), DateUtil.DATE_FORMAT) + " 23:59:59");
return params; return params;
} }
@Override @Override
public void successHandle(JSONObject result) { public void successHandle(JSONObject result) {
flightDynamicsService.insertFlightDynamicsData(result, modified, dailyFlag, flightDates); flightDynamicsService.insertFlightDynamicsData(result, modified, dailyFlag, flightDates);
} }
...@@ -225,7 +162,7 @@ public class DynamicsTaskMain { ...@@ -225,7 +162,7 @@ public class DynamicsTaskMain {
@Override @Override
public String getApiName() { public String getApiName() {
return "dynamics"; return "dynamics";
} }
...@@ -238,7 +175,6 @@ public class DynamicsTaskMain { ...@@ -238,7 +175,6 @@ public class DynamicsTaskMain {
}); });
flightDynamicsTask.run(); flightDynamicsTask.run();
// threadPool.execute(flightDynamicsTask);
} }
} }
...@@ -3,13 +3,6 @@ ...@@ -3,13 +3,6 @@
*/ */
package com.foc.task; package com.foc.task;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
import com.foc.TaskTemplate; import com.foc.TaskTemplate;
...@@ -22,34 +15,38 @@ import com.foc.util.DateUtil; ...@@ -22,34 +15,38 @@ import com.foc.util.DateUtil;
import com.foc.util.IdWorker; import com.foc.util.IdWorker;
import com.foc.version.VersionService; import com.foc.version.VersionService;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* # 同步飞行计划书数据 * # 同步飞行计划书数据
* *#3 4-23 * * * root bash /mnt/foc/project/task/runassigment.sh * *#3 4-23 * * * root bash /mnt/foc/project/task/runassigment.sh
* 导出文件名称:jd-task-assigment-2.0.jar * 导出文件名称:jd-task-assigment-2.0.jar
* @team IT Team *
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @team IT Team
* @time 2016年11月28日 * @time 2016年11月28日
*/ */
public class FlightAssignmentTaskMain { public class FlightAssignmentTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
// String[] ids = "PN6345/PN6346".split("/");
// for (String flightNo:ids) {
// System.out.println("flightNo:"+flightNo);
// }
// System.exit(0);
// Logger logger = Logger.getLogger(BefBasicArchiveMain.class);
final String key = "assignment.task.is.running"; final String key = "assignment.task.is.running";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[FlightSssignmentTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[FlightAssignmentTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[FlightSssignmentTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[FlightAssignmentTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[FlightSssignmentTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[FlightAssignmentTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("assignment.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("assignment.task.last.time", DateUtil.getDateTime());
...@@ -57,38 +54,40 @@ public class FlightAssignmentTaskMain { ...@@ -57,38 +54,40 @@ public class FlightAssignmentTaskMain {
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
long startTime = System.nanoTime(); long startTime = System.nanoTime();
// args = new String[]{"0", "0"}; //args = new String[]{"0", "0"};
// 一个参数: 参数为向后加几天 // 一个参数: 参数为向后加几天
// 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天 // 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天
if (args == null || args.length != 2) { int argsLengthValue = 2;
if (args == null || args.length != argsLengthValue) {
args = new String[] { "0", "0" }; args = new String[]{"0", "0"};
} }
final int start = Integer.valueOf(args[0]);// 开始日期位移天数 // 开始日期位移天数
final int days = Integer.valueOf(args[1]);// 结束日期位移天数 final int start = Integer.valueOf(args[0]);
// final int days = Integer.valueOf(args[1]);// 结束日期位移天数 // 结束日期位移天数
final int days = Integer.valueOf(args[1]);
// TODO Auto-generated method stub // TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool(); final ExecutorService threadPool = Executors.newCachedThreadPool();
final VersionService versionService = new VersionService(); final VersionService versionService = new VersionService();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[ODSTaskMain][修改时间]"+modified); System.out.println("[OdsTaskMain][修改时间]" + modified);
// 5.3 航班动态接口
threadPool.execute(new Runnable() {// 5.3 航班动态接口 threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
for (int i = start; i <= days; i++) { for (int i = start; i <= days; i++) {
String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), i), DateUtil.DATE_FORMAT); String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), i), DateUtil.DATE_FORMAT);
System.out.println("[FlightSssignmentTaskMain]航班日期[" + dateFrom + "]"); System.out.println("[FlightSssignmentTaskMain]航班日期[" + dateFrom + "]");
final String currentVersion = IdWorker.getNextId("V"); final String currentVersion = IdWorker.getNextId("V");
final String lastVersion = versionService.getCurrentVersion("ASSIGNMENT", dateFrom);//HistoryConfig.getValue("assignment.current.use.version", "");// 当前使用版本 // 当前使用版本
System.out.println("[FlightSssignmentTaskMain]FROM VERSION[" + lastVersion + "]TO["+currentVersion+"]"); final String lastVersion = versionService.getCurrentVersion("ASSIGNMENT", dateFrom);
System.out.println("[FlightSssignmentTaskMain]FROM VERSION[" + lastVersion + "]TO[" + currentVersion + "]");
startFlightAssignmentTask(threadPool, lastVersion, currentVersion, i, modified); startFlightAssignmentTask(threadPool, lastVersion, currentVersion, i, modified);
} }
} }
...@@ -103,7 +102,7 @@ public class FlightAssignmentTaskMain { ...@@ -103,7 +102,7 @@ public class FlightAssignmentTaskMain {
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out System.out
.println("[FlightSssignmentTaskMain]结束[" + DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT) + "]"); .println("[FlightAssignmentTaskMain]结束[" + DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT) + "]");
System.out.println("执行总共用时:" + duration + "纳秒"); System.out.println("执行总共用时:" + duration + "纳秒");
System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0"); HistoryConfig.put(key, "0");
...@@ -120,8 +119,8 @@ public class FlightAssignmentTaskMain { ...@@ -120,8 +119,8 @@ public class FlightAssignmentTaskMain {
} }
} }
private static void startFlightAssignmentTask(ExecutorService threadPool, private static void startFlightAssignmentTask(ExecutorService threadPool,
final String lastVersion, final String currentVersion, final int offset, final String modified) { final String lastVersion, final String currentVersion, final int offset, final String modified) {
/** /**
* 航班动态 * 航班动态
*/ */
...@@ -130,6 +129,7 @@ public class FlightAssignmentTaskMain { ...@@ -130,6 +129,7 @@ public class FlightAssignmentTaskMain {
final FlightAssignmentService service = new FlightAssignmentService(); final FlightAssignmentService service = new FlightAssignmentService();
final String flightDate = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offset), DateUtil.DATE_FORMAT); final String flightDate = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offset), DateUtil.DATE_FORMAT);
private boolean hasNewData = false; private boolean hasNewData = false;
@Override @Override
public String setBaseUrl(TaskTemplate taskTemplate) { public String setBaseUrl(TaskTemplate taskTemplate) {
...@@ -140,23 +140,14 @@ public class FlightAssignmentTaskMain { ...@@ -140,23 +140,14 @@ public class FlightAssignmentTaskMain {
@Override @Override
public Map<String, String> setParams() { public Map<String, String> setParams() {
Map<String, String> params = new TreeMap<String, String>(); Map<String, String> params = new TreeMap<String, String>();
//departStation=CTU&arrivalStation=SYX&flightNos=JD5178
params.put("flightDate", flightDate); params.put("flightDate", flightDate);
// params.put("departStation", "CTU");
// params.put("flightDate", "2016-09-22");
// params.put("arrivalStation", "SYX");
// params.put("flightNos", "JD5178");
return params; return params;
} }
@Override @Override
public void successHandle(JSONObject result) { public void successHandle(JSONObject result) {
// String flightDate = flightDate;
boolean ret = service.handle(currentVersion, flightDate, result, modified); boolean ret = service.handle(currentVersion, flightDate, result, modified);
if(!hasNewData && ret){ if (!hasNewData && ret) {
hasNewData = true; hasNewData = true;
} }
} }
...@@ -185,16 +176,16 @@ public class FlightAssignmentTaskMain { ...@@ -185,16 +176,16 @@ public class FlightAssignmentTaskMain {
@Override @Override
public boolean finish() { public boolean finish() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
if(hasNewData){ if (hasNewData) {
System.out.println("【finish】本次有新数据,需要删除老数据!"); System.out.println("【finish】本次有新数据,需要删除老数据!");
service.finish(flightDate, lastVersion, currentVersion); service.finish(flightDate, lastVersion, currentVersion);
} else { } else {
System.out.println("【finish】本次未获取到新数据,古不做处理!"); System.out.println("【finish】本次未获取到新数据,古不做处理!");
} }
return false; return false;
} }
}); });
......
...@@ -6,6 +6,7 @@ import java.util.Map; ...@@ -6,6 +6,7 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
...@@ -17,34 +18,38 @@ import com.foc.hrm.HRMTask; ...@@ -17,34 +18,38 @@ import com.foc.hrm.HRMTask;
import com.foc.hrm.service.HRMService; import com.foc.hrm.service.HRMService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
public class HRMTaskMain { /**
* @author lisu
*/
public class HrmTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
final String key = "hrm.task.is.running"; final String key = "hrm.task.is.running";
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[HRMTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[HrmTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("hrm.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("hrm.task.last.time", DateUtil.getDateTime());
HistoryConfig.put(key, "1"); HistoryConfig.put(key, "1");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
long startTime = System.nanoTime(); long startTime = System.nanoTime();
System.out.println("[HRMTaskMain]统计时间段["+DateUtil.getDateTime()+"]"); System.out.println("[HrmTaskMain]统计时间段[" + DateUtil.getDateTime() + "]");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[ODSTaskMain][修改时间]"+modified); System.out.println("[OdsTaskMain][修改时间]" + modified);
// TODO Auto-generated method stub // TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool(); final ExecutorService threadPool = Executors.newCachedThreadPool();
threadPool.execute(new Runnable() {// 5.4 HRM人资接口 // 5.4 HRM人资接口
threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
// HRM 插入或更新user和role的数据
startHRMTask(threadPool, modified);// HRM 插入或更新user和role的数据 startHRMTask(threadPool, modified);
} }
}); });
threadPool.shutdown(); threadPool.shutdown();
...@@ -53,7 +58,7 @@ public class HRMTaskMain { ...@@ -53,7 +58,7 @@ public class HRMTaskMain {
if (threadPool.isTerminated()) { if (threadPool.isTerminated()) {
System.out.println("线程池结束了!"); System.out.println("线程池结束了!");
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("执行存储过程总共用时:" + duration + "纳秒"); System.out.println("执行存储过程总共用时:" + duration + "纳秒");
...@@ -70,6 +75,7 @@ public class HRMTaskMain { ...@@ -70,6 +75,7 @@ public class HRMTaskMain {
} }
} }
} }
private static void startHRMTask(ExecutorService threadPool, final String modified) { private static void startHRMTask(ExecutorService threadPool, final String modified) {
/** /**
...@@ -83,36 +89,43 @@ public class HRMTaskMain { ...@@ -83,36 +89,43 @@ public class HRMTaskMain {
// return // return
// GConstants.FOC_FLIGHT_DYNAMIC_URL+"&pageParam.pageIndex="+taskTemplate.getPageIndex()+"&pageParam.pageSize="+GConstants.PAGE_SIZE; // GConstants.FOC_FLIGHT_DYNAMIC_URL+"&pageParam.pageIndex="+taskTemplate.getPageIndex()+"&pageParam.pageSize="+GConstants.PAGE_SIZE;
} }
@Override @Override
public Map<String, String> setParams() { public Map<String, String> setParams() {
Map<String, String> params = new TreeMap<String, String>(); Map<String, String> params = new TreeMap<String, String>();
params.put("companyNodeId", "4477"); params.put("companyNodeId", "4477");
params.put("includePost", "1");// 默认null,即false如果true,则返回的HrEmp才会包含empPosts属性值 //默认null,即false如果true,则返回的HrEmp才会包含empPosts属性值
params.put("includePost", "1");
return params; return params;
} }
@Override @Override
public void successHandle(JSONObject result) { public void successHandle(JSONObject result) {
HRMService hRMService = new HRMService(); HRMService hRMService = new HRMService();
hRMService.insertHRM(result, modified); hRMService.insertHRM(result, modified);
} }
@Override @Override
public String setPageIndexProperty() { public String setPageIndexProperty() {
return "foc.hrm.page.index"; return "foc.hrm.page.index";
} }
@Override @Override
public boolean isGet() { public boolean isGet() {
return true; return true;
} }
@Override @Override
public boolean isPost() { public boolean isPost() {
return false; return false;
} }
@Override @Override
public String getApiName() { public String getApiName() {
return "hrm"; return "hrm";
} }
@Override @Override
public boolean finish() { public boolean finish() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
*/ */
package com.foc.task; package com.foc.task;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.foc.conf.HistoryConfig; import com.foc.conf.HistoryConfig;
import com.foc.fetcher.HCFetcher; import com.foc.fetcher.HCFetcher;
import com.foc.hrm.service.HRMUpdatePreMobileService; import com.foc.hrm.service.HRMUpdatePreMobileService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
* # 格式化手机号和座机号 * # 格式化手机号和座机号
* 1 2 * * * root bash /mnt/foc/project/task/runupdatehrmtask.sh * 1 2 * * * root bash /mnt/foc/project/task/runupdatehrmtask.sh
...@@ -21,7 +21,7 @@ import com.foc.util.DateUtil; ...@@ -21,7 +21,7 @@ import com.foc.util.DateUtil;
* @version 1.0 * @version 1.0
* @time 2016年10月30日 * @time 2016年10月30日
*/ */
public class HRMUpdateTaskMain { public class HrmUpdateTaskMain {
/** /**
* *
...@@ -33,21 +33,16 @@ public class HRMUpdateTaskMain { ...@@ -33,21 +33,16 @@ public class HRMUpdateTaskMain {
// TODO Auto-generated method stub // TODO Auto-generated method stub
final String key = "hrm.premobile.task.is.running"; final String key = "hrm.premobile.task.is.running";
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[HRMUpdateTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[HrmUpdateTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("hrm.premobile.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("hrm.premobile.task.last.time", DateUtil.getDateTime());
HistoryConfig.put(key, "1"); HistoryConfig.put(key, "1");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
long startTime = System.nanoTime(); long startTime = System.nanoTime();
System.out.println("[HrmUpdateTaskMain]统计时间段[" + DateUtil.getDateTime() + "]");
System.out.println("[HRMUpdateTaskMain]统计时间段["+DateUtil.getDateTime()+"]");
// String mobile = "18910892562北京";
// mobile = "+61 0468386992";
// mobile = "+61(0)467613626";
// mobile = "+61426286619";
// System.out.println(mobile.replaceAll("[^0-9|+]+", ""));
// 如果有一个参数则修改手机号 // 如果有一个参数则修改手机号
args = new String[]{"1"}; args = new String[]{"1"};
boolean isUpdateMobile = false; boolean isUpdateMobile = false;
...@@ -57,7 +52,7 @@ public class HRMUpdateTaskMain { ...@@ -57,7 +52,7 @@ public class HRMUpdateTaskMain {
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[ODSTaskMain][修改时间]"+modified); System.out.println("[OdsTaskMain][修改时间]" + modified);
HRMUpdatePreMobileService service = new HRMUpdatePreMobileService(); HRMUpdatePreMobileService service = new HRMUpdatePreMobileService();
service.start(isUpdateMobile); service.start(isUpdateMobile);
......
package com.foc.task; package com.foc.task;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
import com.foc.TaskTemplate; import com.foc.TaskTemplate;
...@@ -18,34 +10,40 @@ import com.foc.ods.ODSTask; ...@@ -18,34 +10,40 @@ import com.foc.ods.ODSTask;
import com.foc.ods.service.ODSService; import com.foc.ods.service.ODSService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* 每天定时同步昨天和今天的数据 * 每天定时同步昨天和今天的数据
* 只同步ODS数据 * 只同步ODS数据
* *#1 * * * * root bash /mnt/foc/project/task/runodschangetask.sh * *#1 * * * * root bash /mnt/foc/project/task/runodschangetask.sh
* 导出文件名称: jd-task-odschange-2.0.jar * 导出文件名称: jd-task-odschange-2.0.jar
* *
* @team IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2016年10月3日 * @team IT Team
* @time 2016年10月3日
*/ */
public class ODSChangeTaskMain { public class OdsChangeTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(DateUtil.getDateTime().replaceAll("[-|:|\\s]", "")+".json");
// System.exit(0);
// Logger logger = Logger.getLogger(BefBasicArchiveMain.class);
final String key = "ods.change.task.is.running"; final String key = "ods.change.task.is.running";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[ODSChangeTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsChangeTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[ODSChangeTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsChangeTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[ODSChangeTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsChangeTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("ods.change.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("ods.change.task.last.time", DateUtil.getDateTime());
...@@ -54,43 +52,36 @@ public class ODSChangeTaskMain { ...@@ -54,43 +52,36 @@ public class ODSChangeTaskMain {
long startTime = System.nanoTime(); long startTime = System.nanoTime();
// 一个参数: 参数为向后加几天 // 一个参数: 参数为向后加几天
// 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天 // 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天
if(args == null || args.length ==0 || args.length > 2){ int argsLengthValue1 = 1;
int argsLengthValue2 = 2;
if (args == null || args.length == 0 || args.length > argsLengthValue2) {
args = new String[]{"-1", "0"}; args = new String[]{"-1", "0"};
} else if(args.length == 1){ } else if (args.length == argsLengthValue1) {
args = new String[]{"-1", args[0]}; args = new String[]{"-1", args[0]};
} else if(args.length == 2){ } else if (args.length == argsLengthValue2) {
args = new String[]{args[0], args[1]}; args = new String[]{args[0], args[1]};
} }
// Calendar calendar = Calendar.getInstance(); // 开始日期位移天数
// int hour = calendar.get(Calendar.HOUR_OF_DAY); final int start = Integer.valueOf(args[0]);
// int timeOffset = GConstants.getIntValue("start.time.offset.hour", 8); // 结束日期位移天数
// if(hour>timeOffset){ final int days = Integer.valueOf(args[1]);
// if("-1".equals(args[0])){
// args[0] = "0";
// }
// }
final int start = Integer.valueOf(args[0]);// 开始日期位移天数
final int days = Integer.valueOf(args[1]);// 结束日期位移天数
String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT); String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT);
String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT); String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT);
System.out.println("[ODSChangeTaskMain]统计时间段["+dateFrom+"]TO["+dateTo+"]"); System.out.println("[OdsChangeTaskMain]统计时间段[" + dateFrom + "]TO[" + dateTo + "]");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[ODSChangeTaskMain][修改时间]"+modified); System.out.println("[OdsChangeTaskMain][修改时间]" + modified);
// TODO Auto-generated method stub // TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool(); final ExecutorService threadPool = Executors.newCachedThreadPool();
// 5.2 ODS飞行计划调整单接口
threadPool.execute(new Runnable() {// 5.2 ODS飞行计划调整单接口 threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
startODSChangeTask(threadPool, modified, start, days); startODSChangeTask(threadPool, modified, start, days);
} }
}); });
...@@ -100,14 +91,14 @@ public class ODSChangeTaskMain { ...@@ -100,14 +91,14 @@ public class ODSChangeTaskMain {
if (threadPool.isTerminated()) { if (threadPool.isTerminated()) {
System.out.println("线程池结束了!"); System.out.println("线程池结束了!");
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("执行存储过程总共用时:" + duration + "纳秒"); System.out.println("执行存储过程总共用时:" + duration + "纳秒");
System.out.println("执行存储过程总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("执行存储过程总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0"); HistoryConfig.put(key, "0");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
System.exit(0); System.exit(0);
break; break;
} }
...@@ -118,6 +109,7 @@ public class ODSChangeTaskMain { ...@@ -118,6 +109,7 @@ public class ODSChangeTaskMain {
} }
} }
} }
private static void startODSChangeTask(ExecutorService threadPoolSecond, final String modified, final int startDateIndex, final int offsetDateIndex) { private static void startODSChangeTask(ExecutorService threadPoolSecond, final String modified, final int startDateIndex, final int offsetDateIndex) {
/** /**
* ODS飞行计划调整单 * ODS飞行计划调整单
...@@ -134,11 +126,11 @@ public class ODSChangeTaskMain { ...@@ -134,11 +126,11 @@ public class ODSChangeTaskMain {
public Map<String, String> setParams() { public Map<String, String> setParams() {
Map<String, String> params = new TreeMap<String, String>(); Map<String, String> params = new TreeMap<String, String>();
String fltChangeDateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), startDateIndex), DateUtil.DATE_FORMAT); String fltChangeDateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), startDateIndex), DateUtil.DATE_FORMAT);
String fltChangeDateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offsetDateIndex), DateUtil.DATE_FORMAT); String fltChangeDateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offsetDateIndex), DateUtil.DATE_FORMAT);
params.put("fltChangeDateFrom", fltChangeDateFrom+" 00:00:00"); params.put("fltChangeDateFrom", fltChangeDateFrom + " 00:00:00");
params.put("fltChangeDateTo", fltChangeDateTo+" 23:59:59"); params.put("fltChangeDateTo", fltChangeDateTo + " 23:59:59");
return params; return params;
} }
...@@ -162,10 +154,10 @@ public class ODSChangeTaskMain { ...@@ -162,10 +154,10 @@ public class ODSChangeTaskMain {
public boolean isPost() { public boolean isPost() {
return true; return true;
} }
@Override @Override
public String getApiName() { public String getApiName() {
return "ods.change"; return "ods.change";
} }
......
package com.foc.task; package com.foc.task;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
import com.foc.TaskTemplate; import com.foc.TaskTemplate;
...@@ -18,6 +10,14 @@ import com.foc.ods.ODSTask; ...@@ -18,6 +10,14 @@ import com.foc.ods.ODSTask;
import com.foc.ods.service.ODSService; import com.foc.ods.service.ODSService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* 每天定时同步昨天和今天的数据 * 每天定时同步昨天和今天的数据
* 只同步ODS数据 * 只同步ODS数据
...@@ -26,29 +26,28 @@ import com.foc.util.DateUtil; ...@@ -26,29 +26,28 @@ import com.foc.util.DateUtil;
* *#1 0-2 * * * root bash /mnt/foc/project/task/runodstask.sh * *#1 0-2 * * * root bash /mnt/foc/project/task/runodstask.sh
* *#1 * * * * root bash /mnt/foc/project/task/runodschangetask.sh * *#1 * * * * root bash /mnt/foc/project/task/runodschangetask.sh
* 导出文件名称:jd-task-ods-2.0.jar * 导出文件名称:jd-task-ods-2.0.jar
* *
* @team IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2016年10月3日 * @team IT Team
* @time 2016年10月3日
*/ */
public class ODSTaskMain { public class OdsTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(DateUtil.getDateTime().replaceAll("[-|:|\\s]", "")+".json");
// System.exit(0);
// Logger logger = Logger.getLogger(BefBasicArchiveMain.class);
final String key = "ods.task.is.running"; final String key = "ods.task.is.running";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[ODSTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[ODSTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[ODSTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[OdsTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("ods.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("ods.task.last.time", DateUtil.getDateTime());
...@@ -57,51 +56,52 @@ public class ODSTaskMain { ...@@ -57,51 +56,52 @@ public class ODSTaskMain {
long startTime = System.nanoTime(); long startTime = System.nanoTime();
// 一个参数: 参数为向后加几天 // 一个参数: 参数为向后加几天
// 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天 // 两个参数: 第一个参数为向前减减几天,第二个参数向后加几天
if(args == null || args.length ==0 || args.length > 2){ int argsLength = 2;
if (args == null || args.length == 0 || args.length > argsLength) {
args = new String[]{"-1", "0"}; args = new String[]{"-1", "0"};
} else if(args.length == 1){ } else if (args.length == 1) {
args = new String[]{"-1", args[0]}; args = new String[]{"-1", args[0]};
} else if(args.length == 2){ } else if (args.length == argsLength) {
args = new String[]{args[0], args[1]}; args = new String[]{args[0], args[1]};
} }
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY); int hour = calendar.get(Calendar.HOUR_OF_DAY);
int timeOffset = GConstants.getIntValue("start.time.offset.hour", 8); int timeOffset = GConstants.getIntValue("start.time.offset.hour", 8);
if(hour>timeOffset){ if (hour > timeOffset) {
if("-1".equals(args[0])){ String argsValue = "-1";
if (argsValue.equals(args[0])) {
args[0] = "0"; args[0] = "0";
} }
} }
final int start = Integer.valueOf(args[0]);// 开始日期位移天数 // 开始日期位移天数
final int days = Integer.valueOf(args[1]);// 结束日期位移天数 final int start = Integer.valueOf(args[0]);
// 结束日期位移天数
final int days = Integer.valueOf(args[1]);
String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT); String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT);
String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT); String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT);
System.out.println("[ODSTaskMain]统计时间段["+dateFrom+"]TO["+dateTo+"]"); System.out.println("[OdsTaskMain]统计时间段[" + dateFrom + "]TO[" + dateTo + "]");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final String modified = sdf.format(new Date()); final String modified = sdf.format(new Date());
System.out.println("[ODSTaskMain][修改时间]"+modified); System.out.println("[OdsTaskMain][修改时间]" + modified);
// TODO Auto-generated method stub // TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool(); final ExecutorService threadPool = Executors.newCachedThreadPool();
// 5.1 ODS飞行计划接口(亦即机组排班接口)
threadPool.execute(new Runnable() {// 5.1 ODS飞行计划接口(亦即机组排班接口) threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
// 优先同步今天的数据
if(0>=start && 0<= days){// 优先同步今天的数据 if (0 >= start && 0 <= days) {
startODSTask(threadPool, 0, modified); startODSTask(threadPool, 0, modified);
} }
for (int i = start; i <= days; i++) { for (int i = start; i <= days; i++) {
if(i != 0){ if (i != 0) {
// 插入或更新ods数据
startODSTask(threadPool, i, modified);// 插入或更新ods数据 startODSTask(threadPool, i, modified);
} }
} }
} }
...@@ -112,14 +112,14 @@ public class ODSTaskMain { ...@@ -112,14 +112,14 @@ public class ODSTaskMain {
if (threadPool.isTerminated()) { if (threadPool.isTerminated()) {
System.out.println("线程池结束了!"); System.out.println("线程池结束了!");
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("执行存储过程总共用时:" + duration + "纳秒"); System.out.println("执行存储过程总共用时:" + duration + "纳秒");
System.out.println("执行存储过程总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("执行存储过程总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0"); HistoryConfig.put(key, "0");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
System.exit(0); System.exit(0);
break; break;
} }
...@@ -139,6 +139,7 @@ public class ODSTaskMain { ...@@ -139,6 +139,7 @@ public class ODSTaskMain {
final ODSService oDSService = new ODSService(); final ODSService oDSService = new ODSService();
final String flightDate = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offsetDateIndex), DateUtil.DATE_FORMAT); final String flightDate = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), offsetDateIndex), DateUtil.DATE_FORMAT);
@Override @Override
public String setBaseUrl(TaskTemplate taskTemplate) { public String setBaseUrl(TaskTemplate taskTemplate) {
...@@ -151,13 +152,12 @@ public class ODSTaskMain { ...@@ -151,13 +152,12 @@ public class ODSTaskMain {
Map<String, String> params = new TreeMap<String, String>(); Map<String, String> params = new TreeMap<String, String>();
params.put("flightDate", flightDate); params.put("flightDate", flightDate);
// params.put("flightNos", flightNos);
return params; return params;
} }
@Override @Override
public void successHandle(JSONObject result) { public void successHandle(JSONObject result) {
oDSService.insertOdsData(result, modified); oDSService.insertOdsData(result, modified);
} }
...@@ -175,24 +175,23 @@ public class ODSTaskMain { ...@@ -175,24 +175,23 @@ public class ODSTaskMain {
public boolean isPost() { public boolean isPost() {
return false; return false;
} }
@Override @Override
public String getApiName() { public String getApiName() {
return "ods"; return "ods";
} }
@Override @Override
public boolean finish() { public boolean finish() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
oDSService.finish(flightDate, modified); oDSService.finish(flightDate, modified);
return false; return false;
} }
}); });
oDSTask.run(); oDSTask.run();
// threadPoolSecond.execute(oDSTask);
} }
} }
...@@ -3,34 +3,32 @@ ...@@ -3,34 +3,32 @@
*/ */
package com.foc.task; package com.foc.task;
import com.foc.conf.HistoryConfig;
import com.foc.plan.push.service.PlanPushService;
import com.foc.util.DateUtil;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import com.foc.conf.HistoryConfig;
import com.foc.plan.push.service.PlanPushService;
import com.foc.util.DateUtil;
/** /**
* # 签到推送 * # 签到推送
* *#1 5-23 * * * root bash /mnt/foc/project/task/runpushtask.sh * *#1 5-23 * * * root bash /mnt/foc/project/task/runpushtask.sh
* 导出文件名称: jd-task-push-2.6.jar * 导出文件名称: jd-task-push-2.6.jar
* *
* @team BBDTEK IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @team BBDTEK IT Team
* @time 2016年12月17日 * @time 2016年12月17日
*/ */
public class PlanPushTaskMain { public class PlanPushTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(String.format("%02d", 2));System.exit(0);
// System.out.println(DateUtil.getDateTime().replaceAll("[-|:|\\s]",
// "")+".json");
// System.exit(0);
// Logger logger = Logger.getLogger(BefBasicArchiveMain.class);
boolean isForce = false; boolean isForce = false;
if((args != null && args.length >= 1 && "F".equals((args[args.length-1])))){ final String stringValue = "F";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
if ((args != null && args.length >= 1 && stringValue.equals((args[args.length - 1])))) {
System.out.println("[PlanPushTaskMain]强制模式"); System.out.println("[PlanPushTaskMain]强制模式");
isForce = true; isForce = true;
} }
...@@ -39,11 +37,11 @@ public class PlanPushTaskMain { ...@@ -39,11 +37,11 @@ public class PlanPushTaskMain {
System.out.println("[PlanPushTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[PlanPushTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (!isForce && HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (!isForce && HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[PlanPushTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[PlanPushTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (!isForce && HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (!isForce && HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[PlanPushTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[PlanPushTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
...@@ -60,8 +58,8 @@ public class PlanPushTaskMain { ...@@ -60,8 +58,8 @@ public class PlanPushTaskMain {
System.out.println("[PlanPushTaskMain][修改时间]" + modified); System.out.println("[PlanPushTaskMain][修改时间]" + modified);
// TODO Auto-generated method stub // TODO Auto-generated method stub
final ExecutorService threadPool = Executors.newCachedThreadPool(); final ExecutorService threadPool = Executors.newCachedThreadPool();
// 5.1 ODS飞行计划接口(亦即机组排班接口)
threadPool.execute(new Runnable() {// 5.1 ODS飞行计划接口(亦即机组排班接口) threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -72,7 +70,7 @@ public class PlanPushTaskMain { ...@@ -72,7 +70,7 @@ public class PlanPushTaskMain {
} }
}); });
threadPool.shutdown(); threadPool.shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("[PlanPushTaskMain]总共用时:" + duration + "纳秒"); System.out.println("[PlanPushTaskMain]总共用时:" + duration + "纳秒");
......
...@@ -32,26 +32,21 @@ public class SoundCopyTaskMain { ...@@ -32,26 +32,21 @@ public class SoundCopyTaskMain {
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub
List<Map<String, Object>> sounds = new ArrayList<>();
List<Map<String, Object>> sounds = new ArrayList<>();//.fetch("sound", "select * from dbo.cdr where id BETWEEN " + 10000 + " AND "+30000+" order by id ASC");
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200"; String url = "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200";
Connection conn = null; Connection conn = null;
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
int count = 0;
try { try {
// System.out.println("[SoundTaskMain]统计ID段[" + minId + " ]TO[" + maxId + " ]");
Class.forName(driver); Class.forName(driver);
conn = DriverManager.getConnection(url, "foctest", "123@abc"); conn = DriverManager.getConnection(url, "foctest", "123@abc");
pstmt = conn pstmt = conn
.prepareStatement("select * from dbo.cdr where id BETWEEN " + 10000 + " AND "+30000+" order by id ASC"); .prepareStatement("select * from dbo.cdr where id BETWEEN " + 10000 + " AND "+30000+" order by id ASC");
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>(); List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>();
Long newMaxId = 0L;
System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n","id","caller","callee","stm","edm","elapsed","recfile","filesize","callresult"); System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n","id","caller","callee","stm","edm","elapsed","recfile","filesize","callresult");
while (rs.next()) { while (rs.next()) {
SoundRecordingEntity recordingEntity = new SoundRecordingEntity(); SoundRecordingEntity recordingEntity = new SoundRecordingEntity();
...@@ -66,7 +61,7 @@ public class SoundCopyTaskMain { ...@@ -66,7 +61,7 @@ public class SoundCopyTaskMain {
recordingEntity.setResult(rs.getString("callresult")); recordingEntity.setResult(rs.getString("callresult"));
recordingEntities.add(recordingEntity); recordingEntities.add(recordingEntity);
System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",rs.getObject("id"),rs.getObject("caller"), rs.getObject("callee"), rs.getObject("stm"), rs.getObject("edm"), rs.getObject("elapsed"), rs.getObject("recfile"), rs.getObject("filesize"), rs.getObject("callresult")); System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",rs.getObject("id"),rs.getObject("caller"), rs.getObject("callee"), rs.getObject("stm"), rs.getObject("edm"), rs.getObject("elapsed"), rs.getObject("recfile"), rs.getObject("filesize"), rs.getObject("callresult"));
Map<String, Object> row = new HashMap<>(); Map<String, Object> row = new HashMap<>(10);
row.put("id", rs.getObject("id")); row.put("id", rs.getObject("id"));
row.put("caller", rs.getObject("caller")); row.put("caller", rs.getObject("caller"));
row.put("callee", rs.getObject("callee")); row.put("callee", rs.getObject("callee"));
...@@ -80,8 +75,6 @@ public class SoundCopyTaskMain { ...@@ -80,8 +75,6 @@ public class SoundCopyTaskMain {
sounds.add(row); sounds.add(row);
} }
// service.updateSoundmaxId(newMaxId);
// return count;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -16,13 +16,14 @@ import java.util.*; ...@@ -16,13 +16,14 @@ import java.util.*;
import java.util.Date; import java.util.Date;
/** /**
* # 每分钟同步一次安科录音记录(直接读取安科数据库) * # 每分钟同步一次安科录音记录(直接读取安科数据库)
* *#1 * * * * root bash /mnt/foc/project/task/rundbsounds.sh * *#1 * * * * root bash /mnt/foc/project/task/rundbsounds.sh
* 导出文件名称: jd-task-db-sound-2.20.jar * 导出文件名称: jd-task-db-sound-2.20.jar
* @team BBDTEK IT Team *
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2017年9月1日 * @team BBDTEK IT Team
* @time 2017年9月1日
*/ */
public class SoundDbTaskMain { public class SoundDbTaskMain {
...@@ -43,60 +44,47 @@ public class SoundDbTaskMain { ...@@ -43,60 +44,47 @@ public class SoundDbTaskMain {
// args = new String[]{"1", "6000"}; // args = new String[]{"1", "6000"};
// 一个参数: 参数为向前加几分钟 // 一个参数: 参数为向前加几分钟
// 两个参数: 第一个参数向前加几分钟,第二个参数向后加几分钟 // 两个参数: 第一个参数向前加几分钟,第二个参数向后加几分钟
if (args.length == 2) { int argsLength = 2;
Long minId = Long.parseLong(args[0]);//service.getSoundMaxId(0L)+1; if (args.length == argsLength) {
System.out.print("minId:["+minId+"] TO "); Long minId = Long.parseLong(args[0]);
Long maxId = Long.parseLong(args[1]);//6005L; System.out.print("minId:[" + minId + "] TO ");
System.out.println("maxId:["+maxId+"]大概["+(maxId-minId+1)+"]条"); Long maxId = Long.parseLong(args[1]);
System.out.println("maxId:[" + maxId + "]大概[" + (maxId - minId + 1) + "]条");
int size = GConstants.getIntValue("page.size", 1000); int size = GConstants.getIntValue("page.size", 1000);
int count = 0; int count = 0;
while(minId<=maxId){ while (minId <= maxId) {
long endId = minId+size-1; long endId = minId + size - 1;
if(endId>maxId){ if (endId > maxId) {
endId = maxId; endId = maxId;
} }
System.out.println("id:["+minId+","+endId+"]"); System.out.println("id:[" + minId + "," + endId + "]");
count = startSoundTask(service, minId, endId); count = startSoundTask(service, minId, endId);
System.out.println("id:["+minId+","+endId+"]:"+count); System.out.println("id:[" + minId + "," + endId + "]:" + count);
minId = minId+size; minId = minId + size;
} }
// service.updateSoundmaxId(minId); } else {
} else{
// 获取soundMaxId出错时不应从0开始,退出本次运行即可,不影响下次同步 // 获取soundMaxId出错时不应从0开始,退出本次运行即可,不影响下次同步
// Long minId = service.getSoundMaxId(0L)+1;
Long minId = service.getSoundMaxId(Long.MAX_VALUE - 1) + 1; Long minId = service.getSoundMaxId(Long.MAX_VALUE - 1) + 1;
System.out.println("minId:["+minId+"]"); System.out.println("minId:[" + minId + "]");
Long maxId = getMaxIdFromAnke(1L); Long maxId = getMaxIdFromAnke(1L);
System.out.println("maxId:["+maxId+"]大概["+(maxId-minId+1)+"]条"); System.out.println("maxId:[" + maxId + "]大概[" + (maxId - minId + 1) + "]条");
int size = GConstants.getIntValue("page.size", 1000); int size = GConstants.getIntValue("page.size", 1000);
int count = 0; int count = 0;
while(minId<=maxId){ while (minId <= maxId) {
// System.out.println("count:["+minId+","+(minId+size-1)+"]:");
// count = startSoundTask(service, minId, minId+size-1); long endId = minId + size - 1;
// System.out.println("count:"+count); if (endId > maxId) {
// minId = minId+size;
long endId = minId+size-1;
if(endId>maxId){
endId = maxId; endId = maxId;
} }
System.out.println("id:["+minId+","+endId+"]"); System.out.println("id:[" + minId + "," + endId + "]");
count = startSoundTask(service, minId, endId); count = startSoundTask(service, minId, endId);
System.out.println("id:["+minId+","+endId+"]:"+count); System.out.println("id:[" + minId + "," + endId + "]:" + count);
minId = minId+size; minId = minId + size;
} }
// do{// 循环遍历整个表
//
// count = startSoundTask(service, minId, minId+size);
// System.out.println("count:"+count);
// minId = minId+size+1;
// } while(count>=size);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
...@@ -109,34 +97,26 @@ public class SoundDbTaskMain { ...@@ -109,34 +97,26 @@ public class SoundDbTaskMain {
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
} }
} }
private static int startSoundTask(final SoundService service, final Long minId, final Long maxId) { private static int startSoundTask(final SoundService service, final Long minId, final Long maxId) {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = GConstants.getValue("anke.database.url", "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200"); String url = GConstants.getValue("anke.database.url", "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200");
String username = GConstants.getValue("anke.database.username", "foctest"); String username = GConstants.getValue("anke.database.username", "foctest");
String password = GConstants.getValue("anke.database.password", "123@abc"); String password = GConstants.getValue("anke.database.password", "123@abc");
String tableName = "dbo.cdr"; String tableName = "dbo.cdr";
// String driver = "com.mysql.jdbc.Driver";
// String url = "jdbc:mysql://127.0.0.1:3306/edison200?useUnicode=true&characterEncoding=utf-8";
// String username = "root";
// String password = "";
// String tableName = "dbocdr";
Connection conn = null; Connection conn = null;
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
int count = 0; int count = 0;
try { try {
System.out.println("[SoundTaskMain]统计ID段[" + minId + " ]TO[" + maxId + " ]大概["+(maxId-minId+1)+"]条"); System.out.println("[SoundTaskMain]统计ID段[" + minId + " ]TO[" + maxId + " ]大概[" + (maxId - minId + 1) + "]条");
Class.forName(driver); Class.forName(driver);
conn = DriverManager.getConnection(url, username, password); conn = DriverManager.getConnection(url, username, password);
pstmt = conn pstmt = conn
.prepareStatement("select * from "+tableName+" where id BETWEEN " + minId + " AND "+maxId+" order by id ASC"); .prepareStatement("select * from " + tableName + " where id BETWEEN " + minId + " AND " + maxId + " order by id ASC");
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
// List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>();
Long newMaxId = 0L; Long newMaxId = 0L;
List<Map<String, Object>> sounds = new ArrayList<>(); List<Map<String, Object>> sounds = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
...@@ -148,16 +128,15 @@ public class SoundDbTaskMain { ...@@ -148,16 +128,15 @@ public class SoundDbTaskMain {
recordingEntity.setEndTime(DateUtil.stringToDate(rs.getString("edm"), "yyyy-MM-dd HH:mm:ss")); recordingEntity.setEndTime(DateUtil.stringToDate(rs.getString("edm"), "yyyy-MM-dd HH:mm:ss"));
recordingEntity.setDuration(rs.getInt("elapsed")); recordingEntity.setDuration(rs.getInt("elapsed"));
String downLoadUrl = ""; String downLoadUrl = "";
if(rs.getString("recfile")!=null && !"".equals(rs.getString("recfile"))){ if (rs.getString("recfile") != null && !"".equals(rs.getString("recfile"))) {
downLoadUrl = rs.getString("recfile").replace("D:\\edison_rec", "http://10.72.23.187"); downLoadUrl = rs.getString("recfile").replace("D:\\edison_rec", "http://10.72.23.187");
} }
recordingEntity.setDownloadUrl(downLoadUrl); recordingEntity.setDownloadUrl(downLoadUrl);
recordingEntity.setDownloadSize(rs.getLong("filesize")); recordingEntity.setDownloadSize(rs.getLong("filesize"));
recordingEntity.setResult(rs.getString("callresult")); recordingEntity.setResult(rs.getString("callresult"));
// recordingEntities.add(recordingEntity);
Map<String, Object> row = new HashMap<>(10);
Map<String, Object> row = new HashMap<>();
row.put("id", rs.getObject("id")); row.put("id", rs.getObject("id"));
row.put("caller", rs.getObject("caller")); row.put("caller", rs.getObject("caller"));
row.put("callee", rs.getObject("callee")); row.put("callee", rs.getObject("callee"));
...@@ -168,23 +147,21 @@ public class SoundDbTaskMain { ...@@ -168,23 +147,21 @@ public class SoundDbTaskMain {
row.put("filesize", rs.getObject("filesize")); row.put("filesize", rs.getObject("filesize"));
row.put("direct", rs.getObject("direct")); row.put("direct", rs.getObject("direct"));
row.put("callresult", rs.getObject("callresult")); row.put("callresult", rs.getObject("callresult"));
sounds.add(row); sounds.add(row);
// 将数据保存到分表,0表示插入测试表,1表示插入正式表
// service.inserSoundtDataFromDb(recordingEntity);// 将数据插入主表 service.insert(recordingEntity, "0");
service.insert(recordingEntity, "0");// 将数据保存到分表,0表示插入测试表,1表示插入正式表
Long id = rs.getLong("id"); Long id = rs.getLong("id");
if(newMaxId<id){ if (newMaxId < id) {
newMaxId = id; newMaxId = id;
} }
count++; count++;
} }
if(newMaxId>0){ if (newMaxId > 0) {
System.out.println("UPDATE foc_soundmax_id SET id="+newMaxId); System.out.println("UPDATE foc_soundmax_id SET id=" + newMaxId);
// service.updateSoundmaxId(newMaxId); DBHelper.update("foc", "UPDATE foc_soundmax_id SET id=" + newMaxId);
DBHelper.update("foc", "UPDATE foc_soundmax_id SET id="+newMaxId);
} }
DBHelper.insert("foc", "dbocdr", sounds); DBHelper.insert("foc", "dbocdr", sounds);
return count; return count;
...@@ -195,62 +172,60 @@ public class SoundDbTaskMain { ...@@ -195,62 +172,60 @@ public class SoundDbTaskMain {
} finally { } finally {
try { try {
rs.close(); rs.close();
} catch (Exception e2) {} } catch (Exception e2) {
}
try { try {
pstmt.close(); pstmt.close();
} catch (Exception e2) {} } catch (Exception e2) {
}
try { try {
conn.close(); conn.close();
} catch (Exception e2) {} } catch (Exception e2) {
}
} }
return 0; return 0;
} }
private static Long getMaxIdFromAnke(final Long defaultId) { private static Long getMaxIdFromAnke(final Long defaultId) {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = GConstants.getValue("anke.database.url", "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200"); String url = GConstants.getValue("anke.database.url", "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200");
String username = GConstants.getValue("anke.database.username", "foctest"); String username = GConstants.getValue("anke.database.username", "foctest");
String password = GConstants.getValue("anke.database.password", "123@abc"); String password = GConstants.getValue("anke.database.password", "123@abc");
String tableName = "dbo.cdr"; String tableName = "dbo.cdr";
// Connection conn = null;
// String driver = "com.mysql.jdbc.Driver"; ResultSet rs = null;
// String url = "jdbc:mysql://127.0.0.1:3306/edison200?useUnicode=true&characterEncoding=utf-8"; PreparedStatement pstmt = null;
// String username = "root"; try {
// String password = ""; Class.forName(driver);
// String tableName = "dbocdr"; conn = DriverManager.getConnection(url, username, password);
pstmt = conn
Connection conn = null; .prepareStatement("select MAX(id) AS maxid from " + tableName);
ResultSet rs = null; rs = pstmt.executeQuery();
PreparedStatement pstmt = null; while (rs.next()) {
try {
Class.forName(driver); return rs.getLong("maxid");
conn = DriverManager.getConnection(url, username, password); }
pstmt = conn } catch (ClassNotFoundException e) {
.prepareStatement("select MAX(id) AS maxid from "+tableName); e.printStackTrace();
rs = pstmt.executeQuery(); } catch (SQLException e) {
while (rs.next()) { e.printStackTrace();
} finally {
return rs.getLong("maxid"); try {
} rs.close();
} catch (ClassNotFoundException e) { } catch (Exception e2) {
e.printStackTrace(); }
} catch (SQLException e) { try {
e.printStackTrace(); pstmt.close();
} finally { } catch (Exception e2) {
try { }
rs.close(); try {
} catch (Exception e2) {} conn.close();
try { } catch (Exception e2) {
pstmt.close(); }
} catch (Exception e2) {} }
try { return defaultId;
conn.close(); }
} catch (Exception e2) {}
}
return defaultId;
}
} }
/** /**
* *
*/ */
package com.foc.task; package com.foc.task;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.client.utils.DateUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foc.TaskSupporter; import com.foc.TaskSupporter;
import com.foc.TaskTemplate; import com.foc.TaskTemplate;
...@@ -24,73 +11,76 @@ import com.foc.conf.HistoryConfig; ...@@ -24,73 +11,76 @@ import com.foc.conf.HistoryConfig;
import com.foc.fetcher.HCFetcher; import com.foc.fetcher.HCFetcher;
import com.foc.sound.SoundTask; import com.foc.sound.SoundTask;
import com.foc.sound.entity.SoundRecordingEntity; import com.foc.sound.entity.SoundRecordingEntity;
import com.foc.sound.service.SoundService;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import com.foc.util.MapCounter; import com.foc.util.MapCounter;
import org.apache.http.client.utils.DateUtils;
import java.sql.*;
import java.util.*;
import java.util.Date;
/** /**
* 注:已经弃用 * 注:已经弃用
* * <p>
* # 每5分钟同步一次录音数据 * # 每5分钟同步一次录音数据
* *#2 1-23 * * * root bash /mnt/foc/project/task/runsounds.sh * *#2 1-23 * * * root bash /mnt/foc/project/task/runsounds.sh
* # 每天1点同步一次最近一天的数据 * # 每天1点同步一次最近一天的数据
* 10 0 * * * root bash /mnt/foc/project/task/runsoundsdaily.sh * 10 0 * * * root bash /mnt/foc/project/task/runsoundsdaily.sh
* 导出文件名称: jd-task-sounds-2.7.jar * 导出文件名称: jd-task-sounds-2.7.jar
* @team IT Team *
* @author zhanglg * @author zhanglg
* @version 1.0 * @version 1.0
* @time 2017年2月23日 * @team IT Team
* @time 2017年2月23日
*/ */
public class SoundTaskMain { public class SoundTaskMain {
public static void main(String[] args) { public static void main(String[] args) {
final String key = "sound.task.is.running"; final String key = "sound.task.is.running";
final String allTaskKey = "all.task.is.running";
final String dailyTaskKey = "daily.task.is.running";
long startTime = System.nanoTime(); long startTime = System.nanoTime();
try { try {
if (HistoryConfig.getInt(key, 0) == 1) { if (HistoryConfig.getInt(key, 0) == 1) {
System.out.println("[SoundTaskMain]上次程序正在运行!跳过本次运行。。。"); System.out.println("[SoundTaskMain]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("all.task.is.running", 0) == 1) { if (HistoryConfig.getInt(allTaskKey, 0) == 1) {
System.out.println("[SoundTaskMain][ALL]上次程序正在运行!跳过本次运行。。。"); System.out.println("[SoundTaskMain][ALL]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
if (HistoryConfig.getInt("daily.task.is.running", 0) == 1) { if (HistoryConfig.getInt(dailyTaskKey, 0) == 1) {
System.out.println("[SoundTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。"); System.out.println("[SoundTaskMain][DAILY]上次程序正在运行!跳过本次运行。。。");
return; return;
} }
HistoryConfig.put("sound.task.last.time", DateUtil.getDateTime()); HistoryConfig.put("sound.task.last.time", DateUtil.getDateTime());
HistoryConfig.put(key, "1"); HistoryConfig.put(key, "1");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
// 一个参数: 参数为向前加几分钟 // 一个参数: 参数为向前加几分钟
// 两个参数: 第一个参数向前加几分钟,第二个参数向后加几分钟 // 两个参数: 第一个参数向前加几分钟,第二个参数向后加几分钟
if(args == null || args.length ==0 || args.length > 2){ int intValue1 = 1;
int intValue2 = 2;
args = new String[]{"-30", "10"}; if (args == null || args.length == 0 || args.length > intValue2) {
} else if(args.length == 1){
args = new String[]{"-30", "10"};
args = new String[]{ args[0], "0"}; } else if (args.length == intValue1) {
} else if(args.length == 2){
args = new String[]{args[0], "0"};
args = new String[]{args[0], args[1]}; } else if (args.length == intValue2) {
}
final int start = Integer.valueOf(args[0]);// 开始日期位移天数 args = new String[]{args[0], args[1]};
final int days = Integer.valueOf(args[1]);// 结束日期位移天数 }
// String dateFrom = DateUtil.dateToStr(DateUtil.offsetMinute(new Date(), start), DateUtil.TIMEF_FORMAT); // 开始日期位移天数
// String dateTo = DateUtil.dateToStr(DateUtil.offsetMinute(new Date(), days), DateUtil.TIMEF_FORMAT); final int start = Integer.valueOf(args[0]);
// // 结束日期位移天数
// String dateFrom = "2017-08-04 00:00:00";//DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT); final int days = Integer.valueOf(args[1]);
// String dateTo = "2017-08-04 23:59:59";DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT);
// String dateFrom = "2017-08-07 14:23:00";
// String dateFrom = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), start), DateUtil.DATE_FORMAT); String dateTo = "2017-08-07 14:26:00";
// String dateTo = DateUtil.dateToStr(DateUtil.offsetDate(new Date(), days), DateUtil.DATE_FORMAT);
System.out.println("[SoundTaskMain]统计时间段[" + dateFrom + " ]TO[" + dateTo + " ]");
String dateFrom = "2017-08-07 14:23:00"; startSoundTask(dateFrom, dateTo);
String dateTo = "2017-08-07 14:26:00";
System.out.println("[SoundTaskMain]统计时间段["+dateFrom+" ]TO["+dateTo+" ]");
startSoundTask(dateFrom, dateTo);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); e.printStackTrace();
...@@ -98,104 +88,101 @@ public class SoundTaskMain { ...@@ -98,104 +88,101 @@ public class SoundTaskMain {
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("[SoundTaskMain]结束["+DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT)+"]"); System.out.println("[SoundTaskMain]结束[" + DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT) + "]");
System.out.println("执行总共用时:" + duration + "纳秒"); System.out.println("执行总共用时:" + duration + "纳秒");
System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("执行总共用时格式化:" + DateUtil.getDurationTime(duration));
HistoryConfig.put(key, "0"); HistoryConfig.put(key, "0");
HistoryConfig.saveHistory(); HistoryConfig.saveHistory();
} }
} }
private static void startSoundTask(final String start, final String end){
private static void startSoundTask(final String start, final String end) {
SoundTask task = new SoundTask(new TaskSupporter() { SoundTask task = new SoundTask(new TaskSupporter() {
private SoundService service=new SoundService();
@Override @Override
public String setBaseUrl(TaskTemplate taskTemplate) { public String setBaseUrl(TaskTemplate taskTemplate) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return GConstants.FOC_SOUND_RECORDS_URL+"?pageNo="+taskTemplate.getPageIndex(); return GConstants.FOC_SOUND_RECORDS_URL + "?pageNo=" + taskTemplate.getPageIndex();
} }
@Override @Override
public Map<String, String> setParams() { public Map<String, String> setParams() {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>(3);
// params.put("pageNo", taskTemplate.getPageIndex()); params.put("pageSize", "1000");
params.put("pageSize","1000");
params.put("beginTime", start); params.put("beginTime", start);
params.put("endTime", end); params.put("endTime", end);
return params; return params;
} }
@Override @Override
public void successHandle(JSONObject result) { public void successHandle(JSONObject result) {
// yes更新CALL表,NO更新sound表 // yes更新CALL表,NO更新sound表
// service.insertData(result, start, end, GConstants.getValue("call.record.to", GConstants.YES)); //之前获取的id
int maxId = 0;//之前获取的id int maxId = 0;
//同步数据 String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
// List<Integer> list= service.getSoundMaxId(); String url = "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200";
// if(list!=null && list.size()>0){
// maxId = list.get(0); try {
// } Class.forName(driver);
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; Connection conn = DriverManager.getConnection(url, "foctest", "123@abc");
String url="jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200"; PreparedStatement pstmt = conn.prepareStatement("select * from dbo.cdr where id>" + maxId + " order by id ASC");
ResultSet rs = pstmt.executeQuery();
try { List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>();
Class.forName(driver); while (rs.next()) {
Connection conn=DriverManager.getConnection(url,"foctest","123@abc"); SoundRecordingEntity recordingEntity = new SoundRecordingEntity();
PreparedStatement pstmt=conn.prepareStatement("select * from dbo.cdr where id>"+maxId +" order by id ASC"); recordingEntity.setCallNo(rs.getString("caller"));
ResultSet rs=pstmt.executeQuery(); recordingEntity.setAcceptNo(rs.getString("callee"));
List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>(); recordingEntity.setBeginTime(rs.getDate("stm"));
int newMaxId = 0; recordingEntity.setEndTime(rs.getDate("edm"));
while(rs.next()){ recordingEntity.setDuration(rs.getInt("elapsed"));
SoundRecordingEntity recordingEntity = new SoundRecordingEntity(); recordingEntity.setDownloadUrl(rs.getString("recfile"));
recordingEntity.setCallNo(rs.getString("caller")); recordingEntity.setDownloadSize(rs.getLong("filesize"));
recordingEntity.setAcceptNo(rs.getString("callee")); recordingEntity.setResult(rs.getString("callresult"));
recordingEntity.setBeginTime(rs.getDate("stm")); recordingEntities.add(recordingEntity);
recordingEntity.setEndTime(rs.getDate("edm")); System.out.println("id:" + rs.getInt("id")
recordingEntity.setDuration(rs.getInt("elapsed")); + "callNo:" + rs.getString("caller")
recordingEntity.setDownloadUrl(rs.getString("recfile")); + "acceptNo:" + rs.getString("callee")
recordingEntity.setDownloadSize(rs.getLong("filesize")); + "beginTime:" + DateUtils.formatDate(rs.getDate("stm"), "yyyy-MM-dd HH:mm:ss")
recordingEntity.setResult(rs.getString("callresult")); + "EndTime:" + DateUtils.formatDate(rs.getDate("edm"), "yyyy-MM-dd HH:mm:ss")
recordingEntities.add(recordingEntity); + "Duration:" + rs.getInt("elapsed")
newMaxId = rs.getInt("id"); + "DownloadUrl:" + rs.getString("recfile")
System.out.println("id:"+rs.getInt("id") + "DownloadSize:" + rs.getLong("filesize")
+"callNo:"+rs.getString("caller") + "Result:" + rs.getString("callresult"));
+"acceptNo:"+rs.getString("callee") }
+"beginTime:"+DateUtils.formatDate(rs.getDate("stm"),"yyyy-MM-dd HH:mm:ss") rs.close();
+"EndTime:"+DateUtils.formatDate(rs.getDate("edm"),"yyyy-MM-dd HH:mm:ss") pstmt.close();
+"Duration:"+rs.getInt("elapsed") conn.close();
+"DownloadUrl:"+rs.getString("recfile") } catch (ClassNotFoundException e) {
+"DownloadSize:"+rs.getLong("filesize") e.printStackTrace();
+"Result:"+rs.getString("callresult")); } catch (SQLException e) {
} e.printStackTrace();
// service.insertData(recordingEntities, start, end, GConstants.getValue("call.record.to", GConstants.YES)); }
// service.updateSoundmaxId(newMaxId,maxId);
rs.close();
pstmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Override @Override
public String setPageIndexProperty() { public String setPageIndexProperty() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return "foc.sound.page.index"; return "foc.sound.page.index";
} }
@Override @Override
public boolean isGet() { public boolean isGet() {
return true; return true;
} }
@Override @Override
public boolean isPost() { public boolean isPost() {
return false; return false;
} }
@Override @Override
public String getApiName() { public String getApiName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return "sound"; return "sound";
} }
@Override @Override
public boolean finish() { public boolean finish() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
*/ */
package com.foc.task; package com.foc.task;
import java.util.HashMap;
import java.util.Map;
/** /**
* *
* @team BBDTEK IT Team * @team BBDTEK IT Team
...@@ -20,30 +23,37 @@ public class TestMain { ...@@ -20,30 +23,37 @@ public class TestMain {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
//
int count = 6; // int count = 6;
int pageNo=2; // int pageNo=2;
int pageSize=4; // int pageSize=4;
System.out.println(count/pageSize+1); // System.out.println(count/pageSize+1);
int startSize=(pageNo-1)*pageSize; // int startSize=(pageNo-1)*pageSize;
int endSize=pageNo*pageSize; // int endSize=pageNo*pageSize;
//
String sql = "SELECT ROWNUM AS rowno,tmp.* FROM (SELECT T.PK_JKBX,T.DJZT FROM ER_BXZB T ORDER BY T.TS DESC) tmp WHERE ROWNUM<="+endSize; // String sql = "SELECT ROWNUM AS rowno,tmp.* FROM (SELECT T.PK_JKBX,T.DJZT FROM ER_BXZB T ORDER BY T.TS DESC) tmp WHERE ROWNUM<="+endSize;
System.out.println("SELECT * FROM ("+sql+") tm WHERE tm.rowno >"+startSize); // System.out.println("SELECT * FROM ("+sql+") tm WHERE tm.rowno >"+startSize);
//
//
int index1 = sql.indexOf("SELECT")+6; // int index1 = sql.indexOf("SELECT")+6;
String prefixSql1 = sql.substring(0, index1); // String prefixSql1 = sql.substring(0, index1);
String endSql1 = sql.substring(index1); // String endSql1 = sql.substring(index1);
String qsql1 = prefixSql1+" ROWNUM AS rowno,"+endSql1; // String qsql1 = prefixSql1+" ROWNUM AS rowno,"+endSql1;
//
int index = qsql1.lastIndexOf("WHERE")+5; // int index = qsql1.lastIndexOf("WHERE")+5;
String prefixSql = qsql1.substring(0, index); // String prefixSql = qsql1.substring(0, index);
String endSql = qsql1.substring(index); // String endSql = qsql1.substring(index);
//
String qsql = prefixSql+" ROWNUM<="+endSize+" AND "+endSql; // String qsql = prefixSql+" ROWNUM<="+endSize+" AND "+endSql;
//
System.out.println("SELECT * FROM ("+qsql+") tmp WHERE tmp.rowno >"+startSize); // System.out.println("SELECT * FROM ("+qsql+") tmp WHERE tmp.rowno >"+startSize);
// Map<String,String> map = new HashMap<>(3);
// map.put("1","2");
// map.put("2","2");
// map.put("3","2");
// map.put("4","2");
// map.put("5","2");
// System.out.println(map.size());
} }
} }
/**
*
*/
package com.foc.task;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.foc.sound.entity.SoundRecordingEntity;
import com.foc.util.DBHelper;
/**
*
* @team BBDTEK IT Team
* @author renmb
* @version 1.0
* @time 2017年9月3日
*/
public class TestSoundCopyTaskMain {
/**
* 测试类
*
* @author renmb
* @time 2017年9月3日
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List<Map<String, Object>> sounds = new ArrayList<>();//.fetch("sound", "select * from dbo.cdr where id BETWEEN " + 10000 + " AND "+30000+" order by id ASC");
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200";
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
int count = 0;
try {
// System.out.println("[SoundTaskMain]统计ID段[" + minId + " ]TO[" + maxId + " ]");
Class.forName(driver);
conn = DriverManager.getConnection(url, "foctest", "123@abc");
pstmt = conn
.prepareStatement("select * from dbo.cdr where id BETWEEN " + 10000 + " AND "+30000+" order by id ASC");
rs = pstmt.executeQuery();
List<SoundRecordingEntity> recordingEntities = new ArrayList<SoundRecordingEntity>();
Long newMaxId = 0L;
System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n","id","caller","callee","stm","edm","elapsed","recfile","filesize","callresult");
while (rs.next()) {
SoundRecordingEntity recordingEntity = new SoundRecordingEntity();
recordingEntity.setId(String.valueOf(rs.getInt("id")));
recordingEntity.setCallNo(rs.getString("caller"));
recordingEntity.setAcceptNo(rs.getString("callee"));
recordingEntity.setBeginTime(rs.getDate("stm"));
recordingEntity.setEndTime(rs.getDate("edm"));
recordingEntity.setDuration(rs.getInt("elapsed"));
recordingEntity.setDownloadUrl(rs.getString("recfile"));
recordingEntity.setDownloadSize(rs.getLong("filesize"));
recordingEntity.setResult(rs.getString("callresult"));
recordingEntities.add(recordingEntity);
System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",rs.getObject("id"),rs.getObject("caller"), rs.getObject("callee"), rs.getObject("stm"), rs.getObject("edm"), rs.getObject("elapsed"), rs.getObject("recfile"), rs.getObject("filesize"), rs.getObject("callresult"));
Map<String, Object> row = new HashMap<>();
row.put("id", rs.getObject("id"));
row.put("caller", rs.getObject("caller"));
row.put("callee", rs.getObject("callee"));
row.put("stm", rs.getObject("stm"));
row.put("edm", rs.getObject("edm"));
row.put("elapsed", rs.getObject("elapsed"));
row.put("recfile", rs.getObject("recfile"));
row.put("filesize", rs.getObject("filesize"));
row.put("direct", rs.getObject("direct"));
row.put("callresult", rs.getObject("callresult"));
sounds.add(row);
}
// service.updateSoundmaxId(newMaxId);
// return count;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
} catch (Exception e2) {}
try {
pstmt.close();
} catch (Exception e2) {}
try {
conn.close();
} catch (Exception e2) {}
}
DBHelper.insert("foc", "dbo.cdr", sounds);
}
}
...@@ -3,70 +3,72 @@ ...@@ -3,70 +3,72 @@
*/ */
package com.foc.task; package com.foc.task;
import java.util.List;
import com.foc.fetcher.HCFetcher; import com.foc.fetcher.HCFetcher;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import com.uc.entity.UCImGroupEntity; import com.uc.entity.UCImGroupEntity;
import com.uc.entity.UserProfileEntity;
import com.uc.service.FOCImGroupService; import com.uc.service.FOCImGroupService;
import com.uc.service.UCImGroupService; import com.uc.service.UCImGroupService;
import com.uc.service.UCUserService;
import java.util.List;
/** /**
* # 每小时同步一次华为的群信息 * # 每小时同步一次华为的群信息
* 0 *#1 * * * root bash /mnt/foc/project/task/runucgroup.sh * 0 *#1 * * * root bash /mnt/foc/project/task/runucgroup.sh
* 导出文件名称: jd-task-group-2.6.jar * 导出文件名称: jd-task-group-2.6.jar
* *
* @team BBDTEK IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2017年3月2日 * @team BBDTEK IT Team
* @time 2017年3月2日
*/ */
public class UCImGroupTaskMain { public class UcImGroupTaskMain {
/** /**
*
* @author renmb
* @time 2017年3月2日
* @param args * @param args
* @author renmb
* @time 2017年3月2日
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println("[UCImGroupTaskMain]开始时间[" + DateUtil.getDateTime() + "]"); System.out.println("[UcImGroupTaskMain]开始时间[" + DateUtil.getDateTime() + "]");
long startTime = System.nanoTime(); long startTime = System.nanoTime();
try { try {
FOCImGroupService focService = new FOCImGroupService(); FOCImGroupService focService = new FOCImGroupService();
UCImGroupService ucService = new UCImGroupService(focService); UCImGroupService ucService = new UCImGroupService(focService);
if(args.length>0){ if (args.length > 0) {
if("SQL".equals(args[0])){// 通过SQL同步 // 通过SQL同步
String str1 = "SQL";
if(args[1].startsWith("SELECT")){ String str2 = "SELECT";
String str3 = "ALL";
if (str1.equals(args[0])) {
if (args[1].startsWith(str2)) {
List<UCImGroupEntity> users = ucService.findGroupListBySql(args[1]); List<UCImGroupEntity> users = ucService.findGroupListBySql(args[1]);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
ucService.handleGroup(users, "SQL"); ucService.handleGroup(users, "SQL");
} }
} else if("ALL".equals(args[0])){// 同步所有没有绑定华为账号的用户 // 同步所有没有绑定华为账号的用户
} else if (str3.equals(args[0])) {
List<UCImGroupEntity> users = ucService.findGroupList(null); List<UCImGroupEntity> users = ucService.findGroupList(null);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
ucService.handleGroup(users, "ALL"); ucService.handleGroup(users, "ALL");
} else { } else {
// 同步指定用户ID的用户
List<UCImGroupEntity> users = ucService.findGroupList(args);// 同步指定用户ID的用户 List<UCImGroupEntity> users = ucService.findGroupList(args);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
ucService.handleGroup(users, "ID"); ucService.handleGroup(users, "ID");
} }
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception e.printStackTrace();
} }
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("[UCImGroupTaskMain]结束时间[" + DateUtil.getDateTime() + "]"); System.out.println("[UcImGroupTaskMain]结束时间[" + DateUtil.getDateTime() + "]");
System.out.println("[UCImGroupTaskMain]总共用时:" + duration + "纳秒"); System.out.println("[UcImGroupTaskMain]总共用时:" + duration + "纳秒");
System.out.println("[UCImGroupTaskMain]总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("[UcImGroupTaskMain]总共用时格式化:" + DateUtil.getDurationTime(duration));
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
System.exit(0); System.exit(0);
} }
......
...@@ -3,79 +3,82 @@ ...@@ -3,79 +3,82 @@
*/ */
package com.foc.task; package com.foc.task;
import java.util.List;
import com.foc.fetcher.HCFetcher; import com.foc.fetcher.HCFetcher;
import com.foc.util.DateUtil; import com.foc.util.DateUtil;
import com.uc.demo.UCDepartmentDemo;
import com.uc.entity.SeatEntity; import com.uc.entity.SeatEntity;
import com.uc.entity.UserProfileEntity; import com.uc.entity.UserProfileEntity;
import com.uc.service.UCUserService; import com.uc.service.UCUserService;
import java.util.List;
/** /**
* # 每天凌晨1点同步用户数据 * # 每天凌晨1点同步用户数据
* 1 * * * root bash /mnt/foc/project/task/runhrmtask.sh * 1 * * * root bash /mnt/foc/project/task/runhrmtask.sh
* 导出文件名称: jd-task-hrm-2.6.jar * 导出文件名称: jd-task-hrm-2.6.jar
* *
* @team IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @time 2017年1月17日 * @team IT Team
* @time 2017年1月17日
*/ */
public class UCUserTaskMain { public class UcUserTaskMain {
/** /**
*
* @author renmb
* @time 2017年1月17日
* @param args * @param args
* @author renmb
* @time 2017年1月17日
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println("[UCUserTaskMain]开始时间[" + DateUtil.getDateTime() + "]"); System.out.println("[UcUserTaskMain]开始时间[" + DateUtil.getDateTime() + "]");
long startTime = System.nanoTime(); long startTime = System.nanoTime();
try { try {
UCUserService service = new UCUserService(); UCUserService service = new UCUserService();
if(args.length>0){ String str1 = "SQL";
if("SQL".equals(args[0])){// 通过SQL同步 String str2 = "SELECT";
String str3 = "ALL";
if(args[1].startsWith("SELECT")){ if (args.length > 0) {
// 通过SQL同步
if (str1.equals(args[0])) {
if (args[1].startsWith(str2)) {
List<UserProfileEntity> users = service.findUserListBySql(args[1]); List<UserProfileEntity> users = service.findUserListBySql(args[1]);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
service.addAccountToUc(users); service.addAccountToUc(users);
// 同步指定用户ID的用户
List<SeatEntity> seatList = service.findSeatListBySql(args[1]);// 同步指定用户ID的用户 List<SeatEntity> seatList = service.findSeatListBySql(args[1]);
System.out.println("本次同步总席位数:"+seatList.size()); System.out.println("本次同步总席位数:" + seatList.size());
service.addSeatAccountToUc(seatList); service.addSeatAccountToUc(seatList);
} }
} else if("ALL".equals(args[0])){// 同步所有没有绑定华为账号的用户 // 同步所有没有绑定华为账号的用户
} else if (str3.equals(args[0])) {
List<UserProfileEntity> users = service.findUserList(null); List<UserProfileEntity> users = service.findUserList(null);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
service.addAccountToUc(users); service.addAccountToUc(users);
// 同步指定用户ID的用户
List<SeatEntity> seatList = service.findSeatList(null);// 同步指定用户ID的用户 List<SeatEntity> seatList = service.findSeatList(null);
System.out.println("本次同步总席位数:"+seatList.size()); System.out.println("本次同步总席位数:" + seatList.size());
service.addSeatAccountToUc(seatList); service.addSeatAccountToUc(seatList);
} else { } else {
// 同步指定用户ID的用户
List<UserProfileEntity> users = service.findUserList(args);// 同步指定用户ID的用户 List<UserProfileEntity> users = service.findUserList(args);
System.out.println("本次同步总人数:"+users.size()); System.out.println("本次同步总人数:" + users.size());
service.addAccountToUc(users); service.addAccountToUc(users);
// 同步指定用户ID的用户
List<SeatEntity> seatList = service.findSeatList(args);// 同步指定用户ID的用户 List<SeatEntity> seatList = service.findSeatList(args);
System.out.println("本次同步总席位数:"+seatList.size()); System.out.println("本次同步总席位数:" + seatList.size());
service.addSeatAccountToUc(seatList); service.addSeatAccountToUc(seatList);
} }
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception e.printStackTrace();
} }
long endTime = System.nanoTime(); long endTime = System.nanoTime();
long duration = endTime - startTime; long duration = endTime - startTime;
System.out.println("[UCUserTaskMain]结束时间[" + DateUtil.getDateTime() + "]"); System.out.println("[UcUserTaskMain]结束时间[" + DateUtil.getDateTime() + "]");
System.out.println("[UCUserTaskMain]总共用时:" + duration + "纳秒"); System.out.println("[UcUserTaskMain]总共用时:" + duration + "纳秒");
System.out.println("[UCUserTaskMain]总共用时格式化:" + DateUtil.getDurationTime(duration)); System.out.println("[UcUserTaskMain]总共用时格式化:" + DateUtil.getDurationTime(duration));
HCFetcher.getInstance().shutdown(); HCFetcher.getInstance().shutdown();
System.exit(0); System.exit(0);
} }
......
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