zs il y a 1 an
Parent
commit
dd381ce9d2

+ 95 - 0
src/controller/Upkeep.controller.ts

@@ -0,0 +1,95 @@
+import {
+  Body,
+  Controller,
+  Del,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Query,
+} from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { UpkeepService } from '../service/Upkeep.service';
+import {
+  CDTO_upkeep,
+  CVO_upkeep,
+  FVO_upkeep,
+  QDTO_upkeep,
+  QVO_upkeep,
+  UDTO_upkeep,
+  UVAO_upkeep,
+} from '../interface/Upkeep.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { UserUtilService } from '../service/util/user.util';
+@ApiTags(['维修表'])
+@Controller('/Upkeep')
+export class UpkeepController extends BaseController {
+  @Inject()
+  service: UpkeepService;
+
+  @Inject()
+  userUtil: UserUtilService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_upkeep })
+  async create(@Body() data: CDTO_upkeep) {
+    // 检查是否创建相同维修数据
+    await this.userUtil.checkUpkeep(data);
+    const dbData = await this.service.create(data);
+    const result = new CVO_upkeep(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_upkeep })
+  async query(
+    @Query() filter: QDTO_upkeep,
+    @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_upkeep(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_upkeep })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_upkeep(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_upkeep })
+  async update(@Param('id') id: string, @Body() body: UDTO_upkeep) {
+    const result = await this.service.update(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.');
+  }
+}

+ 25 - 0
src/entity/Upkeep.entity.ts

