admin
2021-06-02 512f368d7d8e71ee72a8f71dd7d2146f4c64f774
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.yeshi.fanli.service.manger;
 
import com.yeshi.fanli.dao.mongo.system.SystemPIDInfoDao;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.util.StringUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * 推广位管理器
 */
@Component
public class PIDManager {
 
    @Resource
    private SystemPIDInfoDao systemPIDInfoDao;
 
 
    /**
     * 根据PID查询pid完整信息
     *
     * @param pid
     * @param sourceType
     * @return
     */
    public List<SystemPIDInfo> listPidInfoByPid(String pid, Integer sourceType) {
        SystemPIDInfoDao.DaoQuery daoQuery = new SystemPIDInfoDao.DaoQuery();
        daoQuery.sourceType = sourceType;
        daoQuery.pid = pid;
        daoQuery.count = 100;
        return systemPIDInfoDao.list(daoQuery);
    }
 
 
    @Cacheable(value = "configCache", key = "' listPidInfoByPid-'+#pid+'-'+#sourceType")
    public List<SystemPIDInfo> listPidInfoByPidCache(String pid, Integer sourceType) {
        return listPidInfoByPid(pid, sourceType);
    }
 
 
    /**
     * 获取PID
     *
     * @param systemEnum
     * @param sourceType
     * @param pidType
     * @return
     */
    public String getPid(SystemEnum systemEnum, Integer sourceType, SystemPIDInfo.PidType pidType) {
        String id = SystemPIDInfo.createId(systemEnum, sourceType, pidType);
        SystemPIDInfo info = systemPIDInfoDao.get(id);
        if (info != null)
            return info.getPid();
        return null;
    }
 
    /**
     * 获取PID缓存
     *
     * @param systemEnum
     * @param pidType
     * @return
     */
    @Cacheable(value = "configCache", key = "'getPid-'+#systemEnum+'-'+#sourceType+'-'+#pidType")
    public String getPidCache(SystemEnum systemEnum, Integer sourceType, SystemPIDInfo.PidType pidType) {
        return getPid(systemEnum, sourceType, pidType);
    }
 
 
    /**
     * 保存PIDInfo
     *
     * @param pidInfo
     * @throws ParamsException
     */
    public void savePidInfo(SystemPIDInfo pidInfo) throws ParamsException {
        if (StringUtil.isNullOrEmpty(pidInfo.getPid()) || pidInfo.getSourceType() == null || pidInfo.getSystem() == null || pidInfo.getPidType() == null) {
            throw new ParamsException(1, "参数不完整");
        }
        String id = SystemPIDInfo.createId(pidInfo.getSystem(), pidInfo.getSourceType(), pidInfo.getPidType());
        pidInfo.setId(id);
        if (pidInfo.getCreateTime() == null) {
            pidInfo.setCreateTime(new Date());
        }
        systemPIDInfoDao.save(pidInfo);
    }
 
 
}