|
@@ -1271,7 +1271,8 @@ public class DeviceServiceImpl implements DeviceService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void setValveV2(Long deviceId, String valve) {
|
|
|
+ public Boolean setValveV2(Long deviceId, String valve) {
|
|
|
+ log.info("setValveV2 deviceId={} valve={}",deviceId,valve);
|
|
|
Device device = deviceMapper.findByDeviceId(deviceId);
|
|
|
DeviceTypeDto deviceTypeDto = deviceTypeMapper.getById(device.getDeviceType());
|
|
|
|
|
@@ -1279,56 +1280,89 @@ public class DeviceServiceImpl implements DeviceService {
|
|
|
valveCommandRequest.setValveStatus(valve);
|
|
|
|
|
|
//1、执行开关阀门
|
|
|
- executeValveCommand(device,deviceTypeDto,valveCommandRequest);
|
|
|
+ Boolean executeResult = executeValveCommand(device,deviceTypeDto,valveCommandRequest);
|
|
|
+
|
|
|
+ //2、更换阀门按钮状态
|
|
|
+ if(executeResult) replaceValveButtonStatus(deviceId,valve);
|
|
|
+
|
|
|
+ return executeResult;
|
|
|
}
|
|
|
|
|
|
- private void executeValveCommand(Device device,DeviceTypeDto deviceTypeDto,ValveCommandRequestDTO valveCommandRequest){
|
|
|
+ private void replaceValveButtonStatus(Long deviceId, String valve){
|
|
|
+ WaterMeterErrorDays waterMeterErrorDays = waterMeterErrorDaysMapper.findByDeviceId(deviceId);
|
|
|
+ Integer valveButtonStatus = 0;
|
|
|
+ if("1".equals(valve))valveButtonStatus = 1;
|
|
|
+
|
|
|
+ if (waterMeterErrorDays != null) {
|
|
|
+ waterMeterErrorDays.setValveButtonStatus(valveButtonStatus);
|
|
|
+ waterMeterErrorDays.setDateUpdate(LocalDateTime.now());
|
|
|
+ waterMeterErrorDaysMapper.updateByPrimaryKeySelective(waterMeterErrorDays);
|
|
|
+ }else {
|
|
|
+ waterMeterErrorDays = new WaterMeterErrorDays();
|
|
|
+ waterMeterErrorDays.setDeviceId(deviceId);
|
|
|
+ waterMeterErrorDays.setValveButtonStatus(valveButtonStatus);
|
|
|
+ waterMeterErrorDaysMapper.insert(waterMeterErrorDays);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean executeValveCommand(Device device,DeviceTypeDto deviceTypeDto,ValveCommandRequestDTO valveCommandRequest){
|
|
|
+
|
|
|
+ String commandId = null;
|
|
|
+ Integer sendValveStatus = Integer.valueOf(valveCommandRequest.getValveStatus());
|
|
|
+ String commandStatus = null;
|
|
|
+ String remark = "";
|
|
|
+ Boolean executeResult = false;
|
|
|
+ JSONObject commandResult = null;
|
|
|
+
|
|
|
if(StringUtils.equals("lora188",deviceTypeDto.getEnModel())){
|
|
|
valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
easylinkinUtils.sendDownlink(device.getDeviceNo(),valveCommandRequest);
|
|
|
+ executeResult = true;
|
|
|
}else if(StringUtils.equals("hxgd",deviceTypeDto.getEnModel()))
|
|
|
{
|
|
|
valveCommandRequest.setMeterCode(String.valueOf(device.getId()));
|
|
|
gdAgentUtils.setMeterValve(valveCommandRequest);
|
|
|
+ executeResult = true;
|
|
|
}
|
|
|
else if(StringUtils.equals("hengxin-nb",deviceTypeDto.getEnModel()))
|
|
|
{
|
|
|
valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
- udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
}
|
|
|
else if(StringUtils.equals("ningbo-nb",deviceTypeDto.getEnModel()))
|
|
|
{
|
|
|
valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
- JSONObject commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
-
|
|
|
- //2、插入开关阀门记录
|
|
|
- DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
|
|
|
- deviceValveRecord.setDeviceId(device.getId());
|
|
|
- deviceValveRecord.setSendValveStatus(Integer.valueOf(valveCommandRequest.getValveStatus()));
|
|
|
- deviceValveRecord.setSendStatus(1);
|
|
|
- deviceValveRecord.setCommandId(commandResult.getString("commandId"));
|
|
|
- deviceValveRecord.setRemark("");
|
|
|
- deviceValveRecordService.insertSelective(deviceValveRecord);
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
}else if(StringUtils.equals("NB-TJ2.0",deviceTypeDto.getEnModel()))
|
|
|
{
|
|
|
if (device.getUdipId() != null && !"".equals(device.getUdipId())) {
|
|
|
valveCommandRequest.setMeterCode(device.getDeviceNo());
|
|
|
- JSONObject commandResult = udipEtlDataCommandService.commandSend(device.getUdipId(),valveCommandRequest);
|
|
|
-
|
|
|
- //2、插入开关阀门记录
|
|
|
- DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
|
|
|
- deviceValveRecord.setDeviceId(device.getId());
|
|
|
- deviceValveRecord.setSendValveStatus(Integer.valueOf(valveCommandRequest.getValveStatus()));
|
|
|
- deviceValveRecord.setSendStatus(1);
|
|
|
- deviceValveRecord.setCommandId(commandResult.getString("commandId"));
|
|
|
- deviceValveRecord.setCommandStatus(commandResult.getString("status"));
|
|
|
- deviceValveRecord.setRemark("");
|
|
|
- deviceValveRecordService.insertSelective(deviceValveRecord);
|
|
|
+ commandResult = udipEtlDataCommandService.commandSend(device.getUdipId(),valveCommandRequest);
|
|
|
}
|
|
|
}else {
|
|
|
valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
- udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (commandResult != null) {
|
|
|
+ commandId = commandResult.getString("commandId");
|
|
|
+ commandStatus = commandResult.getString("status");
|
|
|
+ //判断指令执成功
|
|
|
+ if (commandId != null && !"".equals(commandId)) executeResult = true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //1、插入开关阀门记录
|
|
|
+ DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
|
|
|
+ deviceValveRecord.setDeviceId(device.getId());
|
|
|
+ deviceValveRecord.setSendValveStatus(sendValveStatus);
|
|
|
+ deviceValveRecord.setSendStatus(1);
|
|
|
+ deviceValveRecord.setCommandId(commandId);
|
|
|
+ deviceValveRecord.setCommandStatus(commandStatus);
|
|
|
+ deviceValveRecord.setRemark(remark);
|
|
|
+ deviceValveRecordService.insertSelective(deviceValveRecord);
|
|
|
+
|
|
|
+ return executeResult;
|
|
|
}
|
|
|
|
|
|
@Override
|