if (itemIds == null || itemIds.length <= 0) {
model.addAttribute("status", 2);
return true;
}
CmsVoteTopic topic = cmsVoteTopicMng.findById(topicId);
// 投票主题不存在
if (topic == null) {
model.addAttribute("status", 100);
return true;
}
// 投票项不合法
boolean contains;
for (Integer itemId : itemIds) {
contains = false;
for (CmsVoteItem item : topic.getItems()) {
if (item.getId().equals(itemId)) {
contains = true;
break;
}
}
if (!contains) {
model.addAttribute("status", 101);
return true;
}
}
// 需要登录才能投票
if (topic.getRestrictMember() && user == null) {
model.addAttribute("status", 501);
return true;
}
// 投票主题已经关闭
if (topic.getDisabled()) {
model.addAttribute("status", 200);
return true;
}
// 投票的选项个数大于允许的个数
if (itemIds.length > topic.getMultiSelect()) {
model.addAttribute("status", 201);
return true;
}
long now = System.currentTimeMillis();
// 投票还没有开始
Date start = topic.getStartTime();
if (start != null && now < start.getTime()) {
model.addAttribute("status", 202);
model.addAttribute("startTime", start);
return true;
}
// 投票已经结束
Date end = topic.getEndTime();
if (end != null && now > end.getTime()) {
model.addAttribute("status", 203);
model.addAttribute("endTime", end);
return true;
}
Integer hour = topic.getRepeateHour();
if (hour == null || hour > 0) {
Date vtime;
// 规定时间内,同一会员不能重复投票
if (topic.getRestrictMember()) {
vtime = cmsVoteRecordMng.lastVoteTimeByUserId(user.getId(),
topicId);
if (hour == null
|| vtime.getTime() + hour * 60 * 60 * 1000 > now) {
model.addAttribute("status", 204);
return true;
}
}
// 规定时间内,同一IP不能重复投票
if (topic.getRestrictIp()) {
vtime = cmsVoteRecordMng.lastVoteTimeByIp(ip, topicId);
if (hour == null
|| vtime.getTime() + hour * 60 * 60 * 1000 > now) {
model.addAttribute("status", 205);
return true;
}
}
// 规定时间内,同一COOKIE不能重复投票
if (topic.getRestrictCookie() && cookie != null) {
vtime = cmsVoteRecordMng.lastVoteTimeByCookie(cookie, topicId);
if (hour == null
|| vtime.getTime() + hour * 60 * 60 * 1000 > now) {
model.addAttribute("status", 206);
return true;