This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/service/configuration/WebsiteCfgService.java

216 lines
8.0 KiB
Java
Raw Normal View History

package com.nis.web.service.configuration;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.nis.domain.Page;
import com.nis.domain.configuration.AreaIpCfg;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.HttpBodyCfg;
import com.nis.domain.configuration.HttpReqHeadCfg;
import com.nis.domain.configuration.HttpResHeadCfg;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.domain.configuration.IpPortCfg;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.web.dao.configuration.AreaIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.configuration.WebsiteCfgDao;
import com.nis.web.service.BaseService;
import com.nis.web.service.CrudService;
/**
* 网站相关配置事务类
* @author dell
*
*/
@Service
public class WebsiteCfgService extends CrudService<WebsiteCfgDao,CfgIndexInfo> {
@Autowired
protected WebsiteCfgDao websiteCfgDao;
@Autowired
protected AreaIpCfgDao areaIpCfgDao;
public CfgIndexInfo getHttpCfg(Long cfgId){
CfgIndexInfo entity = websiteCfgDao.getCfgIndexInfo(cfgId);
List<IpPortCfg> ipPortList = websiteCfgDao.getIpPortList(entity);
List<HttpUrlCfg> httpUrlList = websiteCfgDao.getHttpUrlList(entity);
List<HttpReqHeadCfg> httpReqHdrList = websiteCfgDao.getHttpReqHdrList(entity);
List<HttpResHeadCfg> httpResHdrList = websiteCfgDao.getHttpResHdrList(entity);
List<HttpBodyCfg> httpReqBodyList = websiteCfgDao.getHttpReqBodyList(entity);
List<HttpBodyCfg> httpResBodyList = websiteCfgDao.getHttpResBodyList(entity);
List<AreaIpCfg> areaCfg = areaIpCfgDao.getByCompileId(entity.getCompileId());
entity.setIpPortList(ipPortList);
entity.setHttpReqBodyList(httpReqBodyList);
entity.setHttpReqHdrList(httpReqHdrList);
entity.setHttpResBodyList(httpResBodyList);
entity.setHttpResHdrList(httpResHdrList);
entity.setHttpUrlList(httpUrlList);
entity.setAreaCfg(areaCfg);
return entity;
}
public Page<CfgIndexInfo> getHttpList(Page<CfgIndexInfo> page, CfgIndexInfo entity){
// 生成数据权限过滤条件dsf为dataScopeFilter的简写在xml中使用 ${sqlMap.dsf}调用权限SQL
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
entity.setPage(page);
List<CfgIndexInfo> list = websiteCfgDao.getHttpList(entity);
page.setList(list);
return page;
}
public List<IpPortCfg> getHttpIpList(IpPortCfg entity){
return null;
}
public List<HttpUrlCfg> getHttpUrlList(HttpUrlCfg entity){
return null;
}
public List<HttpResHeadCfg> getHttpResHdrList(HttpResHeadCfg entity){
return null;
}
public List<HttpBodyCfg> getHttpResBodyList(HttpBodyCfg entity){
return null;
}
public List<HttpReqHeadCfg> getHttpReqHdrList(HttpReqHeadCfg entity){
return null;
}
public List<HttpBodyCfg> getHttpReqBodyList(HttpBodyCfg entity){
return null;
}
public void saveHttpCfg(CfgIndexInfo entity){
if(entity.getCfgId()==null){
Integer compileId = 0;
try {
List<Integer> idList = ConfigServiceUtil.getId(1, 1);
if(idList!=null && idList.size()>0){
compileId = idList.get(0);
}
entity.setCompileId(compileId);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
websiteCfgDao.saveCfgIndex(entity);
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpIpCfg(cfg);
}
}
if(entity.getHttpUrlList()!=null){
for(HttpUrlCfg cfg:entity.getHttpUrlList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpUrlCfg(cfg);
}
}
if(entity.getHttpReqHdrList()!=null){
for(HttpReqHeadCfg cfg:entity.getHttpReqHdrList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpReqHdrCfg(cfg);
}
}
if(entity.getHttpResHdrList()!=null){
for(HttpResHeadCfg cfg:entity.getHttpResHdrList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpResHdrCfg(cfg);
}
}
if(entity.getHttpReqBodyList()!=null){
for(HttpBodyCfg cfg:entity.getHttpReqBodyList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
if(entity.getHttpResBodyList()!=null){
for(HttpBodyCfg cfg:entity.getHttpResBodyList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
}
}else{
websiteCfgDao.updateCfgIndex(entity);
// entity = websiteCfgDao.getCfgIndexInfo(entity.getCfgId());
//无效子配置后,再新增子配置
websiteCfgDao.deleteHttpIpCfg(entity);
websiteCfgDao.deleteHttpUrlCfg(entity);
websiteCfgDao.deleteHttpReqHdrCfg(entity);
websiteCfgDao.deleteHttpResHdrCfg(entity);
websiteCfgDao.deleteHttpBodyCfg(entity);
AreaIpCfg area = new AreaIpCfg();
area.setCompileId(entity.getCompileId());
area.setFunctionId(entity.getFunctionId());
areaIpCfgDao.deleteAreaIpCfg(area);
entity.setCreateTime(new Date());
entity.setCreatorId(entity.getCurrentUser().getId());
if(entity.getIpPortList()!=null){
for(IpPortCfg cfg:entity.getIpPortList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpIpCfg(cfg);
}
}
if(entity.getHttpUrlList()!=null){
for(HttpUrlCfg cfg:entity.getHttpUrlList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpUrlCfg(cfg);
}
}
if(entity.getHttpReqHdrList()!=null){
for(HttpReqHeadCfg cfg:entity.getHttpReqHdrList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpReqHdrCfg(cfg);
}
}
if(entity.getHttpResHdrList()!=null){
for(HttpResHeadCfg cfg:entity.getHttpResHdrList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpResHdrCfg(cfg);
}
}
if(entity.getHttpReqBodyList()!=null){
for(HttpBodyCfg cfg:entity.getHttpReqBodyList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
if(entity.getHttpResBodyList()!=null){
for(HttpBodyCfg cfg:entity.getHttpResBodyList()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"});
websiteCfgDao.saveHttpBodyCfg(cfg);
}
}
//保存区域IP信息
if(entity.getAreaCfg()!=null){
for(AreaIpCfg cfg:entity.getAreaCfg()){
BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"});
areaIpCfgDao.saveAreaIpCfg(cfg);
}
}
}
}
}