|
@@ -37,6 +37,11 @@ public class SyncMeterDataJob implements Job {
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
Object params = jobExecutionContext.getJobDetail().getJobDataMap().get("params");
|
|
|
Map<String,Object> map= (Map<String, Object>) params;
|
|
|
+ sendTask(map);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ public void sendTask( Map<String,Object> map){
|
|
|
TaskEntity taskEntity=new TaskEntity();
|
|
|
String planId=(String) map.get("PlanId");
|
|
|
taskEntity.setPlanId(planId);
|
|
@@ -44,31 +49,37 @@ public class SyncMeterDataJob implements Job {
|
|
|
receiveDao.creatUploadTask(taskEntity);
|
|
|
log.info("通知上传任务 ,任务返回信息={}",taskEntity.getReturnMsg());
|
|
|
if(taskEntity.getReturnCode()==1){
|
|
|
- try {
|
|
|
- uploadData((Date) map.get("UploadTime"),taskEntity.getTaskId());
|
|
|
+ try {
|
|
|
+ uploadData((Date) map.get("UploadTime"),taskEntity.getTaskId());
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
+ }catch (Exception e){
|
|
|
log.error("泗水上传数据失败",e);
|
|
|
}
|
|
|
- finally{
|
|
|
- quartzManager.deleteJob(planId);
|
|
|
- log.info("删除定时计划={}",planId);
|
|
|
- }
|
|
|
+ finally{
|
|
|
+ quartzManager.deleteJob(planId);
|
|
|
+ log.info("删除定时计划={}",planId);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
private void uploadData(Date uploadDate,String taskId){
|
|
|
List<MeterDataEntity>datas=new ArrayList<>();
|
|
|
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
List<MeterReadRecord> meterReadRecords = getMeterReadRecord(uploadDate);
|
|
|
- meterReadRecords.forEach(meterReadRecord -> {
|
|
|
- MeterDataEntity meterDataEntity=new MeterDataEntity();
|
|
|
- meterDataEntity.setReleationId(StringUtils.upperCase(meterReadRecord.getDeviceNo()));
|
|
|
- meterDataEntity.setCurrentReading(Float.parseFloat(meterReadRecord.getReadData()));
|
|
|
- meterDataEntity.setCurrentReadDate(simpleDateFormat.format(meterReadRecord.getReadTime()));
|
|
|
- datas.add(meterDataEntity);
|
|
|
- });
|
|
|
+ Map<String, String> meterReadRecordRelationId = getMeterReadRecordRelationId(meterReadRecords);
|
|
|
+ if(meterReadRecords.size()>0){
|
|
|
+ meterReadRecords.forEach(meterReadRecord -> {
|
|
|
+ MeterDataEntity meterDataEntity=new MeterDataEntity();
|
|
|
+ String relationId = meterReadRecordRelationId.get(meterReadRecord.getDeviceNo());
|
|
|
+ if(relationId!=null){
|
|
|
+ meterDataEntity.setReleationId(StringUtils.upperCase(relationId));
|
|
|
+ meterDataEntity.setCurrentReading(Float.parseFloat(meterReadRecord.getReadData()));
|
|
|
+ meterDataEntity.setCurrentReadDate(simpleDateFormat.format(meterReadRecord.getReadTime()));
|
|
|
+ datas.add(meterDataEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if(datas.size()>0){
|
|
|
UploadWaterMeterDataEntity uploadWaterMeterDataEntity=new UploadWaterMeterDataEntity();
|
|
@@ -79,6 +90,14 @@ public class SyncMeterDataJob implements Job {
|
|
|
uploadWaterMeterDataEntity.getReturnMsg(),uploadWaterMeterDataEntity.getReturnCode());
|
|
|
}
|
|
|
}
|
|
|
+ private Map<String,String>getMeterReadRecordRelationId( List<MeterReadRecord> meterReadRecords){
|
|
|
+ Map<String,String>relationIds=new HashMap<>();
|
|
|
+ List<Map<String,String>>maps=sendDao.selectRelationIdsByDeviceNo(meterReadRecords);
|
|
|
+ maps.forEach(map->{
|
|
|
+ relationIds.put(map.get("deviceNo"),map.get("relationId"));
|
|
|
+ });
|
|
|
+ return relationIds;
|
|
|
+ }
|
|
|
private List<MeterReadRecord>getMeterReadRecord(Date date){
|
|
|
Map<String,Object>args=new HashMap<>();
|
|
|
LocalDateTime time=dateToLocateDateTime(date);
|