From 46cfaa24e754a6ad434512ff5aae52f2cb5adca4 Mon Sep 17 00:00:00 2001 From: tikkhun Date: Fri, 28 Nov 2025 00:19:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E5=AD=97=E6=AE=B5=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在product和wp_product实体中添加价格字段 - 为模板服务添加分页查询功能 - 更新模板控制器以支持分页参数 - 将Template实体添加到数据源 - 修改QueryBrandDTO的name字段为非必填 --- src/controller/template.controller.ts | 17 +++++------------ src/db/datasource.ts | 2 ++ src/dto/product.dto.ts | 7 ++++++- src/entity/product.entity.ts | 5 +++++ src/entity/template.entity.ts | 9 ++++++++- src/entity/wp_product.entity.ts | 2 +- src/service/template.service.ts | 11 ++++++++--- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/controller/template.controller.ts b/src/controller/template.controller.ts index 3590370..c6eb5dc 100644 --- a/src/controller/template.controller.ts +++ b/src/controller/template.controller.ts @@ -1,4 +1,4 @@ -import { Inject, Controller, Get, Post, Put, Del, Body, Param } from '@midwayjs/core'; +import { Inject, Controller, Get, Post, Put, Del, Body, Param, Query } from '@midwayjs/core'; import { TemplateService } from '../service/template.service'; import { successResponse, errorResponse } from '../utils/response.util'; import { CreateTemplateDTO, UpdateTemplateDTO } from '../dto/template.dto'; @@ -20,17 +20,10 @@ export class TemplateController { * @description 获取所有可用模板的列表 */ @ApiOkResponse({ type: [Template], description: '成功获取模板列表' }) - @Get('/') - async getTemplateList() { - try { - // 调用服务层获取列表 - const data = await this.templateService.getTemplateList(); - // 返回成功响应 - return successResponse(data); - } catch (error) { - // 返回错误响应 - return errorResponse(error.message); - } + @Get('/list') + async getTemplateList(@Query() params: any) { + // 调用服务层获取列表 + return this.templateService.getTemplateList(params); } /** diff --git a/src/db/datasource.ts b/src/db/datasource.ts index 47f57b7..9be274a 100644 --- a/src/db/datasource.ts +++ b/src/db/datasource.ts @@ -34,6 +34,7 @@ import { Subscription } from '../entity/subscription.entity'; import { Site } from '../entity/site.entity'; import { Dict } from '../entity/dict.entity'; import { DictItem } from '../entity/dict_item.entity'; +import { Template } from '../entity/template.entity'; const options: DataSourceOptions & SeederOptions = { type: 'mysql', @@ -79,6 +80,7 @@ const options: DataSourceOptions & SeederOptions = { Site, Dict, DictItem, + Template, ], migrations: ['src/migration/*.ts'], seeds: ['src/db/seeds/**/*.ts'], diff --git a/src/dto/product.dto.ts b/src/dto/product.dto.ts index 035e8d9..2fdfb22 100644 --- a/src/dto/product.dto.ts +++ b/src/dto/product.dto.ts @@ -61,6 +61,11 @@ export class CreateProductDTO { @ApiProperty() @Rule(RuleType.string()) humidity: string; + + // 商品价格 + @ApiProperty({ description: '价格', example: 99.99, required: false }) + @Rule(RuleType.number()) + price?: number; } /** @@ -132,7 +137,7 @@ export class QueryBrandDTO { pageSize: number; // 每页大小 @ApiProperty({ example: 'ZYN', description: '关键字' }) - @Rule(RuleType.string().required()) + @Rule(RuleType.string()) name: string; // 搜索关键字(支持模糊查询) } diff --git a/src/entity/product.entity.ts b/src/entity/product.entity.ts index 8ef7208..a22cf4b 100644 --- a/src/entity/product.entity.ts +++ b/src/entity/product.entity.ts @@ -42,6 +42,11 @@ export class Product { @Column({ unique: true }) sku: string; + // 商品价格 + @ApiProperty({ description: '价格', example: 99.99 }) + @Column({ type: 'decimal', precision: 10, scale: 2, default: 0 }) + price: number; + @ManyToMany(() => DictItem, { cascade: true, }) diff --git a/src/entity/template.entity.ts b/src/entity/template.entity.ts index b44ad6c..81c64f7 100644 --- a/src/entity/template.entity.ts +++ b/src/entity/template.entity.ts @@ -24,7 +24,14 @@ export class Template { @ApiProperty({ nullable: true ,name:"描述"}) @Column('text',{nullable: true,comment: "描述"}) description?: string; - + + @ApiProperty({ + example: true, + description: '是否可删除', + required: true, + }) + @Column({ default: true }) + deletable: boolean; @ApiProperty({ example: '2022-12-12 11:11:11', description: '创建时间', diff --git a/src/entity/wp_product.entity.ts b/src/entity/wp_product.entity.ts index b7070b8..c70a60f 100644 --- a/src/entity/wp_product.entity.ts +++ b/src/entity/wp_product.entity.ts @@ -39,7 +39,7 @@ export class WpProduct { @Column() externalProductId: string; - @ApiProperty({ description: 'sku', type: 'string' }) + @ApiProperty({ description: '商店sku', type: 'string' }) @Column({ nullable: true }) sku?: string; diff --git a/src/service/template.service.ts b/src/service/template.service.ts index 45c512c..de4dff8 100644 --- a/src/service/template.service.ts +++ b/src/service/template.service.ts @@ -17,9 +17,14 @@ export class TemplateService { * 获取所有模板的列表 * @returns {Promise} 模板实体数组 */ - async getTemplateList(): Promise { - // 使用 find 方法查询所有模板 - return this.templateModel.find(); + async getTemplateList(params: { currentPage?: number, pageSize?: number } = {}): Promise<{ items: Template[], total: number }> { + const { currentPage = 1, pageSize = 10 } = params; + // 使用 findAndCount 方法查询所有模板 + const [items, total] = await this.templateModel.findAndCount({ + skip: (currentPage - 1) * pageSize, + take: pageSize, + }); + return { items, total }; } /**