307 lines
12 KiB
Java
307 lines
12 KiB
Java
package com.nis.web.service.configuration;
|
||
|
||
|
||
import info.monitorenter.cpdetector.util.FileUtil;
|
||
|
||
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 java.util.UUID;
|
||
|
||
import net.sf.json.JSONObject;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
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.exceptions.MaatConvertException;
|
||
import com.nis.util.ConfigServiceUtil;
|
||
import com.nis.util.FileUtils;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.web.dao.configuration.AvCfgDao;
|
||
import com.nis.web.security.UserUtils;
|
||
import com.nis.web.service.BaseService;
|
||
|
||
|
||
/**
|
||
* 音视频配置相关事务类
|
||
* @author dell
|
||
*
|
||
*/
|
||
@Service
|
||
public class AvCfgService extends BaseService{
|
||
// @Autowired
|
||
// protected FunctionRegionDictDao functionRegionDictDao;
|
||
// @Autowired
|
||
// protected FunctionServiceDictDao functionServiceDictDao;
|
||
@Autowired
|
||
protected AvCfgDao avCfgDao;
|
||
|
||
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){
|
||
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
|
||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
|
||
entity.setPage(page);
|
||
List<AvFileSampleCfg> list = avCfgDao.getAvFileSampleList(entity);
|
||
page.setList(list);
|
||
return page;
|
||
}
|
||
public Page<AvSignSampleCfg> getAvSignSampleList(Page<AvSignSampleCfg> page, AvSignSampleCfg entity){
|
||
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
|
||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a"));
|
||
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());
|
||
entity.setCreateTime(new Date());
|
||
//调用服务接口获取compileId
|
||
String result = "";
|
||
try {
|
||
result = ConfigServiceUtil.getId(1,1);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
logger.info("获取编译ID出错");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
Integer compileId = Integer.parseInt(result);
|
||
if(compileId!=0){
|
||
entity.setCompileId(compileId);
|
||
avCfgDao.insertAvFileSample(entity);
|
||
}else{
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||
}
|
||
}else{
|
||
entity.setEditorId(UserUtils.getUser().getId());
|
||
entity.setEditTime(new Date());
|
||
entity.setIsValid(0);
|
||
entity.setIsAudit(0);
|
||
avCfgDao.updateAvFileSample(entity);
|
||
}
|
||
}
|
||
public void saveOrUpdateAvSignSample(AvSignSampleCfg entity){
|
||
if(entity.getCfgId()==null){
|
||
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出错");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
Integer compileId = Integer.parseInt(result);
|
||
if(compileId!=0){
|
||
entity.setCompileId(compileId);
|
||
avCfgDao.insertAvSignSample(entity);
|
||
}else{
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||
}
|
||
|
||
}else{
|
||
entity.setEditorId(UserUtils.getUser().getId());
|
||
entity.setEditTime(new Date());
|
||
entity.setIsValid(0);
|
||
entity.setIsAudit(0);
|
||
avCfgDao.updateAvSignSample(entity);
|
||
}
|
||
}
|
||
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());
|
||
|
||
String oldSrcUrl = entity.getSrcPath();
|
||
String oldSampleUrl = entity.getSamplePath();
|
||
if(isAudit==1){
|
||
//音视频文件上传接口调用
|
||
try {
|
||
File srcFile = new File(oldSrcUrl);
|
||
Map<String,Object> srcMap = new HashMap();
|
||
srcMap.put("filetype", FileUtils.getSuffix(srcFile.getName(), false));
|
||
srcMap.put("datatype", "dbSystem");//源文件存入数据中心
|
||
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);
|
||
//获取文件上传响应信息(新的文件访问路径)
|
||
Map<String, Object> srcRes = gson.fromJson(result1,Map.class);
|
||
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);
|
||
Map<String,Object> sampleMap = new HashMap();
|
||
sampleMap.put("filetype", FileUtils.getSuffix(sampleFile.getName(), false));
|
||
srcMap.put("datatype", "fileSystem");//样例文件存入fastdfs
|
||
sampleMap.put("createTime", entity.getCreateTime());
|
||
sampleMap.put("key",FileUtils.getPrefix(sampleFile.getName(), false));
|
||
sampleMap.put("fileName", sampleFile.getName());
|
||
sampleMap.put("checksum", entity.getSampleMd5());
|
||
String result2 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(sampleMap));
|
||
logger.info("音视频样例文件上传响应信息:"+result2);
|
||
|
||
//获取文件上传响应信息(新的文件访问路径)
|
||
Map<String, Object> sampleRes = gson.fromJson(result1,Map.class);
|
||
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("");
|
||
}
|
||
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
logger.info("音视频文件样例配置下发失败");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}
|
||
avCfgDao.auditAvFileSample(entity);
|
||
//删除本地源文件和样例文件
|
||
if(!oldSrcUrl.equals(entity.getSrcUrl())){
|
||
FileUtils.deleteFile(oldSrcUrl);
|
||
}
|
||
if(!oldSampleUrl.equals(entity.getSampleUrl())){
|
||
FileUtils.deleteFile(oldSampleUrl);
|
||
}
|
||
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("音视频文件样例配置下发失败");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}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("音视频文件样取消配置失败");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}
|
||
}
|
||
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("音视频标志样例配置下发失败");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}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("音视频标志样例取消配置失败");
|
||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|