YYC
2023-06-27 1f2c3a31d9652b5d07f852b6d8d2b1b378adcfc2
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
    }
 
}