From 066063ed92fdd40da4dfe21770557f3adba3e1af Mon Sep 17 00:00:00 2001 From: cuikaidong <ckd2942379034@163.com> Date: 星期四, 12 六月 2025 17:30:04 +0800 Subject: [PATCH] 数据库提交 --- jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java | 41 ++++++++++++++++++++++++++++++++++++----- 1 files changed, 36 insertions(+), 5 deletions(-) diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java index 891e9a9..32a844b 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java @@ -7,9 +7,10 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.iot.depository.Influxdb; import org.jeecg.modules.iot.depository.InfluxdbTest; -import org.jeecg.modules.iot.depository.MysqlDataWriter; import org.jeecg.modules.iot.entity.Equipment; import org.jeecg.modules.iot.entity.InfluxdbDeploy; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; +import org.jeecg.modules.iot.mdc.service.IEquipmentLogService; import org.jeecg.modules.iot.service.IEquipmentService; import org.jeecg.modules.iot.service.IInfluxdbDeployService; import org.quartz.Job; @@ -24,6 +25,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** @@ -39,6 +41,8 @@ private DataSource dataSource; @Autowired private IEquipmentService equipmentService; + @Autowired + private IEquipmentLogService equipmentLogService; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { @@ -89,14 +93,21 @@ // 鏍规嵁鏃堕棿杩涜鍒嗙粍 Map<String, List<Influxdb>> timeListMap = timeList.stream() .collect(Collectors.groupingBy(Influxdb::getAcquisitionTime)); - timeListMap.forEach((measurement, influxdbList) -> { - int lastIndex = table.lastIndexOf('.'); - String code = table.substring(lastIndex + 1); + // 澶勭悊璁惧鐘舵�� + int lastIndex = table.lastIndexOf('.'); + String code = table.substring(lastIndex + 1); + EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(code); + // 璁惧鐘舵�� + Integer equipmentState = null; + for (Map.Entry<String, List<Influxdb>> entry : timeListMap.entrySet()) { + String measurement = entry.getKey(); + List<Influxdb> influxdbList = entry.getValue(); Equipment equipment = equipmentService.findEquipmentByCode(code); String tableName = equipment.getControlSystem() + '_' + equipment.getEqptCode(); // 鑾峰彇琛ㄥ悕 String[] columns = new String[influxdbList.size() + 2]; Object[] values = new Object[influxdbList.size() + 2]; + String state = ""; // 閬嶅巻褰撳墠璁惧涓嬬殑鎵�鏈夊弬鏁� for (int i = 0; i < influxdbList.size(); i++) { String parameter = influxdbList.get(i).getParameter(); @@ -104,7 +115,12 @@ values[i] = influxdbList.get(i).getValue(); if (values[i] == null || values[i] == "") { values[i] = ""; + } else { + if (columns[i].equals("Oporation")) { + state = values[i].toString(); + } } + } // 楠岃瘉鏁版嵁鏄惁閮戒负绌� if (!allEmptyStrings(values)) { @@ -119,8 +135,23 @@ values[influxdbList.size()] = tableName; // 鎻掑叆鏁版嵁 equipmentService.insertMysqlData(tableName, columns, values); + if (!state.equals("")) { + EquipmentLog log = new EquipmentLog(); + log.setOporation(Integer.parseInt(state)); + log.setEquipmentId(equipment.getEqptCode()); + log.setEquipmentName(equipment.getEqptName()); + log.setCollectTime(Date.from(dateTime.atZone(java.time.ZoneId.systemDefault()).toInstant())); + // 楠岃瘉璁惧鐘舵�佹槸鍚﹂渶瑕佸瓨鍌� + if (equipmentLog == null) { + equipmentLogService.save(log); + equipmentState = Integer.parseInt(state); + } else if (equipmentState == null && equipmentLog.getOporation() != Integer.parseInt(state)) { + equipmentState = Integer.parseInt(state); + equipmentLogService.save(log); + } + } } - }); + }; }); } catch (Exception e) { log.error(String.valueOf(e)); -- Gitblit v1.9.3