Prechádzať zdrojové kódy

新增政策法规 通知公告

zs 10 mesiacov pred
rodič
commit
dc04f62205

+ 76 - 0
src/controller/core/new.controller.ts

@@ -0,0 +1,76 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { NewService } from '../../service/core/new.service';
+import { CDTO_new, CVO_new, FVO_new, QDTO_new, QVO_new, UDTO_new, UVAO_new } from '../../interface/core/new.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['政策法规'])
+@Controller('/new')
+export class NewController extends BaseController {
+  @Inject()
+  service: NewService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_new })
+  async create(@Body() data: CDTO_new) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_new(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_new })
+  async query(@Query() filter: QDTO_new, @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_new(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/queryTotal')
+  @ApiQuery({ name: 'queryTotal' })
+  @ApiResponse({ type: QVO_new })
+  async queryTotal(@Query() filter: QDTO_new) {
+    const list = await this.service.queryTotal(filter);
+    return list;
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_new })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_new(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_new })
+  async update(@Param('id') id: string, @Body() body: UDTO_new) {
+    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.');
+  }
+}

+ 68 - 0
src/controller/core/notice.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 { NoticeService } from '../../service/core/notice.service';
+import { CDTO_notice, CVO_notice, FVO_notice, QDTO_notice, QVO_notice, UDTO_notice, UVAO_notice } from '../../interface/core/notice.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['通知公告'])
+@Controller('/notice')
+export class NoticeController extends BaseController {
+  @Inject()
+  service: NoticeService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_notice })
+  async create(@Body() data: CDTO_notice) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_notice(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_notice })
+  async query(@Query() filter: QDTO_notice, @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_notice(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_notice })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_notice(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_notice })
+  async update(@Param('id') id: string, @Body() body: UDTO_notice) {
+    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.');
+  }
+}

+ 19 - 0
src/entity/core/new.entity.ts

@@ -0,0 +1,19 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'new' },
+})
+export class New extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: 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;
+}

+ 17 - 0
src/entity/core/notice.entity.ts

@@ -0,0 +1,17 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'notice' },
+})
+export class Notice extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: 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;
+}

+ 100 - 0
src/interface/core/new.interface.ts

@@ -0,0 +1,100 @@
+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_new {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '内容' })
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+
+export class QDTO_new extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'type', 'is_use', 'status'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+
+export class QVO_new extends FVO_new {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class CDTO_new {
+  @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(''))
+  '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_new extends FVO_new {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class UDTO_new extends CDTO_new {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty(''))
+    _id: string = undefined;
+}
+
+
+export class UVAO_new extends FVO_new {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 87 - 0
src/interface/core/notice.interface.ts

@@ -0,0 +1,87 @@
+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_notice {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '内容' })
+  'content': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_notice extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'is_use', 'status'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_notice extends FVO_notice {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_notice {
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': 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_notice extends FVO_notice {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_notice extends CDTO_notice {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_notice extends FVO_notice {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 26 - 0
src/service/core/new.service.ts

@@ -0,0 +1,26 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { New } from '../../entity/core/new.entity';
+type modelType = ReturnModelType<typeof New>;
+@Provide()
+export class NewService extends BaseService<modelType> {
+  @InjectEntityModel(New)
+  model: modelType;
+
+  async queryTotal(filter) {
+    const { is_use, status } = filter;
+    const total0 = await this.model.count({ is_use, status });
+    const total1 = await this.model.count({ is_use, status, type: '0' });
+    const total2 = await this.model.count({ is_use, status, type: '1' });
+    const total3 = await this.model.count({ is_use, status, type: '2' });
+    const list = [
+      { title: '全部', total: total0 },
+      { title: '国家级', total: total1 },
+      { title: '省级', total: total2 },
+      { title: '其他', total: total3 },
+    ];
+    return list;
+  }
+}

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