diff --git a/src/modules/product/product.service.ts b/src/modules/product/product.service.ts index eacf1e4..fc6c9fc 100644 --- a/src/modules/product/product.service.ts +++ b/src/modules/product/product.service.ts @@ -57,7 +57,6 @@ export class ProductService { keyword: `%${keyword}%` } ); - } return paginate(sqb, { page, @@ -69,9 +68,9 @@ export class ProductService { * 新增 */ async create(dto: ProductDto): Promise { - const { name, companyId } = dto; + const { name, companyId, productSpecification } = dto; const isExsit = await this.productRepository.findOne({ - where: { name, company: { id: companyId } } + where: { productSpecification, name, company: { id: companyId } } }); if (isExsit) { throw new BusinessException(ErrorEnum.PRODUCT_EXIST); @@ -86,6 +85,13 @@ export class ProductService { */ async update(id: number, { fileIds, ...data }: Partial): Promise { await this.entityManager.transaction(async manager => { + const { name, companyId, productSpecification } = data; + const isExsit = await this.productRepository.findOne({ + where: { productSpecification, name, company: { id: companyId } } + }); + if (isExsit) { + throw new BusinessException(ErrorEnum.PRODUCT_EXIST); + } await manager.update( ProductEntity, id, diff --git a/src/modules/system/dept/dept.service.ts b/src/modules/system/dept/dept.service.ts index 8d846c3..08f9cfa 100644 --- a/src/modules/system/dept/dept.service.ts +++ b/src/modules/system/dept/dept.service.ts @@ -116,7 +116,6 @@ export class DeptService { } const deptTree = await this.deptRepository.findTrees({ - depth: 2, relations: ['parent'] }); diff --git a/src/modules/user/user.entity.ts b/src/modules/user/user.entity.ts index 3df5839..e311827 100644 --- a/src/modules/user/user.entity.ts +++ b/src/modules/user/user.entity.ts @@ -1,5 +1,9 @@ +import { ApiHideProperty } from '@nestjs/swagger'; import { Exclude } from 'class-transformer'; +import pinyin from 'pinyin'; import { + BeforeInsert, + BeforeUpdate, Column, Entity, JoinColumn, @@ -32,6 +36,25 @@ export class UserEntity extends CommonEntity { @Column({ nullable: true }) nickname: string; + @ApiHideProperty() + @Column({ + name: 'name_pinyin', + type: 'varchar', + length: 255, + nullable: true, + comment: '产品名称的拼音' + }) + namePinyin: string; + + @BeforeInsert() + @BeforeUpdate() + updateNamePinyin() { + this.namePinyin = pinyin(this.nickname, { + style: pinyin.STYLE_NORMAL, + heteronym: false + }).join(''); + } + @Column({ name: 'avatar', nullable: true }) avatar: string; diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index aa4ee6c..e649a64 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -5,7 +5,7 @@ import Redis from 'ioredis'; import { isEmpty, isNil, isNumber } from 'lodash'; import { EntityManager, In, Like, Repository } from 'typeorm'; - +import pinyin from 'pinyin'; import { BusinessException } from '~/common/exceptions/biz.exception'; import { ErrorEnum } from '~/constants/error-code.constant'; import { ROOT_ROLE_ID, SYS_USER_INITPASSWORD } from '~/constants/system.constant'; @@ -268,7 +268,7 @@ export class UserService { if (keyword) { //关键字模糊查询product的name,productNumber,productSpecification queryBuilder.andWhere( - '(user.nickname like :keyword or dept.name like :keyword)', + '(user.nickname like :keyword or user.namePinyin like :keyword or dept.name like :keyword)', { keyword: `%${keyword}%` }