package com.yonge.cooleshow.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.yonge.cooleshow.biz.dal.support.PageUtil;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.page.PageInfo;
import com.yonge.toolset.utils.string.StringUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import com.yonge.cooleshow.biz.dal.vo.StudentAttendanceVo;
import com.yonge.cooleshow.biz.dal.dto.search.StudentAttendanceSearch;
import com.yonge.cooleshow.biz.dal.entity.StudentAttendance;
import com.yonge.cooleshow.biz.dal.service.StudentAttendanceService;

@RestController
@RequestMapping("/studentAttendance")
@Api(value = "学生考勤表", tags = "学生考勤表")
public class StudentAttendanceController extends BaseController {

    @Autowired
    private StudentAttendanceService studentAttendanceService;

	/**
     * 查询单条
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public HttpResponseResult<StudentAttendanceVo> detail(@PathVariable("id") Long id) {
    	return succeed(studentAttendanceService.detail(id));
	}
    
    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入studentAttendanceSearch")
    public HttpResponseResult<PageInfo<StudentAttendanceVo>> page(@RequestBody StudentAttendanceSearch query) {
		IPage<StudentAttendanceVo> pages = studentAttendanceService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
	}
    
    /**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入studentAttendance")
	public HttpResponseResult save(@Valid @RequestBody StudentAttendance studentAttendance) {
    	return status(studentAttendanceService.save(studentAttendance));
	}
    
    /**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入studentAttendance")
	public HttpResponseResult update(@Valid @RequestBody StudentAttendance studentAttendance) {
        return status(studentAttendanceService.updateById(studentAttendance));
	}
    
    /**
	 * 新增或修改
	 */
    @PostMapping("/submit")
    @ApiOperation(value = "新增或修改", notes = "传入studentAttendance")
	public HttpResponseResult submit(@Valid @RequestBody StudentAttendance studentAttendance) {
        return status(studentAttendanceService.saveOrUpdate(studentAttendance));
    }

 	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public HttpResponseResult remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        if (StringUtil.isEmpty(ids)) {
			return failed("参数不能为空");
		}
		return status(studentAttendanceService.removeByIds(StringUtil.toLongList(ids)));
	}
}