package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.SysMusicScoreAccompaniment;
import com.ym.mec.biz.dal.enums.ClientTypeEnum;
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
import com.ym.mec.biz.service.SysMusicScoreAccompanimentService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.exception.BizException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("sysMusicScoreAccompaniment")
@Api(tags = "曲库伴奏服务")
@RestController
public class SysMusicScoreAccompanimentController extends BaseController {

    @Autowired
    private SysMusicScoreAccompanimentService sysMusicScoreAccompanimentService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Object update(@RequestBody SysMusicScoreAccompaniment sysMusicScoreAccompaniment) {
        sysMusicScoreAccompanimentService.updateAcc(sysMusicScoreAccompaniment);
        return succeed();
    }

    @ApiOperation(value = "删除")
    @PostMapping("/del")
    public Object del(Integer id) {
        sysMusicScoreAccompanimentService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "获取伴奏声部列表")
    @GetMapping("/querySubjectIds")
    public Object querySubjectIds() {
        return succeed(sysMusicScoreAccompanimentService.querySubjectIds());
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    public Object queryPage(SysExamSongQueryInfo queryInfo) {
        String type = queryInfo.getType();
        if(StringUtils.isEmpty(type)){
            queryInfo.setType("ALL");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        if(queryInfo.getClientType() == null){
            queryInfo.setClientType(ClientTypeEnum.NETWORK_ROOM);
        }
        queryInfo.setCreateUserId(sysUser.getId());
        return succeed(sysMusicScoreAccompanimentService.queryAccPage(queryInfo));
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPageLimit")
    public Object queryPageLimit(SysExamSongQueryInfo queryInfo) {
        String type = queryInfo.getType();
        if(StringUtils.isEmpty(type)){
            queryInfo.setType("ALL");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        if(queryInfo.getClientType() == null){
            queryInfo.setClientType(ClientTypeEnum.NETWORK_ROOM);
        }
        queryInfo.setCreateUserId(sysUser.getId());
        return succeed(sysMusicScoreAccompanimentService.queryScorePage(queryInfo));
    }
}
