zs %!s(int64=2) %!d(string=hai) anos
pai
achega
437e25a41c

+ 89 - 0
src/controller/company.controller.ts

@@ -0,0 +1,89 @@
+import {
+  Body,
+  Controller,
+  Del,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Query,
+} from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { CompanyService } from '../service/company.service';
+import {
+  CDTO_company,
+  CVO_company,
+  FVO_company,
+  QDTO_company,
+  QVO_company,
+  UDTO_company,
+  UVAO_company,
+} from '../interface/company.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['依托单位'])
+@Controller('/company')
+export class CompanyController extends BaseController {
+  @Inject()
+  service: CompanyService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_company })
+  async create(@Body() data: CDTO_company) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_company(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_company })
+  async query(
+    @Query() filter: QDTO_company,
+    @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_company(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_company })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_company(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_company })
+  async update(@Param('id') id: string, @Body() body: UDTO_company) {
+    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.');
+  }
+}

+ 89 - 0
src/controller/scientist.controller.ts

@@ -0,0 +1,89 @@
+import {
+  Body,
+  Controller,
+  Del,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Query,
+} from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { ScientistService } from '../service/scientist.service';
+import {
+  CDTO_scientist,
+  CVO_scientist,
+  FVO_scientist,
+  QDTO_scientist,
+  QVO_scientist,
+  UDTO_scientist,
+  UVAO_scientist,
+} from '../interface/scientist.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['科学家'])
+@Controller('/scientist')
+export class ScientistController extends BaseController {
+  @Inject()
+  service: ScientistService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_scientist })
+  async create(@Body() data: CDTO_scientist) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_scientist(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_scientist })
+  async query(
+    @Query() filter: QDTO_scientist,
+    @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_scientist(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_scientist })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_scientist(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_scientist })
+  async update(@Param('id') id: string, @Body() body: UDTO_scientist) {
+    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.');
+  }
+}

+ 35 - 0
src/entity/company.entity.ts

@@ -0,0 +1,35 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'company' },
+})
+export class Company extends BaseModel {
+  @prop({ required: false, index: true, zh: '登陆账号' })
+  account: string;
+  @prop({ required: false, index: true, zh: '登录密码' })
+  password: string;
+  @prop({ required: false, index: true, zh: '负责人姓名' })
+  name: string;
+  @prop({ required: false, index: true, zh: '负责人手机号码' })
+  phone: string;
+  @prop({ required: false, index: true, zh: '负责人邮箱' })
+  email: string;
+  @prop({ required: false, index: true, zh: '单位全称' })
+  company: string;
+  @prop({ required: false, index: true, zh: '单位地址' })
+  address: string;
+  @prop({ required: false, index: false, zh: '上传负责人委任证明' })
+  appoint_file: Array<any>;
+  @prop({
+    required: false,
+    index: true,
+    zh: '用户状态',
+    remark: '字典表:company_status',
+    default: '0',
+  })
+  status: string;
+  @prop({ required: false, index: false, zh: '记录' })
+  record: Array<any>;
+  @prop({ required: false, index: true, zh: '角色', remark: '角色表:role' })
+  role_id: string;
+}

+ 55 - 0
src/entity/scientist.entity.ts

@@ -0,0 +1,55 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'scientist' },
+})
+export class Scientist extends BaseModel {
+  @prop({ required: false, index: true, zh: '登陆账号' })
+  account: string;
+  @prop({ required: false, index: true, zh: '登陆密码' })
+  password: string;
+  @prop({ required: false, index: true, zh: '姓名' })
+  name: string;
+  @prop({ required: false, index: true, zh: '常用手机号码' })
+  phone: string;
+  @prop({ required: false, index: true, zh: '邮箱' })
+  email: string;
+  @prop({ required: false, index: false, zh: '上传身份证照片' })
+  card: Array<any>;
+  @prop({ required: false, index: true, zh: '所在单位全称' })
+  company: string;
+  @prop({ required: false, index: true, zh: '所在单位地址' })
+  address: string;
+  @prop({ required: false, index: true, zh: '专业技术职称' })
+  zc: string;
+  @prop({ required: false, index: false, zh: '职称证明' })
+  zc_file: Array<any>;
+  @prop({ required: false, index: false, zh: '单位同意入驻证明' })
+  settle_file: Array<any>;
+  @prop({
+    required: false,
+    index: true,
+    zh: '用户状态',
+    remark: '字典表:scientist_status',
+    default: '0',
+  })
+  status: string;
+  @prop({ required: false, index: false, zh: '记录' })
+  record: Array<any>;
+  @prop({ required: false, index: true, zh: '角色', remark: '角色表:role' })
+  role_id: string;
+  @prop({
+    required: false,
+    index: false,
+    zh: '是否为在职人员',
+    remark: '字典表:scientist_is_job',
+    default: '0',
+  })
+  is_job: string;
+  @prop({ required: false, index: false, zh: '退休前所在单位' })
+  job_company: string;
+  @prop({ required: false, index: false, zh: '上传退休证明材料' })
+  job_file: Array<any>;
+  @prop({ required: false, index: false, zh: '上传职称证明' })
+  job_zc_file: Array<any>;
+}

