2024-03-04 17:31:28 +08:00
|
|
|
|
import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
|
2024-03-05 22:27:01 +08:00
|
|
|
|
import {
|
|
|
|
|
BeforeInsert,
|
|
|
|
|
BeforeUpdate,
|
|
|
|
|
Column,
|
|
|
|
|
Entity,
|
|
|
|
|
JoinColumn,
|
|
|
|
|
JoinTable,
|
|
|
|
|
ManyToMany,
|
|
|
|
|
ManyToOne,
|
|
|
|
|
Relation
|
|
|
|
|
} from 'typeorm';
|
2024-03-04 17:31:28 +08:00
|
|
|
|
import { CommonEntity } from '~/common/entity/common.entity';
|
|
|
|
|
import { Storage } from '../tools/storage/storage.entity';
|
2024-03-05 13:57:03 +08:00
|
|
|
|
import { CompanyEntity } from '../company/company.entity';
|
2024-03-05 22:27:01 +08:00
|
|
|
|
import pinyin from 'pinyin';
|
2024-03-06 11:39:56 +08:00
|
|
|
|
import { DictItemEntity } from '../system/dict-item/dict-item.entity';
|
2024-03-04 17:31:28 +08:00
|
|
|
|
@Entity({ name: 'product' })
|
|
|
|
|
export class ProductEntity extends CommonEntity {
|
2024-03-22 16:47:26 +08:00
|
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
|
name: 'product_number',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
length: 255,
|
|
|
|
|
comment: '产品编号'
|
|
|
|
|
})
|
|
|
|
|
@ApiProperty({ description: '产品编号' })
|
|
|
|
|
productNumber: string;
|
|
|
|
|
|
2024-03-04 17:31:28 +08:00
|
|
|
|
@Column({
|
|
|
|
|
name: 'name',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
length: 255,
|
|
|
|
|
comment: '产品名称'
|
|
|
|
|
})
|
|
|
|
|
@ApiProperty({ description: '产品名称' })
|
|
|
|
|
name: string;
|
2024-03-22 16:47:26 +08:00
|
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
|
name: 'product_specification',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
nullable: true,
|
|
|
|
|
length: 255,
|
|
|
|
|
comment: '产品规格'
|
|
|
|
|
})
|
|
|
|
|
@ApiProperty({ description: '产品规格', nullable: true })
|
|
|
|
|
productSpecification?: string;
|
2024-03-11 13:41:41 +08:00
|
|
|
|
@Column({
|
|
|
|
|
name: 'remark',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
length: 255,
|
2024-03-11 14:12:57 +08:00
|
|
|
|
nullable: true,
|
2024-03-11 13:41:41 +08:00
|
|
|
|
comment: '备注'
|
|
|
|
|
})
|
|
|
|
|
@ApiProperty({ description: '产品备注' })
|
|
|
|
|
remark: string;
|
|
|
|
|
|
2024-03-04 17:31:28 +08:00
|
|
|
|
@Column({ name: 'is_delete', type: 'tinyint', default: 0, comment: '是否删除' })
|
|
|
|
|
@ApiProperty({ description: '删除状态:0未删除,1已删除' })
|
|
|
|
|
isDelete: number;
|
|
|
|
|
|
2024-03-05 13:57:03 +08:00
|
|
|
|
@Column({ name: 'company_id', type: 'int', comment: '所属公司', nullable: true })
|
|
|
|
|
@ApiProperty({ description: '所属公司' })
|
|
|
|
|
companyId: number;
|
|
|
|
|
|
2024-03-06 11:39:56 +08:00
|
|
|
|
@Column({ name: 'unit_id', type: 'int', comment: '单位(字典)', nullable: true })
|
|
|
|
|
@ApiProperty({ description: '单位(字典)' })
|
|
|
|
|
unitId: number;
|
|
|
|
|
|
|
|
|
|
@ManyToOne(() => DictItemEntity)
|
|
|
|
|
@JoinColumn({ name: 'unit_id' })
|
|
|
|
|
unit: DictItemEntity;
|
|
|
|
|
|
2024-03-05 22:27:01 +08:00
|
|
|
|
@ApiHideProperty()
|
|
|
|
|
@Column({
|
|
|
|
|
name: 'name_pinyin',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
length: 255,
|
|
|
|
|
nullable: true,
|
|
|
|
|
comment: '产品名称的拼音'
|
|
|
|
|
})
|
|
|
|
|
namePinyin: string;
|
|
|
|
|
|
|
|
|
|
@BeforeInsert()
|
|
|
|
|
@BeforeUpdate()
|
|
|
|
|
updateNamePinyin() {
|
|
|
|
|
this.namePinyin = pinyin(this.name, {
|
|
|
|
|
style: pinyin.STYLE_NORMAL,
|
|
|
|
|
heteronym: false
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 13:57:03 +08:00
|
|
|
|
@ManyToOne(() => CompanyEntity /* , { onDelete: 'CASCADE' } */)
|
|
|
|
|
@JoinColumn({ name: 'company_id' })
|
|
|
|
|
company: CompanyEntity;
|
|
|
|
|
|
2024-03-04 17:31:28 +08:00
|
|
|
|
@ManyToMany(() => Storage, storage => storage.products)
|
|
|
|
|
@JoinTable({
|
|
|
|
|
name: 'product_storage',
|
|
|
|
|
joinColumn: { name: 'product_id', referencedColumnName: 'id' },
|
|
|
|
|
inverseJoinColumn: { name: 'file_id', referencedColumnName: 'id' }
|
|
|
|
|
})
|
|
|
|
|
files: Relation<Storage[]>;
|
|
|
|
|
}
|