package com.chinacreator.process.job;


import com.chinacreator.process.bean.TencentBillChannel;
import com.chinacreator.process.dao.TencentBillDao;
import com.chinacreator.process.service.TencentBillService;
import org.apache.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;


@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class GDtencentBillJob
{
    private static Logger log;
    @Autowired
    private TencentBillDao dao;
    @Autowired
    private TencentBillService service;
    
    static {
        GDtencentBillJob.log = Logger.getLogger((Class)GDtencentBillJob.class);
    }

    public static void main(String[] args) {
        final long stime = System.currentTimeMillis();
        final Calendar cal = Calendar.getInstance();
        final int day = cal.get(5);
        final int hour = cal.get(11);
        System.out.println(day+"==="+hour);
    }
    public void doProcess() throws Exception {
        final long stime = System.currentTimeMillis();
        final Calendar cal = Calendar.getInstance();
        final int day = cal.get(5);
        final int hour = cal.get(11);
        cal.add(5, -1);
        final String datestr = new SimpleDateFormat("yyyyMMdd").format(cal.getTime());
        if (hour >= 1) {
            try {
                final List<TencentBillChannel> list = this.dao.existChannels();
                if (list != null && list.size() > 0) {
                    for (final TencentBillChannel ch : list) {
                        this.service.Bill(ch, "1", datestr);
                        if (day == 1) {
                            this.service.Bill(ch, "2", datestr.substring(0, 6));
                        }
                    }
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            GDtencentBillJob.log.info((Object)("\u5bf9\u8d26\u65f6\u957f====" + (System.currentTimeMillis() - stime)));
        }
    }
}