首页>代码>SSM网上购物商城系统>/shop/src/com/shop/controller/AdminController.java
package com.shop.controller;

import java.io.File;
import java.util.Date;
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.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.shop.Utils.PageBean;
import com.shop.Utils.UUIDUtiils;
import com.shop.po.Adminuser;
import com.shop.po.Category;
import com.shop.po.Categorysecond;
import com.shop.po.Message;
import com.shop.po.Orders;
import com.shop.po.Product;
import com.shop.po.User;
import com.shop.service.CategorySecondService;
import com.shop.service.CategoryService;
import com.shop.service.MessageService;
import com.shop.service.OrderService;
import com.shop.service.ProductService;
import com.shop.service.UserService;


@Controller
public class AdminController {
	@Autowired
	private UserService userService;
	@Autowired
	public CategoryService categoryService;
	@Autowired
	public CategorySecondService categorySecondService;
	@Autowired
	public ProductService productService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private MessageService messageService;

	@RequestMapping("/admin/admin_findAll")
	public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		List<User> userList = userService.admin_findAll();
		model.addAttribute("userList", userList);
		return "admin/user/list";
	}

	@RequestMapping("/admin/adminCategory_findAll")
	public String adminCategory_findAll(Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		List<Category> categoryList = categoryService.adminbFindCategory();
		/*for (Category category : categoryList) {
			System.out.println(category.getCname());
		}*/
		model.addAttribute("categoryList", categoryList);
		return "admin/category/list";
	}

	@RequestMapping("/admin/adminCategory_add")
	public String adminCategory_add(Model model,HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
//		List<Category> categoryList = categoryService.adminbFindCategory();
//		model.addAttribute("categoryList", categoryList);
		return "admin/category/add";
	}

	@RequestMapping("/admin/adminCategory_save")
	public String adminCategory_save(@RequestParam String cname,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Category addCategory = new Category();
		addCategory.setCname(cname);
		categoryService.addCategory(addCategory);
		return "redirect:/admin/adminCategory_findAll.action";
	}

	@RequestMapping("/admin/adminCategory_edit")
	public String adminCategory_delete(@RequestParam int cid, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Category existCategory = categoryService.findCategory(cid);
		model.addAttribute("existCategory", existCategory);
		return "admin/category/edit";
	}

	@RequestMapping("/admin/adminCategory_update")
	public String adminCategory_update(@RequestParam int cid,
			@RequestParam String cname,HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Category category = new Category();
		category.setCid(cid);
		category.setCname(cname);
		categoryService.adminCategory_update(category);
		return "redirect:/admin/adminCategory_findAll.action";
	}

	@RequestMapping("/admin/adminCategory_delete")
	public String adminCategory_delete(@RequestParam int cid,HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		categorySecondService.adminCategorySecond_deleteByCid(cid);
		categoryService.deleteCategoryByCid(cid);
		return "redirect:/admin/adminCategory_findAll.action";
	}

	// admin 的二级分类的管理
	@RequestMapping("/admin/adminCategorySecond_findAllByPage")
	public String adminCategorySecond_findAllByPage(@RequestParam int page,Model model,HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Categorysecond> csPageBean = categorySecondService
				.adminCategorySecond_findAllByPage(page);
		/*List<Categorysecond> list = csPageBean.getList();
		for (Categorysecond categorysecond : list) {
			System.out.println(categorysecond.getCsname());
		}*/
		model.addAttribute("csPageBean", csPageBean);
		return "admin/categorysecond/list";
	}
	@RequestMapping("admin/adminCategorySecond_addPage")
	public String adminCategorySecond_addPage(Model model,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		List<Category> categoryList = categoryService.adminbFindCategory();
		model.addAttribute("categoryList", categoryList);
		return "admin/categorysecond/add";
	}
	@RequestMapping("admin/adminCategorySecond_save")
	public String adminCategorySecond_save(@RequestParam String csname,@RequestParam int cid,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Categorysecond categorysecond = new Categorysecond();
		categorysecond.setCsname(csname);
		categorysecond.setCid(cid);
		categorySecondService.adminCategorySecond_save(categorysecond);
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}
	@RequestMapping("admin/adminCategorySecond_edit")
	public String adminCategorySecond_edit(@RequestParam int csid,Model model,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Categorysecond findByCsid = categorySecondService.findByCsid(csid);
		model.addAttribute("findByCsid", findByCsid);
		return "admin/categorysecond/edit";
	}
	@RequestMapping("admin/adminCategorySecond_update")
	public String adminCategorySecond_update(@RequestParam String csname,@RequestParam int csid,HttpServletRequest request){
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Categorysecond categorysecond = new Categorysecond();
		categorysecond.setCsname(csname);
		categorysecond.setCsid(csid);
		categorySecondService.adminCategorySecond_update(categorysecond);
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}
	@RequestMapping("admin/adminCategorySecond_delete")
	public String adminCategorySecond_delete(@RequestParam int csid,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		categorySecondService.adminCategorySecond_delete(csid);
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}
	//admin的商品管理
	@RequestMapping("/admin/adminProduct_findAllByPage")
	public String adminProduct_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Product> allProPageBean = productService.findAllProduct(page);
		model.addAttribute("allProPageBean", allProPageBean);
		return "admin/product/list";
	}

	@RequestMapping("/admin/adminProduct_addPage")
	public String adminProduct_addPage(Model model,HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		//查询出所有的二级分类
		List<Categorysecond> cslist = categorySecondService.findAll();
		/*for (Categorysecond categorysecond : cslist) {
			System.out.println(categorysecond.getCsname());
		}*/
		model.addAttribute("cslist", cslist);
		return "admin/product/add";
	}

	@RequestMapping("/admin/adminProduct_save")
	public String adminProduct_save(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		product.setPdate(new Date());
//		上传图片
		if (file != null) {
			String path = request.getServletContext().getRealPath(
					"/products");
			String uploadFileName = file.getOriginalFilename();
			String fileName = UUIDUtiils.getUUID()+uploadFileName;
			File diskFile = new File(path + "//" + fileName);
			file.transferTo(diskFile);
			product.setImage("products/" + fileName);
		}
		System.out.println(product.getImage());
		productService.adminProduct_save(product);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}
	
	@RequestMapping("admin/adminProduct_deletecs")
	public String adminProduct_deletecs(@RequestParam int pid,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		productService.adminProduct_deletecs(pid);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}
	/**
	 * 编辑商品
	 * 
	 * @param pid
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("admin/adminProduct_edit")
	public String adminProduct_edit(@RequestParam int pid,Model model,HttpServletRequest request) throws Exception{
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		Product product = productService.finbProductByPid(pid);
		model.addAttribute("findByPid", product);
		//查询出所有的二级分类
		List<Categorysecond> cslist = categorySecondService.findAll();
		model.addAttribute("cslist", cslist);
		return "admin/product/edit";
	}
	
	@RequestMapping("/admin/adminProduct_update")
	public String adminProduct_update(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		product.setPdate(new Date());
//		上传图片
		if (file != null) {
			String path = request.getServletContext().getRealPath(
					"/products");
			String uploadFileName = file.getOriginalFilename();
			String fileName = UUIDUtiils.getUUID()+uploadFileName;
			File diskFile = new File(path + "//" + fileName);
			file.transferTo(diskFile);
			product.setImage("products/" + fileName);
		}
		 
		productService.adminProduct_update(product);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}

	/** 订单管理模块  **/
	
	@RequestMapping("/admin/adminOrder_findAllByPage")
	public String adminOrder_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(page);
		model.addAttribute("pageBean", allProPageBean);
		return "admin/order/list";
	}
	
	//adminOrder_findByState
	@RequestMapping("/admin/adminOrder_findByState")
	public String adminOrder_findByState(@RequestParam int page,@RequestParam int state, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(state,page);
		model.addAttribute("pageBean", allProPageBean);
		return "admin/order/list";
	}
	
	//订单详情
	//adminOrder_findOrderItem
	@RequestMapping("/admin/adminOrder_findOrderItem")
	public String adminOrder_findOrderItem(@RequestParam int oid, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		Orders orderItems = orderService.findOrderByOid(oid);
		model.addAttribute("orderItems", orderItems);
		return "admin/order/list";
	}
	
	//更新订单状态
	@RequestMapping("/admin/adminOrder_updateState")
	public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		orderService.updateOrderStatus(oid, status);
		
		return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
	}
	
	//后台留言管理 
	@RequestMapping("/admin/adminMessage_findAllByPage")
	public String adminMessage_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
		model.addAttribute("pageBean", pageBean);
		
		return "admin/message/list";
	}
	
	@RequestMapping("/admin/adminMessage_delete")
	public String adminOrder_updateState(@RequestParam int messageid, Model model,HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if(adminuserLogin==null){
			request.getSession().setAttribute("message","对不起您还没有登录");
			return "admin/index";
		}
		
		messageService.deleteMessage(messageid);
		
		return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
	}

}
最近下载更多
lyt010628  LV4 7月9日
3038169233  LV1 7月5日
TY0165  LV20 6月25日
樱花味小然子  LV5 6月21日
lilitu  LV6 5月30日
sunlea  LV20 5月12日
gcr666  LV1 5月8日
gdt234  LV4 4月22日
wzy100007 4月6日
暂无贡献等级
最近浏览更多
暂无贡献等级
hmdzmsl12  LV2 11月10日
lqzixi  LV4 11月6日
暂无贡献等级
krispeng  LV13 10月28日
big_goose 10月21日
暂无贡献等级
zsQWEQ 10月18日
暂无贡献等级
linhua  LV1 10月11日
angaochong  LV5 10月10日
672197082 9月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友