170 lines
5.3 KiB
Java
170 lines
5.3 KiB
Java
|
|
package com.nis.web.service.basics;
|
||
|
|
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
import org.springframework.transaction.annotation.Transactional;
|
||
|
|
|
||
|
|
import com.nis.domain.Page;
|
||
|
|
import com.nis.domain.basics.AsnGroupInfo;
|
||
|
|
import com.nis.domain.specific.ConfigGroupInfo;
|
||
|
|
import com.nis.exceptions.MaatConvertException;
|
||
|
|
import com.nis.util.ConfigServiceUtil;
|
||
|
|
import com.nis.util.StringUtil;
|
||
|
|
import com.nis.web.dao.basics.AsnGroupInfoDao;
|
||
|
|
import com.nis.web.dao.basics.AsnIpCfgDao;
|
||
|
|
import com.nis.web.dao.specific.ConfigGroupInfoDao;
|
||
|
|
import com.nis.web.security.UserUtils;
|
||
|
|
import com.nis.web.service.BaseService;
|
||
|
|
|
||
|
|
import jersey.repackaged.com.google.common.collect.Maps;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
public class AsnGroupInfoService extends BaseService{
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private AsnGroupInfoDao asnGroupInfoDao;
|
||
|
|
@Autowired
|
||
|
|
private ConfigGroupInfoDao configGroupInfoDao;
|
||
|
|
@Autowired
|
||
|
|
private AsnIpCfgDao asnIpCfgDao;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param page
|
||
|
|
* @param entity
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public Page<AsnGroupInfo> findAsnGroupInfoList(Page<AsnGroupInfo> page, AsnGroupInfo entity) {
|
||
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
||
|
|
entity.setPage(page);
|
||
|
|
List<AsnGroupInfo> list=asnGroupInfoDao.findAsnGroupInfoList(entity);
|
||
|
|
page.setList(list);
|
||
|
|
return page;
|
||
|
|
}
|
||
|
|
|
||
|
|
public AsnGroupInfo getById(int id) {
|
||
|
|
AsnGroupInfo AsnGroupInfo=asnGroupInfoDao.getById(id);
|
||
|
|
return AsnGroupInfo;
|
||
|
|
}
|
||
|
|
public List<AsnGroupInfo> getByOrg(String org) {
|
||
|
|
List<AsnGroupInfo> AsnGroupInfos=asnGroupInfoDao.getConfigGroupInfoByName(org);
|
||
|
|
return AsnGroupInfos;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
|
|
public void saveOrUpdate(AsnGroupInfo entity) throws MaatConvertException{
|
||
|
|
//asn类型从综合服务获取groupId
|
||
|
|
String org=entity.getOrganization().trim();
|
||
|
|
String country=entity.getCountry().trim();
|
||
|
|
int groupId=0;
|
||
|
|
//获取组织
|
||
|
|
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getAsnGroupByName(org);
|
||
|
|
|
||
|
|
if(configGroupInfo==null) {
|
||
|
|
List<Integer> groupIds= ConfigServiceUtil.getId(2,2);
|
||
|
|
if(groupIds.size()>0) {
|
||
|
|
groupId=groupIds.get(0).intValue();
|
||
|
|
}else {
|
||
|
|
throw new MaatConvertException("Get asn group id failed");
|
||
|
|
}
|
||
|
|
configGroupInfo=new ConfigGroupInfo();
|
||
|
|
configGroupInfo.setGroupName(org);
|
||
|
|
configGroupInfo.setIsIssued(0);
|
||
|
|
configGroupInfo.setGroupType(4);
|
||
|
|
configGroupInfo.setGroupId(groupIds.get(1));
|
||
|
|
configGroupInfo.setInsertTime(new Date());
|
||
|
|
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
|
||
|
|
}else {
|
||
|
|
List<Integer> groupIds= ConfigServiceUtil.getId(2,1);
|
||
|
|
if(groupIds.size()>0) {
|
||
|
|
groupId=groupIds.get(0).intValue();
|
||
|
|
}else {
|
||
|
|
throw new MaatConvertException("Get asn group id failed");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
//新增
|
||
|
|
if(entity.getGroupId()==null){
|
||
|
|
Date createTime=new Date();
|
||
|
|
entity.setCreatorId(UserUtils.getUser().getId());
|
||
|
|
entity.setCreateTime(createTime);
|
||
|
|
entity.setGroupId(groupId);
|
||
|
|
entity.setIsValid(0);
|
||
|
|
List<Integer> compileIds= ConfigServiceUtil.getId(1,1);
|
||
|
|
if(compileIds.size()>0) {
|
||
|
|
entity.setCompileId(compileIds.get(0));
|
||
|
|
}else {
|
||
|
|
throw new MaatConvertException("Get asn group id failed");
|
||
|
|
}
|
||
|
|
asnGroupInfoDao.insert(entity);
|
||
|
|
//修改
|
||
|
|
}else{
|
||
|
|
Date editTime=new Date();
|
||
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
||
|
|
entity.setEditTime(editTime);
|
||
|
|
entity.setGroupId(groupId);
|
||
|
|
asnGroupInfoDao.update(entity);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||
|
|
public void delete(String ids,String asnIds){
|
||
|
|
|
||
|
|
if(!StringUtil.isEmpty(ids)){
|
||
|
|
for (String id : ids.split(",")) {
|
||
|
|
if(!StringUtil.isEmpty(id)){
|
||
|
|
AsnGroupInfo entity=asnGroupInfoDao.getById(Integer.parseInt(id));
|
||
|
|
entity.setIsValid(-1);
|
||
|
|
entity.setId(Long.parseLong(id));
|
||
|
|
asnGroupInfoDao.updateValid(entity);
|
||
|
|
if(asnGroupInfoDao.getCountGroupInfoByName(entity.getOrganization())==0) {
|
||
|
|
configGroupInfoDao.delAsnGroup(entity.getOrganization());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int result=0;
|
||
|
|
do {
|
||
|
|
result=asnIpCfgDao.deleteByAsnId(asnIds);
|
||
|
|
}while(result>0);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
public boolean checkIps(String groupIds) {
|
||
|
|
for(String groupId:groupIds.split(",")) {
|
||
|
|
Integer.parseInt(groupId);
|
||
|
|
}
|
||
|
|
List<Integer> hasIpList=asnIpCfgDao.hasASNIds(groupIds);
|
||
|
|
if(hasIpList!=null&&hasIpList.size()>0) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public AsnGroupInfo getInfoByAsnNo(AsnGroupInfo AsnGroupInfo){
|
||
|
|
return asnGroupInfoDao.getInfoByAsnNo(AsnGroupInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public Integer getGroupIdByOrganization(String groupName){
|
||
|
|
return asnGroupInfoDao.getGroupIdByOrganization(groupName);
|
||
|
|
}
|
||
|
|
|
||
|
|
public AsnGroupInfo getGroupInfo(AsnGroupInfo AsnGroupInfo){
|
||
|
|
return asnGroupInfoDao.getGroupInfo(AsnGroupInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public AsnGroupInfo getGroupIdByNameAndASNId(String organization,String country,Long asnId) {
|
||
|
|
return asnGroupInfoDao.getGroupIdByNameAndASNId(organization,country,asnId);
|
||
|
|
}
|
||
|
|
public Map<Long,AsnGroupInfo> getGroupList() {
|
||
|
|
Map<Long,AsnGroupInfo> map=Maps.newConcurrentMap();
|
||
|
|
for(AsnGroupInfo info:asnGroupInfoDao.findAsnGroupInfos()) {
|
||
|
|
map.put(info.getAsnId(), info);
|
||
|
|
}
|
||
|
|
return map;
|
||
|
|
}
|
||
|
|
}
|