浏览代码

同步数据

lin 4 年之前
父节点
当前提交
8726ad8d84

+ 30 - 0
meter-reading-job/src/main/java/com/huaxu/zoniot/service/CcrcService.java

@@ -0,0 +1,30 @@
+package com.huaxu.zoniot.service;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+
+@Slf4j
+@Service
+public class CcrcService {
+
+    @Value("${ccrc.url}")
+    private String ccrcUrl;
+
+    private RestTemplate restTemplate = new RestTemplate();
+
+    public List<Integer> getCustomerIds(){
+        String url = ccrcUrl+"/api/external/getSiteCustomerIds";
+        ResponseEntity<String> responseEntity = restTemplate.getForEntity(url,String.class);
+        JSONObject jsonObject = JSONObject.parseObject(responseEntity.getBody());
+        if(jsonObject.getInteger("status")==0){
+            return jsonObject.getJSONArray("data").toJavaList(Integer.class);
+        }
+        return null;
+    }
+}

+ 5 - 2
meter-reading-job/src/main/java/com/huaxu/zoniot/service/impl/BuildingSyncServiceImpl.java

@@ -9,6 +9,7 @@ import com.huaxu.zoniot.entity.PushLog;
 import com.huaxu.zoniot.model.BuildingData;
 import com.huaxu.zoniot.model.DeviceData;
 import com.huaxu.zoniot.service.BuildingSyncService;
+import com.huaxu.zoniot.service.CcrcService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -39,10 +40,12 @@ public class BuildingSyncServiceImpl implements BuildingSyncService {
     @Value("${spring.rabbitmq.building.queue}")
     private String queue;
 
+    @Autowired
+    private CcrcService ccrcService;
+
     @Override
     public int rabbitSync() {
-        List<Integer> customerIds = new ArrayList<>();
-        customerIds.add(127);
+        List<Integer> customerIds = ccrcService.getCustomerIds();
 
         if (customerIds != null && customerIds.size() > 0) {
             for (Integer customerId : customerIds) {

+ 4 - 2
meter-reading-job/src/main/java/com/huaxu/zoniot/service/impl/CommunitySyncServiceImpl.java

@@ -8,6 +8,7 @@ import com.huaxu.zoniot.dao.PushLogMapper;
 import com.huaxu.zoniot.entity.PushLog;
 import com.huaxu.zoniot.model.CommunityData;
 import com.huaxu.zoniot.model.DeviceData;
+import com.huaxu.zoniot.service.CcrcService;
 import com.huaxu.zoniot.service.CommunitySyncService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -38,11 +39,12 @@ public class CommunitySyncServiceImpl implements CommunitySyncService {
     private String exchange;
     @Value("${spring.rabbitmq.community.queue}")
     private String queue;
+    @Autowired
+    private CcrcService ccrcService;
 
     @Override
     public int rabbitSync() {
-        List<Integer> customerIds = new ArrayList<>();
-        customerIds.add(127);
+        List<Integer> customerIds = ccrcService.getCustomerIds();
 
         if (customerIds != null && customerIds.size() > 0) {
             for (Integer customerId : customerIds) {

+ 6 - 4
meter-reading-job/src/main/java/com/huaxu/zoniot/service/impl/MeterFileSyncServiceImpl.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.huaxu.zoniot.dao.*;
 import com.huaxu.zoniot.model.DeviceData;
+import com.huaxu.zoniot.service.CcrcService;
 import com.huaxu.zoniot.utils.HttpClientUtils;
 import com.huaxu.zoniot.entity.DeviceInfoPushConfig;
 import com.huaxu.zoniot.entity.MeterInfo;
@@ -53,6 +54,8 @@ public class MeterFileSyncServiceImpl  implements MeterFileSyncService {
     private String exchange;
     @Value("${spring.rabbitmq.device.queue}")
     private String queue;
+    @Autowired
+    private CcrcService ccrcService;
 
     @Override
     public int httpSync(Integer configId) {
@@ -273,8 +276,7 @@ public class MeterFileSyncServiceImpl  implements MeterFileSyncService {
     @Override
     public int rabbitSync() {
 
-        List<Integer> customerIds = new ArrayList<>();
-        customerIds.add(127);
+        List<Integer> customerIds = ccrcService.getCustomerIds();
 
         if (customerIds != null && customerIds.size() > 0) {
             for (Integer customerId : customerIds) {
@@ -296,8 +298,8 @@ public class MeterFileSyncServiceImpl  implements MeterFileSyncService {
                 List<Integer> cIds = customerMapper.getSubId(customerId);
                 String pushCustomers = StringUtils.join(cIds, ",");
                 String pushChannels = "40,55";
-                log.info("begin query push device list , beginDate={}, endDate={}",
-                         beginDate, endDate);
+                log.info("begin query push device list ,pushCustomers={}, beginDate={}, endDate={}",
+                        pushCustomers,beginDate, endDate);
                 List<DeviceData> dataList = waterMeterMapper.getPushMeterListV2(pushCustomers,
                         pushChannels,
                         status,

+ 3 - 1
meter-reading-job/src/main/resources/application-job-dev.properties

@@ -31,4 +31,6 @@ job.task.rabbit.exchange=job-task-exchange
 spring.rabbitmq.exchange=sync-handler-exchange
 spring.rabbitmq.device.queue=sync-device-handler-queue
 spring.rabbitmq.community.queue=sync-community-handler-queue
-spring.rabbitmq.building.queue=sync-building-handler-queue
+spring.rabbitmq.building.queue=sync-building-handler-queue
+
+ccrc.url=http://localhost:8099