feat: contract模块
This commit is contained in:
parent
6650f9f06a
commit
9c8d2e6ca3
|
@ -1,9 +1,21 @@
|
||||||
import { Controller, Get } from '@nestjs/common';
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Query,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Post,
|
||||||
|
BadRequestException
|
||||||
|
} from '@nestjs/common';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { definePermission } from '../auth/decorators/permission.decorator';
|
import { Perm, definePermission } from '../auth/decorators/permission.decorator';
|
||||||
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator';
|
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator';
|
||||||
import { ContractService } from './contract.service';
|
import { ContractService } from './contract.service';
|
||||||
import { ApiResult } from '~/common/decorators/api-result.decorator';
|
import { ApiResult } from '~/common/decorators/api-result.decorator';
|
||||||
|
import { ContractEntity } from './contract.entity';
|
||||||
|
import { ContractDto, ContractQueryDto, ContractUpdateDto } from './contract.dto';
|
||||||
|
import { IdParam } from '~/common/decorators/id-param.decorator';
|
||||||
export const permissions = definePermission('app:contract', {
|
export const permissions = definePermission('app:contract', {
|
||||||
LIST: 'list',
|
LIST: 'list',
|
||||||
CREATE: 'create',
|
CREATE: 'create',
|
||||||
|
@ -16,48 +28,42 @@ export const permissions = definePermission('app:contract', {
|
||||||
@ApiSecurityAuth()
|
@ApiSecurityAuth()
|
||||||
@Controller('contract')
|
@Controller('contract')
|
||||||
export class ContractController {
|
export class ContractController {
|
||||||
constructor(private menuService: ContractService) {}
|
constructor(private contractService: ContractService) {}
|
||||||
|
|
||||||
// @Get()
|
@Get()
|
||||||
// @ApiOperation({ summary: '获取合同列表' })
|
@ApiOperation({ summary: '获取合同列表' })
|
||||||
// @ApiResult({ type: [RoleEntity], isPage: true })
|
@ApiResult({ type: [ContractEntity], isPage: true })
|
||||||
// @Perm(permissions.LIST)
|
@Perm(permissions.LIST)
|
||||||
// async list(@Query() dto: RoleQueryDto) {
|
async list(@Query() dto: ContractQueryDto) {
|
||||||
// return this.roleService.findAll(dto)
|
return this.contractService.findAll(dto);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// @Get(':id')
|
@Get(':id')
|
||||||
// @ApiOperation({ summary: '获取角色信息' })
|
@ApiOperation({ summary: '获取合同信息' })
|
||||||
// @ApiResult({ type: RoleInfo })
|
@ApiResult({ type: ContractDto })
|
||||||
// @Perm(permissions.READ)
|
@Perm(permissions.READ)
|
||||||
// async info(@IdParam() id: number) {
|
async info(@IdParam() id: number) {
|
||||||
// return this.roleService.info(id)
|
return this.contractService.info(id);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// @Post()
|
@Post()
|
||||||
// @ApiOperation({ summary: '新增角色' })
|
@ApiOperation({ summary: '新增合同' })
|
||||||
// @Perm(permissions.CREATE)
|
@Perm(permissions.CREATE)
|
||||||
// async create(@Body() dto: RoleDto): Promise<void> {
|
async create(@Body() dto: ContractDto): Promise<void> {
|
||||||
// await this.roleService.create(dto)
|
await this.contractService.create(dto);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// @Put(':id')
|
@Put(':id')
|
||||||
// @ApiOperation({ summary: '更新角色' })
|
@ApiOperation({ summary: '更新合同' })
|
||||||
// @Perm(permissions.UPDATE)
|
@Perm(permissions.UPDATE)
|
||||||
// async update(
|
async update(@IdParam() id: number, @Body() dto: ContractUpdateDto): Promise<void> {
|
||||||
// @IdParam() id: number, @Body() dto: RoleUpdateDto): Promise<void> {
|
await this.contractService.update(id, dto);
|
||||||
// await this.roleService.update(id, dto)
|
}
|
||||||
// await this.menuService.refreshOnlineUserPerms()
|
|
||||||
// }
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: '删除合同' })
|
||||||
// @Delete(':id')
|
@Perm(permissions.DELETE)
|
||||||
// @ApiOperation({ summary: '删除角色' })
|
async delete(@IdParam() id: number): Promise<void> {
|
||||||
// @Perm(permissions.DELETE)
|
await this.contractService.delete(id);
|
||||||
// async delete(@IdParam() id: number): Promise<void> {
|
}
|
||||||
// if (await this.roleService.checkUserByRoleId(id))
|
|
||||||
// throw new BadRequestException('该角色存在关联用户,无法删除')
|
|
||||||
|
|
||||||
// await this.roleService.delete(id)
|
|
||||||
// await this.menuService.refreshOnlineUserPerms()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger';
|
||||||
|
import {
|
||||||
|
IsArray,
|
||||||
|
IsDate,
|
||||||
|
IsDateString,
|
||||||
|
IsIn,
|
||||||
|
IsInt,
|
||||||
|
IsNumber,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
Matches,
|
||||||
|
MinLength,
|
||||||
|
|
||||||
|
} from 'class-validator';
|
||||||
|
import { PagerDto } from '~/common/dto/pager.dto';
|
||||||
|
|
||||||
|
export class ContractDto {
|
||||||
|
@ApiProperty({ description: '合同编号' })
|
||||||
|
@Matches(/^[a-z0-9A-Z]+$/, { message: '合同编号只能包含字母和数字' })
|
||||||
|
@IsString()
|
||||||
|
contractNumber: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '合同标题' })
|
||||||
|
@IsString()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '合同类型' })
|
||||||
|
@IsNumber()
|
||||||
|
type: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '甲方' })
|
||||||
|
@IsString()
|
||||||
|
partyA: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '乙方' })
|
||||||
|
@IsString()
|
||||||
|
partyB: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '签订日期' })
|
||||||
|
@IsDateString()
|
||||||
|
signingDate: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '交付期限' })
|
||||||
|
@IsDateString()
|
||||||
|
deliveryDeadline: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '审核状态(字典)' })
|
||||||
|
@IsIn([0, 1, 2])
|
||||||
|
status: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ContractUpdateDto extends PartialType(ContractDto) {}
|
||||||
|
export class ContractQueryDto extends IntersectionType(
|
||||||
|
PagerDto<ContractDto>,
|
||||||
|
PartialType(ContractDto)
|
||||||
|
) {}
|
|
@ -1,4 +1,73 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { ContractEntity } from './contract.entity';
|
||||||
|
import { Like, Repository } from 'typeorm';
|
||||||
|
import { ContractDto, ContractQueryDto } from './contract.dto';
|
||||||
|
import { Pagination } from '~/helper/paginate/pagination';
|
||||||
|
import { isNumber } from 'lodash';
|
||||||
|
import { paginate } from '~/helper/paginate';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ContractService {}
|
export class ContractService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(ContractEntity)
|
||||||
|
private contractRepository: Repository<ContractEntity>
|
||||||
|
) {}
|
||||||
|
/**
|
||||||
|
* 列举所有角色:除去超级管理员
|
||||||
|
*/
|
||||||
|
async findAll({
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
contractNumber,
|
||||||
|
title,
|
||||||
|
type,
|
||||||
|
status
|
||||||
|
}: ContractQueryDto): Promise<Pagination<ContractEntity>> {
|
||||||
|
const queryBuilder = this.contractRepository.createQueryBuilder('contract').where({
|
||||||
|
...(contractNumber ? { contractNumber: Like(`%${contractNumber}%`) } : null),
|
||||||
|
...(title ? { title: Like(`%${title}%`) } : null),
|
||||||
|
...(isNumber(type) ? { type } : null),
|
||||||
|
...(isNumber(status) ? { status } : null)
|
||||||
|
});
|
||||||
|
|
||||||
|
return paginate<ContractEntity>(queryBuilder, {
|
||||||
|
page,
|
||||||
|
pageSize
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
async create(dto: ContractDto): Promise<void> {
|
||||||
|
await this.contractRepository.insert(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
async update(id: number, dto: Partial<ContractDto>): Promise<void> {
|
||||||
|
await this.contractRepository.update(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
async delete(id: number): Promise<void> {
|
||||||
|
await this.contractRepository.softDelete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个合同信息
|
||||||
|
*/
|
||||||
|
async info(id: number) {
|
||||||
|
const info = await this.contractRepository
|
||||||
|
.createQueryBuilder('contract')
|
||||||
|
.where({
|
||||||
|
id
|
||||||
|
})
|
||||||
|
.getOne();
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Body, Controller, Delete, Get, Post, Query } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/common';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
import { ApiResult } from '~/common/decorators/api-result.decorator';
|
import { ApiResult } from '~/common/decorators/api-result.decorator';
|
||||||
|
@ -34,6 +34,14 @@ export class DictItemController {
|
||||||
return this.dictItemService.page(dto);
|
return this.dictItemService.page(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('all/:typeId')
|
||||||
|
@ApiOperation({ summary: '一次性通过字典类型获取所有所属的字典项(不分页)' })
|
||||||
|
@ApiResult({ type: [DictItemEntity] })
|
||||||
|
@Perm(permissions.LIST)
|
||||||
|
async getAll(@Param('typeId') typeId: number): Promise<DictItemEntity[]> {
|
||||||
|
return this.dictItemService.getAllByType(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: '新增字典项' })
|
@ApiOperation({ summary: '新增字典项' })
|
||||||
@Perm(permissions.CREATE)
|
@Perm(permissions.CREATE)
|
||||||
|
@ -43,14 +51,6 @@ export class DictItemController {
|
||||||
await this.dictItemService.create(dto);
|
await this.dictItemService.create(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
@ApiOperation({ summary: '查询字典项信息' })
|
|
||||||
@ApiResult({ type: DictItemEntity })
|
|
||||||
@Perm(permissions.READ)
|
|
||||||
async info(@IdParam() id: number): Promise<DictItemEntity> {
|
|
||||||
return this.dictItemService.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post(':id')
|
@Post(':id')
|
||||||
@ApiOperation({ summary: '更新字典项' })
|
@ApiOperation({ summary: '更新字典项' })
|
||||||
@Perm(permissions.UPDATE)
|
@Perm(permissions.UPDATE)
|
||||||
|
|
|
@ -42,6 +42,11 @@ export class DictItemService {
|
||||||
return paginate(queryBuilder, { page, pageSize });
|
return paginate(queryBuilder, { page, pageSize });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 一次性获取所有的字典项 */
|
||||||
|
async getAllByType(typeId: number) {
|
||||||
|
return this.dictItemRepository.find({ where: { type: { id: typeId } } });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取参数总数
|
* 获取参数总数
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue