对象组提交
This commit is contained in:
@@ -16,11 +16,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import com.nis.domain.basics.*;
|
||||
import com.nis.domain.configuration.*;
|
||||
import com.nis.util.*;
|
||||
import com.nis.web.dao.CrudDao;
|
||||
import com.nis.web.dao.basics.*;
|
||||
import com.nis.web.dao.configuration.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
@@ -129,9 +134,7 @@ import com.nis.web.dao.configuration.StringCfgDao;
|
||||
import com.nis.web.dao.specific.ConfigGroupInfoDao;
|
||||
import com.nis.web.dao.specific.SpecificServiceCfgDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.basics.AsnGroupInfoService;
|
||||
import com.nis.web.service.basics.SysDictInfoService;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
|
||||
/**
|
||||
* Service基类
|
||||
@@ -326,7 +329,7 @@ public abstract class BaseService {
|
||||
*
|
||||
* getTableName(获取表名对应的Class) (这里描述这个方法适用条件 – 可选)
|
||||
*
|
||||
* @param clazz
|
||||
* @param tableName
|
||||
* @return String
|
||||
* @exception @since
|
||||
* 1.0.0
|
||||
@@ -741,7 +744,6 @@ public abstract class BaseService {
|
||||
* @param dstList
|
||||
* @param srcList
|
||||
* @param cfgType,1为IP类型,2为字符串类型,3为增强字符串,4数值类型,5摘要类,6回调类[但字符串类域配置和增强字符串域配置在接口参数中同属于strRegionList]
|
||||
* @param baseCfg,配置基本信息
|
||||
* @param groupRelationList
|
||||
* 配置分组列表
|
||||
* @return
|
||||
@@ -1536,7 +1538,7 @@ public abstract class BaseService {
|
||||
* @param regionDict
|
||||
* @param serviceDict
|
||||
* @param specificServiceCfg
|
||||
* @param asnNoMap
|
||||
* @param asnNoMaps
|
||||
* @param list
|
||||
* @param cfgIndexInfos
|
||||
* @param appPolicyCfgs
|
||||
@@ -2420,7 +2422,7 @@ public abstract class BaseService {
|
||||
|
||||
/**
|
||||
* 导入配置保存App特征
|
||||
* @param appPolicyCfgs
|
||||
* @param appFeatures
|
||||
*/
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveAppFeatureList(List<AppFeatureIndex> appFeatures){
|
||||
@@ -2444,8 +2446,10 @@ public abstract class BaseService {
|
||||
/**
|
||||
* 导入配置时数据批量入库(IP配置)
|
||||
*
|
||||
* @param data
|
||||
* @param tableName
|
||||
* @param regionDict
|
||||
* @param serviceDict
|
||||
* @param cfgs
|
||||
* @param send
|
||||
*/
|
||||
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
|
||||
public void saveIpBatch(FunctionRegionDict regionDict, FunctionServiceDict serviceDict,List<BaseIpCfg> cfgs, boolean send) {
|
||||
@@ -3306,5 +3310,291 @@ public abstract class BaseService {
|
||||
userRegion = gsonToJson(actionParam);
|
||||
return StringEscapeUtils.unescapeJson(userRegion);
|
||||
}
|
||||
|
||||
/**
|
||||
*只会更新maat配置,公共分组删除时会取消配置
|
||||
* 调用场景(1)公共分组域增加(3)公共分组修改(2)公共分组域删除(3)公共分组删除
|
||||
* @param policyGroupInfos
|
||||
|
||||
* @return
|
||||
*/
|
||||
public boolean transObjGroupToMaat(List<PolicyGroupInfo> policyGroupInfos){
|
||||
IpCommGroupCfgDao ipCommGroupCfgDao=SpringContextHolder.getBean(IpCommGroupCfgDao.class);
|
||||
UrlCommGroupDao urlCommGroupCfgDao=SpringContextHolder.getBean(UrlCommGroupDao.class);
|
||||
ScriberIdCommGroupDao scriberIdCommGroupDao=SpringContextHolder.getBean(ScriberIdCommGroupDao.class);
|
||||
DomainCommGroupDao domainCommGroupDao=SpringContextHolder.getBean(DomainCommGroupDao.class);
|
||||
CommonPolicyDao commonPolicyDao=SpringContextHolder.getBean(CommonPolicyDao.class);
|
||||
AreaIpCfgDao areaIpCfgDao=SpringContextHolder.getBean(AreaIpCfgDao.class);
|
||||
Set<String> ipDeletedGroups=new HashSet<>();
|
||||
Set<String> urlDeletedGroups=new HashSet<>();
|
||||
Set<String> subIdDeletedGroups=new HashSet<>();
|
||||
Set<String> domainDeletedGroups=new HashSet<>();
|
||||
//遍历,获取需要下发配置的组
|
||||
StringBuffer realGroupIds=new StringBuffer();
|
||||
for(PolicyGroupInfo policyGroupInfo:policyGroupInfos){
|
||||
//删除的时候
|
||||
if(policyGroupInfo.getUdFlag().equals(2)){
|
||||
realGroupIds.append(policyGroupInfo.getServiceGroupId()).append(",");
|
||||
if(policyGroupInfo.getGroupType().equals(Constants.IP_OBJ_GROUP_TYPE)){
|
||||
if(policyGroupInfo.getIsValid().equals(0)){
|
||||
ipDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||||
}
|
||||
}
|
||||
if(policyGroupInfo.getGroupType().equals(Constants.URL_OBJ_GROUP_TYPE)){
|
||||
if(policyGroupInfo.getIsValid().equals(0)){
|
||||
urlDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||||
}
|
||||
}
|
||||
if(policyGroupInfo.getGroupType().equals(Constants.SUBID_OBJ_GROUP_TYPE)){
|
||||
if(policyGroupInfo.getIsValid().equals(0)){
|
||||
subIdDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||||
}
|
||||
}
|
||||
if(policyGroupInfo.getGroupType().equals(Constants.DOMAIN_OBJ_GROUP_TYPE)){
|
||||
if(policyGroupInfo.getIsValid().equals(0)){
|
||||
domainDeletedGroups.add(policyGroupInfo.getServiceGroupId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(realGroupIds.toString().endsWith(",")){
|
||||
realGroupIds.deleteCharAt(realGroupIds.toString().length()-1);
|
||||
}
|
||||
List<CfgIndexInfo> toUpdateCfgIndexInfos=new ArrayList<>();
|
||||
//查询cfg_index_info表,获取所有用到了这个group_id的非删除配置
|
||||
List<CfgIndexInfo> cfgIndexInfos=commonPolicyDao.getObjGroupListByGroupIds(realGroupIds.toString(),null,null);
|
||||
|
||||
CfgIndexInfo auditCfg=new CfgIndexInfo();
|
||||
auditCfg.setTableName(CfgIndexInfo.getTablename());
|
||||
auditCfg.setIsAudit(Constants.AUDIT_YES);
|
||||
auditCfg.setAuditorId(UserUtils.getUser().getId());
|
||||
auditCfg.setAuditTime(new Date());
|
||||
List compileIds=new ArrayList();
|
||||
//组织一个大的json
|
||||
ToMaatBean maatBean = new ToMaatBean();
|
||||
ServiceConfigTemplateUtil templateUtil=new ServiceConfigTemplateUtil();
|
||||
Map<String,Object> interceptUserRegionMap=new HashMap<>();
|
||||
for(CfgIndexInfo cfgIndexInfo:cfgIndexInfos){
|
||||
Integer serviceId=cfgIndexInfo.getServiceId();
|
||||
if(serviceId!=null&&StringUtils.isNotBlank(cfgIndexInfo.getCommonGroupIds())){
|
||||
MaatCfg maatCfg = new MaatCfg();
|
||||
Set<Integer> groupIdSet=new HashSet<>();
|
||||
List<MaatCfg> configCompileList = new ArrayList();
|
||||
List<GroupCfg> groupRelationList = new ArrayList();
|
||||
List<IpCfg> ipRegionList = new ArrayList();
|
||||
List<StringCfg> strRegionList = new ArrayList();
|
||||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||||
List<DigestCfg> digestRegionList = new ArrayList();
|
||||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||||
Map<String,Object> userRgionMap=gsonFromJson(cfgIndexInfo.getCommonGroupIds(),Map.class);
|
||||
cfgIndexInfo.setUserRegion(userRgionMap);
|
||||
String oldCommonGroupIds=cfgIndexInfo.getCommonGroupIds();
|
||||
|
||||
this.processUserRegionMap(userRgionMap,"ipGroup",ipDeletedGroups,cfgIndexInfo,ipCommGroupCfgDao,IpCommCfg.class);
|
||||
this.processUserRegionMap(userRgionMap,"urlGroup",urlDeletedGroups,cfgIndexInfo,urlCommGroupCfgDao,UrlCommCfg.class);
|
||||
this.processUserRegionMap(userRgionMap,"subscribeIdGroup",subIdDeletedGroups,cfgIndexInfo,scriberIdCommGroupDao,ScriberIdCommCfg.class);
|
||||
this.processUserRegionMap(userRgionMap,"domainGroup",domainDeletedGroups,cfgIndexInfo,domainCommGroupDao,DomainCommCfg.class);
|
||||
|
||||
//需要更新的组
|
||||
cfgIndexInfo.setCommonGroupIds(gsonToJson(userRgionMap));
|
||||
if(!oldCommonGroupIds.equals(cfgIndexInfo.getCommonGroupIds())){
|
||||
toUpdateCfgIndexInfos.add(cfgIndexInfo);
|
||||
//commonPolicyDao.updateCfgIndexCommonGroupIds(cfgIndexInfo);
|
||||
}
|
||||
if(cfgIndexInfo.getIsValid().equals(Constants.VALID_YES)){
|
||||
//没组了,取消配置
|
||||
if(userRgionMap.isEmpty()){
|
||||
maatCfg.setCompileId(cfgIndexInfo.getCompileId());
|
||||
maatCfg.setServiceId(cfgIndexInfo.getServiceId());
|
||||
maatCfg.setIsValid(0);//无效
|
||||
configCompileList.add(maatCfg);
|
||||
}else{//有组,重新下发配置
|
||||
//保存区域IP信息
|
||||
List<AreaIpCfg> areaIpCfgList=areaIpCfgDao.getByCompileId(cfgIndexInfo.getCompileId());
|
||||
if(!StringUtil.isEmpty(areaIpCfgList)){
|
||||
AreaIpCfg cfg = new AreaIpCfg();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||||
cfg.setTableName(AreaIpCfg.getTablename());
|
||||
commonPolicyDao.auditCfg(cfg);
|
||||
|
||||
Map<String,List> map = cfgConvert(areaIpRegionList,areaIpCfgList,1,cfgIndexInfo,groupRelationList);
|
||||
groupRelationList=map.get("groupList");
|
||||
areaIpRegionList=map.get("dstList");
|
||||
}
|
||||
|
||||
Map<String,Object> maatTableMap=new HashMap<>();
|
||||
StringBuffer userRegion=new StringBuffer();
|
||||
List<Map<String,Object>> list= templateUtil.getServiceListByServiceId(serviceId);
|
||||
//获取业务下的配置域
|
||||
List<Map<String,Object>> cfgList = new ArrayList<>();
|
||||
//获取业务下的自定义域
|
||||
List<Map<String,Object>> userRegionList = new ArrayList<>();
|
||||
for(Map<String,Object> service:list){
|
||||
String serviceType = service.get("serviceType").toString();
|
||||
//主表上有maatTable的一般是app的表
|
||||
// if(service.containsKey("maatTable")){ }
|
||||
if(service.containsKey("cfgList")) {
|
||||
cfgList=(List<Map<String, Object>>) service.get("cfgList");
|
||||
maatTableMap=ConfigConvertUtil.convertCommonGroupMaatTable(cfgIndexInfo,cfgList);
|
||||
}
|
||||
if(service.containsKey("userRegionList")){
|
||||
//Map<String,Object> userregionMap=new HashMap<>();
|
||||
//userRegionList=(List<Map<String, Object>>) service.get("userRegionList");
|
||||
if(serviceId.equals(576)){
|
||||
String _userregion=ConfigConvertUtil.generateCommonGroupDefaultUserRegion(interceptUserRegionMap,serviceId);
|
||||
userRegion.append(_userregion);
|
||||
}else if(serviceId.equals(512)){
|
||||
cfgIndexInfo.setAction(2);
|
||||
String _userregion=ConfigConvertUtil.generateCommonGroupDefaultUserRegion(interceptUserRegionMap,serviceId);
|
||||
userRegion.append(_userregion);
|
||||
}
|
||||
}
|
||||
}
|
||||
compileIds.add(cfgIndexInfo.getCompileId());
|
||||
//子表
|
||||
//IP公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getIpCommGroupCfgList())){
|
||||
IpPortCfg cfg = new IpPortCfg();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||||
Map<String,List> map = ConfigConvertUtil.objGroupCfgConvert(ipRegionList,cfgIndexInfo.getIpCommGroupCfgList(),1,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
ipRegionList=map.get("dstList");
|
||||
if(map.get("numRegionList")!=null){
|
||||
numRegionList.addAll(map.get("numRegionList"));
|
||||
}
|
||||
|
||||
}
|
||||
//URL公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getUrlCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfgIndexInfo.getUrlCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
//账号公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getScriberIdCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||||
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfgIndexInfo.getScriberIdCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
|
||||
}
|
||||
//域名公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfgIndexInfo.getDomainCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, cfg, new String[]{"cfgId"});
|
||||
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfgIndexInfo.getDomainCommGroupList(),2,cfgIndexInfo,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
|
||||
}
|
||||
//构造提交综合服务参数格式
|
||||
maatCfg.initDefaultValue();
|
||||
BeanUtils.copyProperties(cfgIndexInfo, maatCfg);
|
||||
maatCfg.setAction(cfgIndexInfo.getAction());
|
||||
maatCfg.setAuditTime(cfgIndexInfo.getAuditTime());
|
||||
maatCfg.setIpRegionList(ipRegionList);
|
||||
maatCfg.setStrRegionList(strRegionList);
|
||||
maatCfg.setNumRegionList(numRegionList);
|
||||
maatCfg.setDigestRegionList(digestRegionList);
|
||||
maatCfg.setGroupRelationList(groupRelationList);
|
||||
maatCfg.setGroupNum(groupRelationList.size());
|
||||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||||
maatCfg.setIsValid(Constants.VALID_YES);
|
||||
//设置用户自定义域
|
||||
String protpcolType=cfgIndexInfo.getUserRegion1();
|
||||
|
||||
if("HTTPS".equalsIgnoreCase(protpcolType)||"INTERCEPT".equalsIgnoreCase(protpcolType)){
|
||||
if(StringUtils.isBlank(userRegion.toString())){
|
||||
userRegion.append("{}");
|
||||
}
|
||||
}else if("HTTP".equalsIgnoreCase(protpcolType)){
|
||||
}
|
||||
maatCfg.setUserRegion(userRegion.toString());
|
||||
|
||||
configCompileList.add(maatCfg);
|
||||
}
|
||||
if(CollectionUtils.isEmpty(maatBean.getConfigCompileList())){
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(cfgIndexInfo.getAuditTime());
|
||||
maatBean.setCreatorName(cfgIndexInfo.getCurrentUser().getName());
|
||||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||||
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
||||
}
|
||||
}
|
||||
|
||||
//下发maat配置
|
||||
//auditPolicy(cfgIndexInfo,cfgIndexInfo.getIsAudit(),Constants.UPDATE_ACTION);
|
||||
}
|
||||
}
|
||||
//需要更新的cfg_index_info数据库更新
|
||||
if(toUpdateCfgIndexInfos.size()>0){
|
||||
commonPolicyDao.updateCfgIndexCommonGroupIds(toUpdateCfgIndexInfos);
|
||||
}
|
||||
//向maat发送配置
|
||||
if(CollectionUtils.isNotEmpty(maatBean.getConfigCompileList())){
|
||||
//调用服务接口下发配置数据
|
||||
String json=gsonToJson(maatBean);
|
||||
logger.info("策略对象组下发配置参数:"+json);
|
||||
//调用服务接口下发配置
|
||||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||||
logger.info("策略对象组下发响应信息:"+result.getMsg());
|
||||
}
|
||||
//commonPolicyDao.auditCfgBatch(CfgIndexInfo.getTablename(),auditCfg,compileIds,null);
|
||||
return true;
|
||||
}
|
||||
private void processUserRegionMap(Map<String,Object> userRgionMap, String key, Set deletedGroups, CfgIndexInfo cfgIndexInfo, CrudDao dao,Class clazz) {
|
||||
if(userRgionMap.containsKey(key)){
|
||||
//排除删除的组,添加新的组
|
||||
for(String urlGroup:((String)userRgionMap.get(key)).split(",")){
|
||||
if(deletedGroups.contains(urlGroup)){
|
||||
userRgionMap.put(key,((String) userRgionMap.get(key)).replace(","+urlGroup+",",","));
|
||||
}
|
||||
}
|
||||
boolean contains=true;
|
||||
//空了
|
||||
if(userRgionMap.get(key).toString().equals(",")){
|
||||
userRgionMap.remove(key);
|
||||
contains=false;
|
||||
}
|
||||
if(contains&&cfgIndexInfo.getIsValid()==Constants.VALID_YES){
|
||||
if("IpCommCfg".equals(clazz.getSimpleName())){
|
||||
IpCommCfg searchCfg=new IpCommCfg();
|
||||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||||
List commCfgs=dao.findAllList(searchCfg);
|
||||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||||
cfgIndexInfo.setIpCommGroupCfgList(commCfgs);
|
||||
}
|
||||
}else if("ScriberIdCommCfg".equals(clazz.getSimpleName()) ){
|
||||
ScriberIdCommCfg searchCfg=new ScriberIdCommCfg();
|
||||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||||
List commCfgs=dao.findAllList(searchCfg);
|
||||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||||
cfgIndexInfo.setScriberIdCommGroupList(commCfgs);
|
||||
}
|
||||
}else if("UrlCommCfg".equals(clazz.getSimpleName())){
|
||||
UrlCommCfg searchCfg=new UrlCommCfg();
|
||||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||||
List commCfgs=dao.findAllList(searchCfg);
|
||||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||||
cfgIndexInfo.setUrlCommGroupList(commCfgs);
|
||||
}
|
||||
}else if("DomainCommCfg".equals(clazz.getSimpleName())){
|
||||
DomainCommCfg searchCfg=new DomainCommCfg();
|
||||
searchCfg.setCommonGroupIds(userRgionMap.get(key).toString().substring(1,userRgionMap.get(key).toString().length()-1));
|
||||
List commCfgs=dao.findAllList(searchCfg);
|
||||
if(CollectionUtils.isNotEmpty(commCfgs)){
|
||||
cfgIndexInfo.setDomainCommGroupList(commCfgs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.nis.web.dao.basics.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -50,7 +51,8 @@ public class CommonGroupManageService extends BaseService{
|
||||
private DomainCommGroupDao domainCommGroupDao;
|
||||
@Autowired
|
||||
private ScriberIdCommGroupDao scriberIdCommGroupDao;
|
||||
|
||||
@Autowired
|
||||
private PolicyGroupInfoDao policyGroupInfoDao;
|
||||
public Page<CommonGroupInfo> findCommonGroupInfoList(Page<CommonGroupInfo> page, CommonGroupInfo entity) {
|
||||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
||||
entity.setPage(page);
|
||||
@@ -108,7 +110,8 @@ public class CommonGroupManageService extends BaseService{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<PolicyGroupInfo> policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(ids);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
// 分组配置界面使用
|
||||
@@ -205,7 +208,7 @@ public class CommonGroupManageService extends BaseService{
|
||||
|
||||
/**
|
||||
* 校验执行删除操作后分组下域配置是否为空
|
||||
* @param serviceGroupIds
|
||||
* @param grouIdAndCfgId
|
||||
* @param groupType
|
||||
* @return
|
||||
*/
|
||||
@@ -225,7 +228,7 @@ public class CommonGroupManageService extends BaseService{
|
||||
map.put(groupId, list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<Integer> resultList = new ArrayList<Integer>();
|
||||
for (Integer groupId : map.keySet()) {
|
||||
List<Integer> cfgIdList = map.get(groupId);
|
||||
@@ -243,7 +246,7 @@ public class CommonGroupManageService extends BaseService{
|
||||
}else if(groupType == 9) { // ScriberId
|
||||
size = commonGroupManageDao.ajaxCheckIsLastOneCfg(groupId, cfgIds.substring(1), ScriberIdCommCfg.getTablename());
|
||||
}
|
||||
|
||||
|
||||
if(size == 0) { // 0为分组下的最后一条配置,获取配置ID提示
|
||||
Integer compileId = commonGroupManageDao.getCompileIdByGroupId(","+groupId+",");
|
||||
if(compileId != null) {
|
||||
@@ -253,5 +256,5 @@ public class CommonGroupManageService extends BaseService{
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class DomainCommGroupService extends CrudService<CrudDao<DomainCommCfg>,
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 8);
|
||||
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
|
||||
//transObjGroupToMaat(policyGroupInfos);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,12 +116,13 @@ public class DomainCommGroupService extends CrudService<CrudDao<DomainCommCfg>,
|
||||
domainCommGroupDao.update(entity);
|
||||
|
||||
// 更新分组状态
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
if(!entity.getUserRegion1().equals(entity.getGroupId().toString())) {
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 8);
|
||||
}
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +132,7 @@ public class DomainCommGroupService extends CrudService<CrudDao<DomainCommCfg>,
|
||||
domainCommGroupDao.delete(ids);
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 8);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
public List<DomainCommCfg> getByIds(String ids) {
|
||||
|
||||
@@ -75,13 +75,13 @@ public class IpCommGroupCfgService extends BaseService {
|
||||
public void update(IpCommCfg entity){
|
||||
ipCommGroupCfgDao.update(entity);
|
||||
// 更新分组状态
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
if(!entity.getUserRegion1().equals(entity.getGroupId().toString())) {
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 5);
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
}
|
||||
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public class IpCommGroupCfgService extends BaseService {
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 5);
|
||||
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
|
||||
//transObjGroupToMaat(policyGroupInfos);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class IpCommGroupCfgService extends BaseService {
|
||||
ipCommGroupCfgDao.delete(ids);
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 5);
|
||||
//transObjGroupToMaat(policyGroupInfos);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ScriberIdCommGroupService extends CrudService<CrudDao<ScriberIdComm
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 9);
|
||||
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
|
||||
//transObjGroupToMaat(policyGroupInfos);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -117,13 +117,13 @@ public class ScriberIdCommGroupService extends CrudService<CrudDao<ScriberIdComm
|
||||
scriberIdCommGroupDao.update(entity);
|
||||
|
||||
// 更新分组状态
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
if(!entity.getUserRegion1().equals(entity.getGroupId().toString())) {
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 9);
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
}
|
||||
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ public class ScriberIdCommGroupService extends CrudService<CrudDao<ScriberIdComm
|
||||
scriberIdCommGroupDao.delete(ids);
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 9);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
public List<ScriberIdCommCfg> getByIds(String ids) {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class UrlCommGroupService extends CrudService<CrudDao<UrlCommCfg>, UrlCom
|
||||
}
|
||||
// 更新分组状态
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 7);
|
||||
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,12 +114,13 @@ public class UrlCommGroupService extends CrudService<CrudDao<UrlCommCfg>, UrlCom
|
||||
urlCommGroupDao.update(entity);
|
||||
|
||||
// 更新分组状态
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
if(!entity.getUserRegion1().equals(entity.getGroupId().toString())) {
|
||||
List<PolicyGroupInfo> policyGroupInfos = new ArrayList<PolicyGroupInfo>();
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 7);
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getUserRegion1()));
|
||||
}
|
||||
policyGroupInfos.addAll(policyGroupInfoDao.findPolicyByServiceGroupInfoList(entity.getGroupId().toString()));
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +130,7 @@ public class UrlCommGroupService extends CrudService<CrudDao<UrlCommCfg>, UrlCom
|
||||
// 更新分组状态
|
||||
List<PolicyGroupInfo> policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(groupIds);
|
||||
groupManageService.updateGroupStatus(policyGroupInfos, 7);
|
||||
transObjGroupToMaat(policyGroupInfos);
|
||||
}
|
||||
|
||||
public List<UrlCommCfg> getByIds(String ids) {
|
||||
|
||||
@@ -1,51 +1,32 @@
|
||||
package com.nis.web.service.configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.nis.domain.basics.*;
|
||||
import com.nis.domain.configuration.*;
|
||||
import com.nis.util.*;
|
||||
import com.nis.web.dao.basics.*;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.dom4j.Node;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import antlr.StringUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.nis.domain.FunctionServiceDict;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.basics.AsnGroupInfo;
|
||||
import com.nis.domain.basics.AsnIpCfg;
|
||||
import com.nis.domain.configuration.AppFeatureIndex;
|
||||
import com.nis.domain.configuration.AppIpCfg;
|
||||
import com.nis.domain.configuration.AppPolicyCfg;
|
||||
import com.nis.domain.configuration.AvFileSampleCfg;
|
||||
import com.nis.domain.configuration.BaseCfg;
|
||||
import com.nis.domain.configuration.BaseStringCfg;
|
||||
import com.nis.domain.configuration.CfgIndexInfo;
|
||||
import com.nis.domain.configuration.ComplexkeywordCfg;
|
||||
import com.nis.domain.configuration.DdosIpCfg;
|
||||
import com.nis.domain.configuration.DnsIpCfg;
|
||||
import com.nis.domain.configuration.DnsResStrategy;
|
||||
import com.nis.domain.configuration.FileDigestCfg;
|
||||
import com.nis.domain.configuration.IpPortCfg;
|
||||
import com.nis.domain.configuration.PxyObjKeyring;
|
||||
import com.nis.domain.configuration.PxyObjSpoofingIpPool;
|
||||
import com.nis.domain.configuration.PxyObjTrustedCaCert;
|
||||
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
|
||||
import com.nis.domain.configuration.WebsiteDomainTopic;
|
||||
import com.nis.domain.maat.GroupReuseAddBean;
|
||||
import com.nis.domain.maat.GroupReuseCfg;
|
||||
import com.nis.domain.maat.MaatCfg;
|
||||
@@ -59,15 +40,6 @@ import com.nis.domain.maat.MaatCfg.StringCfg;
|
||||
import com.nis.domain.maat.ManipulatActionParam;
|
||||
import com.nis.domain.specific.ConfigGroupInfo;
|
||||
import com.nis.domain.specific.SpecificServiceCfg;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DateUtil;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.FileUtils;
|
||||
import com.nis.util.ServiceConfigTemplateUtil;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
||||
import com.nis.web.dao.configuration.AppCfgDao;
|
||||
import com.nis.web.dao.configuration.CommonPolicyDao;
|
||||
import com.nis.web.dao.configuration.ConfigSynchronizationDao;
|
||||
@@ -97,6 +69,14 @@ public class ConfigSynchronizationService extends BaseService{
|
||||
protected AppCfgDao appCfgDao;
|
||||
@Autowired
|
||||
protected PxyObjSpoofingIpPoolDao pxyObjSpoofingIpPoolDao;
|
||||
@Autowired
|
||||
protected IpCommGroupCfgDao ipCommGroupCfgDao;
|
||||
@Autowired
|
||||
protected ScriberIdCommGroupDao scriberIdCommGroupDao;
|
||||
@Autowired
|
||||
protected UrlCommGroupDao urlCommGroupDao;
|
||||
@Autowired
|
||||
protected DomainCommGroupDao domainCommGroupDao;
|
||||
|
||||
private boolean lastServiceTag = false;//标识是否是最后一个同步业务
|
||||
private boolean isFinished = false;
|
||||
@@ -132,25 +112,42 @@ public class ConfigSynchronizationService extends BaseService{
|
||||
String serviceType = service.get("serviceType").toString();
|
||||
String className = service.get("className").toString();
|
||||
String serviceId = service.get("id").toString();
|
||||
String serviceIds=service.get("serviceIds").toString();
|
||||
BaseCfg entity = new BaseCfg();
|
||||
entity.setServiceId(Integer.valueOf(serviceId));
|
||||
entity.setIsAudit(1);
|
||||
entity.setIsValid(1);
|
||||
entity.setTableName(tableName);
|
||||
if("1".equals(serviceType)){//maat类配置
|
||||
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
|
||||
List<Map<String,Object>> userRegionList = (List<Map<String, Object>>) service.get("userRegionList");
|
||||
if(cfgList.size()>0){
|
||||
Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false,tableName);
|
||||
if(StringUtils.isNotBlank(serviceIds)){//公共分组
|
||||
Map<Integer,List<Map<String,Object>>> childrenCfgMap=new HashMap<>();
|
||||
Map<Integer,List<Map<String,Object>>> childrenUserRegionMap=new HashMap<>();
|
||||
for(String _serviceId:serviceIds.split(",")){
|
||||
if(StringUtils.isNotBlank(_serviceId)){
|
||||
Map<String,Object> subService=serviceTemplate.getServiceListByServiceId(Integer.parseInt(_serviceId)).get(0);
|
||||
childrenCfgMap.put(Integer.parseInt(_serviceId),(List<Map<String,Object>>)subService.get("cfgList"));
|
||||
}
|
||||
}
|
||||
if(childrenCfgMap.size()>0){
|
||||
entity.setFunctionId(Integer.parseInt(service.get("functionId").toString()));
|
||||
Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleObjGroupListMaatData(childrenCfgMap,childrenUserRegionMap,page,entity,request,response,false,tableName);
|
||||
}
|
||||
}else{
|
||||
int cfgType = Integer.parseInt(service.get("cfgType").toString());
|
||||
if("ddos_ip_cfg".equals(tableName)){
|
||||
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
|
||||
List<Map<String,Object>> userRegionList = (List<Map<String, Object>>) service.get("userRegionList");
|
||||
if(cfgList.size()>0){
|
||||
Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false,tableName);
|
||||
}else{
|
||||
int cfgType = Integer.parseInt(service.get("cfgType").toString());
|
||||
if("ddos_ip_cfg".equals(tableName)){
|
||||
Page<DdosIpCfg> page=new Page<DdosIpCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false);
|
||||
}else{
|
||||
Page<T> page=new Page<T>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleSingleMaatData(cfgType,userRegionList,page,entity,request,response,false);
|
||||
}else{
|
||||
Page<T> page=new Page<T>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
|
||||
handleSingleMaatData(cfgType,userRegionList,page,entity,request,response,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if("2".equals(serviceType)){//回调类配置
|
||||
@@ -2252,4 +2249,262 @@ public class ConfigSynchronizationService extends BaseService{
|
||||
}
|
||||
return userRegion;
|
||||
}
|
||||
/**
|
||||
* 处理Obj group list
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalAccessException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public void handleObjGroupListMaatData(Map<Integer,List<Map<String,Object>>> cfgMap,Map<Integer,List<Map<String,Object>>> userRegionMap,
|
||||
Page<T> page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response,
|
||||
boolean isUpdateCfg,String tableName) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
||||
|
||||
boolean hasData = true;
|
||||
int index=0;
|
||||
while(hasData){
|
||||
entity.setPage(page);
|
||||
List list = Lists.newArrayList();
|
||||
if("cfg_index_info".equals(tableName)){
|
||||
int ind=0;
|
||||
for(Map.Entry e:cfgMap.entrySet()){
|
||||
entity.setServiceId((Integer) e.getKey());
|
||||
list = configSynchronizationDao.getCfgIndexList(entity);
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
hasData=auditObjGroupListMaatData(cfgMap,userRegionMap,page,entity,list,hasData,isUpdateCfg);
|
||||
if(hasData) {
|
||||
page.setPageNo(page.getNext());
|
||||
}
|
||||
}else{
|
||||
hasData = false;
|
||||
}
|
||||
ind++;
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
logger.info("全量同步未知业务");
|
||||
hasData = false;
|
||||
}
|
||||
|
||||
//此业务无数据需同步,也许向服务端发送一个{}串
|
||||
if(index ==0 && StringUtil.isEmpty(list) && !isUpdateCfg){
|
||||
String json = "{}";
|
||||
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+System.currentTimeMillis()+"(m nodata).json", json, false);
|
||||
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),entity.getTableName(),null);
|
||||
logger.info("全量下发响应信息:"+result.toString());
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Obj Group List 配置批量下发
|
||||
* @param cfgMap
|
||||
* @param userRegionMap
|
||||
* @param page
|
||||
* @param entity
|
||||
* @param list
|
||||
* @param hasData
|
||||
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
|
||||
* @return
|
||||
* @throws NoSuchFieldException
|
||||
* @throws SecurityException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public boolean auditObjGroupListMaatData(Map<Integer,List<Map<String,Object>>> cfgMap,
|
||||
Map<Integer,List<Map<String,Object>>> userRegionMap,
|
||||
Page page,
|
||||
BaseCfg entity,
|
||||
List<CfgIndexInfo> list,
|
||||
boolean hasData,
|
||||
boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
|
||||
ToMaatBean maatBean;
|
||||
MaatCfg maatCfg;
|
||||
List<MaatCfg> configCompileList;
|
||||
List<GroupCfg> groupRelationList;
|
||||
List<IpCfg> ipRegionList;
|
||||
List<StringCfg> strRegionList;
|
||||
List<NumBoundaryCfg> numRegionList;
|
||||
List<DigestCfg> digestRegionList;
|
||||
List<IpCfg> areaIpRegionList;
|
||||
|
||||
List<IpPortCfg> ipList = new ArrayList();
|
||||
List<AsnIpCfg> asnIpList = new ArrayList();
|
||||
List<BaseStringCfg> strList = new ArrayList();
|
||||
List<ComplexkeywordCfg> complexStrList = new ArrayList();
|
||||
List<com.nis.domain.configuration.NumBoundaryCfg> numList = new ArrayList();
|
||||
List<FileDigestCfg> fileList = new ArrayList();
|
||||
maatBean = new ToMaatBean();
|
||||
configCompileList = new ArrayList();
|
||||
List<Integer> compileIds = new ArrayList();
|
||||
List<IpCommCfg> ipCommCfgList=new ArrayList<>();
|
||||
List<ScriberIdCommCfg> scriberIdCommCfgList=new ArrayList<>();
|
||||
List<UrlCommCfg> urlCommCfgList=new ArrayList<>();
|
||||
List<DomainCommCfg> domainCommCfgList=new ArrayList<>();
|
||||
for(CfgIndexInfo cfg:list){
|
||||
//查询子配置
|
||||
String commonGroupIds=cfg.getCommonGroupIds();
|
||||
if(StringUtils.isNotBlank(commonGroupIds)){
|
||||
Map<String,Object> groupMap=ConfigConvertUtil.gsonFromJson(commonGroupIds,Map.class);
|
||||
if(groupMap.containsKey("ipGroup")){
|
||||
IpCommCfg commCfg=new IpCommCfg();
|
||||
commCfg.setCommonGroupIds(groupMap.get("ipGroup").toString().substring(1,groupMap.get("ipGroup").toString().length()-1));
|
||||
List<IpCommCfg> commIps=ipCommGroupCfgDao.findAllList(commCfg);
|
||||
if(CollectionUtils.isNotEmpty(commIps)){
|
||||
cfg.setIpCommGroupCfgList(commIps);
|
||||
}
|
||||
}
|
||||
if(groupMap.containsKey("subscribeIdGroup")){
|
||||
ScriberIdCommCfg commCfg=new ScriberIdCommCfg();
|
||||
commCfg.setCommonGroupIds(groupMap.get("subscribeIdGroup").toString().substring(1,groupMap.get("subscribeIdGroup").toString().length()-1));
|
||||
List<ScriberIdCommCfg> commIds=scriberIdCommGroupDao.findAllList(commCfg);
|
||||
if(CollectionUtils.isNotEmpty(commIds)){
|
||||
cfg.setScriberIdCommGroupList(commIds);
|
||||
}
|
||||
}
|
||||
if(groupMap.containsKey("urlGroup")){
|
||||
UrlCommCfg commCfg=new UrlCommCfg();
|
||||
commCfg.setCommonGroupIds(groupMap.get("urlGroup").toString().substring(1,groupMap.get("urlGroup").toString().length()-1));
|
||||
List<UrlCommCfg> commIds=urlCommGroupDao.findAllList(commCfg);
|
||||
if(CollectionUtils.isNotEmpty(commIds)){
|
||||
cfg.setUrlCommGroupList(commIds);
|
||||
}
|
||||
}
|
||||
if(groupMap.containsKey("domainGroup")){
|
||||
DomainCommCfg commCfg=new DomainCommCfg();
|
||||
commCfg.setCommonGroupIds(groupMap.get("domainGroup").toString().substring(1,groupMap.get("domainGroup").toString().length()-1));
|
||||
List<DomainCommCfg> commIds=domainCommGroupDao.findAllList(commCfg);
|
||||
if(CollectionUtils.isNotEmpty(commIds)){
|
||||
cfg.setDomainCommGroupList(commIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(isUpdateCfg) {
|
||||
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
|
||||
commonPolicyDao.auditCfgBatch( entity.getTableName(), entity,compileIds,null);
|
||||
}
|
||||
}
|
||||
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),分组复用的域配置不需要重新获取regionId,groupId
|
||||
// List<Integer> regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
||||
// List<Integer> groupIds = ConfigServiceUtil.getId(2, ipList.size()+strList.size()+complexStrList.size()+numList.size()+fileList.size());
|
||||
for(CfgIndexInfo cfg:list){
|
||||
maatCfg = new MaatCfg();
|
||||
maatCfg.initDefaultValue();
|
||||
groupRelationList = new ArrayList();
|
||||
ipRegionList = new ArrayList();
|
||||
strRegionList = new ArrayList();
|
||||
numRegionList = new ArrayList();
|
||||
digestRegionList = new ArrayList();
|
||||
areaIpRegionList = new ArrayList();
|
||||
List list1 = new ArrayList();
|
||||
List<BaseStringCfg> list2 = new ArrayList();
|
||||
List<ComplexkeywordCfg> list3 = new ArrayList();
|
||||
List<com.nis.domain.configuration.NumBoundaryCfg> list4 = new ArrayList();
|
||||
List<FileDigestCfg> list5 = new ArrayList();
|
||||
StringBuffer userRegion = new StringBuffer();
|
||||
//处理自定义域
|
||||
if(userRegionMap.containsKey(cfg.getServiceId())){
|
||||
List<Map<String,Object>> userRegionList=userRegionMap.get(cfg.getServiceId());
|
||||
userRegion.append(ConfigConvertUtil.generateCommonGroupDefaultUserRegion(null,cfg.getServiceId()));
|
||||
}
|
||||
|
||||
//Intercept Policy、http(s) 监测 、http(s) 白名单
|
||||
if("HTTPS".equalsIgnoreCase(entity.getUserRegion1())||"INTERCEPT".equalsIgnoreCase(entity.getUserRegion1())&&userRegion.toString().length()==0) {
|
||||
userRegion.append("{}");
|
||||
}
|
||||
//子配置
|
||||
if(cfgMap.containsKey(cfg.getServiceId())){
|
||||
List<Map<String,Object>> cfgList=(List<Map<String,Object>>)cfgMap.get(cfg.getServiceId());
|
||||
Map<String,Object> maatTableMap=ConfigConvertUtil.convertCommonGroupMaatTable(cfg,cfgList);
|
||||
Set<Integer> groupIdSet=new HashSet<>();
|
||||
//IP公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfg.getIpCommGroupCfgList())){
|
||||
IpPortCfg _cfg = new IpPortCfg();
|
||||
BeanUtils.copyProperties(cfg, _cfg, new String[]{"cfgId"});
|
||||
Map<String,List> map = ConfigConvertUtil.objGroupCfgConvert(ipRegionList,cfg.getIpCommGroupCfgList(),1,_cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
ipRegionList=map.get("dstList");
|
||||
if(map.get("numRegionList")!=null){
|
||||
numRegionList.addAll(map.get("numRegionList"));
|
||||
}
|
||||
|
||||
}
|
||||
//URL公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfg.getUrlCommGroupList())){
|
||||
CommonStringCfg _cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfg, _cfg, new String[]{"cfgId"});
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfg.getUrlCommGroupList(),2,_cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
//账号公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfg.getScriberIdCommGroupList())){
|
||||
CommonStringCfg _cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfg, _cfg, new String[]{"cfgId"});
|
||||
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfg.getScriberIdCommGroupList(),2,_cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
|
||||
}
|
||||
//域名公共分组
|
||||
if(CollectionUtils.isNotEmpty(cfg.getDomainCommGroupList())){
|
||||
CommonStringCfg _cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(cfg, _cfg, new String[]{"cfgId",});
|
||||
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,cfg.getDomainCommGroupList(),2,_cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
BeanUtils.copyProperties(cfg, maatCfg);
|
||||
maatCfg.setAction(cfg.getAction());
|
||||
maatCfg.setAuditTime(StringUtil.isEmpty(entity.getAuditTime()) ? cfg.getAuditTime():entity.getAuditTime());
|
||||
maatCfg.setIpRegionList(ipRegionList);
|
||||
maatCfg.setStrRegionList(strRegionList);
|
||||
maatCfg.setNumRegionList(numRegionList);
|
||||
maatCfg.setDigestRegionList(digestRegionList);
|
||||
maatCfg.setGroupRelationList(groupRelationList);
|
||||
maatCfg.setGroupNum(groupRelationList.size());
|
||||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||||
maatCfg.setIsValid(entity.getIsValid());
|
||||
if(!StringUtil.isEmpty(userRegion.toString())){
|
||||
maatCfg.setUserRegion(userRegion.toString());
|
||||
}
|
||||
configCompileList.add(maatCfg);
|
||||
}
|
||||
}
|
||||
page.setList(list);
|
||||
if(page.getLast()==page.getPageNo()){
|
||||
hasData = false;
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(configCompileList)){
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(new Date());
|
||||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||||
String json=gsonToJson(maatBean);
|
||||
//调用服务接口下发配置数据
|
||||
if(isUpdateCfg) {
|
||||
//logger.info("配置批量下发:"+json);
|
||||
//调用服务接口同步回调类配置
|
||||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||||
if(result!=null){
|
||||
logger.info("配置批量下发响应信息:"+result.getMsg());
|
||||
}
|
||||
}else {
|
||||
//调用服务接口配置全量更新
|
||||
isFinished = ((!hasData)&&lastServiceTag)?true:false;
|
||||
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
|
||||
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
|
||||
logger.info("全量下发响应信息:"+result.toString());
|
||||
}
|
||||
}
|
||||
return hasData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,656 @@
|
||||
package com.nis.web.service.configuration;
|
||||
|
||||
import com.nis.domain.FunctionServiceDict;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.basics.*;
|
||||
import com.nis.domain.configuration.*;
|
||||
import com.nis.domain.maat.MaatCfg;
|
||||
import com.nis.domain.maat.ToMaatBean;
|
||||
import com.nis.domain.maat.ToMaatResult;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.*;
|
||||
import com.nis.web.dao.basics.IpCommGroupCfgDao;
|
||||
import com.nis.web.dao.basics.PolicyGroupInfoDao;
|
||||
import com.nis.web.dao.basics.UrlCommGroupDao;
|
||||
import com.nis.web.dao.configuration.AreaIpCfgDao;
|
||||
import com.nis.web.dao.configuration.CommonPolicyDao;
|
||||
import com.nis.web.dao.configuration.ObjectGroupDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.BaseService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ObjectGroupService extends BaseService {
|
||||
@Autowired
|
||||
private ObjectGroupDao objectGroupDao;
|
||||
@Autowired
|
||||
private CommonPolicyDao commonPolicyDao;
|
||||
@Autowired
|
||||
private AreaIpCfgDao areaIpCfgDao;
|
||||
@Autowired
|
||||
private PolicyGroupInfoDao policyGroupInfoDao;
|
||||
@Autowired
|
||||
private IpCommGroupCfgDao ipCommGroupCfgDao;
|
||||
@Autowired
|
||||
private UrlCommGroupDao urlCommGroupCfgDao;
|
||||
public Page getPolicyListList(Page searchPage, CfgIndexInfo searchCfg) {
|
||||
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
|
||||
searchCfg.getSqlMap().put("dsf", configScopeFilter(searchCfg.getCurrentUser(),"a"));
|
||||
searchCfg.setPage(searchPage);
|
||||
List<CfgIndexInfo> list = commonPolicyDao.getPolicyList(searchCfg);
|
||||
for(CfgIndexInfo c:list){
|
||||
if(StringUtils.isNotBlank(c.getCommonGroupIds())){
|
||||
c.setUserRegion(this.gsonFromJson(c.getCommonGroupIds(),Map.class));
|
||||
}
|
||||
}
|
||||
searchPage.setList(list);
|
||||
return searchPage;
|
||||
}
|
||||
public CfgIndexInfo getObjectGroupCfg(Long cfgId,Integer compileId) {
|
||||
CfgIndexInfo cfg=objectGroupDao.getObjectGroupConfig(cfgId,compileId);
|
||||
//去除首尾括号
|
||||
if(StringUtils.isNotBlank(cfg.getCommonGroupIds())){
|
||||
Map<String,Object> userRegionMap=gsonFromJson(cfg.getCommonGroupIds(),Map.class);
|
||||
for(Map.Entry<String,Object> e:userRegionMap.entrySet()){
|
||||
String value=(String)e.getValue();
|
||||
if(value.startsWith(",")){
|
||||
value=value.substring(1);
|
||||
}
|
||||
if(value.endsWith(",")){
|
||||
value=value.substring(0,value.length()-1);
|
||||
}
|
||||
userRegionMap.put(e.getKey(),value);
|
||||
}
|
||||
cfg.setUserRegion(userRegionMap);
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public void saveOrUpdate(CfgIndexInfo entity) {
|
||||
String protocolType=entity.getUserRegion1();
|
||||
//获取旧的ID,用于更新时恢复policyGroupInfo的可选状态
|
||||
String oldCommonGroupIds= StringEscapeUtils.unescapeHtml(entity.getCommonGroupIds());
|
||||
//设置区域运营商信息
|
||||
setAreaEffectiveIds(entity);
|
||||
|
||||
int isValid=0;
|
||||
if(!StringUtil.isEmpty(entity.getIsValid()) && entity.getIsValid()==1) {
|
||||
isValid=1;
|
||||
}
|
||||
entity.setIsValid(0);
|
||||
entity.setIsAudit(0);
|
||||
//设置service_id
|
||||
if("HTTP".equalsIgnoreCase(protocolType)){
|
||||
|
||||
}else if("HTTPS".equalsIgnoreCase(protocolType)){
|
||||
if(entity.getAction().equals(1)){
|
||||
entity.setServiceId(592);
|
||||
}else if(entity.getAction().equals(16)){
|
||||
entity.setServiceId(576);
|
||||
}
|
||||
}else if("INTERCEPT".equalsIgnoreCase(protocolType)){
|
||||
entity.setServiceId(512);
|
||||
}
|
||||
if(entity.getCfgId()==null){
|
||||
Integer compileId = 0;
|
||||
try {
|
||||
//处理组
|
||||
if(!StringUtil.isEmpty(entity.getUserRegion())){
|
||||
entity.setCommonGroupIds(gsonToJson(entity.getUserRegion()));
|
||||
}
|
||||
List<Integer> idList = ConfigServiceUtil.getId(1, 1);
|
||||
if(idList!=null && idList.size()>0){
|
||||
compileId = idList.get(0);
|
||||
}
|
||||
entity.setCompileId(compileId);
|
||||
entity.setCreateTime(new Date());
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
commonPolicyDao.saveCfgIndex(entity);
|
||||
//保存区域IP信息
|
||||
if(entity.getAreaCfg()!=null){
|
||||
for(AreaIpCfg cfg:entity.getAreaCfg()){
|
||||
cfg.initDefaultValue();
|
||||
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
|
||||
areaIpCfgDao.saveAreaIpCfg(cfg);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("数据保存出错");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(isValid==1) {
|
||||
entity.setIsAudit(1);
|
||||
entity.setIsValid(1);
|
||||
auditPolicy(entity, entity.getIsAudit(),Constants.INSERT_ACTION);
|
||||
}
|
||||
|
||||
}else{
|
||||
//处理公共分组
|
||||
if(MapUtils.isNotEmpty(entity.getUserRegion())){
|
||||
entity.setCommonGroupIds(gsonToJson(entity.getUserRegion()));
|
||||
}else{
|
||||
entity.setCommonGroupIds("");
|
||||
}
|
||||
// 审核未通过状态的配置 修改后状态改为未审核
|
||||
entity.setIsValid(0);
|
||||
entity.setIsAudit(0);
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(new Date());
|
||||
commonPolicyDao.updateCfgIndex(entity);
|
||||
|
||||
AreaIpCfg area = new AreaIpCfg();
|
||||
area.setCompileId(entity.getCompileId());
|
||||
area.setFunctionId(entity.getFunctionId());
|
||||
areaIpCfgDao.deleteAreaIpCfg(area);
|
||||
entity.setCreateTime(new Date());
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
|
||||
//保存区域IP信息
|
||||
if(entity.getAreaCfg()!=null){
|
||||
for(AreaIpCfg cfg:entity.getAreaCfg()){
|
||||
cfg.initDefaultValue();
|
||||
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"});
|
||||
areaIpCfgDao.saveAreaIpCfg(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
if(isValid==1) {
|
||||
entity.setIsAudit(1);
|
||||
entity.setIsValid(1);
|
||||
auditPolicy(entity, entity.getIsAudit(), Constants.UPDATE_ACTION);
|
||||
}
|
||||
}
|
||||
//更新UD_FLAG
|
||||
if(StringUtils.isNotBlank(oldCommonGroupIds)){
|
||||
Map<String,Object> oldMap=gsonFromJson(oldCommonGroupIds,Map.class);
|
||||
Map<String,Object> newMap=entity.getUserRegion();
|
||||
StringBuffer canceledGroup=new StringBuffer();
|
||||
|
||||
for(Map.Entry<String,Object> e:oldMap.entrySet()){
|
||||
if(MapUtils.isEmpty(newMap)){
|
||||
for(String s:((String)e.getValue()).split(",")){
|
||||
if(StringUtils.isNotBlank(s)){
|
||||
canceledGroup.append(","+s);
|
||||
}
|
||||
}
|
||||
}else if(newMap.containsKey(e.getKey())){
|
||||
for(String s:((String)e.getValue()).split(",")){
|
||||
if(StringUtils.isNotBlank(s)&&newMap.get(e.getKey()).toString().indexOf(","+s+",")==-1){
|
||||
canceledGroup.append(","+s);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(StringUtils.isNotBlank(e.getValue().toString())){
|
||||
String val=e.getValue().toString().substring(0,e.getValue().toString().length()-1);
|
||||
canceledGroup.append(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StringBuffer okGroup=new StringBuffer();
|
||||
for(Object val:newMap.values()){
|
||||
String _val=(String)val;
|
||||
if(StringUtils.isNotBlank(_val)){
|
||||
if(_val.startsWith(",")){
|
||||
okGroup.append(_val.substring(1));
|
||||
}else{
|
||||
okGroup.append(_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
//取消勾选的组更新UD_FLAG
|
||||
if(StringUtils.isNotBlank(canceledGroup.toString())){
|
||||
policyGroupInfoDao.updateUdFlag(canceledGroup.toString().substring(1),1,null);
|
||||
}
|
||||
//新选择的组更新UD_FALG
|
||||
if(StringUtils.isNotBlank(okGroup.toString())){
|
||||
okGroup.deleteCharAt(okGroup.toString().length()-1);
|
||||
policyGroupInfoDao.updateUdFlag(okGroup.toString(),2,null);
|
||||
}
|
||||
}else if(MapUtils.isNotEmpty(entity.getUserRegion())){
|
||||
policyGroupInfoDao.updateUdFlag(userRegionMapToString(entity.getUserRegion()),2,null);
|
||||
}
|
||||
//处理定时任务
|
||||
handelScheduleCfg(entity, entity.getIndexTable(), entity);
|
||||
}
|
||||
public CfgIndexInfo getObjGroupPolicyWithoutSubCfg(Long cfgId){
|
||||
CfgIndexInfo entity = commonPolicyDao.getPolicyById(cfgId);
|
||||
entity.setUserRegion((Map<String,Object>)this.gsonFromJson(entity.getUserRegion1(),Map.class));
|
||||
return entity;
|
||||
}
|
||||
public CfgIndexInfo getObjGroupPolicy(Long cfgId){
|
||||
CfgIndexInfo entity = commonPolicyDao.getPolicyById(cfgId);
|
||||
entity.setUserRegion((Map<String,Object>)this.gsonFromJson(entity.getCommonGroupIds(),Map.class));
|
||||
if(entity.getUserRegion().containsKey("ipGroup")){
|
||||
String ids=entity.getUserRegion().get("ipGroup").toString().startsWith(",")?entity.getUserRegion().get("ipGroup").toString().substring(1):entity.getUserRegion().get("ipGroup").toString();
|
||||
ids=ids.endsWith(",")?ids.substring(0,ids.length()-1):ids;
|
||||
List<IpCommCfg> ipList = objectGroupDao.getIpCommonList(ids,null);
|
||||
entity.setIpCommGroupCfgList(ipList);
|
||||
}
|
||||
if(entity.getUserRegion().containsKey("subscribeIdGroup")){
|
||||
String ids=entity.getUserRegion().get("subscribeIdGroup").toString().startsWith(",")?entity.getUserRegion().get("subscribeIdGroup").toString().substring(1):entity.getUserRegion().get("subscribeIdGroup").toString();
|
||||
ids=ids.endsWith(",")?ids.substring(0,ids.length()-1):ids;
|
||||
List<ScriberIdCommCfg> stringList=objectGroupDao.getScriberIdCommonList(ids,null);
|
||||
entity.setScriberIdCommGroupList(stringList);
|
||||
}
|
||||
if(entity.getUserRegion().containsKey("domainGroup")){
|
||||
String ids=entity.getUserRegion().get("domainGroup").toString().startsWith(",")?entity.getUserRegion().get("domainGroup").toString().substring(1):entity.getUserRegion().get("domainGroup").toString();
|
||||
ids=ids.endsWith(",")?ids.substring(0,ids.length()-1):entity.getUserRegion().get("domainGroup").toString();
|
||||
List<DomainCommCfg> stringList=objectGroupDao.getDomainCommonList(ids,null);
|
||||
entity.setDomainCommGroupList(stringList);
|
||||
}
|
||||
if(entity.getUserRegion().containsKey("urlGroup")){
|
||||
String ids=entity.getUserRegion().get("urlGroup").toString().startsWith(",")?entity.getUserRegion().get("urlGroup").toString().substring(1):entity.getUserRegion().get("urlGroup").toString();
|
||||
ids=ids.endsWith(",")?ids.substring(0,ids.length()-1):ids;
|
||||
List<UrlCommCfg> stringList = objectGroupDao.getUrlCommonList(ids,null);
|
||||
entity.setUrlCommGroupList(stringList);
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void auditPolicy(CfgIndexInfo entity,Integer isAudit,Integer opAction) throws MaatConvertException {
|
||||
//修改数据库审核状态信息
|
||||
entity.setTableName(CfgIndexInfo.getTablename());
|
||||
entity.setIsAudit(isAudit);
|
||||
entity.setAuditorId(UserUtils.getUser().getId());
|
||||
entity.setAuditTime(new Date());
|
||||
//审核cfg_index_info
|
||||
commonPolicyDao.auditCfg(entity);
|
||||
|
||||
ToMaatBean maatBean = new ToMaatBean();
|
||||
MaatCfg maatCfg = new MaatCfg();
|
||||
Set<Integer> groupIdSet=new HashSet<>();
|
||||
List<MaatCfg> configCompileList = new ArrayList();
|
||||
List<MaatCfg.GroupCfg> groupRelationList = new ArrayList();
|
||||
List<MaatCfg.IpCfg> ipRegionList = new ArrayList();
|
||||
List<MaatCfg.StringCfg> strRegionList = new ArrayList();
|
||||
List<MaatCfg.NumBoundaryCfg> numRegionList = new ArrayList();
|
||||
List<MaatCfg.DigestCfg> digestRegionList = new ArrayList();
|
||||
List<MaatCfg.IpCfg> areaIpRegionList = new ArrayList();
|
||||
|
||||
//查询子配置并修改审核状态
|
||||
entity = this.getObjGroupPolicy(entity.getCfgId());
|
||||
ServiceConfigTemplateUtil templateUtil=new ServiceConfigTemplateUtil();
|
||||
List<Map<String,Object>> serviceMapList= ServiceConfigTemplateUtil.getServiceList();
|
||||
List<FunctionServiceDict> dicts=DictUtils.getFunctionServiceDictList();
|
||||
Integer serviceId=entity.getServiceId();
|
||||
Map<String,Object> maatTableMap=new HashMap<>();
|
||||
|
||||
StringBuffer userRegion=new StringBuffer();
|
||||
if(serviceId!=null){
|
||||
if(isAudit==1){
|
||||
List<Map<String,Object>> list= templateUtil.getServiceListByServiceId(serviceId);
|
||||
//获取业务下的配置域
|
||||
List<Map<String,Object>> cfgList = new ArrayList<>();
|
||||
//获取业务下的自定义域
|
||||
List<Map<String,Object>> userRegionList = new ArrayList<>();
|
||||
for(Map<String,Object> service:list){
|
||||
String serviceType = service.get("serviceType").toString();
|
||||
if(service.containsKey("maatTable")){ }
|
||||
if(service.containsKey("cfgList")) {
|
||||
cfgList=(List<Map<String, Object>>) service.get("cfgList");
|
||||
maatTableMap=ConfigConvertUtil.convertCommonGroupMaatTable(entity,cfgList);
|
||||
}
|
||||
if(service.containsKey("userRegionList")){
|
||||
Map<String,Object> userregionMap=new HashMap<>();
|
||||
userRegionList=(List<Map<String, Object>>) service.get("userRegionList");
|
||||
userRegion.append(ConfigConvertUtil.generateCommonGroupDefaultUserRegion(userregionMap,serviceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//IP公共分组
|
||||
if(CollectionUtils.isNotEmpty(entity.getIpCommGroupCfgList())){
|
||||
IpPortCfg cfg = new IpPortCfg();
|
||||
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
||||
//cfg.setTableName("ip_comm_cfg");
|
||||
//commonPolicyDao.auditCfg(cfg);
|
||||
if(isAudit==1){
|
||||
Map<String,List> map = ConfigConvertUtil.objGroupCfgConvert(ipRegionList,entity.getIpCommGroupCfgList(),1,cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
ipRegionList=map.get("dstList");
|
||||
if(map.get("numRegionList")!=null){
|
||||
numRegionList.addAll(map.get("numRegionList"));
|
||||
}
|
||||
}
|
||||
}
|
||||
//URL公共分组
|
||||
if(CollectionUtils.isNotEmpty(entity.getUrlCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
||||
//cfg.setTableName(CommonStringCfg.getTablename());
|
||||
//commonPolicyDao.auditCfg(cfg);
|
||||
if(isAudit==1){
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,entity.getUrlCommGroupList(),2,cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
}
|
||||
//账号公共分组
|
||||
if(CollectionUtils.isNotEmpty(entity.getScriberIdCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
||||
//cfg.setTableName(CommonStringCfg.getTablename());
|
||||
//commonPolicyDao.auditCfg(cfg);
|
||||
if(isAudit==1){
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,entity.getScriberIdCommGroupList(),2,cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
}
|
||||
//域名公共分组
|
||||
if(CollectionUtils.isNotEmpty(entity.getDomainCommGroupList())){
|
||||
CommonStringCfg cfg = new CommonStringCfg();
|
||||
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
||||
//cfg.setTableName(CommonStringCfg.getTablename());
|
||||
//commonPolicyDao.auditCfg(cfg);
|
||||
if(isAudit==1){
|
||||
Map<String,List> map =ConfigConvertUtil.objGroupCfgConvert(strRegionList,entity.getDomainCommGroupList(),2,cfg,groupRelationList,maatTableMap,groupIdSet);
|
||||
groupRelationList=map.get("groupList");
|
||||
strRegionList=map.get("dstList");
|
||||
}
|
||||
}
|
||||
//保存区域IP信息
|
||||
List<AreaIpCfg> areaIpCfgList=areaIpCfgDao.getByCompileId(entity.getCompileId());
|
||||
if(!StringUtil.isEmpty(areaIpCfgList)){
|
||||
AreaIpCfg cfg = new AreaIpCfg();
|
||||
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
|
||||
cfg.setTableName(AreaIpCfg.getTablename());
|
||||
commonPolicyDao.auditCfg(cfg);
|
||||
if(isAudit==1){
|
||||
Map<String,List> map = cfgConvert(areaIpRegionList,areaIpCfgList,1,entity,groupRelationList);
|
||||
groupRelationList=map.get("groupList");
|
||||
areaIpRegionList=map.get("dstList");
|
||||
}
|
||||
}
|
||||
|
||||
//构造提交综合服务参数格式,一条配置提交一次综合服务
|
||||
if(isAudit==1){
|
||||
maatCfg.initDefaultValue();
|
||||
if(entity.getServiceId().equals(512)){
|
||||
maatCfg.setAction(2);
|
||||
}
|
||||
BeanUtils.copyProperties(entity, maatCfg);
|
||||
maatCfg.setAction(entity.getAction());
|
||||
maatCfg.setAuditTime(entity.getAuditTime());
|
||||
maatCfg.setIpRegionList(ipRegionList);
|
||||
maatCfg.setStrRegionList(strRegionList);
|
||||
maatCfg.setNumRegionList(numRegionList);
|
||||
maatCfg.setDigestRegionList(digestRegionList);
|
||||
maatCfg.setGroupRelationList(groupRelationList);
|
||||
maatCfg.setGroupNum(groupRelationList.size());
|
||||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||||
maatCfg.setIsValid(entity.getIsValid());
|
||||
//设置用户自定义域
|
||||
String protpcolType=entity.getUserRegion1();
|
||||
|
||||
if("HTTPS".equalsIgnoreCase(protpcolType)||"INTERCEPT".equalsIgnoreCase(protpcolType)){
|
||||
if(StringUtils.isBlank(userRegion.toString())){
|
||||
userRegion.append("{}");
|
||||
}
|
||||
}else if("HTTP".equalsIgnoreCase(protpcolType)){
|
||||
|
||||
}
|
||||
maatCfg.setUserRegion(userRegion.toString());
|
||||
|
||||
configCompileList.add(maatCfg);
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(entity.getAuditTime());
|
||||
maatBean.setCreatorName(entity.getCurrentUser().getName());
|
||||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||||
maatBean.setOpAction(opAction);
|
||||
//调用服务接口下发配置数据
|
||||
String json=gsonToJson(maatBean);
|
||||
logger.info("策略对象组下发配置参数:"+json);
|
||||
//调用服务接口下发配置
|
||||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||||
logger.info("策略对象组下发响应信息:"+result.getMsg());
|
||||
|
||||
}else if(isAudit==3){
|
||||
maatCfg.setCompileId(entity.getCompileId());
|
||||
maatCfg.setServiceId(entity.getServiceId());
|
||||
maatCfg.setIsValid(0);//无效
|
||||
configCompileList.add(maatCfg);
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(entity.getAuditTime());
|
||||
maatBean.setCreatorName(entity.getCurrentUser().getName());
|
||||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||||
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
||||
//调用服务接口取消配置
|
||||
String json=gsonToJson(maatBean);
|
||||
logger.info("策略对象组下发配置参数:"+json);
|
||||
//调用服务接口下发配置
|
||||
ToMaatResult result = ConfigServiceUtil.put(json,1);
|
||||
logger.info("策略对象组取消配置响应信息:"+result.getMsg());
|
||||
}
|
||||
}
|
||||
public boolean indexOfContains(String arrayString,String splitor,String current){
|
||||
if(arrayString==null||arrayString==null){
|
||||
return false;
|
||||
}
|
||||
return arrayString.equals(current)?true:arrayString.indexOf(splitor+current+splitor)>-1?true:arrayString.startsWith(current+splitor)?true:arrayString.endsWith(splitor+current)?true:false;
|
||||
}
|
||||
|
||||
public void updatePolicyValid(Integer isValid, String ids, Integer functionId) {
|
||||
String[] idArray = ids.split(",");
|
||||
for(String id :idArray){
|
||||
CfgIndexInfo entity = new CfgIndexInfo();
|
||||
entity.setCfgId(Long.parseLong(id));
|
||||
entity.setIsValid(isValid);
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(new Date());
|
||||
entity.setTableName(CfgIndexInfo.getTablename());
|
||||
entity.setFunctionId(functionId);
|
||||
commonPolicyDao.updateCfgValid(entity);
|
||||
//修改对应的policyGroupInfo的udFlag状态
|
||||
CfgIndexInfo cfg=commonPolicyDao.getPolicyById(Long.parseLong(id));
|
||||
String userregion=cfg.getCommonGroupIds();
|
||||
if(StringUtils.isNotBlank(userregion)){
|
||||
Map<String,Object> userRegionMap=gsonFromJson(userregion,Map.class);
|
||||
StringBuffer serviceGroupIds=new StringBuffer();
|
||||
for(Object val:userRegionMap.values()){
|
||||
if(val.toString().startsWith(",")){
|
||||
serviceGroupIds.append(val.toString().substring(1));
|
||||
}else{
|
||||
serviceGroupIds.append(val.toString());
|
||||
}
|
||||
}
|
||||
if(serviceGroupIds.toString().endsWith(",")){
|
||||
serviceGroupIds.deleteCharAt(serviceGroupIds.toString().length()-1);
|
||||
}
|
||||
//删除之后恢复组的ud_flag
|
||||
int size = ipCommGroupCfgDao.getCfgInfoByGroupIds(serviceGroupIds.toString());
|
||||
if(size==0){
|
||||
policyGroupInfoDao.updateUdFlag(serviceGroupIds.toString(),0,null);
|
||||
}else{
|
||||
policyGroupInfoDao.updateUdFlag(serviceGroupIds.toString(),1,null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@Transactional(rollbackFor = RuntimeException.class)
|
||||
public boolean batchDeleteMaatData(Page page, BaseCfg entity,
|
||||
List<BaseCfg> list, boolean hasData,String groupIds) {
|
||||
// 1.获取所有配置的编译ID
|
||||
List<Integer> compileIds = new ArrayList();
|
||||
|
||||
for(BaseCfg cfg:list){
|
||||
if(entity.getServiceId().equals(1028)) {
|
||||
compileIds.add(Integer.parseInt(cfg.getUserRegion1()));
|
||||
}else if(entity.getServiceId().equals(400)) {
|
||||
compileIds.add(cfg.getRegionId());
|
||||
}else {
|
||||
compileIds.add(cfg.getCompileId());
|
||||
}
|
||||
|
||||
cfg.setIsValid(-1);
|
||||
cfg.setIsAudit(0);
|
||||
}
|
||||
|
||||
// 2.更新配置状态(主表)
|
||||
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
|
||||
commonPolicyDao.deleteCfgBatch(entity.getTableName(), entity,compileIds); // 批量修改配置状态(主表)
|
||||
//更新各配置定时任务信息
|
||||
handelScheduleCfg(list, entity.getTableName(),entity);
|
||||
}
|
||||
//3.恢复policy_group_info可选状态
|
||||
policyGroupInfoDao.updateUdFlag(groupIds,1,null);
|
||||
// 4.判断是否是当前检索条件下最后一页数据 并返回结果
|
||||
page.setList(list);
|
||||
if(page.isLastPage()){
|
||||
hasData = false;
|
||||
}
|
||||
return hasData;
|
||||
}
|
||||
private String userRegionMapToString(Map<String,Object> dataMap){
|
||||
StringBuffer buf=new StringBuffer();
|
||||
for(Object val:dataMap.values()){
|
||||
String _val=(String)val;
|
||||
if(_val.startsWith(",")){
|
||||
buf.append(_val.substring(1));
|
||||
}else{
|
||||
buf.append(_val);
|
||||
}
|
||||
}
|
||||
if(buf.toString().endsWith(",")){
|
||||
buf.deleteCharAt(buf.toString().length()-1);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public List<ObjGroupCfg> getObjGroupList(String ids,Properties msgProp,Integer functionId){
|
||||
List<ObjGroupCfg> list = commonPolicyDao.getObjGroupList(ids);
|
||||
StringBuffer groupIds=new StringBuffer();
|
||||
List<PolicyGroupInfo> policyGroupInfos=new ArrayList<>();
|
||||
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(functionId);
|
||||
for (ObjGroupCfg c : list) {
|
||||
if(!StringUtil.isBlank(c.getCommonGroupIds())) {
|
||||
Map<String,String> groupIdMap=ConfigConvertUtil.gsonFromJson(c.getCommonGroupIds(),Map.class);
|
||||
for(String value:groupIdMap.values()){
|
||||
if(StringUtils.isNotBlank(value)){
|
||||
groupIds.append(value.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (FunctionServiceDict service : serviceList) {
|
||||
if(c.getAction().intValue()==service.getAction().intValue()){
|
||||
c.setActionCode(msgProp.getProperty(service.getActionCode(),service.getActionCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(groupIds.toString())){
|
||||
groupIds.deleteCharAt(groupIds.toString().length()-1);
|
||||
policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(groupIds.toString());
|
||||
}
|
||||
Map<Integer,PolicyGroupInfo> policyGroupInfoMap=new HashMap<>();
|
||||
for(PolicyGroupInfo info:policyGroupInfos){
|
||||
policyGroupInfoMap.put(info.getServiceGroupId(),info);
|
||||
}
|
||||
Map<Integer,PolicyGroupInfo> policyGroupInfoMapCopy=new HashMap<>();
|
||||
policyGroupInfoMapCopy.putAll(policyGroupInfoMap);
|
||||
for (ObjGroupCfg c : list) {
|
||||
for(Map.Entry<Integer,PolicyGroupInfo> e:policyGroupInfoMap.entrySet()){
|
||||
if(c.getCommonGroupIds().indexOf(","+e.getKey()+",")>-1){
|
||||
if(e.getValue().getGroupType().equals(Constants.IP_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getIpGroup())?"":c.getIpGroup())+","+e.getValue().getGroupName();
|
||||
c.setIpGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.URL_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getIpGroup())?"":c.getUrlGroup())+","+e.getValue().getGroupName();
|
||||
c.setUrlGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.SUBID_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getSubscribeIdGroup())?"":c.getSubscribeIdGroup())+","+e.getValue().getGroupName();
|
||||
c.setSubscribeIdGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.DOMAIN_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getDomainGroup())?"":c.getDomainGroup())+","+e.getValue().getGroupName();
|
||||
c.setDomainGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
policyGroupInfoMapCopy.clear();
|
||||
policyGroupInfoMapCopy.putAll(policyGroupInfoMap);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Page<ObjGroupCfg> getObjGroup(Page<ObjGroupCfg> page, ObjGroupCfg entity,Properties msgProp){
|
||||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
|
||||
entity.setPage(page);
|
||||
StringBuffer groupIds=new StringBuffer();
|
||||
List<ObjGroupCfg> list = commonPolicyDao.getObjGroupPagedList(entity);
|
||||
List<PolicyGroupInfo> policyGroupInfos=new ArrayList<>();
|
||||
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(entity.getFunctionId());
|
||||
|
||||
for (ObjGroupCfg c : list) {
|
||||
if(StringUtils.isNotBlank(c.getCommonGroupIds())) {
|
||||
Map<String,String> groupIdMap=ConfigConvertUtil.gsonFromJson(c.getCommonGroupIds(),Map.class);
|
||||
for(String value:groupIdMap.values()){
|
||||
if(StringUtils.isNotBlank(value)){
|
||||
groupIds.append(value.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (FunctionServiceDict service : serviceList) {
|
||||
if(c.getAction().intValue()==service.getAction().intValue()){
|
||||
c.setActionCode(msgProp.getProperty(service.getActionCode(),service.getActionCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(groupIds.toString())){
|
||||
groupIds.deleteCharAt(groupIds.toString().length()-1);
|
||||
policyGroupInfos=policyGroupInfoDao.findPolicyByServiceGroupInfoList(groupIds.toString());
|
||||
}
|
||||
Map<Integer,PolicyGroupInfo> policyGroupInfoMap=new HashMap<>();
|
||||
for(PolicyGroupInfo info:policyGroupInfos){
|
||||
policyGroupInfoMap.put(info.getServiceGroupId(),info);
|
||||
}
|
||||
Map<Integer,PolicyGroupInfo> policyGroupInfoMapCopy=new HashMap<>();
|
||||
policyGroupInfoMapCopy.putAll(policyGroupInfoMap);
|
||||
for (ObjGroupCfg c : list) {
|
||||
for(Map.Entry<Integer,PolicyGroupInfo> e:policyGroupInfoMapCopy.entrySet()){
|
||||
if(c.getCommonGroupIds().indexOf(","+e.getKey()+",")>-1){
|
||||
if(e.getValue().getGroupType().equals(Constants.IP_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getIpGroup())?"":c.getIpGroup())+","+e.getValue().getGroupName();
|
||||
c.setIpGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.URL_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getIpGroup())?"":c.getUrlGroup())+","+e.getValue().getGroupName();
|
||||
c.setUrlGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.SUBID_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getSubscribeIdGroup())?"":c.getSubscribeIdGroup())+","+e.getValue().getGroupName();
|
||||
c.setSubscribeIdGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}else if(e.getValue().getGroupType().equals(Constants.DOMAIN_OBJ_GROUP_TYPE)){
|
||||
String name=(StringUtils.isBlank(c.getDomainGroup())?"":c.getDomainGroup())+","+e.getValue().getGroupName();
|
||||
c.setDomainGroup(name);
|
||||
policyGroupInfoMap.remove(e.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
policyGroupInfoMapCopy.clear();
|
||||
policyGroupInfoMapCopy.putAll(policyGroupInfoMap);
|
||||
}
|
||||
page.setList(list);
|
||||
return page;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user