Commit 67822299 by 高晓磊

新建production工程,添加视频播放接口

parent 6065c97b
...@@ -137,6 +137,7 @@ dependencies { ...@@ -137,6 +137,7 @@ dependencies {
compile "com.beecode:xyst.dinas.oa:${inzVersion}" compile "com.beecode:xyst.dinas.oa:${inzVersion}"
compile "com.beecode:xyst.dinas.biz:${inzVersion}" compile "com.beecode:xyst.dinas.biz:${inzVersion}"
compile "com.beecode:xyst.dinas.project:${inzVersion}" compile "com.beecode:xyst.dinas.project:${inzVersion}"
compile "com.beecode:xyst.dinas.production:${inzVersion}"
providedRuntime lib.spring_boot_starter_tomcat providedRuntime lib.spring_boot_starter_tomcat
} }
......
...@@ -14,6 +14,7 @@ includeBuild("../") { ...@@ -14,6 +14,7 @@ includeBuild("../") {
substitute module('com.beecode:xyst.dinas.oa') with project(':xyst.dinas.oa') substitute module('com.beecode:xyst.dinas.oa') with project(':xyst.dinas.oa')
substitute module('com.beecode:xyst.dinas.biz') with project(':xyst.dinas.biz') substitute module('com.beecode:xyst.dinas.biz') with project(':xyst.dinas.biz')
substitute module('com.beecode:xyst.dinas.project') with project(':xyst.dinas.project') substitute module('com.beecode:xyst.dinas.project') with project(':xyst.dinas.project')
substitute module('com.beecode:xyst.dinas.production') with project(':xyst.dinas.production')
} }
} }
......
...@@ -12,4 +12,5 @@ include "inz.workflow" ...@@ -12,4 +12,5 @@ include "inz.workflow"
include "xyst.dinas.oa" include "xyst.dinas.oa"
include "xyst.dinas.biz" include "xyst.dinas.biz"
include "xyst.dinas.project" include "xyst.dinas.project"
include "xyst.dinas.production"
...@@ -9,7 +9,9 @@ import com.beecode.bcp.type.KObject; ...@@ -9,7 +9,9 @@ import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.internal.dao.AbstractBaseDao; import com.beecode.inz.basis.internal.dao.AbstractBaseDao;
import com.xyst.dinas.biz.constant.CameraInfoConstant; import com.xyst.dinas.biz.constant.CameraInfoConstant;
import com.xyst.dinas.biz.dao.CameraInfoDao; import com.xyst.dinas.biz.dao.CameraInfoDao;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
...@@ -56,17 +58,20 @@ public class CameraInfoDaoImpl extends AbstractBaseDao implements CameraInfoDao, ...@@ -56,17 +58,20 @@ public class CameraInfoDaoImpl extends AbstractBaseDao implements CameraInfoDao,
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.add(Restrictions.eq("regionalCompany.id", currentLoginRegionalCompany.getUuid("id"))); detachedCriteria.add(Restrictions.eq("regionalCompany.id", currentLoginRegionalCompany.getUuid("id")));
detachedCriteria.addOrder(Order.desc("sortOrder"));
if(null!=stationId){ if(null!=stationId){
detachedCriteria.add(Restrictions.eq("regionalStation.id", stationId)); detachedCriteria.add(Restrictions.eq("regionalStation.id", stationId));
} }
if(null!=watershedId){ if(null!=watershedId){
detachedCriteria.add(Restrictions.eq("watershedId", watershedId)); detachedCriteria.add(Restrictions.eq("watershedId", watershedId));
} }
detachedCriteria.add(Restrictions.like("cameraName", "%"+cameraName+"%")); if(StringUtils.isNotBlank(cameraName)){
detachedCriteria.add(Restrictions.like("cameraName", "%"+cameraName+"%"));
}
page.setTotal(template.findByCriteria(detachedCriteria).size());
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize());
page.setDatas(list); page.setDatas(list);
page.setTotal(template.findByCriteria(detachedCriteria).size());
return page; return page;
} }
......
...@@ -11,6 +11,7 @@ import com.xyst.dinas.biz.constant.DinasTypeConstant; ...@@ -11,6 +11,7 @@ import com.xyst.dinas.biz.constant.DinasTypeConstant;
import com.xyst.dinas.biz.dao.DinasOrganizationDao; import com.xyst.dinas.biz.dao.DinasOrganizationDao;
import com.xyst.dinas.biz.dao.DinasTypeDao; import com.xyst.dinas.biz.dao.DinasTypeDao;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.query.NativeQuery; import org.hibernate.query.NativeQuery;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -70,10 +71,11 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D ...@@ -70,10 +71,11 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq("regionalCompany.id", getCurrentLoginRegionalCompany().getUuid("id"))); detachedCriteria.add(Restrictions.eq("regionalCompany.id", getCurrentLoginRegionalCompany().getUuid("id")));
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.addOrder(Order.desc("sortOrder"));
page.setTotal(template.findByCriteria(detachedCriteria).size());
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize());
page.setDatas(list); page.setDatas(list);
page.setTotal(template.findByCriteria(detachedCriteria).size());
return page; return page;
} }
......
...@@ -14,6 +14,7 @@ import com.xyst.dinas.biz.dao.ShipInfoDao; ...@@ -14,6 +14,7 @@ import com.xyst.dinas.biz.dao.ShipInfoDao;
import com.xyst.dinas.biz.service.CameraInfoService; import com.xyst.dinas.biz.service.CameraInfoService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
...@@ -70,10 +71,11 @@ public class ShipInfoDaoImpl extends AbstractBaseDao implements ShipInfoDao, Shi ...@@ -70,10 +71,11 @@ public class ShipInfoDaoImpl extends AbstractBaseDao implements ShipInfoDao, Shi
if(StringUtils.isNotBlank(shipCodeNum)){ if(StringUtils.isNotBlank(shipCodeNum)){
detachedCriteria.add(Restrictions.like("shipCodeNum", "%"+shipCodeNum+"%")); detachedCriteria.add(Restrictions.like("shipCodeNum", "%"+shipCodeNum+"%"));
} }
detachedCriteria.addOrder(Order.desc("sortOrder"));
page.setTotal(template.findByCriteria(detachedCriteria).size());
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize());
page.setDatas(list); page.setDatas(list);
page.setTotal(template.findByCriteria(detachedCriteria).size());
return page; return page;
} }
......
...@@ -10,6 +10,7 @@ import com.xyst.dinas.biz.constant.StationConstant; ...@@ -10,6 +10,7 @@ import com.xyst.dinas.biz.constant.StationConstant;
import com.xyst.dinas.biz.dao.DinasTypeDao; import com.xyst.dinas.biz.dao.DinasTypeDao;
import com.xyst.dinas.biz.dao.StationDao; import com.xyst.dinas.biz.dao.StationDao;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
...@@ -33,7 +34,6 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat ...@@ -33,7 +34,6 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
@Override @Override
public Page<KObject> listStationInfoPaging(Page<KObject> page, Integer stationStatus) { public Page<KObject> listStationInfoPaging(Page<KObject> page, Integer stationStatus) {
// UUID departmentId = AminoContextHolder.getContext().getStaff().get("department").getUuid("id");
KClass bean = Amino.getStaticMetadataContext().getBean(StationConstant.ENTITY, KClass.class); KClass bean = Amino.getStaticMetadataContext().getBean(StationConstant.ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
// detachedCriteria.add(Restrictions.eq("department.id", departmentId)); // detachedCriteria.add(Restrictions.eq("department.id", departmentId));
...@@ -43,10 +43,11 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat ...@@ -43,10 +43,11 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
} }
KObject currentLoginRegionalCompany = dinasTypeDao.getCurrentLoginRegionalCompany(); KObject currentLoginRegionalCompany = dinasTypeDao.getCurrentLoginRegionalCompany();
detachedCriteria.add(Restrictions.eq("regionalCompany.id",currentLoginRegionalCompany.getUuid("id"))); detachedCriteria.add(Restrictions.eq("regionalCompany.id",currentLoginRegionalCompany.getUuid("id")));
detachedCriteria.addOrder(Order.desc("sortOrder"));
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
page.setTotal(template.findByCriteria(detachedCriteria).size());
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria,offset,page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria,offset,page.getPageSize());
page.setDatas(list); page.setDatas(list);
page.setTotal(template.findByCriteria(detachedCriteria).size());
return page; return page;
} }
......
dependencies {
compile lib.bcp_import
compile lib.bcp_type
compile lib.bcp_store
compile lib.hibernate_core
compile lib.spring_web
compile lib.spring_boot_autoconfigure
compile lib.jackson_datatype_jdk8
compile lib.jackson_datatype_jsr310
compile lib.json
compile "com.beecode:bap2.participant:${aminoVersion}"
compile "com.beecode:bcp.org:${aminoVersion}"
compile "com.beecode:bap2.department:${aminoVersion}"
compile "com.beecode:bap2.staff:${aminoVersion}"
compile 'com.deepoove:poi-tl:1.5.0'
compile project(":inz.common")
compile project(":inz.query")
compile project(":inz.workflow")
compile project(":inz.basis")
compile project(":xyst.dinas.project")
compile project(":xyst.dinas.biz")
testCompile lib.amino_boot_web
testCompile lib.mysql_connector
}
rootProject.name = 'xyst.dinas.production'
\ No newline at end of file
package com.xyst.dinas.production.config;
import com.xyst.dinas.production.dao.CameraPlayDao;
import com.xyst.dinas.production.internal.dao.CameraPlayDaoImpl;
import com.xyst.dinas.production.internal.service.CameraPlayServiceImpl;
import com.xyst.dinas.production.service.CameraPlayService;
import com.xyst.dinas.production.web.CameraPlayController;
import org.springframework.context.annotation.Bean;
public class CameraPlayConfiguration {
//CameraPlay相关bean配置
@Bean
public CameraPlayDao CameraPlayDao() {
return new CameraPlayDaoImpl();
}
@Bean
public CameraPlayService CameraPlayService(){
return new CameraPlayServiceImpl();
}
@Bean
public CameraPlayController CameraPlayController(){
return new CameraPlayController();
}
}
\ No newline at end of file
package com.xyst.dinas.production.constant;
/**
* @author scol
*/
public interface CameraPlayConstant {
String YS7_URL="https://open.ys7.com";
String YS7_LAPP_URL="/api/lapp/device";
/**
* 获取摄像头列表的url
*/
String CAMERA_LIST_URL = YS7_URL+YS7_LAPP_URL+"/camera/list";
/**
* 抓图url
*/
String CAPTURE_URL = YS7_URL+YS7_LAPP_URL+"/capture";
/**
* 移动到预置点的URL
*/
String MOVE_PRESET_URL = YS7_URL+YS7_LAPP_URL+"/preset/move";
/**
* 添加预置点url
*/
String ADD_PRESET_URL = YS7_URL+YS7_LAPP_URL+"/preset/add";
/**
* 清除预置点url
*/
String CLEAR_PRESET_URL = YS7_URL+YS7_LAPP_URL+"/preset/clear";
/**
* 云台控制开始url
*/
String CONTR_PIZ_START_URL = YS7_URL+YS7_LAPP_URL+"/ptz/start";
/**
* 云台控制结束URL
*/
String CONTR_PIZ_STOP_URL = YS7_URL+YS7_LAPP_URL+"/ptz/stop";
/**
* 获取本地视频文件url
*/
String VIDEO_FILE_URL = "https://open.ys7.com/api/lapp/video/by/time";
/**
* 获取TOKEN URL
*/
String TOKEN_URL = YS7_URL+"/api/lapp/token/get";
}
\ No newline at end of file
package com.xyst.dinas.production.dao;
import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.dao.BaseDao;
import java.util.List;
import java.util.UUID;
public interface CameraPlayDao extends BaseDao {
}
package com.xyst.dinas.production.internal.dao;
import com.beecode.amino.core.Amino;
import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.core.context.AminoContextHolder;
import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.internal.dao.AbstractBaseDao;
import com.xyst.dinas.biz.constant.CameraInfoConstant;
import com.xyst.dinas.biz.dao.CameraInfoDao;
import com.xyst.dinas.production.dao.CameraPlayDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class CameraPlayDaoImpl extends AbstractBaseDao implements CameraPlayDao, CameraInfoConstant {
/**
* 抽象方法,需要实现类提供HibernateTemplate
*
* @return
*/
@Override
protected HibernateTemplate getHibernateTemplate() {
return null;
}
/**
* 抽象方法,需要实现类提供当前ModelName
*
* @return
*/
@Override
protected String getModelName() {
return null;
}
}
package com.xyst.dinas.production.internal.service;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.biz.constant.CameraInfoConstant;
import com.xyst.dinas.biz.dao.CameraInfoDao;
import com.xyst.dinas.production.service.CameraPlayService;
import com.xyst.dinas.production.util.CameraContrUtil;
import com.xyst.dinas.production.util.PTZVo;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* @author scol
*/
@Transactional(rollbackFor = Exception.class)
public class CameraPlayServiceImpl implements CameraPlayService {
@Autowired
private CameraInfoDao cameraInfoDao;
@Autowired
@Qualifier("com.beecode.inz.basis.config.AuthcConfiguration.tenantRedisTemplate")
RedisTemplate<String, String> redisTemplate;
@Override
public ResponseObj ptzControl(UUID cameraId, int direction, int speed, int op) {
KObject cameraInfo = cameraInfoDao.load(CameraInfoConstant.ENTITY, cameraId);
//判断是否可以拍摄
if (cameraInfo.getBigInteger("cameraType") == null) {
return ResponseObj.error("cameraType错误!此类型不支持操作");
}
if (!"1".equals(cameraInfo.getString("aggType"))) {
return ResponseObj.error("aggType错误!此类型不支持操作");
}
if ((cameraInfo.getBoolean("isShare"))) {
return ResponseObj.error("分享的camera不支持操作");
}
if (cameraInfo.getString("deviceSerial") == null) {
return ResponseObj.error("无效的设备序列号");
}
String accessToken = getEZVIZToken(cameraId);
String deviceSerial = cameraInfo.get("deviceSerial").toString();
Object channel_No = cameraInfo.get("channel_no");
Integer channelNo = null;
if (channel_No != null) {
channelNo = Integer.parseInt(channel_No.toString());
}
PTZVo pztVo;
if (op == 1) {
pztVo = CameraContrUtil.ptzControlStart(deviceSerial, accessToken, direction, speed, channelNo);
} else {
pztVo = CameraContrUtil.ptzControlStop(deviceSerial, accessToken, direction, channelNo);
}
return ResponseObj.success("请查看", pztVo);
}
@Override
public String getEZVIZToken(UUID accountId) {
KObject cameraInfo = cameraInfoDao.load(CameraInfoConstant.ENTITY, accountId);
KObject cameraAccount = cameraInfo.get("cameraAccount");
String appKey = cameraAccount.getString("buildinParamFir");
String appSecret = cameraAccount.getString("buildinParamSec");
String tokenRedisKey = CameraContrUtil.getYsTokenRedisKey(appKey, appSecret);
String token = redisTemplate.opsForValue().get(tokenRedisKey);
if (StringUtils.isNotBlank(token)) {
return token;
} else {
JSONObject map = null;
try {
map = CameraContrUtil.getToken(appKey, appSecret);
} catch (Exception e) {
e.printStackTrace();
}
if (map != null && map.get("accessToken") != null) {
String accessToken = map.get("accessToken").toString();
if (map.get("expireTime") != null) {
long millis = Long.parseLong(map.get("expireTime").toString());
//token缓存时间为7天,根据过期时间设置redis缓存
redisTemplate.opsForValue().set(tokenRedisKey, accessToken, (millis - System.currentTimeMillis()), TimeUnit.MILLISECONDS);
}
return accessToken;
}
}
return null;
}
@Override
public String capturePic(UUID id, String deviceSerial, String channelNo) {
String token = getEZVIZToken(id);
if (StringUtils.isBlank(channelNo)) {
channelNo = "1";
}
String ysPicRedisKey = CameraContrUtil.getYsPicRedisKey(deviceSerial, channelNo);
String ysPicUrl = redisTemplate.opsForValue().get(ysPicRedisKey);
if (StringUtils.isNotBlank(ysPicUrl)) {
return ysPicUrl;
} else {
PTZVo ptzVo = null;
ptzVo = CameraContrUtil.capturePic(deviceSerial, Integer.valueOf(channelNo), token);
if (ptzVo.getIsSuccess()) {
//萤石云建议4分钟调用1次,并存储图片url2小时,这边每隔1小时抓图,避免调用次数过多,也不会查询到的图片太近
redisTemplate.opsForValue().set(ysPicRedisKey, ptzVo.getPicUrl(), 60 * 60 * 1000, TimeUnit.MILLISECONDS);
return ptzVo.getPicUrl();
}
}
return null;
}
@Override
public JSONObject getCameraVideFileInfo(UUID id, Long startDate, Long endDate, Integer recType) {
KObject cameraInfo = cameraInfoDao.load(CameraInfoConstant.ENTITY, id);
String token = getEZVIZToken(id);
return CameraContrUtil.getCameraVideFileInfo(token, cameraInfo.getString("deviceSerial"), Integer.valueOf(cameraInfo.getString("channelNo")), startDate, endDate, recType);
}
@Override
public ResponseObj getCameraStatus(UUID id) {
KObject cameraInfo = cameraInfoDao.load(CameraInfoConstant.ENTITY, id);
String token = getEZVIZToken(id);
JSONObject pztVo = CameraContrUtil.getCameraInfo(token, cameraInfo.getString("deviceSerial"), Integer.valueOf(cameraInfo.getString("channelNo")));
if (pztVo != null) {
if (null != pztVo.getString("code") && "10007".equals(pztVo.getString("code"))) {
return ResponseObj.error("接口调用次数达到上限");
}
return ResponseObj.success("查询成功", pztVo.toString());
} else {
return ResponseObj.error("无效的设备序列号");
}
}
}
package com.xyst.dinas.production.service;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import org.json.JSONObject;
import java.util.UUID;
public interface CameraPlayService {
ResponseObj ptzControl(UUID cameraId, int direction, int speed, int op) ;
String getEZVIZToken(UUID accountId) ;
String capturePic(UUID id, String deviceSerial, String channelNo) ;
JSONObject getCameraVideFileInfo(UUID id, Long startDate, Long endDate, Integer recType) ;
ResponseObj getCameraStatus(UUID id) ;
}
package com.xyst.dinas.production.util;
import com.xyst.dinas.production.constant.CameraPlayConstant;
import org.apache.http.HttpException;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
/**
* @author scol
*/
public class CameraContrUtil implements CameraPlayConstant {
public static String getYsTokenRedisKey(String appKey, String appSecret) {
return "camera_token_key" + appKey + "_" + appSecret;
}
public static String getYsPicRedisKey(String deviceSerial,String channelNo) {
return "camera_pic_key" + deviceSerial + "_" + channelNo;
}
/**
* 向指定URL发送GET方法的请求
*
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public static String sendGet(String url, String param) throws Exception {
StringBuilder result = new StringBuilder();
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 遍历所有的响应头字段
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
throw new Exception("发送GET请求出现异常");
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result.toString();
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式,outformate,out流中文的格式。
* @return 所代表远程资源的响应结果
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static String sendPost(String url, String param, String outformate) throws Exception {
OutputStreamWriter out = null;
BufferedReader in = null;
String result;
try {
URLConnection conn = getUrlConnection(url);
// 获取URLConnection对象对应的输出流
out = new OutputStreamWriter(conn.getOutputStream(), outformate);
// 发送请求参数
out.write(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String lines;
StringBuilder sb = new StringBuilder();
while ((lines = in.readLine()) != null) {
lines = new String(lines.getBytes(), outformate);
sb.append(lines);
}
result = sb.toString();
} catch (Exception e) {
throw new Exception("发送 POST 请求出现异常!");
}
// 使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
private static URLConnection getUrlConnection(String url) throws IOException {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
return conn;
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param) throws Exception {
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
URLConnection conn = getUrlConnection(url);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
throw new Exception("发送请求异常");
}
// 使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result.toString();
}
/**
* @return PTZVo
* update by scol 获取摄像头列表可能要进行分页,并且每页最多50条,类似临夏的账号,100多个摄像头就得再调用一次
* 修改为获取指定设备的通道信息,这个不需要分页
* @Description 获取账号下的摄像头的列表
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static JSONObject getCameraInfo(String accessToken, String deviceSerial, Integer channelNo) {
try {
if (null == channelNo) {
channelNo = 1;
}
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial;
String sendPost = sendPost(CAMERA_LIST_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
JSONArray datalist = new JSONArray(postStr.get("data").toString());
for (Object o : datalist) {
JSONObject data = new JSONObject(o.toString());
data.put("code","200");
if (channelNo.equals(data.get("channelNo"))) {
return data;
}
}
} else if ("10007".equals(code)) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", "10007");
return jsonObject;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* 于根据时间获取存储文件信息
*
* @Param recType 回放源,0-系统自动选择,1-云存储,2-本地录像。非必选,默认为0
*/
public static JSONObject getCameraVideFileInfo(String accessToken, String deviceSerial, Integer channelNo, Long startTime, Long endTime, Integer recType) {
try {
if (null == channelNo) {
channelNo = 1;
}
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&recType=" + recType + "&startTime=" + startTime + "&endTime=" + endTime;
String sendPost = sendPost(VIDEO_FILE_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
JSONArray datalist = new JSONArray(postStr.get("data").toString());
for (Object o : datalist) {
JSONObject data = new JSONObject(o.toString());
if (channelNo.equals(data.get("channelNo"))) {
return data;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* @return PTZVo
* @Description 抓图
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static PTZVo capturePic(String deviceSerial, Integer channelNo, String accessToken) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
if (channelNo == null) {
channelNo = 1;
}
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo;
String sendPost = sendPost(CAPTURE_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
JSONObject data = new JSONObject(postStr.get("data").toString());
pztVo.setIsSuccess(true);
pztVo.setPicUrl(data.get("picUrl").toString());
}
pztVo.setCode(code);
if (postStr.get("msg") != null) {
pztVo.setMsg(postStr.get("msg").toString());
}
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return PTZVo
* @Description 调用预置点
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static PTZVo presetMove(String deviceSerial, Integer channelNo, String accessToken, int index) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo + "&index="
+ index;
doSendPost(pztVo, postParam, MOVE_PRESET_URL);
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
private static void doSendPost(PTZVo pztVo, String postParam, String movePresetUrl) throws Exception {
String sendPost = sendPost(movePresetUrl, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
pztVo.setIsSuccess(true);
}
pztVo.setCode(code);
if (postStr.get("msg") != null) {
pztVo.setMsg(postStr.get("msg").toString());
}
}
/**
* @return PTZVo
* @Description 添加预置点
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static PTZVo presetAdd(String deviceSerial, String accessToken) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=1";
String sendPost = sendPost(ADD_PRESET_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
JSONObject data = new JSONObject(postStr.get("data").toString());
pztVo.setIndex(Integer.parseInt(data.get("index").toString()));
pztVo.setIsSuccess(true);
}
pztVo.setCode(code);
if (postStr.get("msg") != null) {
pztVo.setMsg(postStr.get("msg").toString());
}
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return PTZVo
* @Description 清除预置点
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static PTZVo presetClear(String deviceSerial, String accessToken, int index) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=1&index="
+ index;
doSendPost(pztVo, postParam, CLEAR_PRESET_URL);
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return PTZVo
* @Description 先抓图,再移动到预置点位置
* @author zouli
* @captureIndex 抓图的Index,null表示不抓图
* @moveIndex 抓图后要移动的预置点index,null表示不移动
* @date 2019年5月22日 下午1:47:41
*/
public static PTZVo capturePicAndMove(String deviceSerial, Integer channelNo, String accessToken, Integer moveIndex, Integer captureIndex) {
PTZVo pztVo = new PTZVo();
if (null == channelNo) {
channelNo = 1;
}
pztVo.setIsSuccess(false);
if (moveIndex != null && captureIndex != null) {
return capturePicAndMove(deviceSerial, channelNo, accessToken, moveIndex);
}
if (moveIndex != null) {
return presetMove(deviceSerial, channelNo, accessToken, moveIndex);
}
if (captureIndex != null) {
return capturePic(deviceSerial, channelNo, accessToken);
}
pztVo.setMsg("移动到预置点位置和抓图至少选其一!");
return pztVo;
}
/**
* @return PTZVo
* @Description 先抓图,再调用位置
* @author zouli
* @date 2019年5月22日 下午1:47:41
*/
public static PTZVo capturePicAndMove(String deviceSerial, Integer channelNo, String accessToken, int index) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo;
String sendPost = sendPost(CAPTURE_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
//间隔100ms
Thread.sleep(100);
JSONObject data = new JSONObject(postStr.get("data").toString());
pztVo.setIsSuccess(true);
pztVo.setPicUrl(data.get("picUrl").toString());
//移动
postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo + "&index="
+ index;
sendPost = sendPost(MOVE_PRESET_URL, postParam, "utf-8");
postStr = new JSONObject(sendPost);
pztVo.setIsSuccess(true);
}
pztVo.setCode(code);
if (postStr.get("msg") != null) {
pztVo.setMsg(postStr.get("msg").toString());
}
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return String
* @Description 云台控制开始
* @author zouli
* @date 2019年7月22日 下午1:47:41
* @direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距
*/
public static PTZVo ptzControlStart(String deviceSerial, String accessToken, int direction, int speed, Integer channelNo) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
if (null == channelNo) {
channelNo = 1;
}
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo + "&direction="
+ direction + "&speed=" + speed;
doSendPost(pztVo, postParam, CONTR_PIZ_START_URL);
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return String
* @Description 云台控制停止
* @author zouli
* @date 2019年7月22日 下午1:47:41
* @direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距
*/
public static PTZVo ptzControlStop(String deviceSerial, String accessToken, int direction, Integer channelNo) {
PTZVo pztVo = new PTZVo();
pztVo.setIsSuccess(false);
if (channelNo == null) {
channelNo = 1;
}
try {
String postParam = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo + "&direction="
+ direction;
doSendPost(pztVo, postParam, CONTR_PIZ_STOP_URL);
} catch (Exception ex) {
ex.printStackTrace();
pztVo.setMsg(ex.getMessage());
}
return pztVo;
}
/**
* @return String
* @Description 获取TOKEN地址
* @author zouli
* @date 2019年7月22日 下午1:47:41
*/
public static JSONObject getToken(String appKey, String appSecret) throws Exception {
String postParam = "appKey=" + appKey + "&appSecret=" + appSecret;
String sendPost = sendPost(TOKEN_URL, postParam, "utf-8");
JSONObject postStr = new JSONObject(sendPost);
String code = postStr.get("code").toString();
if ("200".equals(code)) {
if (postStr.get("data") != null) {
return new JSONObject(postStr.get("data").toString());
}
}
return null;
}
public static void main(String[] args) throws IOException, HttpException {
// String accessToken = "at.c4pfqd5abmkuixu0411qilw5829zzqy1-6t50exqtjo-10vf5sd-ercfyf9ah";
String accessToken = "at.6ktiaqu27muu03wqaccu9ickawq2rq2d-5mmddsppz5-10t8qy2-s091j0kem";
String deviceSerial = "D30612398";
// JSONObject data = getCameraInfo(accessToken, deviceSerial, null);
JSONObject data = getCameraVideFileInfo(accessToken, deviceSerial, 1,System.currentTimeMillis()-1000*60*60,System.currentTimeMillis(),null);
System.out.println(data);
}
}
package com.xyst.dinas.production.util;
import java.io.Serializable;
public class PTZVo implements Serializable {
/** 云台返回值 */
private static final long serialVersionUID = -2039961655880584732L;
private boolean isSuccess;
private String code;
private String msg;
private String picUrl;
private Integer index;
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getMsg() {
return msg;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
public String getPicUrl() {
return picUrl;
}
public void setIsSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public boolean getIsSuccess() {
return isSuccess;
}
}
package com.xyst.dinas.production.web;
import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.biz.service.CameraInfoService;
import com.xyst.dinas.biz.service.StationService;
import com.xyst.dinas.production.service.CameraPlayService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* @author scol
*/
@RestController()
@RequestMapping(value = "/production/cameraPlay")
public class CameraPlayController {
@Autowired
private CameraInfoService cameraInfoService;
@Autowired
private CameraPlayService cameraPlayService;
@Autowired
private StationService stationService;
@GetMapping("/getStationCameraTree")
public ResponseObj<ArrayList<Map<String, Object>>> getStationCameraTree() throws Exception {
Page<KObject> kObjectPage = new Page<>();
kObjectPage.setPageNo(1);
kObjectPage.setPageSize(1000);
Page<KObject> stationPage = stationService.queryByPaging(kObjectPage, 1);
HashMap<String, Object> stringObjectHashMap;
ArrayList<Map<String, Object>> maps = new ArrayList<>();
for (KObject data : stationPage.getDatas()) {
stringObjectHashMap = new HashMap<>();
stringObjectHashMap.put("name",data.getString("stationName"));
stringObjectHashMap.put("id",data.getUuid("id"));
List<KObject> datas = cameraInfoService.queryByPaging(kObjectPage, data.getUuid("id"), null, null).getDatas();
for (KObject kObject : datas) {
String picUrl = cameraPlayService.capturePic(kObject.getUuid("id"),kObject.getString("deviceSerial"),kObject.getString("channelNo"));
kObject.set("videoUrl",picUrl);
}
stringObjectHashMap.put("cameras", datas);
maps.add(stringObjectHashMap);
}
return ResponseObj.response(200, "查询成功", maps);
}
/**
* @return
* @Description 云台控制
* @author zhouzy-a
* @date 2017年5月22日 下午1:47:41
* @direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距
* @speed 云台速度:0-慢,1-适中,2-快
* @speed 控制操作:1-开始转动,2-停止转动
*/
@GetMapping("/ptzControl")
public ResponseObj ptzControl(UUID cameraId, int direction, int speed, int op) {
Map<String, Object> retMap = new HashMap<>();
retMap.put("status", "00");
try {
//调用后台服务
return cameraPlayService.ptzControl(cameraId, direction, speed, op);
} catch (Exception e) {
return ResponseObj.error("控制失败");
}
}
/**
*得到萤石云token
* @return
*/
@GetMapping("/getEZVIZToken/{id}")
public ResponseObj getEZVIZToken(@PathVariable("id")UUID id) {
//调用后台服务
String token = cameraPlayService.getEZVIZToken(id);
return ResponseObj.success(token);
}
/**
*获取萤石云文件信息
* @return
*/
@GetMapping("/getCameraVideFileInfo")
public ResponseObj getCameraVideFileInfo(@RequestParam("id") UUID id,@RequestParam(value = "startDate",required = false) Long startDate,@RequestParam(value ="endDate",required = false)Long endDate,@RequestParam(value ="recType",required = false)Integer recType) {
return ResponseObj.success("",cameraPlayService.getCameraVideFileInfo(id,startDate,endDate,recType));
}
/**
*获取萤石云状态
* @return
*/
@GetMapping("/getCameraStatus/{id}")
public ResponseObj getCameraStatus(@PathVariable("id") UUID id) {
return cameraPlayService.getCameraStatus(id);
}
}
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.xyst.dinas.production.config.CameraPlayConfiguration
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment