Commit 058d0e1a by 高鹏

Merge branch 'mymaster' into 'master'

C1000805_微信群群发支持计划式多次发送,增加时间判断2

See merge request rays/pcloud-book!17
parents 39e255c3 f41dc6cf
......@@ -12,6 +12,7 @@ import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -46,6 +47,7 @@ public class PushCheck {
if (push.getStartTime() != null && push.getEndTime() != null && push.getStartTime().getTime() - push.getEndTime().getTime() > 0) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "开始时间必须在结束时间之前!");
}
checkHasDayToSend(push);
if (ListUtils.isEmpty(push.getPushGroups())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "发送群不能为空!");
}
......@@ -99,6 +101,56 @@ public class PushCheck {
}
/**
* 校验时间有效性
*/
private void checkHasDayToSend(Push push) {
if (push.getStartTime() != null && push.getEndTime() != null) {
if (PushTypeEnum.DAY.value.equals(push.getPushType())) {
Date endTime = push.getEndTime();
Date now = new Date();
String pushTime = push.getPushTime();
if (DateUtils.getDayStart(endTime).getTime() == DateUtils.getDayStart(now).getTime()) {
if (DateUtils.getDateFromString(pushTime, "HH:mm:ss").getTime()
< DateUtils.getDateFromString(DateUtils.getStrFormTime("HH:mm:ss", new Date()), "HH:mm:ss").getTime()) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "时间填写错误,没有有效的群发时间,请重新选取!");
}
}
}
if (PushTypeEnum.WEEK.value.equals(push.getPushType()) && push.getWeekDay() != null && push.getEndTime() != null) {
Date endDay = push.getEndTime();
Integer weekDay = push.getWeekDay();
String pushTime = push.getPushTime();
if (weekDay == 7) {
weekDay = 1;
} else {
weekDay = weekDay + 1;
}
List<String> list = new ArrayList<>();
for (Date i = new Date(); !i.after(endDay); i = DateUtils.addDay(i, 1)) {
if (weekDay == DateUtils.getWeekIndex(i)) {
list.add(DateUtils.formatDate(i, "yyyy-MM-dd"));
}
}
if (ListUtils.isEmpty(list)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "时间填写错误,没有有效的群发时间,请重新选取!");
}
if (list.size() == 1) {
String s = list.get(0);
Date date1 = DateUtils.getDateFromString(s, "yyyy-MM-dd");
date1 = DateUtils.addHour(date1, new Integer(pushTime.substring(0, 2)));
date1 = DateUtils.addMinute(date1, new Integer(pushTime.substring(3, 5)));
date1 = DateUtils.addMinute(date1, new Integer(pushTime.substring(6, 8)));
Long sl = date1.getTime();
Long sll = new Date().getTime();
if (sl < sll) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "时间填写错误,没有有效的群发时间,请重新选取!");
}
}
}
}
}
/**
* 校验时间
*
* @param push
......
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