package pwc.taxtech.atms.service.impl; import static pwc.taxtech.atms.common.CommonUtils.copyProperties; import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import pwc.taxtech.atms.dao.CacheMapper; import pwc.taxtech.atms.dto.CacheDto; import pwc.taxtech.atms.entitiy.Cache; import pwc.taxtech.atms.entitiy.CacheExample; import pwc.taxtech.atms.service.CacheService; @Service public class CacheServiceImpl implements CacheService { @Autowired private CacheMapper cacheMapper; @Override public List<CacheDto> getAllCache() { List<Cache> list = cacheMapper.selectByExample(null); return list.stream().map(this::convertToCacheDto).collect(Collectors.toList()); } @Override public CacheDto getCacheByKey(String cacheKey) { CacheExample example = new CacheExample(); example.createCriteria().andCacheKeyEqualTo(cacheKey); List<Cache> list = cacheMapper.selectByExample(example); return list.stream().findFirst().map(this::convertToCacheDto).orElse(null); } private CacheDto convertToCacheDto(Cache from) { CacheDto to = copyProperties(from, new CacheDto()); to.setCacheTime(from.getLastModifyTime()); return to; } }