import { Controller, Get, Post, Put, Del, Inject, Query, Body, Param } from "@midwayjs/core"; import { Context } from "@midwayjs/koa"; import { CustomerService } from "../service/customer.service"; import { IccCustomerSyncService } from "../service/icc_customer_sync.service"; @Controller("/api/customers") export class CustomerController { @Inject() ctx!: Context; @Inject() customerService!: CustomerService; @Inject() iccCustomerSyncService!: IccCustomerSyncService; @Get("/") async list(@Query() query: any) { const result = await this.customerService.list(query, this.ctx); return result; } @Get("/options/all") async getSimpleList() { const result = await this.customerService.getSimpleList(this.ctx); return result; } @Get("/stats") async getStats() { const result = await this.customerService.getStats(this.ctx); return result; } @Post("/sync/icc") async syncIccCustomers() { const result = await this.iccCustomerSyncService.syncFromIcc(this.ctx); return { code: 200, message: "同步完成", data: result }; } @Get("/:id") async detail(@Param("id") id: string) { const result = await this.customerService.detail(Number(id), this.ctx); return result; } @Post("/") async create(@Body() body: any) { const result = await this.customerService.create(body, this.ctx); return result; } @Put("/:id") async update(@Param("id") id: string, @Body() body: any) { const result = await this.customerService.update(Number(id), body, this.ctx); return result; } @Del("/:id") async delete(@Param("id") id: string) { const result = await this.customerService.delete(Number(id), this.ctx); return result; } @Put("/:id/status") async updateStatus(@Param("id") id: string, @Body() body: { status: number }) { const result = await this.customerService.updateStatus(Number(id), body.status, this.ctx); return result; } }