package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.SysExamSong;
import com.ym.mec.biz.dal.page.SysExamSongQueryInfo;
import com.ym.mec.biz.service.SysExamSongService;
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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("sysExamSong")
@Api(tags = "曲库服务")
@RestController
public class SysExamSongController extends BaseController {

    @Autowired
    private SysExamSongService sysExamSongService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('sysExamSong/update')")
    public Object update(@RequestBody SysExamSong sysExamSong) {
        sysExamSongService.update(sysExamSong);
        return succeed();
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('sysExamSong/add')")
    public Object add(@RequestBody SysExamSong sysExamSong) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        sysExamSong.setCreateUserId(sysUser.getId());
        sysExamSongService.insert(sysExamSong);
        return succeed();
    }

    @ApiOperation(value = "删除")
    @PostMapping("/del/{id}")
    @PreAuthorize("@pcs.hasPermissions('sysExamSong/del')")
    public Object del(@ApiParam(value = "收费类型编号", required = true) @PathVariable("id") Integer id) {
        sysExamSongService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('sysExamSong/queryPage')")
    public Object queryPage(SysExamSongQueryInfo queryInfo) {
        return succeed(sysExamSongService.queryPage(queryInfo));
    }

}
