public static int[] timeScope = new int[]{1,2,3,4,6,8,12,24};
public static String[] char26 = new String[]{“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”g”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”};
/
@author: qzf
@date: 2022/5/24 17:35
@describe: 获取下次拍照时间,按整点计算
@param:当前时间,时间间隔 (1,2,3,4,6,8,12,24)
@return:
/
public static Date getPzTimeInterval(Date date, Integer pzjg){
//获取拍照间隔
int finalPzjg = (pzjg == null || pzjg == 0) ? ApplicationConfig.pzTimeInterval : pzjg;
//检测拍照间隔是否正确
if(Arrays.binarySearch(timeScope,finalPzjg) < 0){
//如果不在范围内按24小时计算
finalPzjg = 24;
}
//根据间隔划分拍照区间:如:间隔8小时,24/8 = 3 个区间
/
0 [00:00 - 08:00) 即 [00:00:00.000 - 07:59:59.999]
1 [08:00 - 16:00) 即 [08:00:00.000 - 15:59:59.999]
2 [16:00 - 24:00) 即 [16:00:00.000 - 23:59:59.999]/
int period = 24 / finalPzjg;
String[][] arrPeriod = new String[period][2];
for(int i = 0; i < period; i++){
arrPeriod[i][0] = (ifinalPzjg) + “:00:00.000”;
arrPeriod[i][1] = (ifinalPzjg) + (finalPzjg - 1) + “:59:59.999”;
}
//判断日期在哪个区间
Date pzTime = null;
for(int j = 0; j < arrPeriod.length; j++){
long currSt = date.getTime();
long begSt = DateUtil.stringToDate( DateUtil.dateToString(date) + “ “ + arrPeriod[j][0] ,DateUtil.DATE_TIME_SSS_FORMAT).getTime();
long endSt = DateUtil.stringToDate( DateUtil.dateToString(date) + “ “ + arrPeriod[j][1] ,DateUtil.DATE_TIME_SSS_FORMAT).getTime();
if(currSt >= begSt && currSt <= endSt){
//如果在最后一个区间内,设置为日期为第2天的0点
if(j == arrPeriod.length - 1){
pzTime = DateUtil.stringToDate( DateUtil.dateToString(DateUtil.addDay(date,1)) + “ “ + arrPeriod[0][0], DateUtil.DATE_TIME_SSS_FORMAT);
}
else{
pzTime = DateUtil.stringToDate(DateUtil.dateToString(date) + “ “ + arrPeriod[j+1][0], DateUtil.DATE_TIME_SSS_FORMAT);
}
break;
}
}
//不在任何区间内,一般不会执行这里,如果出现,设置为第2天的0点
if(pzTime == null){
pzTime = DateUtil.addDay( DateUtil.stringToDate( DateUtil.dateToString(date)) ,1);
}
return pzTime;
}
/
@author: qzf
@date: 2022/5/24 17:35
@describe: 获取设备通讯间隔
@param:
@return:
/
public static int getTxTimeInterval(String sbbh){
Long sbbhLong = 0L;
try{
sbbhLong = Long.parseLong(sbbh);
}catch(Exception e){
e.printStackTrace();
try{
sbbh = sbbh.toLowerCase();
for(String s : char26 ){
sbbh = sbbh.replaceAll(s,””);
}
sbbhLong = Long.parseLong(sbbh);
}catch(Exception e1){
e1.printStackTrace();
}
}
Long mod = Math.floorMod(sbbhLong,ApplicationConfig.txTimeInterval);
return mod.intValue();
}
//调用
SxzdParam.getPzTimeInterval(DateUtil.stringToDate(“2021-05-12 21:01:00.00”,DateUtil.DATE_TIME_FORMAT),0);