ClassTimeStatisticsServiceImpl.java 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. package com.xjrsoft.module.classtime.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.github.yulichang.base.MPJBaseServiceImpl;
  6. import com.google.gson.Gson;
  7. import com.google.gson.JsonArray;
  8. import com.google.gson.JsonElement;
  9. import com.google.gson.JsonObject;
  10. import com.google.gson.JsonParser;
  11. import com.xjrsoft.common.enums.CourseAdjustTypeEnum;
  12. import com.xjrsoft.common.enums.CourseTimeTypeEnum;
  13. import com.xjrsoft.common.enums.DeleteMark;
  14. import com.xjrsoft.common.exception.MyException;
  15. import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
  16. import com.xjrsoft.module.classtime.dto.AddClassTimeStatisticsDto;
  17. import com.xjrsoft.module.classtime.entity.ClassTimeDelete;
  18. import com.xjrsoft.module.classtime.entity.ClassTimeStatistics;
  19. import com.xjrsoft.module.classtime.entity.ClassTimeStatisticsRecord;
  20. import com.xjrsoft.module.classtime.entity.ClassTimeStatisticsSet;
  21. import com.xjrsoft.module.classtime.mapper.ClassTimeStatisticsMapper;
  22. import com.xjrsoft.module.classtime.mapper.ClassTimeStatisticsRecordMapper;
  23. import com.xjrsoft.module.classtime.service.IClassTimeDeleteService;
  24. import com.xjrsoft.module.classtime.service.IClassTimeStatisticsService;
  25. import com.xjrsoft.module.classtime.service.IClassTimeStatisticsSetService;
  26. import com.xjrsoft.module.classtime.vo.ClassTimeStatisticsRecordVo;
  27. import com.xjrsoft.module.classtime.vo.CourseListVo;
  28. import com.xjrsoft.module.classtime.vo.TeacherListVo;
  29. import com.xjrsoft.module.classtime.vo.WeekTimeRangeVo;
  30. import com.xjrsoft.module.oa.entity.WfTeacherCourseTime;
  31. import com.xjrsoft.module.system.entity.DictionaryDetail;
  32. import com.xjrsoft.module.system.service.IDictionarydetailService;
  33. import lombok.AllArgsConstructor;
  34. import me.zhyd.oauth.log.Log;
  35. import org.apache.poi.ss.usermodel.Cell;
  36. import org.apache.poi.ss.usermodel.CellStyle;
  37. import org.apache.poi.ss.usermodel.Font;
  38. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  39. import org.apache.poi.ss.usermodel.Row;
  40. import org.apache.poi.ss.usermodel.Sheet;
  41. import org.apache.poi.ss.usermodel.VerticalAlignment;
  42. import org.apache.poi.ss.usermodel.Workbook;
  43. import org.apache.poi.ss.util.CellRangeAddress;
  44. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  45. import org.springframework.stereotype.Service;
  46. import org.springframework.transaction.annotation.Transactional;
  47. import java.io.ByteArrayOutputStream;
  48. import java.math.BigDecimal;
  49. import java.time.DayOfWeek;
  50. import java.time.LocalDate;
  51. import java.time.format.DateTimeFormatter;
  52. import java.time.temporal.ChronoUnit;
  53. import java.util.ArrayList;
  54. import java.util.Arrays;
  55. import java.util.Date;
  56. import java.util.HashMap;
  57. import java.util.HashSet;
  58. import java.util.LinkedHashMap;
  59. import java.util.List;
  60. import java.util.Map;
  61. import java.util.Set;
  62. import java.util.concurrent.CompletableFuture;
  63. import java.util.stream.Collectors;
  64. /**
  65. * @title: 课时统计
  66. * @Author dzx
  67. * @Date: 2024-09-26
  68. * @Version 1.0
  69. */
  70. @Service
  71. @AllArgsConstructor
  72. public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTimeStatisticsMapper, ClassTimeStatistics> implements IClassTimeStatisticsService {
  73. private final ClassTimeStatisticsMapper statisticsMapper;
  74. private final ClassTimeStatisticsRecordMapper recordMapper;
  75. private final IClassTimeStatisticsSetService statisticsSetService;
  76. private final IClassTimeDeleteService deleteService;
  77. private final IDictionarydetailService dictionaryService;
  78. @Override
  79. @Transactional(rollbackFor = Exception.class)
  80. public Boolean add(ClassTimeStatistics classTimeStatistics) {
  81. statisticsMapper.insert(classTimeStatistics);
  82. return true;
  83. }
  84. @Override
  85. @Transactional(rollbackFor = Exception.class)
  86. public Boolean update(ClassTimeStatistics classTimeStatistics) {
  87. statisticsMapper.updateById(classTimeStatistics);
  88. return true;
  89. }
  90. @Override
  91. @Transactional(rollbackFor = Exception.class)
  92. public Boolean delete(List<Long> ids) {
  93. statisticsMapper.deleteBatchIds(ids);
  94. recordMapper.delete(Wrappers.lambdaQuery(ClassTimeStatisticsRecord.class).in(ClassTimeStatisticsRecord::getClassTimeStatisticsId, ids));
  95. return true;
  96. }
  97. @Override
  98. @Transactional(rollbackFor = Exception.class)
  99. public Boolean add(AddClassTimeStatisticsDto dto) {
  100. ClassTimeStatistics classTimeStatistics = BeanUtil.toBean(dto, ClassTimeStatistics.class);
  101. classTimeStatistics.setStatus(0);
  102. classTimeStatistics.setCreateDate(new Date());
  103. //查询最新权重并保存到统计中
  104. Integer category = 1;
  105. List<ClassTimeStatisticsSet> list = statisticsSetService.list(
  106. new QueryWrapper<ClassTimeStatisticsSet>().lambda()
  107. .eq(ClassTimeStatisticsSet::getCategory, category)
  108. .orderByDesc(ClassTimeStatisticsSet::getCreateDate)
  109. );
  110. if(list.isEmpty()){
  111. throw new MyException("请先设置权重并进行保存");
  112. }
  113. classTimeStatistics.setWeightSetJson(list.get(0).getJsonContent());
  114. //查询最新费用并保存到统计中
  115. category = 2;
  116. list = statisticsSetService.list(
  117. new QueryWrapper<ClassTimeStatisticsSet>().lambda()
  118. .eq(ClassTimeStatisticsSet::getCategory, category)
  119. .orderByDesc(ClassTimeStatisticsSet::getCreateDate)
  120. );
  121. if(list.isEmpty()){
  122. throw new MyException("请先设置费用并进行保存");
  123. }
  124. classTimeStatistics.setCostSetJson(list.get(0).getJsonContent());
  125. this.save(classTimeStatistics);
  126. CompletableFuture.runAsync(() -> {
  127. refreshRecord(classTimeStatistics);
  128. });
  129. return true;
  130. }
  131. /**
  132. * 1、通过xjr_user和base_teacher查询所有教师,查询聘用类型为:正式聘用和外聘的
  133. * 2、根据统计的开始日期和结束日期查询课时补充(wf_teacher_course_time)中的教研会、督导听课、临近三年退休政策、出题、阅卷、周末培优
  134. * 3、根绝统计的开始日期和结束日期查询课程表(course_table)中的所有课程数据
  135. * 4、查询补班日期下的所有课程
  136. * 5、属于节假日的课程不查询
  137. * @param statistics
  138. */
  139. @Override
  140. @Transactional(rollbackFor = Exception.class)
  141. public Boolean refreshRecord(ClassTimeStatistics statistics) {
  142. try {
  143. // 1、查询教师
  144. List<TeacherListVo> teacherList = this.baseMapper.getTeacherList();
  145. // 2、查询补课课时
  146. List<DictionaryDetail> CourseTimeTypeList = dictionaryService.list(
  147. new QueryWrapper<DictionaryDetail>().lambda()
  148. .eq(DictionaryDetail::getItemId, 1833772737004875778L)
  149. .eq(DictionaryDetail::getDeleteMark, DeleteMark.NODELETE.getCode())
  150. .orderByAsc(DictionaryDetail::getCode)
  151. );
  152. Map<String, String> CourseTimeTypeMap = CourseTimeTypeList.stream().collect(Collectors.toMap(DictionaryDetail::getCode, DictionaryDetail::getName));
  153. List<WfTeacherCourseTime> courseTimeList = this.baseMapper.getWfTeacherCourseTimeList(statistics);
  154. //按照课时补充类型分类统计
  155. Map<String, List<WfTeacherCourseTime>> courseTimeMap = courseTimeList.stream().collect(Collectors.groupingBy(WfTeacherCourseTime::getCourseTimeType));
  156. JsonParser parser = new JsonParser();
  157. //费用设置jsonArray
  158. JsonArray costSetArray = parser.parse(statistics.getCostSetJson()).getAsJsonArray();
  159. Map<String, Double> costSetMap = new LinkedHashMap<>();
  160. for (JsonElement jsonElement : costSetArray) {
  161. JsonObject object = jsonElement.getAsJsonObject();
  162. costSetMap.put(object.get("field").getAsString(), object.get("value").getAsDouble());
  163. }
  164. //权重设置jsonArray
  165. JsonArray weightSetArray = parser.parse(statistics.getWeightSetJson()).getAsJsonArray();
  166. Map<String, Double> weightSetMap = new LinkedHashMap<>();
  167. for (JsonElement jsonElement : weightSetArray) {
  168. JsonObject object = jsonElement.getAsJsonObject();
  169. weightSetMap.put(object.get("label").getAsString(), object.get("value").getAsDouble());
  170. }
  171. //计算出这个时间段内一共多少周
  172. List<WeekTimeRangeVo> weekTimeRangeVos = calculateNaturalWeeks(statistics.getStartDate(), statistics.getEndDate());
  173. //取出所有的日期
  174. List<LocalDate> allDateList = getDatesBetween(statistics.getStartDate(), statistics.getEndDate());
  175. //查询课程数据,排除开节假日的数据
  176. List<CourseListVo> allCourseList = this.baseMapper.getCourseList(statistics);
  177. allCourseList.addAll(this.baseMapper.getHolidayReplaceCourseList(statistics));
  178. //查询删除课时的数据,将每个班删除的具体日期统计出来
  179. List<ClassTimeDelete> deleteList = deleteService.list(
  180. new QueryWrapper<ClassTimeDelete>().lambda()
  181. .ne(ClassTimeDelete::getStatus, 2)
  182. );
  183. Map<Long, List<ClassTimeDelete>> deleteDataMap = deleteList.stream().collect(Collectors.groupingBy(ClassTimeDelete::getClassId));
  184. Map<Long, Map<LocalDate, String>> deleteMap = new HashMap<>();//将每个班级计算出来所有被删除的日期存入map
  185. for (Long classId : deleteDataMap.keySet()) {
  186. Map<LocalDate, String> dateMap = new HashMap<>();
  187. for (ClassTimeDelete classTimeDelete : deleteDataMap.get(classId)) {
  188. LocalDate currentDate = classTimeDelete.getStartDate();
  189. while (!currentDate.isAfter(classTimeDelete.getEndDate())) {
  190. dateMap.put(currentDate, classTimeDelete.getTimePeriod());
  191. currentDate = currentDate.plusDays(1); // 增加一天
  192. }
  193. }
  194. //去重并存到map中
  195. deleteMap.put(classId, dateMap);
  196. }
  197. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  198. //查询所有老师发起顶课通过的数量,也要分别计算早自习、晚自习、正课、如果日期出入课时删除中,也需要跳过
  199. List<CourseListVo> allSubstituteList = this.baseMapper.getSubstituteList(statistics);
  200. List<ClassTimeStatisticsRecord> insertList = new ArrayList<>();
  201. //循环教师,准备开始计算
  202. for (TeacherListVo teacher : teacherList) {
  203. ClassTimeStatisticsRecord record = new ClassTimeStatisticsRecord();
  204. record.setUserId(teacher.getId());
  205. record.setClassTimeStatisticsId(statistics.getId());
  206. record.setEmployType(teacher.getEmployType());
  207. JsonArray allClassTimeDataArray = new JsonArray();
  208. Double allClassTime = 0D;
  209. //计算补充课时,算作正课课时,但是计算超出课时时不计算这部分
  210. JsonObject courseTimeTypeJson = new JsonObject();
  211. Double courseTimeTypeTime = 0D;
  212. for (String courseTimeType : CourseTimeTypeMap.keySet()) {
  213. List<WfTeacherCourseTime> courseTimes = courseTimeMap.get(courseTimeType);
  214. if(courseTimes == null){
  215. courseTimeTypeJson.addProperty(CourseTimeTypeMap.get(courseTimeType), 0);
  216. continue;
  217. }
  218. double sum = courseTimes.stream()
  219. .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()))
  220. .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
  221. allClassTime = allClassTime + sum;
  222. courseTimeTypeTime = courseTimeTypeTime + sum;
  223. courseTimeTypeJson.addProperty(CourseTimeTypeMap.get(courseTimeType), sum);
  224. for (LocalDate localDate : allDateList) {
  225. double sum1 = courseTimes.stream()
  226. .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
  227. .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
  228. JsonObject courseJson = new JsonObject();
  229. courseJson.addProperty("type", CourseTimeTypeMap.get(courseTimeType));
  230. courseJson.addProperty("scheduleDate", localDate.format(formatter));
  231. courseJson.addProperty("content", sum1);
  232. courseJson.addProperty("adjustType", "");
  233. allClassTimeDataArray.add(courseJson);
  234. }
  235. }
  236. record.setCourseTimeTypeData(courseTimeTypeJson.toString());
  237. //早自习、正课、晚辅、顶课、调课
  238. Double classTime7 = 0D,classTime8 = 0D,classTime9 = 0D,classTime11 = 0D;
  239. List<String> zkList = Arrays.asList("上1","上2","上3","上4","下1","下2","下3","下4");
  240. List<String> wzxList = Arrays.asList("晚1","晚2","晚3");
  241. //查询出老师的课程
  242. List<CourseListVo> courseList = allCourseList.stream()
  243. .filter(x -> x.getTeacherId().contains(teacher.getId().toString()))
  244. .collect(Collectors.toList());
  245. //循环,统计出各项数据
  246. for (CourseListVo courseListVo : courseList) {
  247. //如果这个课程数据包含在被删除的课时中,跳过不计算
  248. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  249. JsonObject courseJson = new JsonObject();
  250. if(deleteDates != null && deleteDates.containsKey(courseListVo.getScheduleDate()) && deleteDates.get(courseListVo.getScheduleDate()) != null
  251. && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber()) ){
  252. courseJson.addProperty("type", courseListVo.getShortName());
  253. courseJson.addProperty("scheduleDate", courseListVo.getScheduleDate().format(formatter));
  254. courseJson.addProperty("content", "");
  255. courseJson.addProperty("adjustType", "course_delete");
  256. allClassTimeDataArray.add(courseJson);
  257. continue;
  258. }
  259. if("早自习".equals(courseListVo.getShortName())){
  260. classTime7 += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  261. }else if(zkList.contains(courseListVo.getShortName())){
  262. classTime8 += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  263. }else if(wzxList.contains(courseListVo.getShortName())){
  264. classTime9 += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  265. }
  266. if(courseListVo.getAdjustType() != null && !courseListVo.getAdjustType().isEmpty()){
  267. if(CourseAdjustTypeEnum.courseExchange.getCode().equals(courseListVo.getAdjustType())){
  268. classTime11 += weightSetMap.get(courseListVo.getShortName());
  269. }
  270. }
  271. courseJson.addProperty("type", courseListVo.getShortName());
  272. courseJson.addProperty("scheduleDate", courseListVo.getScheduleDate().format(formatter));
  273. courseJson.addProperty("content", courseListVo.getClassName() + "," + courseListVo.getCourseName());
  274. courseJson.addProperty("adjustType", courseListVo.getAdjustType() == null?"":courseListVo.getAdjustType());
  275. allClassTimeDataArray.add(courseJson);
  276. }
  277. record.setClassTime7(classTime7);
  278. record.setClassTime8(classTime8);
  279. record.setClassTime9(classTime9);
  280. record.setClassTime11(classTime11);
  281. JsonObject weekDataJson = new JsonObject();
  282. Double allTimes = 0d;
  283. Double allCcksTime = 0d;//总的超出课时,从每周的正课课时中计算
  284. BigDecimal ccksTime = BigDecimal.ZERO;//超出课时标准(每周)
  285. if("FB1601".equals(teacher.getEmployType())){
  286. ccksTime = BigDecimal.valueOf(costSetMap.get("cost7"));
  287. }else{//外聘FB1605、合作人员FB1609
  288. ccksTime = BigDecimal.valueOf(costSetMap.get("cost8"));
  289. }
  290. //存每周的数据
  291. for (WeekTimeRangeVo timeRangeVo : weekTimeRangeVos) {
  292. Double zkTimes = 0d;
  293. Double wzxTimes = 0d;
  294. Double tkTimes = 0d;
  295. for (CourseListVo courseListVo : courseList) {
  296. LocalDate scheduleDate = courseListVo.getScheduleDate();
  297. //如果这个课程数据包含在被删除的课时中,跳过不计算
  298. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  299. if(deleteDates != null && deleteDates.containsKey(scheduleDate) && deleteDates.get(courseListVo.getScheduleDate()) != null
  300. && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber())){
  301. continue;
  302. }
  303. if(!( (scheduleDate.equals(timeRangeVo.getMondayDate()) || scheduleDate.isAfter(timeRangeVo.getMondayDate()))
  304. && (scheduleDate.equals(timeRangeVo.getSundayDate()) || scheduleDate.isBefore(timeRangeVo.getSundayDate())))){
  305. continue;
  306. }
  307. if("早自习".equals(courseListVo.getShortName())){
  308. zkTimes += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  309. }else if(zkList.contains(courseListVo.getShortName())){
  310. zkTimes += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  311. }else if(wzxList.contains(courseListVo.getShortName())){
  312. wzxTimes += weightSetMap.get(courseListVo.getShortName()) == null ? 0d : weightSetMap.get(courseListVo.getShortName());
  313. }
  314. if(courseListVo.getAdjustType() != null && !courseListVo.getAdjustType().isEmpty()){
  315. if(CourseAdjustTypeEnum.courseExchange.getCode().equals(courseListVo.getAdjustType())){
  316. tkTimes += weightSetMap.get(courseListVo.getShortName());
  317. }
  318. }
  319. }
  320. //计算该老师发起的事假、病假顶课数据
  321. List<CourseListVo> substituteList = allSubstituteList.stream().filter(x -> x.getExchangeTeacherId().equals(teacher.getId()))
  322. .collect(Collectors.toList());
  323. Double reduceTime = 0d;//顶课课时
  324. for (CourseListVo courseListVo : substituteList) {
  325. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  326. if(deleteDates != null && deleteDates.containsKey(courseListVo.getScheduleDate()) && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber())){
  327. continue;
  328. }
  329. if(!( (courseListVo.getScheduleDate().equals(timeRangeVo.getMondayDate()) || courseListVo.getScheduleDate().isAfter(timeRangeVo.getMondayDate()))
  330. && (courseListVo.getScheduleDate().equals(timeRangeVo.getSundayDate()) || courseListVo.getScheduleDate().isBefore(timeRangeVo.getSundayDate())))){
  331. continue;
  332. }
  333. reduceTime += weightSetMap.get(courseListVo.getShortName());
  334. }
  335. substituteList = allSubstituteList.stream().filter(x -> x.getTeacherId().equals(teacher.getId().toString()))
  336. .collect(Collectors.toList());
  337. for (CourseListVo courseListVo : substituteList) {
  338. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  339. if(deleteDates != null && deleteDates.containsKey(courseListVo.getScheduleDate()) && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber())){
  340. continue;
  341. }
  342. if(!( (courseListVo.getScheduleDate().equals(timeRangeVo.getMondayDate()) || courseListVo.getScheduleDate().isAfter(timeRangeVo.getMondayDate()))
  343. && (courseListVo.getScheduleDate().equals(timeRangeVo.getSundayDate()) || courseListVo.getScheduleDate().isBefore(timeRangeVo.getSundayDate())))){
  344. continue;
  345. }
  346. reduceTime = reduceTime - weightSetMap.get(courseListVo.getShortName());
  347. }
  348. timeRangeVo.setZkTimes(zkTimes);
  349. timeRangeVo.setWzxTimes(wzxTimes);
  350. timeRangeVo.setDkTimes(reduceTime);
  351. timeRangeVo.setTkTimes(tkTimes);
  352. allTimes += (zkTimes + wzxTimes);
  353. if(zkTimes > ccksTime.doubleValue()){
  354. allCcksTime += zkTimes - ccksTime.doubleValue();
  355. }
  356. }
  357. weekDataJson.add("weekData", new Gson().toJsonTree(weekTimeRangeVos));
  358. weekDataJson.addProperty("allTimes", allTimes);
  359. record.setWeekData(weekDataJson.toString());
  360. //计算总课时
  361. allClassTime = allClassTime + classTime7 + classTime8 + classTime9;
  362. record.setAllClassTime(allClassTime);
  363. //计算费用,根据聘用类型判断费用问题
  364. Double classTimeAmount = 0d;
  365. Double beyondClassTimeAmount = 0d;
  366. BigDecimal zzxCost = BigDecimal.ZERO;//早自习费用
  367. if("FB1601".equals(teacher.getEmployType())){
  368. zzxCost = BigDecimal.valueOf(costSetMap.get("cost1"));
  369. }else{//外聘FB1605、合作人员FB1609
  370. zzxCost = BigDecimal.valueOf(costSetMap.get("cost2"));
  371. }
  372. classTimeAmount += BigDecimal.valueOf(classTime7).multiply(zzxCost).doubleValue();
  373. BigDecimal zkCost = BigDecimal.ZERO;//正课费用
  374. if("FB1601".equals(teacher.getEmployType())){
  375. zkCost = BigDecimal.valueOf(costSetMap.get("cost3"));
  376. }else{//外聘FB1605、合作人员FB1609
  377. zkCost = BigDecimal.valueOf(costSetMap.get("cost4"));
  378. }
  379. double classTime = classTime8
  380. + courseTimeTypeTime;
  381. classTimeAmount += BigDecimal.valueOf(classTime).multiply(zkCost).doubleValue();
  382. BigDecimal wzxCost = BigDecimal.ZERO;//晚自习费用
  383. if("FB1601".equals(teacher.getEmployType())){
  384. wzxCost = BigDecimal.valueOf(costSetMap.get("cost5"));
  385. }else{//外聘FB1605、合作人员FB1609
  386. wzxCost = BigDecimal.valueOf(costSetMap.get("cost6"));
  387. }
  388. classTimeAmount += BigDecimal.valueOf(classTime9).multiply(wzxCost).doubleValue();
  389. /**
  390. * 顶课:
  391. * 1、流程发起人(被顶老师)的课被顶课老师上了,那么被顶老师的课时就会-1,顶课老师课时就会+1
  392. * 2、顶课老师会根据规则额外加一笔费用,根据设置1课时额外加4元
  393. * 3、顶课类型为事假和病假的时候会扣除被顶老师的费用,根据设置为扣除4元
  394. */
  395. BigDecimal reduceTimeAmount = BigDecimal.ZERO;
  396. {
  397. //计算该老师发起的事假、病假顶课数据
  398. List<CourseListVo> substituteList = allSubstituteList.stream().filter(x -> x.getExchangeTeacherId().equals(teacher.getId()))
  399. .collect(Collectors.toList());
  400. Double reduceTime = 0d;//顶课课时
  401. Double dkClassTime = 0d;//去顶课的数量,所有顶课数量
  402. for (CourseListVo courseListVo : substituteList) {
  403. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  404. if(deleteDates != null && deleteDates.containsKey(courseListVo.getScheduleDate()) && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber())){
  405. continue;
  406. }
  407. reduceTime += weightSetMap.get(courseListVo.getShortName());
  408. dkClassTime += weightSetMap.get(courseListVo.getShortName());
  409. }
  410. Double bdkClassTime = 0d;//发起顶课的数量,只统计事假和病假的数量
  411. substituteList = allSubstituteList.stream().filter(x -> x.getTeacherId().equals(teacher.getId().toString()))
  412. .collect(Collectors.toList());
  413. for (CourseListVo courseListVo : substituteList) {
  414. Map<LocalDate, String> deleteDates = deleteMap.get(courseListVo.getClassId());
  415. if(deleteDates != null && deleteDates.containsKey(courseListVo.getScheduleDate()) && deleteDates.get(courseListVo.getScheduleDate()).contains(courseListVo.getTimeNumber())){
  416. continue;
  417. }
  418. reduceTime = reduceTime - weightSetMap.get(courseListVo.getShortName());
  419. if("sick _leave".equals(courseListVo.getReason()) || "leave_absence".equals(courseListVo.getReason())){
  420. bdkClassTime += weightSetMap.get(courseListVo.getShortName());
  421. }
  422. }
  423. record.setClassTime10(reduceTime);
  424. BigDecimal dkCost = BigDecimal.ZERO;//顶课费用,顶课老师加钱
  425. if("FB1601".equals(teacher.getEmployType())){
  426. dkCost = BigDecimal.valueOf(costSetMap.get("cost11"));
  427. }else{//外聘FB1605、合作人员FB1609
  428. dkCost = BigDecimal.valueOf(costSetMap.get("cost12"));
  429. }
  430. reduceTimeAmount = BigDecimal.valueOf(dkClassTime).multiply(dkCost);
  431. BigDecimal bdkCost = BigDecimal.ZERO;//顶课费用,被顶课老师扣钱
  432. if("FB1601".equals(teacher.getEmployType())){
  433. bdkCost = BigDecimal.valueOf(costSetMap.get("cost13")==null?0:costSetMap.get("cost13"));
  434. }else{//外聘FB1605、合作人员FB1609
  435. bdkCost = BigDecimal.valueOf(costSetMap.get("cost14")==null?0:costSetMap.get("cost14"));
  436. }
  437. //计算被扣除的费用
  438. reduceTimeAmount = reduceTimeAmount.subtract(bdkCost.multiply(BigDecimal.valueOf(bdkClassTime)));
  439. }
  440. record.setClassTimeAmount(classTimeAmount);
  441. //计算超出的课时,需要先计算出每个周的开始结束时间
  442. BigDecimal ccksCost = BigDecimal.ZERO;
  443. if("FB1601".equals(teacher.getEmployType())){
  444. ccksCost = BigDecimal.valueOf(costSetMap.get("cost9"));
  445. }else{//外聘FB1605、合作人员FB1609
  446. ccksCost = BigDecimal.valueOf(costSetMap.get("cost10"));
  447. }
  448. //计算出总的超出课时并计算超课时费
  449. beyondClassTimeAmount = BigDecimal.valueOf(allCcksTime).multiply(ccksCost).doubleValue();
  450. if(!"FB1601".equals(teacher.getEmployType())){
  451. record.setBeyondClassTimeAmount(beyondClassTimeAmount);
  452. }
  453. //计算总金额,课时费+超课时费
  454. Double totalAmount = classTimeAmount + beyondClassTimeAmount + reduceTimeAmount.doubleValue();
  455. record.setTotalAmount(totalAmount);
  456. record.setAllClassTimeData(calculateClassTime(allClassTimeDataArray, weightSetMap, allDateList));
  457. record.setCreateDate(new Date());
  458. insertList.add(record);
  459. }
  460. if(!insertList.isEmpty()){
  461. //先删除
  462. String sql = "delete from class_time_statistics_record where class_time_statistics_id = " + statistics.getId();
  463. SqlRunnerAdapter.db().delete(sql);
  464. for (ClassTimeStatisticsRecord record : insertList) {
  465. recordMapper.insert(record);
  466. }
  467. }
  468. statistics.setAllClassTime(insertList.stream().filter(x -> x.getAllClassTime() != null).mapToDouble(ClassTimeStatisticsRecord::getAllClassTime).sum());
  469. statistics.setTotalAmount(insertList.stream().filter(x -> x.getTotalAmount() != null).mapToDouble(ClassTimeStatisticsRecord::getTotalAmount).sum());
  470. statistics.setBeyondClassTimeAmount(insertList.stream().filter(x -> x.getBeyondClassTimeAmount() != null).mapToDouble(ClassTimeStatisticsRecord::getBeyondClassTimeAmount).sum());
  471. statistics.setClassTimeAmount(insertList.stream().filter(x -> x.getClassTimeAmount() != null).mapToDouble(ClassTimeStatisticsRecord::getClassTimeAmount).sum());
  472. statistics.setStatus(1);
  473. this.updateById(statistics);
  474. return true;
  475. }catch (Exception e){
  476. Log.error(e.getMessage(), e);
  477. throw new MyException("统计出错,请联系管理员");
  478. }
  479. }
  480. @Override
  481. public Boolean lockData(Long id) {
  482. ClassTimeStatistics statistics = this.getById(id);
  483. return null;
  484. }
  485. @Override
  486. public List<ClassTimeStatisticsRecordVo> getRecordList(Long id) {
  487. return this.baseMapper.getRecordList(id);
  488. }
  489. /**
  490. * 导出课时统计明细
  491. * @param id
  492. * @return
  493. */
  494. @Override
  495. public byte[] recordExport(Long id) {
  496. try {
  497. //1、查询数据
  498. List<ClassTimeStatisticsRecordVo> recordList = this.baseMapper.getRecordList(id);
  499. //计算出一共有多少周
  500. ClassTimeStatistics statistics = this.getById(id);
  501. List<WeekTimeRangeVo> weekTimeRangeVos = calculateNaturalWeeks(statistics.getStartDate(), statistics.getEndDate());
  502. List<DictionaryDetail> CourseTimeTypeList = dictionaryService.list(
  503. new QueryWrapper<DictionaryDetail>().lambda()
  504. .eq(DictionaryDetail::getItemId, 1833772737004875778L)
  505. .eq(DictionaryDetail::getDeleteMark, DeleteMark.NODELETE.getCode())
  506. .orderByAsc(DictionaryDetail::getCode)
  507. );
  508. /**
  509. * 2、将查询出来的数据按照表头转换成二维数组
  510. * 前端固定表头:序号、工号、姓名、教研会、督导听课、临近三年退休政策、出题、阅卷、周末培优、早自习、正课(含调顶课时)、晚辅(含调顶课时)、顶课、调课
  511. * 中间动态表头:每周,总课时(含调顶课节)、顶课(节)、调课(节)、晚辅(节)......课时晚辅合计
  512. * 后端固定表头:总课时、课时费(元)、外聘教师超课时费(元)、总金额(元)
  513. */
  514. //计算一共多少列
  515. int column = 12 + CourseTimeTypeList.size() + (4 * weekTimeRangeVos.size());
  516. List<ArrayList<String>> dataList = new ArrayList<>();
  517. Integer sortCode = 1;
  518. JsonParser parser = new JsonParser();
  519. for (ClassTimeStatisticsRecordVo recordVo : recordList) {
  520. ArrayList<String> rowData = new ArrayList<>();
  521. rowData.add(sortCode.toString());//序号
  522. rowData.add(recordVo.getUserName());//工号
  523. rowData.add(recordVo.getName());//姓名
  524. JsonObject courseTimeTypeJson = parser.parse(recordVo.getCourseTimeTypeData()).getAsJsonObject();
  525. for (DictionaryDetail dictionaryDetail : CourseTimeTypeList) {
  526. if (courseTimeTypeJson.get(dictionaryDetail.getName()) == null) {
  527. continue;
  528. }
  529. Double courseTimeTypeTime = courseTimeTypeJson.get(dictionaryDetail.getName()).getAsDouble();
  530. rowData.add(courseTimeTypeTime.toString());//教研会
  531. }
  532. // rowData.add(recordVo.getClassTime1()==null?"":recordVo.getClassTime1().toString());//教研会
  533. // rowData.add(recordVo.getClassTime2()==null?"":recordVo.getClassTime2().toString());//督导听课
  534. // rowData.add(recordVo.getClassTime3()==null?"":recordVo.getClassTime3().toString());//临近三年退休政策
  535. // rowData.add(recordVo.getClassTime4()==null?"":recordVo.getClassTime4().toString());//出题
  536. // rowData.add(recordVo.getClassTime5()==null?"":recordVo.getClassTime5().toString());//阅卷
  537. // rowData.add(recordVo.getClassTime6()==null?"":recordVo.getClassTime6().toString());//周末培优
  538. rowData.add(recordVo.getClassTime7()==null?"":recordVo.getClassTime7().toString());//早自习
  539. rowData.add(recordVo.getClassTime8()==null?"":recordVo.getClassTime8().toString());//正课(含调顶课时)
  540. rowData.add(recordVo.getClassTime9()==null?"":recordVo.getClassTime9().toString());//晚辅(含调顶课时)
  541. rowData.add(recordVo.getClassTime10()==null?"":recordVo.getClassTime10().toString());//顶课
  542. rowData.add(recordVo.getClassTime11()==null?"":recordVo.getClassTime11().toString());//调课
  543. //每周数据
  544. JsonObject weekDataJson = parser.parse(recordVo.getWeekData()).getAsJsonObject();
  545. JsonArray weekDataArray = weekDataJson.getAsJsonArray("weekData");
  546. for (int i = 0; i < weekDataArray.size(); i ++){
  547. JsonObject jsonElement = weekDataArray.get(i).getAsJsonObject();
  548. rowData.add(jsonElement.get("zkTimes").getAsString());//总课时(含调顶课节)
  549. rowData.add(jsonElement.get("dkTimes").getAsString());//顶课(节)
  550. rowData.add(jsonElement.get("tkTimes").getAsString());//调课(节)
  551. rowData.add(jsonElement.get("wzxTimes").getAsString());//晚辅(节)
  552. }
  553. rowData.add(weekDataJson.get("allTimes").getAsString());//课时晚辅合计
  554. rowData.add(recordVo.getAllClassTime().toString());//总课时
  555. rowData.add(recordVo.getClassTimeAmount().toString());//课时费(元)
  556. rowData.add(recordVo.getBeyondClassTimeAmount()==null?"":recordVo.getBeyondClassTimeAmount().toString());//外聘教师超课时费(元)
  557. rowData.add(recordVo.getTotalAmount().toString());//总金额(元)
  558. dataList.add(rowData);
  559. sortCode ++;
  560. }
  561. // 创建一个新的工作簿
  562. Workbook workbook = new XSSFWorkbook();
  563. // 创建一个工作表(sheet)
  564. String sheetName = "数据";
  565. Sheet sheet = workbook.createSheet(sheetName);
  566. // 创建一个字体对象
  567. Font font = workbook.createFont();
  568. font.setBold(true);// 设置为粗体
  569. font.setFontName("宋体");
  570. //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
  571. font.setFontHeightInPoints((short)24);
  572. // 创建一个单元格样式对象
  573. CellStyle cellStyle = workbook.createCellStyle();
  574. cellStyle.setFont(font); // 将字体应用到样式
  575. cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  576. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  577. // 第一行表头
  578. {
  579. Row row = sheet.createRow(0);
  580. //合并第一行的列
  581. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, column - 1));
  582. //3、处理表头
  583. String title1 = statistics.getYear() + "年" + statistics.getMonth() + "月课时统计";
  584. // 创建单元格并设置值
  585. Cell cell = row.createCell(0);
  586. cell.setCellValue(title1);
  587. cell.setCellStyle(cellStyle);
  588. }
  589. //第二行表头
  590. createSecondTitle(workbook, sheet, statistics, weekTimeRangeVos.size() * 4 + 1, CourseTimeTypeList);
  591. //第三行表头
  592. createThirdTitle(workbook, sheet, statistics.getMonth(), weekTimeRangeVos, 7 + CourseTimeTypeList.size());
  593. //第四行表头
  594. createFourthTitle(workbook, sheet, weekTimeRangeVos, 7 + CourseTimeTypeList.size());
  595. int dataRowNumber = 4;
  596. //设置样式
  597. font = workbook.createFont();
  598. font.setBold(false);// 设置为粗体
  599. font.setFontName("宋体");
  600. //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
  601. font.setFontHeightInPoints((short)12);
  602. // 创建一个单元格样式对象
  603. cellStyle = workbook.createCellStyle();
  604. cellStyle.setFont(font); // 将字体应用到样式
  605. cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  606. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  607. for (ArrayList<String> rowData : dataList) {
  608. Row dataRow = sheet.createRow(dataRowNumber);
  609. for (int i = 0; i < rowData.size(); i ++){
  610. Cell row1cell2 = dataRow.createCell(i);
  611. String value = rowData.get(i);
  612. if("0".equals(value) || "0.0".equals(value)){
  613. value = "";
  614. }
  615. row1cell2.setCellValue(value);
  616. row1cell2.setCellStyle(cellStyle);
  617. }
  618. dataRowNumber ++;
  619. }
  620. //写入文件
  621. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  622. workbook.write(bot);
  623. return bot.toByteArray();
  624. }catch (Exception e){
  625. Log.error(e.getMessage(), e);
  626. throw new MyException("导出出错,请联系管理员");
  627. }
  628. }
  629. /**
  630. * 生成第二行表头
  631. * 前端固定表头:序号、工号、姓名、教研会、督导听课、临近三年退休政策、出题、阅卷、周末培优、早自习、正课(含调顶课时)、晚辅(含调顶课时)、顶课、调课
  632. * 中间动态表头:每周,总课时(含调顶课节)、顶课(节)、调课(节)、晚辅(节)......课时晚辅合计
  633. * 后端固定表头:总课时、课时费(元)、外聘教师超课时费(元)、总金额(元)
  634. */
  635. void createSecondTitle(Workbook workbook, Sheet sheet, ClassTimeStatistics statistics, int mergeCoulmn, List<DictionaryDetail> CourseTimeTypeList){
  636. Font font = workbook.createFont();
  637. font.setFontName("宋体");
  638. font.setFontHeightInPoints((short)12);
  639. CellStyle cellStyle = workbook.createCellStyle();
  640. cellStyle.setFont(font); // 将字体应用到样式
  641. cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  642. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  643. Row row1 = sheet.createRow(1);
  644. int cellNumber = 0;
  645. Cell row1cell1 = row1.createCell(cellNumber);
  646. row1cell1.setCellValue("序号");
  647. row1cell1.setCellStyle(cellStyle);
  648. cellNumber ++;
  649. Cell row1cell2 = row1.createCell(cellNumber);
  650. row1cell2.setCellValue("工号");
  651. row1cell2.setCellStyle(cellStyle);
  652. cellNumber ++;
  653. Cell row1cell3 = row1.createCell(cellNumber);
  654. row1cell3.setCellValue("姓名");
  655. row1cell3.setCellStyle(cellStyle);
  656. cellNumber ++;
  657. for (DictionaryDetail detail : CourseTimeTypeList) {
  658. Cell row1cell4 = row1.createCell(cellNumber);
  659. row1cell4.setCellValue(detail.getName());
  660. row1cell4.setCellStyle(cellStyle);
  661. cellNumber ++;
  662. }
  663. Cell row1cell10 = row1.createCell(cellNumber);
  664. row1cell10.setCellValue("早自习");
  665. row1cell10.setCellStyle(cellStyle);
  666. cellNumber ++;
  667. Cell row1cell11 = row1.createCell(cellNumber);
  668. row1cell11.setCellValue("正课(含调顶课时)");
  669. row1cell11.setCellStyle(cellStyle);
  670. cellNumber ++;
  671. Cell row1cell12 = row1.createCell(cellNumber);
  672. row1cell12.setCellValue("晚辅(含调顶课时)");
  673. row1cell12.setCellStyle(cellStyle);
  674. cellNumber ++;
  675. Cell row1cell13 = row1.createCell(cellNumber);
  676. row1cell13.setCellValue("顶课");
  677. row1cell13.setCellStyle(cellStyle);
  678. cellNumber ++;
  679. Cell row1cell14 = row1.createCell(cellNumber);
  680. row1cell14.setCellValue("调课");
  681. row1cell14.setCellStyle(cellStyle);
  682. cellNumber ++;
  683. Cell row1cell15 = row1.createCell(cellNumber);
  684. row1cell15.setCellValue("正课课时数(平台导出" + statistics.getMonth() + "月)");
  685. row1cell15.setCellStyle(cellStyle);
  686. cellNumber ++;
  687. int index = cellNumber + mergeCoulmn - 1;
  688. Cell row1cell16 = row1.createCell(index);
  689. row1cell16.setCellValue("总课时");
  690. row1cell16.setCellStyle(cellStyle);
  691. Cell row1cell17 = row1.createCell(index + 1);
  692. row1cell17.setCellValue("课时费(元)");
  693. row1cell17.setCellStyle(cellStyle);
  694. Cell row1cell18 = row1.createCell(index + 2);
  695. row1cell18.setCellValue("外聘教师超课时费(元)");
  696. row1cell18.setCellStyle(cellStyle);
  697. Cell row1cell19 = row1.createCell(index + 3);
  698. row1cell19.setCellValue("总金额(元)");
  699. row1cell19.setCellStyle(cellStyle);
  700. //合并表头
  701. for(int i = 0; i < 8 + CourseTimeTypeList.size(); i ++){
  702. sheet.addMergedRegion(new CellRangeAddress(1, 3, i, i));
  703. }
  704. //合并中间动态表头
  705. sheet.addMergedRegion(new CellRangeAddress(1, 1, 8 + CourseTimeTypeList.size(), index - 1));
  706. //合并前端表头
  707. for(int i = index; i < index + 4; i ++){
  708. sheet.addMergedRegion(new CellRangeAddress(1, 3, i, i));
  709. }
  710. }
  711. /**
  712. * 生成第三行表头
  713. * 关于周的表头,周一日期到周二日期,第几周,最后拼接一个单独的月份
  714. *
  715. * @param workbook
  716. * @param sheet
  717. * @param month 月份
  718. * @param weekTimeRangeVos 周的数据,包含周一的日期周二的日期
  719. * @param lastIndex 前一个表头的单元格
  720. */
  721. void createThirdTitle(Workbook workbook, Sheet sheet, int month, List<WeekTimeRangeVo> weekTimeRangeVos, int lastIndex){
  722. Font font = workbook.createFont();
  723. font.setFontName("宋体");
  724. font.setFontHeightInPoints((short)12);
  725. CellStyle cellStyle = workbook.createCellStyle();
  726. cellStyle.setFont(font); // 将字体应用到样式
  727. cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  728. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  729. //设置内容
  730. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd");
  731. int rowNumber = 2;
  732. Row row2 = sheet.createRow(rowNumber);
  733. for(int i = 0; i < weekTimeRangeVos.size(); i ++){
  734. WeekTimeRangeVo rangeVo = weekTimeRangeVos.get(i);
  735. String cellValue = rangeVo.getMondayDate().format(formatter) + "-"
  736. + rangeVo.getSundayDate().format(formatter) + "(第" + rangeVo.getWeeks() + "周)";
  737. Cell row1cell1 = row2.createCell(lastIndex + 1 + (i * 4));
  738. row1cell1.setCellValue(cellValue);
  739. row1cell1.setCellStyle(cellStyle);
  740. }
  741. //合并单元格
  742. int monthIndex = 0;
  743. for(int i = 0; i < weekTimeRangeVos.size(); i ++){
  744. int startCoulmn = lastIndex + 1 + (i * 4);
  745. int endCoulmn = startCoulmn + 3;
  746. sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, startCoulmn, endCoulmn));
  747. monthIndex = endCoulmn;
  748. }
  749. Cell row1cell2 = row2.createCell(monthIndex + 1);
  750. row1cell2.setCellValue(month + "月");
  751. row1cell2.setCellStyle(cellStyle);
  752. }
  753. /**
  754. * 生成第四行表头
  755. * 表头内容:总课时(含调顶课节)、顶课(节)、调课(节)、晚辅(节)、课时晚辅合计
  756. *
  757. * @param workbook
  758. * @param sheet
  759. * @param weekTimeRangeVos 周的数据,包含周一的日期周二的日期
  760. * @param lastIndex 前一个表头的单元格
  761. */
  762. void createFourthTitle(Workbook workbook, Sheet sheet, List<WeekTimeRangeVo> weekTimeRangeVos, int lastIndex){
  763. Font font = workbook.createFont();
  764. font.setFontName("宋体");
  765. font.setFontHeightInPoints((short)12);
  766. CellStyle cellStyle = workbook.createCellStyle();
  767. cellStyle.setFont(font); // 将字体应用到样式
  768. cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  769. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  770. int rowNumber = 3;
  771. Row row2 = sheet.createRow(rowNumber);
  772. int index = lastIndex + 1;
  773. for(int i = 0; i < weekTimeRangeVos.size(); i ++){
  774. Cell row1cell1 = row2.createCell(index);
  775. row1cell1.setCellValue("总课时(含调顶课节)");
  776. row1cell1.setCellStyle(cellStyle);
  777. index ++;
  778. Cell row1cell2 = row2.createCell(index);
  779. row1cell2.setCellValue("顶课(节)");
  780. row1cell2.setCellStyle(cellStyle);
  781. index ++;
  782. Cell row1cell3 = row2.createCell(index);
  783. row1cell3.setCellValue("调课(节)");
  784. row1cell3.setCellStyle(cellStyle);
  785. index ++;
  786. Cell row1cell4 = row2.createCell(index);
  787. row1cell4.setCellValue("晚辅(节)");
  788. row1cell4.setCellStyle(cellStyle);
  789. index ++;
  790. }
  791. Cell row1cell5 = row2.createCell(index);
  792. row1cell5.setCellValue("课时晚辅合计");
  793. row1cell5.setCellStyle(cellStyle);
  794. }
  795. //计算日期内一共几个周,并返回每周的周一日期和周日日期
  796. private static List<WeekTimeRangeVo> calculateNaturalWeeks(LocalDate startDate, LocalDate endDate) {
  797. List<WeekTimeRangeVo> result = new ArrayList<>();
  798. // 获取第一个周一
  799. LocalDate currentMonday = startDate.with(DayOfWeek.MONDAY);
  800. // 如果 startDate 不是周一,则用下一个周一
  801. if (!startDate.isEqual(currentMonday) && startDate.isAfter(currentMonday)) {
  802. currentMonday = currentMonday.plusWeeks(1);
  803. }
  804. int weeks = 1;
  805. // 遍历每个周
  806. while (!currentMonday.isAfter(endDate)) {
  807. // 计算当前周的周日
  808. LocalDate currentSunday = currentMonday.plusDays(6);
  809. // 限制周日的范围
  810. if (currentSunday.isAfter(endDate)) {
  811. currentSunday = endDate;
  812. }
  813. // 添加结果
  814. WeekTimeRangeVo timeRangeVo = new WeekTimeRangeVo();
  815. timeRangeVo.setMondayDate(currentMonday);
  816. timeRangeVo.setSundayDate(currentSunday);
  817. timeRangeVo .setWeeks(weeks);
  818. result.add(timeRangeVo);
  819. // 移动到下一个周的周一
  820. currentMonday = currentMonday.plusWeeks(1);
  821. weeks ++;
  822. }
  823. return result;
  824. }
  825. /**
  826. * 取出所有日期
  827. * @param startDate 开始时间
  828. * @param endDate 结束时间
  829. * @return 返回所有日期的集合
  830. */
  831. private static List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate) {
  832. List<LocalDate> dates = new ArrayList<>();
  833. long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1; // +1 包含结束日期
  834. for (long i = 0; i < numOfDaysBetween; i++) {
  835. dates.add(startDate.plusDays(i));
  836. }
  837. return dates;
  838. }
  839. String calculateClassTime(JsonArray allClassTimeDataArray, Map<String, Double> weightSetMap, List<LocalDate> allDateList){
  840. JsonObject result = new JsonObject();
  841. //计算纵向的合计
  842. Double allClassTime = 0d;
  843. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd");
  844. JsonArray rowTitle = new JsonArray();
  845. for (LocalDate localDate : allDateList) {
  846. JsonObject rowTitleJson = new JsonObject();
  847. rowTitleJson.addProperty("scheduleDate", localDate.format(formatter));
  848. Double sum = 0d;
  849. for (JsonElement jsonElement : allClassTimeDataArray) {
  850. JsonObject object = jsonElement.getAsJsonObject();
  851. LocalDate scheduleDate = LocalDate.parse(object.get("scheduleDate").getAsString());
  852. if(!scheduleDate.equals(localDate)){
  853. continue;
  854. }
  855. String adjustType = object.get("adjustType").getAsString();
  856. if("course_delete".equals(adjustType)){
  857. continue;
  858. }
  859. if(weightSetMap.get(object.get("type").getAsString()) == null){
  860. sum += object.get("content").getAsDouble();
  861. allClassTime += object.get("content").getAsDouble();
  862. }else{
  863. sum += weightSetMap.get(object.get("type").getAsString());
  864. allClassTime += weightSetMap.get(object.get("type").getAsString());
  865. }
  866. }
  867. rowTitleJson.addProperty("content", sum);
  868. rowTitleJson.addProperty("type", "");
  869. rowTitleJson.addProperty("adjustType", "");
  870. rowTitle.add(rowTitleJson);
  871. }
  872. result.add("rowTitle", rowTitle);
  873. //计算横向的合计
  874. JsonArray columnTitle = new JsonArray();
  875. for (String type : weightSetMap.keySet()) {
  876. Double sum = 0d;
  877. JsonObject columnTitleJson = new JsonObject();
  878. for (JsonElement jsonElement : allClassTimeDataArray) {
  879. JsonObject object = jsonElement.getAsJsonObject();
  880. String typeStr = object.get("type").getAsString();
  881. if(!type.equals(typeStr)){
  882. continue;
  883. }
  884. String adjustType = object.get("adjustType").getAsString();
  885. if("course_delete".equals(adjustType)){
  886. continue;
  887. }
  888. sum += weightSetMap.get(typeStr);
  889. }
  890. columnTitleJson.addProperty("type", type);
  891. columnTitleJson.addProperty("content", sum);
  892. columnTitleJson.addProperty("scheduleDate", "");
  893. columnTitleJson.addProperty("adjustType", "");
  894. columnTitle.add(columnTitleJson);
  895. }
  896. String[] courseTimeTypes = CourseTimeTypeEnum.getValues();
  897. for (String courseTimeType : courseTimeTypes) {
  898. double sum = 0d;
  899. JsonObject columnTitleJson = new JsonObject();
  900. for (JsonElement jsonElement : allClassTimeDataArray) {
  901. JsonObject object = jsonElement.getAsJsonObject();
  902. String typeStr = object.get("type").getAsString();
  903. if (!courseTimeType.equals(typeStr)) {
  904. continue;
  905. }
  906. String adjustType = object.get("adjustType").getAsString();
  907. if("course_delete".equals(adjustType)){
  908. continue;
  909. }
  910. sum += object.get("content").getAsDouble();
  911. }
  912. columnTitleJson.addProperty("type", courseTimeType);
  913. columnTitleJson.addProperty("content", sum);
  914. columnTitleJson.addProperty("scheduleDate", "");
  915. columnTitleJson.addProperty("adjustType", "");
  916. columnTitle.add(columnTitleJson);
  917. }
  918. result.add("columnTitle", columnTitle);
  919. result.add("data", allClassTimeDataArray);
  920. result.addProperty("allClassTime", allClassTime);
  921. return result.toString();
  922. }
  923. }