import java.util.Calendar;
import java.util.Date;
/**
* @Description:时间段划分()
* @History(修改历史):
*/
public class TimePeriodHelper {
/**
* 凌晨
*/
public final static int EARLY_MORNING = 0;
/**
* 早上
*/
public final static int BEFORE_DAWN = 1;
/**
* 上午
*/
public final static int MORNING = 2;
/**
* 中午
*/
public final static int NOON = 3;
/**
* 下午
*/
public final static int AFTERNOON = 4;
/**
* 晚上
*/
public final static int NIGHT = 5;
/**
* 深夜
*/
public final static int LATE_NIGHT = 6;
/**
* @Date 2012-8-28 下午02:04:28
* @Author liuxingmi
* @Description 根据传入小时获取时间段 (0:凌晨、1:早上、2:上午、3:中午、4:下午、5:晚上、6:深夜)
* @param hour 小时 24H
* @return int
*/
public static int getTimePeriod(int hour) {
if (hour < 6) {
return EARLY_MORNING;
}
if (hour >= 6 && hour < 9) {
return BEFORE_DAWN;
}
if (hour >= 9 && hour < 12) {
return MORNING;
}
if (hour >= 12 && hour < 13) {
return NOON;
}
if (hour >= 13 && hour < 18) {
return AFTERNOON;
}
if (hour >= 18 && hour < 22) {
return NIGHT;
}
if (hour >= 22) {
return LATE_NIGHT;
}
return 9;
}
/**
* 计算两个日期相差天数
* @param baseDate
* @param currentDate
* @return
* @author dingchenghong
* @date 2013-03-22 14:43
*/
public static int getDifferDay(Date baseDate,Date currentDate){
if(baseDate == null || currentDate == null){
return 0;
}
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(baseDate);
c1.set(Calendar.HOUR_OF_DAY, 0);
c1.set(Calendar.MINUTE, 0);
c1.set(Calendar.SECOND, 0);
c2.setTime(currentDate);
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
long t1 = c1.getTime().getTime();
long t2 = c2.getTime().getTime();
int k=(int)Math.abs( ( t2 - t1 ) / 1000 / 3600 / 24 );
return k;
}
}
/**
* @Description 组装管理员操作日志信息
* @param data
* @return Map<String,List<AdminOperatLogData>>
*/
private Map<String, List<SysOperatLogData>> getLogDataMap(List<SysReportModel> data){
Map<String, List<SysOperatLogData>> logDataMap = new LinkedHashMap<String, List<SysOperatLogData>>();
for(int i=0;i<data.size();i++)
{
SysReportModel dto=data.get(i);
String key = TimeTool.date2String(dto.getLogTime(), TimeTool.BASE_DATE_FORMAT);
SysOperatLogData logData = this.getAdminOperatLogData(dto);
addDataToMap(key,logData,logDataMap);
}
return logDataMap;
}
/**
* @Description 组装日志详细信息
* @param dto
* @return LoginLogData
*/
private SysOperatLogData getAdminOperatLogData(SysReportModel dto) {
SysOperatLogData logData = new SysOperatLogData();
logData.setTime(TimeTool.date2String(dto.getLogTime(),"HH:mm"));
logData.setOperatUser(dto.getUserId());
logData.setOperatType( String.valueOf(dto.getOperatType()));
logData.setOperatResult(String.valueOf(dto.getOperatResult()));
logData.setContent( dto.getContent());
logData.setUserIp( dto.getUserIp());
return logData;
}
/**
* @Description 添加信息到map
* @param key
* @param logData
* @param logDataMap void
*/
private void addDataToMap(String key,SysOperatLogData logData,
Map<String, List<SysOperatLogData>> logDataMap) {
List<SysOperatLogData> logDatas = logDataMap.get(key);
if( logDatas == null){
logDatas = new ArrayList<SysOperatLogData>();
logDataMap.put(key, logDatas);
}
logDatas.add(logData);
}