package com.ym.mec.web.controller.education;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.MusicGroupNews;
import com.ym.mec.biz.dal.page.MusicGroupTeachersQueryInfo;
import com.ym.mec.biz.service.MusicGroupNewsService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.QueryInfo;
import com.yonge.log.model.AuditLogAnnotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("eduMusicGroupNews")
@Api(tags = "乐团资讯服务")
@RestController
public class EduMusicGroupNewsController extends BaseController {

    @Autowired
    private MusicGroupNewsService musicGroupNewsService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @AuditLogAnnotation(operateName = "新增")
    public Object add(MusicGroupNews musicGroupNews) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        musicGroupNews.setOperatorId(sysUser.getId());
        return succeed(musicGroupNewsService.insert(musicGroupNews));
    }

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

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Object update(MusicGroupNews musicGroupNews) {
        musicGroupNewsService.update(musicGroupNews);
        return succeed();
    }

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

}
