import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { ArchiveTask } from './entity/archiveTask.entity'; import { Repository } from 'typeorm'; @Injectable() export class AppService { constructor( @InjectRepository(ArchiveTask) private readonly archiveTaskRepository: Repository, ) {} async createArchiveTask(payload) { const { username, study } = payload; try { // 跳过的数据 const ignore = []; for (let i = 0; i < study.length; i++) { const { StudyInstanceUID, PatientID } = study[i]; for (let j = 0; j < study[i].subs.length; j++) { const { SeriesInstanceUID } = study[i].subs[j]; // 检查是否病已经分配过 const exist = await this.archiveTaskRepository.findOne({ where: { username, StudyInstanceUID, SeriesInstanceUID }, }); exist ? ignore.push(exist) : await this.archiveTaskRepository.save({ username, PatientID, StudyInstanceUID, SeriesInstanceUID, }); } } return { success: true, data: { ignore } }; } catch (error) { return { success: false, error }; } } async findArchiveTask({ username }) { return await this.archiveTaskRepository.find({ where: { username }, order: { createTime: 'DESC' }, }); } }