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.dto.MusicScoreDto;
import com.ym.mec.biz.dal.entity.SysMusicScore;
import com.ym.mec.biz.dal.enums.ClientTypeEnum;
import com.ym.mec.biz.dal.enums.ExamSongTypeEnum;
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
import com.ym.mec.biz.service.SysMusicScoreService;
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("sysMusicScore")
@Api(tags = "曲库")
@RestController
public class SysMusicScoreController extends BaseController {

    @Autowired
    private SysMusicScoreService sysMusicScoreService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Object add(@RequestBody MusicScoreDto musicScoreDto) {
        SysMusicScore sysMusicScore = musicScoreDto.getSysMusicScore();
        sysMusicScore.setType(ExamSongTypeEnum.PERSON);
        if(sysMusicScore.getClientType() == null){
            sysMusicScore.setClientType(ClientTypeEnum.NETWORK_ROOM);
        }
        sysMusicScoreService.add(musicScoreDto);
        return succeed();
    }

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

    @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(sysMusicScoreService.queryPage(queryInfo));
    }
}
