Browse Source

增加时间的工具类

konghl 4 years ago
parent
commit
165e3e6aea

+ 0 - 2
ebc-sea-platform/src/main/java/com/ai/ipu/server/dao/impl/DeviceManageDaoImpl.java

@ -235,8 +235,6 @@ public class DeviceManageDaoImpl extends AbstractBizDao implements DeviceManageD
235 235
			// 报警类型
236 236
			if (detailInfo.getJSONObject("alarmType")!=null) {
237 237
				detailInfoMap.put("alarmType", detailInfo.getJSONObject("alarmType").getString("value"));
238
			}else {
239
				detailInfoMap.put("alarmType", null);
240 238
			}
241 239
			
242 240
			list.add(detailInfoMap);

+ 22 - 9
ebc-sea-platform/src/main/java/com/ai/ipu/server/dao/impl/RescueDaoImpl.java

@ -52,21 +52,32 @@ public class RescueDaoImpl extends AbstractBizDao implements RescueDao {
52 52
	 */
53 53
	@Override
54 54
	public boolean addRescueLog(Map<String, Object> dataMap) throws Exception {
55
		dataMap.put("dataStatus", "1");
55
		dataMap.put("DATA_STATUS", "1");
56 56
		//TODO 创建人和操作人的编号和部门
57
		dataMap.put("departmentId", 1);
58
		dataMap.put("createDate", TimeUtil.getSysTime());
59
		dataMap.put("createOpId", "");
60
		dataMap.put("createOrgId", "");
61
		dataMap.put("doneDate", TimeUtil.getSysTime());
62
		dataMap.put("opId", "");
63
		dataMap.put("orgId", "");
57
		dataMap.put("CREATE_DATE", TimeUtil.getSysTime());
58
		dataMap.put("CREATE_OP_ID", "");
59
		dataMap.put("CREATE_ORG_ID", "");
60
		dataMap.put("DONE_DATE", TimeUtil.getSysTime());
61
		dataMap.put("OP_ID", "");
62
		dataMap.put("ORG_ID", "");
64 63
65 64
		int num=dao.insert("LR_RESCUE_LOG", dataMap);
66 65
		
67 66
		return num > 0;
68 67
	}
69
68
	
69
	@Override
70
	public boolean modifyRescueLog(Map<String, Object> dataMap) throws Exception {
71
		//TODO 操作人的编号和部门
72
		dataMap.put("DONE_DATE", TimeUtil.getSysTime());
73
		dataMap.put("OP_ID", "");
74
		dataMap.put("ORG_ID", "");
75
		
76
		int num=dao.update("LR_RESCUE_LOG", dataMap);
77
		
78
		return num > 0;
79
	}
80
	
70 81
	@Override
71 82
	public boolean assignRescuer(JMap params) throws Exception {
72 83
		// TODO Auto-generated method stub
@ -78,5 +89,7 @@ public class RescueDaoImpl extends AbstractBizDao implements RescueDao {
78 89
		// TODO Auto-generated method stub
79 90
		return false;
80 91
	}
92
	
93
	
81 94
82 95
}

+ 8 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/dao/interfaces/RescueDao.java

@ -42,6 +42,14 @@ public interface RescueDao {
42 42
	boolean addRescueLog(Map<String, Object> dataMap) throws Exception;
43 43
44 44
	/**
45
	 * 修改报警救援日志
46
	 * @param dataMap
47
	 * @return
48
	 * @throws Exception
49
	 */
50
	boolean modifyRescueLog(Map<String, Object> dataMap) throws Exception;
51
	
52
	/**
45 53
	 * 指派救援
46 54
	 * @return
47 55
	 * @throws Exception

+ 7 - 4
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/impl/DeviceManageServiceImpl.java

@ -18,6 +18,7 @@ import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
18 18
import com.ai.ipu.server.dao.interfaces.RescueDao;
19 19
import com.ai.ipu.server.enums.UserEnums;
20 20
import com.ai.ipu.server.service.interfaces.DeviceManageService;
21
import com.ai.ipu.server.util.DateUtil;
21 22
import com.ai.ipu.server.util.EbcConstant;
22 23
import com.ai.ipu.server.util.JingPingSendDateUtil;
23 24
import com.alibaba.fastjson.JSON;
@ -235,6 +236,7 @@ public class DeviceManageServiceImpl implements DeviceManageService {
235 236
			//离线信息
236 237
			if (map.get("alarmType")!=null&&EbcConstant.alarm_type_offline_beidou==Integer.parseInt(String.valueOf(map.get("alarmType")))) {
237 238
				map.put("locationStatus",EbcConstant.location_status_offline);//定位状态
239
				map.put("alarmType",EbcConstant.alarm_type_offline_ZH);//报警类型
238 240
				flag = false;
239 241
			}
240 242
			
@ -245,10 +247,10 @@ public class DeviceManageServiceImpl implements DeviceManageService {
245 247
					if (deviceId.equals(String.valueOf(alarmMap.get("DEVICE_ID")))) {
246 248
						// 求救时间
247 249
						String alarmDate = String.valueOf(alarmMap.get("CALLER_DATE"));
248
						map.put("alarmDate", alarmDate);
250
						map.put("alarmDate", DateUtil.formatStrDate(alarmDate));
249 251
250 252
						// 计算求救时长
251
						int alarmLong = JingPingSendDateUtil.getBetweenMinuteValue(alarmDate, map.get("newDate"));
253
						int alarmLong = DateUtil.getDifferenceMinute(alarmDate, map.get("newDate"));
252 254
						map.put("alarmLong", String.valueOf(alarmLong));
253 255
						
254 256
						//定位状态
@ -256,10 +258,12 @@ public class DeviceManageServiceImpl implements DeviceManageService {
256 258
						case EbcConstant.alarm_type_autosos_ZH:
257 259
							//自动报警
258 260
							map.put("locationStatus",EbcConstant.location_status_autosos);
261
							map.put("alarmType",EbcConstant.alarm_type_autosos_ZH);
259 262
							break;
260 263
						case EbcConstant.alarm_type_jogsos_ZH:
261 264
							//手动报警
262 265
							map.put("locationStatus",EbcConstant.location_status_jogsos);
266
							map.put("alarmType",EbcConstant.alarm_type_jogsos_ZH);
263 267
							break;
264 268
						default:
265 269
							break;
@ -315,8 +319,7 @@ public class DeviceManageServiceImpl implements DeviceManageService {
315 319
316 320
				} else if (maxMapTagGrade == 3) {
317 321
					// 进入定点(限时),需计算是否超时
318
					int fixedLong = JingPingSendDateUtil
319
							.getBetweenMinuteValue(String.valueOf(areaInfoMap.get("IN_DATE")), map.get("newDate"));
322
					int fixedLong = DateUtil.getDifferenceMinute(String.valueOf(areaInfoMap.get("IN_DATE")), map.get("newDate"));
320 323
321 324
					if (fixedLong > 0) {
322 325
						// 围栏要求定点时间

+ 17 - 9
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/impl/ReceiveSubscribeServiceImpl.java

@ -22,6 +22,7 @@ import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
22 22
import com.ai.ipu.server.dao.interfaces.MapTagManageDao;
23 23
import com.ai.ipu.server.dao.interfaces.RescueDao;
24 24
import com.ai.ipu.server.service.interfaces.ReceiveSubscribeService;
25
import com.ai.ipu.server.util.DateUtil;
25 26
import com.ai.ipu.server.util.EbcConstant;
26 27
import com.ai.ipu.server.util.JingPingSendDateUtil;
27 28
import com.alibaba.fastjson.JSON;
@ -51,7 +52,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
51 52
			public void run() {
52 53
				try {
53 54
					logger.debug("启动定位信息新线程:" + Thread.currentThread().getName());
54
					//处理定位数据
55
					// 处理定位数据
55 56
					executeReceiveIotLocationData(dataMap);
56 57
57 58
					logger.debug("数据库连接全量提交");
@ -76,7 +77,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
76 77
			public void run() {
77 78
				try {
78 79
					logger.debug("启动报警信息新线程:" + Thread.currentThread().getName());
79
					//处理报警数据
80
					// 处理报警数据
80 81
					executeReceiveIotAlarmData(dataMap);
81 82
82 83
					logger.debug("数据库连接全量提交");
@ -105,7 +106,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
105 106
		Map<String, Object> bindInfoMap = deviceManageDao.queryOneBindUser(params.getString("deviceId"), null);
106 107
107 108
		if (bindInfoMap != null) {
108
			//设备与人员绑定
109
			// 设备与人员绑定
109 110
			logger.debug("定位信息的对象为人员: " + bindInfoMap.get("NAME"));
110 111
			params.put("userName", bindInfoMap.get("NAME"));
111 112
			params.put("userCode", bindInfoMap.get("CODE"));
@ -113,7 +114,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
113 114
		} else {
114 115
			bindInfoMap = deviceManageDao.queryOneBindShip(params.getString("deviceId"), null);
115 116
			if (bindInfoMap != null) {
116
				//设备与船舶绑定
117
				// 设备与船舶绑定
117 118
				logger.info("定位信息的对象为船舶: " + bindInfoMap.get("NAME"));
118 119
				params.put("shipName", bindInfoMap.get("NAME"));
119 120
				params.put("shipCode", bindInfoMap.get("CODE"));
@ -123,7 +124,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
123 124
				logger.debug("推送镜屏数据:" + jingpingData);
124 125
				JingPingSendDateUtil.sendData(JingPingSendDateUtil.topic_ship, jingpingData);
125 126
			} else {
126
				//设备未绑定
127
				// 设备未绑定
127 128
				logger.error("定位设备未绑定");
128 129
			}
129 130
			return;
@ -173,10 +174,10 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
173 174
174 175
		// 求救时间
175 176
		String alarmDate = String.valueOf(alarmList.get(0).get("CALLER_DATE"));
176
		params.put("alarmDate", alarmDate);
177
		params.put("alarmDate", DateUtil.formatStrDate(alarmDate));
177 178
178 179
		// 计算求救时长
179
		params.put("alarmLong", JingPingSendDateUtil.getBetweenMinuteValue(alarmDate, params.getString("newDate")));
180
		params.put("alarmLong", DateUtil.getDifferenceMinute(alarmDate, params.getString("newDate")));
180 181
181 182
		params.put("isNewAlarm", "0");
182 183
@ -185,6 +186,12 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
185 186
		logger.debug("推送镜屏数据:" + jingpingData);
186 187
		JingPingSendDateUtil.sendData(JingPingSendDateUtil.topic_personnel, jingpingData);
187 188
189
		// 修改最后定位时间
190
		Map<String, Object> dataMap = new HashMap<String, Object>();
191
		dataMap.put("LOG_ID", alarmList.get(0).get("LOG_ID")); // 日志ID
192
		dataMap.put("LAST_LOCATION_DATE", params.get("newDate")); // 最后定位时间
193
		rescueDao.modifyRescueLog(dataMap);
194
188 195
		return true;
189 196
	}
190 197
@ -343,7 +350,7 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
343 350
344 351
		} else if (maxMapTagGrade == 3) {
345 352
			// 进入定点(限时),需计算是否超时
346
			int fixedLong = JingPingSendDateUtil.getBetweenMinuteValue(
353
			int fixedLong = DateUtil.getDifferenceMinute(
347 354
					String.valueOf(sendDataAreaInfo.get("inAreaDate")), params.getString("newDate"));
348 355
349 356
			if (fixedLong > 0) {
@ -422,7 +429,8 @@ public class ReceiveSubscribeServiceImpl implements ReceiveSubscribeService {
422 429
		dataMap.put("ALARM_TYPE", params.get("alarmType")); // 告警类型
423 430
		dataMap.put("LONGITUDE", params.get("longitude")); // 报警经度
424 431
		dataMap.put("LATITUDE", params.get("latitude")); // 报警纬度
425
		dataMap.put("CALLER_DATE", params.get("msgDate")); // 报警时间
432
		dataMap.put("CALLER_DATE", params.get("newDate")); // 报警时间
433
		dataMap.put("LAST_LOCATION_DATE", params.get("newDate")); // 最后定位时间
426 434
427 435
		// 报警位置
428 436
		if (currentAreaInfoJMap.getInt("mapTagNum") > 0) {

+ 193 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/DateUtil.java

@ -0,0 +1,193 @@
1
package com.ai.ipu.server.util;
2
3
import java.math.BigDecimal;
4
import java.text.ParseException;
5
import java.text.SimpleDateFormat;
6
import java.util.Date;
7
8
import com.ai.ipu.common.date.TimeUtil;
9
10
/**
11
 * 时间工具类
12
 * @author konghl@asiainfo.com
13
 * 2020-11-2
14
 */
15
public class DateUtil {
16
17
	/**
18
	 * 比较日期大小
19
	 * @param dateStr0
20
	 * @param dateStr1
21
	 * @return
22
	 */
23
	public static int compareDate(String dateStr0, String dateStr1) {
24
		Date date1 = convertDate(dateStr0);
25
		Date date2 = convertDate(dateStr1);
26
		int result = date1.compareTo(date2);
27
		return result;
28
	}
29
30
	/**
31
	 * 格式化字符串时间
32
	 * @param date
33
	 * @return yyyy-MM-dd HH:mm:ss
34
	 */
35
	public static String formatStrDate(String dateStr) {
36
		Date date = convertDate(dateStr);
37
		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
38
	}
39
40
	/**
41
	 * 时间转字符串 
42
	 * @param date
43
	 * @return yyyy-MM-dd HH:mm:ss
44
	 */
45
	public static String formatDate(Date date) {
46
		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
47
	}
48
49
	/**
50
	 * 时间转字符串
51
	 * @param date
52
	 * @param pattern 时间格式
53
	 * @return
54
	 */
55
	public static String formatDate(Date date, String pattern) {
56
		if (date == null) {
57
			return "";
58
		}
59
60
		SimpleDateFormat formatter = new SimpleDateFormat(pattern);
61
		return formatter.format(date);
62
	}
63
64
	/**
65
	 * 字符串转时间
66
	 * @param dateStr
67
	 * @return
68
	 */
69
	public static Date convertDate(String dateStr) {
70
		if (dateStr == null || "".equals(dateStr)) {
71
			return null;
72
		}
73
		String pattern = TimeUtil.getTimestampFormat(dateStr);
74
		return convertDate(dateStr, pattern);
75
	}
76
77
	/**
78
	 * 字符串转时间
79
	 * @param dateStr
80
	 * @param pattern
81
	 * @return
82
	 */
83
	public static Date convertDate(String dateStr, String pattern) {
84
		if (dateStr == null || "".equals(dateStr)) {
85
			return null;
86
		}
87
88
		if (pattern == null || "".equals(pattern)) {
89
			pattern = TimeUtil.getTimestampFormat(dateStr);
90
		}
91
92
		SimpleDateFormat formatter = new SimpleDateFormat(pattern);
93
		Date date = null;
94
		try {
95
			date = formatter.parse(dateStr);
96
		} catch (ParseException e) {
97
			e.printStackTrace();
98
		}
99
		return date;
100
	}
101
102
	/**
103
	 * 计算两个时间差,返回毫秒数(endDate-beginDate)
104
	 * @param beginDate
105
	 * @param endDate
106
	 * @return 
107
	 * @throws ParseException
108
	 */
109
	public static long getDifferenceMillisecond(Date beginDate, Date endDate) throws ParseException {
110
		long beginDateLong = 0L;
111
		long endDateLong = 0L;
112
		if (beginDate != null) {
113
			beginDateLong = beginDate.getTime();
114
		}
115
		if (endDate != null) {
116
			endDateLong = endDate.getTime();
117
		}
118
119
		return endDateLong - beginDateLong;
120
	}
121
122
	/**
123
	 * 计算两个时间差,返回毫秒数(endDate-beginDate)
124
	 * @param beginDateStr
125
	 * @param endDateStr
126
	 * @return 
127
	 * @throws ParseException
128
	 */
129
	public static long getDifferenceMillisecond(String beginDateStr, String endDateStr) throws ParseException {
130
		Date beginDate = convertDate(beginDateStr);
131
		Date endDate = convertDate(endDateStr);
132
		return getDifferenceMillisecond(beginDate, endDate);
133
	}
134
135
	/**
136
	 * 计算两个时间差,返回分钟数(endDate-beginDate)
137
	 * @param beginDate
138
	 * @param endDate
139
	 * @return
140
	 * @throws ParseException 
141
	 */
142
	public static int getDifferenceMinute(String beginDateStr, String endDateStr) throws ParseException {
143
		long diffMillisecond = getDifferenceMillisecond(beginDateStr, endDateStr);
144
		if (diffMillisecond > 0) {
145
			BigDecimal diffMillisecondBigDecimal = new BigDecimal(diffMillisecond);
146
			// 单位为分,四舍五入不保留小数
147
			BigDecimal diffMinuteBigDecimal = diffMillisecondBigDecimal.divide(new BigDecimal("60000"), 0,
148
					BigDecimal.ROUND_HALF_UP);
149
			return diffMinuteBigDecimal.intValue();
150
		} else {
151
			return 0;
152
		}
153
154
	}
155
156
	/**
157
	 * 计算两个时间差,返回字符串(endDate-beginDate)
158
	 * @param beginDateStr
159
	 * @param endDateStr
160
	 * @return
161
	 * @throws ParseException
162
	 */
163
	public static String getDifferenceString(String beginDateStr, String endDateStr) throws ParseException {
164
		long diffMillisecond = getDifferenceMillisecond(beginDateStr, endDateStr);
165
166
		if (diffMillisecond <= 60000) {
167
			return "0分钟";
168
		}
169
170
		BigDecimal diffMillisecondBigDecimal = new BigDecimal(diffMillisecond);
171
		BigDecimal diffMinuteBigDecimal = diffMillisecondBigDecimal.divide(new BigDecimal("60000"), 0,
172
				BigDecimal.ROUND_DOWN);
173
		BigDecimal diffHourBigDecimal = diffMinuteBigDecimal.divide(new BigDecimal("60"), 0, BigDecimal.ROUND_DOWN);
174
		BigDecimal diffdayBigDecimal = diffHourBigDecimal.divide(new BigDecimal("24"), 0, BigDecimal.ROUND_DOWN);
175
176
		int diffMinute = diffMinuteBigDecimal.subtract(diffHourBigDecimal.multiply(new BigDecimal("60"))).intValue();
177
		int diffHour = diffHourBigDecimal.subtract(diffdayBigDecimal.multiply(new BigDecimal("24"))).intValue();
178
		int diffDay = diffHourBigDecimal.subtract(diffdayBigDecimal.multiply(new BigDecimal("24"))).intValue();
179
180
		StringBuilder diffStr = new StringBuilder();
181
		if (diffDay > 0) {
182
			diffStr.append(diffDay).append("天");
183
		}
184
		if (diffHour > 0) {
185
			diffStr.append(diffHour).append("小时");
186
		}
187
		if (diffMinute > 0) {
188
			diffStr.append(diffMinute).append("分钟");
189
		}
190
191
		return diffStr.toString();
192
	}
193
}

+ 0 - 28
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/JingPingSendDateUtil.java

@ -1,9 +1,5 @@
1 1
package com.ai.ipu.server.util;
2 2
3
import java.math.BigDecimal;
4
import java.text.ParseException;
5
import java.text.SimpleDateFormat;
6
7 3
import com.ai.ipu.server.connect.ps.EventChannelTool;
8 4
import com.ai.ipu.server.connect.ps.EventChannelTool.PublisherEvent;
9 5
import com.ai.ipu.server.connect.ps.ISubscriber;
@ -38,28 +34,4 @@ public class JingPingSendDateUtil {
38 34
		};
39 35
		publisher.publish(topic, publisherEvent);
40 36
	}
41
42
	/**
43
	 * 计算两个时间相隔的分钟数(endDate-beginDate)
44
	 * @param beginDate
45
	 * @param endDate
46
	 * @return
47
	 * @throws ParseException 
48
	 */
49
	public static int getBetweenMinuteValue(String beginDate, String endDate) throws ParseException {
50
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
51
		long endDateLong = simpleDateFormat.parse(endDate).getTime();
52
		long beginDateLong = simpleDateFormat.parse(beginDate).getTime();
53
		long alarmLong = endDateLong - beginDateLong;
54
		if (alarmLong>0) {
55
			BigDecimal alarmLongBigDecimal = new BigDecimal(alarmLong);
56
			// 单位为分,四舍五入不保留小数
57
			alarmLongBigDecimal = alarmLongBigDecimal.divide(new BigDecimal("60000"), 0, BigDecimal.ROUND_HALF_UP);
58
			return alarmLongBigDecimal.intValue();
59
		}else {
60
			return 0;
61
		}
62
		
63
	}
64
65 37
}