2018-12-01 16:06:08 +08:00
|
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import com.beust.jcommander.internal.Lists;
|
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
|
import com.nis.domain.configuration.IpReusePolicyCfg;
|
2018-12-05 11:45:59 +08:00
|
|
|
|
import com.nis.domain.configuration.UserManage;
|
2018-12-01 16:06:08 +08:00
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
|
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.Constants;
|
2018-12-05 11:45:59 +08:00
|
|
|
|
import com.nis.util.StringUtils;
|
2018-12-01 16:06:08 +08:00
|
|
|
|
import com.nis.web.dao.configuration.IpMultiplexDao;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class IpMultiplexService extends BaseService{
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IpMultiplexDao ipMultiplexDao;
|
|
|
|
|
|
|
|
|
|
|
|
public Page<IpReusePolicyCfg> findPage(Page<IpReusePolicyCfg> page, IpReusePolicyCfg entity) {
|
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List<IpReusePolicyCfg> list=ipMultiplexDao.findPage(entity);
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IpReusePolicyCfg getPolicyCfg(Long cfgId, Integer isValid) {
|
2018-12-03 13:38:32 +08:00
|
|
|
|
List<IpReusePolicyCfg> list=ipMultiplexDao.findList(cfgId,isValid);
|
2018-12-01 16:06:08 +08:00
|
|
|
|
IpReusePolicyCfg policyCfg=null;
|
|
|
|
|
|
if(list != null && list.size()>0){
|
|
|
|
|
|
policyCfg=list.get(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
return policyCfg;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void saveOrUpdate(IpReusePolicyCfg entity, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
Date time = new Date();
|
|
|
|
|
|
entity.setIsValid(0);
|
|
|
|
|
|
entity.setIsAudit(0);
|
|
|
|
|
|
setAreaEffectiveIds(entity);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取用户/账号类型
|
2018-12-05 11:45:59 +08:00
|
|
|
|
if(StringUtils.isNotBlank(entity.getUserName())){
|
|
|
|
|
|
String userType = ipMultiplexDao.getUserType(entity.getUserName());
|
2018-12-01 16:06:08 +08:00
|
|
|
|
entity.setUserType(userType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新策略信息
|
|
|
|
|
|
if(entity.getCfgId() == null){
|
|
|
|
|
|
entity.initDefaultValue();
|
|
|
|
|
|
entity.setCreateTime(time);
|
|
|
|
|
|
entity.setCreatorId(UserUtils.getUser().getId());
|
|
|
|
|
|
//调用服务接口获取compileId
|
|
|
|
|
|
try {
|
|
|
|
|
|
List<Integer> compileIds = ConfigServiceUtil.getId(1,1);
|
|
|
|
|
|
if(compileIds != null && compileIds.size() > 0 ){
|
|
|
|
|
|
entity.setCompileId(compileIds.get(0));
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("获取编译ID出错");
|
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
ipMultiplexDao.savePolicyCfg(entity);
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setEditTime(time);
|
|
|
|
|
|
ipMultiplexDao.updatePolicyCfg(entity);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void delete(Integer isValid, String ids, Integer functionId) {
|
|
|
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
|
IpReusePolicyCfg entity = new IpReusePolicyCfg();
|
|
|
|
|
|
entity.setCfgId(Long.valueOf(id));
|
|
|
|
|
|
entity.setFunctionId(functionId);
|
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
|
ipMultiplexDao.updatePolicyCfg(entity);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 策略配置审核
|
|
|
|
|
|
* @param ids
|
|
|
|
|
|
* @param cfg
|
|
|
|
|
|
* @param auditTime
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void auditSnatPolicy(Integer isAudit, Integer isValid, Integer functionId, String id, Date auditTime) {
|
|
|
|
|
|
// 更新配置审核状态
|
|
|
|
|
|
IpReusePolicyCfg cfg = new IpReusePolicyCfg();
|
|
|
|
|
|
cfg.setCfgId(Long.valueOf(id));
|
|
|
|
|
|
cfg.setIsValid(isValid);
|
|
|
|
|
|
cfg.setIsAudit(isAudit);
|
|
|
|
|
|
cfg.setAuditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
cfg.setAuditTime(auditTime);
|
2018-12-05 11:45:59 +08:00
|
|
|
|
cfg.setDoLog(null);
|
2018-12-01 16:06:08 +08:00
|
|
|
|
ipMultiplexDao.updatePolicyCfg(cfg);
|
|
|
|
|
|
|
|
|
|
|
|
SysDictInfoService sysDictInfoService = SpringContextHolder.getBean(SysDictInfoService.class);
|
|
|
|
|
|
// 获取配置信息
|
|
|
|
|
|
cfg = this.getPolicyCfg(cfg.getCfgId(), null);
|
|
|
|
|
|
String json="";
|
|
|
|
|
|
if(cfg.getIsAudit() == Constants.AUDIT_YES){
|
2018-12-03 10:35:26 +08:00
|
|
|
|
String areaEffectiveIds = cfg.getIsAreaEffective() == 1?sysDictInfoService.setEffectiveRange(cfg.getAreaEffectiveIds()):"0";
|
2018-12-01 16:06:08 +08:00
|
|
|
|
Map<String, Object> params = new HashMap<String,Object>();
|
|
|
|
|
|
params.put("configId", cfg.getCompileId());
|
|
|
|
|
|
params.put("addrPoolId", cfg.getAddrPoolId());
|
|
|
|
|
|
params.put("userType", cfg.getUserType());
|
2018-12-05 11:45:59 +08:00
|
|
|
|
params.put("userId", keywordsEscape(cfg.getUserName()));
|
2018-12-03 13:38:32 +08:00
|
|
|
|
params.put("doLog", cfg.getDoLog());
|
|
|
|
|
|
params.put("action", cfg.getAction());
|
|
|
|
|
|
params.put("service", cfg.getServiceId());
|
2018-12-01 16:06:08 +08:00
|
|
|
|
params.put("isValid", 1);
|
|
|
|
|
|
params.put("opTime", auditTime);
|
2018-12-03 16:22:00 +08:00
|
|
|
|
params.put("translateParam", "byconn=10");
|
2018-12-03 10:35:26 +08:00
|
|
|
|
params.put("effectiveRange", areaEffectiveIds);
|
|
|
|
|
|
|
2018-12-01 16:06:08 +08:00
|
|
|
|
List list = Lists.newArrayList();
|
|
|
|
|
|
list.add(params);
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
json=gsonToJson(list);
|
|
|
|
|
|
logger.info("SNAT策略配置下发参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
logger.info("SNAT策略配置下发响应信息:"+result.getMsg());
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("SNAT策略配置下发失败",e);
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}else if(cfg.getIsAudit() == Constants.AUDIT_NOT_YES){
|
2018-12-03 10:35:26 +08:00
|
|
|
|
String areaEffectiveIds = cfg.getIsAreaEffective() == 1?sysDictInfoService.setEffectiveRange(cfg.getAreaEffectiveIds()):"0";
|
2018-12-01 16:06:08 +08:00
|
|
|
|
Map<String, Object> params = new HashMap<String,Object>();
|
|
|
|
|
|
params.put("configId", cfg.getCompileId());
|
|
|
|
|
|
params.put("addrPoolId", cfg.getAddrPoolId());
|
|
|
|
|
|
params.put("userType", cfg.getUserType());
|
2018-12-05 11:45:59 +08:00
|
|
|
|
params.put("userId", keywordsEscape(cfg.getUserName()));
|
2018-12-03 13:38:32 +08:00
|
|
|
|
params.put("doLog", cfg.getDoLog());
|
|
|
|
|
|
params.put("action", cfg.getAction());
|
|
|
|
|
|
params.put("service", cfg.getServiceId());
|
2018-12-01 16:06:08 +08:00
|
|
|
|
params.put("isValid", 0);
|
|
|
|
|
|
params.put("opTime", auditTime);
|
2018-12-03 16:22:00 +08:00
|
|
|
|
params.put("translateParam", "byconn=10");
|
2018-12-03 10:35:26 +08:00
|
|
|
|
params.put("effectiveRange", areaEffectiveIds);
|
|
|
|
|
|
|
2018-12-01 16:06:08 +08:00
|
|
|
|
List list = Lists.newArrayList();
|
|
|
|
|
|
list.add(params);
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
json=gsonToJson(list);
|
|
|
|
|
|
logger.info("SNAT策略配置下发参数:"+json);
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.put(json, 2);
|
|
|
|
|
|
logger.info("SNAT策略配置响应信息:"+result.getMsg());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("SNAT策略配置配置失败");
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|