/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.pline.web.wind;

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.pline.entity.wind.PlineWind;
import com.thinkgem.jeesite.modules.pline.service.wind.PlineWindService;

/**
 * 风场管理Controller
 * @author GJ
 * @version 2017-08-09
 */
@Controller
@RequestMapping(value = "${adminPath}/pline/wind/plineWind")
public class PlineWindController extends BaseController {

	@Autowired
	private PlineWindService plineWindService;
	
	@ModelAttribute
	public PlineWind get(@RequestParam(required=false) String id) {
		PlineWind entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = plineWindService.get(id);
		}
		if (entity == null){
			entity = new PlineWind();
		}
		return entity;
	}
	
	@RequiresPermissions("pline:wind:plineWind:view")
	@RequestMapping(value = {"list", ""})
	public String list(PlineWind plineWind, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PlineWind> page = plineWindService.findPage(new Page<PlineWind>(request, response), plineWind); 
		model.addAttribute("page", page);
		return "modules/pline/wind/plineWindList";
	}

	@RequiresPermissions("pline:wind:plineWind:view")
	@RequestMapping(value = "form")
	public String form(PlineWind plineWind, Model model) {
		model.addAttribute("plineWind", plineWind);
		return "modules/pline/wind/plineWindForm";
	}

	@RequiresPermissions("pline:wind:plineWind:edit")
	@RequestMapping(value = "save")
	public String save(PlineWind plineWind, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, plineWind)){
			return form(plineWind, model);
		}
		plineWindService.save(plineWind);
		addMessage(redirectAttributes, "保存风场管理成功");
		return "redirect:"+Global.getAdminPath()+"/pline/wind/plineWind/?repage";
	}
	
	@RequiresPermissions("pline:wind:plineWind:edit")
	@RequestMapping(value = "delete")
	public String delete(PlineWind plineWind, RedirectAttributes redirectAttributes) {
		plineWindService.delete(plineWind);
		addMessage(redirectAttributes, "删除风场管理成功");
		return "redirect:"+Global.getAdminPath()+"/pline/wind/plineWind/?repage";
	}

}