/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2021-12-24 10:45:35
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_list.ts
 */
import { Provide } from '@midwayjs/decorator';
import { BaseService } from 'midwayjs-cool-core';
import * as _ from 'lodash';

/**
 * 游戏列表
 */
@Provide()
export class ShuyouGameListService extends BaseService {


  /**
  * 重写分页查询
  * @param query
  */
  async page(query) {
    const { game_name, game_agent, login_mode } = query;
    const sql = `
          SELECT
            a.id,a.createTime,a.updateTime,a.remark,a.game_name,a.game_agentId,a.login_modeId,
            c.name AS game_agent,
            b.name AS login_mode
          FROM
            shuyou_game_list a
            LEFT JOIN shuyou_lo_mode b ON a.login_modeId = b.id
            LEFT JOIN shuyou_game_agent c ON a.game_agentId = c.id
          WHERE 1 = 1
            ${this.setSql(game_name, 'and a.game_name LIKE ?', [`%${game_name}%`])}
            ${this.setSql(game_agent, 'and c.name LIKE ?', [`%${game_agent}%`])}
            ${this.setSql(login_mode, 'and b.name LIKE ?', [`%${login_mode}%`])}
        `;
    return this.sqlRenderPage(sql, query);
  }

  /**
   * 重写list查询
   * @param {*} query
   * @return {*} 
   * @memberof ShuyouGameListService
   */
  async list(query) {
    const sql = `
        SELECT
          a.id,
          a.game_name,
          c.name AS game_agent,
          b.name AS login_mode
        FROM
          shuyou_game_list a
          LEFT JOIN shuyou_lo_mode b ON a.login_modeId = b.id
          LEFT JOIN shuyou_game_agent c ON a.game_agentId = c.id
        `;
    return this.nativeQuery(sql, query);
  }

}
