2018-02-27 15:31:30 +08:00
|
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
2018-04-11 16:44:45 +08:00
|
|
|
|
import java.util.ArrayList;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import java.util.Date;
|
2018-04-09 16:38:45 +08:00
|
|
|
|
import java.util.List;
|
2018-05-30 10:50:22 +08:00
|
|
|
|
import java.util.Map;
|
2018-04-09 16:38:45 +08:00
|
|
|
|
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2018-05-30 10:50:22 +08:00
|
|
|
|
import org.springframework.beans.BeanUtils;
|
2018-02-27 15:31:30 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
2018-04-11 16:44:45 +08:00
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
2018-02-27 15:31:30 +08:00
|
|
|
|
import com.nis.domain.configuration.BaseStringCfg;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import com.nis.domain.configuration.HttpUrlCfg;
|
2018-05-30 10:50:22 +08:00
|
|
|
|
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;
|
2018-06-04 14:42:52 +08:00
|
|
|
|
import com.nis.domain.maat.ToMaatBean;
|
|
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
2018-03-26 14:43:58 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
2018-02-27 15:31:30 +08:00
|
|
|
|
import com.nis.web.dao.configuration.StringCfgDao;
|
|
|
|
|
|
import com.nis.web.service.CrudService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* String相关配置事务类
|
|
|
|
|
|
* @author dell
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class StringCfgService extends CrudService<StringCfgDao,BaseStringCfg> {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
protected StringCfgDao stringCfgDao;
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* addStringCfg(新增IP类配置)
|
|
|
|
|
|
* (继承BaseStringCfg这个类方可使用)
|
|
|
|
|
|
* @param baseStringCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-03-05 16:30:16 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-04-13 13:50:29 +08:00
|
|
|
|
public int addStringCfg(BaseStringCfg baseStringCfg,List<BaseIpCfg> areaIpCfgs){
|
2018-04-09 16:38:45 +08:00
|
|
|
|
if(areaIpCfgs!=null&&areaIpCfgs.size()>0){
|
2018-06-02 17:40:14 +08:00
|
|
|
|
// this.saveIpBatch(areaIpCfgs);
|
2018-04-09 16:38:45 +08:00
|
|
|
|
}
|
2018-05-24 19:33:59 +08:00
|
|
|
|
//调用服务接口获取compileId
|
|
|
|
|
|
Integer compileId = 0;
|
|
|
|
|
|
try {
|
|
|
|
|
|
List<Integer> compileIds = ConfigServiceUtil.getId(1,1);
|
|
|
|
|
|
if(!StringUtil.isEmpty(compileIds)){
|
|
|
|
|
|
compileId = compileIds.get(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("获取编译ID出错");
|
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
if(compileId!=0){
|
|
|
|
|
|
baseStringCfg.setCompileId(compileId);
|
|
|
|
|
|
return stringCfgDao.insert(baseStringCfg);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
|
|
|
|
|
}
|
|
|
|
|
|
// baseStringCfg.setCompileId(0);
|
|
|
|
|
|
// return stringCfgDao.insert(baseStringCfg);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* updateStringCfg(更新IP类配置)
|
|
|
|
|
|
* (继承BaseStringCfg这个类方可使用)
|
|
|
|
|
|
* @param baseStringCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-03-05 16:30:16 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-04-13 13:50:29 +08:00
|
|
|
|
public int updateStringCfg(BaseStringCfg baseStringCfg,List<BaseIpCfg> addAreaCfg,List<BaseIpCfg> updateAreaCfg,List<BaseIpCfg> deleteAreaCfgs){
|
2018-04-09 16:38:45 +08:00
|
|
|
|
if(addAreaCfg!=null&&addAreaCfg.size()>0){
|
2018-06-02 17:40:14 +08:00
|
|
|
|
// this.saveIpBatch(addAreaCfg);
|
2018-04-09 16:38:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(updateAreaCfg!=null&&updateAreaCfg.size()>0){
|
|
|
|
|
|
this.updateIpBatch(updateAreaCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(deleteAreaCfgs!=null&&deleteAreaCfgs.size()>0){
|
|
|
|
|
|
this.deleteIpBatch(deleteAreaCfgs);
|
|
|
|
|
|
}
|
2018-04-13 13:50:29 +08:00
|
|
|
|
return stringCfgDao.update(baseStringCfg);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
2018-05-28 10:18:03 +08:00
|
|
|
|
public void auditWhiteDomain(BaseStringCfg cfg) throws Exception{
|
|
|
|
|
|
List<BaseStringCfg> beans=new ArrayList<>();
|
|
|
|
|
|
beans.add(cfg);
|
|
|
|
|
|
this.auditBatch(beans, StringCfgDao.class);
|
2018-06-04 14:42:52 +08:00
|
|
|
|
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<>();
|
2018-05-30 10:50:22 +08:00
|
|
|
|
ToMaatBean maatBean = new ToMaatBean();
|
|
|
|
|
|
MaatCfg maatCfg = new MaatCfg();
|
|
|
|
|
|
maatCfg.initDefaultValue();
|
|
|
|
|
|
BeanUtils.copyProperties(cfg, maatCfg);
|
2018-05-28 10:18:03 +08:00
|
|
|
|
if(cfg.getIsAudit()==1){
|
2018-05-30 10:50:22 +08:00
|
|
|
|
maatBean.setOpAction(Constants.INSERT_ACTION);
|
|
|
|
|
|
Map<String,List> map = cfgConvert(strRegionList,beans,2,cfg,groupRelationList);
|
|
|
|
|
|
groupRelationList=map.get("groupList");
|
2018-06-04 14:42:52 +08:00
|
|
|
|
strRegionList=map.get("dstList");
|
2018-05-30 10:50:22 +08:00
|
|
|
|
maatCfg.setAreaEffectiveIds("0");
|
|
|
|
|
|
maatCfg.setUserRegion(cfg.getCompileId()+"");
|
|
|
|
|
|
maatCfg.setAction(cfg.getAction());
|
|
|
|
|
|
maatCfg.setAuditTime(cfg.getAuditTime());
|
|
|
|
|
|
maatCfg.setIpRegionList(ipRegionList);
|
|
|
|
|
|
maatCfg.setStrRegionList(strRegionList);
|
|
|
|
|
|
maatCfg.setNumRegionList(numRegionList);
|
|
|
|
|
|
maatCfg.setDigestRegionList(digestRegionList);
|
|
|
|
|
|
maatCfg.setGroupRelationList(groupRelationList);
|
|
|
|
|
|
maatCfg.setGroupNum(groupRelationList.size());
|
|
|
|
|
|
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(cfg.getAuditTime());
|
|
|
|
|
|
maatBean.setCreatorName(cfg.getCurrentUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
2018-05-28 10:18:03 +08:00
|
|
|
|
//调用服务接口下发配置数据
|
2018-05-30 10:50:22 +08:00
|
|
|
|
String json=gsonToJson(maatBean);
|
2018-06-06 11:00:33 +08:00
|
|
|
|
logger.info("域名白名单配置:"+json);
|
2018-05-28 10:18:03 +08:00
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
2018-06-04 14:42:52 +08:00
|
|
|
|
logger.info("域名白名单配置下发响应信息:"+result.getMsg());
|
2018-05-28 10:18:03 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
2018-06-04 14:42:52 +08:00
|
|
|
|
logger.info("域名白名单配置下发失败");
|
2018-05-28 10:18:03 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(cfg.getIsAudit()==3){
|
2018-05-30 10:50:22 +08:00
|
|
|
|
maatCfg.setCompileId(cfg.getCompileId());
|
|
|
|
|
|
maatCfg.setServiceId(cfg.getServiceId());
|
|
|
|
|
|
maatCfg.setIsValid(0);//无效
|
|
|
|
|
|
configCompileList.add(maatCfg);
|
|
|
|
|
|
maatBean.setConfigCompileList(configCompileList);
|
|
|
|
|
|
maatBean.setAuditTime(cfg.getAuditTime());
|
|
|
|
|
|
maatBean.setCreatorName(cfg.getCurrentUser().getName());
|
|
|
|
|
|
maatBean.setVersion(Constants.MAAT_VERSION);
|
|
|
|
|
|
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
2018-05-28 10:18:03 +08:00
|
|
|
|
//调用服务接口取消配置
|
2018-06-04 14:42:52 +08:00
|
|
|
|
String json=gsonToJson(maatBean);
|
|
|
|
|
|
logger.info("域名白名单配置参数:"+json);
|
2018-05-24 19:33:59 +08:00
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
try {
|
2018-06-04 14:42:52 +08:00
|
|
|
|
ToMaatResult result = ConfigServiceUtil.put(json, 1);
|
|
|
|
|
|
logger.info("域名白名单取消配置响应信息:"+result.getMsg());
|
2018-05-24 19:33:59 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
2018-06-04 14:42:52 +08:00
|
|
|
|
logger.info("域名白名单取消配置失败");
|
2018-05-24 19:33:59 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-07 13:27:57 +08:00
|
|
|
|
|
2018-05-24 19:33:59 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void deleteWhiteDomain(String ids){
|
|
|
|
|
|
List<BaseStringCfg> cfgs=new ArrayList<BaseStringCfg>();
|
|
|
|
|
|
Date date =new Date();
|
|
|
|
|
|
if(StringUtils.isNotBlank(ids)){
|
|
|
|
|
|
for(String idStr:ids.split(",")){
|
|
|
|
|
|
if(StringUtils.isNotBlank(idStr)){
|
|
|
|
|
|
BaseStringCfg cfg=new BaseStringCfg();
|
|
|
|
|
|
cfg.setCfgId(Long.parseLong(idStr));
|
|
|
|
|
|
cfg.setTableName(HttpUrlCfg.getTablename());
|
|
|
|
|
|
cfg.setEditorId(cfg.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setEditTime(date);
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_DEL);
|
|
|
|
|
|
cfgs.add(cfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.deleteBatch(cfgs, StringCfgDao.class);
|
|
|
|
|
|
}
|
2018-02-27 15:31:30 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* deleteStringCfg(删除IP类配置)
|
|
|
|
|
|
* (继承BaseStringCfg这个类方可使用)
|
|
|
|
|
|
* @param baseStringCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-03-05 16:30:16 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-04-13 13:50:29 +08:00
|
|
|
|
public void deleteStringCfg(List<BaseStringCfg> stringCfg,List<BaseIpCfg> areaCfg){
|
2018-04-10 10:42:24 +08:00
|
|
|
|
if(areaCfg!=null&&areaCfg.size()>0){
|
|
|
|
|
|
this.deleteIpBatch(areaCfg);
|
|
|
|
|
|
}
|
2018-04-11 16:44:45 +08:00
|
|
|
|
this.deleteBatch(stringCfg, StringCfgDao.class);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* getStringCfg(根据IP与类名获取IP配置)
|
|
|
|
|
|
* (继承BaseStringCfg这个类方可使用)
|
|
|
|
|
|
* @param clazz
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*BaseStringCfg
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
public BaseStringCfg getStringCfgById(BaseStringCfg baseStringCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return stringCfgDao.getById(baseStringCfg.getTableName(), baseStringCfg.getCfgId());
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
2018-05-22 18:59:19 +08:00
|
|
|
|
public BaseStringCfg getStringCfgById(String tableName, long id){
|
|
|
|
|
|
return stringCfgDao.getById(tableName, id);
|
|
|
|
|
|
}
|
2018-02-27 15:31:30 +08:00
|
|
|
|
public Integer getIsValid(BaseStringCfg baseStringCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return stringCfgDao.getIsValid(baseStringCfg);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsValid(String tableName, long id){
|
|
|
|
|
|
return stringCfgDao.getIsValid(tableName,id);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsAudit(BaseStringCfg baseStringCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return stringCfgDao.getIsAudit(baseStringCfg);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsAudit(String tableName, long id){
|
|
|
|
|
|
return stringCfgDao.getIsAudit(tableName,id);
|
|
|
|
|
|
}
|
2018-04-11 16:44:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* getList(这里用一句话描述这个方法的作用)
|
|
|
|
|
|
* (这里描述这个方法适用条件 – 可选)
|
|
|
|
|
|
* @param tableName
|
|
|
|
|
|
* @param ids
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*List<BaseStringCfg>
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-05-24 19:33:59 +08:00
|
|
|
|
public List<BaseStringCfg> getListByCompileId(String tableName, String ids) {
|
2018-04-11 16:44:45 +08:00
|
|
|
|
// TODO Auto-generated method stub
|
2018-05-24 19:33:59 +08:00
|
|
|
|
return stringCfgDao.getListByCompileId(tableName,ids);
|
2018-04-11 16:44:45 +08:00
|
|
|
|
}
|
2018-05-28 10:18:03 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* getListByCfgId(这里用一句话描述这个方法的作用)
|
|
|
|
|
|
* (这里描述这个方法适用条件 – 可选)
|
|
|
|
|
|
* @param tablename
|
|
|
|
|
|
* @param ids
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*List<BaseStringCfg>
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<BaseStringCfg> getListByCfgId(String tableName, String ids) {
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
return stringCfgDao.getListByCfgId(tableName, ids);
|
|
|
|
|
|
}
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|