package com.trade.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; 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 com.trade.model.Employee; import com.trade.model.Page; import com.trade.model.Sales; import com.trade.model.Stock; import com.trade.service.EmployeeService; import com.trade.service.SalesService; import com.trade.service.StockService; import com.trade.util.PageUtils; @Controller public class EmployeeController { @Autowired private EmployeeService employeeService; @Autowired private SalesService salesService; @Autowired private StockService stockService; @RequestMapping("queryEmployeeBypage.do") public String queryEmployeeBypage(Employee employee,Page page,ModelMap model){ page.setMaxRows(5); List<Employee> list = employeeService.queryByEmployee(employee); page.setStart(PageUtils.getPage(page.getPageNumber(), page.getTotalPage(), list.size(), page.getMaxRows())); page.setTotalPage(PageUtils.getTotalPage(page.getPageNumber(), page.getTotalPage(), list.size(), page.getMaxRows())); List<Employee> employeeList = employeeService.queryByList(page, employee); model.put("page", page); model.put("employeeList", employeeList); model.put("employee", employee); return "/empList"; } @RequestMapping("queryEmployeeBypage1.do") public String queryEmployeeBypage1(Page page,ModelMap model){ Employee employee = new Employee(); page.setMaxRows(5); List<Employee> list = employeeService.queryByEmployee(employee); page.setStart(PageUtils.getPage(page.getPageNumber(), page.getTotalPage(), list.size(), page.getMaxRows())); page.setTotalPage(PageUtils.getTotalPage(page.getPageNumber(), page.getTotalPage(), list.size(), page.getMaxRows())); List<Employee> employeeList = employeeService.queryByList(page, employee); model.put("page", page); model.put("employeeList", employeeList); model.put("employee", employee); return "/empList"; } @RequestMapping("addEmployee.do") public String addEmployee(Employee employee,HttpServletRequest request){ employeeService.save(employee); return "redirect:/queryEmployeeBypage.do"; } @RequestMapping("updateEmployee.do") public String updateEmployee(Employee employee,HttpServletRequest request){ employeeService.update(employee); return "redirect:/queryEmployeeBypage.do"; } @RequestMapping("deleteEmployeeByid.do") public String deleteEmployeeByid(Employee employee, ModelMap model){ employee = employeeService.queryById(employee.getEmployeeid()); if(employee.getEmployeerole().equals(1)){ model.put("resultMessage", "管理员不能删除"); }else{ Sales sales = new Sales(); sales.setEmployeeid(employee.getEmployeeid()); Stock stock = new Stock(); stock.setEmployeeid(employee.getEmployeeid()); if(salesService.queryBySales(sales).size() !=0 || stockService.queryByStock(stock).size() !=0){ model.put("resultMessage", "员工有正在操作的订单,不能删除"); }else{ employeeService.deleteById(employee.getEmployeeid()); model.put("resultMessage", "删除成功"); } } return "forward:/queryEmployeeBypage1.do"; } @RequestMapping("login.do") public String login(Employee employee, HttpSession session,ModelMap model){ if(employee.getEmployeename().equals("") || employee.getEmployeepass().equals("")){ model.put("resultMessage", "用户名和密码不能为空"); return "index"; } List<Employee> emplList = employeeService.queryByEmployee(employee); if(emplList.size() > 0){ employee = emplList.get(0); session.setAttribute("emp", employee); return "main"; }else{ model.put("resultMessage", "用户名或密码错误"); return "index"; } } @RequestMapping("logout.do") public String logout(HttpSession session,ModelMap model){ session.invalidate(); return "index"; } }
最近下载更多