package com.jeesite.modules.sys.web.schedule;

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

import com.jeesite.modules.sys.entity.EmpUser;
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.sys.entity.schedule.Schedule;
import com.jeesite.modules.sys.service.schedule.ScheduleService;

import java.util.*;

/**
 * 日程表Controller
 * @author Q
 * @version 2022-05-31
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/schedule/schedule")
public class ScheduleController extends BaseController {

	@Autowired
	private ScheduleService scheduleService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Schedule get(String id, boolean isNewRecord) {
		Schedule ss= scheduleService.get(id,isNewRecord);
		return ss;
	}


	/**
	 * 日历页面
	 */
	@RequiresPermissions("sys:schedule:schedule:view")
	@RequestMapping(value = {"schedule", ""})
	public String schedule() {
		return "modules/sys/schedule/schedule";
	}

	/**
	 * 获取数据
	 */
	@RequiresPermissions("sys:schedule:schedule:view")
	@RequestMapping(value = {"getlist", ""})
	public List<Schedule> getxx(Schedule schedule) {
		List<Schedule> list=scheduleService.findList(schedule);
		return list;
	}



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




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

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

	/**
	 * 保存数据
	 */
	@RequiresPermissions("sys:schedule:schedule:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Schedule schedule) {
		scheduleService.save(schedule);
		return renderResult(Global.TRUE, text("保存日程表成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("sys:schedule:schedule:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Schedule schedule) {
		scheduleService.delete(schedule);
		return renderResult(Global.TRUE, text("删除日程表成功！"));
	}

}
