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/AppMultiFeatureCfgService.java

464 lines
19 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nis.web.service.configuration;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 com.nis.domain.Page;
import com.nis.domain.configuration.AppComplexFeatureCfg;
import com.nis.domain.configuration.AppFeatureIndex;
import com.nis.domain.configuration.AppHttpCfg;
import com.nis.domain.configuration.AppIpCfg;
import com.nis.domain.configuration.AppStringFeatureCfg;
import com.nis.domain.configuration.AppTcpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.domain.configuration.NtcSubscribeIdCfg;
import com.nis.domain.configuration.P2pHashCfg;
import com.nis.domain.configuration.P2pKeywordCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.MaatCfg.DigestCfg;
import com.nis.domain.maat.MaatCfg.GroupCfg;
import com.nis.domain.maat.MaatCfg.IpCfg;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.MaatCfg.StringCfg;
import com.nis.domain.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.util.StringUtil;
import com.nis.web.dao.configuration.AppMultiFeatureCfgDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
/**
* 特定协议相关配置事务类
*
* @author dell
*
*/
@Service
public class AppMultiFeatureCfgService extends BaseService {
@Autowired
protected AppMultiFeatureCfgDao appMultiFeatureCfgDao;
//分页查询
public Page<AppFeatureIndex> findAppFeatureIndexList(Page<AppFeatureIndex> page, AppFeatureIndex entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(), "r"));
entity.setPage(page);
List<AppFeatureIndex> list = appMultiFeatureCfgDao.findAppFeatureIndexList(entity);
page.setList(list);
return page;
}
//分页查询
public List<AppFeatureIndex> findAppByFeatureIndexList(String ids) {
List<AppFeatureIndex> list = appMultiFeatureCfgDao.findAppByFeatureIndexList(ids);
return list;
}
public AppFeatureIndex getAppFeatureIndex(Long cfgId) {
return appMultiFeatureCfgDao.getAppFeatureIndex(cfgId);
}
//新增或保存复杂特征配置
@Transactional(readOnly = false, rollbackFor = RuntimeException.class)
public void saveOrUpdateAppFeatureCfg(AppFeatureIndex entity) throws Exception {
if (entity.getCfgId() == null) {
Integer compileId = 0;
try {
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());
entity.setIsValid(0);
entity.setIsAudit(0);
appMultiFeatureCfgDao.insertAppFeatureIndex(entity);
if(entity.getIpPortList()!=null){
for(AppIpCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppIpRangeCfg(cfg);
}
}
if(entity.getStrList()!=null){
for(AppStringFeatureCfg cfg:entity.getStrList()){
if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppStringFeatureCfg(cfg);
}
}
}
if(entity.getComplexList()!=null){
for(AppComplexFeatureCfg cfg:entity.getComplexList()){
if(StringUtils.isNotBlank(cfg.getDistrict()) && cfg.getDistrict().equals("L3_header")){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
cfg.setIsHexbin(1);
cfg.setIsCaseInsenstive(0);
cfg.setExprType(3);
cfg.setMatchMethod(0);
String keyword = "";
if(cfg.getHeaderType().equals("IP_header")){
if(StringUtils.isNoneBlank(cfg.getVer())){
keyword += "0-3:"+cfg.getVer()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIhl())){
keyword += "4-7:"+cfg.getIhl()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getTos())){
keyword += "8-15:"+cfg.getTos()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getTotalLength())){
keyword += "16-31:"+cfg.getTotalLength()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getFlags())){
keyword += "48-50:"+cfg.getFlags()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getFragmentOffset())){
keyword += "56-63:"+cfg.getFragmentOffset()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getProtocol())){
keyword += "72-79:"+cfg.getProtocol()+"***and***";
}
}else{
if(StringUtils.isNoneBlank(cfg.getIcmpType())){
keyword += "0-7:"+cfg.getIcmpType()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIcmpCode())){
keyword += "8-15:"+cfg.getIcmpCode()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIcmpIdentifier())){
keyword += "32-47:"+cfg.getIcmpIdentifier()+"***and***";
}
}
keyword=keyword.substring(0,keyword.lastIndexOf("***and***"));
cfg.setCfgKeywords(keyword);
appMultiFeatureCfgDao.insertAppComplexFeatureCfg(cfg);
}else if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
cfg.setHeaderType(null);
appMultiFeatureCfgDao.insertAppComplexFeatureCfg(cfg);
}
}
}
if(entity.getNumCfgList()!=null){
for(AppTcpCfg cfg:entity.getNumCfgList()){
if(cfg.getLowBoundary()!=null && cfg.getUpBoundary()!=null){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppTcpCfg(cfg);//复用AppTcpCfg对象作为数值类对象
}
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException(e.getMessage());
}
} else {
entity.setEditorId(entity.getCurrentUser().getId());
entity.setEditTime(new Date());
entity.setIsValid(0);
entity.setIsAudit(0);
appMultiFeatureCfgDao.updateAppFeatureIndex(entity);
appMultiFeatureCfgDao.deleteAppIpRangeCfg(entity);
appMultiFeatureCfgDao.deleteAppStringFeatureCfg(entity);
appMultiFeatureCfgDao.deleteAppComplexFeatureCfg(entity);
appMultiFeatureCfgDao.deleteAppTcpCfg(entity);//复用AppTcpCfg对象作为数值类对象
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
if(entity.getIpPortList()!=null){
for(AppIpCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppIpRangeCfg(cfg);
}
}
if(entity.getStrList()!=null){
for(AppStringFeatureCfg cfg:entity.getStrList()){
if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppStringFeatureCfg(cfg);
}
}
}
if(entity.getComplexList()!=null){
for(AppComplexFeatureCfg cfg:entity.getComplexList()){
if(StringUtils.isNotBlank(cfg.getDistrict()) && cfg.getDistrict().equals("L3_header")){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
cfg.setIsHexbin(1);
cfg.setIsCaseInsenstive(0);
cfg.setExprType(3);
cfg.setMatchMethod(0);
String keyword = "";
if(cfg.getHeaderType().equals("IP_header")){
if(StringUtils.isNoneBlank(cfg.getVer())){
keyword += "0-3:"+cfg.getVer()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIhl())){
keyword += "4-7:"+cfg.getIhl()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getTos())){
keyword += "8-15:"+cfg.getTos()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getTotalLength())){
keyword += "16-31:"+cfg.getTotalLength()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getFlags())){
keyword += "48-50:"+cfg.getFlags()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getFragmentOffset())){
keyword += "56-63:"+cfg.getFragmentOffset()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getProtocol())){
keyword += "72-79:"+cfg.getProtocol()+"***and***";
}
}else{
if(StringUtils.isNoneBlank(cfg.getIcmpType())){
keyword += "0-7:"+cfg.getIcmpType()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIcmpCode())){
keyword += "8-15:"+cfg.getIcmpCode()+"***and***";
}
if(StringUtils.isNotBlank(cfg.getIcmpIdentifier())){
keyword += "32-47:"+cfg.getIcmpIdentifier()+"***and***";
}
}
keyword=keyword.substring(0,keyword.lastIndexOf("***and***"));
cfg.setCfgKeywords(keyword);
appMultiFeatureCfgDao.insertAppComplexFeatureCfg(cfg);
}else if(StringUtils.isNotBlank(cfg.getCfgKeywords())){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
cfg.setHeaderType(null);
appMultiFeatureCfgDao.insertAppComplexFeatureCfg(cfg);
}
}
}
if(entity.getNumCfgList()!=null){
for(AppTcpCfg cfg:entity.getNumCfgList()){
if(cfg.getLowBoundary()!=null && cfg.getUpBoundary()!=null){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
appMultiFeatureCfgDao.insertAppTcpCfg(cfg);
}
}
}
}
}
public void auditAppFeatureCfg(AppFeatureIndex entity, Integer isAudit) {
ToMaatBean maatBean = new ToMaatBean();
MaatCfg maatCfg = new MaatCfg();
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();
entity.setTableName(AppFeatureIndex.getTablename());
appMultiFeatureCfgDao.auditCfg(entity);
/*if (isAudit == 1) {
List<AppFeatureIndex> list = new ArrayList();
list.add(entity);
Map<String, List> map = cfgConvert(strRegionList, list, 2, entity, groupRelationList);
groupRelationList = map.get("groupList");
strRegionList = map.get("dstList");
}*/
//查询APP_IP_RANGE子配置并修改审核状态
List ipRangeList = appMultiFeatureCfgDao.getAppIpRangeCfg(entity.getCompileId(),entity.getFunctionId());
if(ipRangeList!=null && ipRangeList.size()>0){
AppIpCfg cfg = new AppIpCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName("APP_IP_RANGE_CFG");
appMultiFeatureCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(ipRegionList,ipRangeList,1,entity,groupRelationList);
groupRelationList=map.get("groupList");
ipRegionList=map.get("dstList");
if(map.get("numRegionList")!=null){
numRegionList.addAll(map.get("numRegionList"));
}
}
}
List<AppStringFeatureCfg> strList = appMultiFeatureCfgDao.getAppStringFeatureCfg(entity.getCompileId(),entity.getFunctionId(),null);
if(strList!=null && strList.size()>0){
AppStringFeatureCfg cfg = new AppStringFeatureCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(AppStringFeatureCfg.getTablename());
appMultiFeatureCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(strRegionList,strList,2,entity,groupRelationList);
groupRelationList=map.get("groupList");
strRegionList=map.get("dstList");
}
}
List<AppComplexFeatureCfg> complexList = appMultiFeatureCfgDao.getAppComplexFeatureCfg(entity.getCompileId(),entity.getFunctionId(),null);
if(complexList!=null && complexList.size()>0){
AppComplexFeatureCfg cfg = new AppComplexFeatureCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(AppComplexFeatureCfg.getTablename());
appMultiFeatureCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(strRegionList,complexList,2,entity,groupRelationList);
groupRelationList=map.get("groupList");
strRegionList=map.get("dstList");
}
}
List<AppTcpCfg> numCfgList = appMultiFeatureCfgDao.getAppTcpCfg(entity.getCompileId(),entity.getFunctionId(),null);
if(numCfgList!=null && numCfgList.size()>0){
AppTcpCfg cfg = new AppTcpCfg();
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setTableName(AppTcpCfg.getTablename());
appMultiFeatureCfgDao.auditCfg(cfg);
if(isAudit==1){
Map<String,List> map = cfgConvert(numRegionList,numCfgList,4,entity,groupRelationList);
groupRelationList=map.get("groupList");
numRegionList=map.get("dstList");
}
}
// 构造提交综合服务参数格式,一条配置提交一次综合服务
if (isAudit == 1) {
maatCfg.initDefaultValue();
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());
//只有用户自定义域1字段为空才设置maat的自定义域字段信息为APP_ID
if(StringUtil.isEmpty(entity.getUserRegion1())){
// 设置APP自定义域
String userRegion = "APP_ID=" + entity.getAppCode();
maatCfg.setUserRegion(userRegion);
}else{
maatCfg.setUserRegion(entity.getUserRegion1());
}
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(entity.getAuditTime());
maatBean.setCreatorName(entity.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
// 调用服务接口下发配置数据
String json = gsonToJson(maatBean);
logger.info("app 特征配置下发配置参数:" + json);
// 调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("app 特征配置下发响应信息:" + 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("app 特征配置下发配置参数:" + json);
// 调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json, 1);
logger.info("app 特征配置取消配置响应信息:" + result.getMsg());
}
}
public void updateAppFeatureCfgValid(Integer isValid, String ids, Integer functionId) {
String[] idArray = ids.split(",");
for (String id : idArray) {
AppFeatureIndex entity = new AppFeatureIndex();
entity.setCfgId(Long.parseLong(id));
entity.setIsValid(isValid);
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(new Date());
entity.setTableName(AppFeatureIndex.getTablename());
entity.setFunctionId(functionId);
appMultiFeatureCfgDao.updateCfgValid(entity);
//修改IP范围配置表状态
if (!StringUtil.isEmpty(entity.getIpPortList())) {
AppIpCfg cfg = new AppIpCfg();
BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" });
cfg.setTableName("APP_IP_RANGE_CFG");
appMultiFeatureCfgDao.updateCfgValid(cfg);
}
//修改字符串类配置表状态
if (!StringUtil.isEmpty(entity.getStrList())) {
AppStringFeatureCfg cfg = new AppStringFeatureCfg();
BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" });
cfg.setTableName(AppStringFeatureCfg.getTablename());
appMultiFeatureCfgDao.updateCfgValid(cfg);
}
//修改增强字符串类配置表状态
if (!StringUtil.isEmpty(entity.getComplexList())) {
AppComplexFeatureCfg cfg = new AppComplexFeatureCfg();
BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" });
cfg.setTableName(AppComplexFeatureCfg.getTablename());
appMultiFeatureCfgDao.updateCfgValid(cfg);
}
//修改数值域配置表状态
if (!StringUtil.isEmpty(entity.getNumCfgList())) {
AppTcpCfg cfg = new AppTcpCfg();
BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" });
cfg.setTableName(AppTcpCfg.getTablename());
appMultiFeatureCfgDao.updateCfgValid(cfg);
}
}
}
//字符串类特征配置列表
public List<AppStringFeatureCfg> getAppStringFeatureCfg(Integer compileId,Integer functionId,Integer cfgRegionCode){
return appMultiFeatureCfgDao.getAppStringFeatureCfg(compileId,functionId,cfgRegionCode);
}
//增强字符串类特征配置列表
public List<AppComplexFeatureCfg> getAppComplexFeatureCfg(Integer compileId,Integer functionId,Integer cfgRegionCode){
return appMultiFeatureCfgDao.getAppComplexFeatureCfg(compileId,functionId,cfgRegionCode);
}
//IP RANGE配置
public List<AppIpCfg> getAppIpRangeCfg(Integer compileId,Integer functionId){
return appMultiFeatureCfgDao.getAppIpRangeCfg(compileId,functionId);
}
//I数值域配置
public List<AppTcpCfg> getAppTcpCfg(Integer compileId,Integer functionId,Integer cfgRegionCode){
return appMultiFeatureCfgDao.getAppTcpCfg(compileId,functionId,cfgRegionCode);
}
public Map<String, List> exportFeature(AppFeatureIndex entity){
Map<String, List> dataMap=new HashMap<String, List>();
List<AppIpCfg> ipRangeList = appMultiFeatureCfgDao.getAppIpRangeCfg(entity.getCompileId(),entity.getFunctionId());
if(entity.getFunctionId()!=567){
List<AppComplexFeatureCfg> appKeyList = appMultiFeatureCfgDao.getAppComplexFeatureCfg(entity.getCompileId(),entity.getFunctionId(),null);
dataMap.put("APP_KEYWORDS", appKeyList);
}else{
List<AppStringFeatureCfg> appKeyList = appMultiFeatureCfgDao.getAppStringFeatureCfg(entity.getCompileId(),entity.getFunctionId(),null);
dataMap.put("APP_DK_GL", appKeyList);
}
dataMap.put("APP_IP_RANGE", ipRangeList);
return dataMap;
}
}