package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.biz.dal.dto.req.TeacherMusicSheetAuditReq;
import com.yonge.cooleshow.biz.dal.dto.search.TeacherMusicSheetAuditSearch;
import com.yonge.cooleshow.biz.dal.service.MusicSheetAuthRecordService;
import com.yonge.cooleshow.biz.dal.service.SysUserService;
import com.yonge.cooleshow.biz.dal.vo.MusicSheetDetailVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherMusicSheetVo;
import com.yonge.cooleshow.biz.dal.wrapper.MusicSheetWrapper;
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.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("${app-config.url.admin:}/musicSheetAuthRecord")
@Api(tags = "曲谱审核表 API接口")
public class MusicSheetAuthRecordController extends BaseController {
    @Resource
    private MusicSheetAuthRecordService musicSheetAuthRecordService;
	@Resource
	private SysUserService sysUserService;

    @PostMapping(value = "/audit/list", consumes="application/json", produces="application/json")
    @ApiOperation(value = "审核中心-乐谱审核列表", httpMethod="POST", consumes="application/json", produces="application/json")
    @PreAuthorize("@pcs.hasPermissions('musicSheetAuthRecord/audit/list')")
    public HttpResponseResult<PageInfo<TeacherMusicSheetVo>> audit(@RequestBody TeacherMusicSheetAuditSearch query) {
        return succeed(PageUtil.pageInfo(musicSheetAuthRecordService.selectAuditPage(PageUtil.getPage(query),query)));
    }

    @PostMapping(value = "/audit", consumes="application/json", produces="application/json")
    @ApiOperation(value = "审核中心-乐谱审核", httpMethod="POST", consumes="application/json", produces="application/json")
    @PreAuthorize("@pcs.hasPermissions('musicSheetAuthRecord/audit')")
    public HttpResponseResult audit(@Valid @RequestBody TeacherMusicSheetAuditReq param) {
        musicSheetAuthRecordService.audit(param,sysUserService.getUserId());
        return succeed();
    }


    @GetMapping(value = "/auditDetail/{musicSheetAuthRecordId}")
    @ApiOperation(value = "审核中心-乐谱审核详情",  notes = "传入曲目审核id")
    public HttpResponseResult<MusicSheetDetailVo> auditDetail(@PathVariable Long musicSheetAuthRecordId) {
        return succeed(musicSheetAuthRecordService.auditDetail(musicSheetAuthRecordId));
    }

    @GetMapping(value = "/auditDetailList/{batchNo}")
    @ApiOperation(value = "审核中心-乐谱审核详情历史记录",  notes = "传入曲目审核批次号")
    public HttpResponseResult<List<MusicSheetWrapper.MusicSheetDetailVo>> auditDetailList(@PathVariable String batchNo) {
        return succeed(musicSheetAuthRecordService.auditDetailList(batchNo));
    }
}
