package com.saye.hrs.scheduler;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import com.saye.hrs.commons.date.DateDUtil;
import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.commons.webservice.WSUtil;
import com.saye.hrs.service.PatientService;


@Configuration
public class SyncAccountRecord {

	@Resource
    private PatientService patientService;
	/**
	 * @description 定时同步金额记录
	 * @author dqzhang       
	 * @created 2020年4月26日 下午5:25:03
	 */
    @Scheduled(cron="0 59 23 * * ?")
    public void run() {
    	LogUtil.debug(SyncAccountRecord.class, "定时同步金额记录开始");
    	try {
    		
    		String ksrq = DateDUtil.DateToStr("yyyyMMdd", new Date());
    		HashMap<Object,Object> map = WSUtil.getAccountRecord(ksrq, ksrq);
    		if("0".equals(map.get("errCode"))) {
    			List<HashMap<Object,Object>> list =  (List<HashMap<Object, Object>>) map.get("list");
    			this.patientService.syncAccountRecord(list);
    		}
    	} catch (Exception e) {
			LogUtil.error(SyncAccountRecord.class, "定时同步金额记录异常"+e.toString());
		}
    	LogUtil.debug(SyncAccountRecord.class, "定时同步金额记录结束");
    }
}
