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.dto.MusicEnlightenmentQuestionnaireStatDto;
import com.ym.mec.biz.dal.entity.MusicEnlightenmentQuestionnaire;
import com.ym.mec.biz.dal.page.MusicEnlightenmentQuestionnaireQueryInfo;
import com.ym.mec.biz.service.MusicEnlightenmentQuestionnaireService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
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.security.access.prepost.PreAuthorize;
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;

import java.util.Date;
import java.util.List;

/**
 * @Author Joburgess
 * @Date 2021/10/13 0013
 */
@Api(tags = "启蒙课问卷")
@RestController
@RequestMapping("musicEnlightenmentQuestionnaire")
public class MusicEnlightenmentQuestionnaireController extends BaseController {

    @Autowired
    private MusicEnlightenmentQuestionnaireService musicEnlightenmentQuestionnaireService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "启蒙课问卷列表")
    @GetMapping("queryPage")
    @PreAuthorize("@pcs.hasPermissions('musicEnlightenmentQuestionnaire/queryPage')")
    public HttpResponseResult<PageInfo<MusicEnlightenmentQuestionnaire>> queryPage(MusicEnlightenmentQuestionnaireQueryInfo queryInfo){
        return succeed(musicEnlightenmentQuestionnaireService.queryPage(queryInfo));
    }

    @ApiOperation(value = "发送家长会通知")
    @PostMapping("sendParentMeetingNotice")
    @PreAuthorize("@pcs.hasPermissions('musicEnlightenmentQuestionnaire/sendParentMeetingNotice')")
    public HttpResponseResult<Boolean> sendParentMeetingNotice(String musicGroupId, Date meetingDate, String address) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed(HttpStatus.FORBIDDEN, "用户信息获取失败");
        }
        return musicEnlightenmentQuestionnaireService.sendParentMeetingNotice(sysUser.getId(), musicGroupId, meetingDate, address) ? succeed() : failed();
    }

    @ApiOperation(value = "启蒙课问卷统计")
    @GetMapping("musicEnlightenmentQuestionnaireStat")
    @PreAuthorize("@pcs.hasPermissions('musicEnlightenmentQuestionnaire/musicEnlightenmentQuestionnaireStat')")
    public HttpResponseResult<List<MusicEnlightenmentQuestionnaireStatDto>> musicEnlightenmentQuestionnaireStat(String musicGroupId){
        return succeed(musicEnlightenmentQuestionnaireService.musicEnlightenmentQuestionnaireStat(musicGroupId));
    }

}
