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.YinetMessage;
import com.jeesite.modules.yinet.service.YinetMessageService;

/**
 * yinet_messageController
 * @author xqx
 * @version 2022-06-16
 */
@Controller
@RequestMapping(value = "${adminPath}/yinet/yinetMessage")
public class YinetMessageController extends BaseController {

	@Autowired
	private YinetMessageService yinetMessageService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public YinetMessage get(Long messageId, boolean isNewRecord) {
		return yinetMessageService.get(String.valueOf(messageId), isNewRecord);
	}

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

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

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

	/**
	 * 保存数据
	 */
	@RequiresPermissions("yinet:yinetMessage:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated YinetMessage yinetMessage) {
		yinetMessageService.save(yinetMessage);
		return renderResult(Global.TRUE, text("保存yinet_message成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("yinet:yinetMessage:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(YinetMessage yinetMessage) {
		yinetMessageService.delete(yinetMessage);
		return renderResult(Global.TRUE, text("删除yinet_message成功！"));
	}

}
