diff --git a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java index aa1e52b..3119a7f 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java @@ -10,6 +10,8 @@ import com.zhehekeji.web.pojo.street.StreetSearch; import com.zhehekeji.web.pojo.street.StreetVO; import com.zhehekeji.web.service.LightSourceService; import com.zhehekeji.web.service.StreetService; +import com.zhehekeji.web.service.client.ClientChanel; +import com.zhehekeji.web.service.client.LCTransmission; import com.zhehekeji.web.service.damLightSource.JYDAMEquip; import com.zhehekeji.web.service.damLightSource.JYDamHelper; import com.zhehekeji.web.service.hikLightSource.HikControlSocket; @@ -81,87 +83,38 @@ public class StreetController { @GetMapping("/lightSource/open") @ApiOperation(value = "开启光源") public Result openLightSource(){ - List lightSources = lightSourceService.getLightSource(); - - lightSources.forEach(lightSource -> { - JSONObject obj = JSONObject.parseObject(configProperties.getLightSource().getInfo()); - if(configProperties.getLightSource().getType() == 1){ - - JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); - JYDamHelper.openDO(equip,configProperties.getLightSource().getIndex()); - Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); - log.info("ip:{},status:{}",lightSource.getIp(),status); - equip.DisConnect(); - - }else if(configProperties.getLightSource().getType() == 2){ - HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1); - } - + ClientChanel.keys().forEach(k->{ + LCTransmission lcTransmission = new LCTransmission(k,1); + ClientChanel.write(lcTransmission.toString(),k); }); - return Result.success(); } @GetMapping("/lightSource/close") @ApiOperation(value = "关闭光源") public Result closeLightSource(){ - - List lightSources = lightSourceService.getLightSource(); - - lightSources.forEach(lightSource -> { - JSONObject obj = JSONObject.parseObject(configProperties.getLightSource().getInfo()); - if(configProperties.getLightSource().getType() == 1){ - - JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); - JYDamHelper.closeDO(equip,obj.getInteger("index")); - Integer status = JYDamHelper.ReadStatus(equip,obj.getInteger("num"),obj.getInteger("index")); - log.info("ip:{},status:{}",lightSource.getIp(),status); - }else if(configProperties.getLightSource().getType() == 2){ - HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); - } - + ClientChanel.keys().forEach(k->{ + LCTransmission lcTransmission = new LCTransmission(k,0); + ClientChanel.write(lcTransmission.toString(),k); }); - return Result.success(); } @GetMapping("/lightSource/open/{streetId}") @ApiOperation(value = "开启单个巷道光源") public Result openStreetLightSource(@PathVariable Integer streetId){ - List lightSources = lightSourceService.getLightSourceByStreetId(streetId); - lightSources.forEach(lightSource -> { - if(configProperties.getLightSource().getType() == 1){ - JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); - JYDamHelper.openDO(equip,configProperties.getLightSource().getIndex()); - Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); - log.info("ip:{},status:{}",lightSource.getIp(),status); - equip.DisConnect(); - }else if(configProperties.getLightSource().getType() == 2){ - HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1); - } - - }); - + Street street = streetService.streetById(streetId); + LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),1); + ClientChanel.write(lcTransmission.toString(),street.getPlcId()); return Result.success(); } @GetMapping("/lightSource/close/{streetId}") @ApiOperation(value = "关闭单个巷道光源") public Result closeStreetLightSource(@PathVariable Integer streetId){ - List lightSources = lightSourceService.getLightSourceByStreetId(streetId); - lightSources.forEach(lightSource -> { - if(configProperties.getLightSource().getType() == 1){ - JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort()); - JYDamHelper.closeDO(equip,configProperties.getLightSource().getIndex()); - Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex()); - log.info("ip:{},status:{}",lightSource.getIp(),status); - equip.DisConnect(); - }else if(configProperties.getLightSource().getType() == 2){ - HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); - } - - }); - + Street street = streetService.streetById(streetId); + LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),0); + ClientChanel.write(lcTransmission.toString(),street.getPlcId()); return Result.success(); } diff --git a/web/src/main/java/com/zhehekeji/web/service/client/ClientChanel.java b/web/src/main/java/com/zhehekeji/web/service/client/ClientChanel.java index 11a110b..39ae41c 100644 --- a/web/src/main/java/com/zhehekeji/web/service/client/ClientChanel.java +++ b/web/src/main/java/com/zhehekeji/web/service/client/ClientChanel.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * 所有的客户端的chanel @@ -23,6 +24,7 @@ public class ClientChanel { */ private static Map channelMap = new HashMap<>(); + /** * key :IP * value: 巷道标识符 @@ -61,6 +63,11 @@ public class ClientChanel { public static void disConnect(String key){ channelMap.remove(key); + + } + + public static Set keys(){ + return channelMap.keySet(); } public static Channel get(String key){ diff --git a/web/src/main/java/com/zhehekeji/web/service/client/LCTransmission.java b/web/src/main/java/com/zhehekeji/web/service/client/LCTransmission.java new file mode 100644 index 0000000..29f5907 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/client/LCTransmission.java @@ -0,0 +1,34 @@ +package com.zhehekeji.web.service.client; + + +import lombok.Data; + +@Data +/** + * 开关灯 + */ +public class LCTransmission { + + private static String HEADER = "LC"; + + private String SRMNumber; + + /** + * 1:开 0:关 + */ + private Integer status; + + public String toString(){ + return HEADER + "," + SRMNumber+","+status; + } + + public static String getHEADER(){ + return HEADER; + } + + public LCTransmission(String SRMNumber,Integer status){ + this.SRMNumber = SRMNumber; + this.status = status; + } + +}