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 { TemplateService } from '../service/template.service';
|
||||||
import { successResponse, errorResponse } from '../utils/response.util';
|
import { successResponse, errorResponse } from '../utils/response.util';
|
||||||
import { CreateTemplateDTO, UpdateTemplateDTO } from '../dto/template.dto';
|
import { CreateTemplateDTO, UpdateTemplateDTO } from '../dto/template.dto';
|
||||||
|
|
@ -20,17 +20,10 @@ export class TemplateController {
|
||||||
* @description 获取所有可用模板的列表
|
* @description 获取所有可用模板的列表
|
||||||
*/
|
*/
|
||||||
@ApiOkResponse({ type: [Template], description: '成功获取模板列表' })
|
@ApiOkResponse({ type: [Template], description: '成功获取模板列表' })
|
||||||
@Get('/')
|
@Get('/list')
|
||||||
async getTemplateList() {
|
async getTemplateList(@Query() params: any) {
|
||||||
try {
|
|
||||||
// 调用服务层获取列表
|
// 调用服务层获取列表
|
||||||
const data = await this.templateService.getTemplateList();
|
return this.templateService.getTemplateList(params);
|
||||||
// 返回成功响应
|
|
||||||
return successResponse(data);
|
|
||||||
} catch (error) {
|
|
||||||
// 返回错误响应
|
|
||||||
return errorResponse(error.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import { Subscription } from '../entity/subscription.entity';
|
||||||
import { Site } from '../entity/site.entity';
|
import { Site } from '../entity/site.entity';
|
||||||
import { Dict } from '../entity/dict.entity';
|
import { Dict } from '../entity/dict.entity';
|
||||||
import { DictItem } from '../entity/dict_item.entity';
|
import { DictItem } from '../entity/dict_item.entity';
|
||||||
|
import { Template } from '../entity/template.entity';
|
||||||
|
|
||||||
const options: DataSourceOptions & SeederOptions = {
|
const options: DataSourceOptions & SeederOptions = {
|
||||||
type: 'mysql',
|
type: 'mysql',
|
||||||
|
|
@ -79,6 +80,7 @@ const options: DataSourceOptions & SeederOptions = {
|
||||||
Site,
|
Site,
|
||||||
Dict,
|
Dict,
|
||||||
DictItem,
|
DictItem,
|
||||||
|
Template,
|
||||||
],
|
],
|
||||||
migrations: ['src/migration/*.ts'],
|
migrations: ['src/migration/*.ts'],
|
||||||
seeds: ['src/db/seeds/**/*.ts'],
|
seeds: ['src/db/seeds/**/*.ts'],
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,11 @@ export class CreateProductDTO {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@Rule(RuleType.string())
|
@Rule(RuleType.string())
|
||||||
humidity: string;
|
humidity: string;
|
||||||
|
|
||||||
|
// 商品价格
|
||||||
|
@ApiProperty({ description: '价格', example: 99.99, required: false })
|
||||||
|
@Rule(RuleType.number())
|
||||||
|
price?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -132,7 +137,7 @@ export class QueryBrandDTO {
|
||||||
pageSize: number; // 每页大小
|
pageSize: number; // 每页大小
|
||||||
|
|
||||||
@ApiProperty({ example: 'ZYN', description: '关键字' })
|
@ApiProperty({ example: 'ZYN', description: '关键字' })
|
||||||
@Rule(RuleType.string().required())
|
@Rule(RuleType.string())
|
||||||
name: string; // 搜索关键字(支持模糊查询)
|
name: string; // 搜索关键字(支持模糊查询)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ export class Product {
|
||||||
@Column({ unique: true })
|
@Column({ unique: true })
|
||||||
sku: string;
|
sku: string;
|
||||||
|
|
||||||
|
// 商品价格
|
||||||
|
@ApiProperty({ description: '价格', example: 99.99 })
|
||||||
|
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0 })
|
||||||
|
price: number;
|
||||||
|
|
||||||
@ManyToMany(() => DictItem, {
|
@ManyToMany(() => DictItem, {
|
||||||
cascade: true,
|
cascade: true,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,13 @@ export class Template {
|
||||||
@Column('text',{nullable: true,comment: "描述"})
|
@Column('text',{nullable: true,comment: "描述"})
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
example: true,
|
||||||
|
description: '是否可删除',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@Column({ default: true })
|
||||||
|
deletable: boolean;
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
example: '2022-12-12 11:11:11',
|
example: '2022-12-12 11:11:11',
|
||||||
description: '创建时间',
|
description: '创建时间',
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export class WpProduct {
|
||||||
@Column()
|
@Column()
|
||||||
externalProductId: string;
|
externalProductId: string;
|
||||||
|
|
||||||
@ApiProperty({ description: 'sku', type: 'string' })
|
@ApiProperty({ description: '商店sku', type: 'string' })
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
sku?: string;
|
sku?: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,14 @@ export class TemplateService {
|
||||||
* 获取所有模板的列表
|
* 获取所有模板的列表
|
||||||
* @returns {Promise<Template[]>} 模板实体数组
|
* @returns {Promise<Template[]>} 模板实体数组
|
||||||
*/
|
*/
|
||||||
async getTemplateList(): Promise<Template[]> {
|
async getTemplateList(params: { currentPage?: number, pageSize?: number } = {}): Promise<{ items: Template[], total: number }> {
|
||||||
// 使用 find 方法查询所有模板
|
const { currentPage = 1, pageSize = 10 } = params;
|
||||||
return this.templateModel.find();
|
// 使用 findAndCount 方法查询所有模板
|
||||||
|
const [items, total] = await this.templateModel.findAndCount({
|
||||||
|
skip: (currentPage - 1) * pageSize,
|
||||||
|
take: pageSize,
|
||||||
|
});
|
||||||
|
return { items, total };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue