package com.yida.data.school.health.service.impl;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.constant.CachePrefixConstant;
import com.yida.data.common.core.entity.health.*;
import com.yida.data.common.core.entity.user.EduStudent;
import com.yida.data.common.core.utils.ExcelUtil;
import com.yida.data.common.core.utils.FileUtil;
import com.yida.data.school.health.mapper.*;
import com.yida.data.school.health.service.EduGradeService;
import com.yida.data.school.health.service.EduStudentPhysicalExaminationGradeResultsService;
import com.yida.data.school.health.service.EduStudentProjectTestResultService;
import com.yida.data.school.vo.health.ImportErrVO;
import com.yida.data.school.vo.health.ImportStudentScoreVO;
import com.yida.data.system.feign.RemoteDeptService;
import com.yida.data.user.feign.RemoteStudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.yida.data.common.core.utils.ExcelUtil.getCellValue;


/**
 * 学生学年成绩记录表 Service实现
 *
 * @author ccl
 * @date 2021-09-14 17:16:20
 */
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EduStudentPhysicalExaminationGradeResultsServiceImpl extends ServiceImpl
        <EduStudentPhysicalExaminationGradeResultsMapper, EduStudentPhysicalExaminationGradeResults> implements EduStudentPhysicalExaminationGradeResultsService {

    @Resource
    private EduStudentPhysicalExaminationGradeResultsMapper eduStudentPhysicalExaminationGradeResultsMapper;
    @Resource
    private RedisService redisService;
    @Resource
    private RemoteDeptService remoteDeptService;
    @Resource
    private RemoteStudentService remoteStudentService;
    @Resource
    private EduGradeService eduGradeService;
    @Resource
    private EduGradeReleateProjectMapper eduGradeReleateProjectMapper;
    @Resource
    private EduNationalStandardProjectScoreMapper eduNationalStandardProjectScoreMapper;
    @Resource
    private EduStudentProjectTestResultMapper eduStudentProjectTestResultMapper;
    @Resource
    private EduNationalStandardProjectExtraAddScoreMapper eduNationalStandardProjectExtraAddScoreMapper;
    @Resource
    private EduScoreRankMapper eduScoreRankMapper;

    /**
     * 批量上传学生体测成绩
     *
     * @param path       文件路径
     * @param uuid       缓存key
     * @param schoolId   学校id
     * @param schoolName 学校名字
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchUpScore(String path, String uuid, Long schoolId, String schoolName, Long groupId) {
        ImportStudentScoreVO vo = new ImportStudentScoreVO();
        vo.setStatus(0);
        vo.setPercent("0");
        int errNum = 0;

        ArrayList<ImportErrVO> errVOS = new ArrayList<>();
        try {

            redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid.toString(), vo);
            Workbook workbook = ExcelUtil.readExcel(new FileInputStream(path), "xls");

            List<Map<Integer, Cell>> mapList = ExcelUtil.readData(workbook.getSheetAt(0), 1);
            int rowNum = 0;
            int percent = 0;
            int size = mapList.size();

            Sheet sheet = workbook.getSheet("Sheet1");
            //指定行数。一共多少+
            int rows = sheet.getLastRowNum();


            for (Map<Integer, Cell> cellMap : mapList) {
                rowNum++;

                if (rowNum > size) {
                    break;
                }
                //读取cell
                EduStudentPhysicalExaminationGradeResults coreStudentPhysicalExaminationGradeResults = new EduStudentPhysicalExaminationGradeResults();

                //年级
                String gradeName = getCellValue(cellMap.get(0));

                //学号
                String studentName = getCellValue(cellMap.get(1));
                //学号
                String studentNo = getCellValue(cellMap.get(3));


                //获取填报年级的对象
                EduGrade coreGrade = null;


                //身高(130)
                String stuHeight = getCellValue(cellMap.get(4));

                //体重(60)
                String stuWight = getCellValue(cellMap.get(5));

                //肺活量(3000)
                String stuLungCapacity = getCellValue(cellMap.get(6));


                //性别
                String stuSex = getCellValue(cellMap.get(2));
                //50米跑时间(8.8)
                String stu50MeterRace = getCellValue(cellMap.get(7));
                //坐位体前屈（8或者-8）
                String stuBodyFlexion = getCellValue(cellMap.get(8));
                //50米×8往返跑(1′51,1'51'')
                String stu50MeterRaceBack = getCellValue(cellMap.get(9));
                //一分钟仰卧起坐
                String stuOneMiniteSitUp = getCellValue(cellMap.get(10));
                //一分钟跳绳
                String ropeSkipping = getCellValue(cellMap.get(11));
                //立定跳远
                String standingJump = getCellValue(cellMap.get(12));
                //引体向上（男）
                String pullUp = getCellValue(cellMap.get(13));
                //1000米跑（男）
                String meterRace1000 = getCellValue(cellMap.get(14));
                //800米跑（女）
                String meterRace800 = getCellValue(cellMap.get(15));
                //左眼裸眼视力
                String leftEye = getCellValue(cellMap.get(16));
                //右眼裸眼视力
                String rightEye = getCellValue(cellMap.get(17));
                //左眼屈光不正
                String leftEyeRefraction = getCellValue(cellMap.get(18));
                //右眼屈光不正
                String rightEyeRefraction = getCellValue(cellMap.get(19));
                //左眼串镜
                String leftEyeMirror = getCellValue(cellMap.get(20));
                //右眼串镜
                String rightEyeMirror = getCellValue(cellMap.get(21));


                //设置学生id
                EduStudent data = remoteStudentService.getStudentByStuNumAndSchool(studentNo, schoolId).getData();

                if (ObjectUtil.isEmpty(gradeName)) {
                    ImportErrVO errVO = new ImportErrVO();
                    errVO.setRowNum(rowNum);
                    errVO.setErrMsg("年级未填");
                    errVO.setStudentName(studentName);
                    errVO.setStudentNumber(studentNo);
                    errNum++;

                    if (rowNum / size > percent) {
                        java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
                        numberformat.setMaximumFractionDigits(2);
                        vo.setPercent(numberformat.format((float) rowNum / (float) size * 100));
                    }
                    errVOS.add(errVO);
                    vo.setErrVO(errVOS);
                    redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
                    continue;
                }
                if (ObjectUtil.isEmpty(data)) {
                    ImportErrVO errVO = new ImportErrVO();
                    errVO.setRowNum(rowNum);
                    errVO.setErrMsg("学号不存在");
                    errVO.setStudentName(studentName);
                    errVO.setStudentNumber(studentNo);
                    errNum++;

                    if (rowNum / size > percent) {
                        java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
                        numberformat.setMaximumFractionDigits(2);
                        vo.setPercent(numberformat.format((float) rowNum / (float) size * 100));
                    }
                    errVOS.add(errVO);
                    vo.setErrVO(errVOS);
                    redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
                    continue;
                }
                if (!data.getStuName().equals(studentName)) {
                    ImportErrVO errVO = new ImportErrVO();
                    errVO.setRowNum(rowNum);
                    errVO.setErrMsg("学号和学生姓名不匹配");
                    errVO.setStudentName(studentName);
                    errVO.setStudentNumber(studentNo);
                    errNum++;

                    if (rowNum / size > percent) {
                        java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
                        numberformat.setMaximumFractionDigits(2);
                        vo.setPercent(numberformat.format((float) rowNum / (float) size * 100));
                    }
                    errVOS.add(errVO);
                    vo.setErrVO(errVOS);
                    redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
                    continue;
                }

                if (stuSex.isEmpty()) {
                    ImportErrVO errVO = new ImportErrVO();
                    errVO.setRowNum(rowNum);
                    errVO.setErrMsg("未填学生性别");
                    errVO.setStudentName(studentName);
                    errVO.setStudentNumber(studentNo);
                    errNum++;
                    if (rowNum / size > percent) {
                        java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
                        numberformat.setMaximumFractionDigits(2);
                        vo.setPercent(numberformat.format((float) rowNum / (float) size * 100));
                    }
                    errVOS.add(errVO);
                    vo.setErrVO(errVOS);
                    redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
                    continue;
                }
                coreStudentPhysicalExaminationGradeResults.setGroupId(groupId);
                coreStudentPhysicalExaminationGradeResults.setSchoolId(schoolId);
                coreStudentPhysicalExaminationGradeResults.setSchoolName(schoolName);
                coreStudentPhysicalExaminationGradeResults.setGradeId(data.getGradeId());
                coreStudentPhysicalExaminationGradeResults.setGradeName(data.getGradeName());
                coreStudentPhysicalExaminationGradeResults.setClassId(data.getClassId());
                coreStudentPhysicalExaminationGradeResults.setClassName(data.getClassName());
                coreStudentPhysicalExaminationGradeResults.setStudentId(data.getId());
                coreStudentPhysicalExaminationGradeResults.setStudentNumber(data.getStuNumber());

                if ("0".equals(stuSex)) {
                    coreStudentPhysicalExaminationGradeResults.setStudentSex(0);
                } else if ("1".equals(stuSex)) {
                    coreStudentPhysicalExaminationGradeResults.setStudentSex(1);
                }


                coreStudentPhysicalExaminationGradeResults.setStudentName(data.getStuName());

                coreGrade = eduGradeService.getOne(Wrappers.lambdaQuery(new EduGrade())
                        .eq(EduGrade::getGradeName, gradeName));
                EduProject coreProject1 = new EduProject();


                coreProject1.setEduGradeId(coreGrade.getId());
                coreProject1.setHeight(stuHeight);
                coreProject1.setWight(stuWight);
                coreProject1.setLungCapacity(stuLungCapacity);
                coreProject1.setMeterRace800(meterRace800);
                coreProject1.setMeterRace1000(meterRace1000);
                coreProject1.setOneMinuteSitUp(stuOneMiniteSitUp);
                coreProject1.setPullUp(pullUp);
                coreProject1.setRopeSkipping(ropeSkipping);
                coreProject1.setSex(stuSex);
                coreProject1.setStandingJump(standingJump);
                coreProject1.setStu50MeterRace(stu50MeterRace);
                coreProject1.setStu50MeterRaceBack(stu50MeterRaceBack);
                coreProject1.setStuBodyFlexion(stuBodyFlexion);
                coreProject1.setLeftEye(leftEye);
                coreProject1.setRightEye(rightEye);
                coreStudentPhysicalExaminationGradeResults.setRecordGradeId(coreGrade.getId());
                coreStudentPhysicalExaminationGradeResults.setRecordGradeName(coreGrade.getGradeName());
                save(coreStudentPhysicalExaminationGradeResults);
                coreProject1.setCoreStudentPhysicalExaminationGradeResults(coreStudentPhysicalExaminationGradeResults);

                //保存并计算单项项目成绩和总成绩
                saveTestResult(coreProject1);

                //把实数据放入集合里

                if (rowNum / size > percent) {
                    java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
                    numberformat.setMaximumFractionDigits(2);
                    vo.setPercent(numberformat.format((float) rowNum / (float) size * 100));
                    vo.setErrVO(errVOS);
                    redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
                }

            }

        } catch (Exception e) {
            log.error("错误", e);
        } finally {
            vo.setErrNum(errNum);
            vo.setStatus(1);
            vo.setErrVO(errVOS);
            redisService.hset(CachePrefixConstant.HEALTH_IMPORT, uuid, vo);
        }

    }

    @Override
    public void downloadTemplate(HttpServletResponse response) {
        String fileName = "studentHealthModel.xls";
        // 获取导入文件模板
        ClassPathResource classPathResource = new ClassPathResource("template/health/" + fileName);
        InputStream inputStream = null;
        try {
            inputStream = classPathResource.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            FileUtil.download(FileUtil.inputStreamToFile(inputStream), fileName, false, response);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void saveTestResult(EduProject coreProject) {

        Long gradeResultId = coreProject.getCoreStudentPhysicalExaminationGradeResults().getId();
        eduStudentProjectTestResultMapper.delete(Wrappers.lambdaQuery(new EduStudentProjectTestResult())
                .eq(EduStudentProjectTestResult::getGradeResultId, gradeResultId));
        //总分数
        BigDecimal totalScore = new BigDecimal(0);
        //总等级名称
        String totalRank = "";
        //性别
        String sex = coreProject.getSex();
        //年级id
        Integer coreGradeId = coreProject.getEduGradeId().intValue();

        //身高cm需要转化为m
        String height = coreProject.getHeight();
        //体重
        String wight = coreProject.getWight();
        //身高单位cm

        BigDecimal height1 = new BigDecimal(height);
        //单位m
        BigDecimal height2 = new BigDecimal(height).multiply(new BigDecimal(0.0001)).multiply(new BigDecimal(height)).setScale(2, BigDecimal.ROUND_HALF_UP);

        BigDecimal wight1 = new BigDecimal(wight);

        //计算BMI保持一位小数
        BigDecimal BMI = wight1.divide(height2, 1, BigDecimal.ROUND_HALF_UP);
        //肺活量
        String lungCapacity = coreProject.getLungCapacity();
        //50米跑
        String stu50MeterRace = coreProject.getStu50MeterRace();
        //坐位体前屈
        String stuBodyFlexion = coreProject.getStuBodyFlexion();
        //引体向上（男）
        String pullUp = coreProject.getPullUp();
        //800米跑（女）
        String meterRace800 = coreProject.getMeterRace800();

        BigDecimal meterRace8001 = convertToSecond(meterRace800);

        //1000米跑（男）
        String meterRace1000 = coreProject.getMeterRace1000();

        BigDecimal meterRace10001 = convertToSecond(meterRace1000);

        //一分钟仰卧起坐
        String oneMinuteSitUp = coreProject.getOneMinuteSitUp();
        //立定跳远
        String standingJump = coreProject.getStandingJump();
        //一分钟跳绳
        String ropeSkipping = coreProject.getRopeSkipping();
        //50米×8往返跑(1′51,1'51'')
        String stu50MeterRaceBack = coreProject.getStu50MeterRaceBack();
        //处理50米往返跑
        BigDecimal stu50MeterRaceBack1 = convertToSecond(stu50MeterRaceBack);

        EduStudentPhysicalExaminationGradeResults coreStudentPhysicalExaminationGradeResults = coreProject.getCoreStudentPhysicalExaminationGradeResults();
        //学年成绩的主键id
        Long id = coreStudentPhysicalExaminationGradeResults.getId();

        Long schoolId = coreStudentPhysicalExaminationGradeResults.getSchoolId();
        String schoolName = coreStudentPhysicalExaminationGradeResults.getSchoolName();

        Long gradeId = coreStudentPhysicalExaminationGradeResults.getGradeId();
        String gradeName = coreStudentPhysicalExaminationGradeResults.getGradeName();

        String className = coreStudentPhysicalExaminationGradeResults.getClassName();
        Long classId = coreStudentPhysicalExaminationGradeResults.getClassId();

        String idcard = coreStudentPhysicalExaminationGradeResults.getStudentNumber();

        Long stuId = coreStudentPhysicalExaminationGradeResults.getStudentId();

        //查询关联的项目
        List<EduNationalStandardProjectWeight> coreNationalStandardProjectWeights = eduGradeReleateProjectMapper.selectByGradeId(coreGradeId);
        for (EduNationalStandardProjectWeight coreNationalStandardProjectWeight : coreNationalStandardProjectWeights) {
            //项目的主键id
            Long id1 = coreNationalStandardProjectWeight.getId();
            String projectName = coreNationalStandardProjectWeight.getProjectName();
            //比重
            BigDecimal projectProportion = coreNationalStandardProjectWeight.getProjectProportion();

            //左眼视力
            if (id1.intValue() == 22) {
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(coreProject.getLeftEye()) || "/".equals(coreProject.getLeftEye())) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    BigDecimal leftEye = new BigDecimal(coreProject.getLeftEye());
                    projectScore1.setResult(leftEye);
                    projectScore1.setProjectId(id1);
                    String rank = "";
                    if (leftEye.compareTo(new BigDecimal("5.0")) > -1) {
                        rank = "视力正常";
                    } else if (leftEye.compareTo(new BigDecimal("5.0")) < 0 && leftEye.compareTo(new BigDecimal("4.8")) > -1) {
                        rank = "轻度视力低下";
                    } else if (leftEye.compareTo(new BigDecimal("4.6")) < 0 && leftEye.compareTo(new BigDecimal("4.8")) > -1) {
                        rank = "中度视力低下";
                    } else if (leftEye.compareTo(new BigDecimal("4.6")) == -1) {
                        rank = "重度视力低下";
                    }

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectResult(leftEye.toString());
                    build.setProjectRank(rank);

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                }
            }
            //右眼视力
            else if (id1.intValue() == 23) {
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(coreProject.getRightEye()) || "/".equals(coreProject.getLeftEye())) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                } else {
                    BigDecimal rightEye = new BigDecimal(coreProject.getRightEye());
                    projectScore1.setResult(rightEye);
                    projectScore1.setProjectId(id1);
                    String rank = "";
                    if (rightEye.compareTo(new BigDecimal("5.0")) > -1) {
                        rank = "视力正常";
                    } else if (rightEye.compareTo(new BigDecimal("5.0")) < 0 && rightEye.compareTo(new BigDecimal("4.8")) > -1) {
                        rank = "轻度视力低下";
                    } else if (rightEye.compareTo(new BigDecimal("4.6")) < 0 && rightEye.compareTo(new BigDecimal("4.8")) > -1) {
                        rank = "中度视力低下";
                    } else if (rightEye.compareTo(new BigDecimal("4.6")) == -1) {
                        rank = "重度视力低下";
                    }

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectResult(rightEye.toString());
                    build.setProjectRank(rank);

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                }
            }
            //BMI
            else if (id1.intValue() == 1) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                projectScore1.setResult(BMI);
                projectScore1.setProjectId(id1);
                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                //单项得分
                Integer score1 = projectScore.getScore();
                //单项得分的等级
                String rank = projectScore.getRank();

                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                build.setSchoolId(schoolId);
                build.setSchoolName(schoolName);
                build.setGradeId(gradeId);
                build.setGradeName(gradeName);
                build.setClassId(classId);
                build.setClassName(className);
                build.setGradeResultId(id);
                build.setStudentNum(idcard);
                build.setProjectId(id1);
                build.setProjectName(projectName);
                build.setStudentId(stuId);
                build.setProjectResult(BMI.toString());
                build.setProjectScore(new BigDecimal(score1));
                build.setProjectRank(rank);
                build.setHeight(height1);
                build.setWeight(wight1);
                //保存该条数据
                eduStudentProjectTestResultMapper.insert(build);
                //查询该条数据的权重,传入年级id,项目id获取对应的权重
                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));

            }
            //肺活量(通用)
            else if (id1.intValue() == 2) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(lungCapacity)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult((new BigDecimal(lungCapacity)));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectResult(lungCapacity);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);


                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            // 50米跑(一二年级)
            else if (id1 == 3 || id1 == 6 || id1 == 10 || id1 == 15) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(stu50MeterRace)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult((new BigDecimal(stu50MeterRace)));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectResult(stu50MeterRace);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            //坐位体前屈(一二年级)
            else if (id1 == 4 || id1 == 7 || id1 == 11 || id1 == 16) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }

                if (ObjectUtil.isEmpty(stuBodyFlexion)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(new BigDecimal(stuBodyFlexion));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(stuBodyFlexion);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }

            }
            //1分钟跳绳(一二年级)
            else if (id1 == 5 || id1 == 8 || id1 == 12) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }

                if (ObjectUtil.isEmpty(ropeSkipping)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectRank("未参加测试");
                    build.setStudentId(stuId);

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(new BigDecimal(ropeSkipping));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);

                    //单项得分
                    Integer score1 = projectScore.getScore();

                    //总积分
                    Integer sumScore = score1;
                    //附件得分
                    Integer extraScore = 0;

                    BigDecimal dataMin = projectScore.getDataMin();
                    //超过100分才进行额外的加分
                    if (score1 >= 100) {
                        BigDecimal extraData = new BigDecimal(ropeSkipping).subtract(dataMin);
                        extraScore = getExtraScore(sex, extraData, id1, coreGradeId);
                        sumScore += extraScore;

                    }
                    //单项得分的等级
                    String rank = projectScore.getRank();
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(ropeSkipping);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectExtraScore(extraScore.toString());
                    build.setTotalProjectScore(sumScore.toString());
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);

                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(sumScore)));
                }
            }
            //50米跑(三四年级)
//            else if (id1 == 6) {
//                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
//                //查询BMI的得分(sql去查询)
//                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
//                projectScore1.setRecordGradeId(coreGradeId.longValue());
//                if ("男".equals(sex)) {
//                    projectScore1.setApplySex(0);
//                } else if ("1".equals(sex)) {
//                    projectScore1.setApplySex(1);
//                }
//                projectScore1.setResult(new BigDecimal(stu50MeterRace));
//                projectScore1.setProjectId(id1);
//                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
//                //单项得分
//                Integer score1 = projectScore.getScore();
//                //单项得分的等级
//                String rank = projectScore.getRank();
//
//                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
//                build.setSchoolId(schoolId);
//                build.setSchoolName(schoolName);
//                build.setGradeId(gradeId);
//                build.setGradeName(gradeName);
//                build.setClassId(classId);
//                build.setClassName(className);
//                build.setGradeResultId(id);
//                build.setStudentNum(idcard);
//                build.setProjectId(id1);
//                build.setProjectName(projectName);
//                build.setProjectResult(new BigDecimal(stu50MeterRace));
//                build.setProjectScore(new BigDecimal(score1));
//                build.setProjectRank(rank);
//                build.setStudentId(stuId);
//                //保存该条数据
//                eduStudentProjectTestResultMapper.insert(build);
//                //查询该条数据的权重,传入年级id,项目id获取对应的权重
//                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
//
//            }
//            //坐位体前屈小学三、四年级
//            else if (id1 == 7) {
//                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
//                //查询BMI的得分(sql去查询)
//                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
//                projectScore1.setRecordGradeId(coreGradeId.longValue());
//                if ("男".equals(sex)) {
//                    projectScore1.setApplySex(0);
//                } else if ("1".equals(sex)) {
//                    projectScore1.setApplySex(1);
//                }
//                projectScore1.setResult(new BigDecimal(stuBodyFlexion));
//                projectScore1.setProjectId(id1);
//                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
//                //单项得分
//                Integer score1 = projectScore.getScore();
//                //单项得分的等级
//                String rank = projectScore.getRank();
//
//                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
//                build.setSchoolId(schoolId);
//                build.setSchoolName(schoolName);
//                build.setGradeId(gradeId);
//                build.setGradeName(gradeName);
//                build.setClassId(classId);
//                build.setClassName(className);
//                build.setGradeResultId(id);
//                build.setStudentNum(idcard);
//                build.setProjectId(id1);
//                build.setProjectName(projectName);
//                build.setProjectResult(new BigDecimal(stuBodyFlexion));
//                build.setProjectScore(new BigDecimal(score1));
//                build.setProjectRank(rank);
//                build.setStudentId(stuId);
//                //保存该条数据
//                eduStudentProjectTestResultMapper.insert(build);
//                //查询该条数据的权重,传入年级id,项目id获取对应的权重
//                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
//
//            }
            //1分钟仰卧起坐
            else if (id1 == 9 || id1 == 13) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(oneMinuteSitUp)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(new BigDecimal(oneMinuteSitUp));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(oneMinuteSitUp);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            //50x8往返跑
            else if (id1 == 14) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(stu50MeterRaceBack)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(stu50MeterRaceBack1);
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(stu50MeterRaceBack);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            //立定跳远
            else if (id1 == 17) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                if ("0".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("1".equals(sex)) {
                    projectScore1.setApplySex(1);
                } else if ("男".equals(sex)) {
                    projectScore1.setApplySex(0);
                } else if ("女".equals(sex)) {
                    projectScore1.setApplySex(1);
                }
                if (ObjectUtil.isEmpty(standingJump)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(new BigDecimal(standingJump));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(standingJump);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            //引体向上
            else if (id1 == 18 && ("0".equals(sex) || "男".equals(sex))) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());

                projectScore1.setApplySex(0);

                projectScore1.setResult(new BigDecimal(pullUp));
                projectScore1.setProjectId(id1);
                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                //单项得分
                Integer score1 = projectScore.getScore();
                //单项得分的等级
                String rank = projectScore.getRank();

                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                build.setSchoolId(schoolId);
                build.setSchoolName(schoolName);
                build.setGradeId(gradeId);
                build.setGradeName(gradeName);
                build.setClassId(classId);
                build.setClassName(className);
                build.setGradeResultId(id);
                build.setStudentNum(idcard);
                build.setProjectId(id1);
                build.setProjectName(projectName);
                build.setProjectResult(pullUp);
                build.setProjectScore(new BigDecimal(score1));
                build.setProjectRank(rank);
                build.setStudentId(stuId);
                //保存该条数据
                eduStudentProjectTestResultMapper.insert(build);
                //查询该条数据的权重,传入年级id,项目id获取对应的权重
                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
            }
            //一分钟仰卧起坐女（女）初高大
            else if (id1 == 19 && ("1".equals(sex) || "女".equals(sex))) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());

                projectScore1.setApplySex(1);

                if (ObjectUtil.isEmpty(oneMinuteSitUp)) {
                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setStudentId(stuId);
                    build.setProjectRank("未参加测试");
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                } else {
                    projectScore1.setResult(new BigDecimal(oneMinuteSitUp));
                    projectScore1.setProjectId(id1);
                    EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                    //单项得分
                    Integer score1 = projectScore.getScore();
                    //单项得分的等级
                    String rank = projectScore.getRank();

                    EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                    build.setSchoolId(schoolId);
                    build.setSchoolName(schoolName);
                    build.setGradeId(gradeId);
                    build.setGradeName(gradeName);
                    build.setClassId(classId);
                    build.setClassName(className);
                    build.setGradeResultId(id);
                    build.setStudentNum(idcard);
                    build.setProjectId(id1);
                    build.setProjectName(projectName);
                    build.setProjectResult(oneMinuteSitUp);
                    build.setProjectScore(new BigDecimal(score1));
                    build.setProjectRank(rank);
                    build.setStudentId(stuId);
                    //保存该条数据
                    eduStudentProjectTestResultMapper.insert(build);
                    //查询该条数据的权重,传入年级id,项目id获取对应的权重
                    totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
                }
            }
            //1000米跑
            else if (id1 == 20 && ("0".equals(sex) || "男".equals(sex))) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());

                projectScore1.setApplySex(0);
                projectScore1.setResult(meterRace10001);
                projectScore1.setProjectId(id1);
                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                //单项得分
                Integer score1 = projectScore.getScore();
                //单项得分的等级
                String rank = projectScore.getRank();

                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                build.setSchoolId(schoolId);
                build.setSchoolName(schoolName);
                build.setGradeId(gradeId);
                build.setGradeName(gradeName);
                build.setClassId(classId);
                build.setClassName(className);
                build.setGradeResultId(id);
                build.setStudentNum(idcard);
                build.setProjectId(id1);
                build.setProjectName(projectName);
                build.setProjectResult(meterRace1000);
                build.setProjectScore(new BigDecimal(score1));
                build.setProjectRank(rank);
                build.setStudentId(stuId);
                //保存该条数据
                eduStudentProjectTestResultMapper.insert(build);
                //查询该条数据的权重,传入年级id,项目id获取对应的权重
                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
            }
            //800米跑
            else if (id1 == 21 && ("1".equals(sex) || "女".equals(sex))) {
                //计算获得的分数,传入年级和性别和数值和项目id计算该项的得分
                //查询BMI的得分(sql去查询)
                EduNationalStandardProjectScore projectScore1 = new EduNationalStandardProjectScore();
                projectScore1.setRecordGradeId(coreGradeId.longValue());
                projectScore1.setApplySex(1);

                projectScore1.setResult(meterRace8001);
                projectScore1.setProjectId(id1);
                EduNationalStandardProjectScore projectScore = eduNationalStandardProjectScoreMapper.findScoreBySexAndGradeIdAndProjectIdAndResult(projectScore1);
                //单项得分
                Integer score1 = projectScore.getScore();
                //单项得分的等级
                String rank = projectScore.getRank();
                EduStudentProjectTestResult build = new EduStudentProjectTestResult();
                build.setSchoolId(schoolId);
                build.setSchoolName(schoolName);
                build.setGradeId(gradeId);
                build.setGradeName(gradeName);
                build.setClassId(classId);
                build.setClassName(className);
                build.setGradeResultId(id);
                build.setStudentNum(idcard);
                build.setProjectId(id1);
                build.setProjectName(projectName);
                build.setProjectResult(meterRace800);
                build.setProjectScore(new BigDecimal(score1));
                build.setProjectRank(rank);
                build.setStudentId(stuId);
                //保存该条数据
                eduStudentProjectTestResultMapper.insert(build);
                //查询该条数据的权重,传入年级id,项目id获取对应的权重
                totalScore = totalScore.add(projectProportion.multiply(new BigDecimal(score1)));
            }
        }

        coreStudentPhysicalExaminationGradeResults.setTotalScore(totalScore);
        EduScoreRank rankByScore = eduScoreRankMapper.findRankByScore(totalScore);
        coreStudentPhysicalExaminationGradeResults.setTotalRank(rankByScore.getRankName());
        saveOrUpdate(coreStudentPhysicalExaminationGradeResults);
    }

    private Integer getExtraScore(String sex, BigDecimal extraData, Long id1, Integer coreGradeId) {
        EduNationalStandardProjectScore projectScore2 = new EduNationalStandardProjectScore();
        projectScore2.setRecordGradeId(coreGradeId.longValue());
        if ("0".equals(sex)) {
            projectScore2.setApplySex(0);
        } else if ("1".equals(sex)) {
            projectScore2.setApplySex(1);
        } else if ("男".equals(sex)) {
            projectScore2.setApplySex(0);
        } else if ("女".equals(sex)) {
            projectScore2.setApplySex(1);
        }
        projectScore2.setResult(extraData);
        projectScore2.setProjectId(id1);
        EduNationalStandardProjectExtraAddScore extraScoreBySexAndGradeIdAndProjectIdAndResult = eduNationalStandardProjectExtraAddScoreMapper.findExtraScoreBySexAndGradeIdAndProjectIdAndResult(projectScore2);
        return extraScoreBySexAndGradeIdAndProjectIdAndResult.getScore();

    }

    public static BigDecimal convertToSecond(String time) {
        if (ObjectUtil.isEmpty(time)) {
            return new BigDecimal(0);
        }
        if ("/".equals(time)) {
            return new BigDecimal(0);
        }
        if (!time.contains("'")) {
            return new BigDecimal(time);
        }
        if (time.contains("分")) {
            String[] timeArr = time.split("分");
            String minutes = timeArr[0];
            String seconds = timeArr[1];
            String second = seconds.replaceAll("\"", "");
            return new BigDecimal(Integer.parseInt(minutes) * 60 + Integer.parseInt(second));
        }
        String[] timeArr = time.split("'");
        String minutes = timeArr[0];
        String seconds = timeArr[1];
        String second = seconds.replaceAll("\"", "");
        return new BigDecimal(Integer.parseInt(minutes) * 60 + Integer.parseInt(second));
    }

}
