package com.yida.data.school.health.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.health.EduHealthStudentPhysicalExaminationGroup;
import com.yida.data.school.health.service.EduHealthStudentPhysicalExaminationGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 体质健康对应组别表 Controller
 *
 * @author zhanghaijun
 * @date 2021-11-10 17:16:54
 */
@Slf4j
@Validated
@RestController
@RequestMapping("webHealthGroup")
@RequiredArgsConstructor
@Api(tags = "体质健康-国标体测对应组别")
public class EduHealthStudentPhysicalExaminationGroupController {

    private final EduHealthStudentPhysicalExaminationGroupService groupService;

    @GetMapping("/findHealthGroup")
    @ApiOperation("查询学生自测添加的项目列表数据")
    public ResultBean<Page<EduHealthStudentPhysicalExaminationGroup>> findHealthGroup (@ApiParam("学校id")@RequestParam Long schoolId,
                                       @ApiParam("组名")@RequestParam(required = false) String groupName,
                                       @ApiParam("状态0已发送，1未发送")@RequestParam(required = false) Integer status,
                                       @RequestParam(defaultValue = "1") Long pageNum,
                                       @RequestParam(defaultValue = "10") Long pageSize){

        Page<EduHealthStudentPhysicalExaminationGroup> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return ResultBean.buildSuccess(groupService.findHealthGroup(page,schoolId,groupName,status));
    }

    @PostMapping("/saveOrUpdateHealthGroup")
    @ApiOperation("新增或修改组别")
    public ResultBean saveOrUpdateHealthGroup(@RequestBody EduHealthStudentPhysicalExaminationGroup examinationGroup){
        groupService.saveOrUpdateHealthGroup(examinationGroup);
        return ResultBean.buildSuccess();
    }

    @GetMapping("/removeHealthGroup")
    @ApiOperation("删除组别")
    public ResultBean removeHealthGroup(@ApiParam("组id")@RequestParam Long groupId){
        EduHealthStudentPhysicalExaminationGroup byId = groupService.getById(groupId);
        if (byId.getStatus()==1){
            return ResultBean.buildError("成绩已发布，不能删除");
        }
        groupService.removeHealthGroup(groupId);
        return ResultBean.buildSuccess();
    }

    @GetMapping("/sendHealthNotice")
    @ApiOperation("组发送对应体测通知")
    public ResultBean sendHealthNotice(@ApiParam("组id")@RequestParam Long groupId,
                                       @ApiParam("学校id")@RequestParam Long schoolId){
        groupService.sendHealthNotice(groupId,schoolId);
        return ResultBean.buildSuccess();
    }


}
