package com.trade.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; 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.Product; import com.trade.model.Sales; import com.trade.model.Page; import com.trade.service.CustomService; import com.trade.service.EmployeeService; import com.trade.service.ProductService; import com.trade.service.SalesService; import com.trade.util.PageUtils; @Controller public class SalesController { @Autowired private SalesService salesService; @Autowired private CustomService customService; @Autowired private ProductService productService; @Autowired private EmployeeService employeeService; @RequestMapping("querySalesBypage.do") public String querySalesBypage(Sales sales,Page page,ModelMap model){ page.setMaxRows(5); List<Sales> list = salesService.queryBySales(sales); 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<Sales> salesList = salesService.queryByList(page, sales); for(Sales s : salesList){ s.setCustom(customService.queryById(s.getCustomid())); s.setProduct(productService.queryById(s.getProductid())); s.setEmployee(employeeService.queryById(s.getEmployeeid())); } model.put("page", page); model.put("salesList", salesList); model.put("sales", sales); return "/salesList"; } @RequestMapping("querySalesBypage1.do") public String querySalesBypage1(Page page,ModelMap model){ Sales sales = new Sales(); page.setMaxRows(5); List<Sales> list = salesService.queryBySales(sales); 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<Sales> salesList = salesService.queryByList(page, sales); for(Sales s : salesList){ s.setCustom(customService.queryById(s.getCustomid())); s.setProduct(productService.queryById(s.getProductid())); s.setEmployee(employeeService.queryById(s.getEmployeeid())); } model.put("page", page); model.put("salesList", salesList); model.put("sales", sales); return "/salesList"; } @RequestMapping("addSales.do") public String addSales(Sales sales,HttpServletRequest request){ salesService.save(sales); return "redirect:/querySalesBypage.do"; } @RequestMapping("updateSales.do") public String updateSales(Sales sales,ModelMap model,HttpServletRequest request){ sales = salesService.queryById(sales.getSalesid()); if(sales.getSalesstatus().equals("待审核") || sales.getSalesstatus() == "待审核"){ sales.setSalesstatus("已销售"); salesService.update(sales); model.put("resultMessage", "审核成功"); }else if(sales.getSalesstatus().equals("已销售") || sales.getSalesstatus() == "已销售"){ model.put("resultMessage", "销售订单已经审核"); } return "forward:/querySalesBypage1.do"; } @RequestMapping("deleteSalesByid.do") public String deleteSalesByid(Sales sales, ModelMap model){ sales = salesService.queryById(sales.getSalesid()); if(sales.getSalesstatus().equals("待审核") || sales.getSalesstatus() == "待审核"){ Product product = productService.queryById(sales.getProductid()); product.setProductnum(product.getProductnum() + sales.getSalesnum()); product.setProductsnum(product.getProductsnum() - sales.getSalesnum()); productService.update(product); // System.out.println(product); salesService.deleteById(sales.getSalesid()); model.put("resultMessage", "删除成功"); }else if(sales.getSalesstatus().equals("已销售") || sales.getSalesstatus() == "已销售"){ model.put("resultMessage", "该销售单已审核,不能删除"); } return "forward:/querySalesBypage1.do"; } }
最近下载更多