desc time author veaba
 *  import { getTime } from 'date-fns' ; import { getKeysAll , getRankAll , taskChannelList , updateOne } from "../mongo/curd" ; import { axios } from "./axios" ; import { _pushSuccess } from "../app" ; import { getHash , setHash } from "../redis/redis" ; desc export const broadcastTask = async ( ) => { const broadcastList = await taskChannelList ( 'broadcasts' , 2 ) ; let sendData = [ ] ; for ( let item of broadcastList ) { if ( ! item . is_new ) { sendData . push ( item ) ; } } return sendData ; } ; desc export const auditTask = async ( ) => { const broadcastList = await taskChannelList ( 'audits' , 5 ) ; let auditList = [ ] ; for ( let item of broadcastList ) { if ( ! item . pass ) { auditList . push ( item ) ; await updateOne ( { _id : item . _id } , { ... item , pass : true } , 'broadcasts' ) ; } } return auditList ; } ; desc reports audits export const totalTask = async ( ) => { let resList = await getKeysAll ( { pass : true } , [ 'count' , 'cure' , 'dead' , 'suspected' ] , 'audits' ) ; const totalObj = { count : 0 , cure : 0 , dead : 0 , suspected : 0 , treat : 0 } ; resList . map ( ( item ) => { totalObj . count += item . count ; totalObj . cure += item . cure ; totalObj . dead += item . dead ; totalObj . suspected += item . suspected ; } ) ; totalObj . treat = totalObj . count - ( totalObj . cure + totalObj . dead ) ; return totalObj ; } ; desc data time param dateStr return export const worldMapTask = async ( dateStr ? ) => { } ; desc export const rankTask = async ( dateStr ? ) => { let reportDateObj = { } ; if ( dateStr && new Date ( dateStr ) ) { reportDateObj . reportDate = getTime ( new Date ( dateStr ) ) ; } let auditList = await getRankAll ( { pass : true , country : "中国" , ... reportDateObj } , [ "count" , "cure" , "dead" , "suspected" , 'country' , 'province' ] , 'audits' ) || [ ] ; let provinceObj = { } ; auditList . map ( ( item ) => { if ( ! provinceObj [ item . province ] ) { provinceObj [ item . province ] = { count : 0 , cure : 0 , dead : 0 , suspected : 0 } ; } provinceObj [ item . province ] . count += ( item . count || 0 ) ; provinceObj [ item . province ] . cure += ( item . cure || 0 ) ; provinceObj [ item . province ] . dead += ( item . dead || 0 ) ; provinceObj [ item . province ] . suspected += ( item . suspected || 0 ) ; provinceObj [ item . province ] . province = item . province || "" ; provinceObj [ item . province ] . country = item . country || "" ; } ) ; let rankList = [ ] ; for ( let item in provinceObj ) { delete provinceObj [ item ] . _id ; rankList . push ( provinceObj [ item ] ) ; } rankList . sort ( ( left , right ) => { if ( left . count > right . count ) { return 1 ; } if ( left . count < right . count ) { return - 1 ; } return 0 ; } ) ; return rankList ; } ; desc export const parserChinaRank = ( data ) => { const chinaObj = data || { } ; const chinaData = [ ] ; for ( let item of chinaObj . children || [ ] ) { chinaData . push ( { name : item . name , province : item . name , ... item . total } ) ; } return chinaData ; } ; desc return export const parseWorldMap = ( data ) => { const otherCountryArray = data . slice ( 1 ) ; const otherCountryData = [ ] ; for ( let item of otherCountryArray ) { otherCountryData . push ( { name : item . name , country : item . name , province : item . name , city : item . name , ... item . total } ) ; } const chinaObj = data [ 0 ] || { } ; const chinaData = [ ] ; for ( let items of chinaObj . children || [ ] ) { if ( items . children ) { for ( let item of items . children ) { chinaData . push ( { country : "中国" , name : item . name || "地区待确认" , city : item . name || "地区待确认" , province : items . name || "地区待确认" , ... item . total } ) ; } } } return chinaData . concat ( otherCountryData ) ; } ; desc export const parseTotal = ( chinaTotal , otherCountryTotal , lastUpdateTime ) => { const worldTotalObj = { worldConfirm : Number ( chinaTotal . confirm || 0 ) , worldHeal : Number ( chinaTotal . heal || 0 ) , worldDead : Number ( chinaTotal . dead || 0 ) , worldSuspect : Number ( chinaTotal . suspect || 0 ) , } ; for ( let item of otherCountryTotal ) { worldTotalObj . worldConfirm += Number ( ( item . total . confirm || 0 ) ) ; worldTotalObj . worldHeal += Number ( ( item . total . heal || 0 ) ) ; worldTotalObj . worldDead += Number ( ( item . total . dead || 0 ) ) ; worldTotalObj . worldSuspect += Number ( ( item . total . suspect || 0 ) ) ; } return { chinaConfirm : Number ( chinaTotal . confirm ) , chinaHeal : Number ( chinaTotal . heal ) , chinaDead : Number ( chinaTotal . dead ) , chinaSuspect : Number ( chinaTotal . suspect ) , lastUpdateTime , ... worldTotalObj } ; } ; desc export const parseWorldRank = ( data ) => { const worldData = [ ] ; for ( let item of data ) { worldData . push ( { name : item . name , country : item . name , ... item . total } ) ; } return worldData ; } ; desc export const tencent = async ( dateStr ? ) => { axios . get ( 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=' ) . then ( async ( res ) => { if ( res . ret === 0 ) { const allData = JSON . parse ( res . data || { } ) ; const totalData = parseTotal ( allData . chinaTotal , allData . areaTree . slice ( 1 ) , allData . lastUpdateTime ) ; const worldMapData = parseWorldMap ( allData . areaTree ) ; const chinaRank = parserChinaRank ( allData . areaTree [ 0 ] ) ; const worldRank = parseWorldRank ( allData . areaTree ) ; const chinaDayList = allData . chinaDayList ; const fullYear = new Date ( ) . getFullYear ( ) ; const fullMouth = new Date ( ) . getMonth ( ) + 1 ; const fullDay = new Date ( ) . getDate ( ) ; const fullHour = new Date ( ) . getHours ( ) ; const fullMinute = new Date ( ) . getMinutes ( ) ; const date = fullYear + '-' + ( fullMouth + '' ) . padStart ( 2 , '0' ) + '-' + String ( fullDay - 1 ) . padStart ( 2 , '0' ) ; const today = fullYear + '-' + ( fullMouth + '' ) . padStart ( 2 , '0' ) + '-' + String ( fullDay ) . padStart ( 2 , '0' ) ; if ( fullHour < 1 && fullMinute < 10 ) { await updateOne ( { date , totalData , worldMapData , chinaRank , worldRank , chinaDayList } , { } , 'historys' ) ; await setHash ( date . toString ( ) , { date : date . toString ( ) } ) ; } let redisTotalData = await getHash ( today ) ; if ( ! redisTotalData ) { redisTotalData = { } ; } const redisTotal = redisTotalData . totalData || "{}" ; const { worldConfirm , worldHeal , worldDead , worldSuspect } = JSON . parse ( redisTotal ) ; if ( ! redisTotalData . totalData || worldConfirm !== totalData . worldConfirm || worldHeal !== totalData . worldHeal && worldDead !== totalData . worldDead || worldSuspect !== totalData . worldSuspect ) { await _pushSuccess ( 'broadcast' , 'getTotal' , totalData , 'push' ) ; await _pushSuccess ( 'broadcast' , 'getWorldRank' , worldRank , getTime ( new Date ( ) ) ) ; await _pushSuccess ( 'broadcast' , 'getChinaDay' , chinaDayList , getTime ( new Date ( ) ) ) ; await _pushSuccess ( 'broadcast' , 'getChinaRank' , chinaRank , getTime ( new Date ( ) ) ) ; await _pushSuccess ( 'broadcast' , 'getWorldMap' , worldMapData , getTime ( new Date ( ) ) ) ; await setHash ( today , { totalData : JSON . stringify ( totalData || { } ) } ) ; } res = null ; } } ) ; } ;