8a3a86fe43e73062926a588cfe31b939cf478aa8.svn-base 13.3 KB
package com.thinkgem.jeesite.modules.reg.web.updata;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
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.act.entity.Act;
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.base.RegBaseZdjbxx;
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.RegBusJsydsyq;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusQlr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSf;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSh;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSjmain;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSlsq;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSqr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusYwr;
import com.thinkgem.jeesite.modules.reg.entity.qjxt.ZdK103;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSz;
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.qjxt.ZdK103Service;
import com.thinkgem.jeesite.modules.reg.service.updata.RegBusSjhjtableService;
import com.thinkgem.jeesite.modules.reg.utils.RegUtils;
import com.thinkgem.jeesite.modules.reg.web.bus.change.RegBusCSlsqController;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
/**
 * 数据汇交Controller 
 * @author xuyg
 * @version 2015-10-12
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/updata/regBusSjhjtable")
public class SCDJ1000301Controller extends BaseController {
	
	@Autowired
	private RegBusSjhjtableService regBusSjhjtableService;
	@Autowired
	private RegBusCSlsqController regBusCSlsqController;
	@Autowired
	private ZdK103Service kService;
	@Autowired
	private RegBaseChxx11Service regBaseChxxService;
	
    public String updataSCDJ1000301xml(RegBusJsydsyq regBusJsydsyq,RegBusQlr regBusQlr,RegBaseZdjbxx regBaseZdjbxx,RegBusSlsq regBusSlsq,RegBaseZdbhqk regBaseZdbhqk,RegBusSjmain regBusSjmain,RegBusSf regBusSf,RegBusSh regBusSh,RegBusSz regBusSz,RegBusFz regBusFz,RegBusGd regBusGd,RegBusSqr regBusSqr,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("1000301");
        regBusSjhjtable.setRighttype(regBusJsydsyq.getQllx());
        //regBusSjhjtable.setRegtype(regBusJsydsyq.getDjlx());  
        if(StringUtils.isNotBlank(regBusSlsq.getDjdl())){
       	 regBusSjhjtable.setRegtype(regBusSlsq.getDjdl());//set上次不动产权证号
        }
        else  regBusSjhjtable.setRegtype(" ");
        
        regBusSjhjtable.setCreatedate(new Date());
   
		regBusSjhjtable.setRecflowid(regBusJsydsyq.getYwh());//set业务号
       // regBusSjhjtable.setRegorgid(regBusJsydsyq.getDjjg());//set登记机构
        if(StringUtils.isNotBlank(regBusJsydsyq.getDjjg())){
       	 regBusSjhjtable.setRegorgid(regBusJsydsyq.getDjjg());//set上次不动产权证号
        }
        else{
        	String xzq=DictUtils.getDictLabels(Global.getAreaCode(), "reg_bus_xq", "");
        	xzq="陕西省汉中市"+xzq+"不动产登记交易服务中心";
        	regBusSjhjtable.setRegorgid(xzq);
        }
        regBusSjhjtable.setParcelid(regBusJsydsyq.getZddm());//set宗地/宗海代码
        regBusSjhjtable.setEstatenum(regBusJsydsyq.getBdcdyh());//set不动产单元号
        regBusSjhjtable.setPreestatenum(regBusJsydsyq.getBdcdyh());//set上次不动产单元号
        
        if(StringUtils.isNotBlank(regBusJsydsyq.getBdcqzh())){
        	 regBusSjhjtable.setPrecertid(regBusJsydsyq.getBdcqzh());//set上次不动产权证号
        }
        else  regBusSjhjtable.setPrecertid(" ");
        regBusSjhjtable.setCertcount("0");//set不动产权证号码数量
        regBusSjhjtable.setProofcount("0");//set证明号码数量
     //   regBusSjhjtable.setDigitalsign("数字签名");//set数字签名
      //-------------------------
    	//测试用XML字符串
		///String xml = FileUtils.readFileToString(new File("E:/Inspur/schema/4000101/Biz510500201510210000071.xml"), "UTF-8");
		//获取加签后报文
		//String abc = RSASignature.getNewMsgWithSignature(xml, "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANP1Ow58aqG/7dPF5T+M3CyQ6Vc8XfkZ9+bigaNTILZqOmUSJFn7nvHnBhe2qHUHe6WdJBjU8s78/DyLSODW7BCg7SLMaTfUKsiWgWkoBy97kl8bHRcErVx9+wakW+PMv+C9Fkce+oY4fUE7JJPwRw6sOe5PdjcW1hsZ14OUfoAZAgMBAAECgYEAt0IFEI5Dx5vg7cPhZOPODX4xMWqROWnZa7eVLHgYBX+tA2v/IAmssCv1mZUk6yJQJq3J4upjENGs6E/o7/UC3f3juJCIAj0xyJ49x8FoKfHob+VZkkZEBIt7mPyvo1Pl9vW6dE50SQGrEkIIVOZdlKeWKzMKhsyFZqKGNM5cAgECQQD6EeHoHnakfQicM7LHwho2QEtJO+CjKl3EhmDbE3qKGn/W/xVpaDB/EqTfSR45r48009s1bmFjxIslIjNT10lBAkEA2Pv6uPZenhC/cvQNzUZIhHdUJti086N8AAedMkW9sr1Bp3O3hspKvvNYtzwEfGvQWa42qVPLrIjmAmlxNn9o2QJAWFJ2kpAn4ULUBq9vxoP01BJzRMNkPNzaz22Sye2gSyS+4EWp31fQQSFpn/9oMIGkN8lX1BBPT3h8mLnynPsdwQJBALkanNTVN/pYBzqlgHCxmIOI2L0a+aMuwEW2OR/95spoMW4MhW/zerhTGEeYZ6tMvj0DJZZl6caSMsWz9eSr5GECQDq4SKdjEu21caizzRHqyTIlo3675w+iPPrWxx9sKbqfN3OhEPgA7DKdH7s19Smw3kszdu0hVVAR0RpznGAp0Y4=");
	
        /*原报文顺序号生成
        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="",retJsydsyq="",retSlsq="";
        if(StringUtils.isNotBlank(regBusQlr.getId())){
        	retQlr=RegUtils.QlrzhuanStr(regBusQlr,regBusSlsq.getQxdm(),regBusJsydsyq.getBdcdyh(),regBusJsydsyq.getBdcqzh());
         	sbStr.append(retQlr);
        }
        else{
        	tempReturnValue="权利人不能为空!数据上报失败";           
            return tempReturnValue;
         }
        if(StringUtils.isNotBlank(regBaseZdjbxx.getId())){
        	/* retZdjbxx = JaxbMapper.toXml( regBaseZdjbxx, RegBaseZdjbxx.class, "UTF-8");
        	sbStr.append(retZdjbxx.substring(56));*/
        	retZdjbxx=RegUtils.ZdjbxxzhuanStr(regBaseZdjbxx,regBusSlsq);
         	sbStr.append(retZdjbxx);
        }
        else{
        	tempReturnValue="宗地基本信息不能为空!数据上报失败";           
            return tempReturnValue;
         }
      /* if((StringUtils.isNotBlank(regBaseZdbhqk.getId()))&&(StringUtils.isNotBlank(regBusJsydsyq.getId()))){
         	retZdbhqk=RegUtils.ZdbhqkzhuanStr(regBaseZdbhqk,regBusJsydsyq.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")) {
        		if(StringUtils.isNotBlank(regBaseZdjbxx.getChid())) {
            		RegBaseChxx11 regBaseChxx = new RegBaseChxx11();
            		
                    regBaseChxx = regBaseChxxService.get(regBaseZdjbxx.getChid());
            		strzb103=RegUtils.ZBzhuanStr(regBaseChxx,regBaseZdjbxx);
            		}else {
            			tempReturnValue="坐标信息不能为空!数据上报失败";           
                        return tempReturnValue;
            		}
        	}
        	sbStr.append(strzb103);
        	
        }
        else{
        	tempReturnValue="坐标信息不能为空!数据上报失败";           
            return tempReturnValue;
        }
        
        if(StringUtils.isNotBlank(regBusJsydsyq.getId())){
        	retJsydsyq=RegUtils.JsydsyqzhuanStr(regBusJsydsyq);
        	sbStr.append(retJsydsyq);
        }
        else{
            tempReturnValue="建设用地使用权信息不能为空!数据上报失败";           
            return tempReturnValue;
        }
        if(StringUtils.isNotBlank(regBusSlsq.getId())){
        	 retSlsq=RegUtils.SlsqzhuanStr(regBusSlsq);
        	 sbStr.append(retSlsq);
         }
        else{
        	tempReturnValue="受理申请信息不能为空!数据上报失败";           
            return tempReturnValue;
         }
		String retSj="",retSf="",retSh="",retSz="",retFz="",retGd="",retSqr="";
		if(StringUtils.isNotBlank(regBusSjmain.getId())){
			retSj=RegUtils.SjzhuanStr(regBusSjmain,regBusSlsq.getQxdm());
			sbStr.append(retSj);
		}
		if(StringUtils.isNotBlank(regBusSf.getId())){
			retSf=RegUtils.SfzhuanStr(regBusSf);
			sbStr.append(retSf);
		}
		
	   if(StringUtils.isNotBlank(regBusSlsq.getId())){
			 retSh=RegUtils.ShzhuanStr(list, regBusSlsq);
        	 sbStr.append(retSh);
        }
		if(StringUtils.isNotBlank(regBusSz.getId())){
			retSz=RegUtils.SzzhuanStr(regBusSz,regBusSlsq.getQxdm());
			sbStr.append(retSz);
		}
		if(StringUtils.isNotBlank(regBusFz.getId())){
			retFz=RegUtils.FzzhuanStr(regBusFz,regBusSlsq.getQxdm());
			sbStr.append(retFz);
		}
		if(StringUtils.isNotBlank(regBusGd.getId())){
			retGd=RegUtils.GdzhuanStr(regBusGd,regBusSlsq.getQxdm());
			 sbStr.append(retGd);
		}
    	if((StringUtils.isNotBlank(regBusQlr.getId()))||(StringUtils.isNotBlank(regBusYwr.getId()))){
			retSqr=RegUtils.SqrzhuanStr(regBusQlr,regBusYwr,regBusSlsq.getQxdm());
			sbStr.append(retSqr);
		}
    	 else{
            tempReturnValue="申请人不能为空!数据上报失败";           
             return tempReturnValue;
          }
		//赋值相关信息,准备上报省里
		String provincialstr = sbStr.toString();
		RegBusSjhjtable provincialSjhjtable = regBusSjhjtable;
     	
		sbStr.append(JXmlUtils.dataEStr).append(JXmlUtils.messageEStr);
        
		//xml
		//-------------------------------------------
        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 xml = FileUtils.readFileToString(new File(Filepath), "UTF-8");
    	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);
        //tempReturnValue=SftpFileLoad.sshSftp("172.16.56.10","root","123456a",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){
    		e.printStackTrace();
    		regBusSjhjtable.setIssuccess("2");
    	}
        regBusSjhjtableService.save(regBusSjhjtable);
        return tempReturnValue;
    }
}