|
@@ -2,9 +2,11 @@ package com.huaxu.zoniot.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.huaxu.zoniot.dao.CommunityMapper;
|
|
|
import com.huaxu.zoniot.dao.CustomerMapper;
|
|
|
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.CommunitySyncService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -27,6 +30,8 @@ public class CommunitySyncServiceImpl implements CommunitySyncService {
|
|
|
PushLogMapper pushLogMapper;
|
|
|
@Autowired
|
|
|
CustomerMapper customerMapper;
|
|
|
+ @Autowired
|
|
|
+ CommunityMapper communityMapper;
|
|
|
@Resource
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
@Value("${spring.rabbitmq.exchange}")
|
|
@@ -37,12 +42,12 @@ public class CommunitySyncServiceImpl implements CommunitySyncService {
|
|
|
@Override
|
|
|
public int rabbitSync() {
|
|
|
List<Integer> customerIds = new ArrayList<>();
|
|
|
- customerIds.add(54);
|
|
|
+ customerIds.add(127);
|
|
|
|
|
|
if (customerIds != null && customerIds.size() > 0) {
|
|
|
for (Integer customerId : customerIds) {
|
|
|
// 1,查询推送记录,1档案;2数据
|
|
|
- PushLog lastLog = pushLogMapper.findLastRecordBycustomerId(customerId);
|
|
|
+ PushLog lastLog = pushLogMapper.findLastRecordBycustomerId(customerId,4);
|
|
|
// 2,计算推送数据时间;如果为首次推送,则判断是否需要将历史数据推送给对方;
|
|
|
Date beginDate = null ;
|
|
|
Date endDate = new Date();
|
|
@@ -58,11 +63,9 @@ public class CommunitySyncServiceImpl implements CommunitySyncService {
|
|
|
// 3,根据推送数据时间进行数据查询
|
|
|
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);
|
|
|
- /*List<DeviceData> dataList = waterMeterMapper.getPushMeterListV2(pushCustomers,
|
|
|
- pushChannels,
|
|
|
+ List<CommunityData> dataList = communityMapper.getPushCommunityList(pushCustomers,
|
|
|
status,
|
|
|
beginDate,
|
|
|
endDate);
|
|
@@ -70,17 +73,25 @@ public class CommunitySyncServiceImpl implements CommunitySyncService {
|
|
|
log.info("end query push device list , size = {}",dataList.size());
|
|
|
if(dataList.size() != 0) {
|
|
|
sendRabbitData(dataList);
|
|
|
- }*/
|
|
|
+ }
|
|
|
+ // 4,定义push日志
|
|
|
+ PushLog pushLog = new PushLog();
|
|
|
+ pushLog.setDataSize(dataList.size());
|
|
|
+ pushLog.setCustomerId(customerId);
|
|
|
+ pushLog.setDateCreate(new Date());
|
|
|
+ pushLog.setPushTime(endDate);
|
|
|
+ pushLog.setPushContent(4);
|
|
|
+ pushLogMapper.insertSelective(pushLog);
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- private void sendRabbitData(List<DeviceData> dataList) {
|
|
|
- for (DeviceData data : dataList) {
|
|
|
+ private void sendRabbitData(List<CommunityData> dataList) {
|
|
|
+ for (CommunityData data : dataList) {
|
|
|
String msg = JSON.toJSONString(data);
|
|
|
log.info("transfer mq msg:{}",msg);
|
|
|
- //rabbitTemplate.convertAndSend(exchange, queue,msg.getBytes(Charset.forName("UTF-8")));
|
|
|
+ rabbitTemplate.convertAndSend(exchange, queue,msg.getBytes(Charset.forName("UTF-8")));
|
|
|
}
|
|
|
}
|
|
|
}
|