+ 139 - 0
src/interface/company.interface.ts

@@ -0,0 +1,139 @@
+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_company {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '登陆账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '登录密码' })
+  'password': string = undefined;
+  @ApiProperty({ description: '负责人姓名' })
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人手机号码' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '负责人邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '单位全称' })
+  'company': string = undefined;
+  @ApiProperty({ description: '单位地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '上传负责人委任证明' })
+  'appoint_file': Array<any> = undefined;
+  @ApiProperty({ description: '用户状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '记录' })
+  'record': Array<any> = undefined;
+  @ApiProperty({ description: '角色' })
+  'role_id': string = undefined;
+}
+
+export class QDTO_company extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [
+      'account',
+      'password',
+      'name',
+      'phone',
+      'email',
+      'company',
+      'address',
+      'status',
+      'role_id',
+    ];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '登陆账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '登录密码' })
+  'password': string = undefined;
+  @ApiProperty({ description: '负责人姓名' })
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人手机号码' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '负责人邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '单位全称' })
+  'company': string = undefined;
+  @ApiProperty({ description: '单位地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '用户状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role_id': string = undefined;
+}
+
+export class QVO_company extends FVO_company {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_company {
+  @ApiProperty({ description: '登陆账号' })
+  @Rule(RuleType['string']().empty(''))
+  'account': string = undefined;
+  @ApiProperty({ description: '登录密码' })
+  @Rule(RuleType['string']().empty(''))
+  'password': string = undefined;
+  @ApiProperty({ description: '负责人姓名' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人手机号码' })
+  @Rule(RuleType['string']().empty(''))
+  'phone': string = undefined;
+  @ApiProperty({ description: '负责人邮箱' })
+  @Rule(RuleType['string']().empty(''))
+  'email': string = undefined;
+  @ApiProperty({ description: '单位全称' })
+  @Rule(RuleType['string']().empty(''))
+  'company': string = undefined;
+  @ApiProperty({ description: '单位地址' })
+  @Rule(RuleType['string']().empty(''))
+  'address': string = undefined;
+  @ApiProperty({ description: '上传负责人委任证明' })
+  @Rule(RuleType['array']().empty(''))
+  'appoint_file': Array<any> = undefined;
+  @ApiProperty({ description: '用户状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '记录' })
+  @Rule(RuleType['array']().empty(''))
+  'record': Array<any> = undefined;
+  @ApiProperty({ description: '角色' })
+  @Rule(RuleType['string']().empty(''))
+  'role_id': string = undefined;
+}
+
+export class CVO_company extends FVO_company {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_company extends CDTO_company {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_company extends FVO_company {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 177 - 0
src/interface/scientist.interface.ts

@@ -0,0 +1,177 @@
+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_scientist {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '登陆账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '登陆密码' })
+  'password': string = undefined;
+  @ApiProperty({ description: '姓名' })
+  'name': string = undefined;
+  @ApiProperty({ description: '常用手机号码' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '上传身份证照片' })
+  'card': Array<any> = undefined;
+  @ApiProperty({ description: '所在单位全称' })
+  'company': string = undefined;
+  @ApiProperty({ description: '所在单位地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '专业技术职称' })
+  'zc': string = undefined;
+  @ApiProperty({ description: '职称证明' })
+  'zc_file': Array<any> = undefined;
+  @ApiProperty({ description: '单位同意入驻证明' })
+  'settle_file': Array<any> = undefined;
+  @ApiProperty({ description: '用户状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '记录' })
+  'record': Array<any> = undefined;
+  @ApiProperty({ description: '角色' })
+  'role_id': string = undefined;
+  @ApiProperty({ description: '是否为在职人员' })
+  'is_job': string = undefined;
+  @ApiProperty({ description: '退休前所在单位' })
+  'job_company': string = undefined;
+  @ApiProperty({ description: '上传退休证明材料' })
+  'job_file': Array<any> = undefined;
+  @ApiProperty({ description: '上传职称证明' })
+  'job_zc_file': Array<any> = undefined;
+}
+
+export class QDTO_scientist extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [
+      'account',
+      'password',
+      'name',
+      'phone',
+      'email',
+      'company',
+      'address',
+      'zc',
+      'status',
+      'role_id',
+    ];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '登陆账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '登陆密码' })
+  'password': string = undefined;
+  @ApiProperty({ description: '姓名' })
+  'name': string = undefined;
+  @ApiProperty({ description: '常用手机号码' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '所在单位全称' })
+  'company': string = undefined;
+  @ApiProperty({ description: '所在单位地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '专业技术职称' })
+  'zc': string = undefined;
+  @ApiProperty({ description: '用户状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role_id': string = undefined;
+}
+
+export class QVO_scientist extends FVO_scientist {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_scientist {
+  @ApiProperty({ description: '登陆账号' })
+  @Rule(RuleType['string']().empty(''))
+  'account': string = undefined;
+  @ApiProperty({ description: '登陆密码' })
+  @Rule(RuleType['string']().empty(''))
+  'password': string = undefined;
+  @ApiProperty({ description: '姓名' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '常用手机号码' })
+  @Rule(RuleType['string']().empty(''))
+  'phone': string = undefined;
+  @ApiProperty({ description: '邮箱' })
+  @Rule(RuleType['string']().empty(''))
+  'email': string = undefined;
+  @ApiProperty({ description: '上传身份证照片' })
+  @Rule(RuleType['array']().empty(''))
+  'card': Array<any> = undefined;
+  @ApiProperty({ description: '所在单位全称' })
+  @Rule(RuleType['string']().empty(''))
+  'company': string = undefined;
+  @ApiProperty({ description: '所在单位地址' })
+  @Rule(RuleType['string']().empty(''))
+  'address': string = undefined;
+  @ApiProperty({ description: '专业技术职称' })
+  @Rule(RuleType['string']().empty(''))
+  'zc': string = undefined;
+  @ApiProperty({ description: '职称证明' })
+  @Rule(RuleType['array']().empty(''))
+  'zc_file': Array<any> = undefined;
+  @ApiProperty({ description: '单位同意入驻证明' })
+  @Rule(RuleType['array']().empty(''))
+  'settle_file': Array<any> = undefined;
+  @ApiProperty({ description: '用户状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '记录' })
+  @Rule(RuleType['array']().empty(''))
+  'record': Array<any> = undefined;
+  @ApiProperty({ description: '角色' })
+  @Rule(RuleType['string']().empty(''))
+  'role_id': string = undefined;
+  @ApiProperty({ description: '是否为在职人员' })
+  @Rule(RuleType['string']().empty(''))
+  'is_job': string = undefined;
+  @ApiProperty({ description: '退休前所在单位' })
+  @Rule(RuleType['string']().empty(''))
+  'job_company': string = undefined;
+  @ApiProperty({ description: '上传退休证明材料' })
+  @Rule(RuleType['array']().empty(''))
+  'job_file': Array<any> = undefined;
+  @ApiProperty({ description: '上传职称证明' })
+  @Rule(RuleType['array']().empty(''))
+  'job_zc_file': Array<any> = undefined;
+}
+
+export class CVO_scientist extends FVO_scientist {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_scientist extends CDTO_scientist {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_scientist extends FVO_scientist {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 11 - 0
src/service/company.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Company } from '../entity/company.entity';
+type modelType = ReturnModelType<typeof Company>;
+@Provide()
+export class CompanyService extends BaseService<modelType> {
+  @InjectEntityModel(Company)
+  model: modelType;
+}

+ 48 - 1
src/service/message.service.ts

@@ -1,11 +1,58 @@
 import { Provide } from '@midwayjs/decorator';
 import { InjectEntityModel } from '@midwayjs/typegoose';
-import { ReturnModelType } from '@typegoose/typegoose';
+import { getModelForClass, ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Message } from '../entity/message.entity';
+import { Company } from '../entity/company.entity';
+import { Scientist } from '../entity/scientist.entity';
+import _ = require('lodash');
 type modelType = ReturnModelType<typeof Message>;
 @Provide()
 export class MessageService extends BaseService<modelType> {
+  constructor(ctx) {
+    super();
+    if (!this.ctx && ctx) {
+      this.ctx = ctx;
+      if (!this.cModel) this.cModel = getModelForClass(Company);
+      if (!this.sModel) this.sModel = getModelForClass(Scientist);
+      if (!this.model) this.model = getModelForClass(Message);
+    }
+  }
   @InjectEntityModel(Message)
   model: modelType;
+
+  @InjectEntityModel(Company)
+  cModel: ReturnModelType<typeof Company>;
+  @InjectEntityModel(Scientist)
+  sModel: ReturnModelType<typeof Scientist>;
+
+  async create(body) {
+    if (body.type !== '3') {
+      // 企业用户
+      let cList = [];
+      const company = await this.cModel.find({ status: '1' });
+      if (company.length > 0) cList = this.searchC(company, '1');
+      // 科学家用户
+      let sList = [];
+      const scientist = await this.sModel.find({ status: '1' });
+      if (scientist.length > 0) sList = this.searchC(scientist, '2');
+      // 组装接收人数据
+      if (body.type === '0') body.user = [...cList, ...sList];
+      else if (body.type === '1') body.user = [...cList];
+      else if (body.type === '2') body.user = [...sList];
+    }
+    const res = await this.model.create(body);
+    return res;
+  }
+  // 整理user数组数据
+  searchC(e, type) {
+    const list = [];
+    for (const val of e) {
+      let data = {};
+      if (type === '1') data = _.pick(val, ['id', 'company', 'phone']);
+      else if (type === '2') data = _.pick(val, ['id', 'name', 'phone']);
+      list.push(data);
+    }
+    return list;
+  }
 }

+ 11 - 0
src/service/scientist.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Scientist } from '../entity/scientist.entity';
+type modelType = ReturnModelType<typeof Scientist>;
+@Provide()
+export class ScientistService extends BaseService<modelType> {
+  @InjectEntityModel(Scientist)
+  model: modelType;
+}