package com.miaxis.app.controller.coach;

import com.miaxis.app.coach.domain.CoachInfo;
import com.miaxis.app.coach.dto.CoachInfoDTO;
import com.miaxis.app.coach.dto.CoachInfoVO;
import com.miaxis.app.coach.service.ICoachInfoService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
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.SecurityUtils;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【教练】Controller
 *
 * @author miaxis
 * @date 2021-01-07
 */
@RestController
@RequestMapping(Constants.OPEN_PREFIX+"/coach/info")
@Api(tags={"【app-教练】"})
public class CoachInfoController extends BaseController{
    @Autowired
    private ICoachInfoService coachInfoService;

    /**
     * 查询教练列表
     */
    //@PreAuthorize("@ss.hasPermi('coach:info: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<CoachInfo> list(@ModelAttribute CoachInfo coachInfo){
        startPage();
        List<CoachInfo> list = coachInfoService.selectCoachInfoList(coachInfo);
        return toResponsePageInfo(list);
    }

    /**
     * 查询教练列表
     */
    //@PreAuthorize("@ss.hasPermi('coach:info:list')")
    @GetMapping("/urlList")
    @ApiOperation("查询教练列表（带头像距离）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<CoachInfoVO> urlList(@ModelAttribute CoachInfoDTO coachInfoDTO){
        startPage();
        List<CoachInfoVO> list = coachInfoService.selectCoachInfoUrlList(coachInfoDTO);
        return toResponsePageInfo(list);
    }




    /**
     * 导出教练列表
     */
   // @PreAuthorize("@ss.hasPermi('coach:info:export')")
    @Log(title = "教练", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出教练列表Excel")
    public Response<String> export(@ModelAttribute CoachInfo coachInfo){
        List<CoachInfo> list = coachInfoService.selectCoachInfoList(coachInfo);
        ExcelUtil<CoachInfo> util = new ExcelUtil<CoachInfo>(CoachInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取教练详细信息
     */
    //@PreAuthorize("@ss.hasPermi('coach:info:query')")
    @GetMapping(value = "/{coachnum}")
    @ApiOperation("获取教练详细信息")
    public Response<CoachInfo> getInfo(
            @ApiParam(name = "coachnum", value = "教练参数", required = true)
            @PathVariable("coachnum") String coachnum
    ){
        return Response.success(coachInfoService.selectCoachInfoById(coachnum));
    }

    /**
     * 新增教练
     */
    //@PreAuthorize("@ss.hasPermi('coach:info:add')")
    @Log(title = "教练", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增教练")
    public Response<Integer> add(@RequestBody CoachInfo coachInfo){
        return toResponse(coachInfoService.insertCoachInfo(coachInfo));
    }

    /**
     * 修改教练
     */
    //@PreAuthorize("@ss.hasPermi('coach:info:edit')")
    @Log(title = "教练", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改教练")
    public Response<Integer> edit(@RequestBody CoachInfo coachInfo){
        return toResponse(coachInfoService.updateCoachInfo(coachInfo));
    }

    /**
     * 删除教练
     */
    //@PreAuthorize("@ss.hasPermi('coach:info:remove')")
    @Log(title = "教练", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{coachnums}")
    @ApiOperation("删除教练")
    public  Response<Integer> remove(
            @ApiParam(name = "coachnums", value = "教练ids参数", required = true)
            @PathVariable String[] coachnums
    ){
        return toResponse(coachInfoService.deleteCoachInfoByIds(coachnums));
    }
}
