package com.xjrsoft.module.student.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.toolkit.MPJWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.xjrsoft.common.enums.AssessmentTypeEnum;
import com.xjrsoft.common.enums.EvaluateTypeEnum;
import com.xjrsoft.common.enums.ScoreTypeEnum;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
import com.xjrsoft.module.attendance.entity.AttendanceStatistics;
import com.xjrsoft.module.base.entity.BaseClass;
import com.xjrsoft.module.base.mapper.BaseClassMapper;
import com.xjrsoft.module.evaluate.dto.TeaEvaluateClassDto;
import com.xjrsoft.module.evaluate.mapper.EvaluateResultMapper;
import com.xjrsoft.module.evaluate.vo.TeaEvaluateClassListVo;
import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
import com.xjrsoft.module.organization.entity.User;
import com.xjrsoft.module.organization.service.IUserService;
import com.xjrsoft.module.organization.service.IWeChatService;
import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionMobilePageDto;
import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionPageDto;
import com.xjrsoft.module.student.dto.CalssQuantitativeAssessmentPageDto;
import com.xjrsoft.module.student.dto.QuantitativeAssessmentExcelDto;
import com.xjrsoft.module.student.dto.QuantitativeAssessmentSingleScoreDto;
import com.xjrsoft.module.student.entity.BaseClassMajorSet;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentCategory;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentClassRelation;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentInspection;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentProject;
import com.xjrsoft.module.student.entity.BaseStudentAssessmentStudentRelation;
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
import com.xjrsoft.module.student.mapper.BaseStudentAssessmentCategoryMapper;
import com.xjrsoft.module.student.mapper.BaseStudentAssessmentClassRelationMapper;
import com.xjrsoft.module.student.mapper.BaseStudentAssessmentInspectionMapper;
import com.xjrsoft.module.student.mapper.BaseStudentAssessmentProjectMapper;
import com.xjrsoft.module.student.mapper.BaseStudentAssessmentStudentRelationMapper;
import com.xjrsoft.module.student.mapper.BaseStudentSchoolRollMapper;
import com.xjrsoft.module.student.service.IBaseStudentAssessmentInspectionService;
import com.xjrsoft.module.student.service.IQuotaFormulaRuleService;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentClassListVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobilePageVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobileVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionPageVo;
import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionVo;
import com.xjrsoft.module.student.vo.CalssQuantitativeAssessmentPageVo;
import com.xjrsoft.module.student.vo.QuantitativeAssessmentSingleScoreVo;
import com.xjrsoft.module.student.vo.QuantitativeAssessmentSubTableExcelVo;
import com.xjrsoft.module.system.entity.File;
import com.xjrsoft.module.system.service.IFileService;
import com.xjrsoft.module.teacher.entity.XjrUser;
import lombok.AllArgsConstructor;
import me.zhyd.oauth.log.Log;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @title: 学生班级巡查考核
 * @Author dzx
 * @Date: 2023-11-16
 * @Version 1.0
 */
@Service
@AllArgsConstructor
public class BaseStudentAssessmentInspectionServiceImpl extends MPJBaseServiceImpl<BaseStudentAssessmentInspectionMapper, BaseStudentAssessmentInspection> implements IBaseStudentAssessmentInspectionService {

    private final BaseStudentAssessmentInspectionMapper assessmentInspectionMapper;

    private final BaseStudentAssessmentCategoryMapper categoryMapper;

    private final BaseStudentAssessmentProjectMapper projectMapper;

    private final BaseStudentAssessmentStudentRelationMapper assessmentStudentRelationMapper;

    private final BaseStudentAssessmentClassRelationMapper assessmentClassRelationMapper;

    private final BaseClassMapper baseClassMapper;

    private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;

    private final IFileService fileService;

    private final IUserService userService;

    private final IWeChatService weChatService;

    private final EvaluateResultMapper evaluateResultMapper;

    private final IQuotaFormulaRuleService quotaFormulaRuleService;

    @Override
    public Page<BaseStudentAssessmentInspectionPageVo> getPage(Page<BaseStudentAssessmentInspectionPageDto> page, BaseStudentAssessmentInspectionPageDto dto) {
        Page<BaseStudentAssessmentInspectionPageVo> result = assessmentInspectionMapper.getPage(page, dto);
        // 处理加减分
        result.getRecords().forEach((node) -> {
            if (node.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
                node.setScore(node.getScore() * -1);
            }
        });
        return result;
    }

