| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- 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.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.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.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.SimpleDateFormat;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- 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())
- .disableSubLogicDel();
- 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){
- Long classId = Long.parseLong(c.getClassId());
- if(individualBehaviorMap.get(classId) != null){
- c.setStuPersonalBehaviorSubScore(individualBehaviorMap.get(classId).getSumScore());
- c.setStuPersonalBehaviorScore((100 + individualBehaviorMap.get(classId).getSumScore())/100*25);
- }
- if(conventionalManagementMap.get(classId) != null){
- QuantitativeAssessmentSingleScoreVo scoreVo = conventionalManagementMap.get(classId);
- c.setClassConventionalManageSubScore(conventionalManagementMap.get(classId).getSumScore());
- c.setClassConventionalManageScore((100 + conventionalManagementMap.get(classId).getSumScore())/100*25);
- }
- if(awardsAndHonorableMap.get(classId) != null){
- c.setHonorSumScore(awardsAndHonorableMap.get(classId).getSumScore());
- if(awardsAndHonorableMap.get(classId).getSumScore() < 10){
- c.setHonorScore(awardsAndHonorableMap.get(classId).getSumScore());
- }else {
- c.setHonorScore(10D);
- }
- }
- if(c.getClassStatus() != null){
- if(c.getClassStatus() == 1){
- c.setClassStatusCn("在读");
- }
- if(c.getClassStatus() == 2){
- c.setClassStatusCn("毕业");
- }
- }
- if(classEvaluateMap.containsKey(classId)){
- Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
- int evaluateItemSize = 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())).setScale(2, RoundingMode.HALF_UP).doubleValue();
- evaluateSocreList.add(avgScore);
- }
- double jskhValue = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
- 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);
- }
- }
- }
- }
- //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())
- .disableSubLogicDel();
- 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());
- c.setStuPersonalBehaviorScore((100 + individualBehaviorMap.get(classId).getSumScore())/100*25);
- /* ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
- String geRenXingWeiGongShi = "sumSubScore/itemCount";
- int totalScore = scoreBySubmitRecordId.get(mobileResultPageVo.getEvaluateSubmitRecordId()).getTotalScore();
- int itemCount = scoreBySubmitRecordId.get(mobileResultPageVo.getEvaluateSubmitRecordId()).getItemCount();
- double res = 0;
- String newStr1 = zonghezhishu.replace("totalScore", ""+totalScore);
- String newStr2 = newStr1.replace("itemCount", ""+itemCount);
- try{
- res = Double.parseDouble(engine.eval(newStr2).toString());
- }catch (ScriptException s){
- }
- // 创建一个DecimalFormat对象,指定小数位数为两位
- DecimalFormat decimalFormat = new DecimalFormat("#.00");
- // 格式化double值为字符串
- String formattedNumber = decimalFormat.format(res);*/
- }
- if(conventionalManagementMap.get(classId) != null){
- c.setClassConventionalManageSubScore(conventionalManagementMap.get(classId).getSumScore());
- Double SumScore = 0D;
- if(conventionalManagementMap.get(classId).getSumScore() != null){
- SumScore = conventionalManagementMap.get(classId).getSumScore();
- }
- c.setClassConventionalManageScore((100 + SumScore)/100*25);
- }
- if(awardsAndHonorableMap.get(classId) != null){
- c.setHonorSumScore(awardsAndHonorableMap.get(classId).getSumScore());
- if(awardsAndHonorableMap.get(classId).getSumScore() < 10){
- c.setHonorScore(awardsAndHonorableMap.get(classId).getSumScore());
- }else {
- c.setHonorScore(10D);
- }
- }
- if(classEvaluateMap.containsKey(classId)){
- Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
- int evaluateItemSize = 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())).setScale(2, RoundingMode.HALF_UP).doubleValue();
- evaluateSocreList.add(avgScore);
- }
- double jskhValue = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
- 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);
- }
- }
- }
- }
- 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;
- }
- }
|