czt
2025-06-11 283da741b2429cf5a53786e5ee1b5528b757fdf6
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
package com.fzzy.igds.grain.service;
 
import com.fzzy.igds.dzhwk.constant.RedisConst;
import com.fzzy.igds.grain.dto.GrainData;
import com.fzzy.igds.grain.dto.GrainParam;
import com.fzzy.igds.grain.mapper.GrainServiceMapper;
import com.ruoyi.common.core.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @Description 粮情模块核心接口
 * @Author CZT
 * @Date 2024/12/02 15:33
 */
@Slf4j
@Service("dzhwk.grainService")
public class GrainService {
 
    @Resource
    private RedisCache redisCache;
    @Resource
    private GrainServiceMapper grainServiceMapper;
 
 
    /**
     * 获取缓存中最新的粮情检测数据
     *
     * @param companyId
     * @return key=参考编码
     */
    public GrainData getCacheGrainDate(String companyId, String depotId) {
        if (null == companyId || null == depotId) {
            return null;
        }
 
        String key = RedisConst.buildKey(companyId, RedisConst.KEY_GRAIN, depotId);
 
        GrainData grainData = redisCache.getCacheObject(key);
 
        if (null == grainData) {
            GrainParam param = new GrainParam();;
            param.setCompanyId(companyId);
            param.setDepotId(depotId);
            List<GrainData> list = grainServiceMapper.getGrainData(param);
            if (list != null && !list.isEmpty()) {
                grainData = list.get(0);
                redisCache.setCacheObject(key, grainData);
            }
        }
 
        return grainData;
    }
 
 
 
}