Browse Source

修改用户2025年度已学时

zs 9 months ago
parent
commit
0d6268327a

+ 1 - 1
src/controller/system/user.controller.ts

@@ -36,7 +36,7 @@ export class UserController extends BaseController {
   @Get('/:id')
   @Get('/:id')
   @ApiResponse({ type: FVO_user })
   @ApiResponse({ type: FVO_user })
   async fetch(@Param('id') id: string) {
   async fetch(@Param('id') id: string) {
-    const data = await this.service.fetch(id);
+    const data = await this.service.detail(id);
     const result = new FVO_user(data);
     const result = new FVO_user(data);
     return result;
     return result;
   }
   }

+ 2 - 0
src/entity/system/user.entity.ts

@@ -31,6 +31,8 @@ export class User extends BaseModel {
   email: string;
   email: string;
   @prop({ required: false, index: false, zh: '角色' })
   @prop({ required: false, index: false, zh: '角色' })
   role: string;
   role: string;
+  @prop({ required: false, index: true, zh: '观看学时' })
+  hour: string;
   @prop({ required: false, index: true, zh: '状态', default: '1' })
   @prop({ required: false, index: true, zh: '状态', default: '1' })
   status: string;
   status: string;
 }
 }

+ 5 - 0
src/interface/system/user.interface.ts

@@ -30,6 +30,8 @@ export class FVO_user {
   'role_type': string = undefined;
   'role_type': string = undefined;
   @ApiProperty({ description: '角色' })
   @ApiProperty({ description: '角色' })
   'role': string = undefined;
   'role': string = undefined;
+  @ApiProperty({ description: '总学时' })
+  'hour': string = undefined;
   @ApiProperty({ description: '状态' })
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
   'status': string = undefined;
 }
 }
@@ -82,6 +84,9 @@ export class CDTO_user {
   @ApiProperty({ description: '角色' })
   @ApiProperty({ description: '角色' })
   @Rule(RuleType['string']().empty(''))
   @Rule(RuleType['string']().empty(''))
   'role': string = undefined;
   'role': string = undefined;
+  @ApiProperty({ description: '总学时' })
+  @Rule(RuleType['string']().empty(''))
+  'hour': string = undefined;
   @ApiProperty({ description: '状态' })
   @ApiProperty({ description: '状态' })
   @Rule(RuleType['string']().empty(''))
   @Rule(RuleType['string']().empty(''))
   'status': string = undefined;
   'status': string = undefined;

+ 17 - 0
src/service/system/user.service.ts

@@ -5,12 +5,16 @@ import { BaseService, ServiceError } from 'free-midway-component';
 import { User } from '../../entity/system/user.entity';
 import { User } from '../../entity/system/user.entity';
 import { I18nService } from '../i18n.service';
 import { I18nService } from '../i18n.service';
 import { FrameErrorEnum } from '../../error/frame.error';
 import { FrameErrorEnum } from '../../error/frame.error';
+import { Record } from '../../entity/core/record.entity';
 type modelType = ReturnModelType<typeof User>;
 type modelType = ReturnModelType<typeof User>;
 @Provide()
 @Provide()
 export class UserService extends BaseService<modelType> {
 export class UserService extends BaseService<modelType> {
   @InjectEntityModel(User)
   @InjectEntityModel(User)
   model: modelType;
   model: modelType;
 
 
+  @InjectEntityModel(Record)
+  rModel: ReturnModelType<typeof Record>;
+
   @Inject()
   @Inject()
   i18n: I18nService;
   i18n: I18nService;
 
 
@@ -21,4 +25,17 @@ export class UserService extends BaseService<modelType> {
     if (user && user._id) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.USER_EXIST), FrameErrorEnum.USER_EXIST);
     if (user && user._id) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.USER_EXIST), FrameErrorEnum.USER_EXIST);
     return data;
     return data;
   }
   }
+
+  // 查询用户详情
+  async detail(id) {
+    const course = await this.rModel.find({ user_id: id }, { hour: 1 }).lean();
+    const numbers = [];
+    for (const val of course) {
+      numbers.push(parseInt(val.hour) || 0);
+    }
+    const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
+    await this.model.updateOne({ _id: id }, { hour: sum });
+    const user = await this.model.findById(id).lean();
+    return user;
+  }
 }
 }