litianbiao 2 years ago
parent
commit
2e54324ac6

+ 16 - 0
pom.xml

@@ -236,6 +236,22 @@
 			<artifactId>spring-boot-starter-test</artifactId>
 			<scope>test</scope>
 		</dependency>
+		<!--elasticsearch-->
+		<dependency>
+			<groupId>org.elasticsearch</groupId>
+			<artifactId>elasticsearch</artifactId>
+			<version>7.6.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.elasticsearch.client</groupId>
+			<artifactId>elasticsearch-rest-high-level-client</artifactId>
+			<version>7.6.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.elasticsearch.client</groupId>
+			<artifactId>elasticsearch-rest-client</artifactId>
+			<version>7.6.2</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 28 - 0
src/main/java/com/szwl/controller/IndexController.java

@@ -1,6 +1,7 @@
 package com.szwl.controller;
 
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -13,6 +14,7 @@ import com.szwl.model.bo.JsonUtils;
 import com.szwl.model.bo.R;
 import com.szwl.model.entity.*;
 import com.szwl.model.utils.AdminUtils;
+import com.szwl.model.utils.HttpClientSslUtils;
 import com.szwl.model.utils.PushUtils;
 import com.szwl.service.*;
 import com.szwl.service.es.EsTEquipmentService;
@@ -1839,10 +1841,36 @@ public class IndexController { ;
             TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
             equipmentDesc.setCouponStatus(couponStatus);
             equipmentDescService.updateById(equipmentDesc);
+            TAdmin admin = adminService.getById(equipment.getAdminId());
+            //同步数据到鲸准
+            if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")) {
+                sendCouponStatus(clientId,equipment.getFullName(),equipment.getEqeStatus(),couponStatus);
+            }
             return "success";
         }
         return "error";
     }
