CacheServiceImpl.java 1.32 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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;
    }

}