feat: 添加商品价格字段并优化模板分页查询
- 在product和wp_product实体中添加价格字段 - 为模板服务添加分页查询功能 - 更新模板控制器以支持分页参数 - 将Template实体添加到数据源 - 修改QueryBrandDTO的name字段为非必填
This commit is contained in:
parent
3545633f9e
commit
46cfaa24e7
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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; // 搜索关键字(支持模糊查询)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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: '创建时间',
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ export class TemplateService {
|
|||
* 获取所有模板的列表
|
||||
* @returns {Promise<Template[]>} 模板实体数组
|
||||
*/
|
||||
async getTemplateList(): Promise<Template[]> {
|
||||
// 使用 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 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue