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.TeachClassAttendance;
import com.hp.teach.service.ITeachClassAttendanceService;
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-03-02
 */
@Controller
@RequestMapping("/teach/teachClassAttendance")
public class TeachClassAttendanceController extends BaseController
{
    private String prefix = "teach/teachClassAttendance";
	
	@Autowired
	private ITeachClassAttendanceService teachClassAttendanceService;
	
	@RequiresPermissions("teach:teachClassAttendance:view")
	@GetMapping()
	public String teachClassAttendance()
	{
	    return prefix + "/teachClassAttendance";
	}
	
	/**
	 * 查询班级出勤率统计列表
	 */
	@RequiresPermissions("teach:teachClassAttendance:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TeachClassAttendance teachClassAttendance)
	{
		startPage();
        List<TeachClassAttendance> list = teachClassAttendanceService.selectTeachClassAttendanceList(teachClassAttendance);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出班级出勤率统计列表
	 */
	@RequiresPermissions("teach:teachClassAttendance:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeachClassAttendance teachClassAttendance)
    {
    	List<TeachClassAttendance> list = teachClassAttendanceService.selectTeachClassAttendanceList(teachClassAttendance);
        ExcelUtil<TeachClassAttendance> util = new ExcelUtil<TeachClassAttendance>(TeachClassAttendance.class);
        return util.exportExcel(list, "teachClassAttendance");
    }
	
	/**
	 * 新增班级出勤率统计
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存班级出勤率统计
	 */
	@RequiresPermissions("teach:teachClassAttendance:add")
	@Log(title = "班级出勤率统计", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TeachClassAttendance teachClassAttendance)
	{		
		return toAjax(teachClassAttendanceService.insertTeachClassAttendance(teachClassAttendance));
	}

	/**
	 * 修改班级出勤率统计
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		TeachClassAttendance teachClassAttendance = teachClassAttendanceService.selectTeachClassAttendanceById(id);
		mmap.put("teachClassAttendance", teachClassAttendance);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存班级出勤率统计
	 */
	@RequiresPermissions("teach:teachClassAttendance:edit")
	@Log(title = "班级出勤率统计", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TeachClassAttendance teachClassAttendance)
	{		
		return toAjax(teachClassAttendanceService.updateTeachClassAttendance(teachClassAttendance));
	}
	
	/**
	 * 删除班级出勤率统计
	 */
	@RequiresPermissions("teach:teachClassAttendance:remove")
	@Log(title = "班级出勤率统计", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(teachClassAttendanceService.deleteTeachClassAttendanceByIds(ids));
	}
	
}
