package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.dto.MusicScoreQueryInfo;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.TenantConfig;
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
import com.ym.mec.biz.service.SysMusicScoreCategoriesService;
import com.ym.mec.biz.service.TeacherService;
import com.ym.mec.biz.service.TenantConfigService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("sysMusicScoreCategories")
@Api(tags = "曲库分类服务")
@RestController
public class SysMusicScoreCategoriesController extends BaseController {

    @Autowired
    private SysMusicScoreCategoriesService sysMusicScoreCategoriesService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private TeacherService teacherService;
    
    @Autowired
    private TenantConfigService tenantConfigService;


    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    public Object queryPage(SysExamSongQueryInfo queryInfo) {
        return succeed(sysMusicScoreCategoriesService.queryPage(queryInfo));
    }

    @ApiOperation(value = "树状列表")
    @GetMapping("/queryTree")
    public Object queryTree(MusicScoreQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        
        TenantConfig tenantConfig = tenantConfigService.getOne(new QueryWrapper<TenantConfig>().eq("tenant_id_", sysUser.getTenantId()));
        
        return succeed(sysMusicScoreCategoriesService.queryCategoriesTreeList(tenantConfig.getTeachingMaterialId(), queryInfo.getEnable()));
    }

    @ApiOperation(value = "获取分类详情")
    @GetMapping("/get")
    public Object get(Integer id) {
        return succeed(sysMusicScoreCategoriesService.get(id));
    }
}
