diff --git a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java index 3f60d19..90aa5a8 100644 --- a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java +++ b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java @@ -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 1开启,2关闭 + */ + 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 getLightSource(){ return lightSourceMapper.selectByMap(new HashMap<>());