18a58f10a72068f33258f635485b7ebd01ab3528.svn-base 12.4 KB
package com.thinkgem.jeesite.modules.reg.web.updata;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import java.io.File;
import org.apache.commons.io.FileUtils;
//import com.inspur.uaccess.common.utils.RSASignature;

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

import com.inspur.uaccess.common.utils.RSASignature;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.mapper.JaxbMapper;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.xml.JXmlUtils;
import com.thinkgem.jeesite.common.web.BaseController;

import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusQlr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusTdsyq;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZdjbxx;
import com.thinkgem.jeesite.modules.reg.entity.updata.RegBusSjhjtable;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseChxx11Service;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusQlrService;
import com.thinkgem.jeesite.modules.reg.service.qjxt.ZdK103Service;
import com.thinkgem.jeesite.modules.rest.wsapi.dto.service.RestfulService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import com.thinkgem.jeesite.modules.reg.service.updata.RegBusSjhjtableService;
import com.thinkgem.jeesite.modules.reg.entity.bus.change.RegBusCSlsq;
import com.thinkgem.jeesite.modules.reg.entity.qjxt.ZdK103;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseChxx11;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZdbhqk;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSjmain;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSjchild;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSf;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSfSub;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSh;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSz;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusFz;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusGd;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSqr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusYwr;
import com.thinkgem.jeesite.modules.act.entity.Act;
import com.thinkgem.jeesite.modules.reg.utils.RegUtils;
import com.thinkgem.jeesite.modules.reg.web.bus.change.RegBusCSlsqController;
/**
 * 数据汇交Controller 
 * @author xuyg
 * @version 2015-10-12
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/updata/regBusSjhjtable")
public class CSCDJ3000101Controller extends BaseController {
	
	@Autowired
    private RestfulService restfulService; 
	@Autowired
	private RegBusQlrService regBusQlrService;
	@Autowired
	private RegBusSjhjtableService regBusSjhjtableService;
	@Autowired
	private RegBusCSlsqController regBusCSlsqController;
	@Autowired
	private ZdK103Service kService;
	@Autowired
	private RegBaseChxx11Service regBaseChxxService;
	
    public String updataCSCDJ3000101xml(RegBusTdsyq regBusTdsyq,RegBusQlr regBusQlr,RegBusCSlsq regBusCSlsq,RegBaseZdbhqk regBaseZdbhqk,RegBusSjmain regBusSjmain,RegBusSf regBusSf,RegBusSh regBusSh,RegBusSz regBusSz,RegBusFz regBusFz,RegBusGd regBusGd,RegBusSqr regBusSqr,RegBaseZdjbxx regBaseZdjbxx,RegBusYwr regBusYwr,List<Act> list) throws Exception{  
        Date date=new Date();
        String tempReturnValue="";
    	//报文头部数据填充
    	RegBusSjhjtable regBusSjhjtable = new RegBusSjhjtable();
    
    	regBusSjhjtable.setBizmsgid(Global.getAreaCode());//set
        regBusSjhjtable.setAsid("AS100");
        regBusSjhjtable.setAreacode(Global.getAreaCode());
        regBusSjhjtable.setRectype("3000101");
        regBusSjhjtable.setRighttype(regBusTdsyq.getQllx());
        //regBusSjhjtable.setRegtype(regBusTdsyq.getDjlx());  
        if(StringUtils.isNotBlank(regBusCSlsq.getDjdl())){
        	 regBusSjhjtable.setRegtype(regBusCSlsq.getDjdl());//set上次不动产权证号
        }
        else  regBusSjhjtable.setRegtype(" ");
       
        regBusSjhjtable.setCreatedate(new Date());
   
		regBusSjhjtable.setRecflowid(regBusTdsyq.getYwh());//set业务号
       // regBusSjhjtable.setRegorgid(regBusTdsyq.getDjjg());//set登记机构
        if(StringUtils.isNotBlank(regBusTdsyq.getDjjg())){
       	 regBusSjhjtable.setRegorgid(regBusTdsyq.getDjjg());//set上次不动产权证号
        }
        else{
        	String xzq=DictUtils.getDictLabels(Global.getAreaCode(), "reg_bus_xq", "");
        	xzq="陕西省汉中市"+xzq+"不动产登记交易服务中心";         	      	       	        	
        	regBusSjhjtable.setRegorgid(xzq);
        }
        regBusSjhjtable.setParcelid(regBusTdsyq.getZddm());//set宗地/宗海代码
        regBusSjhjtable.setEstatenum(regBusTdsyq.getBdcdyh());//set不动产单元号
        regBusSjhjtable.setPreestatenum(regBusTdsyq.getBdcdyh());//set上次不动产单元号
        if(StringUtils.isNotBlank(regBusTdsyq.getBdcqzh())){
          	 regBusSjhjtable.setPrecertid(regBusTdsyq.getBdcqzh());//set上次不动产权证号
           }
           else  regBusSjhjtable.setPrecertid(" ");
        regBusSjhjtable.setCertcount("0");//set不动产权证号码数量
        regBusSjhjtable.setProofcount("0");//set证明号码数量
        
        /* 原报文顺序号生产
        int currentNum = 0;
		String maxZddmSxh = regBusSjhjtableService.findMaxBizmsgid();//使用当前宗地代码
		currentNum=RegUtils.getxh(maxZddmSxh);
   	    // 0 代表前面补充0     
	    // 4 代表长度为4     
	    // d 代表参数为正数型     
	    String str = String.format("%06d", currentNum+1);     
		regBusSjhjtable.setBizmsgid(Global.getAreaCode()+String.format("%ty", date)+String.format("%tm", date)+String.format("%td", date)+str);
	    */
        
        //查询并生成报文编号
        String bizmsgid = regBusSjhjtableService.Frandom(Global.getAreaCode());
        regBusSjhjtable.setBizmsgid(bizmsgid);
		
		StringBuilder sbStr = new StringBuilder();
        //报文头转化
        String retHead = JaxbMapper.toXml(regBusSjhjtable, RegBusSjhjtable.class, "UTF-8");
        sbStr.append(JXmlUtils.messageBStr).append(retHead.substring(56)).append(JXmlUtils.dataBStr);
        //报文体-权利人信息转化
        String retQlr="",retZdjbxx="",retZdbhqk="",strzb103="",retTdsyq="",retSlsq="";
        if(StringUtils.isNotBlank(regBusQlr.getId())){
        	retQlr=RegUtils.QlrzhuanStr(regBusQlr,regBusCSlsq.getQxdm(),regBusTdsyq.getBdcdyh(),regBusTdsyq.getBdcqzh());
         	sbStr.append(retQlr);
        }
        else{
     	   tempReturnValue="权利人信息不能为空!数据上报失败";           
           return tempReturnValue;
        }
        if(StringUtils.isNotBlank(regBaseZdjbxx.getId())){
        	retZdjbxx=RegUtils.CZdjbxxzhuanStr(regBaseZdjbxx,regBusCSlsq);
         	sbStr.append(retZdjbxx);
        }
        else{
     	   tempReturnValue="宗地基本信息不能为空!数据上报失败";           
           return tempReturnValue;
        }
       /* if(StringUtils.isNotBlank(regBaseZdbhqk.getId())){
        	 retZdbhqk = JaxbMapper.toXml( regBaseZdbhqk, RegBaseZdbhqk.class, "UTF-8");
        	 sbStr.append(retZdbhqk.substring(56));
        }*/
        if((StringUtils.isNotBlank(regBaseZdbhqk.getId()))&&(StringUtils.isNotBlank(regBusTdsyq.getId()))){
         	retZdbhqk=RegUtils.ZdbhqkzhuanStr(regBaseZdbhqk,regBusTdsyq.getQxdm());
         	sbStr.append(retZdbhqk);
         }
  
        if(StringUtils.isNotBlank(regBaseZdjbxx.getId())){
        	ZdK103 zdk103 = new ZdK103();
        	zdk103.setBdcdyh(regBaseZdjbxx.getBdcdyh());
        	strzb103=kService.ZBzhuanStr(zdk103);
        	if(strzb103.equals("1")) {
        		RegBaseChxx11 regBaseChxx = new RegBaseChxx11();
                regBaseChxx = regBaseChxxService.get(regBaseZdjbxx.getChid());
        		strzb103=RegUtils.ZBzhuanStr(regBaseChxx,regBaseZdjbxx);
        	}
        	sbStr.append(strzb103);
        	
        }
        else{
     	   tempReturnValue="坐标信息信息不能为空!数据上报失败";           
           return tempReturnValue;
        }
      		
        if(StringUtils.isNotBlank(regBusTdsyq.getId())){
        	 retTdsyq = JaxbMapper.toXml( regBusTdsyq, RegBusTdsyq.class, "UTF-8");             
        	sbStr.append(retTdsyq.substring(56));
        }
        else{
     	   tempReturnValue="土地所有权不能为空!数据上报失败";           
           return tempReturnValue;
        }
        if(StringUtils.isNotBlank(regBusCSlsq.getId())){
        	 retSlsq=RegUtils.CSlsqzhuanStr(regBusCSlsq);
        	sbStr.append(retSlsq);
        }
        else{
     	   tempReturnValue="受理申请不能为空!数据上报失败";           
           return tempReturnValue;
        }
		String retSj="",retSf="",retSh="",retSz="",retFz="",retGd="",retSqr="";
		if(StringUtils.isNotBlank(regBusSjmain.getId())){
			retSj=RegUtils.SjzhuanStr(regBusSjmain,regBusCSlsq.getQxdm());
			sbStr.append(retSj);
		}
		if(StringUtils.isNotBlank(regBusSf.getId())){
			retSf=RegUtils.SfzhuanStr(regBusSf);
			sbStr.append(retSf);
		}
		
		/*if(StringUtils.isNotBlank(regBusSh.getId())){
			 retSh= JaxbMapper.toXml( regBusSh, RegBusSh.class, "UTF-8");       		
			sbStr.append(retSh.substring(56));
		}*/
		if(StringUtils.isNotBlank(regBusCSlsq.getId())){
			 retSh=RegUtils.CShzhuanStr(list, regBusCSlsq);
       	     sbStr.append(retSh);
       }
		if(StringUtils.isNotBlank(regBusSz.getId())){
		   /* retSz= JaxbMapper.toXml( regBusSz, RegBusSz.class, "UTF-8");       
			sbStr.append(retSz.substring(56));*/
			retSz=RegUtils.SzzhuanStr(regBusSz,regBusCSlsq.getQxdm());
			sbStr.append(retSz);
		}
		if(StringUtils.isNotBlank(regBusFz.getId())){
			retFz=RegUtils.FzzhuanStr(regBusFz,regBusCSlsq.getQxdm());
			sbStr.append(retFz);
		}
		if(StringUtils.isNotBlank(regBusGd.getId())){
			retGd=RegUtils.GdzhuanStr(regBusGd,regBusCSlsq.getQxdm());
			 sbStr.append(retGd);
		}
		/*if(StringUtils.isNotBlank(regBusSqr.getId())){
			 retSqr= JaxbMapper.toXml( regBusSqr, RegBusSqr.class, "UTF-8");
			sbStr.append(retSqr.substring(56));
		}*/
		if((StringUtils.isNotBlank(regBusQlr.getId()))||(StringUtils.isNotBlank(regBusYwr.getId()))){
			retSqr=RegUtils.SqrzhuanStr(regBusQlr,regBusYwr,regBusCSlsq.getQxdm());
			sbStr.append(retSqr);
		}
		else{
      	    tempReturnValue="申请人信息不能为空!数据上报失败";           
            return tempReturnValue;
        }
		//赋值相关信息,准备上报部里
		String provincialstr = sbStr.toString();
		RegBusSjhjtable provincialSjhjtable = regBusSjhjtable;
     	
		sbStr.append(JXmlUtils.dataEStr).append(JXmlUtils.messageEStr);
        
		//---------------------------------
       
        System.out.println(sbStr.toString());
        
        //调用生成XML报文文件的函数,参数为生成文件名和要生成的内容字符串
    	//JXmlUtils.strChangeXML("Biz"+regBusSjhjtable.getBizmsgid(), sbStr.toString());
        String Filepath=Global.getUserfilesBaseDir() + Global.UP_DATA_URL+"Biz"+regBusSjhjtable.getBizmsgid()+".xml";
        
        //String Filepath="src/main/webapp/updatas/"+"Biz"+regBusSjhjtable.getBizmsgid()+".xml";
    	String xml = sbStr.toString();
     	String RSApara=RegUtils.SJHJPara();
     	String abc = RSASignature.getNewMsgWithSignature(xml,RSApara);
     	String Digitalsign = abc.substring(abc.indexOf("<DigitalSign>")+13,abc.indexOf("</DigitalSign>"));
     	
     	//重新生成xml
    	regBusSjhjtable.setDigitalsign(Digitalsign);//set数字签名	
    	//----------
    	FileUtils.writeStringToFile(new File(Filepath), abc, "UTF-8");
        //---------------------------
        String Filename="Biz"+regBusSjhjtable.getBizmsgid()+".xml";
        //SftpFileLoad.sshSftp("172.16.56.7","mysftp","FANXIAPING",0,Filepath,Filename);
      //上报省里
    	//生成xml字符串并调用接口方法,向市局接口系统传送,并在市局接口服务器生成报文文件上报省里
    	try{
	        tempReturnValue = regBusCSlsqController.sjdbxmlinfo(provincialstr, provincialSjhjtable);
	        if(tempReturnValue.contains("成功") || StringUtils.isBlank(tempReturnValue)){
	        	tempReturnValue = "响应成功";
	        	regBusSjhjtable.setIssuccess("0");
	        }else{
	        	regBusSjhjtable.setIssuccess("1");
	        }
    	}catch(Exception e){
    		regBusSjhjtable.setIssuccess("2");
    		e.printStackTrace();
    	}
        regBusSjhjtableService.save(regBusSjhjtable);
        return tempReturnValue;
    }
}