feat(line): 智电改造线路台账新增「线路数据」弹窗展示最近一次模拟量快照 - 后端新增GET /api/electricity-data/latest(按lineId取最大collect_time的全部模拟量行,RBAC device:list);前端electricityDataApi.getLatestByLine与ElectricityLatestSnapshot类型;台账页表格新增固定右侧「操作」列与「线路数据」按钮,点击弹出720px弹窗显示线路信息(线路/编码/采集时间)及模拟量表格(模拟量名称/类型/数值/单位),无数据时显示空态提示
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
This commit is contained in:
1 parent
c92fc7f298
commit
c8a4330f3b
3 files changed
+153
-2
No files matched your search
@@ -1,14 +1,54 @@
|
||||
import { Controller, Post, Inject } from "@midwayjs/core";
|
||||
import { Controller, Post, Get, Query, Inject } from "@midwayjs/core";
|
||||
import { Context } from "@midwayjs/koa";
|
||||
import { InjectRepository } from "@midwayjs/sequelize";
|
||||
import { Repository } from "sequelize-typescript";
|
||||
import { IccAnalogSyncService } from "../service/icc_analog_sync.service";
|
||||
import ElectricityData from "../entity/electricity_data.entity";
|
||||
|
||||
@Controller("/api/electricity-data")
|
||||
export class ElectricityDataController {
|
||||
@Inject() ctx!: Context;
|
||||
@Inject() iccAnalogSyncService!: IccAnalogSyncService;
|
||||
@InjectRepository(ElectricityData)
|
||||
electricityDataRepo!: Repository<ElectricityData>;
|
||||
|
||||
@Post("/sync") async sync() {
|
||||
const result = await this.iccAnalogSyncService.syncFromIcc(this.ctx);
|
||||
return { code: 200, message: "模拟量数据同步完成", data: result };
|
||||
}
|
||||
|
||||
/** 查询某线路最近一次同步的模拟量快照(取最大 collect_time 的全部模拟量行) */
|
||||
@Get("/latest") async latest(@Query("lineId") lineId?: string) {
|
||||
const id = Number(lineId);
|
||||
if (!id || Number.isNaN(id)) {
|
||||
return { code: 400, message: "缺少有效的 lineId 参数" };
|
||||
}
|
||||
const latest = await this.electricityDataRepo.findOne({
|
||||
where: { lineId: id },
|
||||
order: [["collectTime", "DESC"]],
|
||||
attributes: ["lineCode", "lineName", "imei", "customerId", "collectTime"],
|
||||
});
|
||||
if (!latest) {
|
||||
return { code: 200, message: "该线路暂无模拟量数据", data: { lineId: id, hasData: false, collectTime: null, list: [] } };
|
||||
}
|
||||
const rows = await this.electricityDataRepo.findAll({
|
||||
where: { lineId: id, collectTime: latest.getDataValue("collectTime") as Date },
|
||||
order: [["analogType", "ASC"]],
|
||||
attributes: ["analogType", "analogName", "analogUnit", "analogValue"],
|
||||
});
|
||||
return {
|
||||
code: 200,
|
||||
message: "ok",
|
||||
data: {
|
||||
lineId: id,
|
||||
lineCode: latest.getDataValue("lineCode"),
|
||||
lineName: latest.getDataValue("lineName"),
|
||||
imei: latest.getDataValue("imei"),
|
||||
customerId: latest.getDataValue("customerId"),
|
||||
collectTime: latest.getDataValue("collectTime"),
|
||||
hasData: true,
|
||||
list: rows,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user