/*
 * @Author: YKH
 * @Date: 2021-12-22 13:59:30
 * @LastEditTime: 2022-02-11 11:14:59
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_account_temp.ts
 */
import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService } from 'midwayjs-cool-core';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import { ShuyouGameAccountTempEntity } from '../entity/game_account_temp';
import * as _ from 'lodash';
import { Utils } from '../../../comm/utils';

/**
 * 
 */
@Provide()
export class ShuyouGameAccountTempService extends BaseService {
  @InjectEntityModel(ShuyouGameAccountTempEntity)
  ShuyouGameAccountTempEntity: Repository<ShuyouGameAccountTempEntity>;

  @Inject()
  utils: Utils;
  /***
   * 批量插入数据库
   */
  async batchAdd(id_card: any) {
    let idCard = id_card
    const sqlBatchAdd = `
      insert 
        IGNORE into 
        game_account_temp (account_text,
          password_text,
          remark) 
        values
    `+ idCard;
    return await this.nativeQuery(sqlBatchAdd);
  }

  /**
   * 对比临时表和账号表，找出账号表中已存在的数据
   * @param {number} type_id
   * @return {*} 
   * @memberof ShuyouGameAccountTempService
   */
  async contrastData(type_id: number) {
    const sql = `
      select 
        account_text,password_text,remark 
      from game_account_temp A 
      where exists(
        select account_text from shuyou_game_account where type_id = `+ type_id + ` and account_text=A.account_text)
    `
    return await this.nativeQuery(sql);
  }

  /**
   *
   *  清空临时表
   * @memberof ShuyouGameAccountTempService
   */
  async deleteAll() {
    await this.ShuyouGameAccountTempEntity
      .createQueryBuilder()
      .delete()
      .execute();
  }


}
