no message

泸州-视觉+扫码-昆船
LAPTOP-S9HJSOEB\昊天 2 years ago
parent 569af10f66
commit beaba8206d

@ -1,19 +1,101 @@
package com.zhehekeji.web.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.LightSource;
import com.zhehekeji.web.mapper.LightSourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhehekeji.web.service.damLightSource.JYDAMEquip;
import com.zhehekeji.web.service.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
import com.zhehekeji.web.service.light.RelaySource;
import com.zhehekeji.web.service.light.damLightSource.JYDAMEquip;
import com.zhehekeji.web.service.light.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.light.hikLightSource.HikControlSocket;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
@Service
public class LightSourceService {
@Autowired
@Resource
private LightSourceMapper lightSourceMapper;
public static void lightControllerFactory(ConfigProperties.LightSource lightSource,LightSource lightInfo, Integer stat){
if(lightSource.getType() == 1){
JYDAMEquip equip = JYDamHelper.Connect(lightInfo.getIp(),lightInfo.getPort());
if(stat == 1) {
JYDamHelper.openDO(equip, lightSource.getIndex());
}else JYDamHelper.closeDO(equip, lightSource.getIndex());
//暂时关闭灯源状态查询
/*Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex());
log.info("ip:{},status:{}",lightSource.getIp(),status);*/
equip.DisConnect();
}else if(lightSource.getType() == 2){
HikControlSocket.lightController(lightInfo.getIp(),lightInfo.getPort(),lightSource.getIndex(),stat);
}else if (lightSource.getType() == 3){
LightSourceService.lightController(lightInfo.getIp(),lightInfo.getPort(),stat);
}else if (lightSource.getType() == 4){
RelaySource.lightController(lightInfo.getIp(),lightInfo.getPort(),stat);
}
}
/**
*
* @param ip
* @param port
* @param stat 12
*/
public static void lightController(String ip ,Integer port,Integer stat){
Socket socket = new Socket();
OutputStream os = null;
InputStream is = null;
try {
socket.connect(new InetSocketAddress(ip,port),3000);
os = socket.getOutputStream();
is = socket.getInputStream();
int i = 0;
socket.setSoTimeout(1000);
String startCmd = "<1,"+stat+",post>";
byte[]bytes = startCmd.getBytes(StandardCharsets.UTF_8);
os.write(bytes);
} catch (IOException e) {
}finally {
if(os != null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(is != null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public List<LightSource> getLightSource(){
return lightSourceMapper.selectByMap(new HashMap<>());

Loading…
Cancel
Save