灯光控制

nanjing-yancao-wuliuzhongxin
yiming 3 years ago
parent b1f871a74b
commit 12272a6ea8

@ -10,6 +10,8 @@ import com.zhehekeji.web.pojo.street.StreetSearch;
import com.zhehekeji.web.pojo.street.StreetVO; import com.zhehekeji.web.pojo.street.StreetVO;
import com.zhehekeji.web.service.LightSourceService; import com.zhehekeji.web.service.LightSourceService;
import com.zhehekeji.web.service.StreetService; 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.JYDAMEquip;
import com.zhehekeji.web.service.damLightSource.JYDamHelper; import com.zhehekeji.web.service.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.hikLightSource.HikControlSocket; import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
@ -81,87 +83,38 @@ public class StreetController {
@GetMapping("/lightSource/open") @GetMapping("/lightSource/open")
@ApiOperation(value = "开启光源") @ApiOperation(value = "开启光源")
public Result openLightSource(){ public Result openLightSource(){
List<LightSource> lightSources = lightSourceService.getLightSource(); ClientChanel.keys().forEach(k->{
LCTransmission lcTransmission = new LCTransmission(k,1);
lightSources.forEach(lightSource -> { ClientChanel.write(lcTransmission.toString(),k);
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);
}
}); });
return Result.success(); return Result.success();
} }
@GetMapping("/lightSource/close") @GetMapping("/lightSource/close")
@ApiOperation(value = "关闭光源") @ApiOperation(value = "关闭光源")
public Result closeLightSource(){ public Result closeLightSource(){
ClientChanel.keys().forEach(k->{
List<LightSource> lightSources = lightSourceService.getLightSource(); LCTransmission lcTransmission = new LCTransmission(k,0);
ClientChanel.write(lcTransmission.toString(),k);
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);
}
}); });
return Result.success(); return Result.success();
} }
@GetMapping("/lightSource/open/{streetId}") @GetMapping("/lightSource/open/{streetId}")
@ApiOperation(value = "开启单个巷道光源") @ApiOperation(value = "开启单个巷道光源")
public Result openStreetLightSource(@PathVariable Integer streetId){ public Result openStreetLightSource(@PathVariable Integer streetId){
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId); Street street = streetService.streetById(streetId);
lightSources.forEach(lightSource -> { LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),1);
if(configProperties.getLightSource().getType() == 1){ ClientChanel.write(lcTransmission.toString(),street.getPlcId());
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);
}
});
return Result.success(); return Result.success();
} }
@GetMapping("/lightSource/close/{streetId}") @GetMapping("/lightSource/close/{streetId}")
@ApiOperation(value = "关闭单个巷道光源") @ApiOperation(value = "关闭单个巷道光源")
public Result closeStreetLightSource(@PathVariable Integer streetId){ public Result closeStreetLightSource(@PathVariable Integer streetId){
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId); Street street = streetService.streetById(streetId);
lightSources.forEach(lightSource -> { LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),0);
if(configProperties.getLightSource().getType() == 1){ ClientChanel.write(lcTransmission.toString(),street.getPlcId());
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);
}
});
return Result.success(); return Result.success();
} }

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* chanel * chanel
@ -23,6 +24,7 @@ public class ClientChanel {
*/ */
private static Map<String, Channel> channelMap = new HashMap<>(); private static Map<String, Channel> channelMap = new HashMap<>();
/** /**
* key :IP * key :IP
* value: * value:
@ -61,6 +63,11 @@ public class ClientChanel {
public static void disConnect(String key){ public static void disConnect(String key){
channelMap.remove(key); channelMap.remove(key);
}
public static Set<String> keys(){
return channelMap.keySet();
} }
public static Channel get(String key){ public static Channel get(String key){

@ -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;
}
}
Loading…
Cancel
Save