/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2022-03-17 13:35:33
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_agent.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 { ShuyouGameAgentEntity } from '../entity/game_agent';

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

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

  /**
   * 厂商对应的游戏数量+1
   * @param {*} game_agentId
   * @memberof ShuyouGameAgentService
   */
  async recordGameNum(game_agentId: number) {
    if (game_agentId) {
      const gameAgentEntity = await this.ShuyouGameAgentEntity.findOne(game_agentId);
      gameAgentEntity.game_count = gameAgentEntity.game_count + 1;
      await this.ShuyouGameAgentEntity.save(gameAgentEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   * 厂商对应的游戏数量-1
   * @param {*} game_agentId
   * @memberof ShuyouGameAgentService
   */
  async reduceGameNum(game_agentId: number) {
    if (game_agentId) {
      const gameAgentEntity = await this.ShuyouGameAgentEntity.findOne(game_agentId);
      gameAgentEntity.game_count = gameAgentEntity.game_count - 1;
      await this.ShuyouGameAgentEntity.save(gameAgentEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   *
   *减少游戏数量by name
   * @param {*} name
   * @return {*} 
   * @memberof ShuyouGameAgentService
   */
  async reduceGameNumByname(name: any) {
    if (name) {
      const gameAgentEntity = await this.ShuyouGameAgentEntity.findOne({
        name: name
      });
      gameAgentEntity.game_count = gameAgentEntity.game_count - 1;
      await this.ShuyouGameAgentEntity.save(gameAgentEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   *
   *增加游戏数量by name
   * @param {*} name
   * @return {*} 
   * @memberof ShuyouGameAgentService
   */
  async addGameNumByname(name: any) {
    if (name) {
      const gameAgentEntity = await this.ShuyouGameAgentEntity.findOne({
        name: name
      });
      gameAgentEntity.game_count = gameAgentEntity.game_count + 1;
      await this.ShuyouGameAgentEntity.save(gameAgentEntity);
      return 1000
    } else {
      return -1
    }
  }


  //  /**
  //  * 重写分页查询
  //  * @param query
  //  */
  // async page(query) {
  //   const { pc_name, is_rent,shop_name,is_abnormal } = query;
  //   const sql = `
  //         SELECT
  //           *
  //         FROM
  //           shuyou_game_computer
  //         WHERE 1 = 1
  //           ${this.setSql(pc_name, 'and pc_name LIKE ?', [`%${pc_name}%`])}
  //           ${this.setSql(is_rent, 'and is_rent = ?', [is_rent])}
  //           ${this.setSql(shop_name, 'and shop_name LIKE ?', [`%${shop_name}%`])}
  //           ${this.setSql(is_abnormal, 'and is_abnormal = ?', [is_abnormal])}
  //       `;
  //   return this.sqlRenderPage(sql, query);
  // }


}
