253 lines
10 KiB
Java
253 lines
10 KiB
Java
|
|
package com.nis.web.service.basics;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.Date;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
import java.util.Set;
|
|||
|
|
import java.util.Map.Entry;
|
|||
|
|
|
|||
|
|
import org.apache.commons.collections.CollectionUtils;
|
|||
|
|
import org.apache.ibatis.session.ExecutorType;
|
|||
|
|
import org.apache.ibatis.session.SqlSession;
|
|||
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|||
|
|
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.beust.jcommander.internal.Maps;
|
|||
|
|
import com.beust.jcommander.internal.Sets;
|
|||
|
|
import com.google.common.collect.Lists;
|
|||
|
|
import com.nis.domain.FunctionRegionDict;
|
|||
|
|
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.basics.IpCommCfg;
|
|||
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
|||
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
|||
|
|
import com.nis.domain.maat.GroupReuseAddBean;
|
|||
|
|
import com.nis.domain.maat.GroupReuseCfg;
|
|||
|
|
import com.nis.domain.maat.MaatCfg;
|
|||
|
|
import com.nis.domain.maat.ToMaatBean;
|
|||
|
|
import com.nis.domain.maat.ToMaatResult;
|
|||
|
|
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.util.ConfigServiceUtil;
|
|||
|
|
import com.nis.util.Constants;
|
|||
|
|
import com.nis.util.StringUtil;
|
|||
|
|
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
|||
|
|
import com.nis.web.dao.basics.AsnIpCfgDao;
|
|||
|
|
import com.nis.web.dao.basics.IpCommGroupCfgDao;
|
|||
|
|
import com.nis.web.dao.basics.PolicyGroupInfoDao;
|
|||
|
|
import com.nis.web.security.UserUtils;
|
|||
|
|
import com.nis.web.service.BaseService;
|
|||
|
|
import com.nis.web.service.SpringContextHolder;
|
|||
|
|
@Service
|
|||
|
|
public class IpCommGroupCfgService extends BaseService {
|
|||
|
|
@Autowired
|
|||
|
|
private IpCommGroupCfgDao ipCommGroupCfgDao;
|
|||
|
|
@Autowired
|
|||
|
|
private PolicyGroupInfoDao policyGroupInfoDao;
|
|||
|
|
/**
|
|||
|
|
* @param page
|
|||
|
|
* @param entity
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public Page<IpCommCfg> findPage(Page<IpCommCfg> page, IpCommCfg entity) {
|
|||
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|||
|
|
entity.setPage(page);
|
|||
|
|
List<IpCommCfg> list=ipCommGroupCfgDao.findPage(entity);
|
|||
|
|
page.setList(list);
|
|||
|
|
return page;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<IpCommCfg> findByPage(String ids) {
|
|||
|
|
List<IpCommCfg> list=ipCommGroupCfgDao.findByPage(ids);
|
|||
|
|
return list;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IpCommCfg get(Long id ) {
|
|||
|
|
return ipCommGroupCfgDao.get(id);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void save(List<IpCommCfg> entitys) {
|
|||
|
|
logger.warn("Start to save IP,size:"+entitys.size());
|
|||
|
|
long start=System.currentTimeMillis();
|
|||
|
|
for(IpCommCfg ipCfg:entitys) {
|
|||
|
|
ipCommGroupCfgDao.insert(ipCfg);
|
|||
|
|
}
|
|||
|
|
long end=System.currentTimeMillis();
|
|||
|
|
logger.warn("Save IP finish,cost:"+(end-start));
|
|||
|
|
}
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void update(IpCommCfg entity){
|
|||
|
|
ipCommGroupCfgDao.update(entity);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public List<IpCommCfg> getByIds(String ids) {
|
|||
|
|
if(ids==null) {
|
|||
|
|
throw new RuntimeException("ids is null!");
|
|||
|
|
}
|
|||
|
|
return ipCommGroupCfgDao.getByIds(ids);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//新增
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void saveIpCommGroupCfg(CfgIndexInfo entity) {
|
|||
|
|
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
|
|||
|
|
|
|||
|
|
Date createTime=new Date();
|
|||
|
|
if(CollectionUtils.isNotEmpty(entity.getIpCommGroupCfgList())) {
|
|||
|
|
for (int i = 0; i < entity.getIpCommGroupCfgList().size(); i++) {
|
|||
|
|
BeanUtils.copyProperties(entity, entity.getIpCommGroupCfgList().get(i), new String[]{"cfgId","userregion3"});
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setRequestId(0);
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setClassify("0");
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setAttribute("0");
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setLable("0");
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setCreateTime(createTime);
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setCreatorId(entity.getCurrentUser().getId());
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setIsValid(Constants.VALID_NO);
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setIsAudit(Constants.AUDIT_NOT_YET);
|
|||
|
|
entity.getIpCommGroupCfgList().get(i).setGroupId(Integer.parseInt(entity.getUserRegion3()));
|
|||
|
|
ipCommGroupCfgDao.insertForBatch(entity.getIpCommGroupCfgList().get(i));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// @Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
// public void audit(List<IpCommCfg> ipCommGroupCfgs, Integer isAudit, Integer isValid) {
|
|||
|
|
// // TODO Auto-generated method stub
|
|||
|
|
// Set<Integer> groupIds=Sets.newHashSet();
|
|||
|
|
// if(!StringUtil.isEmpty(ipCommGroupCfgs)){
|
|||
|
|
// for(IpCommCfg cfg:ipCommGroupCfgs) {
|
|||
|
|
// cfg.setIsValid(isValid);
|
|||
|
|
// cfg.setIsAudit(isAudit);
|
|||
|
|
// cfg.setAuditorId(UserUtils.getUser().getId());
|
|||
|
|
// cfg.setAuditTime(new Date());
|
|||
|
|
// groupIds.add(cfg.getGroupId());
|
|||
|
|
// ipCommGroupCfgDao.update(cfg);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// //查询有效的Ip配置个数
|
|||
|
|
// for(Integer groupId:groupIds) {
|
|||
|
|
// Integer groupCount=ipCommGroupCfgDao.getGroupIdCount(groupId);
|
|||
|
|
// if(groupCount>0){//udFlag 设置为1
|
|||
|
|
// policyGroupInfoDao.updateUdFlag(groupId, 1,5);
|
|||
|
|
// }else{//udFlag 设置为0
|
|||
|
|
// policyGroupInfoDao.updateUdFlag(groupId, 0,5);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// //下发配置时改变公共组udFlag标识
|
|||
|
|
// send2Maat(ipCommGroupCfgs,isValid);
|
|||
|
|
// }
|
|||
|
|
// public void send2Maat(List<IpCommCfg> ipCommGroupCfgs,int isValid) {
|
|||
|
|
// GroupReuseAddBean maatBean = new GroupReuseAddBean();
|
|||
|
|
// List<GroupReuseCfg> groupReuseList=new ArrayList<>();
|
|||
|
|
// GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
|
|||
|
|
// List<IpCfg> ipRegionList = groupReuseCfgAddRemoveConvert(ipCommGroupCfgs,isValid,null);
|
|||
|
|
// List<StringCfg> strRegionList = new ArrayList<>();
|
|||
|
|
// List<NumBoundaryCfg> numRegionList = new ArrayList<>();
|
|||
|
|
// groupReuseCfg.setIpRegionList(ipRegionList);
|
|||
|
|
// groupReuseCfg.setStrRegionList(strRegionList);
|
|||
|
|
// groupReuseCfg.setNumRegionList(numRegionList);
|
|||
|
|
// groupReuseList.add(groupReuseCfg);
|
|||
|
|
// maatBean.setGroupReuseCfgList(groupReuseList);
|
|||
|
|
// maatBean.setAuditTime(new Date());
|
|||
|
|
// maatBean.setCreatorName(UserUtils.getUser().getName());
|
|||
|
|
// maatBean.setVersion(Constants.MAAT_VERSION);
|
|||
|
|
// logger.warn("IP Common Region Send To Maat start");
|
|||
|
|
// long start=System.currentTimeMillis();
|
|||
|
|
// if(isValid==Constants.VALID_YES) {
|
|||
|
|
// maatBean.setOpAction(Constants.INSERT_ACTION);
|
|||
|
|
// //调用服务接口下发配置数据
|
|||
|
|
// String json=gsonToJson(maatBean);
|
|||
|
|
// if(ipCommGroupCfgs.size()<=100) {
|
|||
|
|
// logger.info("ip 公共组域新增配置下发配置参数:"+json);
|
|||
|
|
// }else {
|
|||
|
|
// logger.info("ip 公共组域新增配置下发region条数:"+ipCommGroupCfgs.size());
|
|||
|
|
// }
|
|||
|
|
// //调用服务接口下发配置
|
|||
|
|
// ToMaatResult result =ConfigServiceUtil.postGroupReuseSources(json);
|
|||
|
|
// logger.info("ip 公共组域新增配置响应信息:"+result.getMsg());
|
|||
|
|
// }else {
|
|||
|
|
// maatBean.setOpAction(Constants.UPDATE_ACTION);
|
|||
|
|
// //调用服务接口下发配置数据
|
|||
|
|
// String json=gsonToJson(maatBean);
|
|||
|
|
// if(ipCommGroupCfgs.size()<=100) {
|
|||
|
|
// logger.info("ip 公共组域删除配置下发配置参数:"+json);
|
|||
|
|
// }else {
|
|||
|
|
// logger.info("ip 公共组域删除配置下发region条数:"+ipCommGroupCfgs.size());
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
// //调用服务接口下发配置
|
|||
|
|
// ToMaatResult result = ConfigServiceUtil.put(json,3);
|
|||
|
|
// logger.info("asn ip复用域删除配置响应信息:"+result.getMsg());
|
|||
|
|
// }
|
|||
|
|
// long end=System.currentTimeMillis();
|
|||
|
|
// logger.warn("IP Common Region Send To Maat finish,cost:"+(end-start));
|
|||
|
|
// }
|
|||
|
|
public void delete(String ids) {
|
|||
|
|
// TODO 公共组配置删除时 需检索是否被其它业务配置引用,没被引用可删除
|
|||
|
|
|
|||
|
|
if(ids==null) {
|
|||
|
|
throw new RuntimeException("ids is null!");
|
|||
|
|
}
|
|||
|
|
ipCommGroupCfgDao.delete(ids);
|
|||
|
|
}
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void saveAndSend(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<BaseIpCfg> cfgs,boolean send) {
|
|||
|
|
logger.warn("Start to save IP,size:"+cfgs.size());
|
|||
|
|
long start=System.currentTimeMillis();
|
|||
|
|
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
|||
|
|
SqlSession batchSqlSession = null;
|
|||
|
|
//需要通过新增域接口新增的ip集合
|
|||
|
|
Map<Integer,Integer> groupCount=Maps.newHashMap();
|
|||
|
|
List<IpCommCfg> ipCommCfgs=new ArrayList(cfgs.size());
|
|||
|
|
try{
|
|||
|
|
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
|||
|
|
|
|||
|
|
for(BaseIpCfg cfg:cfgs) {
|
|||
|
|
IpCommCfg ipCommCfg=new IpCommCfg();
|
|||
|
|
BeanUtils.copyProperties(cfg, ipCommCfg);
|
|||
|
|
ipCommCfgs.add(ipCommCfg);
|
|||
|
|
((IpCommGroupCfgDao) batchSqlSession.getMapper(IpCommGroupCfgDao.class)).insertForBatch(ipCommCfg);
|
|||
|
|
// if(send) {
|
|||
|
|
// if(groupCount.containsKey(ipCommCfg.getGroupId())) {
|
|||
|
|
// groupCount.put(ipCommCfg.getGroupId(), groupCount.get(ipCommCfg.getGroupId())+1);
|
|||
|
|
// }else {
|
|||
|
|
// groupCount.put(ipCommCfg.getGroupId(), 1);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
// if(send) {
|
|||
|
|
// if(groupCount.size()>0) {
|
|||
|
|
// for(Entry<Integer, Integer> groupId:groupCount.entrySet()) {
|
|||
|
|
// policyGroupInfoDao.updateUdFlag(groupId.getKey(), 1,5);
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// this.send2Maat(ipCommCfgs, Constants.VALID_YES);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
batchSqlSession.commit();
|
|||
|
|
}finally {
|
|||
|
|
if(batchSqlSession != null){
|
|||
|
|
batchSqlSession.close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
long end=System.currentTimeMillis();
|
|||
|
|
logger.warn("Save IP finish,cost:"+(end-start));
|
|||
|
|
cfgs.clear();
|
|||
|
|
cfgs=null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|