package com.jeesite.modules.aaaaa.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.aaaaa.entity.Aaaaa;
import com.jeesite.modules.aaaaa.service.AaaaaService;

/**
 * 测试表Controller
 * @author aa
 * @version 2022-05-16
 */
@Controller
@RequestMapping(value = "${adminPath}/aaaaa/aaaaa")
public class AaaaaController extends BaseController {

	@Autowired
	private AaaaaService aaaaaService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Aaaaa get(String id, boolean isNewRecord) {
		return aaaaaService.get(id, isNewRecord);
	}

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

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

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

	/**
	 * 保存数据
	 */
	@RequiresPermissions("aaaaa:aaaaa:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Aaaaa aaaaa) {
		aaaaaService.save(aaaaa);
		return renderResult(Global.TRUE, text("保存测试表成功！"));
	}

	/**
	 * 停用数据
	 */
	@RequiresPermissions("aaaaa:aaaaa:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(Aaaaa aaaaa) {
		aaaaa.setStatus(Aaaaa.STATUS_DISABLE);
		aaaaaService.updateStatus(aaaaa);
		return renderResult(Global.TRUE, text("停用测试表成功"));
	}

	/**
	 * 启用数据
	 */
	@RequiresPermissions("aaaaa:aaaaa:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(Aaaaa aaaaa) {
		aaaaa.setStatus(Aaaaa.STATUS_NORMAL);
		aaaaaService.updateStatus(aaaaa);
		return renderResult(Global.TRUE, text("启用测试表成功"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("aaaaa:aaaaa:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Aaaaa aaaaa) {
		aaaaaService.delete(aaaaa);
		return renderResult(Global.TRUE, text("删除测试表成功！"));
	}

}