    @Override
    public BaseStudentAssessmentInspectionVo getInfo(Long id) {
        BaseStudentAssessmentInspectionVo result = assessmentInspectionMapper.getInfo(id);
        // 处理加减分
        if (result.getScoreType() != null && result.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
            result.setScore(result.getScore() * -1);
        }

        // 获取班级信息
        List<BaseStudentAssessmentClassListVo> baseStudentAssessmentClassListVos = assessmentClassRelationMapper.selectJoinList(BaseStudentAssessmentClassListVo.class,
                MPJWrappers.<BaseStudentAssessmentClassRelation>lambdaJoin()
                        .leftJoin(BaseClass.class, BaseClass::getId, BaseStudentAssessmentClassRelation::getClassId)
                        .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
                        .eq(BaseStudentAssessmentClassRelation::getBaseStudentAssessmentInspectionId, id)
                        .select(BaseStudentAssessmentClassRelation::getId)
                        .selectAs(BaseClass::getName, BaseStudentAssessmentClassListVo::getClassName)
                        .selectAs(XjrUser::getName, BaseStudentAssessmentClassListVo::getTeacherName)
                        .selectAs(XjrUser::getMobile, BaseStudentAssessmentClassListVo::getMobile)
                        .select(BaseStudentAssessmentClassRelation.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentAssessmentClassRelation.class).contains(x.getProperty()))
        );
        result.setClassList(baseStudentAssessmentClassListVos);

        // 获取学生信息
        result.setStudentList(assessmentInspectionMapper.getStudentListByInspectionId(id));