+
+    private void sendCouponStatus(String clientId, String fullName, Integer eqeStatus, String couponStatus) {
+        String url = "http://47.106.13.109:3000/api/listenDeviceStatusChange";
+        Map<String,String> map = new HashMap<>();
+        map.put("clientId",clientId);
+        map.put("address",fullName);
+        map.put("status", String.valueOf(eqeStatus));
+        if(StringUtils.isEmpty(couponStatus)){
+            map.put("wxStatus","1");
+        }else {
+            map.put("wxStatus",couponStatus);
+        }
+        String data = JSON.toJSONString(map);
+        try {
+            String s = HttpClientSslUtils.doPost(url, data);
+            System.out.println("发送鲸准:"+s);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     /**
      *
      *

+ 37 - 2
src/main/java/com/szwl/controller/TEquipmentController.java

@@ -3,6 +3,7 @@ package com.szwl.controller;
 
 import cn.com.crbank.ommo.bean.ResultMessage;
 import cn.com.crbank.ommo.esUtil.BeanUtils;
+//import org.apache.commons.beanutils.BeanUtils;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -160,6 +161,7 @@ public class TEquipmentController {
             Date date_end=calendar_end.getTime();
             LambdaQueryWrapper<TAlarmRecord> query1 = Wrappers.lambdaQuery();
             query1.eq(TAlarmRecord::getEquipmentId,equipmentDTO.getId());
+            query1.eq(TAlarmRecord::getIsEliminate,0);
             query1.gt(TAlarmRecord::getOccurrenceTime,date_start);
             query1.le(TAlarmRecord::getOccurrenceTime,date_end);
             List<TAlarmRecord> alarmRecordList = tAlarmRecordService.list(query1);
@@ -190,10 +192,36 @@ public class TEquipmentController {
     @PostMapping("/findById")
     public ResponseModel<?> findById(@RequestParam Long id) {
         TEquipment equipment = tEquipmentService.getById(id);
+        TEquipmentDTO equipmentDTO = new TEquipmentDTO();
+//        BeanUtils.copyProperties(equipment, equipmentDTO);
+        BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
         TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
         if(equipmentDesc!=null){
-            equipment.setCouponStatus(equipmentDesc.getCouponStatus());
+            equipmentDTO.setCouponStatus(equipmentDesc.getCouponStatus());
+        }
+        String messageReceiver = equipment.getMessageReceiver();
+        if(StringUtils.isNotEmpty(messageReceiver)){
+            String[] message = messageReceiver.split(",");
+            int i = message.length;
+            if(i>0){
+                equipmentDTO.setMessageReceiver1(message[0]);
+            }
+            if(i>1){
+                equipmentDTO.setMessageReceiver2(message[1]);
+            }
+            if(i>2){
+                equipmentDTO.setMessageReceiver3(message[2]);
+            }
+//            equipmentDTO.setMessageReceiver1(message[0]);
+//            equipmentDTO.setMessageReceiver2(message[1]);
+//            equipmentDTO.setMessageReceiver3(message[2]);
         }
+        return R.ok(equipmentDTO);
+    }
+    @ApiOperation(value = "id查找机器详情")
+    @PostMapping("/findById2")
+    public ResponseModel<?> findById2(@RequestParam Long id) {
+        TEquipment equipment = tEquipmentService.getById(id);
         return R.ok(equipment);
     }
     //查找设备
@@ -307,7 +335,7 @@ public class TEquipmentController {
     @ApiOperation(value = "更新机器")
 //    @PostMapping("/update")
     @RequestMapping(value = "/update", method = RequestMethod.POST)
-    public ResponseModel<?> update(@RequestBody TEquipment equipment) {
+    public ResponseModel<?> update(@RequestBody TEquipmentDTO equipment) {
         //获取修改前的设备
         TEquipment oldEquipment = tEquipmentService.getById(equipment.getId());
         if(StringUtils.isNotEmpty(equipment.getSn())){
@@ -369,6 +397,13 @@ public class TEquipmentController {
             }
             oldEquipment.setFlowers(equipment.getFlowers());
         }
+        String[] message = new String[3];;
+        message[0]=equipment.getMessageReceiver1();
+        message[1]=equipment.getMessageReceiver2();
+        message[2]=equipment.getMessageReceiver3();
+        if(message.length>0){
+            oldEquipment.setMessageReceiver(message.toString());
+        }
         tEquipmentService.updateById(oldEquipment);
         String channel = oldEquipment.getChannel();
         String equimentType = oldEquipment.getEquimentType();

+ 1 - 1
src/main/java/com/szwl/controller/TOrderController.java

@@ -417,7 +417,7 @@ public class TOrderController {
         TOrder order = R.getDataIfSuccess(payFeign.getOrder(id));
         String orderStatus = order.getOrderStatus();
         if(StringUtils.isNotEmpty(orderStatus)){
-            if(!orderStatus.equals("0")){
+            if(orderStatus.equals("1")||orderStatus.equals("2")){
                 return ResponseEntity
                         .status(HttpStatus.OK)
                         .body(new ResultMessage()

+ 30 - 0
src/main/java/com/szwl/model/bean/TEquipmentDTO.java

@@ -22,6 +22,12 @@ public class TEquipmentDTO extends TEquipment {
     @ApiModelProperty(value="最新报警信息")
     private String alarmContent = "暂无数据";
 
+    @ApiModelProperty(value = "短信接收者;")
+    private String messageReceiver1;
+    @ApiModelProperty(value = "短信接收者;")
+    private String messageReceiver2;
+    @ApiModelProperty(value = "短信接收者;")
+    private String messageReceiver3;
     @ApiModelProperty(value="当天是否存在告警")
     private boolean hasTodayAlarm= false;
 
@@ -181,4 +187,28 @@ public class TEquipmentDTO extends TEquipment {
             this.occurrenceTime = occurrenceTime;
         }
     }
+
+    public String getMessageReceiver1() {
+        return messageReceiver1;
+    }
+
+    public void setMessageReceiver1(String messageReceiver1) {
+        this.messageReceiver1 = messageReceiver1;
+    }
+
+    public String getMessageReceiver2() {
+        return messageReceiver2;
+    }
+
+    public void setMessageReceiver2(String messageReceiver2) {
+        this.messageReceiver2 = messageReceiver2;
+    }
+
+    public String getMessageReceiver3() {
+        return messageReceiver3;
+    }
+
+    public void setMessageReceiver3(String messageReceiver3) {
+        this.messageReceiver3 = messageReceiver3;
+    }
 }

+ 248 - 0
src/main/java/com/szwl/model/utils/HttpClientSslUtils.java

@@ -0,0 +1,248 @@
+package com.szwl.model.utils;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.jboss.logging.MDC;
+import org.springframework.http.HttpStatus;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * HTTP/HTTPS 请求封装: GET / POST
+ * 默认失败重试3次
+ * @author admin
+ */
+@Slf4j
+public class HttpClientSslUtils {
+
+    /**
+     * 默认的字符编码格式
+     */
+    private static final String DEFAULT_CHAR_SET = "UTF-8";
+    /**
+     * 默认连接超时时间 (毫秒)
+     */
+    private static final Integer DEFAULT_CONNECTION_TIME_OUT = 2000;
+    /**
+     * 默认socket超时时间 (毫秒)
+     */
+    private static final Integer DEFAULT_SOCKET_TIME_OUT = 3000;
+
+    /** socketTimeOut上限 */
+    private static final Integer SOCKET_TIME_OUT_UPPER_LIMIT = 10000;
+
+    /** socketTimeOut下限 */
+    private static final Integer SOCKET_TIME_OUT_LOWER_LIMIT = 1000;
+
+    private static CloseableHttpClient getHttpClient() {
+        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(DEFAULT_SOCKET_TIME_OUT)
+                .setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT).build();
+        return HttpClients.custom().setDefaultRequestConfig(requestConfig)
+                .setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
+    }
+
+    private static CloseableHttpClient getHttpClient(Integer socketTimeOut) {
+        RequestConfig requestConfig =
+                RequestConfig.custom().setSocketTimeout(socketTimeOut).setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT)
+                        .build();
+        return HttpClients.custom().setDefaultRequestConfig(requestConfig)
+                .setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
+    }
+
+    public static String doPost(String url, String requestBody) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON);
+    }
+
+    public static String doPost(String url, String requestBody, Integer socketTimeOut) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON, null, socketTimeOut);
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType) throws Exception {
+        return doPost(url, requestBody, contentType, null);
+    }
+
+    public static String doPost(String url, String requestBody, List<BasicHeader> headers) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON, headers);
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers)
+            throws Exception {
+        return doPost(url, requestBody, contentType, headers, getHttpClient());
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
+                                Integer socketTimeOut) throws Exception {
+        if (socketTimeOut < SOCKET_TIME_OUT_LOWER_LIMIT || socketTimeOut > SOCKET_TIME_OUT_UPPER_LIMIT) {
+            log.error("socketTimeOut非法");
+            throw new Exception();
+        }
+        return doPost(url, requestBody, contentType, headers, getHttpClient(socketTimeOut));
+    }
+
+
+    /**
+     * 通用Post远程服务请求
+     * @param url
+     * 	请求url地址
+     * @param requestBody
+     * 	请求体body
+     * @param contentType
+     * 	内容类型
+     * @param headers
+     * 	请求头
+     * @return String 业务自行解析
+     * @throws Exception
+     */
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
+                                CloseableHttpClient client) throws Exception {
+
+        // 构造http方法,设置请求和传输超时时间,重试3次
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            HttpPost post = new HttpPost(url);
+            if (!CollectionUtils.isEmpty(headers)) {
+                for (BasicHeader header : headers) {
+                    post.setHeader(header);
+                }
+            }
+            StringEntity entity =
+                    new StringEntity(requestBody, ContentType.create(contentType.getMimeType(), DEFAULT_CHAR_SET));
+            post.setEntity(entity);
+            response = client.execute(post);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String result = EntityUtils.toString(response.getEntity());
+            return result;
+        } finally {
+            releaseResourceAndLog(url, requestBody, response, startTime);
+        }
+    }
+
+    /**
+     * 暂时用于智慧园区业务联调方式
+     * @param url 业务请求url
+     * @param param 业务参数
+     * @return
+     * @throws Exception
+     */
+    public static String doPostWithUrlEncoded(String url,
+                                              Map<String, String> param) throws Exception {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = getHttpClient();
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 创建参数列表
+            if (param != null) {
+                List<org.apache.http.NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList, DEFAULT_CHAR_SET);
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}" , EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String resultString = EntityUtils.toString(response.getEntity(), DEFAULT_CHAR_SET);
+            return resultString;
+        } finally {
+            releaseResourceAndLog(url, param == null ? null : param.toString(), response, startTime);
+        }
+    }
+
+    private static void releaseResourceAndLog(String url, String request, CloseableHttpResponse response, long startTime) {
+        if (null != response) {
+            try {
+                response.close();
+                recordInterfaceLog(startTime, url, request);
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+
+    public static String doGet(String url) throws Exception {
+        return doGet(url, ContentType.DEFAULT_TEXT);
+    }
+
+    public static String doGet(String url, ContentType contentType) throws Exception {
+        return doGet(url, contentType, null);
+    }
+
+    public static String doGet(String url, List<BasicHeader> headers) throws Exception {
+        return doGet(url, ContentType.DEFAULT_TEXT, headers);
+    }
+
+    /**
+     * 通用Get远程服务请求
+     * @param url
+     * 	请求参数
+     * @param contentType
+     * 	请求参数类型
+     * @param headers
+     * 	请求头可以填充
+     * @return String 业务自行解析数据
+     * @throws Exception
+     */
+    public static String doGet(String url, ContentType contentType, List<BasicHeader> headers) throws Exception {
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            CloseableHttpClient client = getHttpClient();
+            HttpGet httpGet = new HttpGet(url);
+            if (!CollectionUtils.isEmpty(headers)) {
+                for (BasicHeader header : headers) {
+                    httpGet.setHeader(header);
+                }
+            }
+            if(contentType != null){
+                httpGet.setHeader("Content-Type", contentType.getMimeType());
+            }
+            response = client.execute(httpGet);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String result = EntityUtils.toString(response.getEntity());
+            return result;
+        } finally {
+            releaseResourceAndLog(url, null, response, startTime);
+        }
+    }
+
+    private static void recordInterfaceLog(long startTime, String url, String request) {
+        long endTime = System.currentTimeMillis();
+        long timeCost = endTime - startTime;
+        MDC.put("totalTime", String.valueOf(timeCost));
+        MDC.put("url", url);
+        MDC.put("logType", "third-platform-service");
+        log.info("HttpClientSslUtils 远程请求:{} 参数:{} 耗时:{}ms", url, request, timeCost);
+    }
+}
+

+ 2 - 2
src/main/resources/bootstrap.yml

@@ -3,7 +3,7 @@ spring:
     name: szwl-server
   profiles:
     # 打包或运行时,换这里:sit测试,prod正式
-    active: sit
+    active: prod
   cloud:
     config:
       name: szwl-server
@@ -75,7 +75,7 @@ spring:
 eureka:
   client:
     serviceUrl:
-      defaultZone: http://10.0.0.153:49001/eureka/,http://10.0.0.152:49001/eureka/
+      defaultZone: http://112.74.63.148:49001/eureka/,http://47.112.127.131:49001/eureka/
     register-with-eureka: true
   instance:
     prefer-ip-address: true