zs 1 year ago
parent
commit
4182d13424

+ 68 - 0
src/controller/system/module.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { ModuleService } from '../../service/system/module.service';
+import { CDTO_module, CVO_module, FVO_module, QDTO_module, QVO_module, UDTO_module, UVAO_module } from '../../interface/system/module.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['模块表'])
+@Controller('/module')
+export class ModuleController extends BaseController {
+  @Inject()
+  service: ModuleService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_module })
+  async create(@Body() data: CDTO_module) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_module(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_module })
+  async query(@Query() filter: QDTO_module, @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_module(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_module })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_module(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_module })
+  async update(@Param('id') id: string, @Body() body: UDTO_module) {
+    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.');
+  }
+}

+ 2 - 0
src/entity/core/business.entity.ts

@@ -12,6 +12,8 @@ export class Business extends BaseModel {
   money: string;
   @prop({ required: false, index: false, zh: '收费依据' })
   basic: string;
+  @prop({ required: false, index: false, zh: '邮费', default: '0' })
+  postage: string;
   @prop({ required: false, index: false, zh: '所需材料' })
   material: Array<any>;
   @prop({ required: false, index: true, zh: '是否使用', default: '0' })

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

@@ -6,6 +6,8 @@ import { BaseModel } from 'free-midway-component';
 export class Config extends BaseModel {
   @prop({ required: false, index: false, zh: 'logo' })
   logo: Array<any>;
+  @prop({ required: false, index: false, zh: '首页轮播' })
+  file: Array<any>;
   @prop({ required: false, index: false, zh: '联系电话' })
   phone: string;
   @prop({ required: false, index: false, zh: '邮箱' })

+ 17 - 0
src/entity/system/module.entity.ts

@@ -0,0 +1,17 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'module' },
+})
+export class Module extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: false, zh: '图片' })
+  file: Array<any>;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: false, zh: '路由' })
+  route: string;
+  @prop({ required: false, index: true, zh: '是否使用' })
+  is_use: string;
+}

+ 5 - 0
src/interface/core/business.interface.ts

@@ -22,6 +22,8 @@ export class FVO_business {
   'money': string = undefined;
   @ApiProperty({ description: '收费依据' })
   'basic': string = undefined;
+  @ApiProperty({ description: '邮费' })
+  'postage': string = undefined;
   @ApiProperty({ description: '所需材料' })
   'material': Array<any> = undefined;
   @ApiProperty({ description: '是否使用' })
@@ -61,6 +63,9 @@ export class CDTO_business {
   @ApiProperty({ description: '收费依据' })
   @Rule(RuleType['string']().empty(''))
   'basic': string = undefined;
+  @ApiProperty({ description: '邮费' })
+  @Rule(RuleType['string']().empty(''))
+  'postage': string = undefined;
   @ApiProperty({ description: '所需材料' })
   @Rule(RuleType['array']().empty(''))
   'material': Array<any> = undefined;

+ 16 - 17
src/interface/system/config.interface.ts

@@ -16,6 +16,8 @@ export class FVO_config {
   _id: string = undefined;
   @ApiProperty({ description: 'logo' })
   'logo': Array<any> = undefined;
+  @ApiProperty({ description: '首页轮播图' })
+  'file': Array<any> = undefined;
   @ApiProperty({ description: '联系电话' })
   'phone': string = undefined;
   @ApiProperty({ description: '邮箱' })
@@ -32,7 +34,6 @@ export class FVO_config {
   'agreement': string = undefined;
 }
 
-
 export class QDTO_config extends SearchBase {
   constructor() {
     const like_prop = [];
@@ -42,7 +43,6 @@ export class QDTO_config extends SearchBase {
   }
 }
 
-
 export class QVO_config extends FVO_config {
   constructor(data: object) {
     super(data);
@@ -50,35 +50,36 @@ export class QVO_config extends FVO_config {
   }
 }
 
-
 export class CDTO_config {
   @ApiProperty({ description: 'logo' })
-@Rule(RuleType['array']().empty(''))
+  @Rule(RuleType['array']().empty(''))
   'logo': Array<any> = undefined;
+  @ApiProperty({ description: '首页轮播图' })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
   @ApiProperty({ description: '联系电话' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'phone': string = undefined;
   @ApiProperty({ description: '邮箱' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'email': string = undefined;
   @ApiProperty({ description: '地址' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'address': string = undefined;
   @ApiProperty({ description: '工作时间' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'time': string = undefined;
   @ApiProperty({ description: '平台简介' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'brief': string = undefined;
   @ApiProperty({ description: '办证须知' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'notice': string = undefined;
   @ApiProperty({ description: '用户协议' })
-@Rule(RuleType['string']().empty(''))
+  @Rule(RuleType['string']().empty(''))
   'agreement': string = undefined;
 }
 
-
 export class CVO_config extends FVO_config {
   constructor(data: object) {
     super(data);
@@ -86,14 +87,12 @@ export class CVO_config extends FVO_config {
   }
 }
 
-
 export class UDTO_config extends CDTO_config {
-    @ApiProperty({ description: '数据id' })
-    @Rule(RuleType['string']().empty(''))
-    _id: string = undefined;
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
 }
 
-
 export class UVAO_config extends FVO_config {
   constructor(data: object) {
     super(data);

+ 85 - 0
src/interface/system/module.interface.ts

@@ -0,0 +1,85 @@
+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_module {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '图片' })
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '路由' })
+  'route': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_module extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QVO_module extends FVO_module {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_module {
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '图片' })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '路由' })
+  @Rule(RuleType['string']().empty(''))
+  'route': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_module extends FVO_module {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_module extends CDTO_module {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_module extends FVO_module {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 1 - 0
src/service/init.service.ts

@@ -52,6 +52,7 @@ export class InitService {
       { name: '字典管理', parent_id: smId.toString(), order_num: 3, path: '/system/dict', component: '/system/dict/index', type: '1' },
       { name: '字典数据', parent_id: smId.toString(), order_num: 4, path: '/system/dictData', component: '/system/dictData/index', type: '2' },
       { name: '平台设置', parent_id: smId.toString(), order_num: 5, path: '/system/config', component: '/system/config/index', type: '1' },
+      { name: '模块设置', parent_id: smId.toString(), order_num: 6, path: '/system/module', component: '/system/module/index', type: '1' },
     ];
     // 用户管理
     const umId = new ObjectId();

+ 11 - 0
src/service/system/module.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 { Module } from '../../entity/system/module.entity';
+type modelType = ReturnModelType<typeof Module>;
+@Provide()
+export class ModuleService extends BaseService<modelType> {
+  @InjectEntityModel(Module)
+  model: modelType;
+}