|
@@ -0,0 +1,111 @@
|
|
|
+package com.bz.smart_city.service.udip;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.bz.smart_city.commom.exception.ServiceException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 互联互通
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class HlhtService {
|
|
|
+
|
|
|
+ private RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新水表电子号
|
|
|
+ * @param eleno 水表电子号
|
|
|
+ * @param metercode 水表档案号
|
|
|
+ */
|
|
|
+ public Boolean updatePayMeterEleno(String eleno,String metercode){
|
|
|
+ log.info("begin updatePayMeterEleno");
|
|
|
+ Boolean syncStatus = false;
|
|
|
+ if (metercode != null && !StringUtils.equals("",metercode)) {
|
|
|
+ //String url ="http://192.168.0.170:8089/HuaxuIswaterV1.1/Archives/updatePayMeterEleno";
|
|
|
+ String url ="http://183.62.175.140:9182/HuaxuIswaterV1.1/Archives/updatePayMeterEleno";
|
|
|
+ JSONObject postData = new JSONObject();
|
|
|
+ postData.put("eleno", eleno);
|
|
|
+ postData.put("metercode", metercode);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, postData, String.class);
|
|
|
+ log.info("responseEntity : {}", JSON.toJSONString(responseEntity));
|
|
|
+ if (responseEntity != null && responseEntity.getStatusCode()== HttpStatus.OK) {
|
|
|
+ //String result = (String) responseEntity.getBody();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ log.info("result : {}", jsonObject);
|
|
|
+
|
|
|
+ String succ = jsonObject.getString("succ");
|
|
|
+ if (StringUtils.equals(succ,"0")){
|
|
|
+ syncStatus = true;
|
|
|
+ log.info("success");
|
|
|
+ }else {
|
|
|
+ log.info("fail");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("request error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("end updatePayMeterEleno");
|
|
|
+ return syncStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 换表
|
|
|
+ * @param metercode 水表档案号
|
|
|
+ * @param oldStartcount 旧表起度
|
|
|
+ * @param newStartcount 新表起度
|
|
|
+ * @param newEleno 新表电子号
|
|
|
+ * @param oldEleno 旧表电子号
|
|
|
+ */
|
|
|
+ public Boolean equipmentMeter(String metercode,String oldStartcount,String newStartcount,String newEleno,String oldEleno){
|
|
|
+ log.info("begin equipmentMeter");
|
|
|
+ Boolean syncStatus = false;
|
|
|
+ if (metercode != null && !StringUtils.equals("",metercode)) {
|
|
|
+ //String url ="http://192.168.0.170:8089/HuaxuIswaterV1.1/Archives/equipmentMeter";
|
|
|
+ String url ="http://183.62.175.140:9182/HuaxuIswaterV1.1/Archives/equipmentMeter";
|
|
|
+ JSONObject postData = new JSONObject();
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ postData.put("replacedate", LocalDateTime.now().format(df));//换表时间(yyyy-MM-dd HH:mm:ss)
|
|
|
+ postData.put("metercode", metercode);
|
|
|
+ postData.put("oldStartcount", oldStartcount);
|
|
|
+ postData.put("newStartcount", newStartcount);
|
|
|
+ postData.put("newEleno", newEleno);
|
|
|
+ postData.put("oldEleno", oldEleno);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, postData, String.class);
|
|
|
+ log.info("responseEntity : {}", JSON.toJSONString(responseEntity));
|
|
|
+ if (responseEntity != null && responseEntity.getStatusCode()== HttpStatus.OK) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ log.info("result : {}", jsonObject);
|
|
|
+ String succ = jsonObject.getString("succ");
|
|
|
+ JSONArray meterList = jsonObject.getJSONArray("meterList");
|
|
|
+ JSONObject meter = meterList.getJSONObject(0);
|
|
|
+ if (meter != null) {
|
|
|
+ String result = meter.getString("result");
|
|
|
+ String msg = meter.getString("msg");
|
|
|
+ if (StringUtils.equals(result,"0")){
|
|
|
+ syncStatus = true;
|
|
|
+ log.info("success");
|
|
|
+ }else {
|
|
|
+ throw new ServiceException(-999, msg);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info("meter fail");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("request error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("end equipmentMeter");
|
|
|
+ return syncStatus;
|
|
|
+ }
|
|
|
+}
|