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-24 19:33:59 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
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;
|
|
|
|
|
|
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-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){
|
|
|
|
|
|
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){
|
|
|
|
|
|
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){
|
|
|
|
|
|
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 stringCfgDao.update(baseStringCfg);
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}
|
2018-05-24 19:33:59 +08:00
|
|
|
|
public void auditWhiteDomain(String ids,HttpUrlCfg cfg) throws Exception{
|
|
|
|
|
|
for(String id:ids.split(",")){
|
|
|
|
|
|
Long.parseLong(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
List<BaseStringCfg> beans=stringCfgDao.getListByCfgId(HttpUrlCfg.getTablename(),ids);
|
|
|
|
|
|
Date date=new Date();
|
|
|
|
|
|
for(BaseStringCfg 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, StringCfgDao.class);
|
|
|
|
|
|
if(cfg.getIsAudit()==1){
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gsonToJson(beans);
|
|
|
|
|
|
logger.info("文件样例下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
|
|
|
|
|
|
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-27 15:31:30 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* auditStringCfg(审核IP类配置)
|
|
|
|
|
|
* (继承BaseStringCfg这个类方可使用)
|
|
|
|
|
|
* @param baseStringCfg
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*int
|
2018-03-26 14:43:58 +08:00
|
|
|
|
* @throws Exception
|
2018-02-27 15:31:30 +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 auditStringCfg(int isAduit,List<BaseStringCfg> auditCfg,List<BaseStringCfg> sendCfg) throws Exception{
|
|
|
|
|
|
List<BaseIpCfg> areaCfg=new ArrayList<>();
|
|
|
|
|
|
for(BaseStringCfg c:auditCfg){
|
|
|
|
|
|
if(c.getAreaCfg()!=null){
|
|
|
|
|
|
areaCfg.addAll(c.getAreaCfg());
|
|
|
|
|
|
}
|
2018-04-11 16:44:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(Constants.AUDIT_NOT_YES==isAduit||
|
|
|
|
|
|
Constants.AUDIT_YES==isAduit){//审核通过,取消审核通过需要发到maat
|
2018-05-24 19:33:59 +08:00
|
|
|
|
if(sendToMaatConvertorBatch(isAduit,sendCfg)){
|
2018-04-11 16:44:45 +08:00
|
|
|
|
if(areaCfg!=null&&areaCfg.size()>0){
|
|
|
|
|
|
this.auditIpBatch(areaCfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.auditBatch(auditCfg, StringCfgDao.class);
|
2018-03-26 14:43:58 +08:00
|
|
|
|
}
|
2018-02-27 15:31:30 +08:00
|
|
|
|
}else{
|
2018-04-17 16:44:27 +08:00
|
|
|
|
this.auditBatch(auditCfg, StringCfgDao.class);
|
2018-02-27 15:31:30 +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-02-27 15:31:30 +08:00
|
|
|
|
}
|