Commit 79d2f73c by shenjinzhu

数据统计更新

parent eceb8328
......@@ -150,35 +150,37 @@ public class MainThread extends Thread {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH");
while (true) {
String today = sdf.format(new Date());
Date d = new Date();
Date d = null;
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
String today = sdf.format(start.getTime());
try {
d = sdf.parse(today);
start.setTime(sdf2.parse(sdf2.format(start.getTime())));
if (start.get(Calendar.HOUR_OF_DAY) > 1) {
start.add(Calendar.HOUR_OF_DAY, -1);
} else {
start.setTime(sdf.parse(today));
d.setHours(d.getHours()-1);
start.setTime(d);
}
end.setTime(sdf2.parse(sdf2.format(end.getTime())));
// end.add(Calendar.HOUR_OF_DAY, -1);
} catch (ParseException e2) {
e2.printStackTrace();
}
try {
mainLock.lock();
int count = 0;
List<Channel> channel = serverService.findDisChannel();
for (Channel chan : channel) {
try {
count = (int) dataService.finCountByDayData(start.getTime(), end.getTime(), chan.getPt());
System.out.println(count);
Data data = new Data();
data.setCount(count);
data.setPt(chan.getPt());
data.setTime(d);
dataService.insert(data);
log.info(TimeUtil.yearToDay(start.getTime()) + "|" + chan.getPt() + "|入库");
log.info(sdf.format(start.getTime()) + "|" + chan.getPt() + "|入库");
} catch (Exception e) {
log.error(chan.getPt() + "入库出错,错误信息{}", e);
}
......@@ -216,10 +218,8 @@ public class MainThread extends Thread {
}
} catch (Exception e) {
e.printStackTrace();
} finally {
mainLock.unlock();
}
Tools.sleep(1000 * 60 * 60);
Tools.sleep(1000 *60*60);
}
}
......
......@@ -6,6 +6,7 @@ import java.util.Date;
public class TimeUtil {
public static String yearToDay(Date date){
System.out.println(date);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
......
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