wangrong
2026-09-29 2f52450964665480f13c94c865bcac9027490380
src/modules/push/service/open.ts
@@ -58,11 +58,13 @@
    try {
      // 1. 保存原始称重数据
      const rawWeight = new PushWeightEntity();
      const rawWeightValue = data.garbageWeight || 0;
      const processedWeight = this.calcProcessedWeight(data.garbageType, rawWeightValue);
      rawWeight.deviceNo = data.deviceNo;
      // rawWeight.uploadTime = data.uploadTime ? new Date(data.uploadTime) : new Date();
      rawWeight.uploadTime = new Date();
      rawWeight.garbageType = data.garbageType;
      rawWeight.weight = data.garbageWeight || 0;
      rawWeight.weight = processedWeight;
      rawWeight.extraData =
        typeof data.extraData === 'object'
          ? JSON.stringify(data.extraData)
@@ -87,7 +89,6 @@
        siteWeight.businessId = iotDevices[0].businessId;
        siteWeight.departmentId = iotDevices[0].departmentId;
        await this.pushSiteweightEntity.save(siteWeight);
      } else {
        siteWeight.businessId = 'UNKNOWN';
        siteWeight.departmentId = -1;
@@ -582,4 +583,28 @@
    }
  }
  /**
   * 计算处理后的重量
   * 规则:
   * 1. 去皮重:干垃圾/可回收物 -1kg,湿垃圾 -10kg,其它类型同干垃圾(-1kg)
   * 2. 去皮后重量 × 1/10
   * 3. 结果不小于 0
   * SW60     有毒有害
   * SW61     湿垃圾
   * SW62001  可回收-废纸张
   * SW62002  可回收-废塑料
   * SW62003  可回收-废金属
   * SW62004  可回收-废玻璃
   * SW62005  可回收-废织物
   * SW62006  可回收-废旧电子产品
   * SW62007  可回收-废旧电源电池
   * SW63     大件垃圾
   * SW64     干垃圾
   */
  private calcProcessedWeight(garbageType: string, weight: number): number {
    const TARE_MAP: Record<string, number> = { SW61: 10 };
    const tareWeight = TARE_MAP[garbageType] ?? 1;
    return Math.max((weight - tareWeight) / 10, 0);
  }
}