package com.miaxis.pc.controller.coach;

import com.miaxis.coach.domain.CoachEvaluate;
import com.miaxis.coach.service.ICoachEvaluateService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【教练评价】Controller
 *
 * @author wwl
 * @date 2021-01-15
 */
@RestController
@RequestMapping("/coach/evaluate")
@Api(tags={"【pc-教练评价】"})
public class PcCoachEvaluateController extends BaseController{

    @Autowired
    private ICoachEvaluateService coachEvaluateService;

    /**
     * 查询教练评价列表
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:list')")
    @GetMapping("/list")
    @ApiOperation("查询教练评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<CoachEvaluate> list(@ModelAttribute CoachEvaluate coachEvaluate){
        startPage();
        List<CoachEvaluate> list = coachEvaluateService.queryList(coachEvaluate);
        return toResponsePageInfo(list);
    }

    /**
     * 导出教练评价列表
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:export')")
    @Log(title = "教练评价", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出教练评价列表Excel")
    public Response<String> export(@ModelAttribute CoachEvaluate coachEvaluate){
        List<CoachEvaluate> list = coachEvaluateService.queryList(coachEvaluate);
        ExcelUtil<CoachEvaluate> util = new ExcelUtil<CoachEvaluate>(CoachEvaluate.class);
        return util.exportExcel(list, "evaluate");
    }

    /**
     * 获取教练评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取教练评价详细信息")
    public Response<CoachEvaluate> getInfo(
            @ApiParam(name = "id", value = "教练评价参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(coachEvaluateService.getById(id));
    }

    /**
     * 新增教练评价
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:add')")
    @Log(title = "教练评价", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增教练评价")
    public Response<Integer> add(@RequestBody CoachEvaluate coachEvaluate){
        return toResponse(coachEvaluateService.save(coachEvaluate) ? 1 : 0);
    }

    /**
     * 修改教练评价
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:edit')")
    @Log(title = "教练评价", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改教练评价")
    public Response<Integer> edit(@RequestBody CoachEvaluate coachEvaluate){
        return toResponse(coachEvaluateService.updateById(coachEvaluate) ? 1 : 0);
    }

    /**
     * 删除教练评价
     */
    @PreAuthorize("@ss.hasPermi('coach:evaluate:remove')")
    @Log(title = "教练评价", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除教练评价")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "教练评价ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(coachEvaluateService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
