|
|
package com.yohoufo.resource.service.impl;
|
|
|
|
|
|
import com.yoho.core.cache.LocalCache;
|
|
|
import com.yohoufo.dal.resource.ResourcesGoodsPoolMapper;
|
|
|
import com.yohoufo.dal.resource.model.ConfigType;
|
|
|
import com.yohoufo.dal.resource.model.ResourcesGoodsPool;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by li.ma on 2018/11/17.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ResourcesGoodsPoolService {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ResourcesGoodsPoolService.class);
|
|
|
|
|
|
private LocalCache localCache = new LocalCache();
|
|
|
|
|
|
@Autowired
|
|
|
private ResourcesGoodsPoolMapper resourcesGoodsPoolMapper;
|
|
|
|
|
|
private final String NormalResourcesGoodsPool_CACHE_KEY= "ResourcesGoodsPoolList";
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
localCache.init(NormalResourcesGoodsPool_CACHE_KEY, 10, TimeUnit.MINUTES, (String s, Object o) -> {
|
|
|
LOGGER.info("ResourcesGoodsPoolList init s = {}, o = {}", s, o);
|
|
|
List<ResourcesGoodsPool> resourcesGoodsPoolList = resourcesGoodsPoolMapper.selectAll();
|
|
|
return resourcesGoodsPoolList.stream().collect(Collectors.toMap(ResourcesGoodsPool::getId, ResourcesGoodsPool::getPoolId));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有状态正常的配置项
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<Integer,Integer> configTypeList(){
|
|
|
Map<Integer,Integer> map = (Map<Integer,Integer>) localCache.get(NormalResourcesGoodsPool_CACHE_KEY);
|
|
|
if (map != null && map.size() > 0) {
|
|
|
return map;
|
|
|
}
|
|
|
return new HashMap<Integer, Integer>() {
|
|
|
{
|
|
|
map.put(2, 2);
|
|
|
map.put(4, 4);
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
} |
...
|
...
|
|