        // 获取文件列表
        result.setFileInfos(fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, result.getFileId())));

        return result;
    }

    @Override
    public Page<BaseStudentAssessmentInspectionMobilePageVo> getMobilePage(Page<BaseStudentAssessmentInspectionMobilePageDto> page, BaseStudentAssessmentInspectionMobilePageDto dto) {
        if (dto.getClassIds() == null || dto.getClassIds().size() == 0) {
            // 获取当前用户所管班级
            List<Long> classIds = baseClassMapper.selectList(
                    Wrappers.<BaseClass>query().lambda()
                            .eq(BaseClass::getTeacherId, StpUtil.getLoginIdAsLong())
                            .select(BaseClass::getId)
            ).stream().map(BaseClass::getId).collect(Collectors.toList());
            dto.setClassIds(classIds);
        }
        if (dto.getClassIds() == null || dto.getClassIds().size() == 0) {
            return null;
        }
        Page<BaseStudentAssessmentInspectionMobilePageVo> result = assessmentInspectionMapper.getMobilePage(page, dto);
        // 处理加减分
        result.getRecords().forEach((node) -> {
            if (node.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
                node.setScore(node.getScore() * -1);
            }
        });
        return result;
    }

    @Override
    public BaseStudentAssessmentInspectionMobileVo getMobileInfo(Long id) {
        BaseStudentAssessmentInspectionMobileVo result = assessmentInspectionMapper.getMobileInfo(id);
        // 处理加减分
        if (result.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
            result.setScore(result.getScore() * -1);
        }

        // 获取学生信息
        List<BaseStudentAssessmentStudentRelation> baseStudentAssessmentStudentRelations = assessmentStudentRelationMapper.selectList(
                Wrappers.<BaseStudentAssessmentStudentRelation>query().lambda()
                        .eq(BaseStudentAssessmentStudentRelation::getBaseStudentAssessmentInspectionId, result.getBaseStudentAssessmentInspectionId())
                        .eq(BaseStudentAssessmentStudentRelation::getClassId, result.getClassId())
        );
        result.setStudentList(baseStudentAssessmentStudentRelations);
        result.setStudentCount(baseStudentAssessmentStudentRelations.size());

        // 获取文件列表
        result.setFileInfos(fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, result.getFileId())));

        return result;
    }

    @Override
    public ResponseEntity<byte[]> getQuantitativeAssessmentExcelByte(QuantitativeAssessmentExcelDto dto) {
        //导出的文件名，字节流
        String fileName = "StudentAssessmentInspection" + ExcelTypeEnum.XLSX.getValue();
        ByteArrayOutputStream bot = new ByteArrayOutputStream();

        //获取需要导出的子表
        List<Long> baseStudentAssessmentCategoryIdList = new ArrayList<>();
        baseStudentAssessmentCategoryIdList.add(1768178717588197377L);
        baseStudentAssessmentCategoryIdList.add(1768179375900987394L);
        baseStudentAssessmentCategoryIdList.add(1769927649167151105L);

        LambdaQueryWrapper<BaseStudentAssessmentCategory> baseStudentAssessmentCategoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseStudentAssessmentCategoryLambdaQueryWrapper
                .in(BaseStudentAssessmentCategory::getId, baseStudentAssessmentCategoryIdList);
        List<BaseStudentAssessmentCategory> baseStudentAssessmentCategorieList = categoryMapper.selectList(baseStudentAssessmentCategoryLambdaQueryWrapper);

        //导出子表
        if(baseStudentAssessmentCategorieList.size() > 0){
            //需要合并的列
            int[] mergeColumeIndex = {0, 1, 2, 3, 4};
            ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(1, mergeColumeIndex);

            //开始处理写入
            try (ExcelWriter excelWriter = EasyExcel.write(bot, QuantitativeAssessmentSubTableExcelVo.class).registerWriteHandler(excelFillCellMergeStrategy).build()) {
                int no = 1;
                for (BaseStudentAssessmentCategory bsac : baseStudentAssessmentCategorieList) {
                    dto.setBaseStudentAssessmentCategoryId(bsac.getId());
                    //sheet名
                    String sheetName = bsac.getName();

                    WriteSheet writeSheet = EasyExcel.writerSheet(no++, sheetName ).build();

                    //求所有的个人行为集合
                    List<QuantitativeAssessmentSubTableExcelVo> quantitativeAssessmentSubTableExcelVoList = assessmentInspectionMapper.getQuantitativeAssessmentSubTableExcelVoList(dto);

                    excelWriter.write(quantitativeAssessmentSubTableExcelVoList, writeSheet);
                }
                //TODO 班级量化考核统计表总
                //以班级为数据的基础进行数据的填充
                MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
                baseClassMPJLambdaWrapper
                        .selectAs(BaseClass::getTeacherId, CalssQuantitativeAssessmentPageVo::getHeadTeacherId)
                        .selectAs(XjrUser::getUserName, CalssQuantitativeAssessmentPageVo::getOa)
                        .selectAs(XjrUser::getName, CalssQuantitativeAssessmentPageVo::getHeadTeacherName)
                        .selectAs(BaseClass::getId, CalssQuantitativeAssessmentPageVo::getClassId)
                        .selectAs(BaseClass::getName, CalssQuantitativeAssessmentPageVo::getClassName)
                        .selectAs(BaseClassMajorSet::getTotalStudent, CalssQuantitativeAssessmentPageVo::getStudentNum)
                        .selectAs(BaseClass::getIsGraduate, CalssQuantitativeAssessmentPageVo::getClassStatus)
                        .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
                        .leftJoin(BaseClassMajorSet.class, BaseClassMajorSet::getClassId, BaseClass::getId)
                        .eq(dto.getGradeId() != null, BaseClass::getGradeId, dto.getGradeId())
                        .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
                        .eq(dto.getClassStatus() != null, BaseClass::getIsGraduate, dto.getClassStatus())
                        .like(dto.getName() != null && !dto.getName().equals(""), XjrUser::getName, dto.getName());

                List<CalssQuantitativeAssessmentPageVo> resultList = baseClassMapper.selectJoinList(CalssQuantitativeAssessmentPageVo.class, baseClassMPJLambdaWrapper);

                //当前数据记录班级id
                List<Long> classIdList = new ArrayList<>();
                for(CalssQuantitativeAssessmentPageVo c: resultList){
                    classIdList.add(Long.parseLong(c.getClassId()));
                }
                dto.setClassIdList(classIdList);

                if(dto.getStartTime() != null){
                    // 获取上个月的最后一秒
                    LocalDateTime lastMonthEnd = dto.getStartTime().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);

                    // 获取下个月的第一秒
                    LocalDateTime nextMonthStart = dto.getStartTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
                    dto.setStartTime(lastMonthEnd);
                    dto.setEndTime(nextMonthStart);
                }

                if(!classIdList.isEmpty()){
                    CalssQuantitativeAssessmentPageDto calssQuantitativeAssessmentPageDto = new CalssQuantitativeAssessmentPageDto();
                    BeanUtils.copyProperties(dto, calssQuantitativeAssessmentPageDto);

                    //学生个人行为
                    dto.setBaseStudentAssessmentCategoryId(1768178717588197377L);
                    Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);

                    //常规管理
                    dto.setBaseStudentAssessmentCategoryId(1769927649167151105L);
                    Map<Long , QuantitativeAssessmentSingleScoreVo> conventionalManagementMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);

                    //获奖及荣誉奖彰
                    dto.setBaseStudentAssessmentCategoryId(1768179375900987394L);
                    Map<Long , QuantitativeAssessmentSingleScoreVo> awardsAndHonorableMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);

                    //准军事化考核
                    List<QuantitativeAssessmentSingleScoreVo> paramilitaryList = assessmentInspectionMapper.getParamilitaryList(new QuantitativeAssessmentSingleScoreDto(){{
                        setClassIdList(classIdList);
                    }});
                    Map<Long , QuantitativeAssessmentSingleScoreVo> paramilitaryMap = new HashMap<>();
                    for (QuantitativeAssessmentSingleScoreVo q : paramilitaryList) {
                        awardsAndHonorableMap.put(q.getClassId(), q);
                    }

                    //查询任课教师查询班级的数据
                    TeaEvaluateClassDto evaluateClassDto = new TeaEvaluateClassDto();
                    evaluateClassDto.setEvaluateType(EvaluateTypeEnum.TEACHER_EVALUATE_CLASS.getCode());
                    evaluateClassDto.setYear(dto.getYear());
                    LocalDate now = LocalDate.now();
                    if(dto.getYear() == null){
                        evaluateClassDto.setYear(now.getYear());
                    }
                    evaluateClassDto.setMonth(dto.getMonth());
                    if(dto.getMonth() == null){
                        evaluateClassDto.setMonth(now.getMonthValue());
                    }
                    List<TeaEvaluateClassListVo> teaEvaluateClassList = evaluateResultMapper.getTeaEvaluateClassList(evaluateClassDto);
                    Map<Long, List<TeaEvaluateClassListVo>> classEvaluateMap = teaEvaluateClassList.stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getEvaluatedObjectId));
                    String jskhFormula = quotaFormulaRuleService.getFormulaByQuota("teacher_assessment");

                    //将结果写进对应的班级里
                    for(CalssQuantitativeAssessmentPageVo c: resultList){
                        if(c.getOa() == null){
                            c.setOa(" ");
                        }
                        if(c.getHeadTeacherName() == null){
                            c.setHeadTeacherName(" ");
                        }
                        Long classId = Long.parseLong(c.getClassId());
                        c.setStuPersonalBehaviorSubScore(" ");
                        c.setStuPersonalBehaviorScore(" ");
                        if(individualBehaviorMap.get(classId) != null){
                            Double sumScore = individualBehaviorMap.get(classId).getSumScore();
                            if(sumScore != null){
                                c.setStuPersonalBehaviorSubScore(sumScore.toString());
                                double v = (100 + sumScore) / 100 * 25;
                                c.setStuPersonalBehaviorScore(v + "");
                            }
                        }

                        c.setClassConventionalManageSubScore(" ");
                        c.setClassConventionalManageScore(" ");
                        if(conventionalManagementMap.get(classId) != null){
                            Double sumScore = conventionalManagementMap.get(classId).getSumScore();
                            if(sumScore != null){
                                c.setClassConventionalManageSubScore(sumScore.toString());
                                double v = (100 + sumScore) / 100 * 25;
                                c.setClassConventionalManageScore(v + "");
                            }
                        }

                        c.setHonorSumScore(" ");
                        c.setHonorScore(" ");
                        if(awardsAndHonorableMap.get(classId) != null){
                            Double sumScore = awardsAndHonorableMap.get(classId).getSumScore();
                            if(sumScore != null){
                                c.setHonorSumScore(sumScore.toString());
                                if(sumScore < 10){
                                    c.setHonorScore(sumScore.toString());
                                }else {
                                    c.setHonorScore("10");
                                }
                            }
                        }

                        if(c.getClassStatus() != null){
                            if(c.getClassStatus() == 1){
                                c.setClassStatusCn("在读");
                            }
                            if(c.getClassStatus() == 2){
                                c.setClassStatusCn("毕业");
                            }
                        }

                        c.setTeacherAssessComprehensiveIndex(" ");
                        c.setTeacherAssessScore(" ");
                        if(classEvaluateMap.containsKey(classId)){
                            Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
                            int size = evaluateCategoryMap.size();

                            List<Double> evaluateSocreList = new ArrayList<>();//存每个项的平均分
                            for (Long id : evaluateCategoryMap.keySet()) {
                                List<TeaEvaluateClassListVo> evaluateList = evaluateCategoryMap.get(id);
                                int allSorce = evaluateList.stream().mapToInt(TeaEvaluateClassListVo::getScore).sum();
                                double avgScore = BigDecimal.valueOf(allSorce).divide(BigDecimal.valueOf(resultList.size()),2, RoundingMode.HALF_UP).doubleValue();
                                evaluateSocreList.add(avgScore);
                            }

                            double sum = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
                            double jskhValue = BigDecimal.valueOf(sum).divide(BigDecimal.valueOf(size),2, RoundingMode.HALF_UP).doubleValue();
                            c.setTeacherAssessComprehensiveIndex(jskhValue + "");
                            String replacedExpression = jskhFormula.replace("JSKH", Double.toString(jskhValue));

                            ScriptEngineManager manager = new ScriptEngineManager();
                            ScriptEngine engine = manager.getEngineByName("JavaScript");
                            try {
                                double result = ((Number) engine.eval(replacedExpression)).doubleValue();
                                c.setTeacherAssessScore(result + " ");
                            } catch (ScriptException e) {
                                Log.error(e.getMessage(), e);
                            }
                        }

                        c.setMilitaryManageScore(" ");
                        c.setMilitaryManageComprehensiveIndex(" ");
                        c.setAssessMoney(" ");
                        c.setAssessSumScore(" ");
                    }
                }
                //sheet名
                String sheetName = "量化考核总表";

                WriteSheet writeSheet = EasyExcel.writerSheet(0, sheetName ).build();
