/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2022-03-17 13:35:48
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\lo_mode.ts
 */
import { Provide } from '@midwayjs/decorator';
import { BaseService } from 'midwayjs-cool-core';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import * as _ from 'lodash';
import { ShuyouLoModeEntity } from '../entity/lo_mode';

/**
 * 游戏目标
 */
@Provide()
export class ShuyouLoModeService extends BaseService {

  @InjectEntityModel(ShuyouLoModeEntity)
  ShuyouLoModeEntity: Repository<ShuyouLoModeEntity>;

  /**
   * 端口对应的游戏数量+1
   * @param {*} login_modeId
   * @memberof ShuyouLoModeService
   */
  async recordGameNum(login_modeId: number) {
    if (login_modeId) {
      const gameLoModeEntity = await this.ShuyouLoModeEntity.findOne(login_modeId);
      gameLoModeEntity.game_count = gameLoModeEntity.game_count + 1;
      await this.ShuyouLoModeEntity.save(gameLoModeEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   * 端口对应的游戏数量-1
   * @param {*} login_modeId
   * @memberof ShuyouLoModeService
   */
  async reduceGameNum(login_modeId: number) {
    if (login_modeId) {
      const gameLoModeEntity = await this.ShuyouLoModeEntity.findOne(login_modeId);
      gameLoModeEntity.game_count = gameLoModeEntity.game_count - 1;
      await this.ShuyouLoModeEntity.save(gameLoModeEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   *
   *减少游戏数量by name
   * @param {*} name
   * @return {*} 
   * @memberof ShuyouLoModeService
   */
  async reduceGameNumByname(name: any) {
    if (name) {
      const gameLoModeEntity = await this.ShuyouLoModeEntity.findOne({
        name: name
      });
      gameLoModeEntity.game_count = gameLoModeEntity.game_count - 1;
      await this.ShuyouLoModeEntity.save(gameLoModeEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   *
   *增加游戏数量by name
   * @param {*} name
   * @return {*} 
   * @memberof ShuyouLoModeService
   */
  async addGameNumByname(name: any) {
    if (name) {
      const gameLoModeEntity = await this.ShuyouLoModeEntity.findOne({
        name: name
      });
      gameLoModeEntity.game_count = gameLoModeEntity.game_count + 1;
      await this.ShuyouLoModeEntity.save(gameLoModeEntity);
      return 1000
    } else {
      return -1
    }
  }



}
