package com.nis.web.service.configuration; import java.io.File; import java.util.ArrayList; 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.google.gson.Gson; import com.google.gson.GsonBuilder; import com.nis.domain.Page; import com.nis.domain.configuration.AreaBean; import com.nis.domain.configuration.AreaIpCfg; import com.nis.domain.configuration.AvContIpCfg; import com.nis.domain.configuration.AvFileSampleCfg; import com.nis.domain.configuration.AvSignSampleCfg; import com.nis.domain.configuration.AvVoipAccountCfg; import com.nis.domain.configuration.AvVoipIpCfg; import com.nis.domain.configuration.CfgIndexInfo; import com.nis.exceptions.MaatConvertException; import com.nis.util.ConfigServiceUtil; import com.nis.util.Constants; import com.nis.util.StringUtil; import com.nis.util.StringUtils; import com.nis.web.dao.configuration.AreaIpCfgDao; import com.nis.web.dao.configuration.AvContentCfgDao; import com.nis.web.security.UserUtils; import com.nis.web.service.BaseService; /** * 音视频文本 * @author dell * */ @Service public class AvContentCfgService extends BaseService{ @Autowired protected AvContentCfgDao avContentCfgDao; @Autowired protected AreaIpCfgDao areaIpCfgDao; /** * 查询分页数据 * @param page 分页对象 * @param entity * @return */ public Page findPage(Page page, CfgIndexInfo entity) { entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r")); entity.setPage(page); List list=avContentCfgDao.findVoipList(entity); page.setList(list); return page; } /** * 根据索引表信息获取voipIpCfg信息 * @param entity * @return */ public List getVoipIpCfgList(CfgIndexInfo entity) { return avContentCfgDao.findVoipIpCfgList(entity); } /** * 根据索引表信息获取voipAccountCfg信息 * @param entity * @return */ public List getVoipAccountCfgList(CfgIndexInfo entity) { return avContentCfgDao.findVoipAccountCfgList(entity); } /** * 根据索引表信息获取voipAccountCfg信息 * @param entity * @return */ public CfgIndexInfo getCfgIndexInfo(CfgIndexInfo entity) { CfgIndexInfo cfg=avContentCfgDao.getCfgIndexInfo(entity); List voipAccounts=new ArrayList<>(); voipAccounts=getVoipAccountCfgList(entity); if(voipAccounts ==null || voipAccounts.size() <=0){ voipAccounts.add(new AvVoipAccountCfg()); } List voipIps=new ArrayList<>(); voipIps=getVoipIpCfgList(entity); if(voipIps ==null || voipIps.size() <=0){ voipIps.add(new AvVoipIpCfg()); } cfg.setVoipAccounts(voipAccounts); cfg.setVoipIps(voipIps); return cfg; } @Transactional(readOnly=false,rollbackFor=RuntimeException.class) public void saveOrUpdateAvVoip(CfgIndexInfo entity,String voipIpIds,String voipAccountIds,String areaCfgIds){ Date createTime=new Date(); //区域IPsetAreaEffectiveIds设置 List areaCfg=entity.getAreaCfg(); List areaIsps=entity.getAreaIsp(); if(Constants.IS_AREA_EFFECTIVE_NO==entity.getIsAreaEffective()){ entity.setAreaEffectiveIds(""); entity.setAreaType(null); }else if(Constants.IS_AREA_EFFECTIVE_YES==entity.getIsAreaEffective()){ if(Constants.AREA_EFFECTIVE_TYPE_AREA_ISP==entity.getAreaType()&&areaIsps!=null&&areaIsps.size()>0){ StringBuffer areaEffectiveIds=new StringBuffer(); for(int i=0;i0){ entity.setAreaEffectiveIds(""); } } //新增 if(entity.getCfgId()==null){ entity.setCreatorId(UserUtils.getUser().getId()); entity.setCreateTime(createTime); entity.setIsValid(0); entity.setIsAudit(0); //调用服务接口获取compileId List compileIds = new ArrayList(); try { //TODO //compileIds = ConfigServiceUtil.getId(1,1); compileIds.add((int)Math.floor(Math.random()*1000000+1)); } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+e.getMessage()); } if(compileIds != null && compileIds.size() >0 && compileIds.get(0) != 0){ entity.setCompileId(compileIds.get(0)); //保存avVoipIp if(entity.getVoipIps() != null && entity.getVoipIps().size() > 0){ for (AvVoipIpCfg voipIp : entity.getVoipIps()) { entity.setVoipIp(voipIp); avContentCfgDao.insertAvVoipIp(entity); } } //保存avVoipAccount if(entity.getVoipAccounts() != null && entity.getVoipAccounts().size() > 0){ for (AvVoipAccountCfg voipAccount : entity.getVoipAccounts()) { entity.setVoipAccount(voipAccount); avContentCfgDao.insertAvVoipAccount(entity); } } //保存区域IP信息 if(entity.getAreaCfg()!=null&&entity.getAreaCfg().size()>0){ for (AreaIpCfg areaIpCfg : entity.getAreaCfg()) { entity.setAreaIpCfg(areaIpCfg); areaIpCfgDao.saveAreaIpCfgFromCfgIndexInfo(entity); } } //保存cfgIndexInfo avContentCfgDao.insertCfgIndexInfo(entity); }else{ throw new MaatConvertException(""); } //修改 }else{ Date editTime=new Date(); entity.setIsValid(0); entity.setIsAudit(0); voipIpIds=!StringUtil.isEmpty(voipIpIds)? voipIpIds+",":""; voipAccountIds=!StringUtil.isEmpty(voipAccountIds)? voipAccountIds+",":""; areaCfgIds=!StringUtil.isEmpty(areaCfgIds)? ","+areaCfgIds:""; //判断voip信息为新增还是修改,清楚voipIpIds修改的voipId记录,剩下即为需要删除的voipId if(!StringUtil.isEmpty(entity.getVoipIps())){ for (AvVoipIpCfg voipIp : entity.getVoipIps()) { if(!StringUtil.isEmpty(voipIp.getCfgId())){ if(voipIpIds.contains(","+voipIp.getCfgId()+",")){ voipIpIds=voipIpIds.replace(voipIp.getCfgId()+",", ""); } //修改 entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(editTime); entity.setVoipIp(voipIp); avContentCfgDao.updateAvVoipIp(entity); }else{ //新增 entity.setCreatorId(UserUtils.getUser().getId()); entity.setCreateTime(createTime); entity.setVoipIp(voipIp); avContentCfgDao.insertAvVoipIp(entity); } } } if(!StringUtil.isEmpty(entity.getVoipAccounts())){ for (AvVoipAccountCfg voipAccount : entity.getVoipAccounts()) { if(!StringUtil.isEmpty(voipAccount.getCfgId())){ if(voipAccountIds.contains(","+voipAccount.getCfgId()+",")){ voipAccountIds=voipAccountIds.replace(voipAccount.getCfgId()+",", ""); } //修改 entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(editTime); entity.setVoipAccount(voipAccount); avContentCfgDao.updateAvVoipAccount(entity); }else{ //新增 entity.setCreatorId(UserUtils.getUser().getId()); entity.setCreateTime(createTime); entity.setVoipAccount(voipAccount); avContentCfgDao.insertAvVoipAccount(entity); } } } if(!StringUtil.isEmpty(entity.getAreaCfg())){ for (AreaIpCfg areaIpCfg : entity.getAreaCfg()) { if(!StringUtil.isEmpty(areaIpCfg.getCfgId())){ if(areaCfgIds.contains(","+areaIpCfg.getCfgId()+",")){ areaCfgIds=areaCfgIds.replace(areaIpCfg.getCfgId()+",", ""); } //修改 entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(editTime); entity.setAreaIpCfg(areaIpCfg); areaIpCfgDao.updateAreaIpCfgFromCfgIndexInfo(entity); }else{ //新增 entity.setCreatorId(UserUtils.getUser().getId()); entity.setCreateTime(createTime); entity.setAreaIpCfg(areaIpCfg); areaIpCfgDao.saveAreaIpCfgFromCfgIndexInfo(entity); } } } //delete 真是删除voipAccount信息 if(!StringUtil.isEmpty(voipAccountIds.replaceAll(",", ""))){ voipAccountIds=voipAccountIds.substring(1,voipAccountIds.length()); for (String cfgId : voipAccountIds.split(",")) { CfgIndexInfo cfg=new CfgIndexInfo(); AvVoipAccountCfg voipAccountCfg=new AvVoipAccountCfg(); voipAccountCfg.setCfgId(Long.parseLong(cfgId)); cfg.setVoipAccount(voipAccountCfg); avContentCfgDao.deleteAvVoipAccount(cfg); } } //delete 真是删除voipAccount信息 if(!StringUtil.isEmpty(voipIpIds.replaceAll(",", ""))){ voipIpIds=voipIpIds.substring(1,voipIpIds.length()); for (String cfgId : voipIpIds.split(",")) { CfgIndexInfo cfg=new CfgIndexInfo(); AvVoipIpCfg voipIpCfg=new AvVoipIpCfg(); voipIpCfg.setCfgId(Long.parseLong(cfgId)); cfg.setVoipIp(voipIpCfg); avContentCfgDao.deleteAvVoipIp(cfg); } } //delete 真是删除areaIpCfg信息 if(!StringUtil.isEmpty(areaCfgIds.replaceAll(",", ""))){ areaCfgIds=areaCfgIds.substring(1,areaCfgIds.length()); for (String cfgId : areaCfgIds.split(",")) { CfgIndexInfo cfg=new CfgIndexInfo(); AreaIpCfg areaIpCfg=new AreaIpCfg(); areaIpCfg.setCfgId(Long.parseLong(cfgId)); cfg.setAreaIpCfg(areaIpCfg); areaIpCfgDao.deleteAreaIpCfgByCfgId(cfg); } } //修改 entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(editTime); avContentCfgDao.updateCfgIndexInfo(entity); } } /** * * @param isAudit * @param isValid * @param ids compileIds */ @Transactional(readOnly=false,rollbackFor=RuntimeException.class) public void updateAvVoipValid(Integer isAudit,Integer isValid,String ids,Integer functionId){ CfgIndexInfo entity = new CfgIndexInfo(); String[] idArray = ids.split(","); for(String id :idArray){ entity.setCompileId(Integer.parseInt(id)); entity.setFunctionId(functionId); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(new Date()); avContentCfgDao.updateAvVoipIp(entity); avContentCfgDao.updateAvVoipAccount(entity); avContentCfgDao.updateCfgIndexInfo(entity); areaIpCfgDao.updateAreaIpCfgFromCfgIndexInfo(entity); } } /** * * @param isAudit * @param isValid * @param ids 编译Id * @param functionId */ public void auditAvVoip(Integer isAudit,Integer isValid,String ids,Integer functionId){ CfgIndexInfo entity = new CfgIndexInfo(); String[] idArray = ids.split(","); List list = new ArrayList(); List voipIpList = new ArrayList(); List voipAccountList = new ArrayList(); List areaIpCfgList = new ArrayList(); Map childMap=new HashMap<>(); CfgIndexInfo searchCfg=new CfgIndexInfo(); Date auditTime=new Date(); for(String id :idArray){ searchCfg.setCompileId(Integer.parseInt(id)); entity = avContentCfgDao.getCfgIndexInfo(searchCfg); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(auditTime); voipIpList=avContentCfgDao.findVoipIpCfgList(entity); voipAccountList=avContentCfgDao.findVoipAccountCfgList(entity); areaIpCfgList=areaIpCfgDao.findAreaIpCfgList(entity); avContentCfgDao.updateAvVoipIp(entity); avContentCfgDao.updateAvVoipAccount(entity); avContentCfgDao.updateCfgIndexInfo(entity); areaIpCfgDao.updateAreaIpCfgFromCfgIndexInfo(entity); childMap.put("voipIps", voipIpList); childMap.put("voipAccounts", voipAccountList); childMap.put("areaIpCfgs", areaIpCfgList); list.add(entity); } /*if(isAudit==1){ //调用服务接口下发配置数据 String json=gsonToJson(list); logger.info("文件样例下发配置参数:"+json); //调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json); logger.info("音视频VOIP配置下发响应信息:"+result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("音视频VOIP配置下发失败"); throw new MaatConvertException(":"+e.getMessage()); } }else if(isAudit==3){ //调用服务接口取消配置 String json=gsonToJson(list); logger.info("音视频VOIP配置参数:"+json); //调用服务接口取消配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 2); logger.info("音视频VOIP取消配置响应信息:"+result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("音视频VOIP消配置失败"); throw new MaatConvertException(":"+e.getMessage()); } }*/ } /** * contIp查询分页数据 * @param page 分页对象 * @param entity * @return */ public Page findContIpPage(Page page, AvContIpCfg entity) { entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r")); entity.setPage(page); List list=avContentCfgDao.findContIpList(entity); page.setList(list); return page; } /** * contUp根据id查询contIpCfg信息 * @param entity * @return */ public AvContIpCfg getContIpCfgById(AvContIpCfg entity) { return avContentCfgDao.findVoipIpCfgById(entity); } @Transactional(readOnly=false,rollbackFor=RuntimeException.class) public void saveOrUpdateAvContIp(AvContIpCfg entity){ Date createTime=new Date(); //新增 if(entity.getCfgId()==null){ entity.setCreatorId(UserUtils.getUser().getId()); entity.setCreateTime(createTime); entity.setIsValid(0); entity.setIsAudit(0); //调用服务接口获取compileId List compileIds = new ArrayList(); try { //TODO //compileIds = ConfigServiceUtil.getId(1,1); compileIds.add((int)Math.floor(Math.random()*1000000+1)); } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+e.getMessage()); } if(compileIds != null && compileIds.size() >0 && compileIds.get(0) != 0){ entity.setCompileId(compileIds.get(0)); //保存cfgIndexInfo avContentCfgDao.insertAvContIp(entity); }else{ throw new MaatConvertException(""); } //修改 }else{ Date editTime=new Date(); entity.setIsValid(0); entity.setIsAudit(0); entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(editTime); avContentCfgDao.updateAvContIp(entity); } } }