Parcourir la source

Merge branch 'master' of http://git.iamberry.com/wangxiaoming/iamberry-watero

wangxiaoming il y a 6 ans
Parent
commit
ff48969dcd

+ 47 - 4
watero-common-tool/src/main/java/com/iamberry/wechat/tools/DateTimeUtil.java

@@ -689,8 +689,6 @@ public class DateTimeUtil {
     
     /** 
      * 两个时间相差距离多少分钟
-     * @param Date1
-     * @param Date2
      * @return long 返回值为:分钟数
      */  
     public static long getDiffTimeMinutes(Date one, Date two) {  
@@ -718,8 +716,6 @@ public class DateTimeUtil {
     
     /** 
      * 两个时间相差距离多少毫秒数
-     * @param Date1
-     * @param Date2
      * @return String 返回值为:多少毫秒的字符串
      */  
     public static String getDistanceTime2(Date nowDate, Date endDate) { 
@@ -735,4 +731,51 @@ public class DateTimeUtil {
              }  */
     	return String.valueOf(diff);
     }
+
+    /**
+     * 判断某一时间是否在一个区间内
+     *
+     * @param sourceTime
+     *            时间区间,半闭合,如[10:00-20:00)
+     * @param curTime
+     *            需要判断的时间 如10:00
+     * @return
+     * @throws IllegalArgumentException
+     */
+    public static boolean isInTime(String sourceTime, String curTime) {
+        if (sourceTime == null || !sourceTime.contains("-") || !sourceTime.contains(":")) {
+            throw new IllegalArgumentException("Illegal Argument arg:" + sourceTime);
+        }
+        if (curTime == null || !curTime.contains(":")) {
+            throw new IllegalArgumentException("Illegal Argument arg:" + curTime);
+        }
+        String[] args = sourceTime.split("-");
+        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
+        try {
+            long now = sdf.parse(curTime).getTime();
+            long start = sdf.parse(args[0]).getTime();
+            long end = sdf.parse(args[1]).getTime();
+            if (args[1].equals("00:00")) {
+                args[1] = "24:00";
+            }
+            if (end < start) {
+                if (now >= end && now < start) {
+                    return false;
+                } else {
+                    return true;
+                }
+            }
+            else {
+                if (now >= start && now < end) {
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+            throw new IllegalArgumentException("Illegal Argument arg:" + sourceTime);
+        }
+
+    }
 }

+ 27 - 1
watero-wechat-service/src/main/java/com/iamberry/wechat/service/wechat/WeChatServiceImpl.java

@@ -117,7 +117,7 @@ public class WeChatServiceImpl implements WeChatService {
 			textMessage.setToUserName(fromUserName);
 			textMessage.setFromUserName(toUserName);
 			textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
-			
+
 			//多客服处理
 			String intxml = "<xml>"+
 					"<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>" +
@@ -253,6 +253,32 @@ public class WeChatServiceImpl implements WeChatService {
 		return respMessage;
 	}
 
+	//判断当前是否是工作时间
+	public boolean isWorkingDays(){
+		//是否在工作时间内
+		boolean istf = false;
+		Date today = new Date();
+		Calendar c=Calendar.getInstance();
+		c.setTime(today);
+		int weekday=c.get(Calendar.DAY_OF_WEEK);
+		//获取当前时分
+		SimpleDateFormat format = new SimpleDateFormat("HH:mm");
+		Date date = new Date();
+		String currentDate = format.format(date);
+		//1=周日 2=周一...7=周六
+		if(weekday > 1 & weekday < 6){//周一到周五
+			String date1 = "09:00-22:00";
+			istf = DateTimeUtil.isInTime(date1,currentDate);
+		}else{
+			String date1 = "09:00-18:00";
+			istf = DateTimeUtil.isInTime(date1,currentDate);
+		}
+		//判断午休时间
+		String date2 = "12:30-14:00";
+		istf = DateTimeUtil.isInTime(date2,currentDate);
+		return istf;
+	}
+
 	/**
 	 * 扫码进入赠送礼品信息页面(已关注)
 	 * @param requestMap