package cn.com.countrygarden.bi.main.controller.Time;

import cn.com.countrygarden.bi.main.model.bd_psndoc;
import cn.com.countrygarden.bi.main.model.hi_psndoc_train;
import cn.com.countrygarden.bi.main.model.hi_psndoc_work;
import cn.com.countrygarden.bi.main.model.hi_psnjob;
import cn.com.countrygarden.bi.main.service.financial.FinancialService;
import cn.com.countrygarden.bi.main.service.performance.bdpsndocService;
import cn.com.countrygarden.bi.main.service.performance.hipsndoctrainService;
import cn.com.countrygarden.bi.main.service.performance.hipsndocworkService;
import cn.com.countrygarden.bi.main.service.performance.hipsnjobService;
import cn.com.countrygarden.bi.main.util.RedisUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import nc.itf.hi.ws.IPsnInfoQueryWs.IPsnInfoQueryWsPortTypeProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 

@Configuration
@EnableScheduling   //启用定时任务

public class RenLiTime {   
	@Autowired
	private bdpsndocService bdpsndocService;
	
	@Autowired
	private hipsndocworkService hipsndocworkService;
	
	@Autowired
	private hipsndoctrainService hipsndoctrainService;
	
	@Autowired
	private hipsnjobService hipsnjobService;

	@Autowired
    private FinancialService financialService;

	private static final Logger logger = LoggerFactory.getLogger(RenLiTime.class);
	
