165 lines
4.8 KiB
Java
165 lines
4.8 KiB
Java
|
|
package com.nis.web.service.configuration;
|
|||
|
|
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.Date;
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
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.callback.InlineIp;
|
|||
|
|
import com.nis.domain.configuration.DdosIpCfg;
|
|||
|
|
import com.nis.domain.maat.ToMaatResult;
|
|||
|
|
import com.nis.exceptions.MaatConvertException;
|
|||
|
|
import com.nis.util.ConfigServiceUtil;
|
|||
|
|
import com.nis.web.dao.configuration.DdosCfgDao;
|
|||
|
|
import com.nis.web.security.UserUtils;
|
|||
|
|
import com.nis.web.service.BaseService;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* ddos配置业务
|
|||
|
|
* @author dell
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
@Service
|
|||
|
|
public class DdosCfgService extends BaseService{
|
|||
|
|
@Autowired
|
|||
|
|
protected DdosCfgDao ddosCfgDao;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public Page<DdosIpCfg> findPage(Page page, DdosIpCfg entity) {
|
|||
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|||
|
|
entity.setPage(page);
|
|||
|
|
List<DdosIpCfg> list=ddosCfgDao.findPage(entity);
|
|||
|
|
page.setList(list);
|
|||
|
|
return page;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public DdosIpCfg getDdosIpCfg(Long cfgId) {
|
|||
|
|
return ddosCfgDao.getDdosIpCfg(cfgId);
|
|||
|
|
}
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void saveOrUpdate(DdosIpCfg entity){
|
|||
|
|
Date createTime=new Date();
|
|||
|
|
//设置区域运营商信息
|
|||
|
|
setAreaEffectiveIds(entity);
|
|||
|
|
//新增
|
|||
|
|
if(entity.getCfgId()==null){
|
|||
|
|
entity.setCreatorId(UserUtils.getUser().getId());
|
|||
|
|
entity.setCreateTime(createTime);
|
|||
|
|
entity.setIsValid(0);
|
|||
|
|
entity.setIsAudit(0);
|
|||
|
|
//调用服务接口获取compileId
|
|||
|
|
List<Integer> compileIds = new ArrayList<Integer>();
|
|||
|
|
try {
|
|||
|
|
compileIds = ConfigServiceUtil.getId(1,1);
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
logger.info("获取编译ID出错");
|
|||
|
|
throw new MaatConvertException(e.getMessage());
|
|||
|
|
}
|
|||
|
|
if(compileIds != null && compileIds.size() >0 && compileIds.get(0) != 0){
|
|||
|
|
entity.setCompileId(compileIds.get(0));
|
|||
|
|
ddosCfgDao.insert(entity);
|
|||
|
|
}else{
|
|||
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//修改
|
|||
|
|
}else{
|
|||
|
|
Date editTime=new Date();
|
|||
|
|
entity.setIsValid(0);
|
|||
|
|
entity.setIsAudit(0);
|
|||
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|||
|
|
entity.setEditTime(editTime);
|
|||
|
|
ddosCfgDao.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){
|
|||
|
|
DdosIpCfg entity = new DdosIpCfg();
|
|||
|
|
String[] idArray = ids.split(",");
|
|||
|
|
for(String id :idArray){
|
|||
|
|
entity.setCfgId(Long.valueOf(id));
|
|||
|
|
entity.setFunctionId(functionId);
|
|||
|
|
entity.setIsAudit(isAudit);
|
|||
|
|
entity.setIsValid(isValid);
|
|||
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|||
|
|
entity.setEditTime(new Date());
|
|||
|
|
ddosCfgDao.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){
|
|||
|
|
DdosIpCfg entity = new DdosIpCfg();
|
|||
|
|
|
|||
|
|
List<DdosIpCfg> list = new ArrayList();
|
|||
|
|
|
|||
|
|
entity.setCfgId(Long.valueOf(id));
|
|||
|
|
entity.setIsAudit(isAudit);
|
|||
|
|
entity.setIsValid(isValid);
|
|||
|
|
entity.setAuditorId(UserUtils.getUser().getId());
|
|||
|
|
entity.setAuditTime(auditTime);
|
|||
|
|
|
|||
|
|
ddosCfgDao.update(entity);
|
|||
|
|
|
|||
|
|
entity=ddosCfgDao.getDdosIpCfg(Long.valueOf(id));
|
|||
|
|
|
|||
|
|
String json="";
|
|||
|
|
if(entity.getIsAudit()==1){
|
|||
|
|
List<InlineIp> ipList=new ArrayList<InlineIp>();
|
|||
|
|
InlineIp resStrategy=convertCallBackIp(entity,null);
|
|||
|
|
ipList.add(resStrategy);
|
|||
|
|
//调用服务接口下发配置数据
|
|||
|
|
json=gsonToJson(ipList);
|
|||
|
|
logger.info("DDOS IP配置下发配置参数:"+json);
|
|||
|
|
//调用服务接口下发配置
|
|||
|
|
try {
|
|||
|
|
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
|||
|
|
if(result!=null){
|
|||
|
|
logger.info("DDOS IP配置下发响应信息:"+result.getMsg());
|
|||
|
|
}
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
logger.error("DDOS IP配置下发失败",e);
|
|||
|
|
throw e;
|
|||
|
|
}
|
|||
|
|
}else if(entity.getIsAudit()==3){
|
|||
|
|
List<InlineIp> resStrategyList=new ArrayList<>();
|
|||
|
|
InlineIp resStrategy=convertCallBackIp(entity,entity.getDnsStrategyId());
|
|||
|
|
resStrategyList.add(resStrategy);
|
|||
|
|
//调用服务接口取消配置
|
|||
|
|
json=gsonToJson(resStrategyList);
|
|||
|
|
logger.info("DDOS IP配置参数:"+json);
|
|||
|
|
//调用服务接口取消配置
|
|||
|
|
try {
|
|||
|
|
ToMaatResult result = ConfigServiceUtil.put(json, 2);
|
|||
|
|
logger.info("DDOS IP配置响应信息:"+result.getMsg());
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
logger.info("DDOS IP配置配置失败");
|
|||
|
|
throw e;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|