This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/service/configuration/ObjectGroupService.java

668 lines
32 KiB
Java
Raw Normal View History

2019-06-13 20:57:29 +08:00
package com.nis.web.service.configuration;
import com.nis.domain.FunctionRegionDict;
2019-06-13 20:57:29 +08:00
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.*;
2019-06-13 20:57:29 +08:00
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;
@Autowired
private ScriberIdCommGroupDao scriberIdCommGroupDao;
@Autowired
private DomainCommGroupDao domainCommGroupDao;
2019-06-13 20:57:29 +08:00
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());
// if(StringUtils.isBlank(entity.getCommonGroupIds())){
//
// }
2019-06-13 20:57:29 +08:00
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);
if(entity.getServiceId().equals(512)){
maatCfg.setAction(2);
}else{
maatCfg.setAction(entity.getAction());
}
2019-06-13 20:57:29 +08:00
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());
int size1 = urlCommGroupCfgDao.getCfgInfoByGroupIds(serviceGroupIds.toString());
int size2 = scriberIdCommGroupDao.getCfgInfoByGroupIds(serviceGroupIds.toString());
int size3 = domainCommGroupDao.getCfgInfoByGroupIds(serviceGroupIds.toString());
if((size+size1+size2+size3)==0){
2019-06-13 20:57:29 +08:00
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){
2019-06-14 19:21:01 +08:00
compileIds.add(cfg.getCompileId());
2019-06-13 20:57:29 +08:00
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可选状态
2019-06-14 19:21:01 +08:00
if(StringUtils.isNotBlank(groupIds)){
policyGroupInfoDao.updateUdFlag(groupIds,1,null);
}
2019-06-13 20:57:29 +08:00
// 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;
}
public void saveAndSend(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<BaseStringCfg<?>> stringCfgs) {
}
2019-06-13 20:57:29 +08:00
}