|
|
@@ -12,6 +12,7 @@ import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.common.enums.CourseAdjustTypeEnum;
|
|
|
import com.xjrsoft.common.enums.CourseTimeTypeEnum;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
import com.xjrsoft.module.classtime.dto.AddClassTimeStatisticsDto;
|
|
|
import com.xjrsoft.module.classtime.entity.ClassTimeDelete;
|
|
|
import com.xjrsoft.module.classtime.entity.ClassTimeStatistics;
|
|
|
@@ -42,11 +43,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
@@ -174,9 +175,11 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
}
|
|
|
//计算出这个时间段内一共多少周
|
|
|
List<WeekTimeRangeVo> weekTimeRangeVos = calculateNaturalWeeks(statistics.getStartDate(), statistics.getEndDate());
|
|
|
-
|
|
|
+ //取出所有的日期
|
|
|
+ List<LocalDate> allDateList = getDatesBetween(statistics.getStartDate(), statistics.getEndDate());
|
|
|
//查询课程数据,排除开节假日的数据
|
|
|
List<CourseListVo> allCourseList = this.baseMapper.getCourseList(statistics);
|
|
|
+ allCourseList.addAll(this.baseMapper.getHolidayReplaceCourseList(statistics));
|
|
|
|
|
|
//查询删除课时的数据,将每个班删除的具体日期统计出来
|
|
|
List<ClassTimeDelete> deleteList = deleteService.list(
|
|
|
@@ -221,16 +224,82 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
allClassTime = allClassTime + sum;
|
|
|
if(CourseTimeTypeEnum.CTT001.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime1(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}else if(CourseTimeTypeEnum.CTT002.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime2(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}else if(CourseTimeTypeEnum.CTT003.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime3(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}else if(CourseTimeTypeEnum.CTT004.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime4(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}else if(CourseTimeTypeEnum.CTT005.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime5(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}else if(CourseTimeTypeEnum.CTT006.getCode().equals(courseTimeType)){
|
|
|
record.setClassTime6(sum);
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ double sum1 = courseTimes.stream()
|
|
|
+ .filter(x -> x.getTeacherIds().contains(teacher.getId().toString()) && localDate.equals(x.getScheduleDate()))
|
|
|
+ .mapToDouble(WfTeacherCourseTime::getCourseTime).sum();
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
+ courseJson.addProperty("type", CourseTimeTypeEnum.CTT001.getValue());
|
|
|
+ courseJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ courseJson.addProperty("content", sum1);
|
|
|
+ courseJson.addProperty("adjustType", "");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//早自习、正课、晚辅、顶课、调课
|
|
|
@@ -247,7 +316,13 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
for (CourseListVo courseListVo : courseList) {
|
|
|
//如果这个课程数据包含在被删除的课时中,跳过不计算
|
|
|
Set<LocalDate> deleteDates = deleteMap.get(courseListVo.getClassId());
|
|
|
+ JsonObject courseJson = new JsonObject();
|
|
|
if(deleteDates != null && deleteDates.contains(courseListVo.getScheduleDate())){
|
|
|
+ courseJson.addProperty("type", courseListVo.getShortName());
|
|
|
+ courseJson.addProperty("scheduleDate", courseListVo.getScheduleDate().format(formatter));
|
|
|
+ courseJson.addProperty("content", "");
|
|
|
+ courseJson.addProperty("adjustType", "course_delete");
|
|
|
+ allClassTimeDataArray.add(courseJson);
|
|
|
continue;
|
|
|
}
|
|
|
if("早自习".equals(courseListVo.getShortName())){
|
|
|
@@ -263,7 +338,6 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
classTime11 += weightSetMap.get(courseListVo.getShortName());
|
|
|
}
|
|
|
}
|
|
|
- JsonObject courseJson = new JsonObject();
|
|
|
courseJson.addProperty("type", courseListVo.getShortName());
|
|
|
courseJson.addProperty("scheduleDate", courseListVo.getScheduleDate().format(formatter));
|
|
|
courseJson.addProperty("content", courseListVo.getClassName() + "," + courseListVo.getCourseName());
|
|
|
@@ -434,21 +508,20 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
//计算总金额,课时费+超课时费
|
|
|
Double totalAmount = classTimeAmount + beyondClassTimeAmount + reduceTimeAmount.doubleValue();
|
|
|
record.setTotalAmount(totalAmount);
|
|
|
+ record.setAllClassTimeData(calculateClassTime(allClassTimeDataArray, weightSetMap, allDateList));
|
|
|
+ record.setCreateDate(new Date());
|
|
|
|
|
|
insertList.add(record);
|
|
|
}
|
|
|
|
|
|
if(!insertList.isEmpty()){
|
|
|
//先删除
|
|
|
- recordMapper.delete(
|
|
|
- new QueryWrapper<ClassTimeStatisticsRecord>().lambda()
|
|
|
- .eq(ClassTimeStatisticsRecord::getClassTimeStatisticsId, statistics.getId())
|
|
|
- );
|
|
|
+ String sql = "delete from class_time_statistics_record where class_time_statistics_id = " + statistics.getId();
|
|
|
+ SqlRunnerAdapter.db().delete(sql);
|
|
|
for (ClassTimeStatisticsRecord record : insertList) {
|
|
|
recordMapper.insert(record);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
statistics.setAllClassTime(insertList.stream().filter(x -> x.getAllClassTime() != null).mapToDouble(ClassTimeStatisticsRecord::getAllClassTime).sum());
|
|
|
statistics.setTotalAmount(insertList.stream().filter(x -> x.getTotalAmount() != null).mapToDouble(ClassTimeStatisticsRecord::getTotalAmount).sum());
|
|
|
statistics.setBeyondClassTimeAmount(insertList.stream().filter(x -> x.getBeyondClassTimeAmount() != null).mapToDouble(ClassTimeStatisticsRecord::getBeyondClassTimeAmount).sum());
|
|
|
@@ -479,7 +552,7 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public byte[] recordExport(Long id) throws IOException {
|
|
|
+ public byte[] recordExport(Long id) {
|
|
|
try {
|
|
|
//1、查询数据
|
|
|
List<ClassTimeStatisticsRecordVo> recordList = this.baseMapper.getRecordList(id);
|
|
|
@@ -849,4 +922,98 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 取出所有日期
|
|
|
+ * @param startDate 开始时间
|
|
|
+ * @param endDate 结束时间
|
|
|
+ * @return 返回所有日期的集合
|
|
|
+ */
|
|
|
+ private static List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate) {
|
|
|
+ List<LocalDate> dates = new ArrayList<>();
|
|
|
+
|
|
|
+ long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1; // +1 包含结束日期
|
|
|
+ for (long i = 0; i < numOfDaysBetween; i++) {
|
|
|
+ dates.add(startDate.plusDays(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ return dates;
|
|
|
+ }
|
|
|
+
|
|
|
+ String calculateClassTime(JsonArray allClassTimeDataArray, Map<String, Double> weightSetMap, List<LocalDate> allDateList){
|
|
|
+ JsonObject result = new JsonObject();
|
|
|
+ //计算纵向的合计
|
|
|
+ Double allClassTime = 0d;
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd");
|
|
|
+ JsonArray rowTitle = new JsonArray();
|
|
|
+ for (LocalDate localDate : allDateList) {
|
|
|
+ JsonObject rowTitleJson = new JsonObject();
|
|
|
+ rowTitleJson.addProperty("scheduleDate", localDate.format(formatter));
|
|
|
+ Double sum = 0d;
|
|
|
+ for (JsonElement jsonElement : allClassTimeDataArray) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ LocalDate scheduleDate = LocalDate.parse(object.get("scheduleDate").getAsString());
|
|
|
+ if(!scheduleDate.equals(localDate)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(weightSetMap.get(object.get("type").getAsString()) == null){
|
|
|
+ sum += object.get("content").getAsDouble();
|
|
|
+ allClassTime += object.get("content").getAsDouble();
|
|
|
+ }else{
|
|
|
+ sum += weightSetMap.get(object.get("type").getAsString());
|
|
|
+ allClassTime += weightSetMap.get(object.get("type").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rowTitleJson.addProperty("content", sum);
|
|
|
+ rowTitleJson.addProperty("type", "");
|
|
|
+ rowTitleJson.addProperty("adjustType", "");
|
|
|
+ rowTitle.add(rowTitleJson);
|
|
|
+ }
|
|
|
+ result.add("rowTitle", rowTitle);
|
|
|
+
|
|
|
+ //计算横向的合计
|
|
|
+ JsonArray columnTitle = new JsonArray();
|
|
|
+ for (String type : weightSetMap.keySet()) {
|
|
|
+ Double sum = 0d;
|
|
|
+ JsonObject columnTitleJson = new JsonObject();
|
|
|
+ for (JsonElement jsonElement : allClassTimeDataArray) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ String typeStr = object.get("type").getAsString();
|
|
|
+
|
|
|
+ if(!type.equals(typeStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sum += weightSetMap.get(typeStr);
|
|
|
+ }
|
|
|
+ columnTitleJson.addProperty("type", type);
|
|
|
+ columnTitleJson.addProperty("content", sum);
|
|
|
+ columnTitleJson.addProperty("scheduleDate", "");
|
|
|
+ columnTitleJson.addProperty("adjustType", "");
|
|
|
+ columnTitle.add(columnTitleJson);
|
|
|
+ }
|
|
|
+ String[] courseTimeTypes = CourseTimeTypeEnum.getValues();
|
|
|
+ for (String courseTimeType : courseTimeTypes) {
|
|
|
+ double sum = 0d;
|
|
|
+ JsonObject columnTitleJson = new JsonObject();
|
|
|
+ for (JsonElement jsonElement : allClassTimeDataArray) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ String typeStr = object.get("type").getAsString();
|
|
|
+ if (!courseTimeType.equals(typeStr)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sum += object.get("content").getAsDouble();
|
|
|
+ }
|
|
|
+ columnTitleJson.addProperty("type", courseTimeType);
|
|
|
+ columnTitleJson.addProperty("content", sum);
|
|
|
+ columnTitleJson.addProperty("scheduleDate", "");
|
|
|
+ columnTitleJson.addProperty("adjustType", "");
|
|
|
+ columnTitle.add(columnTitleJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.add("columnTitle", columnTitle);
|
|
|
+
|
|
|
+ result.add("data", allClassTimeDataArray);
|
|
|
+ result.addProperty("allClassTime", allClassTime);
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|