package com.yonge.cooleshow.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.biz.dal.dto.search.CourseScheduleRepliedSearch;
import com.yonge.cooleshow.biz.dal.entity.CourseScheduleReplied;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleRepliedService;
import com.yonge.cooleshow.biz.dal.vo.CourseScheduleRepliedVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.base.util.StringUtil;
import com.yonge.toolset.mybatis.support.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("${app-config.url.admin:}/courseScheduleReplied")
@Api(value = "课程点评", tags = "课程点评")
public class CourseScheduleRepliedController extends BaseController {

    @Autowired
    private CourseScheduleRepliedService courseScheduleRepliedService;

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

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