feat(M06-E): 接入智慧插座业务控制
This commit is contained in:
@@ -58,11 +58,30 @@ const subLockSchema = contextSchema.extend({
|
||||
content: z.string().min(1).max(128).optional(),
|
||||
dangerConfirmation: z.string().max(64).optional()
|
||||
});
|
||||
const socketReadSchema = contextSchema.extend({
|
||||
target: z.enum(['basicInfo', 'workInfo']).default('workInfo')
|
||||
});
|
||||
const socketSwitchSchema = contextSchema.extend({
|
||||
on: z.boolean(),
|
||||
slotNum: z.number().int().min(1).max(20).default(1)
|
||||
});
|
||||
const socketTaskSchema = contextSchema.extend({
|
||||
taskNum: z.number().int().min(1).max(20),
|
||||
action: z.enum(['on', 'off']),
|
||||
mode: z.enum(['once', 'daily', 'weekly']),
|
||||
time: z.string().regex(/^\d{2}:\d{2}$/),
|
||||
weekdays: z.array(z.number().int().min(1).max(7)).max(7).optional()
|
||||
});
|
||||
const socketClearTaskSchema = contextSchema.extend({
|
||||
taskNum: z.number().int().min(0).max(20)
|
||||
});
|
||||
|
||||
export interface DeviceControlRouteOptions {
|
||||
service: Pick<DeviceControlService,
|
||||
'controlPower' | 'controlDoor' | 'playTts' | 'stopTts' | 'controlLed'
|
||||
| 'startTask' | 'extendTask' | 'cancelTask' | 'pairSubLock' | 'controlSubLock'>;
|
||||
| 'startTask' | 'extendTask' | 'cancelTask' | 'pairSubLock' | 'controlSubLock'
|
||||
| 'readSmartSocket' | 'switchSmartSocket' | 'scheduleSmartSocket'
|
||||
| 'clearSmartSocketTask'>;
|
||||
authRepository: Pick<AuthRepository, 'validateSession'>;
|
||||
accessControl: { getAccessProfile(tenantId: string, userId: string): Promise<AccessProfile> };
|
||||
jwtSecret: string;
|
||||
@@ -91,6 +110,14 @@ export async function registerDeviceControlRoutes(
|
||||
(context, body) => options.service.pairSubLock(context, body.timeout));
|
||||
register('/admin-api/device-control/sub-lock/action', subLockSchema,
|
||||
(context, body) => options.service.controlSubLock(context, body));
|
||||
register('/admin-api/device-control/socket/read', socketReadSchema,
|
||||
(context, body) => options.service.readSmartSocket(context, body.target));
|
||||
register('/admin-api/device-control/socket/switch', socketSwitchSchema,
|
||||
(context, body) => options.service.switchSmartSocket(context, body));
|
||||
register('/admin-api/device-control/socket/task', socketTaskSchema,
|
||||
(context, body) => options.service.scheduleSmartSocket(context, body));
|
||||
register('/admin-api/device-control/socket/task/clear', socketClearTaskSchema,
|
||||
(context, body) => options.service.clearSmartSocketTask(context, body.taskNum));
|
||||
|
||||
function register<T extends z.ZodTypeAny>(
|
||||
url: string,
|
||||
|
||||
Reference in New Issue
Block a user