BaseStudentAssessmentInspectionServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. package com.xjrsoft.module.student.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.util.IdUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.excel.EasyExcel;
  6. import com.alibaba.excel.ExcelWriter;
  7. import com.alibaba.excel.support.ExcelTypeEnum;
  8. import com.alibaba.excel.write.metadata.WriteSheet;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.baomidou.mybatisplus.core.metadata.IPage;
  13. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import com.github.yulichang.base.MPJBaseServiceImpl;
  16. import com.github.yulichang.toolkit.MPJWrappers;
  17. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  18. import com.xjrsoft.common.enums.AssessmentTypeEnum;
  19. import com.xjrsoft.common.enums.EvaluateTypeEnum;
  20. import com.xjrsoft.common.enums.ScoreTypeEnum;
  21. import com.xjrsoft.common.model.result.RT;
  22. import com.xjrsoft.common.utils.VoToColumnUtil;
  23. import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
  24. import com.xjrsoft.module.base.entity.BaseClass;
  25. import com.xjrsoft.module.base.mapper.BaseClassMapper;
  26. import com.xjrsoft.module.evaluate.dto.TeaEvaluateClassDto;
  27. import com.xjrsoft.module.evaluate.mapper.EvaluateResultMapper;
  28. import com.xjrsoft.module.evaluate.vo.TeaEvaluateClassListVo;
  29. import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
  30. import com.xjrsoft.module.organization.entity.User;
  31. import com.xjrsoft.module.organization.service.IUserService;
  32. import com.xjrsoft.module.organization.service.IWeChatService;
  33. import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionMobilePageDto;
  34. import com.xjrsoft.module.student.dto.BaseStudentAssessmentInspectionPageDto;
  35. import com.xjrsoft.module.student.dto.CalssQuantitativeAssessmentPageDto;
  36. import com.xjrsoft.module.student.dto.QuantitativeAssessmentExcelDto;
  37. import com.xjrsoft.module.student.dto.QuantitativeAssessmentSingleScoreDto;
  38. import com.xjrsoft.module.student.entity.BaseClassMajorSet;
  39. import com.xjrsoft.module.student.entity.BaseStudentAssessmentCategory;
  40. import com.xjrsoft.module.student.entity.BaseStudentAssessmentClassRelation;
  41. import com.xjrsoft.module.student.entity.BaseStudentAssessmentInspection;
  42. import com.xjrsoft.module.student.entity.BaseStudentAssessmentProject;
  43. import com.xjrsoft.module.student.entity.BaseStudentAssessmentStudentRelation;
  44. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  45. import com.xjrsoft.module.student.mapper.BaseStudentAssessmentCategoryMapper;
  46. import com.xjrsoft.module.student.mapper.BaseStudentAssessmentClassRelationMapper;
  47. import com.xjrsoft.module.student.mapper.BaseStudentAssessmentInspectionMapper;
  48. import com.xjrsoft.module.student.mapper.BaseStudentAssessmentProjectMapper;
  49. import com.xjrsoft.module.student.mapper.BaseStudentAssessmentStudentRelationMapper;
  50. import com.xjrsoft.module.student.mapper.BaseStudentSchoolRollMapper;
  51. import com.xjrsoft.module.student.service.IBaseStudentAssessmentInspectionService;
  52. import com.xjrsoft.module.student.service.IQuotaFormulaRuleService;
  53. import com.xjrsoft.module.student.vo.BaseStudentAssessmentClassListVo;
  54. import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobilePageVo;
  55. import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionMobileVo;
  56. import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionPageVo;
  57. import com.xjrsoft.module.student.vo.BaseStudentAssessmentInspectionVo;
  58. import com.xjrsoft.module.student.vo.CalssQuantitativeAssessmentPageVo;
  59. import com.xjrsoft.module.student.vo.QuantitativeAssessmentSingleScoreVo;
  60. import com.xjrsoft.module.student.vo.QuantitativeAssessmentSubTableExcelVo;
  61. import com.xjrsoft.module.system.entity.File;
  62. import com.xjrsoft.module.system.service.IFileService;
  63. import com.xjrsoft.module.teacher.entity.XjrUser;
  64. import lombok.AllArgsConstructor;
  65. import me.zhyd.oauth.log.Log;
  66. import org.springframework.beans.BeanUtils;
  67. import org.springframework.http.ResponseEntity;
  68. import org.springframework.stereotype.Service;
  69. import org.springframework.transaction.annotation.Transactional;
  70. import javax.script.ScriptEngine;
  71. import javax.script.ScriptEngineManager;
  72. import javax.script.ScriptException;
  73. import java.io.ByteArrayOutputStream;
  74. import java.math.BigDecimal;
  75. import java.math.RoundingMode;
  76. import java.text.SimpleDateFormat;
  77. import java.time.LocalDate;
  78. import java.time.LocalDateTime;
  79. import java.time.temporal.TemporalAdjusters;
  80. import java.util.ArrayList;
  81. import java.util.HashMap;
  82. import java.util.List;
  83. import java.util.Map;
  84. import java.util.stream.Collectors;
  85. /**
  86. * @title: 学生班级巡查考核
  87. * @Author dzx
  88. * @Date: 2023-11-16
  89. * @Version 1.0
  90. */
  91. @Service
  92. @AllArgsConstructor
  93. public class BaseStudentAssessmentInspectionServiceImpl extends MPJBaseServiceImpl<BaseStudentAssessmentInspectionMapper, BaseStudentAssessmentInspection> implements IBaseStudentAssessmentInspectionService {
  94. private final BaseStudentAssessmentInspectionMapper assessmentInspectionMapper;
  95. private final BaseStudentAssessmentCategoryMapper categoryMapper;
  96. private final BaseStudentAssessmentProjectMapper projectMapper;
  97. private final BaseStudentAssessmentStudentRelationMapper assessmentStudentRelationMapper;
  98. private final BaseStudentAssessmentClassRelationMapper assessmentClassRelationMapper;
  99. private final BaseClassMapper baseClassMapper;
  100. private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
  101. private final IFileService fileService;
  102. private final IUserService userService;
  103. private final IWeChatService weChatService;
  104. private final EvaluateResultMapper evaluateResultMapper;
  105. private final IQuotaFormulaRuleService quotaFormulaRuleService;
  106. @Override
  107. public Page<BaseStudentAssessmentInspectionPageVo> getPage(Page<BaseStudentAssessmentInspectionPageDto> page, BaseStudentAssessmentInspectionPageDto dto) {
  108. Page<BaseStudentAssessmentInspectionPageVo> result = assessmentInspectionMapper.getPage(page, dto);
  109. // 处理加减分
  110. result.getRecords().forEach((node) -> {
  111. if (node.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
  112. node.setScore(node.getScore() * -1);
  113. }
  114. });
  115. return result;
  116. }
  117. @Override
  118. public BaseStudentAssessmentInspectionVo getInfo(Long id) {
  119. BaseStudentAssessmentInspectionVo result = assessmentInspectionMapper.getInfo(id);
  120. // 处理加减分
  121. if (result.getScoreType() != null && result.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
  122. result.setScore(result.getScore() * -1);
  123. }
  124. // 获取班级信息
  125. List<BaseStudentAssessmentClassListVo> baseStudentAssessmentClassListVos = assessmentClassRelationMapper.selectJoinList(BaseStudentAssessmentClassListVo.class,
  126. MPJWrappers.<BaseStudentAssessmentClassRelation>lambdaJoin()
  127. .leftJoin(BaseClass.class, BaseClass::getId, BaseStudentAssessmentClassRelation::getClassId)
  128. .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
  129. .eq(BaseStudentAssessmentClassRelation::getBaseStudentAssessmentInspectionId, id)
  130. .select(BaseStudentAssessmentClassRelation::getId)
  131. .selectAs(BaseClass::getName, BaseStudentAssessmentClassListVo::getClassName)
  132. .selectAs(XjrUser::getName, BaseStudentAssessmentClassListVo::getTeacherName)
  133. .selectAs(XjrUser::getMobile, BaseStudentAssessmentClassListVo::getMobile)
  134. .select(BaseStudentAssessmentClassRelation.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentAssessmentClassRelation.class).contains(x.getProperty()))
  135. );
  136. result.setClassList(baseStudentAssessmentClassListVos);
  137. // 获取学生信息
  138. result.setStudentList(assessmentInspectionMapper.getStudentListByInspectionId(id));
  139. // 获取文件列表
  140. result.setFileInfos(fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, result.getFileId())));
  141. return result;
  142. }
  143. @Override
  144. public Page<BaseStudentAssessmentInspectionMobilePageVo> getMobilePage(Page<BaseStudentAssessmentInspectionMobilePageDto> page, BaseStudentAssessmentInspectionMobilePageDto dto) {
  145. if (dto.getClassIds() == null || dto.getClassIds().size() == 0) {
  146. // 获取当前用户所管班级
  147. List<Long> classIds = baseClassMapper.selectList(
  148. Wrappers.<BaseClass>query().lambda()
  149. .eq(BaseClass::getTeacherId, StpUtil.getLoginIdAsLong())
  150. .select(BaseClass::getId)
  151. ).stream().map(BaseClass::getId).collect(Collectors.toList());
  152. dto.setClassIds(classIds);
  153. }
  154. if (dto.getClassIds() == null || dto.getClassIds().size() == 0) {
  155. return null;
  156. }
  157. Page<BaseStudentAssessmentInspectionMobilePageVo> result = assessmentInspectionMapper.getMobilePage(page, dto);
  158. // 处理加减分
  159. result.getRecords().forEach((node) -> {
  160. if (node.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
  161. node.setScore(node.getScore() * -1);
  162. }
  163. });
  164. return result;
  165. }
  166. @Override
  167. public BaseStudentAssessmentInspectionMobileVo getMobileInfo(Long id) {
  168. BaseStudentAssessmentInspectionMobileVo result = assessmentInspectionMapper.getMobileInfo(id);
  169. // 处理加减分
  170. if (result.getScoreType().equals(ScoreTypeEnum.ScoreMinus.getCode())) {
  171. result.setScore(result.getScore() * -1);
  172. }
  173. // 获取学生信息
  174. List<BaseStudentAssessmentStudentRelation> baseStudentAssessmentStudentRelations = assessmentStudentRelationMapper.selectList(
  175. Wrappers.<BaseStudentAssessmentStudentRelation>query().lambda()
  176. .eq(BaseStudentAssessmentStudentRelation::getBaseStudentAssessmentInspectionId, result.getBaseStudentAssessmentInspectionId())
  177. .eq(BaseStudentAssessmentStudentRelation::getClassId, result.getClassId())
  178. );
  179. result.setStudentList(baseStudentAssessmentStudentRelations);
  180. result.setStudentCount(baseStudentAssessmentStudentRelations.size());
  181. // 获取文件列表
  182. result.setFileInfos(fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, result.getFileId())));
  183. return result;
  184. }
  185. @Override
  186. public ResponseEntity<byte[]> getQuantitativeAssessmentExcelByte(QuantitativeAssessmentExcelDto dto) {
  187. //导出的文件名,字节流
  188. String fileName = "StudentAssessmentInspection" + ExcelTypeEnum.XLSX.getValue();
  189. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  190. //获取需要导出的子表
  191. List<Long> baseStudentAssessmentCategoryIdList = new ArrayList<>();
  192. baseStudentAssessmentCategoryIdList.add(1768178717588197377L);
  193. baseStudentAssessmentCategoryIdList.add(1768179375900987394L);
  194. baseStudentAssessmentCategoryIdList.add(1769927649167151105L);
  195. LambdaQueryWrapper<BaseStudentAssessmentCategory> baseStudentAssessmentCategoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
  196. baseStudentAssessmentCategoryLambdaQueryWrapper
  197. .in(BaseStudentAssessmentCategory::getId, baseStudentAssessmentCategoryIdList);
  198. List<BaseStudentAssessmentCategory> baseStudentAssessmentCategorieList = categoryMapper.selectList(baseStudentAssessmentCategoryLambdaQueryWrapper);
  199. //导出子表
  200. if(baseStudentAssessmentCategorieList.size() > 0){
  201. //需要合并的列
  202. int[] mergeColumeIndex = {0, 1, 2, 3, 4};
  203. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(1, mergeColumeIndex);
  204. //开始处理写入
  205. try (ExcelWriter excelWriter = EasyExcel.write(bot, QuantitativeAssessmentSubTableExcelVo.class).registerWriteHandler(excelFillCellMergeStrategy).build()) {
  206. int no = 1;
  207. for (BaseStudentAssessmentCategory bsac : baseStudentAssessmentCategorieList) {
  208. dto.setBaseStudentAssessmentCategoryId(bsac.getId());
  209. //sheet名
  210. String sheetName = bsac.getName();
  211. WriteSheet writeSheet = EasyExcel.writerSheet(no++, sheetName ).build();
  212. //求所有的个人行为集合
  213. List<QuantitativeAssessmentSubTableExcelVo> quantitativeAssessmentSubTableExcelVoList = assessmentInspectionMapper.getQuantitativeAssessmentSubTableExcelVoList(dto);
  214. excelWriter.write(quantitativeAssessmentSubTableExcelVoList, writeSheet);
  215. }
  216. //TODO 班级量化考核统计表总
  217. //以班级为数据的基础进行数据的填充
  218. MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
  219. baseClassMPJLambdaWrapper
  220. .selectAs(BaseClass::getTeacherId, CalssQuantitativeAssessmentPageVo::getHeadTeacherId)
  221. .selectAs(XjrUser::getUserName, CalssQuantitativeAssessmentPageVo::getOa)
  222. .selectAs(XjrUser::getName, CalssQuantitativeAssessmentPageVo::getHeadTeacherName)
  223. .selectAs(BaseClass::getId, CalssQuantitativeAssessmentPageVo::getClassId)
  224. .selectAs(BaseClass::getName, CalssQuantitativeAssessmentPageVo::getClassName)
  225. .selectAs(BaseClassMajorSet::getTotalStudent, CalssQuantitativeAssessmentPageVo::getStudentNum)
  226. .selectAs(BaseClass::getIsGraduate, CalssQuantitativeAssessmentPageVo::getClassStatus)
  227. .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
  228. .leftJoin(BaseClassMajorSet.class, BaseClassMajorSet::getClassId, BaseClass::getId)
  229. .eq(dto.getGradeId() != null, BaseClass::getGradeId, dto.getGradeId())
  230. .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
  231. .eq(dto.getClassStatus() != null, BaseClass::getIsGraduate, dto.getClassStatus())
  232. .like(dto.getName() != null && !dto.getName().equals(""), XjrUser::getName, dto.getName())
  233. .disableSubLogicDel();
  234. List<CalssQuantitativeAssessmentPageVo> resultList = baseClassMapper.selectJoinList(CalssQuantitativeAssessmentPageVo.class, baseClassMPJLambdaWrapper);
  235. //当前数据记录班级id
  236. List<Long> classIdList = new ArrayList<>();
  237. for(CalssQuantitativeAssessmentPageVo c: resultList){
  238. classIdList.add(Long.parseLong(c.getClassId()));
  239. }
  240. dto.setClassIdList(classIdList);
  241. if(dto.getStartTime() != null){
  242. // 获取上个月的最后一秒
  243. LocalDateTime lastMonthEnd = dto.getStartTime().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
  244. // 获取下个月的第一秒
  245. LocalDateTime nextMonthStart = dto.getStartTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
  246. dto.setStartTime(lastMonthEnd);
  247. dto.setEndTime(nextMonthStart);
  248. }
  249. if(!classIdList.isEmpty()){
  250. CalssQuantitativeAssessmentPageDto calssQuantitativeAssessmentPageDto = new CalssQuantitativeAssessmentPageDto();
  251. BeanUtils.copyProperties(dto, calssQuantitativeAssessmentPageDto);
  252. //学生个人行为
  253. dto.setBaseStudentAssessmentCategoryId(1768178717588197377L);
  254. Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);
  255. //常规管理
  256. dto.setBaseStudentAssessmentCategoryId(1769927649167151105L);
  257. Map<Long , QuantitativeAssessmentSingleScoreVo> conventionalManagementMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);
  258. //获奖及荣誉奖彰
  259. dto.setBaseStudentAssessmentCategoryId(1768179375900987394L);
  260. Map<Long , QuantitativeAssessmentSingleScoreVo> awardsAndHonorableMap = getQuantitativeAssessmentSingleScoreMap(calssQuantitativeAssessmentPageDto);
  261. //准军事化考核
  262. List<QuantitativeAssessmentSingleScoreVo> paramilitaryList = assessmentInspectionMapper.getParamilitaryList(new QuantitativeAssessmentSingleScoreDto(){{
  263. setClassIdList(classIdList);
  264. }});
  265. Map<Long , QuantitativeAssessmentSingleScoreVo> paramilitaryMap = new HashMap<>();
  266. for (QuantitativeAssessmentSingleScoreVo q : paramilitaryList) {
  267. awardsAndHonorableMap.put(q.getClassId(), q);
  268. }
  269. //查询任课教师查询班级的数据
  270. TeaEvaluateClassDto evaluateClassDto = new TeaEvaluateClassDto();
  271. evaluateClassDto.setEvaluateType(EvaluateTypeEnum.TEACHER_EVALUATE_CLASS.getCode());
  272. evaluateClassDto.setYear(dto.getYear());
  273. LocalDate now = LocalDate.now();
  274. if(dto.getYear() == null){
  275. evaluateClassDto.setYear(now.getYear());
  276. }
  277. evaluateClassDto.setMonth(dto.getMonth());
  278. if(dto.getMonth() == null){
  279. evaluateClassDto.setMonth(now.getMonthValue());
  280. }
  281. List<TeaEvaluateClassListVo> teaEvaluateClassList = evaluateResultMapper.getTeaEvaluateClassList(evaluateClassDto);
  282. Map<Long, List<TeaEvaluateClassListVo>> classEvaluateMap = teaEvaluateClassList.stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getEvaluatedObjectId));
  283. String jskhFormula = quotaFormulaRuleService.getFormulaByQuota("teacher_assessment");
  284. //将结果写进对应的班级里
  285. for(CalssQuantitativeAssessmentPageVo c: resultList){
  286. Long classId = Long.parseLong(c.getClassId());
  287. if(individualBehaviorMap.get(classId) != null){
  288. c.setStuPersonalBehaviorSubScore(individualBehaviorMap.get(classId).getSumScore());
  289. c.setStuPersonalBehaviorScore((100 + individualBehaviorMap.get(classId).getSumScore())/100*25);
  290. }
  291. if(conventionalManagementMap.get(classId) != null){
  292. QuantitativeAssessmentSingleScoreVo scoreVo = conventionalManagementMap.get(classId);
  293. c.setClassConventionalManageSubScore(conventionalManagementMap.get(classId).getSumScore());
  294. c.setClassConventionalManageScore((100 + conventionalManagementMap.get(classId).getSumScore())/100*25);
  295. }
  296. if(awardsAndHonorableMap.get(classId) != null){
  297. c.setHonorSumScore(awardsAndHonorableMap.get(classId).getSumScore());
  298. if(awardsAndHonorableMap.get(classId).getSumScore() < 10){
  299. c.setHonorScore(awardsAndHonorableMap.get(classId).getSumScore());
  300. }else {
  301. c.setHonorScore(10D);
  302. }
  303. }
  304. if(c.getClassStatus() != null){
  305. if(c.getClassStatus() == 1){
  306. c.setClassStatusCn("在读");
  307. }
  308. if(c.getClassStatus() == 2){
  309. c.setClassStatusCn("毕业");
  310. }
  311. }
  312. if(classEvaluateMap.containsKey(classId)){
  313. Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
  314. int evaluateItemSize = evaluateCategoryMap.size();
  315. List<Double> evaluateSocreList = new ArrayList<>();//存每个项的平均分
  316. for (Long id : evaluateCategoryMap.keySet()) {
  317. List<TeaEvaluateClassListVo> evaluateList = evaluateCategoryMap.get(id);
  318. int allSorce = evaluateList.stream().mapToInt(TeaEvaluateClassListVo::getScore).sum();
  319. double avgScore = BigDecimal.valueOf(allSorce).divide(BigDecimal.valueOf(resultList.size())).setScale(2, RoundingMode.HALF_UP).doubleValue();
  320. evaluateSocreList.add(avgScore);
  321. }
  322. double jskhValue = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
  323. c.setTeacherAssessComprehensiveIndex(jskhValue);
  324. String replacedExpression = jskhFormula.replace("JSKH", Double.toString(jskhValue));
  325. ScriptEngineManager manager = new ScriptEngineManager();
  326. ScriptEngine engine = manager.getEngineByName("JavaScript");
  327. try {
  328. double result = ((Number) engine.eval(replacedExpression)).doubleValue();
  329. c.setTeacherAssessScore(result);
  330. } catch (ScriptException e) {
  331. Log.error(e.getMessage(), e);
  332. }
  333. }
  334. }
  335. }
  336. //sheet名
  337. String sheetName = "量化考核总表";
  338. // WriteSheet writeSheet = EasyExcel.writerSheet(0, sheetName ).build();
  339. //
  340. // excelWriter.write(resultList, writeSheet);
  341. }
  342. /*for (BaseStudentAssessmentCategory bsac : baseStudentAssessmentCategorieList) {
  343. dto.setBaseStudentAssessmentCategoryId(bsac.getId());
  344. //sheet名
  345. String sheetName = bsac.getName();
  346. //求所有的个人行为集合
  347. List<QuantitativeAssessmentSubTableExcelVo> quantitativeAssessmentSubTableExcelVoList = assessmentInspectionMapper.getQuantitativeAssessmentSubTableExcelVoList(dto);
  348. //需要合并的列
  349. int[] mergeColumeIndex = {0, 1, 2, 3, 4};
  350. //写字节流
  351. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(1, mergeColumeIndex);
  352. EasyExcel.write(bot, QuantitativeAssessmentSubTableExcelVo.class)
  353. .registerWriteHandler(excelFillCellMergeStrategy)
  354. .sheet(sheetName)
  355. .doWrite(quantitativeAssessmentSubTableExcelVoList);
  356. }*/
  357. }
  358. return RT.fileStream(bot.toByteArray(), fileName);
  359. }
  360. @Override
  361. public IPage<CalssQuantitativeAssessmentPageVo> getCalssQuantitativeAssessmentPage(Page<CalssQuantitativeAssessmentPageDto> page, CalssQuantitativeAssessmentPageDto dto) {
  362. //以班级为数据的基础进行数据的填充
  363. MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
  364. baseClassMPJLambdaWrapper
  365. .selectAs(BaseClass::getTeacherId, CalssQuantitativeAssessmentPageVo::getHeadTeacherId)
  366. .selectAs(XjrUser::getUserName, CalssQuantitativeAssessmentPageVo::getOa)
  367. .selectAs(XjrUser::getName, CalssQuantitativeAssessmentPageVo::getHeadTeacherName)
  368. .selectAs(BaseClass::getId, CalssQuantitativeAssessmentPageVo::getClassId)
  369. .selectAs(BaseClass::getName, CalssQuantitativeAssessmentPageVo::getClassName)
  370. .selectAs(BaseClassMajorSet::getTotalStudent, CalssQuantitativeAssessmentPageVo::getStudentNum)
  371. .selectAs(BaseClass::getIsGraduate, CalssQuantitativeAssessmentPageVo::getClassStatus)
  372. .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
  373. .leftJoin(BaseClassMajorSet.class, BaseClassMajorSet::getClassId, BaseClass::getId)
  374. .eq(dto.getGradeId() != null, BaseClass::getGradeId, dto.getGradeId())
  375. .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
  376. .eq(dto.getClassStatus() != null, BaseClass::getIsGraduate, dto.getClassStatus())
  377. .like(dto.getName() != null && !dto.getName().equals(""), XjrUser::getName, dto.getName())
  378. .disableSubLogicDel();
  379. IPage<CalssQuantitativeAssessmentPageVo> resultPage = baseClassMapper.selectJoinPage(page, CalssQuantitativeAssessmentPageVo.class, baseClassMPJLambdaWrapper);
  380. //当前数据记录班级id
  381. List<Long> classIdList = new ArrayList<>();
  382. for(CalssQuantitativeAssessmentPageVo c: resultPage.getRecords()){
  383. classIdList.add(Long.parseLong(c.getClassId()));
  384. }
  385. dto.setClassIdList(classIdList);
  386. if(dto.getStartTime() != null){
  387. // 获取上个月的最后一秒
  388. LocalDateTime lastMonthEnd = dto.getStartTime().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
  389. // 获取下个月的第一秒
  390. LocalDateTime nextMonthStart = dto.getStartTime().plusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
  391. dto.setStartTime(lastMonthEnd);
  392. dto.setEndTime(nextMonthStart);
  393. }
  394. if(!classIdList.isEmpty()){
  395. //学生个人行为
  396. dto.setBaseStudentAssessmentCategoryId(1768178717588197377L);
  397. Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = getQuantitativeAssessmentSingleScoreMap(dto);
  398. //常规管理
  399. dto.setBaseStudentAssessmentCategoryId(1769927649167151105L);
  400. Map<Long , QuantitativeAssessmentSingleScoreVo> conventionalManagementMap = getQuantitativeAssessmentSingleScoreMap(dto);
  401. //获奖及荣誉奖彰
  402. dto.setBaseStudentAssessmentCategoryId(1768179375900987394L);
  403. Map<Long , QuantitativeAssessmentSingleScoreVo> awardsAndHonorableMap = getQuantitativeAssessmentSingleScoreMap(dto);
  404. //准军事化考核
  405. List<QuantitativeAssessmentSingleScoreVo> paramilitaryList = assessmentInspectionMapper.getParamilitaryList(new QuantitativeAssessmentSingleScoreDto(){{
  406. setClassIdList(classIdList);
  407. }});
  408. Map<Long , QuantitativeAssessmentSingleScoreVo> paramilitaryMap = new HashMap<>();
  409. for (QuantitativeAssessmentSingleScoreVo q : paramilitaryList) {
  410. awardsAndHonorableMap.put(q.getClassId(), q);
  411. }
  412. //查询任课教师查询班级的数据
  413. TeaEvaluateClassDto evaluateClassDto = new TeaEvaluateClassDto();
  414. evaluateClassDto.setEvaluateType(EvaluateTypeEnum.TEACHER_EVALUATE_CLASS.getCode());
  415. evaluateClassDto.setYear(dto.getYear());
  416. LocalDate now = LocalDate.now();
  417. if(dto.getYear() == null){
  418. evaluateClassDto.setYear(now.getYear());
  419. }
  420. evaluateClassDto.setMonth(dto.getMonth());
  421. if(dto.getMonth() == null){
  422. evaluateClassDto.setMonth(now.getMonthValue());
  423. }
  424. List<TeaEvaluateClassListVo> teaEvaluateClassList = evaluateResultMapper.getTeaEvaluateClassList(evaluateClassDto);
  425. Map<Long, List<TeaEvaluateClassListVo>> classEvaluateMap = teaEvaluateClassList.stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getEvaluatedObjectId));
  426. String jskhFormula = quotaFormulaRuleService.getFormulaByQuota("teacher_assessment");
  427. //将结果写进对应的班级里
  428. for(CalssQuantitativeAssessmentPageVo c: resultPage.getRecords()){
  429. Long classId = Long.parseLong(c.getClassId());
  430. if(individualBehaviorMap.get(classId) != null){
  431. c.setStuPersonalBehaviorSubScore(individualBehaviorMap.get(classId).getSumScore());
  432. c.setStuPersonalBehaviorScore((100 + individualBehaviorMap.get(classId).getSumScore())/100*25);
  433. /* ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
  434. String geRenXingWeiGongShi = "sumSubScore/itemCount";
  435. int totalScore = scoreBySubmitRecordId.get(mobileResultPageVo.getEvaluateSubmitRecordId()).getTotalScore();
  436. int itemCount = scoreBySubmitRecordId.get(mobileResultPageVo.getEvaluateSubmitRecordId()).getItemCount();
  437. double res = 0;
  438. String newStr1 = zonghezhishu.replace("totalScore", ""+totalScore);
  439. String newStr2 = newStr1.replace("itemCount", ""+itemCount);
  440. try{
  441. res = Double.parseDouble(engine.eval(newStr2).toString());
  442. }catch (ScriptException s){
  443. }
  444. // 创建一个DecimalFormat对象,指定小数位数为两位
  445. DecimalFormat decimalFormat = new DecimalFormat("#.00");
  446. // 格式化double值为字符串
  447. String formattedNumber = decimalFormat.format(res);*/
  448. }
  449. if(conventionalManagementMap.get(classId) != null){
  450. c.setClassConventionalManageSubScore(conventionalManagementMap.get(classId).getSumScore());
  451. Double SumScore = 0D;
  452. if(conventionalManagementMap.get(classId).getSumScore() != null){
  453. SumScore = conventionalManagementMap.get(classId).getSumScore();
  454. }
  455. c.setClassConventionalManageScore((100 + SumScore)/100*25);
  456. }
  457. if(awardsAndHonorableMap.get(classId) != null){
  458. c.setHonorSumScore(awardsAndHonorableMap.get(classId).getSumScore());
  459. if(awardsAndHonorableMap.get(classId).getSumScore() < 10){
  460. c.setHonorScore(awardsAndHonorableMap.get(classId).getSumScore());
  461. }else {
  462. c.setHonorScore(10D);
  463. }
  464. }
  465. if(classEvaluateMap.containsKey(classId)){
  466. Map<Long, List<TeaEvaluateClassListVo>> evaluateCategoryMap = classEvaluateMap.get(classId).stream().collect(Collectors.groupingBy(TeaEvaluateClassListVo::getId));
  467. int evaluateItemSize = evaluateCategoryMap.size();
  468. List<Double> evaluateSocreList = new ArrayList<>();//存每个项的平均分
  469. for (Long id : evaluateCategoryMap.keySet()) {
  470. List<TeaEvaluateClassListVo> resultList = evaluateCategoryMap.get(id);
  471. int allSorce = resultList.stream().mapToInt(TeaEvaluateClassListVo::getScore).sum();
  472. double avgScore = BigDecimal.valueOf(allSorce).divide(BigDecimal.valueOf(resultList.size())).setScale(2, RoundingMode.HALF_UP).doubleValue();
  473. evaluateSocreList.add(avgScore);
  474. }
  475. double jskhValue = evaluateSocreList.stream().mapToDouble(Double::doubleValue).sum();
  476. c.setTeacherAssessComprehensiveIndex(jskhValue);
  477. String replacedExpression = jskhFormula.replace("JSKH", Double.toString(jskhValue));
  478. ScriptEngineManager manager = new ScriptEngineManager();
  479. ScriptEngine engine = manager.getEngineByName("JavaScript");
  480. try {
  481. double result = ((Number) engine.eval(replacedExpression)).doubleValue();
  482. c.setTeacherAssessScore(result);
  483. } catch (ScriptException e) {
  484. Log.error(e.getMessage(), e);
  485. }
  486. }
  487. }
  488. }
  489. return resultPage;
  490. }
  491. private Map<Long, QuantitativeAssessmentSingleScoreVo> getQuantitativeAssessmentSingleScoreMap(CalssQuantitativeAssessmentPageDto dto){
  492. List<QuantitativeAssessmentSingleScoreVo> individualBehaviorList = assessmentInspectionMapper.getAssessmentInspectionByClassIdList(new QuantitativeAssessmentSingleScoreDto(){{
  493. setClassIdList(dto.getClassIdList());
  494. setBaseStudentAssessmentCategoryId(dto.getBaseStudentAssessmentCategoryId());
  495. if(dto.getBaseSemesterId() != null){
  496. setBaseSemesterId(dto.getBaseSemesterId());
  497. }
  498. if(dto.getStartTime() != null){
  499. setStartTime(dto.getStartTime());
  500. }
  501. if(dto.getEndTime() != null){
  502. setStartTime(dto.getEndTime());
  503. }
  504. }});
  505. Map<Long , QuantitativeAssessmentSingleScoreVo> individualBehaviorMap = new HashMap<>();
  506. for (QuantitativeAssessmentSingleScoreVo q : individualBehaviorList) {
  507. if(q.getClassId() != null){
  508. individualBehaviorMap.put(q.getClassId(), q);
  509. }
  510. }
  511. return individualBehaviorMap;
  512. }
  513. @Override
  514. @Transactional
  515. public Boolean dataHandle(Long id) {
  516. //获取考核记录
  517. BaseStudentAssessmentInspection baseStudentAssessmentInspection = this.getById(id);
  518. if(baseStudentAssessmentInspection != null){
  519. double totalScore = 0d;
  520. if(StrUtil.isNotEmpty(baseStudentAssessmentInspection.getClassIds())) {
  521. //同步数据到考核关联班级表
  522. String[] classIds = baseStudentAssessmentInspection.getClassIds().split(",");
  523. for (String classId : classIds) {
  524. assessmentClassRelationMapper.insert(new BaseStudentAssessmentClassRelation() {{
  525. setClassId(Long.parseLong(classId));
  526. setBaseStudentAssessmentInspectionId(baseStudentAssessmentInspection.getId());
  527. QueryWrapper<BaseStudentAssessmentClassRelation> queryWrapperSortcode = new QueryWrapper<>();
  528. queryWrapperSortcode.select("IFNULL(MAX(sort_code),0) as sortCode");
  529. BaseStudentAssessmentClassRelation b = assessmentClassRelationMapper.selectOne(queryWrapperSortcode);
  530. setSortCode(b.getSortCode() + 1);
  531. }});
  532. }
  533. totalScore = baseStudentAssessmentInspection.getScore();
  534. }
  535. //同步数据到考核关联学生表
  536. if(StrUtil.isNotEmpty(baseStudentAssessmentInspection.getPersonalStudentUserIds())){
  537. String[] studentIds = baseStudentAssessmentInspection.getPersonalStudentUserIds().split(",");
  538. for (String studentId: studentIds) {
  539. assessmentStudentRelationMapper.insert(new BaseStudentAssessmentStudentRelation(){{
  540. MPJLambdaWrapper<BaseStudentSchoolRoll> baseStudentSchoolRollMPJLambdaWrapper = new MPJLambdaWrapper<>();
  541. baseStudentSchoolRollMPJLambdaWrapper
  542. .select(BaseStudentSchoolRoll::getId)
  543. .select(BaseStudentSchoolRoll.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentSchoolRoll.class).contains(x.getProperty()))
  544. .eq(BaseStudentSchoolRoll::getUserId, studentId);
  545. BaseStudentSchoolRoll baseStudentSchoolRoll = baseStudentSchoolRollMapper.selectOne(baseStudentSchoolRollMPJLambdaWrapper);
  546. if(baseStudentSchoolRoll != null){
  547. setClassId(baseStudentSchoolRoll.getClassId());
  548. }
  549. setUserId(Long.parseLong(studentId));
  550. setBaseStudentAssessmentInspectionId(baseStudentAssessmentInspection.getId());
  551. QueryWrapper<BaseStudentAssessmentStudentRelation> queryWrapperSortcode = new QueryWrapper<>();
  552. queryWrapperSortcode.select("IFNULL(MAX(sort_code),0) as sortCode");
  553. BaseStudentAssessmentStudentRelation b = assessmentStudentRelationMapper.selectOne(queryWrapperSortcode);
  554. setSortCode(b.getSortCode() + 1);
  555. setScore(baseStudentAssessmentInspection.getScore());
  556. }});
  557. }
  558. totalScore = studentIds.length * baseStudentAssessmentInspection.getScore();
  559. }
  560. baseStudentAssessmentInspection.setTotalScore(totalScore);
  561. this.updateById(baseStudentAssessmentInspection);
  562. }
  563. return true;
  564. }
  565. @Override
  566. public Boolean noticeTeacher(Long id) {
  567. BaseStudentAssessmentInspection inspection = this.getById(id);
  568. String classIds = inspection.getClassIds();
  569. BaseClass baseClass = baseClassMapper.selectById(classIds);
  570. User user = userService.getById(baseClass.getTeacherId());
  571. String wechatTemplate = "Xb21V8au0Ur9puQs4hIDJTl8LP6GTgVOHQtOeie1Oco";
  572. WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
  573. weChatSendMessageDto.setUserId(user.getOpenId());
  574. weChatSendMessageDto.setTemplateId(wechatTemplate);
  575. weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
  576. JSONObject data = new JSONObject();
  577. String thing4 = "";
  578. String thing1 = "";
  579. if(AssessmentTypeEnum.CLASS.getCode().equals(inspection.getAssessmentType())){
  580. data.put("const3", new JSONObject() {{
  581. put("value", AssessmentTypeEnum.CLASS.getValue());
  582. }});
  583. BaseStudentAssessmentProject project = projectMapper.selectById(inspection.getBaseStudentAssessmentProjectId());
  584. thing4 = project.getName();
  585. }else if(AssessmentTypeEnum.PERSONAL.getCode().equals(inspection.getAssessmentType())){
  586. data.put("const3", new JSONObject() {{
  587. put("value", AssessmentTypeEnum.PERSONAL.getValue());
  588. }});
  589. String[] studentUsers = inspection.getPersonalStudentUserIds().split(",");
  590. List<String> studentIds = new ArrayList<>();
  591. for (String studentUser : studentUsers) {
  592. studentIds.add(studentUser.trim());
  593. }
  594. List<User> userList = userService.listByIds(studentIds);
  595. for (int i = 0; i < userList.size(); i ++){
  596. if(i > 0){
  597. thing1 += ",";
  598. }
  599. thing1 += userList.get(i).getName();
  600. }
  601. if(thing1.length() > 20){
  602. thing1 = thing1.substring(0, 16) + "...";
  603. }
  604. BaseStudentAssessmentCategory category = categoryMapper.selectById(inspection.getBaseStudentAssessmentCategoryId());
  605. thing4 = category.getName();
  606. }
  607. //得分
  608. JSONObject thing4Json = new JSONObject();
  609. thing4Json.put("value", thing4);
  610. data.put("thing4", thing4Json);
  611. //学生
  612. JSONObject thing1Json = new JSONObject();
  613. thing1Json.put("value", thing1);
  614. data.put("thing1", thing1Json);
  615. //得分
  616. data.put("character_string5", new JSONObject() {{
  617. put("value", inspection.getScore());
  618. }});
  619. //考核时间
  620. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  621. data.put("time2", new JSONObject() {{
  622. put("value", sdf.format(inspection.getAssessmentDate()));
  623. }});
  624. weChatSendMessageDto.setContent(data);
  625. weChatService.sendTemplateMessage(weChatSendMessageDto);
  626. return true;
  627. }
  628. }