	//@Scheduled(cron ="34 34 23 1 * ?")
	public void time1(){
		IPsnInfoQueryWsPortTypeProxy ip = new IPsnInfoQueryWsPortTypeProxy();   
		String dayin;	
		String circle;	
			try {
				int pageno = 1;
				int pagesize = 60; 
				dayin = ip.queryPsnInfo(pageno, pagesize);
				JSONObject jsonObject = JSON.parseObject(dayin);
				String total = jsonObject.getString("total");
				int inttotal = Integer.parseInt(total);
				int pagenototal = inttotal/pagesize;
				if(inttotal%pagesize==0){
					 pagenototal = inttotal/pagesize;
				}else{
					pagenototal = inttotal/pagesize+1;
				}
				for(int j=82;j<=pagenototal;j++){
					circle = ip.queryPsnInfo(j, pagesize);
					JSONObject jsonObjectcircle = JSON.parseObject(circle);
					JSONObject data = (JSONObject) jsonObjectcircle.get("data");
					/*System.out.println("1");*/
					JSONArray psndoc = data.getJSONArray("psndoc");	
					List<bd_psndoc> bd_psndoc = new ArrayList<bd_psndoc>();
					System.out.println(psndoc);
						if(psndoc!=null||psndoc.size()!=0){ 
							for(int i=0;i<psndoc.size();i++){ 
							JSONObject jo = (JSONObject)psndoc.getJSONObject(i);
							bd_psndoc bd =new bd_psndoc();
  	       						String addr= jo.getString("addr");  
  	       						String birthdate= jo.getString("birthdate");  
  	       						String code= jo.getString("code");  
  	       						String creationtime= jo.getString("creationtime");  
  	       						String creator= jo.getString("creator");  
  	       					//分布式
  	       					    int dataoriginflag=0;
  	       						if(jo.getString("dataoriginflag")!=null) {
  	       						dataoriginflag= Integer.parseInt(jo.getString("dataoriginflag"));  
  	       						}
  	       						String email= jo.getString("email"); 
  	       						//启用状态
  	       						int enablestate=0;
  	       						if(jo.getString("sex")!=null) {
  	       						enablestate= Integer.parseInt(jo.getString("enablestate")); 
  	       						}
  	       						String homephone= jo.getString("homephone");  
  	       						String id= jo.getString("id"); 
  	       						String idtype= jo.getString("idtype"); 
  	       						String isshopassist= jo.getString("isshopassist");
  	       						String joinworkdate= jo.getString("joinworkdate"); 
  	       						String mnecode= jo.getString("mnecode"); 
  	       						String mobile= jo.getString("mobile"); 
  	       						String modifiedtime= jo.getString("modifiedtime"); 
  	       						String modifier= jo.getString("modifier"); 
  	       						String name= jo.getString("name"); 
  	       						String name2= jo.getString("name2"); 
  	       						String name3= jo.getString("name3"); 
  	       						String name4= jo.getString("name4");
  	       						String name5= jo.getString("name5"); 
  	       						String name6= jo.getString("name6"); 
  	       						String officephone= jo.getString("officephone");
  	       						String pk_group= jo.getString("pk_group");
  	       						String pk_org= jo.getString("pk_org");
  	       						String pk_psndoc= jo.getString("pk_psndoc");
  	       						
  	       						//性别
  	       					    int sex=0;
  	       						if(jo.getString("sex")!=null) {
  	       						sex= Integer.parseInt(jo.getString("sex")); 
  	       						}
  	       						
  	       						
  	       						Date ts = null;
//  	       						时间转换
  	       					    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  	       					    if(jo.getString("ts")!=null) {
  	       						 ts=df.parse(jo.getString("ts"));
  	       					    }
  	       					    
  	       						String usedname= jo.getString("usedname");
  	       						String bloodtype= jo.getString("bloodtype");
  	       						String censusaddr= jo.getString("censusaddr");
  	       						String characterrpr= jo.getString("characterrpr"); 
  	       						String country= jo.getString("country"); 
  	       						String die_date= jo.getString("die_date");
  	       						String die_remark= jo.getString("die_remark"); 
  	       						String edu= jo.getString("edu"); 
  	       						String fax= jo.getString("fax"); 
  	       						String fileaddress= jo.getString("fileaddress");
  	       						String health= jo.getString("health"); 
  	       						String ishiskeypsn= jo.getString("ishiskeypsn");
  	       						String joinpolitydate= jo.getString("joinpolitydate");
  	       						String marital= jo.getString("marital");  
  	       						String marriagedate= jo.getString("marriagedate"); 
  	       						String nationality= jo.getString("nationality"); 
  	       						String nativeplace= jo.getString("nativeplace"); 
  	       						String penelauth= jo.getString("penelauth");  
  	       						String permanreside= jo.getString("permanreside");
  	       					//照片	
  	       					    byte[] photo=null;
  	       					    String pho=jo.getString("photo");
  	       					    if(pho!=null) {
  	       						photo=pho.getBytes(); 
  	       					    }
  	       					    
  	       						String pk_degree= jo.getString("pk_degree");
  	       						String pk_hrorg= jo.getString("pk_hrorg"); 
  	       						String polity= jo.getString("polity");  
  	       						String postalcode= jo.getString("postalcode");
  	       						
  	       					    byte[] previewphoto=null;
  	       					    String pre=jo.getString("previewphoto");
  	       					    if(pre!=null) {
  	       					    previewphoto= pre.getBytes();
  	       					    }
  	       					    String prof= jo.getString("prof");  
  	       						String retiredate= jo.getString("retiredate");
  	       						String secret_email= jo.getString("secret_email");
  	       						String shortname= jo.getString("shortname");  
  	       						String titletechpost= jo.getString("titletechpost"); 
  	       						String firstname= jo.getString("firstname");  
  	       						String lastname= jo.getString("lastname");  
  	       						String iscadre= jo.getString("iscadre");  
  	       						String ishisleader= jo.getString("ishisleader");
  	       						String age= jo.getString("age");  
  	       						String workage= jo.getString("workage"); 
  	       						String glbdef21= jo.getString("glbdef21"); 
  	       						String glbdef1= jo.getString("glbdef1"); 
  	       						String glbdef2= jo.getString("glbdef2"); 
  	       						String glbdef3= jo.getString("glbdef3"); 
  	       						String glbdef4= jo.getString("glbdef4"); 
  	       						String glbdef5= jo.getString("glbdef5"); 
  	       						String glbdef6= jo.getString("glbdef6"); 
  	       						String glbdef7= jo.getString("glbdef7");  
  	       						String glbdef8= jo.getString("glbdef8"); 
  	       						String glbdef9= jo.getString("glbdef9"); 
  	       						String glbdef10= jo.getString("glbdef10");
  	       						String glbdef11= jo.getString("glbdef11"); 
  	       						String glbdef12= jo.getString("glbdef12"); 
  	       						String glbdef13= jo.getString("glbdef13"); 
  	       						String glbdef14= jo.getString("glbdef14"); 
  	       						String glbdef15= jo.getString("glbdef15"); 
  	       						String glbdef17= jo.getString("glbdef17"); 
  	       						String glbdef18= jo.getString("glbdef18"); 
  	       						String glbdef19= jo.getString("glbdef19"); 
  	       						String glbdef20= jo.getString("glbdef20"); 
  	       						String glbdef22= jo.getString("glbdef22"); 
  	       						String glbdef23= jo.getString("glbdef23"); 
  	       						String glbdef16= jo.getString("glbdef16"); 
  	       						String glbdef24= jo.getString("glbdef24"); 
  	       						String glbdef25= jo.getString("glbdef25"); 
  	       						String glbdef26= jo.getString("glbdef26"); 
  	       						String glbdef27= jo.getString("glbdef27"); 
  	       						String glbdef28= jo.getString("glbdef28"); 
  	       						String glbdef29= jo.getString("glbdef29");
  	       						String glbdef30= jo.getString("glbdef30"); 
  	       						String rn= jo.getString("rn"); 
  	       						String dr= jo.getString("dr");
                                bd.setADDR(addr);
                                bd.setBIRTHDATE(birthdate); 
                                bd.setCODE(code);  
                                bd.setCREATIONTIME(creationtime); 
                                bd.setCREATOR(creator);
                                bd.setDATAORIGINFLAG(dataoriginflag);
                                bd.setEMAIL(email); 
                                bd.setENABLESTATE(enablestate);
                                bd.setHOMEPHONE(homephone); 
                                bd.setID(id); 
                                bd.setIDTYPE(idtype);
                                bd.setISSHOPASSIST(isshopassist);
                                bd.setJOINWORKDATE(joinworkdate);
                                bd.setMNECODE(mnecode);
                                bd.setMOBILE(mobile); 
                                bd.setMODIFIEDTIME(modifiedtime);
                                bd.setMODIFIER(modifier);
                                bd.setNAME(name);
                                bd.setNAME2(name2);
                                bd.setNAME3(name3);
                                bd.setNAME4(name4);
                                bd.setNAME5(name5);
                                bd.setNAME6(name6);
                                bd.setOFFICEPHONE(officephone);
                                bd.setPK_GROUP(pk_group);
                                bd.setPK_ORG(pk_org);
                                bd.setPK_PSNDOC(pk_psndoc);
                                bd.setSEX(sex);
                                bd.setTS(ts);
                                bd.setUSEDNAME(usedname);
                                bd.setBLOODTYPE(bloodtype);
                                bd.setCENSUSADDR(censusaddr);
                                bd.setCHARACTERRPR(characterrpr);
                                bd.setCOUNTRY(country);
                                bd.setDIE_DATE(die_date);
                                bd.setDIE_REMARK(die_remark);
                                bd.setEDU(edu);
                                bd.setFAX(fax); 
                                bd.setFILEADDRESS(fileaddress);
                                bd.setHEALTH(health);
                                bd.setISHISKEYPSN(ishiskeypsn);
                                bd.setJOINPOLITYDATE(joinpolitydate);
                                bd.setMARITAL(marital);
                                bd.setMARRIAGEDATE(marriagedate);
                                bd.setNATIONALITY(nationality);
                                bd.setNATIVEPLACE(nativeplace);
                                bd.setPENELAUTH(penelauth);
                                bd.setPERMANRESIDE(permanreside);
                                bd.setPHOTO(photo);
                                bd.setPK_DEGREE(pk_degree);
                                bd.setPK_HRORG(pk_hrorg);
                                bd.setPOLITY(polity); 
                                bd.setPOSTALCODE(postalcode);
                                bd.setPREVIEWPHOTO(previewphoto);
                                bd.setPROF(prof); 
                                bd.setRETIREDATE(retiredate); 
                                bd.setSECRET_EMAIL(secret_email);
                                bd.setSHORTNAME(shortname);
                                bd.setTITLETECHPOST(titletechpost);
                                bd.setFIRSTNAME(firstname); 
                                bd.setLASTNAME(lastname);
                                bd.setISCADRE(iscadre);
                                bd.setISHISLEADER(ishisleader);
                                bd.setAGE(age); 
                                bd.setWORKAGE(workage); 
                                bd.setGLBDEF21(glbdef21);
                                bd.setGLBDEF1(glbdef1);
                                bd.setGLBDEF2(glbdef2); 
                                bd.setGLBDEF3(glbdef3); 
                                bd.setGLBDEF4(glbdef4); 
                                bd.setGLBDEF5(glbdef5); 
                                bd.setGLBDEF6(glbdef6); 
                                bd.setGLBDEF7(glbdef7); 
                                bd.setGLBDEF8(glbdef8); 
                                bd.setGLBDEF9(glbdef9); 
                                bd.setGLBDEF10(glbdef10);
                                bd.setGLBDEF11(glbdef11);
                                bd.setGLBDEF12(glbdef12); 
                                bd.setGLBDEF13(glbdef13); 
                                bd.setGLBDEF14(glbdef14);
                                bd.setGLBDEF15(glbdef15);
                                bd.setGLBDEF17(glbdef17);
                                bd.setGLBDEF18(glbdef18);
                                bd.setGLBDEF19(glbdef19);
                                bd.setGLBDEF20(glbdef20);
                                bd.setGLBDEF22(glbdef22);
                                bd.setGLBDEF23(glbdef23); 
                                bd.setGLBDEF16(glbdef16);
                                bd.setGLBDEF24(glbdef24);
                                bd.setGLBDEF25(glbdef25);
                                bd.setGLBDEF26(glbdef26);
                                bd.setGLBDEF27(glbdef27);
                                bd.setGLBDEF28(glbdef28);
                                bd.setGLBDEF29(glbdef29);
                                bd.setGLBDEF30(glbdef30);
                                bd.setRN(rn); 
                                bd.setDR(dr);
                                bd_psndoc.add(bd);
					//设置区域								
							bd= null;
							System.gc();

						}
					}	
						bdpsndocService.insertOrUpdate(bd_psndoc);	
						bd_psndoc = null;
						System.gc();
				}						
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
 }
	
	
	//@Scheduled(cron ="0 0 12 2 * ?")
	public void time2(){
		IPsnInfoQueryWsPortTypeProxy ip = new IPsnInfoQueryWsPortTypeProxy();  
  	  String dayin;
   	  String circle;	
   	    try {      
   	    	int pageno = 1;
			int pagesize = 70; 
			dayin = ip.queryPsnTrainInfo(pageno, pagesize);
//			System.out.println(dayin);
			JSONObject jsonObject = JSON.parseObject(dayin);
			String total = jsonObject.getString("total");
			int inttotal = Integer.parseInt(total);
			int pagenototal = inttotal/pagesize;
			if(inttotal%pagesize==0){
				 pagenototal = inttotal/pagesize;
			}else{
				pagenototal = inttotal/pagesize+1;
			}
			for(int j=5704;j<=pagenototal;j++){
			circle = ip.queryPsnTrainInfo(j, pagesize);
			System.out.println(circle);
			JSONObject jsonObjectcircle = JSON.parseObject(circle);
			JSONObject data = (JSONObject) jsonObjectcircle.get("data");
			System.out.println(data);
			JSONArray train = data.getJSONArray("train");	
		   	List<hi_psndoc_train> hi_psndoc_train = new ArrayList<hi_psndoc_train>();
			System.out.println(train);
			if(train!=null||train.size()!=0){ 
				for(int i=0;i<train.size();i++){ 
					JSONObject jo = (JSONObject)train.getJSONObject(i);
					hi_psndoc_train hit=new hi_psndoc_train();
					String absence_count= jo.getString("absence_count"); 
					String act_code= jo.getString("act_code");
					String act_name= jo.getString("act_name");
					String act_name2= jo.getString("act_name2");
					String act_name3= jo.getString("act_name3");
					String act_name4= jo.getString("act_name4");
					String act_name5= jo.getString("act_name5");
					String act_name6= jo.getString("act_name6");
					String ass_option= jo.getString("ass_option");
					String ass_result= jo.getString("ass_result");
					String assist_unit= jo.getString("assist_unit");
					String begindate= jo.getString("begindate");
					String certificate_date= jo.getString("certificate_date");
					String certificate_unit= jo.getString("certificate_unit");
					String contcode= jo.getString("contcode");
					String creationtime= jo.getString("creationtime");
					String creator= jo.getString("creator");
					String enddate= jo.getString("enddate"); 
					String entrepreneur= jo.getString("entrepreneur");
					String isallduty= jo.getString("isallduty");
					String lastflag= jo.getString("lastflag"); 
					String memo= jo.getString("memo");
					String modifiedtime= jo.getString("modifiedtime");
					String modifier= jo.getString("modifier"); 
					String pk_act= jo.getString("pk_act");
					String pk_group= jo.getString("pk_group"); 
					String pk_org= jo.getString("pk_org"); 
					String pk_psndoc= jo.getString("pk_psndoc"); 
					String pk_psndoc_sub= jo.getString("pk_psndoc_sub");
					String pk_psnjob= jo.getString("pk_psnjob");
					String pk_psnorg= jo.getString("pk_psnorg");
					String purveyor= jo.getString("purveyor"); 
					String recordnum= jo.getString("recordnum");
					String signon_dt= jo.getString("signon_dt"); 
					
					int source_type=0;
					if(jo.getString("source_type")!=null) {
						source_type=Integer.parseInt(jo.getString("source_type"));
					}
					
					int taketrm_method=0;
					if(jo.getString("taketrm_method")!=null){
					taketrm_method=Integer.parseInt(jo.getString("taketrm_method"));
					}
					
					String tra_content= jo.getString("tra_content"); 
					String tra_cost= jo.getString("tra_cost");
					String tra_mode= jo.getString("tra_mode"); 
					String tra_result= jo.getString("tra_result"); 
					String tra_time= jo.getString("tra_time"); 
					String tra_type= jo.getString("tra_type"); 
					String traim= jo.getString("traim"); 
					String trm_certif_code= jo.getString("trm_certif_code");
					String trm_certif_name= jo.getString("trm_certif_name"); 
					String trm_location= jo.getString("trm_location"); 
					String ts= jo.getString("ts"); 
					
					int glbdef1=0;
					if(jo.getString("glbdef1")!=null) {
						glbdef1=Integer.parseInt(jo.getString("glbdef1"));
					}
					
					String glbdef2= jo.getString("glbdef2"); 
					String glbdef3= jo.getString("glbdef3"); 
					String glbdef4= jo.getString("glbdef4"); 
					String rn= jo.getString("rn"); 
					String dr= jo.getString("dr"); 
					hit.setABSENCE_COUNT(absence_count); 
					hit.setACT_CODE(act_code); 
					hit.setACT_NAME(act_name); 
					hit.setACT_NAME2(act_name2);
					hit.setACT_NAME3(act_name3); 
					hit.setACT_NAME4(act_name4); 
					hit.setACT_NAME5(act_name5); 
					hit.setACT_NAME6(act_name6); 
					hit.setASS_OPTION(ass_option); 
					hit.setASS_RESULT(ass_result); 
					hit.setASSIST_UNIT(assist_unit); 
					hit.setBEGINDATE(begindate); 
					hit.setCERTIFICATE_DATE(certificate_date); 
					hit.setCERTIFICATE_UNIT(certificate_unit); 
					hit.setCONTCODE(contcode); 
					hit.setCREATIONTIME(creationtime); 
					hit.setCREATOR(creator); 
					hit.setENDDATE(enddate); 
					hit.setENTREPRENEUR(entrepreneur); 
					hit.setISALLDUTY(isallduty); 
					hit.setLASTFLAG(lastflag); 
					hit.setMEMO(memo); 
					hit.setMODIFIEDTIME(modifiedtime); 
					hit.setMODIFIER(modifier); 
					hit.setPK_ACT(pk_act); 
					hit.setPK_GROUP(pk_group);
					hit.setPK_ORG(pk_org);
					hit.setPK_PSNDOC(pk_psndoc);
					hit.setPK_PSNDOC_SUB(pk_psndoc_sub); 
					hit.setPK_PSNJOB(pk_psnjob); 
					hit.setPK_PSNORG(pk_psnorg); 
					hit.setPURVEYOR(purveyor); 
					hit.setRECORDNUM(recordnum);
					hit.setSIGNON_DT(signon_dt); 
					hit.setSOURCE_TYPE(source_type); 
					hit.setTAKETRM_METHOD(taketrm_method); 
					hit.setTRA_CONTENT(tra_content); 
					hit.setTRA_COST(tra_cost); 
					hit.setTRA_MODE(tra_mode); 
					hit.setTRA_RESULT(tra_result); 
					hit.setTRA_TIME(tra_time); 
					hit.setTRA_TYPE(tra_type); 
					hit.setTRAIM(traim); 
					hit.setTRM_CERTIF_CODE(trm_certif_code); 
					hit.setTRM_CERTIF_NAME(trm_certif_name); 
					hit.setTRM_LOCATION(trm_location); 
					hit.setTS(ts); 
					hit.setGLBDEF1(glbdef1); 
					hit.setGLBDEF2(glbdef2); 
					hit.setGLBDEF3(glbdef3); 
					hit.setGLBDEF4(glbdef4); 
					hit.setRN(rn); 
					hit.setDR(dr);
					hi_psndoc_train.add(hit);
					hit=null;
					System.gc();
				 }
				}
			     hipsndoctrainService.insertOrUpdate(hi_psndoc_train);
			     hi_psndoc_train = null;
				 System.gc();
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	//@Scheduled(cron ="0 0 12 3 * ?")
	public void time3(){
		IPsnInfoQueryWsPortTypeProxy ip = new IPsnInfoQueryWsPortTypeProxy();
   	    String dayin;
   	    String circle;	
   	    try {
   	    	int pageno = 1;
			int pagesize = 85; 
			dayin = ip.queryPsnWorkInfo(pageno, pagesize);
//			System.out.println(dayin);
			JSONObject jsonObject = JSON.parseObject(dayin);	
			String total = jsonObject.getString("total");
			int inttotal = Integer.parseInt(total);
			//这里需要加判断是否为奇数
			int pagenototal = inttotal/pagesize;
			if(inttotal%pagesize==0){
				 pagenototal = inttotal/pagesize;
			}else{
				pagenototal = inttotal/pagesize+1;
			}
			for(int j=1962;j<=pagenototal;j++){
			circle = ip.queryPsnWorkInfo(j, pagesize);
				/*System.out.println(circle);*/
			JSONObject jsonObjectcircle = JSON.parseObject(circle);
			JSONObject data = (JSONObject) jsonObjectcircle.get("data");
			/*System.out.println(data);*/
			JSONArray work = data.getJSONArray("work");	
		    List<hi_psndoc_work> hi_psndoc_work = new ArrayList<hi_psndoc_work>();
			/*System.out.println(work);*/
			if(work!=null||work.size()!=0){ 
				for(int i=0;i<work.size();i++){ 
					JSONObject jo = (JSONObject)work.getJSONObject(i);
					hi_psndoc_work hi=new hi_psndoc_work();
					String begindate = jo.getString("begindate");
					String bg_check = jo.getString("bg_check");
					String certifier = jo.getString("certifier");
					String certiphone = jo.getString("certiphone");
					String creationtime = jo.getString("creationtime");
					String creator = jo.getString("creator");
					String dimission_reason = jo.getString("dimission_reason");
					String enddate = jo.getString("enddate");
					String lastflag = jo.getString("lastflag");
					String linkphone = jo.getString("linkphone");
					String memo = jo.getString("memo");
					String modifiedtime = jo.getString("modifiedtime");
					String modifier = jo.getString("modifier");
					String pk_group = jo.getString("pk_group");
					String pk_org = jo.getString("pk_org");
					String pk_psndoc = jo.getString("pk_psndoc");
					String pk_psndoc_sub = jo.getString("pk_psndoc_sub");
					String pk_psnjob = jo.getString("pk_psnjob");
					String pk_psnorg = jo.getString("pk_psnorg");
					String recordnum = jo.getString("recordnum");
					String ts = jo.getString("ts");
					String work_addr = jo.getString("work_addr");
					String workachive = jo.getString("workachive");
					String workcorp = jo.getString("workcorp");
					String workdept = jo.getString("workdept");
					String workduty = jo.getString("workduty");
					String workjob = jo.getString("workjob");
					String workpost = jo.getString("workpost");
					String glbdef1 = jo.getString("glbdef1");
					String glbdef2 = jo.getString("glbdef2");
					String glbdef3 = jo.getString("glbdef3");
					String glbdef4 = jo.getString("glbdef4");
					String glbdef5 = jo.getString("glbdef5");
					String glbdef6 = jo.getString("glbdef6");
					String glbdef7 = jo.getString("glbdef7");
					String glbdef8 = jo.getString("glbdef8");
					String glbdef9 = jo.getString("glbdef9");
					String glbdef10 = jo.getString("glbdef10");
					String glbdef11 = jo.getString("glbdef11");
					String glbdef12 = jo.getString("glbdef12");
					String glbdef13 = jo.getString("glbdef13");
					String glbdef14 = jo.getString("glbdef14");
					String rn = jo.getString("rn");
					String dr = jo.getString("dr");					
					hi.setBEGINDATE(begindate);
					hi.setBG_CHECK(bg_check);
					hi.setCERTIFIER(certifier);
					hi.setCERTIPHONE(certiphone);
					hi.setCREATIONTIME(creationtime);
					hi.setCREATOR(creator);
					hi.setDIMISSION_REASON(dimission_reason);
					hi.setENDDATE(enddate);
					hi.setLASTFLAG(lastflag);
					hi.setLINKPHONE(linkphone);
					hi.setMEMO(memo);
					hi.setMODIFIEDTIME(modifiedtime);
					hi.setMODIFIER(modifier);
					hi.setPK_GROUP(pk_group);
					hi.setPK_ORG(pk_org);
					hi.setPK_PSNDOC(pk_psndoc);
					hi.setPK_PSNDOC_SUB(pk_psndoc_sub);
					hi.setPK_PSNJOB(pk_psnjob); 
					hi.setPK_PSNORG(pk_psnorg);
					hi.setRECORDNUM(recordnum);
					hi.setTS(ts);
					hi.setWORK_ADDR(work_addr);
					hi.setWORKACHIVE(workachive);
					hi.setWORKCORP(workcorp);
					hi.setWORKDEPT(workdept);
					hi.setWORKDUTY(workduty);
					hi.setWORKJOB(workjob);
					hi.setWORKPOST(workpost);
					hi.setGLBDEF1(glbdef1);
					hi.setGLBDEF2(glbdef2);
					hi.setGLBDEF3(glbdef3);
					hi.setGLBDEF4(glbdef4);
					hi.setGLBDEF5(glbdef5);
					hi.setGLBDEF6(glbdef6);
					hi.setGLBDEF7(glbdef7);
					hi.setGLBDEF8(glbdef8);
					hi.setGLBDEF9(glbdef9);
					hi.setGLBDEF10(glbdef10);
					hi.setGLBDEF11(glbdef11);
					hi.setGLBDEF12(glbdef12);
					hi.setGLBDEF13(glbdef13);
					hi.setGLBDEF14(glbdef14);
					hi.setRN(rn);
					hi.setDR(dr);
					hi_psndoc_work.add(hi);
					hi=null;
  					System.gc();
				 }
				}
			
			     hipsndocworkService.insertOrUpdate(hi_psndoc_work);
			     hi_psndoc_work = null;
				 System.gc();
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	//@Scheduled(cron ="0 0 1 4 * ?")
	public void time4(){
		IPsnInfoQueryWsPortTypeProxy ip = new IPsnInfoQueryWsPortTypeProxy();
   	    String dayin;
   	    String circle;	
   	 try {
   		    int pageno = 1;
		    int pagesize = 95; 
			dayin = ip.queryPsnJobInfo(pageno, pagesize);
//			System.out.println(dayin);
			JSONObject jsonObject = JSON.parseObject(dayin);
			String total = jsonObject.getString("total");
			int inttotal = Integer.parseInt(total);
			int pagenototal = inttotal/pagesize;
			if(inttotal%pagesize==0){
				 pagenototal = inttotal/pagesize;
			}else{
				pagenototal = inttotal/pagesize+1;
			}
			for(int j=56;j<=pagenototal;j++){
			circle = ip.queryPsnJobInfo(j, pagesize);
				/*System.out.println(circle);*/
			JSONObject jsonObjectcircle = JSON.parseObject(circle);
			JSONObject data = (JSONObject) jsonObjectcircle.get("data");
		/*	System.out.println(data);*/
			JSONArray psnjob = data.getJSONArray("psnjob");	
	   	    List<hi_psnjob> hi_psnjob = new ArrayList<hi_psnjob>();
			/*System.out.println(psnjob);*/
			if(psnjob!=null||psnjob.size()!=0){ 
				for(int i=0;i<psnjob.size();i++){ 
					JSONObject jo = (JSONObject)psnjob.getJSONObject(i);
					hi_psnjob hij=new hi_psnjob();
					String jobmode = jo.getString("jobmode");
					hij.setJOBMODE(jobmode);
					String memo = jo.getString("memo");
					hij.setMEMO(memo);
					String oribilltype = jo.getString("oribilltype");
					hij.setORIBILLTYPE(oribilltype);
					String oribillpk = jo.getString("oribillpk");
					hij.setORIBILLPK(oribillpk);
					String occupation = jo.getString("occupation");
					hij.setOCCUPATION(occupation);
					        String lastflag = jo.getString("lastflag");
					        hij.setLASTFLAG(lastflag);
					        
					        int psntype=0;
					        if(jo.getString("psntype")!=null){
					         psntype=Integer.parseInt(jo.getString("psntype"));	
					        }
					        
							String pk_dept = jo.getString("pk_dept");
					        hij.setPK_DEPT(pk_dept);
							String jobglbdef1 = jo.getString("jobglbdef1");
					        hij.setJOBGLBDEF1(jobglbdef1);
							String jobglbdef2 = jo.getString("jobglbdef2");
					        hij.setJOBGLBDEF2(jobglbdef2);
							String dr = jo.getString("dr");
					        hij.setDR(dr);
							String jobglbdef4 = jo.getString("jobglbdef4");
					        hij.setJOBGLBDEF4(jobglbdef4);
							String jobglbdef5 = jo.getString("jobglbdef5");
					        hij.setJOBGLBDEF5(jobglbdef5);
							String recordnum = jo.getString("recordnum");
					        hij.setRECORDNUM(recordnum);
							String modifiedtime = jo.getString("modifiedtime");
					        hij.setMODIFIEDTIME(modifiedtime);
							String pk_org = jo.getString("pk_org");
					        hij.setPK_ORG(pk_org);
							String assgid = jo.getString("assgid");
					        hij.setASSGID(assgid);
							String creationtime = jo.getString("creationtime");
					        hij.setCREATIONTIME(creationtime);
							String creator = jo.getString("creator");
					        hij.setCREATOR(creator);
							String pk_psncl = jo.getString("pk_psncl");
					        hij.setPK_PSNCL(pk_psncl);
					        
					        int trnsevent=0;
					        if(jo.getString("trnsevent")!=null) {
					        trnsevent=Integer.parseInt(jo.getString("trnsevent"));
					        }
					        
							String pk_group = jo.getString("pk_group");
					        hij.setPK_GROUP(pk_group);
							String rn = jo.getString("rn");
					        hij.setRN(rn);
							String clerkcode = jo.getString("clerkcode");
							hij.setCLERKCODE(clerkcode);
							String endflag = jo.getString("endflag");
							hij.setENDFLAG(endflag);
							String trnsreason = jo.getString("trnsreason");
							hij.setTRNSREASON(trnsreason);
							String pk_psndoc = jo.getString("pk_psndoc");
							hij.setPK_PSNDOC(pk_psndoc);
							String pk_hrorg = jo.getString("pk_hrorg");
							hij.setPK_HRORG(pk_hrorg);
							String pk_psnjob = jo.getString("pk_psnjob");
							hij.setPK_PSNJOB(pk_psnjob);
							String modifier = jo.getString("modifier");
							hij.setMODIFIER(modifier);
							String begindate = jo.getString("begindate");
							hij.setBEGINDATE(begindate);
							String pk_postseries = jo.getString("pk_postseries");
							hij.setPK_POSTSERIES(pk_postseries);
							String pk_post = jo.getString("pk_post");
							hij.setPK_POST(pk_post);
							String showorder = jo.getString("showorder");
							hij.setSHOWORDER(showorder);
							String pk_hrgroup = jo.getString("pk_hrgroup");
							hij.setPK_HRGROUP(pk_hrgroup);
							String poststat = jo.getString("poststat");
							hij.setPOSTSTAT(poststat);
							String trial_flag = jo.getString("trial_flag");
							hij.setTRIAL_FLAG(trial_flag);
							String ismainjob = jo.getString("ismainjob");
							hij.setISMAINJOB(ismainjob);
							String pk_psnorg = jo.getString("pk_psnorg");
							hij.setPK_PSNORG(pk_psnorg);
							String trnstype = jo.getString("trnstype");
							hij.setTRNSTYPE(trnstype);
							String ts = jo.getString("ts");
							hij.setTS(ts);
							String pk_dept_v = jo.getString("pk_dept_v");
							hij.setPK_DEPT_V(pk_dept_v);
							String pk_job = jo.getString("pk_job");
							hij.setPK_JOB(pk_job);
							String pk_job_type = jo.getString("pk_job_type");
							hij.setPK_JOB_TYPE(pk_job_type);
							String pk_jobrank = jo.getString("pk_jobrank");
							hij.setPK_JOBRANK(pk_jobrank);
							String series =jo.getString("series");
							hij.setSERIES(series);
							String jobglbdef3 = jo.getString("jobglbdef3");
							hij.setJOBGLBDEF3(jobglbdef3);
							String jobglbdef6 = jo.getString("jobglbdef6");
							hij.setJOBGLBDEF6(jobglbdef6);
							String pk_org_v = jo.getString("pk_org_v");
							hij.setPK_ORG_V(pk_org_v);
							String jobglbdef8 = jo.getString("jobglbdef8");
							hij.setJOBGLBDEF8(jobglbdef8);
							String jobglbdef9 = jo.getString("jobglbdef9");
							hij.setJOBGLBDEF9(jobglbdef9);
							String jobglbdef7 = jo.getString("jobglbdef7");
							hij.setJOBGLBDEF7(jobglbdef7);
							String jobglbdef10 = jo.getString("jobglbdef10");
							hij.setJOBGLBDEF10(jobglbdef10);
							String jobglbdef11 = jo.getString("jobglbdef11");
							hij.setJOBGLBDEF11(jobglbdef11);
							
							int dataoriginflag=0;
							if(jo.getString("dataoriginflag")!=null){
							dataoriginflag =Integer.parseInt(jo.getString("dataoriginflag"));
							}
							
							hij.setDATAORIGINFLAG(dataoriginflag);
							
							String deposemode = jo.getString("deposemode");
							hij.setDEPOSEMODE(deposemode);
							String enddate = jo.getString("enddate");
							hij.setENDDATE(enddate);
					hi_psnjob.add(hij);	
					hij=null;
  					System.gc();
				
				 }
				}
			       hipsnjobService.insertOrUpdate(hi_psnjob);
			       hi_psnjob = null;
				   System.gc();
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	//每月15号定期删除一次PLByMonth缓存数据
	@Scheduled(cron = "0 0 0 15 * ?")
	public void finanicalPLByMonthTime(){
		logger.info(String.valueOf(RedisUtils.del("bgyNCFinanicalPLByMonth")));
	}
	//每日0时定期删除一次PLByProject缓存数据 并且获取2017、2018年 所有区域的数据 进入缓存
	@Scheduled(cron = "0 0 0 * * ?")
	public void finanicalPLByProjectTime(){
		logger.info(String.valueOf(RedisUtils.del("bgyNCFinanicalPLByProject")));
//		List<String> organCodeList = tbHsprCommunityService.selectAllOrganCode();
//		for (String organCode : organCodeList) {
//			logger.info(String.valueOf(RedisUtils.hset("bgyNCFinanicalPLByProject",organCode+"2017", JSONObject.toJSONString(
//					financialService.getPLByProject(organCode,null,"2017",1)))));
//			logger.info(String.valueOf(RedisUtils.hset("bgyNCFinanicalPLByProject",organCode+"2018", JSONObject.toJSONString(
//					financialService.getPLByProject(organCode,null,"2018",1)))));
//		}
	}



    @Scheduled(cron = "0 30 2 */2 * ?")
    public void saveDataToRedis() {
        String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
        try {
            financialService.saveErpDataToRedis(year, null);
        } catch (Exception e) {
            System.out.println("NC财务ERP收入数据定时入库失败，Reason:" + e.getMessage());
        }
    }
}
