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.MusicGroupQuestionnaire;
import com.ym.mec.biz.dal.page.MusicGroupPerformanceQueryInfo;
import com.ym.mec.biz.service.MusicGroupQuestionnaireService;
import com.ym.mec.common.controller.BaseController;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("eduMusicGroupQuestionnaire")
@Api(tags = "乐团满意度调查")
@RestController
public class EduMusicGroupQuestionnaireController extends BaseController {

    @Autowired
    private MusicGroupQuestionnaireService musicGroupQuestionnaireService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Object add(@RequestBody MusicGroupQuestionnaire musicGroupQuestionnaire){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        if(musicGroupQuestionnaire.getOperatorId() == null){
            musicGroupQuestionnaire.setOperatorId(sysUser.getId());
        }
        musicGroupQuestionnaireService.add(musicGroupQuestionnaire);
        return succeed();
    }

    @ApiOperation(value = "获取题目详情详情")
    @GetMapping("/getQuestionDetail")
    public Object getDetail() {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        if(sysUser.getTenantId() == null){
            return failed("机构信息异常，请联系管理员");
        }
        return succeed(musicGroupQuestionnaireService.getQuestionDetail(sysUser.getTenantId()));
    }

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

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Object update(@RequestBody MusicGroupQuestionnaire musicGroupQuestionnaire){
        musicGroupQuestionnaireService.updateResult(musicGroupQuestionnaire);
        return succeed();
    }

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

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