|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.core.cache.LocalCache;
|
|
|
import com.yohobuy.ufo.model.order.resp.ExpressCompanyRespBo;
|
|
|
import com.yohoufo.common.utils.OrikaUtils;
|
|
|
import com.yohoufo.dal.order.ExpressCompanyMapper;
|
|
|
import com.yohoufo.dal.order.model.ExpressCompany;
|
|
|
import com.yohoufo.order.service.IExpressCompanyService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
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.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @author kun.wang
|
|
|
* @date 2018/9/25
|
|
|
*/
|
|
|
@Service
|
|
|
public class ExpressCompanyServiceImpl implements IExpressCompanyService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ExpressCompanyServiceImpl.class);
|
|
|
|
|
|
private static final String EXPRESS_COMPANY_CACHE_KEY = "expressCompanyCacheKey";
|
|
|
|
|
|
@Autowired
|
|
|
private ExpressCompanyMapper expressCompanyMapper;
|
|
|
|
|
|
private LocalCache localCache = new LocalCache();
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<ExpressCompanyRespBo> queryAllExpressCompany() {
|
|
|
List<ExpressCompanyRespBo> expressCompanyRespBoList = (List<ExpressCompanyRespBo>) localCache.get(EXPRESS_COMPANY_CACHE_KEY);
|
|
|
if (CollectionUtils.isNotEmpty(expressCompanyRespBoList)) {
|
|
|
return expressCompanyRespBoList;
|
|
|
}
|
|
|
List<ExpressCompany> expressCompanies = expressCompanyMapper.queryAllExpressCompany();
|
|
|
return OrikaUtils.mapToList(expressCompanies, ExpressCompanyRespBo.class);
|
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
localCache.init("ExpressCompany", 2, TimeUnit.HOURS, (String s, Object o) -> {
|
|
|
LOGGER.info("init s = {}, o = {}", s, o);
|
|
|
List<ExpressCompany> expressCompanies = expressCompanyMapper.queryAllExpressCompany();
|
|
|
return OrikaUtils.mapToList(expressCompanies, ExpressCompanyRespBo.class);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getExpressName(Integer id) {
|
|
|
LOGGER.info("getExpressName param = {}", id);
|
|
|
ExpressCompanyRespBo expressCompanyRespBo = getExpressCompanyById(id);
|
|
|
if (expressCompanyRespBo == null) {
|
|
|
return StringUtils.EMPTY;
|
|
|
}
|
|
|
return expressCompanyRespBo.getCompanyName();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ExpressCompanyRespBo getExpressCompanyById(Integer id) {
|
|
|
LOGGER.info("getExpressCompanyById param = {}", id);
|
|
|
List<ExpressCompanyRespBo> expressCompanyRespBoList = (List<ExpressCompanyRespBo>) localCache.get(EXPRESS_COMPANY_CACHE_KEY);
|
|
|
LOGGER.info("getExpressCompanyById ExpressCompanyRespBo list = {}", JSON.toJSONString(expressCompanyRespBoList));
|
|
|
if (CollectionUtils.isEmpty(expressCompanyRespBoList)) {
|
|
|
return null;
|
|
|
}
|
|
|
for (ExpressCompanyRespBo expressCompanyRespBo : expressCompanyRespBoList) {
|
|
|
if (StringUtils.equals(String.valueOf(id), String.valueOf(expressCompanyRespBo.getId()))) {
|
|
|
return expressCompanyRespBo;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|