package com.yonge.cooleshow.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.req.AuthOperaReq;
import com.yonge.cooleshow.biz.dal.dto.search.AuthEntryRecordSearch;
import com.yonge.cooleshow.biz.dal.service.TeacherAuthMusicianRecordService;
import com.yonge.cooleshow.biz.dal.vo.MusicianAuthEntryRecordVo;
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.mybatis.support.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("${app-config.url.admin:}/teacherAuthMusicianRecord")
@Api(value = "老师音乐人审核表", tags = "老师音乐人审核表")
public class TeacherAuthMusicianRecordController extends BaseController {
    @Autowired
    private TeacherAuthMusicianRecordService teacherAuthMusicianRecordService;
	@Autowired
	private SysUserFeignService sysUserFeignService;

	/**
	 * 查询单条详情
	 */
	@GetMapping("/detail/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "path", dataType = "long", required = true),
	})
	@PreAuthorize("@pcs.hasPermissions('teacherAuthMusicianRecord/detail')")
	public HttpResponseResult<MusicianAuthEntryRecordVo> detail(@PathVariable("id") Long id) {
		MusicianAuthEntryRecordVo detail = teacherAuthMusicianRecordService.detail(id);
		return succeed(detail);
	}

	/**
	 * 查询分页
	 */
	@PostMapping("/page")
	@ApiOperation(value = "查询分页", notes = "传入AuthEntryRecordSearch")
	@PreAuthorize("@pcs.hasPermissions('teacherAuthMusicianRecord/page')")
	public HttpResponseResult<PageInfo<MusicianAuthEntryRecordVo>> page(@RequestBody AuthEntryRecordSearch query) {
		IPage<MusicianAuthEntryRecordVo> pages = teacherAuthMusicianRecordService.selectPage(PageUtil.getPage(query), query);
		return succeed(PageUtil.pageInfo(pages));
	}

	@PostMapping("/doAuth")
	@ApiOperation(value = "审核", notes = "传入authOperaDto")
	@PreAuthorize("@pcs.hasPermissions('teacherAuthMusicianRecord/doAuth')")
	public HttpResponseResult<Boolean> doAuth(@Valid @RequestBody AuthOperaReq authOperaReq) throws Exception {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		return teacherAuthMusicianRecordService.doAuth(authOperaReq, sysUser);
	}
}