BI月台数据改造
This commit is contained in:
+98
-1
@@ -1,22 +1,28 @@
|
||||
package com.mhd.bi.domain.biPlatformRealData.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mhd.bi.domain.biPlatformRealData.repository.mapper.BiPlatformRealDataMapper;
|
||||
import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformVehiclePO;
|
||||
import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformOverviewPO;
|
||||
import com.mhd.bi.domain.biPlatformRealData.repository.po.RealVehicleStatusPO;
|
||||
import com.mhd.bi.domain.biPlatformRealData.repository.po.RealTaskLoadPO;
|
||||
import com.mhd.bi.domain.biPlatformSurveillance.repository.mapper.BiPlatformSurveillanceReportMapper;
|
||||
import com.mhd.bi.domain.biSnapshotSync.repository.mapper.BiSnapshotWriteMapper;
|
||||
import com.mhd.bi.domain.biSnapshotSync.support.BiSnapshotWeeklyRandomDataBuilder;
|
||||
import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.PlatformSurveillanceVO;
|
||||
import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.PlatformVehicleItemVO;
|
||||
import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.TaskLoadItemVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -30,6 +36,96 @@ public class BiPlatformRealDataService {
|
||||
@Resource
|
||||
private BiPlatformRealDataMapper biPlatformRealDataMapper;
|
||||
|
||||
@Resource
|
||||
private BiSnapshotWriteMapper biSnapshotWriteMapper;
|
||||
|
||||
@Resource
|
||||
private BiPlatformSurveillanceReportMapper biPlatformSurveillanceReportMapper;
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private static final String REMARK_REALTIME = "realtime platform-surveillance";
|
||||
|
||||
/**
|
||||
* 实时组装月台监测数据;仅当真实业务数据(YMS 库查出的字段)发生变化时,
|
||||
* 才覆盖更新 BI_PLATFORM_SURVEILLANCE_SNAPSHOT 快照表最新一条后返回。
|
||||
* 写死字段变化不触发更新;表中尚无记录时插入一条兜底。
|
||||
*/
|
||||
public PlatformSurveillanceVO buildRealTimePlatformSurveillanceAndPersist() {
|
||||
PlatformSurveillanceVO vo = buildRealTimePlatformSurveillance();
|
||||
try {
|
||||
String fullJson = objectMapper.writeValueAsString(vo);
|
||||
String fingerprint = realDataFingerprint(vo);
|
||||
|
||||
String latestJson = biPlatformSurveillanceReportMapper.selectLatestPayloadJson();
|
||||
if (StringUtils.isNotBlank(latestJson)) {
|
||||
PlatformSurveillanceVO latestVo = objectMapper.readValue(latestJson.trim(), PlatformSurveillanceVO.class);
|
||||
if (Objects.equals(fingerprint, realDataFingerprint(latestVo))) {
|
||||
log.info("BI 月台监测真实业务数据未变化,跳过落库");
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
int rows = biSnapshotWriteMapper.updateLatestPlatformSurveillanceSnapshot(fullJson, REMARK_REALTIME);
|
||||
if (rows < 1) {
|
||||
// 表中无最新记录可更新,插入一条兜底
|
||||
biSnapshotWriteMapper.insertPlatformSurveillanceSnapshot(fullJson, REMARK_REALTIME);
|
||||
}
|
||||
log.info("BI 月台监测实时数据已落库(覆盖最新, 数据变化), affectedRows={}", rows);
|
||||
} catch (Exception e) {
|
||||
log.error("BI 月台监测实时数据落库失败", e);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取月台监测的「真实业务数据」指纹(仅含 YMS 库查出的字段),用于判断业务数据是否变化。
|
||||
* 写死/随机字段不纳入指纹,故其变化不会触发更新。
|
||||
*/
|
||||
private String realDataFingerprint(PlatformSurveillanceVO vo) throws Exception {
|
||||
Map<String, Object> fp = new LinkedHashMap<>();
|
||||
if (vo.getPlatformOverview() != null) {
|
||||
fp.put("totalPlatforms", vo.getPlatformOverview().getTotalPlatforms());
|
||||
fp.put("operatingPlatforms", vo.getPlatformOverview().getOperatingPlatforms());
|
||||
fp.put("todayTasks", vo.getPlatformOverview().getTodayTasks());
|
||||
}
|
||||
if (vo.getVehicleStatus() != null) {
|
||||
fp.put("todayReservedVehicles", vo.getVehicleStatus().getTodayReservedVehicles());
|
||||
fp.put("notCheckedIn", vo.getVehicleStatus().getNotCheckedIn());
|
||||
fp.put("operatingVehicles", vo.getVehicleStatus().getOperatingVehicles());
|
||||
fp.put("completedVehicles", vo.getVehicleStatus().getCompletedVehicles());
|
||||
}
|
||||
if (vo.getMonthlyTaskStatistics() != null) {
|
||||
fp.put("taskTotal", vo.getMonthlyTaskStatistics().getTaskTotal());
|
||||
}
|
||||
if (vo.getVehicles() != null) {
|
||||
List<Map<String, Object>> vehicles = new ArrayList<>();
|
||||
for (PlatformVehicleItemVO v : vo.getVehicles()) {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("appointmentTime", v.getAppointmentTime());
|
||||
m.put("workFloor", v.getWorkFloor());
|
||||
m.put("plateNumber", v.getPlateNumber());
|
||||
m.put("status", v.getStatus());
|
||||
m.put("platformId", v.getPlatformId());
|
||||
m.put("platformDuration", v.getPlatformDuration());
|
||||
vehicles.add(m);
|
||||
}
|
||||
fp.put("vehicles", vehicles);
|
||||
}
|
||||
if (vo.getTaskLoadStatistics() != null) {
|
||||
List<Map<String, Object>> loads = new ArrayList<>();
|
||||
for (TaskLoadItemVO item : vo.getTaskLoadStatistics()) {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("time", item.getTime());
|
||||
m.put("taskCount", item.getTaskCount());
|
||||
loads.add(m);
|
||||
}
|
||||
fp.put("taskLoadStatistics", loads);
|
||||
}
|
||||
return objectMapper.writeValueAsString(fp);
|
||||
}
|
||||
|
||||
public List<RealPlatformVehiclePO> queryVehicles() {
|
||||
try {
|
||||
return biPlatformRealDataMapper.queryVehicles();
|
||||
@@ -111,7 +207,8 @@ public class BiPlatformRealDataService {
|
||||
* 每次调用实时查库,不经过快照表。
|
||||
*/
|
||||
public PlatformSurveillanceVO buildRealTimePlatformSurveillance() {
|
||||
Random r = new Random();
|
||||
// 固定种子,保证写死字段每次生成值一致(真实字段随后实时覆盖)
|
||||
Random r = new Random(20260825L);
|
||||
PlatformSurveillanceVO template = BiSnapshotWeeklyRandomDataBuilder.platformSurveillance(r);
|
||||
|
||||
// 作业车辆列表
|
||||
|
||||
+2
@@ -13,6 +13,8 @@ public interface BiSnapshotWriteMapper {
|
||||
|
||||
int insertPlatformSurveillanceSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark);
|
||||
|
||||
int updateLatestPlatformSurveillanceSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark);
|
||||
|
||||
int insertOverallOperationSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark);
|
||||
|
||||
int insertWarehouseOperationZoneSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark);
|
||||
|
||||
+2
-1
@@ -150,7 +150,8 @@ public class BiReportSnapshotSyncService {
|
||||
|
||||
/** TODO 业务落地:部分字段改为真实数据,其余仍写死。 */
|
||||
protected PlatformSurveillanceVO buildPlatformSurveillanceSnapshot() {
|
||||
Random r = new Random();
|
||||
// 固定种子,保证写死字段每次生成值一致(真实字段随后实时覆盖)
|
||||
Random r = new Random(20260825L);
|
||||
// 写死数据复用原 builder
|
||||
PlatformSurveillanceVO template = BiSnapshotWeeklyRandomDataBuilder.platformSurveillance(r);
|
||||
|
||||
|
||||
@@ -96,12 +96,12 @@ public class BiReportApi extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 月台监测指标查询(实时查 YMS 库,真实字段 + 写死字段)
|
||||
* 月台监测指标查询(实时查 YMS 库,真实字段 + 写死字段),并落库一条到 BI_PLATFORM_SURVEILLANCE_SNAPSHOT
|
||||
*/
|
||||
@ApiOperation(value = "月台监测指标查询", notes = "每次调用实时查询 YMS 库组装;部分字段为真实业务数据,部分为写死数据")
|
||||
@ApiOperation(value = "月台监测指标查询", notes = "每次调用实时查询 YMS 库组装并写入快照表;部分字段为真实业务数据,部分为写死数据")
|
||||
@GetMapping("/platformSurveillance")
|
||||
public BiApiResult<PlatformSurveillanceVO> platformSurveillance() {
|
||||
PlatformSurveillanceVO data = biPlatformRealDataService.buildRealTimePlatformSurveillance();
|
||||
PlatformSurveillanceVO data = biPlatformRealDataService.buildRealTimePlatformSurveillanceAndPersist();
|
||||
return BiApiResult.ok(data);
|
||||
}
|
||||
//园区物流大屏接口----------------------------------------------------------------------
|
||||
|
||||
@@ -18,6 +18,15 @@
|
||||
values (#{payloadJson}, SYSDATE, SYSDATE, 1, #{remark})
|
||||
</insert>
|
||||
|
||||
<update id="updateLatestPlatformSurveillanceSnapshot">
|
||||
update NGWL_TEST_BI.BI_PLATFORM_SURVEILLANCE_SNAPSHOT
|
||||
set PAYLOAD_JSON = #{payloadJson},
|
||||
UPDATE_TIME = SYSDATE,
|
||||
REMARK = #{remark}
|
||||
where DEL_FLAG = 1
|
||||
and ID = (select max(t.ID) from NGWL_TEST_BI.BI_PLATFORM_SURVEILLANCE_SNAPSHOT t where t.DEL_FLAG = 1)
|
||||
</update>
|
||||
|
||||
<insert id="insertOverallOperationSnapshot">
|
||||
insert into NGWL_TEST_BI.BI_OVERALL_OPERATION_SNAPSHOT (PAYLOAD_JSON, CREATE_TIME, UPDATE_TIME, DEL_FLAG, REMARK)
|
||||
values (#{payloadJson}, SYSDATE, SYSDATE, 1, #{remark})
|
||||
|
||||
Reference in New Issue
Block a user