/*
 * @Author: YKH
 * @Date: 2021-12-10 09:04:02
 * @LastEditTime: 2022-06-14 11:56:58
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\data_abnormal_rate.ts
 */
import { Provide, Inject, Post, Body, ALL } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { ShuyouAbnormalRateEntity } from '../../entity/data_abnormal_rate';
import { ShuyouAbnormalRateService } from '../../service/data_abnormal_rate';

/**
 * 游戏负责人
 */
@Provide()
@CoolController({
  // 添加通用CRUD接口
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  // 设置表实体
  entity: ShuyouAbnormalRateEntity,
  service: ShuyouAbnormalRateService,

  before: ctx => {
    //前段数据转JSON格式
    const data = ctx.request.body;
    // console.log(data.agentOrDirector)
    if (typeof (data.new_date) == "undefined") {
      data.new_date = [new Date(), new Date()]
    }
    ctx.request.body.data = JSON.stringify(data);
  },
  // 分页查询配置
  // pageQueryOp: {
  //   // 让字段支持模糊查询
  //   keyWordLikeFields: ['directorName'],
  //   // 让字段支持筛选
  //   fieldEq: ['directorName'],
  //   // 添加排序
  //   addOrderBy: {
  //     // 排序字段及排序方式
  //     id: 'desc',
  //   },
  // },
})
export class ShuyouAbnormalRateController extends BaseController {

  @Inject()
  ShuyouAbnormalRateService: ShuyouAbnormalRateService;

  @Post('/queryAbnormalRate')
  async queryAbnormalRate(@Body(ALL) queryObject: any) {
    let { date } = queryObject
    if (typeof (date) == "undefined") {
      date = [new Date(), new Date()]
    }
    let queryAbnormalRate = await this.ShuyouAbnormalRateService.queryAbnormalRate(date);
    // console.log(queryAbnormalRate)
    if (!queryAbnormalRate) {
      return { code: -1, message: '未查询到数据' };
    }
    return await this.ok({ code: 1, data: queryAbnormalRate });
  }

  @Post('/querySeven')
  async querySeven(@Body(ALL) queryObject: any) {
    let { task_id, new_date } = queryObject
    let queryAbnormalRate = await this.ShuyouAbnormalRateService.querySeven(task_id, new_date);
    // console.log(queryAbnormalRate)
    if (!queryAbnormalRate) {
      return { code: -1, message: '未查询到数据' };
    }
    return await this.ok({ code: 1, data: queryAbnormalRate });
  }

  @Post('/querySomeTime')
  async querySomeTime(@Body(ALL) queryObject: any) {
    let { task_id, new_date } = queryObject
    if (typeof (new_date) == "undefined") {
      new_date = [new Date().getTime() - 3600 * 1000 * 24 * 1, new Date().getTime() - 3600 * 1000 * 24 * 1]
    }
    let queryAbnormalRate = await this.ShuyouAbnormalRateService.querySomeTime(task_id, new_date);
    // console.log(queryAbnormalRate)
    if (!queryAbnormalRate) {
      return { code: -1, message: '未查询到数据' };
    }
    return await this.ok({ code: 1, data: queryAbnormalRate });
  }
}
