package com.ld.igds.common.impl;
|
|
import com.ld.igds.common.CoreThreeService;
|
import com.ld.igds.common.mapper.CommonMapper;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.RedisConst;
|
import com.ld.igds.models.ThreeConf;
|
import com.ld.igds.util.RedisUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Set;
|
|
@Slf4j
|
@Service(CoreThreeService.BEAN_ID)
|
public class CoreThreeServiceImpl implements CoreThreeService {
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private CommonMapper commonMapper;
|
|
|
@Override
|
public List<ThreeConf> getCacheThreeAll(String companyId) {
|
|
String patten = Constant.APP_NAME + ":" + companyId + ":" + RedisConst.KEY_THREE_CONF;
|
Set<String> keys = redisUtil.keys(patten);
|
List<ThreeConf> threeList = new ArrayList<>();
|
ThreeConf threeConf;
|
for (String key : keys) {
|
threeConf = (ThreeConf) redisUtil.get(key);
|
|
if(null != threeConf){
|
threeList.add(threeConf);
|
}
|
}
|
|
if (threeList.size() == 0) {
|
//从数据库获取并存入缓存
|
threeList = commonMapper.getAllThreeConf(companyId);
|
if (threeList.size() == 0) {
|
log.error("没有获取到三维配置");
|
return null;
|
}
|
}
|
|
return threeList;
|
}
|
|
@Override
|
public ThreeConf getCacheThreeConfById(String companyId, String threeId) {
|
|
String key = RedisConst.buildKey(companyId, RedisConst.KEY_THREE_CONF, threeId);
|
|
ThreeConf threeConf = (ThreeConf) redisUtil.get(key);
|
if(threeConf == null){
|
threeConf = commonMapper.getThreeConfByUid(companyId, threeId);
|
}
|
|
return threeConf;
|
}
|
|
}
|