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);
|
}
|
|
|
}
|