547 lines
20 KiB
Plaintext
547 lines
20 KiB
Plaintext
package com.securityControl.task.service.impl;
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.securityControl.common.core.utils.aes.ListHelper;
|
|
import com.securityControl.common.core.utils.aes.StringHelper;
|
|
import com.securityControl.common.redis.service.RedisService;
|
|
import com.securityControl.task.domain.vo.*;
|
|
import com.securityControl.task.mapper.DeviceDao;
|
|
import com.securityControl.task.service.DeviceService;
|
|
import com.securityControl.task.util.*;
|
|
import com.securityControl.task.util.video.QxVideotape;
|
|
import com.securityControl.task.util.video.TVideoConfigUtil;
|
|
import com.sgcc.isc.service.adapter.factory.agent.IFrontLoadedAgent;
|
|
import jdk.nashorn.internal.runtime.ECMAException;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.xml.crypto.Data;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 设备信息
|
|
*/
|
|
@Service
|
|
public class DeviceServiceImpl implements DeviceService {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DeviceServiceImpl.class);
|
|
|
|
@Autowired
|
|
private DeviceDao deviceDao;
|
|
@Resource
|
|
private RedisService redisUtil;
|
|
@Resource
|
|
TVideoConfigUtil configUtil;
|
|
/**
|
|
* 更新通道二 全部设备状态
|
|
*/
|
|
@Override
|
|
public void QxUpdateDeviceState() {
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
list.add("2");list.add("to-2");
|
|
List<DeviceVo> deviceVoList=deviceDao.getAllDeviceList(list);
|
|
if(ListHelper.isNotEmpty(deviceVoList)){
|
|
List<DeviceVo> puids=new ArrayList<>();
|
|
int j=1;
|
|
for (int i = 0; i <deviceVoList.size() ; i++) {
|
|
puids.add(deviceVoList.get(i));
|
|
if(j%50==0){
|
|
getQxDeviceState(puids);
|
|
puids.clear();
|
|
}
|
|
j++;
|
|
}
|
|
getQxDeviceState(puids);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新通道一 全部设备状态
|
|
*/
|
|
@Override
|
|
public void TyUpdateDeviceState() {
|
|
try{
|
|
if("ty".equals(configUtil.getConfig())){
|
|
List<DeviceVo> deviceVoList=deviceDao.getTyDeviceList();
|
|
getTyDeviceState(deviceVoList);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
/**
|
|
* 通道一 当日施工球机状态更新
|
|
*/
|
|
@Override
|
|
public void TyDeviceState(){
|
|
try {
|
|
if("ty".equals(configUtil.getConfig())) {
|
|
List<DeviceVo> deviceVoList = deviceDao.getTYClassMettintState();
|
|
getTyDeviceState(deviceVoList);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 通道二 当日施工球机状态更新
|
|
*/
|
|
@Override
|
|
public void QxDeviceState(){
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
list.add("2");list.add("to-2");
|
|
List<DeviceVo> deviceVoList=deviceDao.getClassMettintState(list,DateTimeHelper.getNowDay());
|
|
getQxDeviceState(deviceVoList);
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新球机信号
|
|
*/
|
|
@Override
|
|
public void updateDeviceXh() {
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String URL=configUtil.getUrl();
|
|
list.add("to-1");list.add("to-2");
|
|
List<DeviceVo> deviceVoList=deviceDao.getOnlineDevice(list);
|
|
String token=QxVideotape.login(map,URL);
|
|
for (DeviceVo dev:deviceVoList) {
|
|
String puid=dev.getPuId();
|
|
String xh= QxVideotape.getDeviceXh(puid,token,map,URL);
|
|
if(StringHelper.isNotEmpty(xh)){
|
|
deviceDao.updateDeviceXh(xh,puid);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
|
|
}
|
|
}
|
|
/**
|
|
* 通道 2在线时长
|
|
*/
|
|
@Override
|
|
public void getQxUpdateDeviceTime(){
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
list.add("2");list.add("to-2");
|
|
String time=DateTimeHelper.getNowTime();
|
|
String day=DateTimeHelper.getNowDay();
|
|
List<DeviceVo> deviceVoList=deviceDao.getAllDeviceList(list);
|
|
for (DeviceVo vo:deviceVoList) {
|
|
String state=redisUtil.get("STATE",vo.getPuId());
|
|
insertDeviceUpDownTime(vo.getPuId(),state,time,day);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 上下线记录
|
|
*/
|
|
@Override
|
|
public void getTyUpdateDeviceTime(int num){
|
|
try{
|
|
List<DeviceVo> deviceVoList=new ArrayList<DeviceVo>();
|
|
if(num==1){
|
|
deviceVoList =deviceDao.getTYClassMettintState();//获取施工的统一视频设备
|
|
}else{
|
|
deviceVoList=deviceDao.getTyDeviceList();//获取全部统一视频
|
|
}
|
|
for (DeviceVo deviceVo:deviceVoList) {//从统一视频获取上线下记录
|
|
String puid=deviceVo.getPuId();
|
|
List<String> list=new ArrayList<>();
|
|
list.add(deviceVo.getTCode());
|
|
List<TDevUpDownVo> upDownVoList =TYVideoUtil.getDevUpDown(list,DateTimeHelper.getNowDay(),DateTimeHelper.getNextDay());// 查询设备上线下记录
|
|
if(ListHelper.isNotEmpty(upDownVoList)){
|
|
for (TDevUpDownVo vo : upDownVoList) {//上下线记录入库
|
|
if (vo != null) {
|
|
List<TUpDownVo> updownList = vo.getRows();
|
|
if (ListHelper.isNotEmpty(updownList)) {
|
|
for (TUpDownVo upDownVo : updownList) {//
|
|
deviceDao.replaceUpdown(puid, DateTimeHelper.getTimesUPDown(upDownVo.getOnlineTime()),DateTimeHelper.getTimesUPDown(upDownVo.getOfflineTime()),DateTimeHelper.getNextDay());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设备上下线
|
|
*/
|
|
@Override
|
|
public void getBallUpDown() {
|
|
try{
|
|
List<String> puids =deviceDao.getClassPuid();//获取施工的统一视频设备
|
|
String URL=configUtil.getUrl();
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String token=QxVideotape.login(map,URL);
|
|
for (String puid:puids) {
|
|
String xml= QxVideotape.getBallUpDown(puid,token,DateTimeHelper.getTodayStartTime(),DateTimeHelper.getTodayEndTime(),URL);
|
|
List<BallUpDownEntity> list = PostXml.getXmlData(xml);
|
|
for (BallUpDownEntity en :list) {
|
|
//上线时间
|
|
if(StringHelper.isNotEmpty(en.getOnLineTime())){
|
|
deviceDao.replaceUpdown(puid,en.getOnLineTime(),"",DateTimeHelper.getNowDay());
|
|
}else if(StringHelper.isNotEmpty(en.getOffLineTime())){//下线时间
|
|
List<DeviceUpdownVo> updownList=deviceDao.getOnlineTime(puid);
|
|
if(ListHelper.isNotEmpty(updownList)){
|
|
deviceDao.replaceUpdown(puid,updownList.get(0).getUpTime(),en.getOffLineTime(),DateTimeHelper.getNowDay());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 修改球机水印及名称
|
|
*/
|
|
@Override
|
|
public void updateDeviceName() {
|
|
try{
|
|
String time=DateTimeHelper.getNowDay();
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String URL=configUtil.getUrl();
|
|
List<DeviceNameClassVo> list= deviceDao.getDeviceName(time);
|
|
if(ListHelper.isNotEmpty(list)){
|
|
for (DeviceNameClassVo vo:list) {
|
|
String puid=vo.getPuId();
|
|
String bidName=vo.getProName();
|
|
String manage=vo.getUserName();
|
|
String phone =vo.getPhone();
|
|
String ssdw=vo.getSsdwName();
|
|
String text =bidName+"\\r\\n"+manage+"-"+phone;//水印名称
|
|
String osdName=bidName+"|"+manage+"-"+phone;//设备名称
|
|
String osdCamera=manage+phone;//摄像头名称
|
|
if(StringHelper.isNotEmpty(ssdw)){
|
|
osdName=ssdw+"|"+osdName;
|
|
}
|
|
String token =QxVideotape.login(map,URL);
|
|
QxVideotape.setOsdText(puid,text,token,map,URL);//修改文字
|
|
QxVideotape.setOsdName(puid, osdName,token,map,URL);//修改名称
|
|
QxVideotape.setOsCameraName(puid, osdCamera,token,map,URL);//修改摄像头名称
|
|
updateThisDeviceName(puid,osdName);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改设备名称
|
|
*/
|
|
public void updateThisDeviceName(String puid,String name){
|
|
try{
|
|
deviceDao.updateDerviceName(puid,name);
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 自动分配分组
|
|
*/
|
|
@Override
|
|
public void zdfpGroupBy() {
|
|
try{
|
|
String json=QxWebUtil.getGroupNode();
|
|
if(StringHelper.isNotEmpty(json)){
|
|
TQxGroupVo vo= JSON.parseObject(json,TQxGroupVo.class);
|
|
List<TNodeVo> cityList=getChilderList(vo,"1");//城市分组
|
|
List<TNodeVo> riskList=getChilderList(vo,"2");//风险分组
|
|
//城市分组分配数据
|
|
for (TNodeVo nodeVo:cityList) {//
|
|
String index=nodeVo.getIndex();//节点索引
|
|
String cityName=nodeVo.getName();//节点名称
|
|
if(StringHelper.isNotEmpty(cityName)){
|
|
cityName=cityName.replaceAll("市","").trim();
|
|
cityName=cityName.replaceAll("公司","").trim();
|
|
}
|
|
List<String> puidList=deviceDao.getPuidListByParam(cityName,"");
|
|
if(ListHelper.isNotEmpty(puidList)){
|
|
String puids=ListHelper.joinList(puidList,",");
|
|
deleteGroupBy(puids,cityList);//删除
|
|
QxWebUtil.getPuSet(puids,index);
|
|
}
|
|
}
|
|
//风险数据分配
|
|
for (TNodeVo nodeVo:riskList) {
|
|
String index=nodeVo.getIndex();//节点索引
|
|
String riskLevel=nodeVo.getName();//节点名称
|
|
String risk="1";
|
|
if("二级".equals(riskLevel)){
|
|
risk="2";
|
|
}else if("三级".equals(riskLevel)){
|
|
risk="3";
|
|
}else if("四级".equals(riskLevel)){
|
|
risk="4";
|
|
} else if("五级".equals(riskLevel)){
|
|
risk="5";
|
|
}
|
|
List<String> puidList=deviceDao.getPuidListByParam("",risk);
|
|
if(ListHelper.isNotEmpty(puidList)){
|
|
String puids=ListHelper.joinList(puidList,",");
|
|
deleteGroupBy(puids,riskList);//删除
|
|
QxWebUtil.getPuSet(puids,index);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 统一视频设备GPS定位
|
|
*/
|
|
@Override
|
|
public void updateTYDeviceGps() {
|
|
try {
|
|
//获取施工的统一视频设备
|
|
List<DeviceVo> deviceVoList = deviceDao.getTYClassMettintState();
|
|
for (DeviceVo vo : deviceVoList) {
|
|
GpsResult data = TYVideoUtil.getDevGPS(vo.getTCode());
|
|
if (data != null) {
|
|
deviceDao.updateDeviceGps(data);
|
|
}
|
|
}
|
|
}catch(Exception e){
|
|
log.error(e.toString(), e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void updateQxDeviceGps() {
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
list.add("2");list.add("to-2");
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String URL=configUtil.getUrl();
|
|
List<DeviceVo> deviceVoList=deviceDao.getClassMettintState(list,DateTimeHelper.getNowDay());
|
|
for (DeviceVo vo:deviceVoList) {
|
|
String token = QxVideotape.login(map,URL);
|
|
BallGpsEntity entity= QxVideotape.getBallGps(vo.getPuId(),token,map,URL);
|
|
if (entity!=null){
|
|
if(ListHelper.isNotEmpty(entity.getRes())){
|
|
GpsDtoEntity gps =entity.getRes().get(0).getGps();
|
|
gps.setPuid(vo.getPuId());
|
|
deviceDao.updateGps(gps);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 上下线记录
|
|
*/
|
|
@Override
|
|
public void QxDeviceStateUpDown() {
|
|
try{
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String URL=configUtil.getUrl();
|
|
List<String> list=new ArrayList<>();
|
|
list.add("2");list.add("to-2");
|
|
String time=DateTimeHelper.getNowTime();
|
|
List<DeviceVo> deviceVoList=deviceDao.getClassMettintState(list,DateTimeHelper.getNowDay());
|
|
List<String> params=new ArrayList<>();
|
|
for (DeviceVo dev:deviceVoList) {
|
|
params.add(dev.getPuId());
|
|
}
|
|
String day=DateTimeHelper.getNowDay();
|
|
if(ListHelper.isNotEmpty(params)) {
|
|
List<ReturnDataEntity> result = QxVideotape.getBallStatuss(params, null,map,URL);//返回的数据
|
|
for (ReturnDataEntity data : result) {
|
|
if (StringHelper.isNotEmpty(data.getOnlineFlag())) {//
|
|
insertDeviceUpDownTime(data.getPuid(),data.getOnlineFlag(),time,day);
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
//删除其他分组数据
|
|
public void deleteGroupBy( String puids, List<TNodeVo> cityList){
|
|
try{
|
|
for (TNodeVo nodevo:cityList) {
|
|
QxWebUtil.getPuRemove(puids,nodevo.getIndex());
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取 相关分组节点
|
|
* @param vo
|
|
* @return
|
|
*/
|
|
private List<TNodeVo> getChilderList(TQxGroupVo vo,String type) {
|
|
List<TNodeVo> list=new ArrayList<>();
|
|
try{
|
|
List<TNodeVo> nodeList=vo.getNodelist();
|
|
for (TNodeVo nodeVo:nodeList) {
|
|
String parentIndex=nodeVo.getParentIndex();
|
|
if("0".equals(parentIndex)){
|
|
if("1".equals(type)){
|
|
if("城市分组".equals(nodeVo.getName()) || "地市分组".equals(nodeVo.getName()) || "地市".equals(nodeVo.getName()) ){
|
|
getChilder(list,nodeVo,nodeList);
|
|
break;
|
|
}
|
|
}else if("2".equals(type)){
|
|
if("风险等级分组".equals(nodeVo.getName()) || "风险等级".equals(nodeVo.getName()) || "风险".equals(nodeVo.getName())){
|
|
getChilder(list,nodeVo,nodeList);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void getChilder( List<TNodeVo> list,TNodeVo nodeVo,List<TNodeVo> nodelist){
|
|
try{
|
|
for (TNodeVo node:nodelist) {
|
|
if(node.getParentIndex().equals(nodeVo.getIndex())){
|
|
list.add(node);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 上下线
|
|
* @param puid
|
|
* @param state
|
|
* @param time
|
|
* @param day
|
|
*/
|
|
public void insertDeviceUpDownTime(String puid,String state,String time,String day){
|
|
try{
|
|
List<DeviceUpdownVo> list=deviceDao.getUpdownList(puid,day);
|
|
if("1".equals(state)){
|
|
if(ListHelper.isEmpty(list)){//无上线记录
|
|
deviceDao.insertUpTime(puid,time,day);
|
|
}
|
|
}else if("0".equals(state)){//
|
|
if(ListHelper.isNotEmpty(list)){
|
|
deviceDao.updateDownTime(puid,list.get(0).getUpTime(),time);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
/**
|
|
* 通道二设备解析处理
|
|
* @param deviceVoList
|
|
*/
|
|
public void getQxDeviceState( List<DeviceVo> deviceVoList){
|
|
try{
|
|
Map<String, Object> map =configUtil.getMaps();
|
|
String URL=configUtil.getUrl();
|
|
List<String> params=new ArrayList<>();
|
|
for (DeviceVo dev:deviceVoList) {
|
|
params.add(dev.getPuId());
|
|
}
|
|
if(ListHelper.isNotEmpty(params)) {
|
|
List<ReturnDataEntity> result = QxVideotape.getBallStatuss(params, null,map,URL);//返回的数据
|
|
for (ReturnDataEntity data : result) {
|
|
if (StringHelper.isNotEmpty(data.getOnlineFlag())) {//
|
|
redisUtil.set("STATE", data.getPuid(), data.getOnlineFlag());//存储到redis
|
|
deviceDao.updateDeviceState(data, DateTimeHelper.getNowTime());//更新数据库
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 通道一设备处理
|
|
* @param deviceVoList
|
|
*/
|
|
public void getTyDeviceState(List<DeviceVo> deviceVoList){
|
|
try{
|
|
List<String> list=new ArrayList<>();
|
|
if(ListHelper.isNotEmpty(deviceVoList)){
|
|
for (DeviceVo vo:deviceVoList) {
|
|
String tCode=vo.getTCode();
|
|
if(StringHelper.isNotEmpty(tCode)){
|
|
list.add(tCode);
|
|
}
|
|
int size=list.size();
|
|
if(ListHelper.isNotEmpty(list)){
|
|
if(size%40==0){
|
|
getTyDeviceList(list);
|
|
list=new ArrayList<>();
|
|
}
|
|
}
|
|
}
|
|
getTyDeviceList(list);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
/**
|
|
* 数据请求进行更改状态
|
|
* @param list
|
|
*/
|
|
public void getTyDeviceList( List<String> list){
|
|
try{
|
|
List<TDResultValue> resultValues= TYVideoUtil.getDeviceList(list);
|
|
for (TDResultValue res: resultValues) {
|
|
if(StringHelper.isNotEmpty(res.getStatus()))
|
|
deviceDao.refreshTyDevice(res);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
}
|