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

268 lines
8.6 KiB
Java
Raw Normal View History

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.Set;
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.basics.SysDictInfo;
import com.nis.domain.callback.ProxyObjKeyring;
import com.nis.domain.callback.ProxyObjTrustedCa;
import com.nis.domain.callback.ProxyObjTrustedCaCrl;
import com.nis.domain.configuration.AvFileSampleCfg;
import com.nis.domain.configuration.PxyObjSpoofingIpPool;
import com.nis.domain.configuration.PxyObjSpoofingIpPool;
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
import com.nis.domain.maat.EffectiveRangeCfg;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.maat.EffectiveRangeCfg.AreaIsp;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.web.dao.basics.ServiceDictInfoDao;
import com.nis.web.dao.basics.SysDictInfoDao;
import com.nis.web.dao.configuration.PxyObjSpoofingIpPoolDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.BaseService;
import com.nis.web.service.SpringContextHolder;
import com.nis.web.service.basics.SysDictInfoService;
import oracle.sql.ARRAY;
/**
* 欺骗IP地址池管理
* @author dell
*
*/
@Service
public class PxyObjSpoofingIpPoolService extends BaseService{
@Autowired
protected PxyObjSpoofingIpPoolDao pxyObjSpoofingIpPoolDao;
@Autowired
private SysDictInfoDao sysDictInfoDao;
/**
* @param entity
* @return
*/
public PxyObjSpoofingIpPool getPxyObjSpoofingIpPool(Long cfgId) {
return pxyObjSpoofingIpPoolDao.getPxyObjSpoofingIpPool(cfgId);
}
/**
* 查询分页数据
* @param page 分页对象
* @param entity
* @return
*/
public Page<PxyObjSpoofingIpPool> findPage(Page page, PxyObjSpoofingIpPool entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
entity.setPage(page);
List<PxyObjSpoofingIpPool> list=pxyObjSpoofingIpPoolDao.findPage(entity);
page.setList(list);
return page;
}
public List<PxyObjSpoofingIpPool> findPxyObjSpoofingIpPools(PxyObjSpoofingIpPool entity) {
List<PxyObjSpoofingIpPool> list=pxyObjSpoofingIpPoolDao.findList(entity);
return list;
}
//新增或保存
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveOrUpdate(PxyObjSpoofingIpPool entity){
Date createTime=new Date();
setAreaEffectiveIds(entity);
entity.setIsValid(0);
entity.setIsAudit(0);
//设置区域运营商信息
setAreaEffectiveIds(entity);
//新增
if(StringUtil.isEmpty(entity.getCfgId())){
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(createTime);
//调用服务接口获取compileId
List<Integer> compileIds = new ArrayList<Integer>();
try {
compileIds = ConfigServiceUtil.getId(1,1);
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
}
if(compileIds != null && compileIds.size() >0 && compileIds.get(0) != 0){
entity.setCompileId(compileIds.get(0));
}
pxyObjSpoofingIpPoolDao.insert(entity);
//修改
}else{
Date editTime=new Date();
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(editTime);
pxyObjSpoofingIpPoolDao.update(entity);
}
}
/**
*
* @param isAudit
* @param isValid
* @param ids compileIds
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(Integer isAudit,Integer isValid,String ids,Integer functionId){
String[] idArray = ids.split(",");
for(String id :idArray){
PxyObjSpoofingIpPool entity = new PxyObjSpoofingIpPool();
entity.setCfgId(Long.valueOf(id));
entity.setFunctionId(functionId);
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(new Date());
pxyObjSpoofingIpPoolDao.update(entity);
}
}
/**
*
* @param isAudit
* @param isValid
* @param ids cfgId
* @param functionId
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void audit(Integer isAudit,Integer isValid,Integer functionId,String id,Date auditTime){
PxyObjSpoofingIpPool entity=new PxyObjSpoofingIpPool();
entity.setCfgId(Long.valueOf(id));
entity.setIsValid(isValid);
entity.setIsAudit(isAudit);
entity.setEditTime(auditTime);
entity.setEditorId(UserUtils.getUser().getId());
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(auditTime);
pxyObjSpoofingIpPoolDao.update(entity);
entity=pxyObjSpoofingIpPoolDao.getPxyObjSpoofingIpPool(entity.getCfgId());
List<PxyObjSpoofingIpPool> list = new ArrayList<PxyObjSpoofingIpPool>();
String json="";
String areaEffectiveIds="0";
if(entity.getIsAudit()==1){
if(!StringUtils.isEmpty(entity.getAreaEffectiveIds())){
// 组织区域、运营商配置下发格式
areaEffectiveIds = this.setEffectiveRange(entity.getAreaEffectiveIds());
}
entity.setAreaEffectiveIds(areaEffectiveIds);
list.add(entity);
//调用服务接口下发配置数据
json=gsonToJson(list);
logger.info("欺骗IP池配置下发配置参数"+json);
//调用服务接口下发配置
try {
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
if(result!=null){
logger.info("欺骗IP池配置下发响应信息"+result.getMsg());
}
} catch (Exception e) {
logger.error("欺骗IP池配置配置下发失败",e);
throw e;
}
}else if(entity.getIsAudit()==3){
PxyObjSpoofingIpPool cfg = new PxyObjSpoofingIpPool();
cfg.setIsValid(0);
cfg.setCompileId(entity.getCompileId());
cfg.setServiceId(entity.getServiceId());
list.add(cfg);
//调用服务接口取消配置
json=gsonToJson(list);
logger.info("欺骗IP池配置配置参数"+json);
//调用服务接口取消配置
try {
ToMaatResult result = ConfigServiceUtil.put(json, 2);
logger.info("欺骗IP池配置响应信息"+result.getMsg());
} catch (Exception e) {
e.printStackTrace();
logger.info("欺骗IP池配置配置失败");
throw e;
}
}
}
public String setEffectiveRange(String areaEffectiveIds){
HashMap<String, List<String>> map = new HashMap<String,List<String>>();
List<String> ispList = new ArrayList();
for (String areaEffectiveId : StringUtils.split(areaEffectiveIds, ",")) {
if(areaEffectiveId.contains(":")) {
// 区域和运营商
int index = areaEffectiveId.indexOf(":");
String areaCode = areaEffectiveId.substring(0, index);
String ispCode = areaEffectiveId.substring(index+1);
if(!map.containsKey(areaCode)){
ispList = new ArrayList();
ispList.add(ispCode);
map.put(areaCode, ispList);
}else{
if(!ispList.contains(ispCode)){
ispList.add(ispCode);
}
map.replace(areaCode, ispList);
}
}else {
// 区域
if(!map.containsKey(areaEffectiveId)){
map.put(areaEffectiveId, null);
}
}
}
EffectiveRangeCfg rangeCfg = new EffectiveRangeCfg();
List<List<AreaIsp>> effectiveRangeList = new ArrayList();
Set<String> keySet = map.keySet();
for (String key : keySet) {
AreaIsp area = new AreaIsp();
area.setTag(Constants.AREA_TAG);
AreaIsp isp = new AreaIsp();
isp.setTag(Constants.ISP_TAG);
List<String> locaValueList = new ArrayList();
List<String> ispValueList = new ArrayList();
List<AreaIsp> areaIspList = new ArrayList();
// 获取区域信息
String areaStr = "";
SysDictInfo areaDict = sysDictInfoDao.getDictByItemCode(key);
areaStr += areaDict.getItemValue();
while(areaDict.getParent().getSysDictId() != 0) {
areaDict = sysDictInfoDao.getDictById(areaDict.getParent().getSysDictId());
areaStr += "/"+areaDict.getItemValue();
}
locaValueList.add(StringUtils.revertStr(areaStr, "/"));
area.setValue(locaValueList);
areaIspList.add(area);
// 获取运营商信息
if(map.get(key) != null){
for (String ispCode : map.get(key)) {
SysDictInfo ispDict = sysDictInfoDao.getDictByItemCode(ispCode);
ispValueList.add(ispDict.getItemValue());
}
isp.setValue(ispValueList);
areaIspList.add(isp);
}
effectiveRangeList.add(areaIspList);
}
rangeCfg.setEffectiveRangeList(effectiveRangeList);
return gsonToJson(rangeCfg);
}
}