package com.controller;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pojo.Menu;
import com.pojo.Supplier;
import com.pojo.User;
import com.service.MenuService;
import com.service.SupplierService;
import com.service.UserService;
@Controller
public class MenuController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource(name = "menuServiceImp")
MenuService menuService;
@Resource(name = "userServiceImp")
UserService userService;
@Resource(name = "supplierServiceImp")
SupplierService supplierService;
public SupplierService getSupplierService() {
return supplierService;
}
public void setSupplierService(SupplierService supplierService) {
this.supplierService = supplierService;
}
public MenuService getMenuService() {
return menuService;
}
public void setMenuService(MenuService menuService) {
this.menuService = menuService;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@RequestMapping("index")
public String getMenuListByUserId(HttpServletRequest request, User user,
String rand1) {
String rand = (String) request.getSession().getAttribute("rand");
if (rand.equals(rand1)) {
User u = userService.denglu(user);
if (u != null && u.getSign() == 0) {
List<Menu> list = menuService.getMenuListByUserId(u.getId());
System.out.println(u.getName() + u.getPwd() + u.getSign());
request.getSession().setAttribute("user", u);
request.setAttribute("username", u.getName());
request.setAttribute("list", list);
System.out.println(list.size());
} else {
request.setAttribute("mess", "账号或密码错误,请重新登录");
return "forward:index.jsp";
}
} else {
request.setAttribute("mess", "验证码错误");
return "forward:index.jsp";
}
return "index";
}
@RequestMapping("suppindex")
public String getSuppMenuListByUserId(HttpServletRequest request,
User user, String rand1) {
String rand = (String) request.getSession().getAttribute("rand");
if (rand.equals(rand1)) {
User u = userService.denglu(user);
if (u != null && u.getSign() == 1) {
List<Menu> list = menuService.getSuppMenuListByUserId();
System.out.println(list.size() + "|" + u.getId());
request.getSession().setAttribute("user", u);
request.setAttribute("username", u.getName());
request.setAttribute("list", list);
} else {
request.setAttribute("mess", "账号或密码错误,请重新登录");
return "forward:suppindex.jsp";
}
} else {
request.setAttribute("mess", "验证码错误");
return "forward:suppindex.jsp";
}
return "index";
}
@RequestMapping("invindex")
public String getInvMenuListByUserId(HttpServletRequest request, User user,
String rand1) {
String rand = (String) request.getSession().getAttribute("rand");
if (rand.equals(rand1)) {
User u = userService.denglu(user);
if (u != null && u.getSign() == 2) {
List<Menu> list = menuService.getInvMenuListByUserId();
System.out.println(list.size() + "|" + u.getId());
request.getSession().setAttribute("user", u);
request.setAttribute("username", u.getName());
request.setAttribute("list", list);
} else {
request.setAttribute("mess", "账号或密码错误,请重新登录");
return "forward:invindex.jsp";
}
} else {
request.setAttribute("mess", "验证码错误");
return "forward:invindex.jsp";
}
return "index";
}
@RequestMapping("selectSupplierBySymbol")
public String selectSupplierBySymbol(HttpServletRequest request,
Integer symbol, Integer pagenum) {
// System.out.println(pagenum+symbol);
PageHelper.startPage(pagenum == null ? 1 : pagenum, 2);
List<Supplier> supplierlist = supplierService
.selectSupplierBySymbol(symbol);
// System.out.println(supplierlist);
request.getSession().setAttribute("supplierlist", supplierlist);
request.getSession().setAttribute("pageinfo",
new PageInfo(supplierlist));
request.setAttribute("symbol", symbol);
return "forward:complain.jsp";
}
@RequestMapping("updateSymbolSuccess")
public String updateSymbolSuccess(Supplier id) {
Supplier s = supplierService.selectSupplier(id);
if (s.getSymbol() == 0 || s.getSymbol() == 2) {
s.setSymbol(s.getSymbol() + 2);
int a = supplierService.updateSymbolSuccess(s);
System.out.println(a);
}
return "forward:complain.jsp";
}
@RequestMapping("updateSymbolFailed")
public String updateSymbolFailed(Supplier id) {
Supplier s = supplierService.selectSupplier(id);
if (s.getSymbol() == 0 || s.getSymbol() == 2) {
s.setSymbol(s.getSymbol() + 1);
int a = supplierService.updateSymbolSuccess(s);
System.out.println(a);
}
return "forward:complain.jsp";
}
@RequestMapping("addblack")
public String addblack(Supplier id) {
Supplier s = supplierService.selectSupplier(id);
s.setSymbol(5);
int a = supplierService.updateSymbolSuccess(s);
return "forward:complain.jsp";
}
@RequestMapping("deleteSupplier")
public String deleteSupplier(Supplier id) {
Supplier s = supplierService.selectSupplier(id);
int a = supplierService.deleteSupplier(s);
return "forward:complain.jsp";
}
@RequestMapping("selectSupplier")
public String selectAllSupplier(HttpServletRequest request, Integer pagenum) {
PageHelper.startPage(pagenum == null ? 1 : pagenum, 3);
List<Supplier> listsup = supplierService.selectAllSupplier();
request.getSession().setAttribute("listsup", listsup);
request.getSession().setAttribute("pageinfo", new PageInfo(listsup));
return "forward:complain1.jsp";
}
@RequestMapping("updateSupplier1")
public String updateSupplier1(HttpServletRequest request, Supplier id) {
Supplier s = supplierService.selectSupplier(id);
request.getSession().setAttribute("s", s);
return "forward:updateSupplier1.jsp";
}
@RequestMapping("updateSupplier2")
public String updateSupplier2(HttpServletRequest request, Supplier id,
int upsymbol) {
Supplier s = supplierService.selectSupplier(id);
s.setSymbol(upsymbol);
int a = supplierService.updateSymbolSuccess(s);
return "forward:updateSupplier1.jsp";
}
@RequestMapping("selectAllMenu")
public String selectAllMenu(HttpServletRequest request, Integer pagenum) {
PageHelper.startPage(pagenum == null ? 1 : pagenum, 8);
List<Menu> menulist = menuService.selectAllMenu();
request.getSession().setAttribute("menulist", menulist);
request.getSession().setAttribute("pageinfo", new PageInfo(menulist));
return "forward:menulist.jsp";
}
@RequestMapping("updateMenu")
public String updateMenu(HttpServletRequest request, Menu menu) {
Menu menu1 = menuService.selectMenu(menu);
request.getSession().setAttribute("menu1", menu1);
return "forward:updateMenu.jsp";
}
@RequestMapping("updateMenu1")
public String updateMenu1(Menu id, int optionval) {
Menu menu2 = menuService.selectMenu(id);
menu2.setMenuparentid(optionval);
menuService.updateByPrimaryKeySelective(menu2);
return "forward:updateMenu.jsp";
}
@RequestMapping("insertMenu")
public String insertMenu(Menu menu) {
menuService.insertSelective(menu);
return "forward:menulist.jsp";
}
@RequestMapping("deleteMenu")
public String deleteMenu(Menu id) {
Menu m = menuService.selectMenu(id);
int a = menuService.deleteMenu(m);
return "forward:menulist.jsp";
}
@RequestMapping(