package com.jeesite.modules.yinet.web;

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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.yinet.entity.YinetMessageDitch;
import com.jeesite.modules.yinet.service.YinetMessageDitchService;

/**
 * 消息渠道Controller
 * @author xqx
 * @version 2022-06-18
 */
@Controller
@RequestMapping(value = "${adminPath}/yinet/yinetMessageDitch")
public class YinetMessageDitchController extends BaseController {

	@Autowired
	private YinetMessageDitchService yinetMessageDitchService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public YinetMessageDitch get(Long messageDitchId, boolean isNewRecord) {
		return yinetMessageDitchService.get(String.valueOf(messageDitchId), isNewRecord);
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("yinet:yinetMessageDitch:view")
	@RequestMapping(value = {"list", ""})
	public String list(YinetMessageDitch yinetMessageDitch, Model model) {
		model.addAttribute("yinetMessageDitch", yinetMessageDitch);
		return "modules/yinet/yinetMessageDitchList";
	}

	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("yinet:yinetMessageDitch:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<YinetMessageDitch> listData(YinetMessageDitch yinetMessageDitch, HttpServletRequest request, HttpServletResponse response) {
		yinetMessageDitch.setPage(new Page<>(request, response));
		Page<YinetMessageDitch> page = yinetMessageDitchService.findPage(yinetMessageDitch);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("yinet:yinetMessageDitch:view")
	@RequestMapping(value = "form")
	public String form(YinetMessageDitch yinetMessageDitch, Model model) {
		model.addAttribute("yinetMessageDitch", yinetMessageDitch);
		return "modules/yinet/yinetMessageDitchForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("yinet:yinetMessageDitch:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated YinetMessageDitch yinetMessageDitch) {
		yinetMessageDitchService.save(yinetMessageDitch);
		return renderResult(Global.TRUE, text("保存消息渠道成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("yinet:yinetMessageDitch:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(YinetMessageDitch yinetMessageDitch) {
		yinetMessageDitchService.delete(yinetMessageDitch);
		return renderResult(Global.TRUE, text("删除消息渠道成功！"));
	}

}
