/*
 * @Author: YKH
 * @Date: 2022-02-17 16:27:22
 * @LastEditTime: 2022-02-25 11:48:43
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_account_record.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 { ShuyouGameAccountRecordEntity } from '../entity/game_account_record';
// import { Utils } from '../../../comm/utils';

/**
 * 商品
 */
@Provide()
export class ShuyouGameAccountRecordService extends BaseService {

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

  // @Inject()
  // utils: Utils;
  /**
    * 重写分页查询
    * @param query
    */
  async page(query) {
    const { account_text, game_name } = query;
    const sql = `
        SELECT
          a.id,a.createTime,a.updateTime,a.account_id,a.game_id,
          b.account_text,b.status,c.game_name,c.game_agentId,c.login_modeId
        FROM
          game_account_record a
          LEFT JOIN shuyou_game_account b ON a.account_id = b.id
          LEFT JOIN shuyou_game_list c ON a.game_id = c.id
        WHERE 1 = 1
          ${this.setSql(account_text, 'and b.account_text LIKE ?', [`%${account_text}%`])}
          ${this.setSql(game_name, 'and c.game_name LIKE ?', [`%${game_name}%`])}
      `;
    return this.sqlRenderPage(sql, query);
  }





}
