package com.nms.swspkmas_standalone.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.benmanes.caffeine.cache.Cache;
|
import com.nms.swspkmas_standalone.entity.CaptureRecord;
|
import com.nms.swspkmas_standalone.entity.Examinee;
|
import com.nms.swspkmas_standalone.entity.vo.CaptureRecordVO;
|
import com.nms.swspkmas_standalone.exception.ApiException;
|
import com.nms.swspkmas_standalone.mapper.CaptureRecordMapper;
|
import com.nms.swspkmas_standalone.service.CaptureRecordService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.sql.Wrapper;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 抓拍记录表 服务实现类
|
* </p>
|
*
|
* @author kzy
|
* @since 2023-09-21 08:41:38
|
*/
|
@Service
|
public class CaptureRecordServiceImpl extends ServiceImpl<CaptureRecordMapper, CaptureRecord> implements CaptureRecordService {
|
|
@Autowired
|
private Cache<String,Object> cacheService;
|
|
@Override
|
public void addCaptureRecord(CaptureRecordVO captureRecordVO) {
|
CaptureRecord captureRecord=new CaptureRecord();
|
BeanUtils.copyProperties(captureRecordVO,captureRecord);
|
String nowday= DateUtil.today();
|
captureRecord.setTime(nowday);
|
save(captureRecord);
|
}
|
|
@Override
|
public Map<String,List<CaptureRecord>> getCaptureRecord(String time) {
|
Map<String,List<CaptureRecord>> map=new LinkedHashMap<>();
|
List<CaptureRecord> captureRecordList=null;
|
Long count=count(Wrappers.<CaptureRecord>lambdaQuery().eq(true,CaptureRecord::getTime,time));
|
if(count==0){
|
return map;
|
}
|
String key="capture_"+time;
|
captureRecordList= (List<CaptureRecord>) cacheService.getIfPresent(key);
|
if(captureRecordList==null||count!=captureRecordList.size()){
|
captureRecordList=baseMapper.getCaptureRecord(time);
|
}
|
cacheService.put(key,captureRecordList);
|
for(CaptureRecord captureRecord:captureRecordList){
|
List<CaptureRecord> crList=map.get(captureRecord.getIdNumber());
|
if(crList==null){
|
crList=new ArrayList<>();
|
}
|
crList.add(captureRecord);
|
map.put(captureRecord.getIdNumber(),crList);
|
}
|
// Map<String,List<CaptureRecord>> map=captureRecordList.stream().collect(Collectors.toMap(CaptureRecord::getIdNumber,
|
// e -> new ArrayList(Arrays.asList(e)),
|
// (List<CaptureRecord> oldList,List<CaptureRecord> newList) -> {oldList.addAll(newList);return oldList;}));
|
return map;
|
}
|
|
@Override
|
public void deleteCaptureRecord(Long id) {
|
CaptureRecord captureRecord=getById(id);
|
if(captureRecord==null){
|
throw new ApiException("抓取记录不存在");
|
}
|
removeById(id);
|
}
|
}
|