//
                excelWriter.write(resultList, writeSheet);
            }
            /*for (BaseStudentAssessmentCategory bsac : baseStudentAssessmentCategorieList) {
                dto.setBaseStudentAssessmentCategoryId(bsac.getId());
                //sheet名
                String sheetName = bsac.getName();

                //求所有的个人行为集合
                List<QuantitativeAssessmentSubTableExcelVo> quantitativeAssessmentSubTableExcelVoList = assessmentInspectionMapper.getQuantitativeAssessmentSubTableExcelVoList(dto);

                //需要合并的列
                int[] mergeColumeIndex = {0, 1, 2, 3, 4};

                //写字节流
                ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(1, mergeColumeIndex);
                EasyExcel.write(bot, QuantitativeAssessmentSubTableExcelVo.class)
                        .registerWriteHandler(excelFillCellMergeStrategy)
                        .sheet(sheetName)
                        .doWrite(quantitativeAssessmentSubTableExcelVoList);
            }*/
        }

        return RT.fileStream(bot.toByteArray(), fileName);
    }

    @Override
    public IPage<CalssQuantitativeAssessmentPageVo> getCalssQuantitativeAssessmentPage(Page<CalssQuantitativeAssessmentPageDto> page, CalssQuantitativeAssessmentPageDto dto) {
        //以班级为数据的基础进行数据的填充
        MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
        baseClassMPJLambdaWrapper
                .selectAs(BaseClass::getTeacherId, CalssQuantitativeAssessmentPageVo::getHeadTeacherId)
                .selectAs(XjrUser::getUserName, CalssQuantitativeAssessmentPageVo::getOa)
                .selectAs(XjrUser::getName, CalssQuantitativeAssessmentPageVo::getHeadTeacherName)
                .selectAs(BaseClass::getId, CalssQuantitativeAssessmentPageVo::getClassId)
                .selectAs(BaseClass::getName, CalssQuantitativeAssessmentPageVo::getClassName)
                .selectAs(BaseClassMajorSet::getTotalStudent, CalssQuantitativeAssessmentPageVo::getStudentNum)
                .selectAs(BaseClass::getIsGraduate, CalssQuantitativeAssessmentPageVo::getClassStatus)
                .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
                .leftJoin(BaseClassMajorSet.class, BaseClassMajorSet::getClassId, BaseClass::getId)
                .eq(dto.getGradeId() != null, BaseClass::getGradeId, dto.getGradeId())
                .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
                .eq(dto.getClassStatus() != null, BaseClass::getIsGraduate, dto.getClassStatus())
                .like(dto.getName() != null && !dto.getName().equals(""), XjrUser::getName, dto.getName());

        IPage<CalssQuantitativeAssessmentPageVo> resultPage = baseClassMapper.selectJoinPage(page, CalssQuantitativeAssessmentPageVo.class, baseClassMPJLambdaWrapper);

        //当前数据记录班级id
        List<Long> classIdList = new ArrayList<>();
        for(CalssQuantitativeAssessmentPageVo c: resultPage.getRecords()){
            classIdList.add(Long.parseLong(c.getClassId()));
        }
        dto.setClassIdList(classIdList);

        if(dto.getStartTime() != null){
            // 获取上个月的最后一秒
            LocalDateTime lastMonthEnd = dto.getStartTime().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);

            // 获取下个月的第一秒
            LocalDateTime nextMonthStart = dto.getStartTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
            dto.setStartTime(lastMonthEnd);
            dto.setEndTime(nextMonthStart);
        }

        if(!classIdList.isEmpty()){
            //学生个人行为
            dto.setBaseStudentAssessmentCategoryId(1768178717588197377L);
            Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = getQuantitativeAssessmentSingleScoreMap(dto);

            //常规管理
            dto.setBaseStudentAssessmentCategoryId(1769927649167151105L);
            Map<Long , QuantitativeAssessmentSingleScoreVo> conventionalManagementMap = getQuantitativeAssessmentSingleScoreMap(dto);

            //获奖及荣誉奖彰
            dto.setBaseStudentAssessmentCategoryId(1768179375900987394L);
            Map<Long , QuantitativeAssessmentSingleScoreVo> awardsAndHonorableMap = getQuantitativeAssessmentSingleScoreMap(dto);

            //准军事化考核
            List<QuantitativeAssessmentSingleScoreVo> paramilitaryList = assessmentInspectionMapper.getParamilitaryList(new QuantitativeAssessmentSingleScoreDto(){{
                setClassIdList(classIdList);
            }});
            Map<Long , QuantitativeAssessmentSingleScoreVo> paramilitaryMap = new HashMap<>();
            for (QuantitativeAssessmentSingleScoreVo q : paramilitaryList) {
                awardsAndHonorableMap.put(q.getClassId(), q);
            }

            //查询任课教师查询班级的数据
            TeaEvaluateClassDto evaluateClassDto = new TeaEvaluateClassDto();
            evaluateClassDto.setEvaluateType(EvaluateTypeEnum.TEACHER_EVALUATE_CLASS.getCode());
            evaluateClassDto.setYear(dto.getYear());
            LocalDate now = LocalDate.now();
            if(dto.getYear() == null){
                evaluateClassDto.setYear(now.getYear());
            }
            evaluateClassDto.setMonth(dto.getMonth());
            if(dto.getMonth() == null){
                evaluateClassDto.setMonth(now.getMonthValue());
            }
            List<TeaEvaluateClassListVo> teaEvaluateClassList = evaluateResultMapper.getTeaEvaluateClassList(evaluateClassDto);
            Map<Long, List<TeaEvaluateClassListVo>> classEvaluateMap = teaEvaluateClassList.stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getEvaluatedObjectId));
            String jskhFormula = quotaFormulaRuleService.getFormulaByQuota("teacher_assessment");

            //将结果写进对应的班级里
            for(CalssQuantitativeAssessmentPageVo c: resultPage.getRecords()){
                Long classId = Long.parseLong(c.getClassId());
                if(individualBehaviorMap.get(classId) != null){
                    c.setStuPersonalBehaviorSubScore(individualBehaviorMap.get(classId).getSumScore()==null?"":individualBehaviorMap.get(classId).getSumScore().toString());
                    double v = (100 + individualBehaviorMap.get(classId).getSumScore()) / 100 * 25;
                    c.setStuPersonalBehaviorScore(v + "");
                }

                if(conventionalManagementMap.get(classId) != null){
                    Double sumScore = conventionalManagementMap.get(classId).getSumScore();
                    if(sumScore != null){
                        String scoreStr = sumScore.toString();
//                    boolean isInteger = sumScore == Math.floor(sumScore);
//                    if(isInteger){
//                        scoreStr = sumScore.intValue() + "";
//                    }
                        c.setClassConventionalManageSubScore(scoreStr);

                        double v = (100 + sumScore) / 100 * 25;
                        c.setClassConventionalManageScore(v + "");
                    }
                }

                if(awardsAndHonorableMap.get(classId) != null){
                    Double sumScore = awardsAndHonorableMap.get(classId).getSumScore();
                    if(sumScore != null){
                        c.setHonorSumScore(sumScore.toString());
                        if(sumScore < 10){
                            c.setHonorScore(sumScore.toString());
                        }else {
                            c.setHonorScore("10");
                        }
                    }
                }

                if(classEvaluateMap.containsKey(classId)){
                    Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
                    int size = evaluateCategoryMap.size();
                    List<Double> evaluateSocreList = new ArrayList<>();//存每个项的平均分
                    for (Long id : evaluateCategoryMap.keySet()) {
                        List<TeaEvaluateClassListVo> resultList = evaluateCategoryMap.get(id);
                        int allSorce = resultList.stream().mapToInt(TeaEvaluateClassListVo::getScore).sum();
                        double avgScore = BigDecimal.valueOf(allSorce).divide(BigDecimal.valueOf(resultList.size()), 2, RoundingMode.HALF_UP).doubleValue();
                        evaluateSocreList.add(avgScore);
                    }
                    double sum = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
                    double jskhValue = BigDecimal.valueOf(sum).divide(BigDecimal.valueOf(size),2, RoundingMode.HALF_UP).doubleValue();
                    c.setTeacherAssessComprehensiveIndex(jskhValue + "");
                    String replacedExpression = jskhFormula.replace("JSKH", Double.toString(jskhValue));

                    ScriptEngineManager manager = new ScriptEngineManager();
                    ScriptEngine engine = manager.getEngineByName("JavaScript");
                    try {
                        double result = ((Number) engine.eval(replacedExpression)).doubleValue();
                        c.setTeacherAssessScore(BigDecimal.valueOf(result).setScale(2, RoundingMode.HALF_UP).doubleValue() + "");
                    } catch (ScriptException e) {
                        Log.error(e.getMessage(), e);
                    }
                }
            }
        }

        return resultPage;
    }

    private Map<Long, QuantitativeAssessmentSingleScoreVo> getQuantitativeAssessmentSingleScoreMap(CalssQuantitativeAssessmentPageDto dto){
        List<QuantitativeAssessmentSingleScoreVo> individualBehaviorList = assessmentInspectionMapper.getAssessmentInspectionByClassIdList(new QuantitativeAssessmentSingleScoreDto(){{
            setClassIdList(dto.getClassIdList());
            setBaseStudentAssessmentCategoryId(dto.getBaseStudentAssessmentCategoryId());
            if(dto.getBaseSemesterId() != null){
                setBaseSemesterId(dto.getBaseSemesterId());
            }
            if(dto.getStartTime() != null){
                setStartTime(dto.getStartTime());
            }
            if(dto.getEndTime() != null){
                setStartTime(dto.getEndTime());
            }
        }});
        Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = new HashMap<>();
        for (QuantitativeAssessmentSingleScoreVo q : individualBehaviorList) {
            if(q.getClassId() != null){
                individualBehaviorMap.put(q.getClassId(), q);
            }
        }
       return individualBehaviorMap;
    }

    @Override
    @Transactional
    public Boolean dataHandle(Long id) {
        //获取考核记录
        BaseStudentAssessmentInspection baseStudentAssessmentInspection = this.getById(id);
        if(baseStudentAssessmentInspection != null){
            double totalScore = 0d;
            if(StrUtil.isNotEmpty(baseStudentAssessmentInspection.getClassIds())) {
                //同步数据到考核关联班级表
                String[] classIds = baseStudentAssessmentInspection.getClassIds().split(",");
                for (String classId : classIds) {
                    assessmentClassRelationMapper.insert(new BaseStudentAssessmentClassRelation() {{
                        setClassId(Long.parseLong(classId));
                        setBaseStudentAssessmentInspectionId(baseStudentAssessmentInspection.getId());
                        QueryWrapper<BaseStudentAssessmentClassRelation> queryWrapperSortcode = new QueryWrapper<>();
                        queryWrapperSortcode.select("IFNULL(MAX(sort_code),0) as sortCode");
                        BaseStudentAssessmentClassRelation b = assessmentClassRelationMapper.selectOne(queryWrapperSortcode);
                        setSortCode(b.getSortCode() + 1);
                    }});
                }
                totalScore = baseStudentAssessmentInspection.getScore();
            }
            //同步数据到考核关联学生表
            if(StrUtil.isNotEmpty(baseStudentAssessmentInspection.getPersonalStudentUserIds())){
                String[] studentIds = baseStudentAssessmentInspection.getPersonalStudentUserIds().split(",");
                for (String studentId: studentIds) {
                    assessmentStudentRelationMapper.insert(new BaseStudentAssessmentStudentRelation(){{
                        MPJLambdaWrapper<BaseStudentSchoolRoll> baseStudentSchoolRollMPJLambdaWrapper = new MPJLambdaWrapper<>();
                        baseStudentSchoolRollMPJLambdaWrapper
                                .select(BaseStudentSchoolRoll::getId)
                                .select(BaseStudentSchoolRoll.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentSchoolRoll.class).contains(x.getProperty()))
                                .eq(BaseStudentSchoolRoll::getUserId, studentId);
                        BaseStudentSchoolRoll baseStudentSchoolRoll = baseStudentSchoolRollMapper.selectOne(baseStudentSchoolRollMPJLambdaWrapper);
                        if(baseStudentSchoolRoll != null){
                            setClassId(baseStudentSchoolRoll.getClassId());
                        }
                        setUserId(Long.parseLong(studentId));
                        setBaseStudentAssessmentInspectionId(baseStudentAssessmentInspection.getId());
                        QueryWrapper<BaseStudentAssessmentStudentRelation> queryWrapperSortcode = new QueryWrapper<>();
                        queryWrapperSortcode.select("IFNULL(MAX(sort_code),0) as sortCode");
                        BaseStudentAssessmentStudentRelation b = assessmentStudentRelationMapper.selectOne(queryWrapperSortcode);
                        setSortCode(b.getSortCode() + 1);
                        setScore(baseStudentAssessmentInspection.getScore());

                    }});
                }

                totalScore = studentIds.length * baseStudentAssessmentInspection.getScore();
            }
            baseStudentAssessmentInspection.setTotalScore(totalScore);
            this.updateById(baseStudentAssessmentInspection);

        }
        return true;
    }

    @Override
    public Boolean noticeTeacher(Long id) {
        BaseStudentAssessmentInspection inspection = this.getById(id);
        String classIds = inspection.getClassIds();
        BaseClass baseClass = baseClassMapper.selectById(classIds);
        User user = userService.getById(baseClass.getTeacherId());
        String wechatTemplate = "Xb21V8au0Ur9puQs4hIDJTl8LP6GTgVOHQtOeie1Oco";

        WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
        weChatSendMessageDto.setUserId(user.getOpenId());
        weChatSendMessageDto.setTemplateId(wechatTemplate);
        weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");

        JSONObject data = new JSONObject();
        String thing4 = "";
        String thing1 = "";
        if(AssessmentTypeEnum.CLASS.getCode().equals(inspection.getAssessmentType())){
            data.put("const3", new JSONObject() {{
                put("value", AssessmentTypeEnum.CLASS.getValue());
            }});

            BaseStudentAssessmentProject project = projectMapper.selectById(inspection.getBaseStudentAssessmentProjectId());
            thing4 = project.getName();

        }else if(AssessmentTypeEnum.PERSONAL.getCode().equals(inspection.getAssessmentType())){
            data.put("const3", new JSONObject() {{
                put("value", AssessmentTypeEnum.PERSONAL.getValue());
            }});
            String[] studentUsers = inspection.getPersonalStudentUserIds().split(",");
            List<String> studentIds = new ArrayList<>();
            for (String studentUser : studentUsers) {
                studentIds.add(studentUser.trim());
            }
            List<User> userList = userService.listByIds(studentIds);
            for (int i = 0; i < userList.size(); i ++){
                if(i > 0){
                    thing1 += ",";
                }
                thing1 += userList.get(i).getName();
            }
            if(thing1.length() > 20){
                thing1 = thing1.substring(0, 16) + "...";
            }

            BaseStudentAssessmentCategory category = categoryMapper.selectById(inspection.getBaseStudentAssessmentCategoryId());
            thing4 = category.getName();
        }
        //得分
        JSONObject thing4Json = new JSONObject();
        thing4Json.put("value", thing4);
        data.put("thing4", thing4Json);

        //学生
        JSONObject thing1Json = new JSONObject();
        thing1Json.put("value", thing1);
        data.put("thing1", thing1Json);

        //得分
        data.put("character_string5", new JSONObject() {{
            put("value", inspection.getScore());
        }});

        //考核时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        data.put("time2", new JSONObject() {{
            put("value", sdf.format(inspection.getAssessmentDate()));
        }});

        weChatSendMessageDto.setContent(data);
        weChatService.sendTemplateMessage(weChatSendMessageDto);
        return true;
    }

    @Override
    public byte[] getExcelByte(CalssQuantitativeAssessmentPageDto dto) throws IOException {
        IPage<CalssQuantitativeAssessmentPageVo> page = this.getCalssQuantitativeAssessmentPage(new Page<>(1, 10000), dto);

        Workbook workbook = new XSSFWorkbook();
        // 创建一个工作表(sheet)
        String sheetName = "数据";
        Sheet sheet = workbook.createSheet(sheetName);
        createFirstTitle(workbook, sheet);
        createSecondTitle(workbook, sheet, 6);

        Font font = workbook.createFont();
        font.setBold(false);// 设置为粗体
        font.setFontName("宋体");
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font); // 将字体应用到样式
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        int sortCode = 1;
        for (CalssQuantitativeAssessmentPageVo pageVo : page.getRecords()) {
            Row dataRow = sheet.createRow(sortCode + 1);

            int columnNumber = 0;
            Cell cell = dataRow.createCell(columnNumber);
            cell.setCellValue(sortCode + "");
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getOa());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getClassName());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getHeadTeacherName());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getStudentNum().toString());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getClassStatusCn());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getStuPersonalBehaviorSubScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getStuPersonalBehaviorScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getClassConventionalManageSubScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getClassConventionalManageScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getHonorSumScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getHonorScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getMilitaryManageComprehensiveIndex());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getMilitaryManageScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getTeacherAssessComprehensiveIndex());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getTeacherAssessScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getAssessSumScore());
            cell.setCellStyle(cellStyle);

            columnNumber ++;
            cell = dataRow.createCell(columnNumber);
            cell.setCellValue(pageVo.getAssessMoney());
            cell.setCellStyle(cellStyle);

            sortCode ++;
        }

        ByteArrayOutputStream bot = new ByteArrayOutputStream();
        workbook.write(bot);
        return bot.toByteArray();
    }

    void createFirstTitle(Workbook workbook, Sheet sheet) {
        int rowNumber = 0;
        Font font = workbook.createFont();
        font.setFontName("宋体");
        //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
        font.setFontHeightInPoints((short)12);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font); // 将字体应用到样式
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);

        Row row = sheet.createRow(rowNumber);
        //3、处理表头
        int columnNumber = 0;
        Cell cell = row.createCell(columnNumber);
        cell.setCellValue("序号");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("工号");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("班级");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("班主任");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("人数");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("状态");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("学生个人行为");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, columnNumber, columnNumber + 1));
        columnNumber ++;

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("常规管理");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, columnNumber, columnNumber + 1));
        columnNumber ++;

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("获奖及荣誉奖章");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, columnNumber, columnNumber + 1));
        columnNumber ++;

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("准军事化管理效果");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, columnNumber, columnNumber + 1));
        columnNumber ++;

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("任课教师考核");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, columnNumber, columnNumber + 1));
        columnNumber ++;

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("月份总得分");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));

        columnNumber ++;
        cell = row.createCell(columnNumber);
        cell.setCellValue("月考核金额");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));
    }

    void createSecondTitle(Workbook workbook, Sheet sheet, int startColunm) {
        int rowNumber = 1;
        Font font = workbook.createFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short)12);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font); // 将字体应用到样式
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);

        Row row = sheet.createRow(rowNumber);

        int columnNumber = startColunm;
        Cell cell = row.createCell(columnNumber);
        cell.setCellValue("扣分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("此项得分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("扣分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("此项得分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("汇总");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("此项得分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("指数");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("此项得分");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("指数");
        cell.setCellStyle(cellStyle);
        columnNumber ++;

        cell = row.createCell(columnNumber);
        cell.setCellValue("此项得分");
        cell.setCellStyle(cellStyle);
    }
}
