新增水表推送
This commit is contained in:
parent
2ee126d8cb
commit
f6f6f1bc51
|
@ -645,6 +645,58 @@ public class StandardTask {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Scheduled(cron = "0 30 2 * * ?")
|
||||
// @Scheduled(cron = "0/5 * * * * ? ")
|
||||
public void DeviceWatterInfoRecord() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 昨天
|
||||
LocalDateTime yesterday = now.minusDays(1);
|
||||
// 转成yyyy-MM-dd HH:mm:ss格式
|
||||
List<DevicePowerInfo> lists = devicePowerInfoService.list(new QueryWrapper<DevicePowerInfo>()
|
||||
.eq("is_send", "0")
|
||||
.likeRight("deviceSN", "C1E81")
|
||||
);
|
||||
|
||||
for (DevicePowerInfo h : lists) {
|
||||
DevicePowerInfoDTO dto = new DevicePowerInfoDTO();
|
||||
DevicePowerInfoDataDTO dataDTO = new DevicePowerInfoDataDTO();
|
||||
dataDTO.setRequestFlag("single");
|
||||
DevicePowerInfoDataListDTO dataListDTO = new DevicePowerInfoDataListDTO();
|
||||
dataListDTO.setDeviceSN(h.getDeviceSN());
|
||||
|
||||
dataListDTO.setPowerEnd(h.getPowerEnd());
|
||||
dataListDTO.setPowerStart(h.getPowerStart());
|
||||
dataListDTO.setPowerUse(h.getPowerUse());
|
||||
dataListDTO.setRoomNo(h.getRoomNo());
|
||||
dataListDTO.setUseDate(h.getUseDate());
|
||||
dataListDTO.setUserName(h.getUserName());
|
||||
List<DevicePowerInfoDataListDTO> list = new ArrayList<>();
|
||||
list.add(dataListDTO);
|
||||
dataDTO.setRequestDataList(list);
|
||||
dto.setRequestData(dataDTO);
|
||||
String requestBody = JSON.toJSONString(dto, SerializerFeature.BrowserCompatible);
|
||||
String url = "https://cyy.csxdtx.com:10010/api/zdyq-equipment/dwBoxRecord/acceptDwDeviceUsage";
|
||||
|
||||
try {
|
||||
// 发送 POST 请求,这里假设接口返回类型为 String ,可根据实际调整
|
||||
// 消息队列发送
|
||||
// rabbitTemplate.convertAndSend(queueName, JSON.toJSONString(dto));
|
||||
// 调接口
|
||||
String result = restTemplate.postForObject(url, requestBody, String.class);
|
||||
logger.info("调用接口返回结果:{}", result);
|
||||
|
||||
// 若返回码符合成功逻辑(需看接口文档定义),更新发送状态
|
||||
h.setIsSend(1);
|
||||
devicePowerInfoService.saveOrUpdate(h);
|
||||
logger.info("电表设备用电信息发送成功:" + h.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("调用接口发送数据失败,记录 ID:{},异常:{}", h.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 昨天
|
||||
|
|
Loading…
Reference in New Issue