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.support.PageUtil;
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.mybatis.page.PageInfo;
import com.yonge.toolset.utils.string.StringUtil;
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 javax.validation.Valid;

@RestController
@RequestMapping("/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);
	}
}