Browse Source

Merge branch 'master' of http://git.cc-lotus.info/videoDemand/video_server

lrf 10 months ago
parent
commit
7bd196b96d

+ 1 - 1
src/config/config.default.ts

@@ -4,7 +4,7 @@ export default {
   // use for cookie sign key, should change to your own and keep security
   keys: '1706233305258_2249',
   koa: {
-    port: 20001,
+    port: 19000,
   },
   // 请求记录在redis留存时间,超过时间.数据变化将不会记录.以秒为单位--5分钟
   requestTimeLimit: 300,

+ 2 - 2
src/config/config.local.ts

@@ -1,6 +1,6 @@
 import { MidwayConfig } from '@midwayjs/core';
-const ip = '127.0.0.1'; //120.48.146.1
-const redisHost = '127.0.0.1';
+const ip = '120.48.146.1'; //120.48.146.1
+const redisHost = '120.48.146.1';
 const redisPwd = '123456';
 const redisDB = 6;
 const projectDB = 'video';

+ 2 - 2
src/config/config.prod.ts

@@ -31,7 +31,7 @@ export default {
         },
         entities: ['./entity'],
       },
-      record:{
+      record: {
         uri: `mongodb://${ip}:27017/${recordDB}`,
         options: {
           user: 'admin',
@@ -40,7 +40,7 @@ export default {
           useNewUrlParser: true,
         },
         entities: ['./entityRecord'],
-      }
+      },
     },
   },
   redis: {

+ 74 - 0
src/controller/core/course.controller.ts

@@ -0,0 +1,74 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { CourseService } from '../../service/core/course.service';
+import { CDTO_course, CVO_course, FVO_course, QDTO_course, QVO_course, UDTO_course, UVAO_course } from '../../interface/core/course.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['课程表'])
+@Controller('/course')
+export class CourseController extends BaseController {
+  @Inject()
+  service: CourseService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_course })
+  async create(@Body() data: CDTO_course) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_course(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_course })
+  async query(@Query() filter: QDTO_course, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_course(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/list')
+  async list() {
+    const data = await this.service.list();
+    return data;
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_course })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_course(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_course })
+  async update(@Param('id') id: string, @Body() body: UDTO_course) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 29 - 0
src/entity/core/course.entity.ts

