package com.hp.web.controller.teach;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hp.common.annotation.Log;
import com.hp.common.enums.BusinessType;
import com.hp.teach.domain.School;
import com.hp.teach.service.ISchoolService;
import com.hp.framework.web.base.BaseController;
import com.hp.common.page.TableDataInfo;
import com.hp.common.base.AjaxResult;
import com.hp.common.utils.poi.ExcelUtil;

/**
 * 校区 信息操作处理
 * 
 * @author hp
 * @date 2019-02-12
 */
@Controller
@RequestMapping("/teach/school")
public class SchoolController extends BaseController
{
    private String prefix = "teach/school";
	
	@Autowired
	private ISchoolService schoolService;
	
	@RequiresPermissions("teach:school:view")
	@GetMapping()
	public String school()
	{
	    return prefix + "/school";
	}
	
	/**
	 * 查询校区列表
	 */
	@RequiresPermissions("teach:school:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(School school)
	{
		startPage();
        List<School> list = schoolService.selectSchoolList(school);
		return getDataTable(list);
	}

	/**
	 * 导出校区列表
	 */
	@RequiresPermissions("teach:school:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(School school)
    {
    	List<School> list = schoolService.selectSchoolList(school);
        ExcelUtil<School> util = new ExcelUtil<School>(School.class);
        return util.exportExcel(list, "school");
    }
	
	/**
	 * 新增校区
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存校区
	 */
	@RequiresPermissions("teach:school:add")
	@Log(title = "校区", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(School school)
	{		
		return toAjax(schoolService.insertSchool(school));
	}

	/**
	 * 修改校区
	 */
	@GetMapping("/edit/{schoolId}")
	public String edit(@PathVariable("schoolId") Integer schoolId, ModelMap mmap)
	{
		School school = schoolService.selectSchoolById(schoolId);
		mmap.put("school", school);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存校区
	 */
	@RequiresPermissions("teach:school:edit")
	@Log(title = "校区", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(School school)
	{		
		return toAjax(schoolService.updateSchool(school));
	}
	
	/**
	 * 删除校区
	 */
	@RequiresPermissions("teach:school:remove")
	@Log(title = "校区", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(schoolService.deleteSchoolByIds(ids));
	}
	
}
