|
|
|
@ -28,6 +28,8 @@ import cn.teammodel.test.LessonRecordQueryService;
|
|
|
|
|
import cn.teammodel.utils.GroupUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
import com.google.common.cache.Cache;
|
|
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
@ -48,6 +50,7 @@ import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
@ -76,14 +79,33 @@ public class LaborEducationServiceImpl implements LaborEducationService {
|
|
|
|
|
private static Environment environment; // 静态字段
|
|
|
|
|
@Autowired
|
|
|
|
|
private Environment env; // 非静态字段
|
|
|
|
|
|
|
|
|
|
private static final int CACHE_EXPIRATION_HOURS = 8;
|
|
|
|
|
private static final int CACHE_MAXIMUM_SIZE = 1000;
|
|
|
|
|
private static final TimeUnit CACHE_EXPIRATION_UNIT = TimeUnit.HOURS;
|
|
|
|
|
// 引入缓存,需根据实际情况配置大小和过期时间 每次服务重启时 缓存会清空
|
|
|
|
|
private Cache<String, Map<String, Object>> analysisCache;
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init() {
|
|
|
|
|
LaborEducationServiceImpl.environment = env; // 在初始化时将非静态字段赋值给静态字段
|
|
|
|
|
// 创建公共配置的CacheBuilder
|
|
|
|
|
CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
|
|
|
|
|
.expireAfterWrite(CACHE_EXPIRATION_HOURS, CACHE_EXPIRATION_UNIT)
|
|
|
|
|
.maximumSize(CACHE_MAXIMUM_SIZE);
|
|
|
|
|
|
|
|
|
|
// 构建各缓存实例
|
|
|
|
|
analysisCache = cacheBuilder.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> getAnalysis(MoralDto laborDto, HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
String cacheKey = String.format("Moral_%s_%s_%s_%s_%s_%s_%s_%s_%s", laborDto.getCode(), laborDto.getStartTime(),
|
|
|
|
|
laborDto.getEndTime(), laborDto.getGrade(), laborDto.getClassId(), laborDto.getPeriodId(),
|
|
|
|
|
laborDto.getSubjectId(),laborDto.getAcademicYearId(),laborDto.getTmdId());
|
|
|
|
|
Map<String, Object> cachedResult = analysisCache.getIfPresent(cacheKey);
|
|
|
|
|
if (cachedResult != null) {
|
|
|
|
|
return cachedResult;
|
|
|
|
|
}
|
|
|
|
|
//根据具体参数查询相关课列内容
|
|
|
|
|
List<LessonRecord> records;
|
|
|
|
|
LessonRecordQueryService queryService = new LessonRecordQueryService(lessonRecordRepository);
|
|
|
|
@ -222,6 +244,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
|
|
|
|
|
List<Map<String, Object>> students = combineScoresWithExamResults(scores,examResults,knowledgeMap,point,knowledgeBlockToPointsMap);
|
|
|
|
|
resMap.put("scores", students);
|
|
|
|
|
}
|
|
|
|
|
analysisCache.put(cacheKey, resMap);
|
|
|
|
|
//处理主观评价内容
|
|
|
|
|
return resMap;
|
|
|
|
|
|
|
|
|
|