|
@@ -1,15 +1,20 @@
|
|
|
package com.jeesite.modules.tianHong.service;
|
|
package com.jeesite.modules.tianHong.service;
|
|
|
|
|
|
|
|
|
|
+import java.sql.Connection;
|
|
|
|
|
+import java.sql.PreparedStatement;
|
|
|
|
|
+import java.sql.ResultSet;
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
+import javax.sql.DataSource;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -21,15 +26,36 @@ import com.jeesite.modules.tianHong.entity.MachineAttrHistory;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 设备历史属性Service
|
|
* 设备历史属性Service
|
|
|
- * @author ljr
|
|
|
|
|
- * @version 2026-07-07
|
|
|
|
|
|
|
+ * 读主库 mes_cloud_ljr.tianhong_backup(eqp_id + create_date),
|
|
|
|
|
+ * create_date 分钟个位向下取整为 10min 窗口末尾,# 串拆成 600 秒展示。
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
@Transactional(readOnly = true)
|
|
|
public class MachineAttrHistoryService extends CrudService<MachineAttrHistoryDao, MachineAttrHistory> {
|
|
public class MachineAttrHistoryService extends CrudService<MachineAttrHistoryDao, MachineAttrHistory> {
|
|
|
|
|
|
|
|
|
|
+ private static final int POINT_COUNT = 600;
|
|
|
|
|
+ /** 列表查询 create_date 跨度上限(毫秒):30 分钟 */
|
|
|
|
|
+ private static final long MAX_RANGE_MS = 30L * 60L * 1000L;
|
|
|
|
|
+
|
|
|
|
|
+ private static final String SELECT_BACKUP_SQL =
|
|
|
|
|
+ "SELECT eqp_id, create_date,"
|
|
|
|
|
+ + " cru_temp, alu_temp, mould_info,"
|
|
|
|
|
+ + " theory_pressure, real_pressure, pressure_level, ele_consume,"
|
|
|
|
|
+ + " alu_val, pressurize_time, cooling_time, pre_pres, hold_pressure, mold_filling_pre,"
|
|
|
|
|
+ + " point_count"
|
|
|
|
|
+ + " FROM tianhong_backup"
|
|
|
|
|
+ + " WHERE eqp_id = ?"
|
|
|
|
|
+ + " AND create_date >= ?"
|
|
|
|
|
+ + " AND create_date <= ?"
|
|
|
|
|
+ + " ORDER BY create_date DESC";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DataSource dataSource;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 分页:必须先选设备;按 event_time 倒序,每页默认 20;关联表按「秒」补齐
|
|
|
|
|
|
|
+ * 分页:eqpId + beginTime(上传时间/create_date);秒级正序。
|
|
|
|
|
+ * 无截止时间时自动按上传时间起向后取最长 30 分钟;
|
|
|
|
|
+ * 展示从上传时间减 3 秒起,更早的秒隐藏。
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Page<MachineAttrHistory> findPage(MachineAttrHistory machineAttrHistory) {
|
|
public Page<MachineAttrHistory> findPage(MachineAttrHistory machineAttrHistory) {
|
|
@@ -38,11 +64,13 @@ public class MachineAttrHistoryService extends CrudService<MachineAttrHistoryDao
|
|
|
page = new Page<>();
|
|
page = new Page<>();
|
|
|
machineAttrHistory.setPage(page);
|
|
machineAttrHistory.setPage(page);
|
|
|
}
|
|
}
|
|
|
- if (StringUtils.isBlank(machineAttrHistory.getEqpId())) {
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(machineAttrHistory.getEqpId())
|
|
|
|
|
+ || machineAttrHistory.getBeginTime() == null) {
|
|
|
page.setList(Collections.emptyList());
|
|
page.setList(Collections.emptyList());
|
|
|
page.setCount(0);
|
|
page.setCount(0);
|
|
|
return page;
|
|
return page;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
int pageSize = page.getPageSize() > 0 ? page.getPageSize() : 20;
|
|
int pageSize = page.getPageSize() > 0 ? page.getPageSize() : 20;
|
|
|
int pageNo = page.getPageNo() > 0 ? page.getPageNo() : 1;
|
|
int pageNo = page.getPageNo() > 0 ? page.getPageNo() : 1;
|
|
|
if (pageSize > 100) {
|
|
if (pageSize > 100) {
|
|
@@ -51,217 +79,336 @@ public class MachineAttrHistoryService extends CrudService<MachineAttrHistoryDao
|
|
|
page.setPageSize(pageSize);
|
|
page.setPageSize(pageSize);
|
|
|
page.setPageNo(pageNo);
|
|
page.setPageNo(pageNo);
|
|
|
|
|
|
|
|
- machineAttrHistory.setPage(null);
|
|
|
|
|
- Long count = dao.findHistoryCount(machineAttrHistory);
|
|
|
|
|
- page.setCount(count == null ? 0L : count);
|
|
|
|
|
|
|
+ Date uploadTime = machineAttrHistory.getBeginTime();
|
|
|
|
|
+ Date begin = uploadTime;
|
|
|
|
|
+ Date end = machineAttrHistory.getEndTime();
|
|
|
|
|
+ if (end == null || end.before(begin)) {
|
|
|
|
|
+ end = new Date(begin.getTime() + MAX_RANGE_MS);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (end.getTime() - begin.getTime() > MAX_RANGE_MS) {
|
|
|
|
|
+ end = new Date(begin.getTime() + MAX_RANGE_MS);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- machineAttrHistory.setLimit(pageSize);
|
|
|
|
|
- machineAttrHistory.setOffset((pageNo - 1) * pageSize);
|
|
|
|
|
- List<MachineAttrHistory> list = dao.findList(machineAttrHistory);
|
|
|
|
|
- fillRelatedBySecond(machineAttrHistory.getEqpId(), list);
|
|
|
|
|
- page.setList(list);
|
|
|
|
|
|
|
+ List<BackupRow> backups;
|
|
|
|
|
+ try {
|
|
|
|
|
+ backups = loadBackups(machineAttrHistory.getEqpId(), begin, end);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("load tianhong_backup failed, eqpId={}", machineAttrHistory.getEqpId(), e);
|
|
|
|
|
+ page.setList(Collections.emptyList());
|
|
|
|
|
+ page.setCount(0);
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<MachineAttrHistory> all = expandBackups(backups);
|
|
|
|
|
+ // 展示从上传时间减 3 秒开始,前面隐藏
|
|
|
|
|
+ final long showFromMs = uploadTime.getTime() - 3L * 1000L;
|
|
|
|
|
+ List<MachineAttrHistory> filtered = new ArrayList<>();
|
|
|
|
|
+ for (MachineAttrHistory row : all) {
|
|
|
|
|
+ if (row.getAttrEventTime() != null && row.getAttrEventTime().getTime() >= showFromMs) {
|
|
|
|
|
+ filtered.add(row);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ filtered.sort(Comparator.comparing(MachineAttrHistory::getAttrEventTime,
|
|
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder())));
|
|
|
|
|
+
|
|
|
|
|
+ page.setCount(filtered.size());
|
|
|
|
|
+ int from = (pageNo - 1) * pageSize;
|
|
|
|
|
+ if (from >= filtered.size()) {
|
|
|
|
|
+ page.setList(Collections.emptyList());
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+ int to = Math.min(from + pageSize, filtered.size());
|
|
|
|
|
+ page.setList(filtered.subList(from, to));
|
|
|
return page;
|
|
return page;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 查询列表(必须带设备号)
|
|
|
|
|
- */
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<MachineAttrHistory> findList(MachineAttrHistory machineAttrHistory) {
|
|
public List<MachineAttrHistory> findList(MachineAttrHistory machineAttrHistory) {
|
|
|
- if (StringUtils.isBlank(machineAttrHistory.getEqpId())) {
|
|
|
|
|
|
|
+ Page<MachineAttrHistory> page = findPage(machineAttrHistory);
|
|
|
|
|
+ return page.getList() == null ? Collections.emptyList() : page.getList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 属性明细:主库 backup 展开后按秒取槽位拼 attrList
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<MachineAttrHistory> findAttrList(MachineAttrHistory machineAttrHistory) {
|
|
|
|
|
+ MachineAttrHistory one = resolveOneSecond(machineAttrHistory);
|
|
|
|
|
+ if (one == null || one.getAttrList() == null) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
- if (machineAttrHistory.getLimit() == null) {
|
|
|
|
|
- machineAttrHistory.setLimit(20);
|
|
|
|
|
- }
|
|
|
|
|
- if (machineAttrHistory.getOffset() == null) {
|
|
|
|
|
- machineAttrHistory.setOffset(0);
|
|
|
|
|
- }
|
|
|
|
|
- List<MachineAttrHistory> list = dao.findList(machineAttrHistory);
|
|
|
|
|
- fillRelatedBySecond(machineAttrHistory.getEqpId(), list);
|
|
|
|
|
- return list;
|
|
|
|
|
|
|
+ return one.getAttrList();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 用本页时间点截断到秒,按索引范围补齐温压电量(避免大表按秒 JOIN)
|
|
|
|
|
|
|
+ * 单条详情(含 attrList),全部主库
|
|
|
*/
|
|
*/
|
|
|
- private void fillRelatedBySecond(String eqpId, List<MachineAttrHistory> list) {
|
|
|
|
|
- if (StringUtils.isBlank(eqpId) || list == null || list.isEmpty()) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Set<Date> secSet = new LinkedHashSet<>();
|
|
|
|
|
- for (MachineAttrHistory row : list) {
|
|
|
|
|
- if (row.getAttrEventTime() != null) {
|
|
|
|
|
- secSet.add(truncateToSecond(row.getAttrEventTime()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public MachineAttrHistory get(MachineAttrHistory machineAttrHistory) {
|
|
|
|
|
+ if (StringUtils.isBlank(machineAttrHistory.getEqpId())) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- if (secSet.isEmpty()) {
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ MachineAttrHistory entity = resolveOneSecond(machineAttrHistory);
|
|
|
|
|
+ if (entity == null) {
|
|
|
|
|
+ entity = new MachineAttrHistory();
|
|
|
|
|
+ entity.setEqpId(machineAttrHistory.getEqpId());
|
|
|
|
|
+ entity.setAttrList(Collections.emptyList());
|
|
|
}
|
|
}
|
|
|
- List<Date> secList = new ArrayList<>(secSet);
|
|
|
|
|
-
|
|
|
|
|
- Map<Long, MachineAttrHistory> cruMap = latestBySec(dao.findCruBySecList(eqpId, secList));
|
|
|
|
|
- Map<Long, MachineAttrHistory> aluMap = latestBySec(dao.findAluBySecList(eqpId, secList));
|
|
|
|
|
- Map<Long, MachineAttrHistory> mouldMap = latestBySec(dao.findMouldBySecList(eqpId, secList));
|
|
|
|
|
- Map<Long, MachineAttrHistory> pressMap = latestBySec(dao.findPressureBySecList(eqpId, secList));
|
|
|
|
|
- Map<Long, MachineAttrHistory> eleMap = latestBySec(dao.findEleBySecList(eqpId, secList));
|
|
|
|
|
|
|
+ return entity;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (MachineAttrHistory row : list) {
|
|
|
|
|
- if (row.getAttrEventTime() == null) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- Long key = secKey(row.getAttrEventTime());
|
|
|
|
|
- MachineAttrHistory cru = cruMap.get(key);
|
|
|
|
|
- if (cru != null) {
|
|
|
|
|
- row.setCruTemp(cru.getCruTemp());
|
|
|
|
|
- row.setCruTempTime(cru.getCruTempTime());
|
|
|
|
|
- }
|
|
|
|
|
- MachineAttrHistory alu = aluMap.get(key);
|
|
|
|
|
- if (alu != null) {
|
|
|
|
|
- row.setAluTemp(alu.getAluTemp());
|
|
|
|
|
- row.setAluTempTime(alu.getAluTempTime());
|
|
|
|
|
- }
|
|
|
|
|
- MachineAttrHistory mould = mouldMap.get(key);
|
|
|
|
|
- if (mould != null) {
|
|
|
|
|
- row.setMouldInfo(mould.getMouldInfo());
|
|
|
|
|
- row.setMouldTempTime(mould.getMouldTempTime());
|
|
|
|
|
|
|
+ private MachineAttrHistory resolveOneSecond(MachineAttrHistory query) {
|
|
|
|
|
+ if (query == null || StringUtils.isBlank(query.getEqpId())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date target = resolveTargetSecond(query);
|
|
|
|
|
+ if (target == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date windowStart = floorTo10Minutes(target);
|
|
|
|
|
+ Date windowEnd = addMinutes(windowStart, 10);
|
|
|
|
|
+ Date createFrom = windowEnd;
|
|
|
|
|
+ Date createTo = addMinutes(windowEnd, 10);
|
|
|
|
|
+ List<BackupRow> backups;
|
|
|
|
|
+ try {
|
|
|
|
|
+ backups = loadBackups(query.getEqpId(), createFrom, createTo);
|
|
|
|
|
+ if (backups.isEmpty()) {
|
|
|
|
|
+ backups = loadBackups(query.getEqpId(), addMinutes(windowEnd, -1), createTo);
|
|
|
}
|
|
}
|
|
|
- MachineAttrHistory press = pressMap.get(key);
|
|
|
|
|
- if (press != null) {
|
|
|
|
|
- row.setTheoryPressure(press.getTheoryPressure());
|
|
|
|
|
- row.setRealPressure(press.getRealPressure());
|
|
|
|
|
- row.setPressureLevel(press.getPressureLevel());
|
|
|
|
|
- row.setPressureTime(press.getPressureTime());
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("load tianhong_backup for detail failed, eqpId={}", query.getEqpId(), e);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ BackupRow hit = null;
|
|
|
|
|
+ for (BackupRow row : backups) {
|
|
|
|
|
+ Date we = floorTo10Minutes(row.createDate);
|
|
|
|
|
+ Date ws = addMinutes(we, -10);
|
|
|
|
|
+ if (!target.before(ws) && target.before(we)) {
|
|
|
|
|
+ hit = row;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- MachineAttrHistory ele = eleMap.get(key);
|
|
|
|
|
- if (ele != null) {
|
|
|
|
|
- row.setEleConsume(ele.getEleConsume());
|
|
|
|
|
- row.setEleConsumeTime(ele.getEleConsumeTime());
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hit == null && !backups.isEmpty()) {
|
|
|
|
|
+ hit = backups.get(0);
|
|
|
|
|
+ windowEnd = floorTo10Minutes(hit.createDate);
|
|
|
|
|
+ windowStart = addMinutes(windowEnd, -10);
|
|
|
|
|
+ } else if (hit != null) {
|
|
|
|
|
+ windowEnd = floorTo10Minutes(hit.createDate);
|
|
|
|
|
+ windowStart = addMinutes(windowEnd, -10);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int idx = secIndex(target, windowStart);
|
|
|
|
|
+ if (idx < 0 || idx >= POINT_COUNT) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ MachineAttrHistory row = buildSecondRow(query.getEqpId(), windowStart, idx, hit);
|
|
|
|
|
+ row.setAttrList(buildAttrList(row));
|
|
|
|
|
+ return row;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Date resolveTargetSecond(MachineAttrHistory query) {
|
|
|
|
|
+ if (StringUtils.isNotBlank(query.getEventTimeKey())) {
|
|
|
|
|
+ Date parsed = parseEventTimeKey(query.getEventTimeKey());
|
|
|
|
|
+ if (parsed != null) {
|
|
|
|
|
+ return truncateToSecond(parsed);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (query.getEventTime() != null) {
|
|
|
|
|
+ return truncateToSecond(query.getEventTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getAttrEventTime() != null) {
|
|
|
|
|
+ return truncateToSecond(query.getAttrEventTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (query.getBeginTime() != null) {
|
|
|
|
|
+ return truncateToSecond(query.getBeginTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 同一秒多条时保留 EventTime 最新的一条 */
|
|
|
|
|
- private Map<Long, MachineAttrHistory> latestBySec(List<MachineAttrHistory> rows) {
|
|
|
|
|
- Map<Long, MachineAttrHistory> map = new HashMap<>();
|
|
|
|
|
- if (rows == null) {
|
|
|
|
|
- return map;
|
|
|
|
|
|
|
+ /** eventTimeKey: yyyyMMddHHmmss + 微秒6位,共20位 */
|
|
|
|
|
+ private Date parseEventTimeKey(String key) {
|
|
|
|
|
+ String k = StringUtils.trim(key);
|
|
|
|
|
+ if (k == null || k.length() < 14) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- for (MachineAttrHistory row : rows) {
|
|
|
|
|
- Date t = row.getEventTime();
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- t = row.getCruTempTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- t = row.getAluTempTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- t = row.getMouldTempTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- t = row.getPressureTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- t = row.getEleConsumeTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (t == null) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- Long key = secKey(t);
|
|
|
|
|
- MachineAttrHistory old = map.get(key);
|
|
|
|
|
- if (old == null || compareTime(t, resolveTime(old)) > 0) {
|
|
|
|
|
- if (row.getEventTime() == null) {
|
|
|
|
|
- row.setEventTime(t);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ return new SimpleDateFormat("yyyyMMddHHmmss").parse(k.substring(0, 14));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<BackupRow> loadBackups(String eqpId, Date createFrom, Date createTo) throws Exception {
|
|
|
|
|
+ List<BackupRow> list = new ArrayList<>();
|
|
|
|
|
+ try (Connection conn = dataSource.getConnection();
|
|
|
|
|
+ PreparedStatement ps = conn.prepareStatement(SELECT_BACKUP_SQL)) {
|
|
|
|
|
+ ps.setString(1, eqpId);
|
|
|
|
|
+ ps.setTimestamp(2, new Timestamp(createFrom.getTime()));
|
|
|
|
|
+ ps.setTimestamp(3, new Timestamp(createTo.getTime()));
|
|
|
|
|
+ try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ BackupRow row = new BackupRow();
|
|
|
|
|
+ row.eqpId = rs.getString("eqp_id");
|
|
|
|
|
+ Timestamp cd = rs.getTimestamp("create_date");
|
|
|
|
|
+ row.createDate = cd == null ? null : new Date(cd.getTime());
|
|
|
|
|
+ row.cruTemp = rs.getString("cru_temp");
|
|
|
|
|
+ row.aluTemp = rs.getString("alu_temp");
|
|
|
|
|
+ row.mouldInfo = rs.getString("mould_info");
|
|
|
|
|
+ row.theoryPressure = rs.getString("theory_pressure");
|
|
|
|
|
+ row.realPressure = rs.getString("real_pressure");
|
|
|
|
|
+ row.pressureLevel = rs.getString("pressure_level");
|
|
|
|
|
+ row.eleConsume = rs.getString("ele_consume");
|
|
|
|
|
+ row.aluVal = rs.getString("alu_val");
|
|
|
|
|
+ row.pressurizeTime = rs.getString("pressurize_time");
|
|
|
|
|
+ row.coolingTime = rs.getString("cooling_time");
|
|
|
|
|
+ row.prePres = rs.getString("pre_pres");
|
|
|
|
|
+ row.holdPressure = rs.getString("hold_pressure");
|
|
|
|
|
+ row.moldFillingPre = rs.getString("mold_filling_pre");
|
|
|
|
|
+ list.add(row);
|
|
|
}
|
|
}
|
|
|
- map.put(key, row);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return map;
|
|
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Date resolveTime(MachineAttrHistory row) {
|
|
|
|
|
- if (row.getEventTime() != null) {
|
|
|
|
|
- return row.getEventTime();
|
|
|
|
|
- }
|
|
|
|
|
- if (row.getCruTempTime() != null) {
|
|
|
|
|
- return row.getCruTempTime();
|
|
|
|
|
|
|
+ private List<MachineAttrHistory> expandBackups(List<BackupRow> backups) {
|
|
|
|
|
+ List<MachineAttrHistory> result = new ArrayList<>();
|
|
|
|
|
+ if (backups == null || backups.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
- if (row.getAluTempTime() != null) {
|
|
|
|
|
- return row.getAluTempTime();
|
|
|
|
|
|
|
+ for (BackupRow backup : backups) {
|
|
|
|
|
+ if (backup.createDate == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date windowEnd = floorTo10Minutes(backup.createDate);
|
|
|
|
|
+ Date windowStart = addMinutes(windowEnd, -10);
|
|
|
|
|
+ for (int i = 0; i < POINT_COUNT; i++) {
|
|
|
|
|
+ result.add(buildSecondRow(backup.eqpId, windowStart, i, backup));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- if (row.getMouldTempTime() != null) {
|
|
|
|
|
- return row.getMouldTempTime();
|
|
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private MachineAttrHistory buildSecondRow(String eqpId, Date windowStart, int idx, BackupRow backup) {
|
|
|
|
|
+ Date sec = new Date(windowStart.getTime() + idx * 1000L);
|
|
|
|
|
+ MachineAttrHistory row = new MachineAttrHistory();
|
|
|
|
|
+ row.setEqpId(eqpId);
|
|
|
|
|
+ row.setAttrEventTime(sec);
|
|
|
|
|
+ row.setEventTime(sec);
|
|
|
|
|
+ row.setId(eqpId + "_" + formatEventTimeKey(sec));
|
|
|
|
|
+
|
|
|
|
|
+ row.setCruTemp(slot(backup.cruTemp, idx));
|
|
|
|
|
+ row.setAluTemp(slot(backup.aluTemp, idx));
|
|
|
|
|
+ row.setMouldInfo(slot(backup.mouldInfo, idx));
|
|
|
|
|
+ row.setTheoryPressure(slot(backup.theoryPressure, idx));
|
|
|
|
|
+ row.setRealPressure(slot(backup.realPressure, idx));
|
|
|
|
|
+ row.setPressureLevel(slot(backup.pressureLevel, idx));
|
|
|
|
|
+ row.setEleConsume(slot(backup.eleConsume, idx));
|
|
|
|
|
+ row.setAluVal(slot(backup.aluVal, idx));
|
|
|
|
|
+ row.setPressurizeTime(slot(backup.pressurizeTime, idx));
|
|
|
|
|
+ row.setCoolingTime(slot(backup.coolingTime, idx));
|
|
|
|
|
+ row.setPrePres(slot(backup.prePres, idx));
|
|
|
|
|
+ row.setHoldPressure(slot(backup.holdPressure, idx));
|
|
|
|
|
+ row.setMoldFillingPre(slot(backup.moldFillingPre, idx));
|
|
|
|
|
+
|
|
|
|
|
+ row.setCruTempTime(sec);
|
|
|
|
|
+ row.setAluTempTime(sec);
|
|
|
|
|
+ row.setMouldTempTime(sec);
|
|
|
|
|
+ row.setPressureTime(sec);
|
|
|
|
|
+ row.setEleConsumeTime(sec);
|
|
|
|
|
+ return row;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<MachineAttrHistory> buildAttrList(MachineAttrHistory row) {
|
|
|
|
|
+ List<MachineAttrHistory> list = new ArrayList<>();
|
|
|
|
|
+ addAttr(list, row, "alu_val", row.getAluVal());
|
|
|
|
|
+ addAttr(list, row, "pressurizeTime", row.getPressurizeTime());
|
|
|
|
|
+ addAttr(list, row, "coolingTime", row.getCoolingTime());
|
|
|
|
|
+ addAttr(list, row, "PrePres", row.getPrePres());
|
|
|
|
|
+ addAttr(list, row, "HoldPressure", row.getHoldPressure());
|
|
|
|
|
+ addAttr(list, row, "moldFillingPre", row.getMoldFillingPre());
|
|
|
|
|
+ addAttr(list, row, "cruTemp", row.getCruTemp());
|
|
|
|
|
+ addAttr(list, row, "aluTemp", row.getAluTemp());
|
|
|
|
|
+ addAttr(list, row, "mouldInfo", row.getMouldInfo());
|
|
|
|
|
+ addAttr(list, row, "theoryPressure", row.getTheoryPressure());
|
|
|
|
|
+ addAttr(list, row, "realPressure", row.getRealPressure());
|
|
|
|
|
+ addAttr(list, row, "pressureLevel", row.getPressureLevel());
|
|
|
|
|
+ addAttr(list, row, "eleConsume", row.getEleConsume());
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addAttr(List<MachineAttrHistory> list, MachineAttrHistory src, String attr, String val) {
|
|
|
|
|
+ MachineAttrHistory item = new MachineAttrHistory();
|
|
|
|
|
+ item.setEqpId(src.getEqpId());
|
|
|
|
|
+ item.setAttr(attr);
|
|
|
|
|
+ item.setVal(val == null ? "" : val);
|
|
|
|
|
+ item.setEventTime(src.getAttrEventTime());
|
|
|
|
|
+ list.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String slot(String series, int idx) {
|
|
|
|
|
+ if (series == null) {
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
- if (row.getPressureTime() != null) {
|
|
|
|
|
- return row.getPressureTime();
|
|
|
|
|
|
|
+ String[] parts = series.split("#", -1);
|
|
|
|
|
+ if (idx < 0 || idx >= parts.length) {
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
- return row.getEleConsumeTime();
|
|
|
|
|
|
|
+ return parts[idx] == null ? "" : parts[idx];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private int compareTime(Date a, Date b) {
|
|
|
|
|
- if (a == null && b == null) {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- if (a == null) {
|
|
|
|
|
|
|
+ private static int secIndex(Date eventTime, Date windowStart) {
|
|
|
|
|
+ long ms = eventTime.getTime() - windowStart.getTime();
|
|
|
|
|
+ if (ms < 0) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- if (b == null) {
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
- return a.compareTo(b);
|
|
|
|
|
|
|
+ return (int) (ms / 1000L);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Date truncateToSecond(Date date) {
|
|
|
|
|
|
|
+ /** 分钟个位向下取整(对 10 取整),秒/毫秒清零 → 10min 窗口锚点/末尾 */
|
|
|
|
|
+ private static Date floorTo10Minutes(Date date) {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);
|
|
cal.setTime(date);
|
|
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
+ int minute = cal.get(Calendar.MINUTE);
|
|
|
|
|
+ cal.set(Calendar.MINUTE, minute - (minute % 10));
|
|
|
return cal.getTime();
|
|
return cal.getTime();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 用 epoch 秒做 map key,避免 Date 毫秒差异 */
|
|
|
|
|
- private Long secKey(Date date) {
|
|
|
|
|
- return date.getTime() / 1000L;
|
|
|
|
|
|
|
+ private static Date addMinutes(Date date, int minutes) {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+ cal.add(Calendar.MINUTE, minutes);
|
|
|
|
|
+ return cal.getTime();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 查询指定设备的所有属性明细(用于详情展示)
|
|
|
|
|
- */
|
|
|
|
|
- public List<MachineAttrHistory> findAttrList(MachineAttrHistory machineAttrHistory) {
|
|
|
|
|
- if (StringUtils.isBlank(machineAttrHistory.getEqpId())) {
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
- }
|
|
|
|
|
- return dao.findAttrList(machineAttrHistory);
|
|
|
|
|
|
|
+ private static Date truncateToSecond(Date date) {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
+ return cal.getTime();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取单条数据(按 eqp_id + 快照时间查询属性明细)
|
|
|
|
|
- * 须带 eventTimeKey / eventTime / beginTime~endTime,禁止无时间条件全量加载
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public MachineAttrHistory get(MachineAttrHistory machineAttrHistory) {
|
|
|
|
|
- if (StringUtils.isBlank(machineAttrHistory.getEqpId())) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- MachineAttrHistory entity = new MachineAttrHistory();
|
|
|
|
|
- entity.setEqpId(machineAttrHistory.getEqpId());
|
|
|
|
|
- entity.setAttrEventTime(machineAttrHistory.getEventTime());
|
|
|
|
|
- entity.setEventTimeKey(machineAttrHistory.getEventTimeKey());
|
|
|
|
|
- boolean hasTime = StringUtils.isNotBlank(machineAttrHistory.getEventTimeKey())
|
|
|
|
|
- || machineAttrHistory.getEventTime() != null
|
|
|
|
|
- || machineAttrHistory.getBeginTime() != null
|
|
|
|
|
- || machineAttrHistory.getEndTime() != null;
|
|
|
|
|
- if (!hasTime) {
|
|
|
|
|
- entity.setAttrList(Collections.emptyList());
|
|
|
|
|
- return entity;
|
|
|
|
|
- }
|
|
|
|
|
- MachineAttrHistory queryParam = new MachineAttrHistory();
|
|
|
|
|
- queryParam.setEqpId(machineAttrHistory.getEqpId());
|
|
|
|
|
- queryParam.setEventTimeKey(machineAttrHistory.getEventTimeKey());
|
|
|
|
|
- queryParam.setEventTime(machineAttrHistory.getEventTime());
|
|
|
|
|
- queryParam.setBeginTime(machineAttrHistory.getBeginTime());
|
|
|
|
|
- queryParam.setEndTime(machineAttrHistory.getEndTime());
|
|
|
|
|
- entity.setAttrList(dao.findAttrList(queryParam));
|
|
|
|
|
- return entity;
|
|
|
|
|
|
|
+ private static String formatEventTimeKey(Date sec) {
|
|
|
|
|
+ return new SimpleDateFormat("yyyyMMddHHmmss").format(sec) + "000000";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static final class BackupRow {
|
|
|
|
|
+ String eqpId;
|
|
|
|
|
+ Date createDate;
|
|
|
|
|
+ String cruTemp;
|
|
|
|
|
+ String aluTemp;
|
|
|
|
|
+ String mouldInfo;
|
|
|
|
|
+ String theoryPressure;
|
|
|
|
|
+ String realPressure;
|
|
|
|
|
+ String pressureLevel;
|
|
|
|
|
+ String eleConsume;
|
|
|
|
|
+ String aluVal;
|
|
|
|
|
+ String pressurizeTime;
|
|
|
|
|
+ String coolingTime;
|
|
|
|
|
+ String prePres;
|
|
|
|
|
+ String holdPressure;
|
|
|
|
|
+ String moldFillingPre;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|