package com.xinyilu.web.controller.checkreport;

import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.system.service.checkreport.CheckReportService;
import com.xinyilu.system.service.checkreport.HeightAndWeightCheckReportService;
import com.xinyilu.system.service.checkreport.KindConstitutionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Description 检测报告控制器
 * @Author 纪寒
 * @Date 2022-09-23 13:25:12
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/checkReport")
public class CheckReportController extends BaseController {


    @Resource
    private CheckReportService checkReportService;
    @Resource
    private KindConstitutionService kindConstitutionService;

    /**
     * 根据学生id和批次编号生成该批次检测报告
     *
     * @param studentId 学生id
     * @param batchCode 批次编号
     * @return 检测报告
     * @throws Exception 异常信息
     */
    @PreAuthorize("@ss.hasPermi('system:checkReport:report')")
    @PostMapping("/report")
    public AjaxResult generateStudentCheckReport(Long studentId, String batchCode) throws Exception {
        if (Objects.isNull(studentId)) {
            return AjaxResult.error("学生id不能为空！");
        }
        if (StringUtils.isBlank(batchCode)) {
            return AjaxResult.error("批次编号不能为空！");
        }
        return checkReportService.generateStudentCheckReport(studentId, batchCode);
    }

    /**
     * 根据学生id和批次编号生成该批次检测报告
     *
     * @param kindergartenId, 幼儿园id
     * @param batchCode       批次编号
     * @return 检测报告
     * @throws Exception 异常信息
     */
    @PreAuthorize("@ss.hasPermi('system:kindergartenCheckReport:preview')")
    @PostMapping("/kindergarten/constitution")
    public AjaxResult kindergartenConstitutionCheckReport(@RequestParam("kindergartenId") Long kindergartenId,
                                                          @RequestParam("batchCode") String batchCode) throws Exception {
        if (Objects.isNull(kindergartenId)) {
            return AjaxResult.error("幼儿园信息不能为空");
        }
        if (StringUtils.isBlank(batchCode)) {
            return AjaxResult.error("批次信息不能为空");
        }
        return kindConstitutionService.getKinderPhysiqueAnalysis(kindergartenId, batchCode);
    }

}
