package com.asiainfo.vdsp.cms.web.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.asiainfo.vdsp.cms.domain.Event;
import com.asiainfo.vdsp.cms.domain.StatVote;
import com.asiainfo.vdsp.cms.domain.Viewpoint;
import com.asiainfo.vdsp.exception.ApplicationException;
import com.asiainfo.vdsp.subsys.common.datatype.bean.UserToken;
import com.asiainfo.vdsp.subsys.vnet.service.remote.common.CommonServiceBasedUtil;
import com.asiainfo.vdsp.subsys.vnet.service.remote.common.CommonServiceRemote;
@Controller
public class VoteController extends BaseController {
@Autowired
private CommonServiceRemote commonService;
@RequestMapping("/getVote.htm")
public void getVote(HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap)
throws ServletException, IOException, ApplicationException {
String eventName = "";
if (request.getParameter("eventName") == null) {
if(request.getAttribute("eventName")!=null)
{
eventName = request.getAttribute("eventName").toString();
}
} else {
eventName = request.getParameter("eventName");
}
Event event = this.cmsServiceForSite.findEventByName(eventName);
if (event == null) {
request.setAttribute("errMessage", "问卷名称不存在");
}
List<Viewpoint> list = event.getViewpoints();
// modelMap.addAttribute("viewpoint", list);
// modelMap.addAttribute("event",event);
// System.out.println(" event.getId():"+event.getId());
// modelMap.addAttribute("eventId", event.getId());
request.setAttribute("viewpoint", list);
request.setAttribute("event",event);
StringBuilder sb = new StringBuilder();
sb.append("/cms/").append(event.getVnetPage().getFileName());
request.getRequestDispatcher(sb.toString()).forward(request,
response);
}
@RequestMapping("/vote.htm")
public void vote(@RequestParam("eventId")
String eventId, @RequestParam("viewpointId")
String viewpointId, HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap)
throws ServletException, IOException, ApplicationException {
Event event = this.cmsServiceForSite.findEventById(Long
.valueOf(eventId));
try {
UserToken userToken = CommonServiceBasedUtil
.parseUserTokenFromCookie(request, commonService);
Long vnetUserId = null;
if (userToken != null) {
vnetUserId = Long.valueOf(userToken.getUserID());
}
String clientIp = request.getRemoteAddr();
String[] temp = viewpointId.split(",");
this.cmsServiceForSite.submitVote(Long.valueOf(eventId), temp,
clientIp, vnetUserId);
request.setAttribute("message", "投票成功,谢谢您的参与");
} catch (ApplicationException e) {
e.printStackTrace();
request.setAttribute("message", e.getMessage());
}
request.setAttribute("eventName", event.getName());
this.getVote(request, response, modelMap);
}
@RequestMapping("/checkVote.htm")
public String checkVoteResult(@RequestParam("eventId")
String eventId, HttpServletRequest request, HttpServletResponse response,
ModelMap modelMap) throws NumberFormatException,
ApplicationException {
List<StatVote> list = this.cmsServiceForSite.findVoteResult(Long
.valueOf(eventId));
Event event = this.cmsServiceForSite.findEventById(Long
.valueOf(eventId));
modelMap.addAttribute("voteList", list);
modelMap.addAttribute("desc", event.getDescription());
return "/vote/voteResult";
}
}
package com.asiainfo.vdsp.cms.web.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import com.asiainfo.vdsp.cms.service.CmsServiceForSite;
@Controller
public class BaseController {
@Autowired
@Qualifier("dateFormat")
protected String dateFormat;
@Autowired
protected CmsServiceForSite cmsServiceForSite;
}
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.asiainfo.vdsp.cms.domain.Event;
import com.asiainfo.vdsp.cms.domain.StatVote;
import com.asiainfo.vdsp.cms.domain.Viewpoint;
import com.asiainfo.vdsp.exception.ApplicationException;
import com.asiainfo.vdsp.subsys.common.datatype.bean.UserToken;
import com.asiainfo.vdsp.subsys.vnet.service.remote.common.CommonServiceBasedUtil;
import com.asiainfo.vdsp.subsys.vnet.service.remote.common.CommonServiceRemote;
@Controller
public class VoteController extends BaseController {
@Autowired
private CommonServiceRemote commonService;
@RequestMapping("/getVote.htm")
public void getVote(HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap)
throws ServletException, IOException, ApplicationException {
String eventName = "";
if (request.getParameter("eventName") == null) {
if(request.getAttribute("eventName")!=null)
{
eventName = request.getAttribute("eventName").toString();
}
} else {
eventName = request.getParameter("eventName");
}
Event event = this.cmsServiceForSite.findEventByName(eventName);
if (event == null) {
request.setAttribute("errMessage", "问卷名称不存在");
}
List<Viewpoint> list = event.getViewpoints();
// modelMap.addAttribute("viewpoint", list);
// modelMap.addAttribute("event",event);
// System.out.println(" event.getId():"+event.getId());
// modelMap.addAttribute("eventId", event.getId());
request.setAttribute("viewpoint", list);
request.setAttribute("event",event);
StringBuilder sb = new StringBuilder();
sb.append("/cms/").append(event.getVnetPage().getFileName());
request.getRequestDispatcher(sb.toString()).forward(request,
response);
}
@RequestMapping("/vote.htm")
public void vote(@RequestParam("eventId")
String eventId, @RequestParam("viewpointId")
String viewpointId, HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap)
throws ServletException, IOException, ApplicationException {
Event event = this.cmsServiceForSite.findEventById(Long
.valueOf(eventId));
try {
UserToken userToken = CommonServiceBasedUtil
.parseUserTokenFromCookie(request, commonService);
Long vnetUserId = null;
if (userToken != null) {
vnetUserId = Long.valueOf(userToken.getUserID());
}
String clientIp = request.getRemoteAddr();
String[] temp = viewpointId.split(",");
this.cmsServiceForSite.submitVote(Long.valueOf(eventId), temp,
clientIp, vnetUserId);
request.setAttribute("message", "投票成功,谢谢您的参与");
} catch (ApplicationException e) {
e.printStackTrace();
request.setAttribute("message", e.getMessage());
}
request.setAttribute("eventName", event.getName());
this.getVote(request, response, modelMap);
}
@RequestMapping("/checkVote.htm")
public String checkVoteResult(@RequestParam("eventId")
String eventId, HttpServletRequest request, HttpServletResponse response,
ModelMap modelMap) throws NumberFormatException,
ApplicationException {
List<StatVote> list = this.cmsServiceForSite.findVoteResult(Long
.valueOf(eventId));
Event event = this.cmsServiceForSite.findEventById(Long
.valueOf(eventId));
modelMap.addAttribute("voteList", list);
modelMap.addAttribute("desc", event.getDescription());
return "/vote/voteResult";
}
}
package com.asiainfo.vdsp.cms.web.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import com.asiainfo.vdsp.cms.service.CmsServiceForSite;
@Controller
public class BaseController {
@Autowired
@Qualifier("dateFormat")
protected String dateFormat;
@Autowired
protected CmsServiceForSite cmsServiceForSite;
}