2019-06-03 14:53:39 +08:00
|
|
|
package com.nis.web.service.basics;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import com.beust.jcommander.internal.Maps;
|
|
|
|
|
import com.nis.domain.FunctionRegionDict;
|
|
|
|
|
import com.nis.domain.FunctionServiceDict;
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
import com.nis.domain.basics.IpCommCfg;
|
|
|
|
|
import com.nis.domain.configuration.BaseIpCfg;
|
|
|
|
|
import com.nis.domain.configuration.CfgIndexInfo;
|
2019-06-05 10:40:36 +08:00
|
|
|
import com.nis.exceptions.MaatConvertException;
|
2019-06-03 14:53:39 +08:00
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
import com.nis.web.dao.basics.IpCommGroupCfgDao;
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
import com.nis.web.service.SpringContextHolder;
|
|
|
|
|
@Service
|
|
|
|
|
public class IpCommGroupCfgService extends BaseService {
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IpCommGroupCfgDao ipCommGroupCfgDao;
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
/**
|
|
|
|
|
* @param page
|
|
|
|
|
* @param entity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Page<IpCommCfg> findPage(Page<IpCommCfg> page, IpCommCfg entity) {
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
List<IpCommCfg> list=ipCommGroupCfgDao.findPage(entity);
|
|
|
|
|
page.setList(list);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<IpCommCfg> findByPage(String ids) {
|
|
|
|
|
List<IpCommCfg> list=ipCommGroupCfgDao.findByPage(ids);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IpCommCfg get(Long id ) {
|
|
|
|
|
return ipCommGroupCfgDao.get(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
public void save(List<IpCommCfg> entitys) {
|
|
|
|
|
logger.warn("Start to save IP,size:"+entitys.size());
|
|
|
|
|
long start=System.currentTimeMillis();
|
|
|
|
|
for(IpCommCfg ipCfg:entitys) {
|
|
|
|
|
ipCommGroupCfgDao.insert(ipCfg);
|
|
|
|
|
}
|
|
|
|
|
long end=System.currentTimeMillis();
|
|
|
|
|
logger.warn("Save IP finish,cost:"+(end-start));
|
|
|
|
|
}
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
public void update(IpCommCfg entity){
|
|
|
|
|
ipCommGroupCfgDao.update(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<IpCommCfg> getByIds(String ids) {
|
|
|
|
|
if(ids==null) {
|
|
|
|
|
throw new RuntimeException("ids is null!");
|
|
|
|
|
}
|
|
|
|
|
return ipCommGroupCfgDao.getByIds(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//新增
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
public void saveIpCommGroupCfg(CfgIndexInfo entity) {
|
|
|
|
|
//TODO 组配置更新时 需检索是否被其它配置引用,若被引用需调用相应服务接口更新配置
|
|
|
|
|
|
|
|
|
|
Date createTime=new Date();
|
|
|
|
|
if(CollectionUtils.isNotEmpty(entity.getIpCommGroupCfgList())) {
|
|
|
|
|
for (int i = 0; i < entity.getIpCommGroupCfgList().size(); i++) {
|
|
|
|
|
BeanUtils.copyProperties(entity, entity.getIpCommGroupCfgList().get(i), new String[]{"cfgId","userregion3"});
|
2019-06-05 10:40:36 +08:00
|
|
|
Integer regionId = 0;
|
|
|
|
|
List<Integer> regionIds = ConfigServiceUtil.getId(3, 1);
|
|
|
|
|
if(regionIds!=null && regionIds.size()>0){
|
|
|
|
|
regionId = regionIds.get(0);
|
|
|
|
|
}else {
|
|
|
|
|
throw new MaatConvertException("Get region id failed");
|
|
|
|
|
}
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setRegionId(regionId);
|
2019-06-03 14:53:39 +08:00
|
|
|
entity.getIpCommGroupCfgList().get(i).setRequestId(0);
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setClassify("0");
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setAttribute("0");
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setLable("0");
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setCreateTime(createTime);
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setCreatorId(entity.getCurrentUser().getId());
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setIsValid(Constants.VALID_NO);
|
|
|
|
|
entity.getIpCommGroupCfgList().get(i).setIsAudit(Constants.AUDIT_NOT_YET);
|
2019-06-05 10:40:36 +08:00
|
|
|
entity.getIpCommGroupCfgList().get(i).setGroupId(entity.getGroupId());
|
2019-06-03 14:53:39 +08:00
|
|
|
ipCommGroupCfgDao.insertForBatch(entity.getIpCommGroupCfgList().get(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void delete(String ids) {
|
|
|
|
|
// TODO 公共组配置删除时 需检索是否被其它业务配置引用,没被引用可删除
|
|
|
|
|
|
|
|
|
|
if(ids==null) {
|
|
|
|
|
throw new RuntimeException("ids is null!");
|
|
|
|
|
}
|
|
|
|
|
ipCommGroupCfgDao.delete(ids);
|
|
|
|
|
}
|
2019-06-05 10:40:36 +08:00
|
|
|
|
2019-06-03 14:53:39 +08:00
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
public void saveAndSend(FunctionRegionDict regionDict, FunctionServiceDict serviceDict, List<BaseIpCfg> cfgs,boolean send) {
|
|
|
|
|
logger.warn("Start to save IP,size:"+cfgs.size());
|
|
|
|
|
long start=System.currentTimeMillis();
|
|
|
|
|
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
SqlSession batchSqlSession = null;
|
|
|
|
|
//需要通过新增域接口新增的ip集合
|
|
|
|
|
Map<Integer,Integer> groupCount=Maps.newHashMap();
|
|
|
|
|
List<IpCommCfg> ipCommCfgs=new ArrayList(cfgs.size());
|
|
|
|
|
try{
|
|
|
|
|
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
|
|
|
|
|
|
|
|
|
for(BaseIpCfg cfg:cfgs) {
|
|
|
|
|
IpCommCfg ipCommCfg=new IpCommCfg();
|
|
|
|
|
BeanUtils.copyProperties(cfg, ipCommCfg);
|
|
|
|
|
ipCommCfgs.add(ipCommCfg);
|
|
|
|
|
((IpCommGroupCfgDao) batchSqlSession.getMapper(IpCommGroupCfgDao.class)).insertForBatch(ipCommCfg);
|
|
|
|
|
// if(send) {
|
|
|
|
|
// if(groupCount.containsKey(ipCommCfg.getGroupId())) {
|
|
|
|
|
// groupCount.put(ipCommCfg.getGroupId(), groupCount.get(ipCommCfg.getGroupId())+1);
|
|
|
|
|
// }else {
|
|
|
|
|
// groupCount.put(ipCommCfg.getGroupId(), 1);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// if(send) {
|
|
|
|
|
// if(groupCount.size()>0) {
|
|
|
|
|
// for(Entry<Integer, Integer> groupId:groupCount.entrySet()) {
|
|
|
|
|
// policyGroupInfoDao.updateUdFlag(groupId.getKey(), 1,5);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// this.send2Maat(ipCommCfgs, Constants.VALID_YES);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
batchSqlSession.commit();
|
|
|
|
|
}finally {
|
|
|
|
|
if(batchSqlSession != null){
|
|
|
|
|
batchSqlSession.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
long end=System.currentTimeMillis();
|
|
|
|
|
logger.warn("Save IP finish,cost:"+(end-start));
|
|
|
|
|
cfgs.clear();
|
|
|
|
|
cfgs=null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|