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.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.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 { @Autowired protected WebsiteCfgDao websiteCfgDao; public CfgIndexInfo getHttpCfg(Long cfgId){ CfgIndexInfo entity = websiteCfgDao.getCfgIndexInfo(cfgId); List ipPortList = websiteCfgDao.getIpPortList(entity); List httpUrlList = websiteCfgDao.getHttpUrlList(entity); List httpReqHdrList = websiteCfgDao.getHttpReqHdrList(entity); List httpResHdrList = websiteCfgDao.getHttpResHdrList(entity); List httpReqBodyList = websiteCfgDao.getHttpReqBodyList(entity); List httpResBodyList = websiteCfgDao.getHttpResBodyList(entity); entity.setIpPortList(ipPortList); entity.setHttpReqBodyList(httpReqBodyList); entity.setHttpReqHdrList(httpReqHdrList); entity.setHttpResBodyList(httpResBodyList); entity.setHttpResHdrList(httpResHdrList); entity.setHttpUrlList(httpUrlList); return entity; } public Page getHttpList(Page page, CfgIndexInfo entity){ // 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL) entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a")); entity.setPage(page); List list = websiteCfgDao.getHttpList(entity); page.setList(list); return page; } public List getHttpIpList(IpPortCfg entity){ return null; } public List getHttpUrlList(HttpUrlCfg entity){ return null; } public List getHttpResHdrList(HttpResHeadCfg entity){ return null; } public List getHttpResBodyList(HttpBodyCfg entity){ return null; } public List getHttpReqHdrList(HttpReqHeadCfg entity){ return null; } public List getHttpReqBodyList(HttpBodyCfg entity){ return null; } public void saveHttpCfg(CfgIndexInfo entity){ if(entity.getCfgId()==null){ Integer compileId = 0; try { List 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); } } } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+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); 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); } } } } }