ms_schedule.ts 1.9 KB

import * as infodb from '../table'

import moment = require('moment');
import { cache,redis as client, redis, task_lock } from '../../../cache';

//ms_schedule
async function getMsSchedulesByLottery({lotteryId}:any) {
    let key = `${config.CachePrefix}match:match_ms_schedule:v1_${moment().add(-10,'day').format('YYYY-MM-DD')}_${lotteryId}`
    let reply = await client.get(key);
    if (reply) {
        return JSON.parse(reply)
    }

    let result = await infodb.ms_schedule.findAll({
        where:{
                core_lottery_id:lotteryId,
                core_match_time:{$gt:moment().add(-10,'day').format('YYYY-MM-DD')},
            },
        limit:1000,
        attributes: ['core_match_id', 'sportsdt_match_id', 'sportsdt_host_team_id'
        , 'sportsdt_guest_team_id', 'sportsdt_competition_id', 'sportsdt_type', 'sportsdt_degree'
        , 'sportsdt_num', 'sportsdt_starttime', 'sportsdt_isah'],
    })

    await client.set(key,JSON.stringify(result))
    await client.expire(key, 60*10)
    return result
}

async function getMsSchedulesByCoreIds({CoreIds}:any) {
    return cache(async ({CoreIds}:any)=>{
        let result = (await infodb.ms_schedule.findAll({
            where:{
                    core_match_id:{$in:CoreIds},
                    core_match_time:{$gt:moment().add(-120,'day').format('YYYY-MM-DD')},
                },
            limit:1000,
            attributes: ['core_match_id', 'sportsdt_match_id', 'sportsdt_host_team_id'
            , 'sportsdt_guest_team_id', 'sportsdt_competition_id', 'sportsdt_type', 'sportsdt_degree'
            , 'sportsdt_num', 'sportsdt_starttime', 'sportsdt_isah', 'sportsdt_n'
            , 'yiqiu_match_id', 'sporttery_match_id', 'w500_match_id', 'info_match_id'],
        })).map((o:any)=>o.dataValues)
        return result
    },{CoreIds},10,"getMsSchedulesByCoreIds:v1",60,100)
}

export {getMsSchedulesByLottery,getMsSchedulesByCoreIds}