import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService} from 'midwayjs-cool-core';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import * as _ from 'lodash';
import { ShuyouGameCompleteEntity } from '../entity/game_complete';
import { ILogger } from '@midwayjs/logger';
import { ShuyouGameTaskEntity } from '../entity/game_task';
import { Utils } from '../../../comm/utils';
/**
 * 游戏目标
 */
@Provide()
export class ShuyouGameCompleteService extends BaseService {

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

  @Inject()
  logger: ILogger;

  @Inject()
  utils: Utils;
  
  /**
   * 添加任务完成
   */
  async addComplete(queryObject: ShuyouGameTaskEntity) {
    const gameCompleteEntity = await this.ShuyouGameCompleteEntity.findOne({
      task_id: queryObject.id,
      new_date: this.utils.formatDate(new Date())
    });
    
    let obj = {
      task_id: queryObject.id,
      task_name: queryObject.task_name,
      new_date: this.utils.formatDate(new Date()),
      updateTime: new Date()
    }
    if (!gameCompleteEntity) { 
      //不存在，则新建
      await this.ShuyouGameCompleteEntity.insert(obj)
    } 
  }
   
}
