Compare commits
2 Commits
main
...
codex/anal
| Author | SHA1 | Date | |
|---|---|---|---|
| e61e244c39 | |||
| 2c90404637 |
@@ -1,5 +1,5 @@
|
||||
import { Hono } from "hono";
|
||||
import { desc, eq, sql } from "drizzle-orm";
|
||||
import { desc, eq, sql, inArray } from "drizzle-orm";
|
||||
import dayjs from "dayjs";
|
||||
import { useDrizzle } from "@/lib/db.js";
|
||||
import { chargePoint, connector } from "@/db/schema.js";
|
||||
@@ -81,12 +81,12 @@ app.post("/", async (c) => {
|
||||
if (body.feePerKwh !== undefined && (!Number.isInteger(body.feePerKwh) || body.feePerKwh < 0)) {
|
||||
return c.json({ error: "feePerKwh must be a non-negative integer" }, 400);
|
||||
}
|
||||
if (body.pricingMode !== undefined && !["fixed", "tou"].includes(body.pricingMode)) {
|
||||
if (body.pricingMode !== undefined && !['fixed', 'tou'].includes(body.pricingMode)) {
|
||||
return c.json({ error: "pricingMode must be 'fixed' or 'tou'" }, 400);
|
||||
}
|
||||
|
||||
const plainPassword = generateOcppPassword();
|
||||
const passwordHash = await hashOcppPassword(plainPassword);
|
||||
const plainPassword = generateOcppPassword()
|
||||
const passwordHash = await hashOcppPassword(plainPassword)
|
||||
|
||||
const [created] = await db
|
||||
.insert(chargePoint)
|
||||
@@ -175,19 +175,21 @@ app.patch("/:id", async (c) => {
|
||||
}
|
||||
set.registrationStatus = body.registrationStatus as "Accepted" | "Pending" | "Rejected";
|
||||
}
|
||||
if (body.chargePointVendor !== undefined)
|
||||
set.chargePointVendor = body.chargePointVendor.trim() || "Unknown";
|
||||
if (body.chargePointModel !== undefined)
|
||||
set.chargePointModel = body.chargePointModel.trim() || "Unknown";
|
||||
if (body.chargePointVendor !== undefined) set.chargePointVendor = body.chargePointVendor.trim() || "Unknown";
|
||||
if (body.chargePointModel !== undefined) set.chargePointModel = body.chargePointModel.trim() || "Unknown";
|
||||
if ("deviceName" in body) set.deviceName = body.deviceName?.trim() || null;
|
||||
if (body.pricingMode !== undefined) {
|
||||
if (!["fixed", "tou"].includes(body.pricingMode)) {
|
||||
if (!['fixed', 'tou'].includes(body.pricingMode)) {
|
||||
return c.json({ error: "pricingMode must be 'fixed' or 'tou'" }, 400);
|
||||
}
|
||||
set.pricingMode = body.pricingMode;
|
||||
}
|
||||
|
||||
const [updated] = await db.update(chargePoint).set(set).where(eq(chargePoint.id, id)).returning();
|
||||
const [updated] = await db
|
||||
.update(chargePoint)
|
||||
.set(set)
|
||||
.where(eq(chargePoint.id, id))
|
||||
.returning();
|
||||
|
||||
if (!updated) return c.json({ error: "Not found" }, 404);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { desc, eq } from "drizzle-orm";
|
||||
import dayjs from "dayjs";
|
||||
import { useDrizzle } from "@/lib/db.js";
|
||||
import { idTag } from "@/db/schema.js";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { z } from "zod";
|
||||
import type { HonoEnv } from "@/types/hono.ts";
|
||||
|
||||
|
||||
0
apps/csms/src/types/db.ts
Normal file
0
apps/csms/src/types/db.ts
Normal file
@@ -185,7 +185,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
|
||||
dayjs().diff(dayjs(cp.lastHeartbeatAt), "second") < (cp.heartbeatInterval ?? 60) * 3;
|
||||
const commandChannelUnavailable = cp?.transportStatus === "unavailable";
|
||||
const statusLabel = isOnline ? "在线" : commandChannelUnavailable ? "通道异常" : "离线";
|
||||
const transportStatusDotClass = isOnline
|
||||
const statusDotClass = isOnline
|
||||
? "bg-success animate-pulse"
|
||||
: commandChannelUnavailable
|
||||
? "bg-warning"
|
||||
@@ -253,7 +253,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
|
||||
</Chip>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span
|
||||
className={`size-2 rounded-full ${transportStatusDotClass}`}
|
||||
className={`size-2 rounded-full ${statusDotClass}`}
|
||||
/>
|
||||
<span className="text-xs text-muted">{statusLabel}</span>
|
||||
</div>
|
||||
@@ -445,7 +445,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
|
||||
<dd>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span
|
||||
className={`size-2 rounded-full ${transportStatusDotClass}`}
|
||||
className={`size-2 rounded-full ${statusDotClass}`}
|
||||
/>
|
||||
<span className="text-sm text-foreground">{statusLabel}</span>
|
||||
</div>
|
||||
|
||||
@@ -184,6 +184,7 @@ export default function PricingPage() {
|
||||
const [activeTier, setActiveTier] = useState<PriceTier>("peak");
|
||||
const [isDirty, setIsDirty] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [showPayload, setShowPayload] = useState(false);
|
||||
|
||||
// Populate state once remote tariff loads
|
||||
useEffect(() => {
|
||||
@@ -285,6 +286,7 @@ export default function PricingPage() {
|
||||
|
||||
// ── Derived values ───────────────────────────────────────────────────────
|
||||
const slots = scheduleToSlots(schedule);
|
||||
const apiPayload: TariffConfig = { slots, prices };
|
||||
|
||||
// ── Admin gate ───────────────────────────────────────────────────────────
|
||||
if (!isAdmin) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Controls,
|
||||
Handle,
|
||||
MiniMap,
|
||||
Panel,
|
||||
Position,
|
||||
type Node,
|
||||
type Edge,
|
||||
@@ -26,8 +27,7 @@ type ConnectionStatus = "online" | "stale" | "offline";
|
||||
|
||||
function getStatus(cp: ChargePoint, connected: string[]): ConnectionStatus {
|
||||
if (cp.transportStatus === "unavailable") return "stale";
|
||||
if (cp.transportStatus !== "online" || !connected.includes(cp.chargePointIdentifier))
|
||||
return "offline";
|
||||
if (cp.transportStatus !== "online" || !connected.includes(cp.chargePointIdentifier)) return "offline";
|
||||
if (!cp.lastHeartbeatAt) return "stale";
|
||||
return dayjs().diff(dayjs(cp.lastHeartbeatAt), "minute") < 5 ? "online" : "stale";
|
||||
}
|
||||
|
||||
@@ -3,7 +3,18 @@
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { CreditCard, Gear, TagDollar, Thunderbolt, Xmark, Bars } from "@gravity-ui/icons";
|
||||
import {
|
||||
CreditCard,
|
||||
Gear,
|
||||
ListCheck,
|
||||
Person,
|
||||
PlugConnection,
|
||||
TagDollar,
|
||||
Thunderbolt,
|
||||
ThunderboltFill,
|
||||
Xmark,
|
||||
Bars,
|
||||
} from "@gravity-ui/icons";
|
||||
import SidebarFooter from "@/components/sidebar-footer";
|
||||
import { useSession } from "@/lib/auth-client";
|
||||
import { EvCharger, Gauge, Network, ReceiptText, UserCog, Users } from "lucide-react";
|
||||
|
||||
@@ -4,7 +4,7 @@ const CSMS_INTERNAL_URL =
|
||||
process.env.CSMS_INTERNAL_URL ?? process.env.NEXT_PUBLIC_CSMS_URL ?? "http://localhost:3001";
|
||||
|
||||
/** 检查 CSMS 是否已完成初始化(有用户存在)。 */
|
||||
async function isInitialized(): Promise<boolean> {
|
||||
async function isInitialized(request: NextRequest): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch(`${CSMS_INTERNAL_URL}/api/setup`, {
|
||||
method: "GET",
|
||||
@@ -25,7 +25,7 @@ export async function proxy(request: NextRequest) {
|
||||
|
||||
// /setup 页面:已初始化则跳转登录
|
||||
if (pathname === "/setup") {
|
||||
if (await isInitialized()) {
|
||||
if (await isInitialized(request)) {
|
||||
return NextResponse.redirect(new URL("/login", request.url));
|
||||
}
|
||||
return NextResponse.next();
|
||||
@@ -33,7 +33,7 @@ export async function proxy(request: NextRequest) {
|
||||
|
||||
// /dashboard 路由:检查 session,未登录跳转 /login
|
||||
if (pathname.startsWith("/dashboard")) {
|
||||
if (!(await isInitialized())) {
|
||||
if (!(await isInitialized(request))) {
|
||||
return NextResponse.redirect(new URL("/setup", request.url));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export async function proxy(request: NextRequest) {
|
||||
|
||||
// /login 路由:未初始化则跳转 /setup
|
||||
if (pathname === "/login") {
|
||||
if (!(await isInitialized())) {
|
||||
if (!(await isInitialized(request))) {
|
||||
return NextResponse.redirect(new URL("/setup", request.url));
|
||||
}
|
||||
return NextResponse.next();
|
||||
|
||||
Reference in New Issue
Block a user