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.Stock; import com.trade.model.Page; import com.trade.model.Suproduct; import com.trade.service.EmployeeService; import com.trade.service.ProductService; import com.trade.service.StockService; import com.trade.service.SupplierService; import com.trade.service.SuproductService; import com.trade.util.PageUtils; @Controller public class StockController { @Autowired private StockService stockService; @Autowired private SupplierService supplierService; @Autowired private SuproductService suproductService; @Autowired private EmployeeService employeeService; @Autowired private ProductService productService; @RequestMapping("queryStockBypage.do") public String queryStockBypage(Stock stock,Page page,ModelMap model){ page.setMaxRows(5); List<Stock> list = stockService.queryByStock(stock); 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<Stock> stockList = stockService.queryByList(page, stock); for(Stock s : stockList){ s.setSupplier(supplierService.queryById(s.getSupplierid())); s.setSuproduct(suproductService.queryById(s.getSuproductid())); s.setEmployee(employeeService.queryById(s.getEmployeeid())); } model.put("page", page); model.put("stockList", stockList); model.put("stock", stock); return "/stockList"; } @RequestMapping("queryStockBypage1.do") public String queryStockBypage1(Page page,ModelMap model){ Stock stock = new Stock(); page.setMaxRows(5); List<Stock> list = stockService.queryByStock(stock); 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<Stock> stockList = stockService.queryByList(page, stock); for(Stock s : stockList){ s.setSupplier(supplierService.queryById(s.getSupplierid())); s.setSuproduct(suproductService.queryById(s.getSuproductid())); s.setEmployee(employeeService.queryById(s.getEmployeeid())); } model.put("page", page); model.put("stockList", stockList); model.put("stock", stock); return "/stockList"; } @RequestMapping("addStock.do") public String addStock(Stock stock,HttpServletRequest request){ stockService.save(stock); return "redirect:/queryStockBypage.do"; } @RequestMapping("updateStock.do") public String updateStock(Stock stock, ModelMap model, HttpServletRequest request){ stock = stockService.queryById(stock.getStockid()); if(stock.getStockstatus().equals("已入库") || stock.getStockstatus() == "已入库"){ model.put("resultMessage", "进货订单已经审核"); return "forward:/queryStockBypage1.do"; } Product p = new Product(); p.setSuproductid(stock.getSuproductid()); List<Product> pList = productService.queryByProduct(p); if(pList.size() != 0){ p = pList.get(0); p.setProductnum(p.getProductnum() + stock.getStocknum()); productService.update(p); }else{ Product product = new Product(); Suproduct suproduct = suproductService.queryById(stock.getSuproductid()); product.setProductname(suproduct.getSuproductname()); product.setProductnum(stock.getStocknum()); product.setProductdesc(suproduct.getSuproductdesc()); product.setProductprice(suproduct.getSuproductprice() + 1); product.setSuproductid(suproduct.getSuproductid()); product.setProductsnum(0); productService.save(product); model.put("resultMessage", "审核成功"); } stock.setStockstatus("已入库"); stockService.update(stock); return "forward:/queryStockBypage1.do"; } @RequestMapping("deleteStockByid.do") public String deleteStockByid(Stock stock, ModelMap model){ stock = stockService.queryById(stock.getStockid()); if(stock.getStockstatus().equals("待审核") || stock.getStockstatus() == "待审核"){ stockService.deleteById(stock.getStockid()); model.put("resultMessage", "删除成功"); }else if(stock.getStockstatus().equals("已入库") || stock.getStockstatus() == "已入库"){ model.put("resultMessage", "该订货单已入库,不能删除"); } return "forward:/queryStockBypage1.do"; } }
最近下载更多