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
package com.qianwen.mdc.collect.service;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.mdc.collect.entity.mgr.WorkstationDatapoints;
import com.qianwen.mdc.collect.mapper.mgr.WorkstationDatapointsMapper;
import com.qianwen.mdc.collect.vo.WorkstationDatapointsVO;
/**
 * 工位数据点服务,主要用于获取数据点定义。定义在smartman应用
 */
@Service
public class WorkstationDatapointsService extends BaseServiceImpl<WorkstationDatapointsMapper, WorkstationDatapoints> {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    
    
    /**
     * 获取工位数据点配置 ,从缓存
     * @param workstationId
     * @return
     */
    @Cacheable(value = "collect:datapoint" ,key = "#appId")
    public WorkstationDatapointsVO getDatapointsByAppIdFromCache(String appId) {
        return this.getDataPointByAppId(appId);
    }
    
    /*
    @CachePut(value = "collect:datapoint" ,key = "#appId")
    public WorkstationDatapointsVO datapointsCachePut(String appId) {
        return this.getDataPointByAppId(appId);
    }
    */
    
    @CacheEvict(value = "collect:datapoint" ,key = "#appId")
    public void datapointsCacheEvict(String appId) {
        
    }
    /**
     * 从数据库查询数据点定义
     * @param workstationId 工位id
     * @return
     */
    WorkstationDatapointsVO getDataPointByAppId(String appId) {
        log.info("appid={}", appId);
        WorkstationDatapoints dp = baseMapper.selectOne(Wrappers.<WorkstationDatapoints>lambdaQuery()
                .eq(WorkstationDatapoints::getAppId, appId));
 
        log.info("dp={}", dp);
 
        WorkstationDatapointsVO dpVO = null;
 
        if (dp != null) {
            dpVO = new WorkstationDatapointsVO(dp.getWorkstationId(), dp.getAppId(), dp.getDpConfig());
        }
        return dpVO;
    }
 
}