513 lines
18 KiB
Plaintext
513 lines
18 KiB
Plaintext
package com.sercurityControl.proteam.service.impl;
|
|
|
|
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
|
import com.securityControl.common.core.utils.aes.ListHelper;
|
|
import com.sercurityControl.proteam.domain.ReturnDataEntity;
|
|
import com.sercurityControl.proteam.domain.vo.BallSwHGVo;
|
|
import com.sercurityControl.proteam.domain.vo.DeviceVo;
|
|
import com.sercurityControl.proteam.domain.vo.ReturnCodeEntity;
|
|
import com.sercurityControl.proteam.domain.vo.SysVideoConfigVo;
|
|
import com.sercurityControl.proteam.mapper.DeviceMapper;
|
|
import com.sercurityControl.proteam.service.DeviceService;
|
|
import com.sercurityControl.proteam.util.PostXml;
|
|
import com.sercurityControl.proteam.util.QxVideotape;
|
|
import com.sercurityControl.proteam.domain.ty.ResultValue;
|
|
import com.sercurityControl.proteam.util.TyVideoUtil;
|
|
import com.sercurityControl.proteam.util.VideoConfigUtil;
|
|
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 java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* 设备管理
|
|
*/
|
|
@Service
|
|
public class DeviceServiceImpl implements DeviceService {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DeviceServiceImpl.class);
|
|
|
|
@Autowired
|
|
private DeviceMapper mapper;
|
|
|
|
@Resource
|
|
private VideoConfigUtil configUtil;
|
|
|
|
/**
|
|
* 分页查询
|
|
* @param deviceVo
|
|
* @return
|
|
*/
|
|
@Override
|
|
public List<DeviceVo> getDeviceList(DeviceVo deviceVo) {
|
|
|
|
return mapper.getDeviceList(deviceVo);
|
|
}
|
|
/**
|
|
* 新增设备
|
|
* @param deviceVo
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity insertDevice(DeviceVo deviceVo) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
int num=mapper.getNumByMacId(deviceVo);
|
|
if(num>0){
|
|
returnCodeEntity.setMsg("设备mac编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num2=mapper.getNumByPuId(deviceVo);
|
|
if(num2>0){
|
|
returnCodeEntity.setMsg("puid已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num3=mapper.getNumByGbCode(deviceVo);
|
|
if(num3>0){
|
|
returnCodeEntity.setMsg("国标编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
if("1".equals(deviceVo.getIst())){
|
|
int num4=mapper.getNumByTcode(deviceVo);
|
|
if(num4>0){
|
|
returnCodeEntity.setMsg("统一视频编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
Pattern pattern =Pattern.compile("[0-9]*");
|
|
if(!pattern.matcher(deviceVo.gettCode()).matches()){
|
|
returnCodeEntity.setMsg("统一编码格式不正确");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
|
|
}else{
|
|
if(deviceVo.gettCode().length()!=18){
|
|
returnCodeEntity.setMsg("统一编码格式不正确");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
}
|
|
|
|
|
|
int num5=mapper.getNumByTWcode(deviceVo);
|
|
if(num5>0){
|
|
returnCodeEntity.setMsg("统一前端协议编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num6=mapper.getNumByTDcode(deviceVo);
|
|
if(num6>0){
|
|
returnCodeEntity.setMsg("统一设备协议编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
}
|
|
|
|
deviceVo.setCreateTime(DateTimeHelper.getNowDate());
|
|
deviceVo.setUpdateTime(DateTimeHelper.getNowDate());
|
|
int num4=mapper.insertDevice(deviceVo);
|
|
if(num4<1){
|
|
returnCodeEntity.setMsg("添加失败,请联系管理员");
|
|
returnCodeEntity.setCode("202");
|
|
return returnCodeEntity;
|
|
}else{
|
|
returnCodeEntity.setMsg("添加成功");
|
|
returnCodeEntity.setCode("200");
|
|
return returnCodeEntity;
|
|
}
|
|
}catch (Exception e){
|
|
returnCodeEntity.setMsg("网络异常,请稍后重试");
|
|
returnCodeEntity.setCode("203");
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
@Override
|
|
public ReturnCodeEntity updateDevice(DeviceVo deviceVo) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
int num=mapper.getNumByMacId(deviceVo);
|
|
if(num>0){
|
|
returnCodeEntity.setMsg("设备mac编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num2=mapper.getNumByPuId(deviceVo);
|
|
if(num2>0){
|
|
returnCodeEntity.setMsg("puid已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num3=mapper.getNumByGbCode(deviceVo);
|
|
if(num3>0){
|
|
returnCodeEntity.setMsg("国标编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
if("1".equals(deviceVo.getIst())){
|
|
|
|
int num4=mapper.getNumByTcode(deviceVo);
|
|
if(num4>0){
|
|
returnCodeEntity.setMsg("统一视频编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
Pattern pattern =Pattern.compile("[0-9]*");
|
|
if(!pattern.matcher(deviceVo.gettCode()).matches()){
|
|
returnCodeEntity.setMsg("统一编码格式不正确");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
|
|
}else{
|
|
if(deviceVo.gettCode().length()!=18){
|
|
returnCodeEntity.setMsg("统一编码格式不正确");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
}
|
|
int num5=mapper.getNumByTWcode(deviceVo);
|
|
if(num5>0){
|
|
returnCodeEntity.setMsg("统一前端协议编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
int num6=mapper.getNumByTDcode(deviceVo);
|
|
if(num6>0){
|
|
returnCodeEntity.setMsg("统一设备协议编码已存在");
|
|
returnCodeEntity.setCode("201");
|
|
return returnCodeEntity;
|
|
}
|
|
}
|
|
|
|
deviceVo.setUpdateTime(DateTimeHelper.getNowDate());
|
|
int num4=mapper.updateDevice(deviceVo);
|
|
if(num4<1){
|
|
returnCodeEntity.setMsg("修改失败,请联系管理员");
|
|
returnCodeEntity.setCode("202");
|
|
return returnCodeEntity;
|
|
}else{
|
|
returnCodeEntity.setMsg("修改成功");
|
|
returnCodeEntity.setCode("200");
|
|
return returnCodeEntity;
|
|
}
|
|
}catch (Exception e){
|
|
returnCodeEntity.setMsg("网络异常,请稍后重试");
|
|
returnCodeEntity.setCode("203");
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
@Override
|
|
public ReturnCodeEntity deleteDevice(String keyId) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
int num=mapper.deleteDevice(keyId);
|
|
if(num<1){
|
|
returnCodeEntity.setMsg("删除失败,请联系管理员");
|
|
returnCodeEntity.setCode("202");
|
|
return returnCodeEntity;
|
|
}else{
|
|
returnCodeEntity.setMsg("删除成功");
|
|
returnCodeEntity.setCode("200");
|
|
return returnCodeEntity;
|
|
}
|
|
}catch (Exception e){
|
|
returnCodeEntity.setMsg("网络异常,请稍后重试");
|
|
returnCodeEntity.setCode("203");
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
@Override
|
|
public DeviceVo getDeviceDetail(String keyId) {
|
|
try{
|
|
DeviceVo entity=mapper.getDeviceDetail(keyId);
|
|
return entity;
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
return new DeviceVo();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param list
|
|
*/
|
|
@Override
|
|
public void addImportData(List<DeviceVo> list) {
|
|
mapper.addImportData(list);
|
|
}
|
|
|
|
/**
|
|
* 刷新设备状态
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity refresh() {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
refreshQXDevice();
|
|
returnCodeEntity.setCode("200");
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
/**
|
|
* 重置设备状态都是在线
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity refreshDevice() {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
mapper.refreshDevice();
|
|
returnCodeEntity.setCode("200");
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
/**
|
|
* 球机守望位置
|
|
* @param puid
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity setSwwzConfig(String puid) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
|
|
Map<String, Object> map= configUtil.getMaps();
|
|
String url= configUtil.getUrl();
|
|
String xml= PostXml.getSwwzXmlData();
|
|
String returnXml= QxVideotape.setSwWzConfig(puid,xml,map,url);
|
|
String msg = PostXml.getSetConfig(returnXml);
|
|
returnCodeEntity.setCode("200");
|
|
returnCodeEntity.setMsg(msg);
|
|
}catch (Exception e){
|
|
returnCodeEntity.setCode("400");
|
|
returnCodeEntity.setMsg("指令发送异常");
|
|
log.error(e.toString(),e);
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
/**
|
|
* 去往球机守望位置
|
|
* @param puid
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity gotoSwwzConfig(String puid) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
Map<String, Object> map= configUtil.getMaps();
|
|
String url= configUtil.getUrl();
|
|
String xml= PostXml.getToSwwzConfig();
|
|
String returnXml= QxVideotape.setSwWzConfig(puid,xml,map,url);
|
|
String msg = PostXml.getSetConfig(returnXml);//解析操作
|
|
returnCodeEntity.setCode("200");
|
|
returnCodeEntity.setMsg("执行成功");
|
|
}catch (Exception e){
|
|
returnCodeEntity.setCode("400");
|
|
returnCodeEntity.setMsg("指令发送异常");
|
|
log.error(e.toString(),e);
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
/**
|
|
* 获取守望位置信息
|
|
* @param vo
|
|
* @return
|
|
*/
|
|
@Override
|
|
public BallSwHGVo getSwwzData(BallSwHGVo vo) {
|
|
try{
|
|
Map<String, Object> map= configUtil.getMaps();
|
|
String url= configUtil.getUrl();
|
|
String puid=vo.getPuid();
|
|
String xml= PostXml.getZDHGConfig();//获取自动回归配置
|
|
String returnXml= QxVideotape.setSwWzConfig(puid,xml,map,url);//如果不支持 则返回0
|
|
Integer msg = PostXml.getConfigDataValue(returnXml);//解析操作
|
|
vo.setKq(msg);//自动回归是否开启
|
|
|
|
String xml2= PostXml.getHGTime();//获取自动回归配置
|
|
String returnXml2= QxVideotape.setSwWzConfig(puid,xml2,map,url);//如果不支持 则返回0
|
|
Integer msg2 = PostXml.getConfigDataValue(returnXml2);//解析操作
|
|
vo.setTime(msg2);// 自动回归时间
|
|
}catch (Exception e){
|
|
vo.setKq(0);//自动回归是否开启
|
|
vo.setTime(0);// 自动回归时间
|
|
log.error(e.toString(),e);
|
|
}
|
|
return vo;
|
|
}
|
|
|
|
@Override
|
|
public BallSwHGVo setSwwzData(BallSwHGVo vo) {
|
|
try{
|
|
Map<String, Object> map= configUtil.getMaps();
|
|
String url= configUtil.getUrl();
|
|
String puid=vo.getPuid();
|
|
String xml= PostXml.setZDHGConfig(vo.getKq());//获取自动回归配置
|
|
String returnXml= QxVideotape.setSwWzConfig(puid,xml,map,url);//如果不支持 则返回0
|
|
String msg = PostXml.getSetConfig(returnXml);//解析操作
|
|
vo.setMsg(msg);//设置开启是否成功
|
|
|
|
String xml2= PostXml.setHGTime(vo.getTime());//获取自动回归配置
|
|
String returnXml2= QxVideotape.setSwWzConfig(puid,xml2,map,url);//如果不支持 则返回0
|
|
String msg2 = PostXml.getSetConfig(returnXml2);//解析操作
|
|
vo.setMsg(msg2);// 设置回归时间是否成功
|
|
vo.setCode("200");
|
|
}catch (Exception e){
|
|
vo.setCode("400");
|
|
vo.setMsg("设置失败,球机未升级");// 自动回归时间
|
|
log.error(e.toString(),e);
|
|
}
|
|
return vo;
|
|
}
|
|
|
|
/**
|
|
* 查询前端初始化数据
|
|
* @return
|
|
*/
|
|
@Override
|
|
public SysVideoConfigVo getVideoConfig() {
|
|
SysVideoConfigVo vo=new SysVideoConfigVo();
|
|
try{
|
|
List<SysVideoConfigVo> list=mapper.getVideoConfigByType("1");
|
|
if(ListHelper.isEmpty(list)){
|
|
return configUtil.getConfigData();
|
|
}
|
|
return list.get(0);
|
|
}catch (Exception e){
|
|
vo=configUtil.getConfigData();
|
|
log.error(e.toString(),e);
|
|
}
|
|
return vo;
|
|
}
|
|
|
|
/**
|
|
* 更新设备状态
|
|
* @param deviceVo
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity updateDeviceState(DeviceVo deviceVo) {
|
|
ReturnCodeEntity returnCodeEntity=new ReturnCodeEntity();
|
|
try{
|
|
String puid=deviceVo.getPuId();
|
|
String state=deviceVo.getState();
|
|
String[] puids=puid.split(",");
|
|
for (String str:puids) {
|
|
mapper.updateDeviceState(str,state);
|
|
}
|
|
returnCodeEntity.setCode("200");
|
|
returnCodeEntity.setMsg("更新成功");
|
|
}catch (Exception e){
|
|
returnCodeEntity.setCode("201");
|
|
returnCodeEntity.setMsg("更新失败");
|
|
log.error(e.toString(),e);
|
|
}
|
|
return returnCodeEntity;
|
|
}
|
|
|
|
|
|
/**
|
|
* 统一视频状态刷新
|
|
*/
|
|
public void refreshTYDevice(){
|
|
try{
|
|
List<String> tCodes= mapper.getAllTyDeviceList();
|
|
if(ListHelper.isNotEmpty(tCodes)){
|
|
List<String> params=new ArrayList<>();
|
|
for (String tCode:tCodes) {
|
|
params.add(tCode);
|
|
int size=params.size();
|
|
if(size%40==0){
|
|
getDeviceList(params);
|
|
params=new ArrayList<>();
|
|
}
|
|
}
|
|
getDeviceList(params);
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
|
|
}
|
|
public void getDeviceList( List<String> params){
|
|
if(ListHelper.isEmpty(params)){
|
|
return ;
|
|
}
|
|
try{
|
|
List<ResultValue> list=TyVideoUtil.getDeviceList(params);
|
|
for (ResultValue res: list) {
|
|
try{
|
|
mapper.refreshTyDevice(res);
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
public void refreshQXDevice(){
|
|
try{
|
|
List<String> puids= mapper.getAllDeviceList();
|
|
if(ListHelper.isNotEmpty(puids)) {
|
|
List<String> puid=new ArrayList<>();
|
|
int j=1;
|
|
for (int i = 0; i <puids.size() ; i++) {
|
|
puid.add(puids.get(i));//加入
|
|
if(j%50==0){
|
|
getBallStatus(puid);//查询状态
|
|
puid.clear();//清空
|
|
}
|
|
j++;
|
|
}
|
|
getBallStatus(puid);//不足的最后执行一次
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
public void getBallStatus(List<String> puids){
|
|
try{
|
|
Map<String, Object> map= configUtil.getMaps();
|
|
String url= configUtil.getUrl();
|
|
String token = QxVideotape.login(map,url);
|
|
List<ReturnDataEntity> data = QxVideotape.getBallStatuss(puids, token,url);
|
|
if (ListHelper.isNotEmpty(data)) {
|
|
for (ReturnDataEntity vo : data) {
|
|
try {
|
|
mapper.refreshQXDevice(vo);
|
|
} catch (Exception e) {
|
|
log.error(e.toString(), e);
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
}
|