package com.yihu.wlyy.job;

import com.yihu.wlyy.util.DateUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by lyr-pc on 2017/3/9.
 */
@Component
public class RenewToSignJob implements Job {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
//            Calendar cal = Calendar.getInstance();
//            int year = cal.get(Calendar.YEAR)-1;
//            int month = cal.get(Calendar.MONTH)+1;
//            if(month >=7){
//                //设置已过期
//                String sql = "UPDATE wlyy_sign_family t SET t.status = -4,t.apply_unsign_date='"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss")+"'  WHERE t.status>=0 AND t.sign_year='"+year+"'";
////                //数据迁移
//                String sql2 ="INSERT INTO wlyy_sign_family(" +
//                        "code,lw_code,type,patient,openid,name,idcard,ssc," +
//                        "mobile,emer_mobile,hospital,hospital_name,doctor," +
//                        "doctor_name,begin,end,images,group_code,status,reason," +
//                        "czrq,team_code,sign_type,apply_date,release_speak," +
//                        "doctor_health_name,doctor_health,family_code,patient_apply_date," +
//                        "expenses,expenses_status,sign_source,sign_doctor_code,sign_doctor_name," +
//                        "sign_doctor_level,patient_apply_unsgin_date,apply_unsign_date,expenses_type," +
//                        "sign_year,medical_insurance_num,agent_doctor_code,agent_doctor_name," +
//                        "agent_doctor_level,admin_team_code,expenses_time,server_type,server_type_name,special_population,special_population_name,renew_flag,renew_change_reason) " +
//                        "SELECT code,lw_code,type,patient,openid,name,idcard,ssc," +
//                        "mobile,emer_mobile,hospital,hospital_name,doctor,doctor_name," +
//                        "begin,end,images,group_code,status,reason,czrq,team_code," +
//                        "sign_type,apply_date,release_speak,doctor_health_name," +
//                        "doctor_health,family_code,patient_apply_date,expenses," +
//                        "expenses_status,sign_source,sign_doctor_code,sign_doctor_name," +
//                        "sign_doctor_level,patient_apply_unsgin_date,apply_unsign_date," +
//                        "expenses_type,sign_year,medical_insurance_num,agent_doctor_code," +
//                        "agent_doctor_name,agent_doctor_level,admin_team_code,expenses_time,server_type,server_type_name,special_population,special_population_name,renew_flag,renew_change_reason " +
//                        "FROM wlyy_sign_family_renew t WHERE t.is_valid =0 AND t.sign_year='"+(year+1)+"'";
//                //更改迁移状态
//                String sql3 = "UPDATE wlyy_sign_family_renew t SET t.is_valid =1 WHERE t.is_valid =0 AND t.sign_year='"+(year+1)+"'";
//                jdbcTemplate.execute(sql);
//                jdbcTemplate.execute(sql2);
//                jdbcTemplate.execute(sql3);
//            }

            System.out.println("RenewToSign end");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("RenewToSign failed");
        }
    }

}
