package com.zc.business.domain; import cn.hutool.core.date.DateUtil; import lombok.Data; import org.apache.commons.codec.digest.DigestUtils; import java.util.Objects; /** * 交通断面数据统计定义 * @author xiepufeng */ @Data public class DcTrafficSectionData extends DcStatisticsData { /** * 车流量 */ private Integer trafficVolume; /** * 大型车车流量 */ private Integer largeTrafficVolume; /** * 平均速度 */ private Integer averageSpeed; /** * 所属设备 */ private Long deviceId; /** * 道路方向 */ private Byte direction; /** * 所在桩号 */ private Integer stakeMark; /** * 设备类型 */ private Integer deviceType; /** * 重写equals方法,用于比较两个对象是否相等。 * @param o 要与当前对象比较的对象。 * @return 如果两个对象相等,则返回true;否则返回false。 */ @Override public boolean equals(Object o) { if (this == o) return true; // 同一对象比较,直接返回true if (o == null || getClass() != o.getClass()) return false; // 对象为空或类型不同,返回false DcTrafficSectionData that = (DcTrafficSectionData) o; // 类型转换 return Objects.equals(deviceId, that.deviceId) && Objects.equals(getReportTime(), that.getReportTime()) && Objects.equals(direction, that.direction) && Objects.equals(getPeriodType(), that.getPeriodType()) && Objects.equals(stakeMark, that.stakeMark); // 比较各属性值 } /** * 重写hashCode方法,基于对象的属性生成哈希码。 * @return 对象的哈希码值。 */ @Override public int hashCode() { return Objects.hash(deviceId, getReportTime(), direction, getPeriodType(), stakeMark); } /** * 根据设备ID、统计时间、方向、时段类型、桩号生成一个唯一ID */ public void generateUniqueId() { String combinedAttributes = deviceId + "_" + DateUtil.format(getStatisticalDate(), "yyyyMMdd_HHmmss") + "_" + direction + "_" + getPeriodType() + "_" + stakeMark; this.setId(DigestUtils.md5Hex(combinedAttributes)); } }