package com.skyline.wo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.skyline.base.exception.NoResourceException;
import com.skyline.common.util.Constant;
import com.skyline.common.util.ViewPaths;
import com.skyline.common.util.WebHelper;
import com.skyline.user.model.User;
import com.skyline.user.service.PersonalInfoService;
@Controller
@RequestMapping("/wo")
public class WoController {
// private static final Log LOGGER = LogFactory.getLog(WoController.class);
// @Value("${view.wo.myWo}")
// private String myWoView;
//
// @Value("${view.user.login}")
// private String loginView;
//
// @Value("${view.wo.wo}")
// private String woView;
@Autowired
private PersonalInfoService personalInfoService;
@RequestMapping(value = "/myWo", method = RequestMethod.GET)
public ModelAndView myWo() {
ModelAndView mav = new ModelAndView();
User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
if (user == null || user.getId() == 0) {
/*
* throw new NotLoginException();
* 似乎在很多情况下都不能使用NotLoginException,不然的话,会在我们的系统中输出过多的这类异常
*/
mav.setViewName(ViewPaths.USER_LOGIN);
} else {
mav.setViewName(ViewPaths.WO_MYWO);
mav.addObject("woOwner", user);
}
return mav;
}
@RequestMapping(value = "/{ownerId}", method = RequestMethod.GET)
public ModelAndView wo(@PathVariable long ownerId) {
ModelAndView mav = new ModelAndView();
User user = (User) personalInfoService.getPersonInfoByUserID(ownerId);
if (user == null) {
throw new NoResourceException();
} else {
mav.setViewName(ViewPaths.WO_WO);
mav.addObject("woOwner", user);
}
return mav;
}
}