Merge branch 'main' of http://113.45.157.195:3003/raohaotian/train-data
This commit is contained in:
commit
02aea6ef8b
|
@ -0,0 +1,9 @@
|
||||||
|
import { Controller, UseGuards } from "@nestjs/common";
|
||||||
|
import { AuthGuard } from '@server/auth/auth.guard';
|
||||||
|
import { DailyTrainService } from "./dailyTrain.service";
|
||||||
|
|
||||||
|
@Controller('train-content')
|
||||||
|
export class DailyTrainController {
|
||||||
|
constructor(private readonly dailyTrainService: DailyTrainService) {}
|
||||||
|
//@UseGuards(AuthGuard)
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { StaffModule } from '../staff/staff.module';
|
||||||
|
import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
|
import { DailyTrainController } from './dailyTrain.controller';
|
||||||
|
import { DailyTrainService } from './dailyTrain.service';
|
||||||
|
import { DailyTrainRouter } from './dailyTrain.router';
|
||||||
|
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [StaffModule],
|
||||||
|
controllers: [DailyTrainController],
|
||||||
|
providers: [DailyTrainService,DailyTrainRouter,TrpcService],
|
||||||
|
exports: [DailyTrainService,DailyTrainRouter],
|
||||||
|
})
|
||||||
|
export class DailyTrainModule {}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { TrpcService } from "@server/trpc/trpc.service";
|
||||||
|
import { DailyTrainService } from "./dailyTrain.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyTrainRouter {
|
||||||
|
constructor(
|
||||||
|
private readonly trpc: TrpcService,
|
||||||
|
private readonly dailyTrainService: DailyTrainService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
router = this.trpc.router({
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { BaseService } from "../base/base.service";
|
||||||
|
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
||||||
|
import { DefaultArgs } from "@prisma/client/runtime/library";
|
||||||
|
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyTrainService extends BaseService<Prisma.DailyTrainTimeDelegate> {
|
||||||
|
constructor() {
|
||||||
|
super(db,ObjectType.DAILY_TRAIN,true);
|
||||||
|
}
|
||||||
|
async create(args: Prisma.DailyTrainTimeCreateArgs) {
|
||||||
|
console.log(args)
|
||||||
|
const result = await super.create(args)
|
||||||
|
this.emitDataChanged(CrudOperation.CREATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(args:Prisma.DailyTrainTimeUpdateArgs){
|
||||||
|
const result = await super.update(args)
|
||||||
|
this.emitDataChanged(CrudOperation.UPDATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async findMany(args: Prisma.DailyTrainTimeFindManyArgs) {
|
||||||
|
const result = await super.findMany(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
||||||
|
EventBus.emit('dataChanged', {
|
||||||
|
type:ObjectType.DAILY_TRAIN,
|
||||||
|
operation,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { Controller, UseGuards } from "@nestjs/common";
|
||||||
|
import { AuthGuard } from '@server/auth/auth.guard';
|
||||||
|
import { DailyTrainService } from "./dailyTrain.service";
|
||||||
|
|
||||||
|
@Controller('train-content')
|
||||||
|
export class DailyTrainController {
|
||||||
|
constructor(private readonly dailyTrainService: DailyTrainService) {}
|
||||||
|
//@UseGuards(AuthGuard)
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { StaffModule } from '../staff/staff.module';
|
||||||
|
import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
|
import { DailyTrainController } from './dailyTrain.controller';
|
||||||
|
import { DailyTrainService } from './dailyTrain.service';
|
||||||
|
import { DailyTrainRouter } from './dailyTrain.router';
|
||||||
|
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [StaffModule],
|
||||||
|
controllers: [DailyTrainController],
|
||||||
|
providers: [DailyTrainService,DailyTrainRouter,TrpcService],
|
||||||
|
exports: [DailyTrainService,DailyTrainRouter],
|
||||||
|
})
|
||||||
|
export class DailyTrainModule {}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { TrpcService } from "@server/trpc/trpc.service";
|
||||||
|
import { DailyTrainService } from "./dailyTrain.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyTrainRouter {
|
||||||
|
constructor(
|
||||||
|
private readonly trpc: TrpcService,
|
||||||
|
private readonly dailyTrainService: DailyTrainService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
router = this.trpc.router({
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { BaseService } from "../base/base.service";
|
||||||
|
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
||||||
|
import { DefaultArgs } from "@prisma/client/runtime/library";
|
||||||
|
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyTrainService extends BaseService<Prisma.DailyTrainTimeDelegate> {
|
||||||
|
constructor() {
|
||||||
|
super(db,ObjectType.DAILY_TRAIN,true);
|
||||||
|
}
|
||||||
|
async create(args: Prisma.DailyTrainTimeCreateArgs) {
|
||||||
|
console.log(args)
|
||||||
|
const result = await super.create(args)
|
||||||
|
this.emitDataChanged(CrudOperation.CREATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(args:Prisma.DailyTrainTimeUpdateArgs){
|
||||||
|
const result = await super.update(args)
|
||||||
|
this.emitDataChanged(CrudOperation.UPDATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async findMany(args: Prisma.DailyTrainTimeFindManyArgs) {
|
||||||
|
const result = await super.findMany(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
||||||
|
EventBus.emit('dataChanged', {
|
||||||
|
type:ObjectType.DAILY_TRAIN,
|
||||||
|
operation,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { BaseService } from "../base/base.service";
|
import { BaseService } from "../base/base.service";
|
||||||
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
||||||
|
import { DefaultArgs } from "@prisma/client/runtime/library";
|
||||||
|
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -8,5 +10,31 @@ export class TrainContentService extends BaseService<Prisma.TrainContentDelegate
|
||||||
constructor() {
|
constructor() {
|
||||||
super(db,ObjectType.TRAIN_CONTENT,true);
|
super(db,ObjectType.TRAIN_CONTENT,true);
|
||||||
}
|
}
|
||||||
|
async create(args: Prisma.TrainContentCreateArgs) {
|
||||||
|
console.log(args)
|
||||||
|
const result = await super.create(args)
|
||||||
|
this.emitDataChanged(CrudOperation.CREATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(args:Prisma.TrainContentUpdateArgs){
|
||||||
|
const result = await super.update(args)
|
||||||
|
this.emitDataChanged(CrudOperation.UPDATED,result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async findMany(args: Prisma.TrainContentFindManyArgs) {
|
||||||
|
const result = await super.findMany(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
||||||
|
EventBus.emit('dataChanged', {
|
||||||
|
type:ObjectType.TRAIN_SITUATION,
|
||||||
|
operation,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import { TrainSituationController } from './trainSituation.controller';
|
||||||
import { TrainSituationRouter } from './trainSituation.router';
|
import { TrainSituationRouter } from './trainSituation.router';
|
||||||
import { TrpcService } from '@server/trpc/trpc.service';
|
import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [StaffModule],
|
imports: [StaffModule],
|
||||||
controllers: [TrainSituationController],
|
controllers: [TrainSituationController],
|
||||||
|
|
|
@ -5,7 +5,8 @@ import { z, ZodType } from "zod";
|
||||||
import { Prisma } from "@nice/common";
|
import { Prisma } from "@nice/common";
|
||||||
|
|
||||||
const TrainSituationArgsSchema:ZodType<Prisma.TrainSituationCreateArgs> = z.any()
|
const TrainSituationArgsSchema:ZodType<Prisma.TrainSituationCreateArgs> = z.any()
|
||||||
|
const TrainSituationUpdateArgsSchema:ZodType<Prisma.TrainSituationUpdateArgs> = z.any()
|
||||||
|
const TrainSituationFindManyArgsSchema:ZodType<Prisma.TrainSituationFindManyArgs> = z.any()
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrainSituationRouter {
|
export class TrainSituationRouter {
|
||||||
|
@ -18,8 +19,27 @@ export class TrainSituationRouter {
|
||||||
create:this.trpc.protectProcedure
|
create:this.trpc.protectProcedure
|
||||||
.input(TrainSituationArgsSchema)
|
.input(TrainSituationArgsSchema)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
this.trainSituationService.create(input)
|
return this.trainSituationService.create(input)
|
||||||
}),
|
}),
|
||||||
|
update:this.trpc.protectProcedure
|
||||||
|
.input(TrainSituationUpdateArgsSchema)
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
return this.trainSituationService.update(input)
|
||||||
|
}),
|
||||||
|
findMany:this.trpc.protectProcedure
|
||||||
|
.input(TrainSituationFindManyArgsSchema)
|
||||||
|
.mutation(async ({input}) =>{
|
||||||
|
return this.trainSituationService.findMany(input)
|
||||||
|
}),
|
||||||
|
findManyByDepId:this.trpc.protectProcedure
|
||||||
|
.input(z.object({
|
||||||
|
deptId: z.string().optional(),
|
||||||
|
domainId: z.string().optional(),
|
||||||
|
trainContentId: z.string().optional()
|
||||||
|
}))
|
||||||
|
.mutation(async ({input}) => {
|
||||||
|
return this.trainSituationService.findManyByDeptId(input)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,13 +2,16 @@ import { Injectable } from "@nestjs/common";
|
||||||
import { BaseService } from "../base/base.service";
|
import { BaseService } from "../base/base.service";
|
||||||
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
import { db, ObjectType, Prisma, UserProfile } from "@nice/common";
|
||||||
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
import EventBus, { CrudOperation } from "@server/utils/event-bus";
|
||||||
|
import { DefaultArgs } from "@prisma/client/runtime/library";
|
||||||
|
import { StaffService } from "../staff/staff.service";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrainSituationService extends BaseService<Prisma.TrainSituationDelegate> {
|
export class TrainSituationService extends BaseService<Prisma.TrainSituationDelegate> {
|
||||||
constructor() {
|
constructor(private readonly staffService:StaffService) {
|
||||||
super(db,ObjectType.TRAIN_SITUATION,false);
|
super(db,ObjectType.TRAIN_SITUATION,false);
|
||||||
}
|
}
|
||||||
|
// 创建培训情况
|
||||||
async create(
|
async create(
|
||||||
args: Prisma.TrainSituationCreateArgs,
|
args: Prisma.TrainSituationCreateArgs,
|
||||||
){
|
){
|
||||||
|
@ -17,7 +20,56 @@ export class TrainSituationService extends BaseService<Prisma.TrainSituationDele
|
||||||
this.emitDataChanged(CrudOperation.CREATED, result);
|
this.emitDataChanged(CrudOperation.CREATED, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
// 更新培训情况
|
||||||
|
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
|
||||||
|
}
|
||||||
|
//async createDailyTrainTime()
|
||||||
|
|
||||||
|
// 发送数据变化事件
|
||||||
private emitDataChanged(operation: CrudOperation, data: any) {
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
||||||
EventBus.emit('dataChanged', {
|
EventBus.emit('dataChanged', {
|
||||||
type:ObjectType.TRAIN_SITUATION,
|
type:ObjectType.TRAIN_SITUATION,
|
||||||
|
|
|
@ -49,10 +49,11 @@ export class GenDevService {
|
||||||
try {
|
try {
|
||||||
await this.calculateCounts();
|
await this.calculateCounts();
|
||||||
await this.generateDepartments(3, 6);
|
await this.generateDepartments(3, 6);
|
||||||
await this.generateTerms(2, 6);
|
//await this.generateTerms(2, 6);
|
||||||
await this.generateStaffs(4);
|
await this.generateStaffs(4);
|
||||||
await this.generateCourses(8);
|
//await this.generateCourses(8);
|
||||||
await this.generateTrainContent(2,6)
|
await this.generateTrainContent(2,6)
|
||||||
|
await this.generateTrainSituations()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +210,7 @@ export class GenDevService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async generateStaffs(countPerDept: number = 3) {
|
private async generateStaffs(countPerDept: number = 2) {
|
||||||
if (this.counts.staffCount === 1) {
|
if (this.counts.staffCount === 1) {
|
||||||
this.logger.log('Generating staffs...');
|
this.logger.log('Generating staffs...');
|
||||||
// Calculate the total number of staffs to be generated
|
// Calculate the total number of staffs to be generated
|
||||||
|
@ -344,7 +345,7 @@ export class GenDevService {
|
||||||
|
|
||||||
await createTermTree(null, 1);
|
await createTermTree(null, 1);
|
||||||
}
|
}
|
||||||
|
// 生成培训内容
|
||||||
private async createTrainContent(
|
private async createTrainContent(
|
||||||
type:string,
|
type:string,
|
||||||
title:string,
|
title:string,
|
||||||
|
@ -359,7 +360,7 @@ export class GenDevService {
|
||||||
});
|
});
|
||||||
return trainContent;
|
return trainContent;
|
||||||
}
|
}
|
||||||
|
// 生成培训内容
|
||||||
private async generateTrainContent(depth:number=3,count:number=6){
|
private async generateTrainContent(depth:number=3,count:number=6){
|
||||||
if(this.counts.trainContentCount !== 0) return;
|
if(this.counts.trainContentCount !== 0) return;
|
||||||
const totalTrainContent = this.calculateTotalTrainContent(depth,count)
|
const totalTrainContent = this.calculateTotalTrainContent(depth,count)
|
||||||
|
@ -368,6 +369,7 @@ export class GenDevService {
|
||||||
this.trainContents = await db.trainContent.findMany()
|
this.trainContents = await db.trainContent.findMany()
|
||||||
this.logger.log(`Completed: Generated ${this.trainContents.length} departments.`);
|
this.logger.log(`Completed: Generated ${this.trainContents.length} departments.`);
|
||||||
}
|
}
|
||||||
|
// 生成培训内容子内容
|
||||||
private async generateSubTrainContent(
|
private async generateSubTrainContent(
|
||||||
parentId: string | null,
|
parentId: string | null,
|
||||||
currentDepth:number,
|
currentDepth:number,
|
||||||
|
@ -404,4 +406,47 @@ export class GenDevService {
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async createTrainSituation(staffId:string,trainContentId:string){
|
||||||
|
const trainSituation = await db.trainSituation.create({
|
||||||
|
data:{
|
||||||
|
staffId,
|
||||||
|
trainContentId,
|
||||||
|
mustTrainTime:Math.floor(Math.random()*100),
|
||||||
|
alreadyTrainTime:Math.floor(Math.random()*100),
|
||||||
|
score:Math.floor(Math.random()*100),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return trainSituation
|
||||||
|
}
|
||||||
|
|
||||||
|
private async generateTrainSituations(probability: number = 0.7){
|
||||||
|
this.logger.log("Start generating train situations...")
|
||||||
|
const allTrainContents = await db.trainContent.findMany();
|
||||||
|
// 这里相当于两次遍历 找到没有parentID的即是
|
||||||
|
const leafNodes = allTrainContents.filter((item)=>item.parentId !== null)
|
||||||
|
console.log(leafNodes.length)
|
||||||
|
const staffs = await db.staff.findMany()
|
||||||
|
|
||||||
|
let situationCount = 0
|
||||||
|
const totalPossibleSituations = leafNodes.length * staffs.length
|
||||||
|
|
||||||
|
for (const staff of staffs){
|
||||||
|
for(const leaf of leafNodes){
|
||||||
|
if(Math.random() < probability){
|
||||||
|
await this.createTrainSituation(staff.id,leaf.id)
|
||||||
|
situationCount++
|
||||||
|
if (situationCount % 100 === 0) {
|
||||||
|
this.logger.log(
|
||||||
|
`Generated ${situationCount} train situations`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.logger.log(
|
||||||
|
`Completed: Generated ${situationCount} train situations out of ${totalPossibleSituations} possible combinations.`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ import { TransformModule } from '@server/models/transform/transform.module';
|
||||||
import { TrainContentModule } from '@server/models/train-content/trainContent.module';
|
import { TrainContentModule } from '@server/models/train-content/trainContent.module';
|
||||||
import { ResourceModule } from '@server/models/resource/resource.module';
|
import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
import { TrainSituationModule } from '@server/models/train-situation/trainSituation.module';
|
import { TrainSituationModule } from '@server/models/train-situation/trainSituation.module';
|
||||||
|
import { DailyTrainModule } from '@server/models/daily-train/dailyTrain.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
AuthModule,
|
AuthModule,
|
||||||
|
@ -35,7 +35,8 @@ import { TrainSituationModule } from '@server/models/train-situation/trainSituat
|
||||||
WebSocketModule,
|
WebSocketModule,
|
||||||
ResourceModule,
|
ResourceModule,
|
||||||
TrainContentModule,
|
TrainContentModule,
|
||||||
TrainSituationModule
|
TrainSituationModule,
|
||||||
|
DailyTrainModule
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [TrpcService, TrpcRouter, Logger],
|
providers: [TrpcService, TrpcRouter, Logger],
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { RoleRouter } from '@server/models/rbac/role.router';
|
||||||
import { ResourceRouter } from '../models/resource/resource.router';
|
import { ResourceRouter } from '../models/resource/resource.router';
|
||||||
import { TrainContentRouter } from '@server/models/train-content/trainContent.router';
|
import { TrainContentRouter } from '@server/models/train-content/trainContent.router';
|
||||||
import { TrainSituationRouter } from '@server/models/train-situation/trainSituation.router';
|
import { TrainSituationRouter } from '@server/models/train-situation/trainSituation.router';
|
||||||
|
import { DailyTrainRouter } from '@server/models/daily-train/dailyTrain.router';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrpcRouter {
|
export class TrpcRouter {
|
||||||
|
@ -36,6 +37,7 @@ export class TrpcRouter {
|
||||||
private readonly resource: ResourceRouter,
|
private readonly resource: ResourceRouter,
|
||||||
private readonly trainContent: TrainContentRouter,
|
private readonly trainContent: TrainContentRouter,
|
||||||
private readonly trainSituation:TrainSituationRouter,
|
private readonly trainSituation:TrainSituationRouter,
|
||||||
|
private readonly dailyTrain:DailyTrainRouter
|
||||||
) {}
|
) {}
|
||||||
getRouter() {
|
getRouter() {
|
||||||
return;
|
return;
|
||||||
|
@ -54,7 +56,8 @@ export class TrpcRouter {
|
||||||
visitor: this.visitor.router,
|
visitor: this.visitor.router,
|
||||||
resource: this.resource.router,
|
resource: this.resource.router,
|
||||||
trainContent:this.trainContent.router,
|
trainContent:this.trainContent.router,
|
||||||
trainSituation:this.trainSituation.router
|
trainSituation:this.trainSituation.router,
|
||||||
|
dailyTrain:this.dailyTrain.router
|
||||||
});
|
});
|
||||||
wss: WebSocketServer = undefined;
|
wss: WebSocketServer = undefined;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,15 @@ export function useTrainSituation(){
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const update = api.trainSituation.update.useMutation({
|
||||||
|
onSuccess:(res:any)=>{
|
||||||
|
queryClient.invalidateQueries({queryKey});
|
||||||
|
emitDataChange(ObjectType.TRAIN_SITUATION,res,CrudOperation.UPDATED)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create
|
create,
|
||||||
|
update
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -360,12 +360,23 @@ model TrainSituation {
|
||||||
trainContent TrainContent @relation(fields: [trainContentId], references: [id])
|
trainContent TrainContent @relation(fields: [trainContentId], references: [id])
|
||||||
|
|
||||||
score Float @default(0.0) @map("score")
|
score Float @default(0.0) @map("score")
|
||||||
mustTrainTime String @map("must_train_time")
|
mustTrainTime Float @map("must_train_time")
|
||||||
alreadyTrainTime String @map("already_train_time")
|
alreadyTrainTime Float @map("already_train_time")
|
||||||
|
dailyTrainTime DailyTrainTime[] @relation("DailyTrainSituation")
|
||||||
|
|
||||||
@@map("train_situation")
|
@@map("train_situation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model DailyTrainTime {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
trainSituationId String @map("train_situatio_id")
|
||||||
|
trainSituation TrainSituation @relation("DailyTrainSituation", fields: [trainSituationId], references: [id])
|
||||||
|
trainTime Float @default(0.0) @map("trainTime")
|
||||||
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
|
||||||
|
@@map("daily_train_situation")
|
||||||
|
}
|
||||||
|
|
||||||
model Position {
|
model Position {
|
||||||
id String @id @default(cuid()) @map("id")
|
id String @id @default(cuid()) @map("id")
|
||||||
type String @map("type")
|
type String @map("type")
|
||||||
|
|
|
@ -60,7 +60,8 @@ export enum ObjectType {
|
||||||
ENROLLMENT = "enrollment",
|
ENROLLMENT = "enrollment",
|
||||||
RESOURCE = "resource",
|
RESOURCE = "resource",
|
||||||
TRAIN_CONTENT = "trainContent",
|
TRAIN_CONTENT = "trainContent",
|
||||||
TRAIN_SITUATION = "trainSituation"
|
TRAIN_SITUATION = "trainSituation",
|
||||||
|
DAILY_TRAIN = "dailyTrainTime"
|
||||||
}
|
}
|
||||||
export enum RolePerms {
|
export enum RolePerms {
|
||||||
// Create Permissions 创建权限
|
// Create Permissions 创建权限
|
||||||
|
|
|
@ -135,3 +135,35 @@ export const lectureDetailSelect: Prisma.PostSelect = {
|
||||||
|
|
||||||
meta: true,
|
meta: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const trainSituationDetailSelect: Prisma.TrainSituationSelect = {
|
||||||
|
id: true,
|
||||||
|
staffId: true,
|
||||||
|
trainContentId: true,
|
||||||
|
mustTrainTime: true,
|
||||||
|
alreadyTrainTime: true,
|
||||||
|
score: true,
|
||||||
|
staff: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
showname: true,
|
||||||
|
avatar: true,
|
||||||
|
department: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
age: true,
|
||||||
|
sex: true,
|
||||||
|
absent: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
trainContent: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue