package com.ym.mec.web.controller;

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.dao.EmployeeDao;
import com.ym.mec.biz.dal.entity.Employee;
import com.ym.mec.biz.dal.entity.SysMusicScoreCategories;
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.SysMusicScoreCategoriesService;
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.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

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

    @Autowired
    private SysMusicScoreCategoriesService sysMusicScoreCategoriesService;
    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/queryPage')")
    public Object queryPage(SysExamSongQueryInfo queryInfo) {
        queryInfo.setParentId(0);
        queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(sysMusicScoreCategoriesService.queryPage(queryInfo));
    }

    @ApiOperation(value = "启用、停用")
    @RequestMapping("/enable")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/enable')")
    public Object enable(Integer categoriesId) {
        sysMusicScoreCategoriesService.enable(categoriesId);
        return succeed();
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/save')")
    public Object save(@RequestBody SysMusicScoreCategories musicScoreCategories) {
        sysMusicScoreCategoriesService.save(musicScoreCategories);
        return succeed();
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/update')")
    public Object update(@RequestBody SysMusicScoreCategories musicScoreCategories) {
        sysMusicScoreCategoriesService.updateCategories(musicScoreCategories);
        return succeed();
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/delete')")
    public Object delete(Integer id) {
        sysMusicScoreCategoriesService.del(id);
        return succeed();
    }

    @ApiOperation(value = "树状列表")
    @GetMapping("/queryTree")
    @PreAuthorize("@pcs.hasPermissions('sysMusicScoreCategories/queryTree')")
    public Object queryTree(MusicScoreQueryInfo queryInfo) {
        //queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(sysMusicScoreCategoriesService.queryTree(queryInfo));
    }

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