/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2021-12-16 15:13:09
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_computer.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 { ShuyouGameComputerEntity } from '../entity/game_computer';

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

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

  /**
   * 重载新增接口
   */
  // async add(param) {
  //   const exists = await this.ShuyouGameTaskEntity.findOne({
  //     id: param.id,
  //   });
  //   if (!_.isEmpty(exists)) {
  //     throw new CoolCommException('已存在相同任务id~');
  //   }
  //   param.createTime = new Date()
  //   param.updateTime = new Date()
  //   console.log(param)
  //   return super.add(param);

  // }

  /**
  * 重写分页查询
  * @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);
  }


}
