对象组提交
This commit is contained in:
@@ -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