@@ -0,0 +1,29 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'course' },
+})
+export class Course extends BaseModel {
+  @prop({ required: false, index: true, zh: '年度' })
+  year: string;
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: true, zh: '课程类型' })
+  brand: string;
+  @prop({ required: false, index: false, zh: '封面' })
+  logo: Array<any>;
+  @prop({ required: false, index: false, zh: '总学时' })
+  hour: string;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: string;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: false, zh: '内容' })
+  content: string;
+  @prop({ required: false, index: true, zh: '是否使用', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态', default: '0' })
+  status: string;
+}

+ 6 - 0
src/entity/core/record.entity.ts

@@ -6,10 +6,16 @@ import { BaseModel } from 'free-midway-component';
 export class Record extends BaseModel {
   @prop({ required: false, index: true, zh: '用户id' })
   user_id: string;
+  @prop({ required: false, index: true, zh: '课程id' })
+  course_id: string;
   @prop({ required: false, index: true, zh: '视频id' })
   video_id: string;
   @prop({ required: false, index: true, zh: '观看时长' })
   time: string;
+  @prop({ required: false, index: true, zh: '总时长' })
+  total_time: string;
+  @prop({ required: false, index: true, zh: '观看学时' })
+  hour: string;
   @prop({ required: false, index: false, zh: '开始时间' })
   start_time: string;
   @prop({ required: false, index: false, zh: '结束时间' })

+ 8 - 4
src/entity/core/video.entity.ts

@@ -4,24 +4,28 @@ import { BaseModel } from 'free-midway-component';
   schemaOptions: { collection: 'video' },
 })
 export class Video extends BaseModel {
+  @prop({ required: false, index: true, zh: '课程id' })
+  course: string;
   @prop({ required: false, index: true, zh: '标题' })
   title: string;
   @prop({ required: false, index: false, zh: '简介' })
   brief: string;
   @prop({ required: false, index: false, zh: '视频来源' })
   sourse: string;
-  @prop({ required: false, index: false, zh: '类型' })
+  @prop({ required: false, index: true, zh: '类型' })
   type: string;
   @prop({ required: false, index: false, zh: '封面' })
   logo: Array<any>;
   @prop({ required: false, index: false, zh: '视频' })
   file: Array<any>;
-  @prop({ required: false, index: true, zh: '播放次数', default: 0 })
+  @prop({ required: false, index: false, zh: '学时' })
+  hour: string;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: string;
+  @prop({ required: false, index: true, zh: '播放次数' })
   number: number;
   @prop({ required: false, index: false, zh: '内容' })
   content: string;
-  @prop({ required: false, index: false, zh: '发布时间' })
-  time: string;
   @prop({ required: false, index: true, zh: '是否使用', default: '0' })
   is_use: string;
   @prop({ required: false, index: false, zh: '状态', default: '0' })

+ 1 - 0
src/error/frame.error.ts

@@ -12,5 +12,6 @@ export enum ErrorCode {
   USER_IS_DISABLED = '401-6',
   ROLE_IS_DISABLED = '401-7',
   SERVICE_REPEAT = '401-8',
+  USER_EXIST = '401-9',
 }
 export const FrameErrorEnum = registerErrorCode('FrameError', ErrorCode);

+ 125 - 0
src/interface/core/course.interface.ts

@@ -0,0 +1,125 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_course {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '年度' })
+  'year': string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '课程类型' })
+  'brand': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '封面' })
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '总学时' })
+  'hour': string = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '内容' })
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_course extends SearchBase {
+  constructor() {
+    const like_prop = ['title'];
+    const props = ['year', 'type', 'brand', 'title', 'time', 'is_use', 'status'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '年度' })
+  'year': string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '课程类型' })
+  'brand': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_course extends FVO_course {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_course {
+  @ApiProperty({ description: '年度' })
+  @Rule(RuleType['string']().empty(''))
+  'year': string = undefined;
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '课程类型' })
+  @Rule(RuleType['string']().empty(''))
+  'brand': string = undefined;
+  @ApiProperty({ description: '封面' })
+  @Rule(RuleType['array']().empty(''))
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '总学时' })
+  @Rule(RuleType['string']().empty(''))
+  'hour': string = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '内容' })
+  @Rule(RuleType['string']().empty(''))
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_course extends FVO_course {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_course extends CDTO_course {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_course extends FVO_course {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 20 - 1
src/interface/core/record.interface.ts

@@ -16,10 +16,16 @@ export class FVO_record {
   _id: string = undefined;
   @ApiProperty({ description: '用户id' })
   'user_id': string = undefined;
+  @ApiProperty({ description: '课程id' })
+  'course_id': string = undefined;
   @ApiProperty({ description: '视频id' })
   'video_id': string = undefined;
   @ApiProperty({ description: '观看时长' })
   'time': string = undefined;
+  @ApiProperty({ description: '总时长' })
+  'total_time': string = undefined;
+  @ApiProperty({ description: '学时' })
+  'hour': string = undefined;
   @ApiProperty({ description: '开始时间' })
   'start_time': string = undefined;
   @ApiProperty({ description: '结束时间' })
@@ -29,16 +35,20 @@ export class FVO_record {
 export class QDTO_record extends SearchBase {
   constructor() {
     const like_prop = [];
-    const props = ['user_id', 'video_id', 'time'];
+    const props = ['user_id', 'course_id', 'video_id', 'total_time', 'time'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
+  @ApiProperty({ description: '课程id' })
+  'course_id': string = undefined;
   @ApiProperty({ description: '用户id' })
   'user_id': string = undefined;
   @ApiProperty({ description: '视频id' })
   'video_id': string = undefined;
   @ApiProperty({ description: '观看时长' })
   'time': string = undefined;
+  @ApiProperty({ description: '总时长' })
+  'total_time': string = undefined;
 }
 
 export class QVO_record extends FVO_record {
@@ -55,9 +65,18 @@ export class CDTO_record {
   @ApiProperty({ description: '视频id' })
   @Rule(RuleType['string']().empty(''))
   'video_id': string = undefined;
+  @ApiProperty({ description: '课程id' })
+  @Rule(RuleType['string']().empty(''))
+  'course_id': string = undefined;
+  @ApiProperty({ description: '学时' })
+  @Rule(RuleType['string']().empty(''))
+  'hour': string = undefined;
   @ApiProperty({ description: '观看时长' })
   @Rule(RuleType['string']().empty(''))
   'time': string = undefined;
+  @ApiProperty({ description: '总时长' })
+  @Rule(RuleType['string']().empty(''))
+  'total_time': string = undefined;
   @ApiProperty({ description: '开始时间' })
   @Rule(RuleType['string']().empty(''))
   'start_time': string = undefined;

+ 20 - 4
src/interface/core/video.interface.ts

@@ -14,6 +14,8 @@ export class FVO_video {
   }
   @ApiProperty({ description: '数据id' })
   _id: string = undefined;
+  @ApiProperty({ description: '课程id' })
+  'course': string = undefined;
   @ApiProperty({ description: '标题' })
   'title': string = undefined;
   @ApiProperty({ description: '简介' })
@@ -26,6 +28,8 @@ export class FVO_video {
   'logo': Array<any> = undefined;
   @ApiProperty({ description: '视频' })
   'file': Array<any> = undefined;
+  @ApiProperty({ description: '学时' })
+  'hour': string = undefined;
   @ApiProperty({ description: '播放次数' })
   'number': number = undefined;
   @ApiProperty({ description: '内容' })
@@ -41,12 +45,18 @@ export class FVO_video {
 export class QDTO_video extends SearchBase {
   constructor() {
     const like_prop = ['title'];
-    const props = ['title', 'number', 'type', 'is_use'];
+    const props = ['course', 'type', 'title', 'time', 'number', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
+  @ApiProperty({ description: '课程id' })
+  'course': string = undefined;
   @ApiProperty({ description: '标题' })
   'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
   @ApiProperty({ description: '播放次数' })
   'number': number = undefined;
   @ApiProperty({ description: '是否使用' })
@@ -61,6 +71,9 @@ export class QVO_video extends FVO_video {
 }
 
 export class CDTO_video {
+  @ApiProperty({ description: '课程id' })
+  @Rule(RuleType['string']().empty(''))
+  'course': string = undefined;
   @ApiProperty({ description: '标题' })
   @Rule(RuleType['string']().empty(''))
   'title': string = undefined;
@@ -70,6 +83,9 @@ export class CDTO_video {
   @ApiProperty({ description: '视频来源' })
   @Rule(RuleType['string']().empty(''))
   'sourse': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
   @ApiProperty({ description: '类型' })
   @Rule(RuleType['string']().empty(''))
   'type': string = undefined;
@@ -79,15 +95,15 @@ export class CDTO_video {
   @ApiProperty({ description: '视频' })
   @Rule(RuleType['array']().empty(''))
   'file': Array<any> = undefined;
+  @ApiProperty({ description: '学时' })
+  @Rule(RuleType['string']().empty(''))
+  'hour': string = undefined;
   @ApiProperty({ description: '播放次数' })
   @Rule(RuleType['number']().empty(''))
   'number': number = undefined;
   @ApiProperty({ description: '内容' })
   @Rule(RuleType['string']().empty(''))
   'content': string = undefined;
-  @ApiProperty({ description: '发布时间' })
-  @Rule(RuleType['string']().empty(''))
-  'time': string = undefined;
   @ApiProperty({ description: '是否使用' })
   @Rule(RuleType['string']().empty(''))
   'is_use': string = undefined;

+ 1 - 0
src/locales/zh_cn/errors.ts

@@ -24,6 +24,7 @@ const codes = {
   '401-6': '该用户已被禁用',
   '401-7': '当前角色下的用户无法使用',
   '401-8': '该比赛已报名请勿重复报名!',
+  '401-9': '该用户账号已存在请勿重复填写!',
 };
 const errCodes = {};
 const prefix = 'FRAMEERROR_';

+ 9 - 7
src/middleware/setLocaleToCtx.middleware.ts

@@ -7,13 +7,15 @@ export class SetLocaleToCtxMiddleware implements IMiddleware<Context, NextFuncti
   resolve() {
     return async (ctx: Context, next: NextFunction) => {
       const cookies = ctx.request.headers.cookie;
-      let arr = cookies.split(';');
-      arr = arr.filter(f => f.includes('locale='));
-      // 没找到locale就默认使用中文
-      if (arr.length <= 0) arr = ['locale=zh-cn'];
-      const a2 = head(arr).split('=');
-      const locale = last(a2);
-      ctx.locale = locale;
+      if (cookies) {
+        let arr = cookies.split(';');
+        arr = arr.filter(f => f.includes('locale='));
+        // 没找到locale就默认使用中文
+        if (arr.length <= 0) arr = ['locale=zh-cn'];
+        const a2 = head(arr).split('=');
+        const locale = last(a2);
+        ctx.locale = locale;
+      }
       await next();
     };
   }

+ 42 - 0
src/service/core/course.service.ts

@@ -0,0 +1,42 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Course } from '../../entity/core/course.entity';
+type modelType = ReturnModelType<typeof Course>;
+@Provide()
+export class CourseService extends BaseService<modelType> {
+  @InjectEntityModel(Course)
+  model: modelType;
+
+   // 首页查询
+   async list() {
+    const one = { type: '0', is_use: '0', status: '1' };
+    const two = { type: '1', is_use: '0', status: '1' };
+    const thr = { type: '2', is_use: '0', status: '1' };
+    const four = { type: '3', is_use: '0', status: '1' };
+    const five = { type: '4', is_use: '0', status: '1' };
+    let data;
+    data = await this.model.find(one).skip(0).limit(7).lean();
+    const oneInfo = data[0] || {};
+    const oneList = data.slice(1, 7) || [];
+    const oneTotal = await this.model.count(one);
+    data = await this.model.find(two).skip(0).limit(7).lean();
+    const twoInfo = data[0]|| {};
+    const twoList = data.slice(1, 7)|| [];
+    const twoTotal = await this.model.count(two);
+    data = await this.model.find(thr).skip(0).limit(7).lean();
+    const thrInfo = data[0]|| {};
+    const thrList = data.slice(1, 7)|| [];
+    const thrTotal = await this.model.count(thr);
+    data = await this.model.find(four).skip(0).limit(7).lean();
+    const fourInfo = data[0]|| {};
+    const fourList = data.slice(1, 7)|| [];
+    const fourTotal = await this.model.count(four);
+    data = await this.model.find(five).skip(0).limit(7).lean();
+    const fiveInfo = data[0]|| {};
+    const fiveList = data.slice(1, 7)|| [];
+    const fiveTotal = await this.model.count(five);
+    return { oneInfo, oneList, oneTotal, twoInfo, twoList, twoTotal, thrInfo, thrList, thrTotal, fourInfo, fourList, fourTotal, fiveInfo, fiveList, fiveTotal };
+  }
+}

+ 21 - 3
src/service/core/record.service.ts

@@ -6,6 +6,7 @@ import { Record } from '../../entity/core/record.entity';
 import { get } from 'lodash';
 import { Video } from '../../entity/core/video.entity';
 import { User } from '../../entity/system/user.entity';
+import { Course } from '../../entity/core/course.entity';
 type modelType = ReturnModelType<typeof Record>;
 @Provide()
 export class RecordService extends BaseService<modelType> {
@@ -15,10 +16,12 @@ export class RecordService extends BaseService<modelType> {
   vModel: ReturnModelType<typeof Video>;
   @InjectEntityModel(User)
   uModel: ReturnModelType<typeof User>;
+  @InjectEntityModel(Course)
+  cModel: ReturnModelType<typeof Course>;
 
   // 特殊查询
   async special(filter) {
-    const { skip = 0, limit = 0, user_name, video_name, ...info } = filter;
+    const { skip = 0, limit = 0, user_name, video_name, course_name, ...info } = filter;
     if (user_name) {
       const userData = await this.uModel.findOne({ nick_name: user_name }).lean();
       if (userData) info.user_id = get(userData, '_id');
@@ -27,6 +30,10 @@ export class RecordService extends BaseService<modelType> {
       const videoData = await this.vModel.findOne({ title: { $regex: video_name } }).lean();
       if (videoData) info.video_id = get(videoData, '_id');
     }
+    if (video_name) {
+      const courseData = await this.cModel.findOne({ title: { $regex: course_name } }).lean();
+      if (courseData) info.course_id = get(courseData, '_id');
+    }
     const data = await this.model.find(info).skip(skip).limit(limit).lean();
     for (const val of data) {
       if (get(val, 'user_id')) {
@@ -39,15 +46,26 @@ export class RecordService extends BaseService<modelType> {
         const videoData = await this.vModel.findById(val.video_id).lean();
         if (videoData) Object.assign(val, { video_name: videoData.title });
       }
+      if (get(val, 'course_id')) {
+        // 查询视频信息
+        const courseData = await this.cModel.findById(val.course_id).lean();
+        if (courseData) Object.assign(val, { course_name: courseData.title });
+      }
     }
     const total = await this.model.count(info);
     return { data, total };
   }
   // 特殊创建
   async createBefore(data) {
-    const { user_id, video_id, ...info } = data;
+    const { user_id, video_id, course_id, total_time, ...info } = data;
+    const calculate = parseInt(((get(info, 'time') / total_time) * 100).toFixed(2));
+    if (calculate > 80) {
+      const videoData = await this.vModel.findById(video_id).lean();
+      info.hour = get(videoData, 'hour');
+      data.hour = get(videoData, 'hour');
+    }
     let result;
-    const record = await this.model.findOne({ user_id, video_id }).lean();
+    const record = await this.model.findOne({ user_id, video_id, course_id }).lean();
     if (record) {
       if (get(record, 'time') < get(info, 'time')) {
         await this.model.updateOne({ _id: get(record, '_id') }, info);

+ 5 - 5
src/service/init.service.ts

@@ -154,11 +154,11 @@ export class InitService {
       { code: 'icon', label: 'Film', value: 'Film', sort: 7, is_use: '0' },
       { code: 'icon', label: 'SwitchFilled', value: 'SwitchFilled', sort: 8, is_use: '0' },
       { code: 'icon', label: 'VideoPlay', value: 'VideoPlay', sort: 9, is_use: '0' },
-      { code: 'videoType', label: '科普视频', value: '0', sort: 1, is_use: '0' },
-      { code: 'videoType', label: '科普电影', value: '1', sort: 2, is_use: '0' },
-      { code: 'videoType', label: '综艺', value: '2', sort: 3, is_use: '0' },
-      { code: 'videoType', label: '动漫', value: '3', sort: 4, is_use: '0' },
-      { code: 'videoType', label: '少儿', value: '4', sort: 5, is_use: '0' },
+      { code: 'videoType', label: '自然科学研究', value: '0', sort: 1, is_use: '0' },
+      { code: 'videoType', label: '工程系列', value: '1', sort: 2, is_use: '0' },
+      { code: 'videoType', label: '档案系列', value: '2', sort: 3, is_use: '0' },
+      { code: 'videoType', label: '哲学社会科学研究', value: '3', sort: 4, is_use: '0' },
+      { code: 'videoType', label: '农业系列', value: '4', sort: 5, is_use: '0' },
     ];
     await this.dictTypeModel.insertMany(isUseType);
     await this.dictDataModel.insertMany(isUseData);

+ 10 - 5
src/service/system/user.service.ts

@@ -1,19 +1,24 @@
-import { Provide } from '@midwayjs/decorator';
+import { Provide, Inject } from '@midwayjs/decorator';
 import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
-import { BaseService } from 'free-midway-component';
+import { BaseService, ServiceError } from 'free-midway-component';
 import { User } from '../../entity/system/user.entity';
+import { I18nService } from '../i18n.service';
+import { FrameErrorEnum } from '../../error/frame.error';
 type modelType = ReturnModelType<typeof User>;
 @Provide()
 export class UserService extends BaseService<modelType> {
   @InjectEntityModel(User)
   model: modelType;
 
+  @Inject()
+  i18n: I18nService;
+
   // 创建前判断是否是普通用户 普通用户不用审核直接通过
   async createBefore(data) {
-    const { role } = data;
-    if (role && role === 'User') data.status = '1';
-    else data.status = '0';
+    const { account } = data;
+    const user = await this.model.findOne({ account }).lean();
+    if (user && user._id) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.USER_EXIST), FrameErrorEnum.USER_EXIST);
     return data;
   }
 }