2025-03-11 16:15:05 +08:00
|
|
|
import { Injectable } from "@nestjs/common";
|
|
|
|
import { BaseService } from "../base/base.service";
|
|
|
|
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
|
|
|
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
2025-03-11 22:36:54 +08:00
|
|
|
import { DefaultArgs } from "@prisma/client/runtime/library";
|
|
|
|
import { StaffService } from "../staff/staff.service";
|
2025-03-11 16:15:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class TrainSituationService extends BaseService<Prisma.TrainSituationDelegate> {
|
2025-03-11 22:36:54 +08:00
|
|
|
constructor(private readonly staffService:StaffService) {
|
2025-03-11 16:15:05 +08:00
|
|
|
super(db,ObjectType.TRAIN_SITUATION,false);
|
|
|
|
}
|
2025-03-11 22:36:54 +08:00
|
|
|
// 创建培训情况
|
2025-03-11 16:15:05 +08:00
|
|
|
async create(
|
|
|
|
args: Prisma.TrainSituationCreateArgs,
|
|
|
|
){
|
|
|
|
console.log(args)
|
|
|
|
const result = await super.create(args);
|
|
|
|
this.emitDataChanged(CrudOperation.CREATED, result);
|
|
|
|
return result;
|
|
|
|
}
|
2025-03-11 22:36:54 +08:00
|
|
|
// 更新培训情况
|
|
|
|
async update(
|
|
|
|
args: Prisma.TrainSituationUpdateArgs,
|
|
|
|
){
|
|
|
|
const result = await super.update(args);
|
|
|
|
this.emitDataChanged(CrudOperation.UPDATED, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 查找培训情况
|
|
|
|
async findMany(args: Prisma.TrainSituationFindManyArgs): Promise<{
|
|
|
|
id: string;
|
|
|
|
staffId: string;
|
|
|
|
trainContentId: string;
|
|
|
|
mustTrainTime: number;
|
|
|
|
alreadyTrainTime: number;
|
|
|
|
score: number;
|
|
|
|
}[]>
|
|
|
|
{
|
|
|
|
const result = await super.findMany(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// 查找某一单位所有人员的培训情况
|
|
|
|
async findManyByDeptId(args:{
|
|
|
|
deptId?:string,
|
|
|
|
domainId?:string,
|
|
|
|
trainContentId?:string
|
|
|
|
}):Promise<{
|
|
|
|
id: string;
|
|
|
|
staffId: string;
|
|
|
|
trainContentId: string;
|
|
|
|
mustTrainTime: number;
|
|
|
|
alreadyTrainTime: number;
|
|
|
|
score: number;
|
|
|
|
}[]>
|
|
|
|
{
|
|
|
|
const staffs = await this.staffService.findByDept({deptId:args.deptId,domainId:args.domainId})
|
|
|
|
const result = await super.findMany({
|
|
|
|
where:{
|
|
|
|
staffId:{
|
|
|
|
in:staffs.map(staff=>staff.id)
|
|
|
|
},
|
|
|
|
...(args.trainContentId ? {trainContentId:args.trainContentId} : {})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
}
|
2025-03-12 08:25:08 +08:00
|
|
|
//async createDailyTrainTime()
|
|
|
|
|
2025-03-11 22:36:54 +08:00
|
|
|
// 发送数据变化事件
|
2025-03-11 16:15:05 +08:00
|
|
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
|
|
|
EventBus.emit('dataChanged', {
|
|
|
|
type:ObjectType.TRAIN_SITUATION,
|
|
|
|
operation,
|
|
|
|
data,
|
|
|
|
});
|
2025-03-12 08:25:08 +08:00
|
|
|
}
|
2025-03-11 16:15:05 +08:00
|
|
|
}
|