190 lines
7.6 KiB
Java
190 lines
7.6 KiB
Java
|
|
package com.nis.util;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
import com.google.common.collect.Lists;
|
|||
|
|
import com.nis.domain.configuration.AvFileSampleCfg;
|
|||
|
|
import com.nis.domain.configuration.AvSignSampleCfg;
|
|||
|
|
import com.nis.domain.configuration.BaseCfg;
|
|||
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
|||
|
|
import com.nis.domain.configuration.DnsIpCfg;
|
|||
|
|
import com.nis.domain.configuration.DnsResStrategy;
|
|||
|
|
import com.nis.domain.configuration.IpPortCfg;
|
|||
|
|
import com.nis.domain.configuration.PxyObjKeyring;
|
|||
|
|
import com.nis.domain.configuration.PxyObjTrustedCaCert;
|
|||
|
|
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
|
|||
|
|
import com.nis.web.dao.configuration.ConfigSynchronizationDao;
|
|||
|
|
import com.nis.web.service.BaseService;
|
|||
|
|
import com.nis.web.service.SpringContextHolder;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 配置任务调度通用类
|
|||
|
|
* 定时任务调用,处理界面配置状态修改,以及下发综合服务处理
|
|||
|
|
* @author ThinkPad
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
public class SchedulerTaskUtil {
|
|||
|
|
|
|||
|
|
//调度任务的配置信息,复用配置同步DAO
|
|||
|
|
private static ConfigSynchronizationDao configSynchronizationDao = SpringContextHolder.getBean(ConfigSynchronizationDao.class);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 根据业务与编译ID查询配置,修改失效或生效状态,并下发至综合服务
|
|||
|
|
* @param serviceId 不可空
|
|||
|
|
* @param compileId 不可空
|
|||
|
|
* @param oldIsValid 配置当前状态 0无效,1有效,可空
|
|||
|
|
* @param newIsValid 配置最新修改状态 0无效,1有效,不可空
|
|||
|
|
* @return boolean
|
|||
|
|
*/
|
|||
|
|
public boolean updateConfigByServiceAndCompile(Integer serviceId,Integer compileId,Integer oldIsValid,Integer newIsValid){
|
|||
|
|
//根据业务查询配置文件,获取该业务的配置域表信息
|
|||
|
|
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
|
|||
|
|
List<Map<String,Object>> serviceList = serviceTemplate.getServiceListByServiceId(serviceId);
|
|||
|
|
//根据编译ID查询配置表中的配置信息
|
|||
|
|
for(Map<String,Object> service:serviceList){
|
|||
|
|
String tableName = service.get("tableName").toString();
|
|||
|
|
String serviceType = service.get("serviceType").toString();
|
|||
|
|
String className = service.get("className").toString();
|
|||
|
|
BaseCfg entity = new BaseCfg();
|
|||
|
|
entity.setServiceId(serviceId);
|
|||
|
|
entity.setCompileId(compileId);
|
|||
|
|
entity.setTableName(tableName);
|
|||
|
|
List list = Lists.newArrayList();
|
|||
|
|
if("1".equals(serviceType)){//maat类配置
|
|||
|
|
//查询配置
|
|||
|
|
if("cfg_index_info".equals(tableName)){
|
|||
|
|
list = configSynchronizationDao.getCfgIndexList(entity);
|
|||
|
|
|
|||
|
|
}else if("file_digest_cfg".equals(tableName)){
|
|||
|
|
list = configSynchronizationDao.getFileDigestListByService(entity);
|
|||
|
|
|
|||
|
|
}else if("app_policy_cfg".equals(tableName)){
|
|||
|
|
list = configSynchronizationDao.getAppPolicyList(entity);
|
|||
|
|
|
|||
|
|
}else if("app_feature_index".equals(tableName)){
|
|||
|
|
list = configSynchronizationDao.getAppFeatureIndexList(entity);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if(newIsValid.equals(1)){//生效
|
|||
|
|
//调用综合服务配置生效启用接口
|
|||
|
|
|
|||
|
|
}else if(newIsValid.equals(0)){//失效
|
|||
|
|
//调用综合服务配置失效停用接口
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}else if("2".equals(serviceType)){//回调类配置
|
|||
|
|
List newList = Lists.newArrayList();
|
|||
|
|
List ids = Lists.newArrayList();
|
|||
|
|
//查询配置
|
|||
|
|
if(entity.getServiceId().equals(3)){//ip drop回调类配置用了主表和子表关系
|
|||
|
|
list = configSynchronizationDao.getCfgIndexList(entity);
|
|||
|
|
if(!StringUtil.isEmpty(list)){
|
|||
|
|
List<Integer> compileIds = Lists.newArrayList();
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
CfgIndexInfo cfg = (CfgIndexInfo) list.get(i);
|
|||
|
|
compileIds.add(cfg.getCompileId());
|
|||
|
|
}
|
|||
|
|
List subList = configSynchronizationDao.getIpDropList("ip_port_cfg", compileIds);
|
|||
|
|
for(int i=0;i<subList.size();i++){
|
|||
|
|
IpPortCfg cfg = (IpPortCfg) subList.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(BaseService.convertCallBackIp(cfg,cfg.getGroupId()));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}else{
|
|||
|
|
if(className.equals("AvFileSampleCfg")){
|
|||
|
|
list = configSynchronizationDao.getAvFileCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
AvFileSampleCfg cfg = (AvFileSampleCfg) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(cfg);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}else if(className.equals("AvSignSampleCfg")){//音视频场景配置
|
|||
|
|
list = configSynchronizationDao.getAvSignCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
AvSignSampleCfg cfg = (AvSignSampleCfg) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(cfg);
|
|||
|
|
}
|
|||
|
|
}else if(className.equals("PxyObjKeyring")){
|
|||
|
|
list = configSynchronizationDao.getPxyObjKeyringCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
PxyObjKeyring cfg = (PxyObjKeyring) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(BaseService.convertCallBackProxyObjKeyring(cfg));
|
|||
|
|
}
|
|||
|
|
}else if(className.equals("PxyObjTrustedCaCert")){
|
|||
|
|
//下发cert配置时,需绑定下发crl配置
|
|||
|
|
list = configSynchronizationDao.getPxyObjTrustedCertCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
PxyObjTrustedCaCert cfg = (PxyObjTrustedCaCert) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.addAll(BaseService.convertCallBackProxyObjTrustedCa(cfg,null));
|
|||
|
|
ids.add(cfg.getCompileId());
|
|||
|
|
}
|
|||
|
|
if(!StringUtil.isEmpty(ids)){
|
|||
|
|
list=new ArrayList<>();
|
|||
|
|
list=configSynchronizationDao.getPxyObjTrustedCrlCfgListByCertId(ids);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
PxyObjTrustedCaCrl cfg = (PxyObjTrustedCaCrl) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.addAll(BaseService.convertCallBackProxyObjTrustedCa(null,cfg));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}else if(className.equals("PxyObjTrustedCaCrl")){
|
|||
|
|
ids=new ArrayList<>();
|
|||
|
|
//只允许单独下发certId为空或0的crl配置
|
|||
|
|
list = configSynchronizationDao.getPxyObjTrustedCrlCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
PxyObjTrustedCaCrl cfg = (PxyObjTrustedCaCrl) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.addAll(BaseService.convertCallBackProxyObjTrustedCa(null,cfg));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}else if(className.equals("DnsResStrategy")){
|
|||
|
|
list = configSynchronizationDao.getDnsStrategyList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
DnsResStrategy cfg = (DnsResStrategy) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(BaseService.convertCallBackDnsResStrategy(cfg));
|
|||
|
|
}
|
|||
|
|
}else if(className.equals("DnsIpCfg")){
|
|||
|
|
list = configSynchronizationDao.getDnsIpCfgList(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
DnsIpCfg cfg = (DnsIpCfg) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(BaseService.convertCallBackIp(cfg,cfg.getDnsStrategyId()));
|
|||
|
|
}
|
|||
|
|
}else if(className.equals("IpPortCfg")){
|
|||
|
|
list = configSynchronizationDao.getIpPortListByService(entity);
|
|||
|
|
for(int i=0;i<list.size();i++){
|
|||
|
|
IpPortCfg cfg = (IpPortCfg) list.get(i);
|
|||
|
|
cfg.setIsValid(newIsValid);
|
|||
|
|
newList.add(BaseService.convertCallBackIp(cfg,cfg.getGroupId()));
|
|||
|
|
}
|
|||
|
|
}else if(className.equals("PxyObjSpoofingIpPool")){
|
|||
|
|
list = configSynchronizationDao.getSpoofingIpPoolList(entity);
|
|||
|
|
newList.addAll(list);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//调用服务接口下发配置数据
|
|||
|
|
String json=BaseService.gsonToJson(newList);
|
|||
|
|
if(newIsValid.equals(1)){//生效
|
|||
|
|
//调用综合服务配置生效启用接口
|
|||
|
|
|
|||
|
|
}else if(newIsValid.equals(0)){//失效
|
|||
|
|
//调用综合服务配置失效停用接口
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|