2018-05-17 15:33:30 +08:00
|
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-21 11:22:51 +08:00
|
|
|
|
import info.monitorenter.cpdetector.util.FileUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.HashMap;
|
2018-05-18 16:46:46 +08:00
|
|
|
|
import java.util.List;
|
2018-05-21 11:22:51 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
import net.sf.json.JSONObject;
|
2018-05-18 16:46:46 +08:00
|
|
|
|
|
2018-05-17 15:33:30 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
2018-05-21 11:22:51 +08:00
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
import com.google.gson.GsonBuilder;
|
2018-05-18 16:46:46 +08:00
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
|
import com.nis.domain.configuration.AvFileSampleCfg;
|
|
|
|
|
|
import com.nis.domain.configuration.AvSignSampleCfg;
|
2018-05-21 11:22:51 +08:00
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
|
import com.nis.util.FileUtils;
|
2018-05-22 13:47:49 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
2018-05-17 15:33:30 +08:00
|
|
|
|
import com.nis.web.dao.configuration.AvCfgDao;
|
2018-05-18 16:46:46 +08:00
|
|
|
|
import com.nis.web.security.UserUtils;
|
2018-05-21 11:22:51 +08:00
|
|
|
|
import com.nis.web.service.BaseService;
|
2018-05-17 15:33:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-05-18 16:46:46 +08:00
|
|
|
|
* 音视频配置相关事务类
|
2018-05-17 15:33:30 +08:00
|
|
|
|
* @author dell
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
2018-05-21 11:22:51 +08:00
|
|
|
|
public class AvCfgService extends BaseService{
|
2018-05-18 16:46:46 +08:00
|
|
|
|
// @Autowired
|
|
|
|
|
|
// protected FunctionRegionDictDao functionRegionDictDao;
|
|
|
|
|
|
// @Autowired
|
|
|
|
|
|
// protected FunctionServiceDictDao functionServiceDictDao;
|
2018-05-17 15:33:30 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
protected AvCfgDao avCfgDao;
|
|
|
|
|
|
|
2018-05-18 16:46:46 +08:00
|
|
|
|
public AvFileSampleCfg getAvFileSampleById(Long cfgId){
|
|
|
|
|
|
return avCfgDao.getAvFileSampleById(cfgId);
|
|
|
|
|
|
}
|
|
|
|
|
|
public AvSignSampleCfg getAvSignSampleById(Long cfgId){
|
|
|
|
|
|
return avCfgDao.getAvSignSampleById(cfgId);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Page<AvFileSampleCfg> getAvFileSampleList(Page<AvFileSampleCfg> page, AvFileSampleCfg entity){
|
2018-05-21 17:21:21 +08:00
|
|
|
|
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
|
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
|
2018-05-18 16:46:46 +08:00
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List<AvFileSampleCfg> list = avCfgDao.getAvFileSampleList(entity);
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
public Page<AvSignSampleCfg> getAvSignSampleList(Page<AvSignSampleCfg> page, AvSignSampleCfg entity){
|
2018-05-21 17:21:21 +08:00
|
|
|
|
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
|
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
|
2018-05-18 16:46:46 +08:00
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
List<AvSignSampleCfg> list = avCfgDao.getAvSignSampleList(entity);
|
|
|
|
|
|
page.setList(list);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
public void saveOrUpdateAvFileSample(AvFileSampleCfg entity){
|
|
|
|
|
|
if(entity.getCfgId()==null){
|
|
|
|
|
|
entity.setCreatorId(UserUtils.getUser().getId());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
entity.setCreateTime(new Date());
|
|
|
|
|
|
//调用服务接口获取compileId
|
|
|
|
|
|
String result = "";
|
|
|
|
|
|
try {
|
|
|
|
|
|
result = ConfigServiceUtil.getId(1,1);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("获取编译ID出错");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
Integer compileId = Integer.parseInt(result);
|
|
|
|
|
|
if(compileId!=0){
|
|
|
|
|
|
entity.setCompileId(compileId);
|
|
|
|
|
|
avCfgDao.insertAvFileSample(entity);
|
|
|
|
|
|
}else{
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
2018-05-18 16:46:46 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
|
entity.setIsValid(0);
|
|
|
|
|
|
entity.setIsAudit(0);
|
2018-05-18 16:46:46 +08:00
|
|
|
|
avCfgDao.updateAvFileSample(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void saveOrUpdateAvSignSample(AvSignSampleCfg entity){
|
|
|
|
|
|
if(entity.getCfgId()==null){
|
2018-05-21 11:22:51 +08:00
|
|
|
|
entity.setCreatorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setCreateTime(new Date());
|
|
|
|
|
|
//调用服务接口获取compileId
|
|
|
|
|
|
String result = "";
|
|
|
|
|
|
try {
|
|
|
|
|
|
result = ConfigServiceUtil.getId(1,1);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("获取编译ID出错");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
Integer compileId = Integer.parseInt(result);
|
|
|
|
|
|
if(compileId!=0){
|
|
|
|
|
|
entity.setCompileId(compileId);
|
|
|
|
|
|
avCfgDao.insertAvSignSample(entity);
|
|
|
|
|
|
}else{
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-18 16:46:46 +08:00
|
|
|
|
}else{
|
2018-05-21 11:22:51 +08:00
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
|
entity.setIsValid(0);
|
|
|
|
|
|
entity.setIsAudit(0);
|
2018-05-18 16:46:46 +08:00
|
|
|
|
avCfgDao.updateAvSignSample(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-21 11:22:51 +08:00
|
|
|
|
public void updateAvFileSampleValid(Integer isAudit,Integer isValid,String ids){
|
|
|
|
|
|
AvFileSampleCfg entity = new AvFileSampleCfg();
|
|
|
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
|
entity.setCfgId(Long.parseLong(id));
|
|
|
|
|
|
entity.setIsAudit(isAudit);
|
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
|
avCfgDao.updateAvFileSampleValid(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void auditAvFileSample(Integer isAudit,Integer isValid,String ids){
|
|
|
|
|
|
AvFileSampleCfg entity = new AvFileSampleCfg();
|
|
|
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
|
List<AvFileSampleCfg> list = new ArrayList();
|
|
|
|
|
|
Gson gson=new GsonBuilder().disableHtmlEscaping()
|
|
|
|
|
|
.excludeFieldsWithoutExposeAnnotation()
|
|
|
|
|
|
.create();
|
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
|
entity = getAvFileSampleById(Long.parseLong(id));
|
|
|
|
|
|
entity.setIsAudit(isAudit);
|
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
|
entity.setAuditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setAuditTime(new Date());
|
2018-05-22 13:47:49 +08:00
|
|
|
|
|
|
|
|
|
|
String oldSrcUrl = entity.getSrcPath();
|
|
|
|
|
|
String oldSampleUrl = entity.getSamplePath();
|
2018-05-21 11:22:51 +08:00
|
|
|
|
if(isAudit==1){
|
|
|
|
|
|
//音视频文件上传接口调用
|
|
|
|
|
|
try {
|
2018-05-22 13:47:49 +08:00
|
|
|
|
File srcFile = new File(oldSrcUrl);
|
2018-05-21 11:22:51 +08:00
|
|
|
|
Map<String,Object> srcMap = new HashMap();
|
|
|
|
|
|
srcMap.put("filetype", FileUtils.getSuffix(srcFile.getName(), false));
|
2018-05-22 13:47:49 +08:00
|
|
|
|
srcMap.put("datatype", "dbSystem");//源文件存入数据中心
|
2018-05-21 11:22:51 +08:00
|
|
|
|
srcMap.put("createTime", entity.getCreateTime());
|
|
|
|
|
|
srcMap.put("key",FileUtils.getPrefix(srcFile.getName(), false));
|
|
|
|
|
|
srcMap.put("fileName", srcFile.getName());
|
|
|
|
|
|
srcMap.put("checksum", entity.getSrcMd5());
|
|
|
|
|
|
String result1 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(srcMap));
|
|
|
|
|
|
logger.info("音视频源文件上传响应信息:"+result1);
|
2018-05-22 13:47:49 +08:00
|
|
|
|
//获取文件上传响应信息(新的文件访问路径)
|
2018-05-21 17:21:21 +08:00
|
|
|
|
Map<String, Object> srcRes = gson.fromJson(result1,Map.class);
|
2018-05-22 13:47:49 +08:00
|
|
|
|
String srcAccessUrl = null;
|
|
|
|
|
|
if(!StringUtil.isEmpty(srcRes.get("data"))){
|
|
|
|
|
|
Map<String,Object> data = (Map<String,Object>)srcRes.get("data");
|
|
|
|
|
|
if(!StringUtil.isEmpty(data.get("accessUrl"))){
|
|
|
|
|
|
srcAccessUrl=data.get("accessUrl").toString();
|
|
|
|
|
|
entity.setSrcUrl(srcAccessUrl);
|
|
|
|
|
|
// entity.setSrcPath("");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
File sampleFile = new File(oldSampleUrl);
|
2018-05-21 11:22:51 +08:00
|
|
|
|
Map<String,Object> sampleMap = new HashMap();
|
2018-05-22 13:47:49 +08:00
|
|
|
|
sampleMap.put("filetype", FileUtils.getSuffix(sampleFile.getName(), false));
|
|
|
|
|
|
srcMap.put("datatype", "fileSystem");//样例文件存入fastdfs
|
2018-05-21 11:22:51 +08:00
|
|
|
|
sampleMap.put("createTime", entity.getCreateTime());
|
2018-05-22 13:47:49 +08:00
|
|
|
|
sampleMap.put("key",FileUtils.getPrefix(sampleFile.getName(), false));
|
|
|
|
|
|
sampleMap.put("fileName", sampleFile.getName());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
sampleMap.put("checksum", entity.getSampleMd5());
|
|
|
|
|
|
String result2 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(sampleMap));
|
|
|
|
|
|
logger.info("音视频样例文件上传响应信息:"+result2);
|
2018-05-22 13:47:49 +08:00
|
|
|
|
|
|
|
|
|
|
//获取文件上传响应信息(新的文件访问路径)
|
2018-05-21 17:21:21 +08:00
|
|
|
|
Map<String, Object> sampleRes = gson.fromJson(result1,Map.class);
|
2018-05-22 13:47:49 +08:00
|
|
|
|
String sampleAccessUrl = null;
|
|
|
|
|
|
if(!StringUtil.isEmpty(sampleRes.get("data"))){
|
|
|
|
|
|
Map<String,Object> data = (Map<String,Object>)sampleRes.get("data");
|
|
|
|
|
|
if(!StringUtil.isEmpty(data.get("accessUrl"))){
|
|
|
|
|
|
sampleAccessUrl = data.get("accessUrl").toString();
|
|
|
|
|
|
entity.setSampleUrl(sampleAccessUrl);
|
|
|
|
|
|
// entity.setSamplePath("");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-21 11:22:51 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("音视频文件样例配置下发失败");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-22 13:47:49 +08:00
|
|
|
|
avCfgDao.auditAvFileSample(entity);
|
|
|
|
|
|
//删除本地源文件和样例文件
|
|
|
|
|
|
if(!oldSrcUrl.equals(entity.getSrcUrl())){
|
|
|
|
|
|
FileUtils.deleteFile(oldSrcUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!oldSampleUrl.equals(entity.getSampleUrl())){
|
|
|
|
|
|
FileUtils.deleteFile(oldSampleUrl);
|
|
|
|
|
|
}
|
2018-05-21 11:22:51 +08:00
|
|
|
|
list.add(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isAudit==1){
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gson.toJson(list);
|
|
|
|
|
|
logger.info("音视频文件样例下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = ConfigServiceUtil.postCallbackCfg(json);
|
|
|
|
|
|
logger.info("音视频文件样例配置下发响应信息:"+result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("音视频文件样例配置下发失败");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}else if(isAudit==3){
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
String json=gson.toJson(list);
|
|
|
|
|
|
logger.info("音视频文件样例下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = ConfigServiceUtil.put(json,2);
|
|
|
|
|
|
logger.info("音视频文件样例取消配置响应信息:"+result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("音视频文件样取消配置失败");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void updateAvSignSampleValid(Integer isAudit,Integer isValid,String ids){
|
|
|
|
|
|
AvSignSampleCfg entity = new AvSignSampleCfg();
|
|
|
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
|
entity.setCfgId(Long.parseLong(id));
|
|
|
|
|
|
entity.setIsAudit(isAudit);
|
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
|
avCfgDao.updateAvSignSampleValid(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void auditAvSignSample(Integer isAudit,Integer isValid,String ids){
|
|
|
|
|
|
AvSignSampleCfg entity = new AvSignSampleCfg();
|
|
|
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
|
List<AvSignSampleCfg> list = new ArrayList();
|
|
|
|
|
|
Gson gson=new GsonBuilder().disableHtmlEscaping()
|
|
|
|
|
|
.excludeFieldsWithoutExposeAnnotation()
|
|
|
|
|
|
.create();
|
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
|
entity = getAvSignSampleById(Long.parseLong(id));
|
|
|
|
|
|
entity.setIsAudit(isAudit);
|
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
|
entity.setAuditorId(UserUtils.getUser().getId());
|
|
|
|
|
|
entity.setAuditTime(new Date());
|
|
|
|
|
|
avCfgDao.auditAvSignSample(entity);
|
|
|
|
|
|
list.add(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isAudit==1){
|
|
|
|
|
|
//调用服务接口下发配置数据
|
|
|
|
|
|
String json=gson.toJson(list);
|
|
|
|
|
|
logger.info("文件样例下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口下发配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = ConfigServiceUtil.postCallbackCfg(json);
|
|
|
|
|
|
logger.info("音视频标志样例配置下发响应信息:"+result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("音视频标志样例配置下发失败");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}else if(isAudit==3){
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
String json=gson.toJson(list);
|
|
|
|
|
|
logger.info("标志样例下发配置参数:"+json);
|
|
|
|
|
|
//调用服务接口取消配置
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = ConfigServiceUtil.put(json, 2);
|
|
|
|
|
|
logger.info("音视频标志样例配置取消配置响应信息:"+result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger.info("音视频标志样例取消配置失败");
|
2018-05-21 14:10:11 +08:00
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
2018-05-21 11:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-05-17 15:33:30 +08:00
|
|
|
|
}
|