WharfController.java 2.9 KB
/**
 * 
 */
package com.thinkgem.jeesite.modules.yard.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.yard.entity.Wharf;
import com.thinkgem.jeesite.modules.yard.entity.Yard;
import com.thinkgem.jeesite.modules.yard.service.WharfService;
import com.thinkgem.jeesite.modules.yard.service.YardService;

/**
 * 码头管理Controller
 * @author promise
 * @version 2018-09-29
 */
@Controller
@RequestMapping(value = "${adminPath}/yard/wharf")
public class WharfController extends BaseController {

	@Autowired
	private WharfService wharfService;
	
	@Autowired
	private YardService yardService;
	
	@ModelAttribute
	public Wharf get(@RequestParam(required=false) String id) {
		Wharf entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = wharfService.get(id);
		}
		if (entity == null){
			entity = new Wharf();
		}
		return entity;
	}
	
	@RequiresPermissions("yard:wharf:view")
	@RequestMapping(value = {"list", ""})
	public String list(Wharf wharf, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Wharf> page = wharfService.findPage(new Page<Wharf>(request, response), wharf); 
		model.addAttribute("page", page);
		return "modules/yard/wharfList";
	}

	@RequiresPermissions("yard:wharf:view")
	@RequestMapping(value = "form")
	public String form(Wharf wharf, Model model) {
		Yard yard = new Yard();
	    List<Yard> yardList = yardService.findList(yard);
	    model.addAttribute("yardList", yardList);
		model.addAttribute("wharf", wharf);
		return "modules/yard/wharfForm";
	}

	@RequiresPermissions("yard:wharf:edit")
	@RequestMapping(value = "save")
	public String save(Wharf wharf, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, wharf)){
			return form(wharf, model);
		}
		wharfService.save(wharf);
		addMessage(redirectAttributes, "保存码头成功");
		return "redirect:"+Global.getAdminPath()+"/yard/wharf/?repage";
	}
	
	@RequiresPermissions("yard:wharf:edit")
	@RequestMapping(value = "delete")
	public String delete(Wharf wharf, RedirectAttributes redirectAttributes) {
		wharfService.delete(wharf);
		addMessage(redirectAttributes, "删除码头成功");
		return "redirect:"+Global.getAdminPath()+"/yard/wharf/?repage";
	}

}