309 lines
10 KiB
Java
309 lines
10 KiB
Java
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.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.domain.maat.ToMaatResult;
|
||
import com.nis.exceptions.MaatConvertException;
|
||
import com.nis.util.ConfigServiceUtil;
|
||
import com.nis.util.FileUtils;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.web.dao.FunctionRegionDictDao;
|
||
import com.nis.web.dao.FunctionServiceDictDao;
|
||
import com.nis.web.dao.configuration.AvCfgDao;
|
||
import com.nis.web.dao.configuration.AvContentCfgDao;
|
||
import com.nis.web.security.UserUtils;
|
||
import com.nis.web.service.BaseService;
|
||
import com.nis.web.service.CrudService;
|
||
|
||
import net.sf.json.JSONObject;
|
||
|
||
|
||
/**
|
||
* 音视频文本
|
||
* @author dell
|
||
*
|
||
*/
|
||
@Service
|
||
public class AvContentCfgService extends BaseService{
|
||
@Autowired
|
||
protected AvContentCfgDao avContentCfgDao;
|
||
|
||
/**
|
||
* 查询分页数据
|
||
* @param page 分页对象
|
||
* @param entity
|
||
* @return
|
||
*/
|
||
public Page<CfgIndexInfo> findPage(Page<CfgIndexInfo> page, CfgIndexInfo entity) {
|
||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
||
entity.setPage(page);
|
||
List<CfgIndexInfo> list=avContentCfgDao.findVoipList(entity);
|
||
page.setList(list);
|
||
return page;
|
||
}
|
||
/**
|
||
* 根据索引表信息获取voipIpCfg信息
|
||
* @param entity
|
||
* @return
|
||
*/
|
||
public List<AvVoipIpCfg> getVoipIpCfgList(CfgIndexInfo entity) {
|
||
return avContentCfgDao.findVoipIpCfgList(entity);
|
||
}
|
||
/**
|
||
* 根据索引表信息获取voipAccountCfg信息
|
||
* @param entity
|
||
* @return
|
||
*/
|
||
public List<AvVoipAccountCfg> getVoipAccountCfgList(CfgIndexInfo entity) {
|
||
return avContentCfgDao.findVoipAccountCfgList(entity);
|
||
}
|
||
/**
|
||
* 根据索引表信息获取voipAccountCfg信息
|
||
* @param entity
|
||
* @return
|
||
*/
|
||
public CfgIndexInfo getCfgIndexInfo(CfgIndexInfo entity) {
|
||
CfgIndexInfo cfg=avContentCfgDao.getCfgIndexInfo(entity);
|
||
List<AvVoipAccountCfg> voipAccounts=new ArrayList<>();
|
||
voipAccounts=getVoipAccountCfgList(entity);
|
||
if(voipAccounts ==null || voipAccounts.size() <=0){
|
||
voipAccounts.add(new AvVoipAccountCfg());
|
||
}
|
||
List<AvVoipIpCfg> 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){
|
||
Date createTime=new Date();
|
||
//新增
|
||
if(entity.getCfgId()==null){
|
||
entity.setCreatorId(UserUtils.getUser().getId());
|
||
entity.setCreateTime(createTime);
|
||
entity.setIsValid(0);
|
||
entity.setIsAudit(0);
|
||
//调用服务接口获取compileId
|
||
List<Integer> compileIds = new ArrayList<Integer>();
|
||
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("<spring:message code=\"request_service_failed\"/>:"+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);
|
||
}
|
||
}
|
||
//保存cfgIndexInfo
|
||
avContentCfgDao.insertCfgIndexInfo(entity);
|
||
}else{
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||
}
|
||
|
||
//修改
|
||
}else{
|
||
Date editTime=new Date();
|
||
entity.setIsValid(0);
|
||
entity.setIsAudit(0);
|
||
|
||
voipIpIds=!StringUtil.isEmpty(voipIpIds)? voipIpIds+",":"";
|
||
voipAccountIds=!StringUtil.isEmpty(voipAccountIds)? voipAccountIds+",":"";
|
||
|
||
//判断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);
|
||
}
|
||
}
|
||
}
|
||
//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);
|
||
}
|
||
}
|
||
//修改
|
||
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);
|
||
}
|
||
}
|
||
/**
|
||
*
|
||
* @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<CfgIndexInfo> list = new ArrayList();
|
||
List<AvVoipIpCfg> voipIpList = new ArrayList();
|
||
List<AvVoipAccountCfg> voipAccountList = new ArrayList();
|
||
Map<String, Object> 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);
|
||
|
||
avContentCfgDao.updateAvVoipIp(entity);
|
||
avContentCfgDao.updateAvVoipAccount(entity);
|
||
avContentCfgDao.updateCfgIndexInfo(entity);
|
||
childMap.put("voipIp", voipIpList);
|
||
childMap.put("voipAccount", voipAccountList);
|
||
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("<spring:message code=\"request_service_failed\"/>:"+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("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}*/
|
||
|
||
}
|
||
}
|