package com.qimai.log.service

import android.app.IntentService
import android.content.Intent
import com.qimai.log.QmLog
import com.qimai.log.database.PushNotifiDataBase
import com.qimai.log.database.PushNotifiInfoDao
import com.qimai.log.QmLogConfig

/**
 * 定时执行任务
 */
class ScheduledExecutionService(name: String = "schedule") : IntentService(name) {
    private val mDataBse: PushNotifiInfoDao by lazy {
        PushNotifiDataBase.getDatabase(application).pushInfoDao()
    }

    override fun onHandleIntent(intent: Intent?) {
        val totalTime: Long = (QmLog.getConfig().expiredDays * 24 * 60 * 60 * 1000).toLong()
        mDataBse.deleteExpiredItems((System.currentTimeMillis() - totalTime))
    }
}