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.Custom; import com.trade.model.Page; import com.trade.model.Sales; import com.trade.service.CustomService; import com.trade.service.SalesService; import com.trade.util.PageUtils; @Controller public class CustomController { @Autowired private CustomService customService; @Autowired private SalesService salesService; @RequestMapping("queryCustomBypage.do") public String queryCustomBypage(Custom custom,Page page,ModelMap model){ page.setMaxRows(5); List<Custom> list = customService.queryByCustom(custom); 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<Custom> customList = customService.queryByList(page, custom); model.put("page", page); model.put("customList", customList); model.put("custom", custom); return "/customList"; } @RequestMapping("queryCustomBypage1.do") public String queryCustomBypage1(Page page,ModelMap model){ Custom custom = new Custom(); page.setMaxRows(5); List<Custom> list = customService.queryByCustom(custom); 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<Custom> customList = customService.queryByList(page, custom); model.put("page", page); model.put("customList", customList); model.put("custom", custom); return "/customList"; } @RequestMapping("addCustom.do") public String addCustom(Custom custom,HttpServletRequest request){ customService.save(custom); return "redirect:/queryCustomBypage.do"; } @RequestMapping("editCustom.do") public String editCustom(Custom custom,ModelMap model){ custom = customService.queryById(custom.getCustomid()); model.put("custom", custom); return "/custom_edit"; } @RequestMapping("updateCustom.do") public String updateCustom(Custom custom,HttpServletRequest request){ customService.update(custom); return "redirect:/queryCustomBypage.do"; } @RequestMapping("deleteCustomByid.do") public String deleteCustomByid(Custom custom, ModelMap model){ Sales sales = new Sales(); sales.setCustomid(custom.getCustomid()); List<Sales> salesList = salesService.queryBySales(sales); if(salesList.size() != 0){ model.put("resultMessage", "客户有关联的销售订单,不能删除"); }else{ customService.deleteById(custom.getCustomid()); model.put("resultMessage", "删除成功"); } return "forward:/queryCustomBypage1.do"; } }
