2018-01-09 16:50:39 +08:00
|
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
2018-04-11 13:45:04 +08:00
|
|
|
|
import java.util.ArrayList;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import java.util.Date;
|
2018-04-08 16:15:06 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2018-02-23 09:54:28 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-01-09 16:50:39 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
2018-02-25 18:43:20 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2018-01-09 16:50:39 +08:00
|
|
|
|
|
2018-04-08 16:15:06 +08:00
|
|
|
|
import com.nis.domain.configuration.AreaIpCfg;
|
2018-02-23 09:54:28 +08:00
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
2018-05-24 19:33:59 +08:00
|
|
|
|
import com.nis.domain.configuration.IpPortCfg;
|
|
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
|
|
|
|
|
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-04-08 16:15:06 +08:00
|
|
|
|
import com.nis.web.dao.configuration.AreaIpCfgDao;
|
2018-02-23 09:54:28 +08:00
|
|
|
|
import com.nis.web.dao.configuration.IpCfgDao;
|
|
|
|
|
|
import com.nis.web.service.CrudService;
|
|
|
|
|
|
|
2018-01-09 16:50:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* IP相关配置事务类
|
|
|
|
|
|
* @author dell
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
2018-02-23 09:54:28 +08:00
|
|
|
|
public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
protected IpCfgDao ipCfgDao;
|
2018-04-08 16:15:06 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
protected AreaIpCfgDao areaIpCfgDao;
|
2018-02-23 09:54:28 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* addIpCfg(新增IP类配置)
|
|
|
|
|
|
* (继承BaseIpCfg这个类方可使用)
|
|
|
|
|
|
* @param baseIpCfg
|
|
|
|
|
|
* @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 addIpCfg(BaseIpCfg baseIpCfg,List<BaseIpCfg> areaIpCfgs){
|
2018-04-08 16:15:06 +08:00
|
|
|
|
if(areaIpCfgs!=null&&areaIpCfgs.size()>0){
|
|
|
|
|
|
this.saveIpBatch(areaIpCfgs);
|
|
|
|
|
|
}
|
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){
|
|
|
|
|
|
baseIpCfg.setCompileId(compileId);
|
|
|
|
|
|
return ipCfgDao.insert(baseIpCfg);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-23 09:54:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* updateIpCfg(更新IP类配置)
|
|
|
|
|
|
* (继承BaseIpCfg这个类方可使用)
|
|
|
|
|
|
* @param baseIpCfg
|
|
|
|
|
|
* @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 updateIpCfg(BaseIpCfg baseIpCfg,List<BaseIpCfg> addAreaCfg,List<BaseIpCfg> updateAreaCfg,List<BaseIpCfg> deleteAreaCfgs){
|
2018-04-08 16:15:06 +08:00
|
|
|
|
if(addAreaCfg!=null&&addAreaCfg.size()>0){
|
|
|
|
|
|
this.saveIpBatch(addAreaCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
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 ipCfgDao.update(baseIpCfg);
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
2018-05-24 19:33:59 +08:00
|
|
|
|
public void auditWhiteIp(String ids,IpPortCfg cfg) throws Exception{
|
|
|
|
|
|
for(String id:ids.split(",")){
|
|
|
|
|
|
Long.parseLong(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
List<BaseIpCfg> beans=this.getListByCfgId(IpPortCfg.getTablename(),ids);
|
|
|
|
|
|
Date date=new Date();
|
|
|
|
|
|
for(BaseIpCfg bean:beans){
|
|
|
|
|
|
bean.setTableName(IpPortCfg.getTablename());
|
|
|
|
|
|
bean.setAuditorId(bean.getCurrentUser().getId());
|
|
|
|
|
|
bean.setAuditTime(date);
|
|
|
|
|
|
bean.setIsAudit(cfg.getIsAudit());
|
|
|
|
|
|
bean.setIsValid(cfg.getIsValid());
|
|
|
|
|
|
}
|
|
|
|
|
|
this.auditBatch(beans, IpCfgDao.class);
|
|
|
|
|
|
if(cfg.getIsAudit()==1){
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gsonToJson(beans);
|
|
|
|
|
|
logger.info("IP白名单下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
2018-05-25 08:59:02 +08:00
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
2018-05-24 19:33:59 +08:00
|
|
|
|
logger.info("IP白名单配置下发响应信息:"+result.getMsg());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("IP白名单配置下发失败");
|
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if(cfg.getIsAudit()==3){
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
String json=gsonToJson(beans);
|
|
|
|
|
|
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 new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-25 18:43:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* auditIpCfg(审核IP类配置)
|
|
|
|
|
|
* (继承BaseIpCfg这个类方可使用)
|
|
|
|
|
|
* @param baseIpCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
2018-03-26 14:43:58 +08:00
|
|
|
|
* @throws Exception
|
2018-02-25 18:43:20 +08:00
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-03-05 16:30:16 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-05-24 19:33:59 +08:00
|
|
|
|
public void auditIpCfg(int isAduit,List<BaseIpCfg> auditCfg) throws Exception{
|
|
|
|
|
|
List<BaseIpCfg> areaCfg=new ArrayList<>();
|
|
|
|
|
|
for(BaseIpCfg c:auditCfg){
|
|
|
|
|
|
if(c.getAreaCfg()!=null){
|
|
|
|
|
|
areaCfg.addAll(c.getAreaCfg());
|
|
|
|
|
|
}
|
2018-04-11 13:45:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(Constants.AUDIT_NOT_YES==isAduit||
|
|
|
|
|
|
Constants.AUDIT_YES==isAduit){//审核通过,取消审核通过需要发到maat
|
2018-05-24 19:33:59 +08:00
|
|
|
|
if(sendToMaatConvertorBatch(isAduit,auditCfg)){
|
2018-04-11 13:45:04 +08:00
|
|
|
|
if(areaCfg!=null&&areaCfg.size()>0){
|
|
|
|
|
|
this.auditIpBatch(areaCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.auditBatch(auditCfg, IpCfgDao.class);
|
2018-03-26 14:43:58 +08:00
|
|
|
|
}
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}else{
|
2018-04-11 13:45:04 +08:00
|
|
|
|
if(areaCfg!=null&&areaCfg.size()>0){
|
|
|
|
|
|
this.auditIpBatch(areaCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.auditBatch(auditCfg, IpCfgDao.class);
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-24 19:33:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
|
public void deleteWhiteIp(String ids){
|
|
|
|
|
|
List<BaseIpCfg> ipCfgs=new ArrayList<BaseIpCfg>();
|
|
|
|
|
|
Date date =new Date();
|
|
|
|
|
|
if(StringUtils.isNotBlank(ids)){
|
|
|
|
|
|
for(String idStr:ids.split(",")){
|
|
|
|
|
|
if(StringUtils.isNotBlank(idStr)){
|
|
|
|
|
|
BaseIpCfg cfg=new BaseIpCfg();
|
|
|
|
|
|
cfg.setCfgId(Long.parseLong(idStr));
|
|
|
|
|
|
cfg.setTableName(IpPortCfg.getTablename());
|
|
|
|
|
|
cfg.setEditorId(cfg.getCurrentUser().getId());
|
|
|
|
|
|
cfg.setEditTime(date);
|
|
|
|
|
|
cfg.setIsValid(Constants.VALID_DEL);
|
|
|
|
|
|
ipCfgs.add(cfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.deleteBatch(ipCfgs, IpCfgDao.class);
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* deleteIpCfg(删除IP类配置)
|
|
|
|
|
|
* (继承BaseIpCfg这个类方可使用)
|
|
|
|
|
|
* @param baseIpCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
2018-03-05 16:30:16 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-04-11 13:45:04 +08:00
|
|
|
|
public void deleteIpCfg(List<BaseIpCfg> baseIpCfg, List<AreaIpCfg> areaCfg){
|
|
|
|
|
|
List<BaseIpCfg> cfgs=new ArrayList<>();
|
2018-04-10 10:42:24 +08:00
|
|
|
|
if(areaCfg!=null&&areaCfg.size()>0){
|
2018-05-21 19:42:24 +08:00
|
|
|
|
cfgs.addAll(areaCfg);
|
2018-04-11 13:45:04 +08:00
|
|
|
|
this.deleteBatch(cfgs,IpCfgDao.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(baseIpCfg!=null&&baseIpCfg.size()>0){
|
|
|
|
|
|
this.deleteBatch(baseIpCfg, IpCfgDao.class);
|
2018-04-10 10:42:24 +08:00
|
|
|
|
}
|
2018-04-11 13:45:04 +08:00
|
|
|
|
|
2018-02-23 09:54:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* getIpCfg(根据IP与类名获取IP配置)
|
|
|
|
|
|
* (继承BaseIpCfg这个类方可使用)
|
|
|
|
|
|
* @param clazz
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*BaseIpCfg
|
|
|
|
|
|
* @exception
|
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
public BaseIpCfg getIpCfgById(BaseIpCfg baseIpCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return ipCfgDao.getById(baseIpCfg.getTableName(), baseIpCfg.getCfgId());
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
2018-05-21 19:42:24 +08:00
|
|
|
|
public BaseIpCfg getIpCfgById(String tableName,long id){
|
|
|
|
|
|
return ipCfgDao.getById(tableName, id);
|
|
|
|
|
|
}
|
2018-02-25 18:43:20 +08:00
|
|
|
|
public Integer getIsValid(BaseIpCfg baseIpCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return ipCfgDao.getIsValid(baseIpCfg);
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsValid(String tableName, long id){
|
|
|
|
|
|
return ipCfgDao.getIsValid(tableName,id);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsAudit(BaseIpCfg baseIpCfg){
|
2018-03-26 14:43:58 +08:00
|
|
|
|
return ipCfgDao.getIsAudit(baseIpCfg);
|
2018-02-25 18:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
public Integer getIsAudit(String tableName, long id){
|
|
|
|
|
|
return ipCfgDao.getIsAudit(tableName,id);
|
2018-02-23 09:54:28 +08:00
|
|
|
|
}
|
2018-04-08 16:15:06 +08:00
|
|
|
|
public List<AreaIpCfg> getAreaCfgByCompileId(int compileId){
|
|
|
|
|
|
return areaIpCfgDao.getByCompileId(compileId);
|
|
|
|
|
|
}
|
2018-05-24 19:33:59 +08:00
|
|
|
|
public List<BaseIpCfg> getListByComileId(String tableName,String ids){
|
|
|
|
|
|
return ipCfgDao.getListByComileId(tableName,ids);
|
|
|
|
|
|
}
|
|
|
|
|
|
public List<BaseIpCfg> getListByCfgId(String tableName,String ids){
|
|
|
|
|
|
return ipCfgDao.getListByCfgId(tableName,ids);
|
2018-04-11 13:45:04 +08:00
|
|
|
|
}
|
2018-01-09 16:50:39 +08:00
|
|
|
|
}
|