Commit 56e31553 authored by 赵啸非's avatar 赵啸非

分组更新设备

parent 5b103540
package com.mortals.xhx.thread; package com.mortals.xhx.thread;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
...@@ -112,7 +113,10 @@ public class DeviceDownMsgThread extends AbstractThread { ...@@ -112,7 +113,10 @@ public class DeviceDownMsgThread extends AbstractThread {
} }
} }
if (!ObjectUtils.isEmpty(deviceLogList)) { if (!ObjectUtils.isEmpty(deviceLogList)) {
deviceLogService.save(deviceLogList); List<List<DeviceLogEntity>> partition = ListUtil.partition(deviceLogList, 100);
for (List<DeviceLogEntity> deviceLogEntities : partition) {
deviceLogService.save(deviceLogEntities);
}
} }
} }
} }
......
...@@ -17,6 +17,9 @@ import org.springframework.core.annotation.Order; ...@@ -17,6 +17,9 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_IN_HTTP_URL; import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_IN_HTTP_URL;
import static com.mortals.xhx.common.key.RedisKey.KEY_DEVICE_THIRDPARTY_QUEUE; import static com.mortals.xhx.common.key.RedisKey.KEY_DEVICE_THIRDPARTY_QUEUE;
...@@ -47,19 +50,35 @@ public class SendThirdPartyThread extends AbstractThread { ...@@ -47,19 +50,35 @@ public class SendThirdPartyThread extends AbstractThread {
@Override @Override
protected void process() { protected void process() {
// log.info("SendThirdPartyThread process"); // log.info("SendThirdPartyThread process");
DeviceReq deviceReq = cacheService.blpop(KEY_DEVICE_THIRDPARTY_QUEUE, 10, DeviceReq.class); List<DeviceReq> deviceMsgReqs = new ArrayList<>();
if (!ObjectUtils.isEmpty(deviceReq)) { while (true) {
DeviceReq deviceReq = cacheService.lpop(KEY_DEVICE_THIRDPARTY_QUEUE, DeviceReq.class);
if (ObjectUtils.isEmpty(deviceReq)) {
// log.info("deviceMsgReq:{}", deviceMsgReq == null);
break;
}
deviceMsgReqs.add(deviceReq);
}
if (!ObjectUtils.isEmpty(deviceMsgReqs)) {
// DeviceReq deviceReq = cacheService.lpop(KEY_DEVICE_THIRDPARTY_QUEUE, DeviceReq.class);
if (!ObjectUtils.isEmpty(deviceMsgReqs)) {
for (DeviceReq deviceMsgReq : deviceMsgReqs) {
//设备上下线信息 不更新通知 //设备上下线信息 不更新通知
if (DeviceMethodEnum.ONLINE.getValue() == deviceReq.getDeviceStatus() || DeviceMethodEnum.ONLINE.getValue() == deviceReq.getDeviceStatus()) { if (DeviceMethodEnum.ONLINE.getValue() == deviceMsgReq.getDeviceStatus() || DeviceMethodEnum.ONLINE.getValue() == deviceMsgReq.getDeviceStatus()) {
return; return;
} }
//deviceReq.getReceiveMethod() //deviceReq.getReceiveMethod()
String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://127.0.0.1:11078/zwfw_api"); String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://127.0.0.1:11078/zwfw_api");
ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(phpInUrl).addPath(thirdPartyPath).build(), deviceReq); ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(phpInUrl).addPath(thirdPartyPath).build(), deviceMsgReq);
log.info("sendThirty req==>{} \n resp ==>{}", JSON.toJSONString(deviceReq), JSON.toJSONString(resp)); log.info("sendThirty req==>deviceCode:{} TYPE:{} \n resp ==>{}",deviceMsgReq.getDeviceCode(),DeviceMethodEnum.getByValue(deviceMsgReq.getDeviceStatus()).getDesc(), JSON.toJSONString(resp));
} }
} }
}
}
@Override @Override
protected void threadClosed() { protected void threadClosed() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment