localhost_oa_based/src/modules/product/product.entity.ts

105 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
import {
BeforeInsert,
BeforeUpdate,
Column,
Entity,
JoinColumn,
JoinTable,
ManyToMany,
ManyToOne,
Relation
} from 'typeorm';
import { CommonEntity } from '~/common/entity/common.entity';
import { Storage } from '../tools/storage/storage.entity';
import { CompanyEntity } from '../company/company.entity';
import pinyin from 'pinyin';
import { DictItemEntity } from '../system/dict-item/dict-item.entity';
@Entity({ name: 'product' })
export class ProductEntity extends CommonEntity {
@Column({
name: 'product_number',
type: 'varchar',
length: 255,
comment: '产品编号'
})
@ApiProperty({ description: '产品编号' })
productNumber: string;
@Column({
name: 'name',
type: 'varchar',
length: 255,
comment: '产品名称'
})
@ApiProperty({ description: '产品名称' })
name: string;
@Column({
name: 'product_specification',
type: 'varchar',
nullable: true,
length: 255,
comment: '产品规格'
})
@ApiProperty({ description: '产品规格', nullable: true })
productSpecification?: string;
@Column({
name: 'remark',
type: 'varchar',
length: 255,
nullable: true,
comment: '备注'
})
@ApiProperty({ description: '产品备注' })
remark: string;
@Column({ name: 'is_delete', type: 'tinyint', default: 0, comment: '是否删除' })
@ApiProperty({ description: '删除状态0未删除1已删除' })
isDelete: number;
@Column({ name: 'company_id', type: 'int', comment: '所属公司', nullable: true })
@ApiProperty({ description: '所属公司' })
companyId: number;
@Column({ name: 'unit_id', type: 'int', comment: '单位(字典)', nullable: true })
@ApiProperty({ description: '单位(字典)' })
unitId: number;
@ManyToOne(() => DictItemEntity)
@JoinColumn({ name: 'unit_id' })
unit: DictItemEntity;
@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('');
}
@ManyToOne(() => CompanyEntity /* , { onDelete: 'CASCADE' } */)
@JoinColumn({ name: 'company_id' })
company: CompanyEntity;
@ManyToMany(() => Storage, storage => storage.products)
@JoinTable({
name: 'product_storage',
joinColumn: { name: 'product_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'file_id', referencedColumnName: 'id' }
})
files: Relation<Storage[]>;
}