@@ -0,0 +1,25 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'Upkeep' },
+})
+export class Upkeep extends BaseModel {
+  @prop({ required: true, index: true, zh: '用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '用户名称' })
+  user_name: string;
+  @prop({ required: true, index: true, zh: '供应商id' })
+  supplier: string;
+  @prop({ required: false, index: true, zh: '供应商名称' })
+  supplier_name: string;
+  @prop({ required: true, index: true, zh: '商品id' })
+  good: string;
+  @prop({ required: false, index: true, zh: '商品名称' })
+  good_name: string;
+  @prop({ required: true, index: true, zh: '规格id' })
+  spec: string;
+  @prop({ required: false, index: true, zh: '规格名称' })
+  spec_name: string;
+  @prop({ required: false, index: false, zh: '维修地址' })
+  address: string;
+}

+ 146 - 0
src/interface/Upkeep.interface.ts

@@ -0,0 +1,146 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import {
+  FrameworkErrorEnum,
+  SearchBase,
+  ServiceError,
+} 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_upkeep {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '用户名称' })
+  'user_name': string = undefined;
+  @ApiProperty({ description: '供应商id' })
+  'supplier': string = undefined;
+  @ApiProperty({ description: '供应商名称' })
+  'supplier_name': string = undefined;
+  @ApiProperty({ description: '商品id' })
+  'good': string = undefined;
+  @ApiProperty({ description: '商品名称' })
+  'good_name': string = undefined;
+  @ApiProperty({ description: '规格id' })
+  'spec': string = undefined;
+  @ApiProperty({ description: '规格名称' })
+  'spec_name': string = undefined;
+  @ApiProperty({ description: '维修地址' })
+  'address': string = undefined;
+}
+
+export class QDTO_upkeep extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [
+      'user',
+      'user_name',
+      'supplier',
+      'supplier_name',
+      'good',
+      'good_name',
+      'spec',
+      'spec_name',
+    ];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '用户名称' })
+  'user_name': string = undefined;
+  @ApiProperty({ description: '供应商id' })
+  'supplier': string = undefined;
+  @ApiProperty({ description: '供应商名称' })
+  'supplier_name': string = undefined;
+  @ApiProperty({ description: '商品id' })
+  'good': string = undefined;
+  @ApiProperty({ description: '商品名称' })
+  'good_name': string = undefined;
+  @ApiProperty({ description: '规格id' })
+  'spec': string = undefined;
+  @ApiProperty({ description: '规格名称' })
+  'spec_name': string = undefined;
+}
+
+export class QVO_upkeep extends FVO_upkeep {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_upkeep {
+  @ApiProperty({ description: '用户id' })
+  @Rule(
+    RuleType['string']()
+      .required()
+      .error(new ServiceError('缺少用户id', FrameworkErrorEnum.NEED_BODY))
+  )
+  'user': string = undefined;
+  @ApiProperty({ description: '用户名称' })
+  @Rule(RuleType['string']().empty(''))
+  'user_name': string = undefined;
+  @ApiProperty({ description: '供应商id' })
+  @Rule(
+    RuleType['string']()
+      .required()
+      .error(new ServiceError('缺少供应商id', FrameworkErrorEnum.NEED_BODY))
+  )
+  'supplier': string = undefined;
+  @ApiProperty({ description: '供应商名称' })
+  @Rule(RuleType['string']().empty(''))
+  'supplier_name': string = undefined;
+  @ApiProperty({ description: '商品id' })
+  @Rule(
+    RuleType['string']()
+      .required()
+      .error(new ServiceError('缺少商品id', FrameworkErrorEnum.NEED_BODY))
+  )
+  'good': string = undefined;
+  @ApiProperty({ description: '商品名称' })
+  @Rule(RuleType['string']().empty(''))
+  'good_name': string = undefined;
+  @ApiProperty({ description: '规格id' })
+  @Rule(
+    RuleType['string']()
+      .required()
+      .error(new ServiceError('缺少规格id', FrameworkErrorEnum.NEED_BODY))
+  )
+  'spec': string = undefined;
+  @ApiProperty({ description: '规格名称' })
+  @Rule(RuleType['string']().empty(''))
+  'spec_name': string = undefined;
+  @ApiProperty({ description: '维修地址' })
+  @Rule(RuleType['string']().empty(''))
+  'address': string = undefined;
+}
+
+export class CVO_upkeep extends FVO_upkeep {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_upkeep extends CDTO_upkeep {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_upkeep extends FVO_upkeep {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 7 - 0
src/interface/util/user.util.interface.ts

@@ -11,3 +11,10 @@ export interface checkPhoneAndPid {
 export interface checkOffice {
   office?: string;
 }
+export interface checkUpkeep {
+  order_id?: string;
+  user?: string;
+  supplier?: string;
+  good?: string;
+  spec?: string;
+}

+ 22 - 0
src/service/Upkeep.service.ts

@@ -0,0 +1,22 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Upkeep } from '../entity/Upkeep.entity';
+import { OrderDetail } from '../entity/OrderDetail.entity';
+type modelType = ReturnModelType<typeof Upkeep>;
+@Provide()
+export class UpkeepService extends BaseService<modelType> {
+  @InjectEntityModel(Upkeep)
+  model: modelType;
+
+  @InjectEntityModel(OrderDetail)
+  orderModel: ReturnModelType<typeof OrderDetail>;
+
+  async update(id, body) {
+    if (body.status === '2')
+      await this.orderModel.updateOne({ _id: body.order_id }, { status: '9' });
+    const result = await this.model.updateOne({ _id: id }, body);
+    return result;
+  }
+}

+ 24 - 0
src/service/util/user.util.ts

@@ -7,8 +7,10 @@ import {
   CheckUpdateCardAndPid,
   checkPhoneAndPid,
   checkOffice,
+  checkUpkeep,
 } from '../../interface/util/user.util.interface';
 import { ShopSetting } from '../../entity/ShopSetting.entity';
+import { Upkeep } from '../../entity/Upkeep.entity';
 
 @Provide()
 export class UserUtilService {
@@ -17,6 +19,9 @@ export class UserUtilService {
 
   @InjectEntityModel(ShopSetting)
   shopModel: ReturnModelType<typeof ShopSetting>;
+
+  @InjectEntityModel(Upkeep)
+  keepModel: ReturnModelType<typeof Upkeep>;
   /**
    * 检查创建时,是否创建改街道/社区设置
    * @param data 参数
@@ -136,4 +141,23 @@ export class UserUtilService {
       }
     }
   }
+
+  // 创建维修检查
+  async checkUpkeep(data: checkUpkeep) {
+    // 检查街道/社区
+    const keepan = await this.shopModel.count({
+      user: data.user,
+      supplier: data.supplier,
+      good: data.good,
+      spec: data.spec,
+      order_id: data.order_id,
+      status: '0',
+    });
+    if (keepan > 0) {
+      throw new ServiceError(
+        '已有维修申请 请等待维修人员上门或联系您!',
+        FrameworkErrorEnum.BAD_BODY
+      );
+    }
+  }
 }