284 lines
9.0 KiB
Java
284 lines
9.0 KiB
Java
package com.nis.web.service.configuration;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import com.nis.domain.configuration.AreaIpCfg;
|
||
import com.nis.domain.configuration.BaseIpCfg;
|
||
import com.nis.domain.configuration.IpPortCfg;
|
||
import com.nis.domain.maat.ToMaatResult;
|
||
import com.nis.exceptions.MaatConvertException;
|
||
import com.nis.util.ConfigServiceUtil;
|
||
import com.nis.util.Constants;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.web.dao.configuration.AreaIpCfgDao;
|
||
import com.nis.web.dao.configuration.IpCfgDao;
|
||
import com.nis.web.service.CrudService;
|
||
|
||
/**
|
||
* IP相关配置事务类
|
||
* @author dell
|
||
*
|
||
*/
|
||
@Service
|
||
public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
|
||
@Autowired
|
||
protected IpCfgDao ipCfgDao;
|
||
@Autowired
|
||
protected AreaIpCfgDao areaIpCfgDao;
|
||
/**
|
||
*
|
||
* addIpCfg(新增IP类配置)
|
||
* (继承BaseIpCfg这个类方可使用)
|
||
* @param baseIpCfg
|
||
* @return
|
||
*int
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public int addIpCfg(BaseIpCfg baseIpCfg,List<BaseIpCfg> areaIpCfgs){
|
||
if(areaIpCfgs!=null&&areaIpCfgs.size()>0){
|
||
this.saveIpBatch(areaIpCfgs);
|
||
}
|
||
//调用服务接口获取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\"/>");
|
||
}
|
||
|
||
}
|
||
/**
|
||
*
|
||
* updateIpCfg(更新IP类配置)
|
||
* (继承BaseIpCfg这个类方可使用)
|
||
* @param baseIpCfg
|
||
* @return
|
||
*int
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public int updateIpCfg(BaseIpCfg baseIpCfg,List<BaseIpCfg> addAreaCfg,List<BaseIpCfg> updateAreaCfg,List<BaseIpCfg> deleteAreaCfgs){
|
||
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);
|
||
}
|
||
return ipCfgDao.update(baseIpCfg);
|
||
}
|
||
public void auditWhiteIp(BaseIpCfg cfg) throws Exception{
|
||
List<BaseIpCfg> beans=new ArrayList<>();
|
||
beans.add(cfg);
|
||
this.auditBatch(beans, IpCfgDao.class);
|
||
if(cfg.getIsAudit()==1){
|
||
//待调整
|
||
|
||
//调用服务接口下发配置数据
|
||
String json=gsonToJson(beans);
|
||
logger.info("IP白名单下发配置参数:"+json);
|
||
//调用服务接口下发配置
|
||
try {
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(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());
|
||
}
|
||
}
|
||
}
|
||
public void auditWhiteIp(String ids,IpPortCfg cfg) throws Exception{
|
||
|
||
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 {
|
||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(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());
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
*
|
||
* auditIpCfg(审核IP类配置)
|
||
* (继承BaseIpCfg这个类方可使用)
|
||
* @param baseIpCfg
|
||
* @return
|
||
*int
|
||
* @throws Exception
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
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());
|
||
}
|
||
}
|
||
if(Constants.AUDIT_NOT_YES==isAduit||
|
||
Constants.AUDIT_YES==isAduit){//审核通过,取消审核通过需要发到maat
|
||
if(sendToMaatConvertorBatch(isAduit,auditCfg)){
|
||
if(areaCfg!=null&&areaCfg.size()>0){
|
||
this.auditIpBatch(areaCfg);
|
||
}
|
||
this.auditBatch(auditCfg, IpCfgDao.class);
|
||
}
|
||
}else{
|
||
if(areaCfg!=null&&areaCfg.size()>0){
|
||
this.auditIpBatch(areaCfg);
|
||
}
|
||
this.auditBatch(auditCfg, IpCfgDao.class);
|
||
}
|
||
|
||
}
|
||
@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);
|
||
}
|
||
/**
|
||
*
|
||
* deleteIpCfg(删除IP类配置)
|
||
* (继承BaseIpCfg这个类方可使用)
|
||
* @param baseIpCfg
|
||
* @return
|
||
*int
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
public void deleteIpCfg(List<BaseIpCfg> baseIpCfg, List<AreaIpCfg> areaCfg){
|
||
List<BaseIpCfg> cfgs=new ArrayList<>();
|
||
if(areaCfg!=null&&areaCfg.size()>0){
|
||
cfgs.addAll(areaCfg);
|
||
this.deleteBatch(cfgs,IpCfgDao.class);
|
||
}
|
||
if(baseIpCfg!=null&&baseIpCfg.size()>0){
|
||
this.deleteBatch(baseIpCfg, IpCfgDao.class);
|
||
}
|
||
|
||
}
|
||
/**
|
||
*
|
||
* getIpCfg(根据IP与类名获取IP配置)
|
||
* (继承BaseIpCfg这个类方可使用)
|
||
* @param clazz
|
||
* @param id
|
||
* @return
|
||
*BaseIpCfg
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public BaseIpCfg getIpCfgById(BaseIpCfg baseIpCfg){
|
||
return ipCfgDao.getById(baseIpCfg.getTableName(), baseIpCfg.getCfgId());
|
||
}
|
||
public BaseIpCfg getIpCfgById(String tableName,long id){
|
||
return ipCfgDao.getById(tableName, id);
|
||
}
|
||
public Integer getIsValid(BaseIpCfg baseIpCfg){
|
||
return ipCfgDao.getIsValid(baseIpCfg);
|
||
}
|
||
public Integer getIsValid(String tableName, long id){
|
||
return ipCfgDao.getIsValid(tableName,id);
|
||
}
|
||
public Integer getIsAudit(BaseIpCfg baseIpCfg){
|
||
return ipCfgDao.getIsAudit(baseIpCfg);
|
||
}
|
||
public Integer getIsAudit(String tableName, long id){
|
||
return ipCfgDao.getIsAudit(tableName,id);
|
||
}
|
||
public List<AreaIpCfg> getAreaCfgByCompileId(int compileId){
|
||
return areaIpCfgDao.getByCompileId(compileId);
|
||
}
|
||
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);
|
||
}
|
||
}
|