package com.jeesite.modules.consult.web;

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

import com.jeesite.modules.sys.utils.UserUtils;
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.consult.entity.ConsultHelpSlave;
import com.jeesite.modules.consult.service.ConsultHelpSlaveService;

import java.util.Date;

/**
 * 咨询帮助-从表Controller
 * @author wxm
 * @version 2022-06-07
 */
@Controller
@RequestMapping(value = "${adminPath}/consult/consultHelpSlave")
public class ConsultHelpSlaveController extends BaseController {

	@Autowired
	private ConsultHelpSlaveService consultHelpSlaveService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ConsultHelpSlave get(String id, boolean isNewRecord) {
		return consultHelpSlaveService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("consult:consultHelpSlave:view")
	@RequestMapping(value = {"list", ""})
	public String list(ConsultHelpSlave consultHelpSlave, Model model) {
		model.addAttribute("consultHelpSlave", consultHelpSlave);
		return "modules/consult/consultHelpSlaveList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("consult:consultHelpSlave:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ConsultHelpSlave> listData(ConsultHelpSlave consultHelpSlave, HttpServletRequest request, HttpServletResponse response) {
		consultHelpSlave.setPage(new Page<>(request, response));
		Page<ConsultHelpSlave> page = consultHelpSlaveService.findPage(consultHelpSlave);
		return page;
	}

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

	/**
	 * 保存数据
	 */
	@RequiresPermissions("consult:consultHelpSlave:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ConsultHelpSlave consultHelpSlave) {
		consultHelpSlave.setUserId(UserUtils.getUser().getUserCode());
		consultHelpSlave.setUserName(UserUtils.getUser().getUserName());
		consultHelpSlave.setCreateTime(new Date());
		consultHelpSlaveService.save(consultHelpSlave);
		return renderResult(Global.TRUE, text("保存咨询帮助-从表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("consult:consultHelpSlave:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ConsultHelpSlave consultHelpSlave) {
		consultHelpSlaveService.delete(consultHelpSlave);
		return renderResult(Global.TRUE, text("删除咨询帮助-从表成功！"));
	}
	
}