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

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import nc.itf.hi.ws.IPsnInfoQueryWs.IPsnInfoQueryWsPortTypeProxy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.com.countrygarden.bi.main.model.hi_psndoc_work;
import cn.com.countrygarden.bi.main.service.performance.hipsndocworkService;


@Controller("HdwController")
@RequestMapping("/HdwController")
public class HdwController {
	@Autowired
	private hipsndocworkService hipsndocworkService;
	
    @ResponseBody
    @RequestMapping(value = "/Hipsndocwork",method = {RequestMethod.POST,RequestMethod.GET})
    public void hipsndocwork(@RequestParam(value = "pageno") int pageno,@RequestParam(value = "pagesize") int pagesize){
    	IPsnInfoQueryWsPortTypeProxy ip = new IPsnInfoQueryWsPortTypeProxy();
   	    String dayin;
   	    String circle;	
   	    try {
			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=387;j<=pagenototal;j++){
			circle = ip.queryPsnWorkInfo(j, pagesize);
				/*System.out.println(circle);*/
			JSONObject jsonObjectcircle = JSON.parseObject(circle);
			JSONObject data = (JSONObject) jsonObject.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();
		}
	}
    	
    	
     
}
