|
@@ -7,6 +7,7 @@ import com.bz.smart_city.commom.util.HttpClientUtils;
|
|
|
import com.bz.smart_city.commom.util.HttpRequest;
|
|
|
import com.bz.smart_city.dto.DeviceTypeDto;
|
|
|
import com.bz.smart_city.dto.UdipUnitDTO;
|
|
|
+import com.bz.smart_city.dto.ValveCommandRequestDTO;
|
|
|
import com.bz.smart_city.dto.udip.DataCommandRequestDTO;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -15,6 +16,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -24,7 +28,53 @@ public class UdipEtlDataCommandService {
|
|
|
@Autowired
|
|
|
ObjectMapper objectMapper;
|
|
|
|
|
|
- public JSONObject commandSend(DataCommandRequestDTO dataCommandRequest){
|
|
|
+ public JSONObject commandSend(String udipId, ValveCommandRequestDTO valveCommandRequest){
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("electronicNo","AAAAAAAAAAAAAA");
|
|
|
+ map.put("valveStatus", valveCommandRequest.getValveStatus());//阀门状态 0:关阀 1:开阀
|
|
|
+ DataCommandRequestDTO dataCommandRequest = new DataCommandRequestDTO();
|
|
|
+ dataCommandRequest.setDeviceId(udipId);
|
|
|
+ dataCommandRequest.setUnitIdentifier(valveCommandRequest.getMeterCode());
|
|
|
+ dataCommandRequest.setReceiveTime(new Date());
|
|
|
+ dataCommandRequest.setMethod("WriteValve");
|
|
|
+ dataCommandRequest.setParams(map);
|
|
|
+
|
|
|
+ String url = unitUrl+"/center/command/send";
|
|
|
+ try {
|
|
|
+ String json = objectMapper.writeValueAsString(dataCommandRequest);
|
|
|
+ log.info("udipUnit json:"+ json);
|
|
|
+ //String result = HttpRequest.doPost(url, JSON.toJSONString(json));
|
|
|
+ String result = HttpClientUtils.doPostWithJson(url, json);
|
|
|
+ log.info("msg result=" + result);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer status = jsonObject.getInteger("status");
|
|
|
+ if(status == 0){
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ //return data.getString("commandId");
|
|
|
+ return data;
|
|
|
+ }else {
|
|
|
+ log.debug(jsonObject.getString("msg"));
|
|
|
+ throw new ServiceException(-900, jsonObject.getString("msg"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.debug(e.getMessage());
|
|
|
+ throw new ServiceException(-900, "下发指令错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject commandSendV2(String udipId, ValveCommandRequestDTO valveCommandRequest){
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("meterCode",valveCommandRequest.getMeterCode());
|
|
|
+ map.put("valveStatus", valveCommandRequest.getValveStatus());//阀门状态 0:关阀 1:开阀
|
|
|
+ DataCommandRequestDTO dataCommandRequest = new DataCommandRequestDTO();
|
|
|
+ dataCommandRequest.setDeviceId(udipId);
|
|
|
+ dataCommandRequest.setUnitIdentifier(valveCommandRequest.getMeterCode());
|
|
|
+ dataCommandRequest.setReceiveTime(new Date());
|
|
|
+ dataCommandRequest.setMethod("WriteValve");
|
|
|
+ dataCommandRequest.setParams(map);
|
|
|
+
|
|
|
String url = unitUrl+"/center/command/send";
|
|
|
try {
|
|
|
String json = objectMapper.writeValueAsString(dataCommandRequest);
|
|
@@ -47,4 +97,5 @@ public class UdipEtlDataCommandService {
|
|
|
throw new ServiceException(-900, "下发指令错误");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|