d86e57def055e0565e2bef1f2752fc71197b411b.svn-base 16.1 KB
package com.thinkgem.jeesite.modules.reg.web.updata;

import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSlsq;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSz;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusYwr;
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.updata.RegBusSjhjtable;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseCService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseChxx11Service;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseFdcqxmService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZdjbxxService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZrzService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusFdcq1Service;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusFzService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusGdService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusQlrService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSfService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusShService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSjmainService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSzService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusYwrService;
import com.thinkgem.jeesite.modules.reg.service.qjxt.ZdK103Service;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
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.DateUtils;
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.RegBaseC;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseChxx11;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseFdcqxm;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZdjbxx;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZrz;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusFdcq1;
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.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.service.updata.RegBusSjhjtableService;
import com.thinkgem.jeesite.modules.reg.utils.RegUtils;
import com.thinkgem.jeesite.modules.reg.web.bus.change.RegBusCSlsqController;

import java.io.File;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "${adminPath}/reg/updata/regBusSjhjtable")
public class SCDJ4000401Controller extends BaseController {
	@Autowired
	private RegBaseHService regBaseHService;
	@Autowired
	private RegBusFdcq1Service regBusFdcq1Service;
	@Autowired
	private RegBaseZrzService regBaseZrzService;
	@Autowired
	private RegBusSjhjtableService regBusSjhjtableService;
	@Autowired
	private RegBusYwrService regBusYwrService;
	@Autowired
	private RegBusQlrService regBusQlrService;
	@Autowired
	private RegBaseCService regBaseCService;
	@Autowired
	private RegBaseZdjbxxService regBaseZdjbxxService;
	@Autowired
	private RegBaseFdcqxmService regBaseFdcqxmService;
	@Autowired
	private RegBusSjmainService regBusSjmainService;
	@Autowired
	private RegBusShService regBusShService;
	@Autowired
	private RegBusSzService regBusSzService;
	@Autowired
	private RegBusFzService regBusFzService;
	@Autowired
	private RegBusGdService regBusGdService;
	@Autowired
	private RegBusSfService regBusSfService;
	@Autowired
	private RegBusCSlsqController regBusCSlsqController;
	@Autowired
	private ZdK103Service kService;
	@Autowired
	private RegBaseChxx11Service regBaseChxxService;
	
	public String scdj4000401Controller(RegBusCSlsq regBusCSlsq,RegBusBdcqzsdjxx regBusBdcqzsdjxx,List<Act> list) throws Exception{ 
		String tempReturnValue="",djjgStr="",retFdcq1="",retFdcqxm="";
		String retQlr="",retZrz="",retC="",retH="",retLjz="";
		Date date=new Date();
		//报文头部数据填充
    	RegBusSjhjtable regBusSjhjtable = new RegBusSjhjtable();  
    	regBusSjhjtable.setBizmsgid(Global.getAreaCode());
        regBusSjhjtable.setAsid("AS100");
        regBusSjhjtable.setAreacode(Global.getAreaCode());
        regBusSjhjtable.setRectype("4000401");
        regBusSjhjtable.setCreatedate(new Date());
        regBusSjhjtable.setCertcount("0");//set不动产权证号码数量
        regBusSjhjtable.setProofcount("0");//set证明号码数量
        regBusSjhjtable.setRecflowid(regBusCSlsq.getYwh());//set业务号   
        regBusSjhjtable.setRighttype(regBusBdcqzsdjxx.getQllx());//权利类型
		if(StringUtils.isNotBlank(regBusCSlsq.getDjdl())){
	         regBusSjhjtable.setRegtype(regBusCSlsq.getDjdl());
	    }else{
	    	 regBusSjhjtable.setRegtype(" ");
	    }
		
		regBusSjhjtable.setParcelid(regBusBdcqzsdjxx.getZddm());//set宗地/宗海代码
		
		if(StringUtils.isNotBlank(regBusBdcqzsdjxx.getBdcqzh())){
		    regBusSjhjtable.setPrecertid(regBusBdcqzsdjxx.getBdcqzh());//set上次不动产权证号
		}else{
			regBusSjhjtable.setPrecertid(" ");
		}
		regBusSjhjtable.setEstatenum(regBusBdcqzsdjxx.getBdcdyh());//set不动产单元号
        //-----------------------------
		//报文体-权利人信息转化 	//获取权利人信息xml
		RegBusQlr regBusQlrSJHJ=new RegBusQlr();
		regBusQlrSJHJ.setYwh(regBusCSlsq.getYwh());
		List<RegBusQlr> findQlrSJHJList = regBusQlrService.findListSxh(regBusQlrSJHJ);
		if(findQlrSJHJList.size() > 0){
			regBusQlrSJHJ = findQlrSJHJList.get(0);											 
		}
	    if(StringUtils.isNotBlank(regBusQlrSJHJ.getId())){
	    	retQlr=RegUtils.QlrzhuanStr(regBusQlrSJHJ,regBusCSlsq.getQxdm(),regBusBdcqzsdjxx.getBdcdyh(),regBusBdcqzsdjxx.getBdcqzh());
	    }else{
	        tempReturnValue="权利人不能为空!数据上报失败";           
	        return tempReturnValue;
	    }
	    //----------------------------------
		if(regBusBdcqzsdjxx != null) {
			RegBusBdcqzsdjxx tempEntity = regBusBdcqzsdjxx;
			tempEntity.setDbsj(DateUtils.getDate("yyyy-MM-dd"));
			RegBaseFdcqxm fdcqxm = new RegBaseFdcqxm();
			fdcqxm.setBdcdyh(tempEntity.getBdcdyh());
			List<RegBaseFdcqxm> fdcqxmList = regBaseFdcqxmService.findList(fdcqxm);
			for(int n=0;n<fdcqxmList.size();n++){
				fdcqxm = fdcqxmList.get(n);
				retFdcqxm+=RegUtils.FdcqxmzhuanStr(fdcqxm);
			}
			
			RegBusFdcq1 regBusFdcq1 = new RegBusFdcq1();
			regBusFdcq1.setYwh(tempEntity.getYwh());
			regBusFdcq1.setBdcdyh(tempEntity.getBdcdyh());
			List<RegBusFdcq1> findList = regBusFdcq1Service.findList(regBusFdcq1);
			RegBaseZrz zrz;
			RegBaseC c;
			RegBaseH h = new RegBaseH();
			if(findList.size() > 0){
				regBusFdcq1 = findList.get(0);
				zrz =new RegBaseZrz();
				zrz.setBdcdyh(regBusFdcq1.getBdcdyh().substring(0,20));
				List<RegBaseZrz> zrzList = regBaseZrzService.findList(zrz);
				for(int i=0;i<zrzList.size();i++){
					zrz = zrzList.get(i);
					
					retZrz+=RegUtils.ZrzzhuanStr(zrz,regBusCSlsq.getQxdm());
					retLjz+=RegUtils.LjzzhuanStr(h,zrz,regBusCSlsq.getQxdm());
					c = new RegBaseC();
					c.setZid(zrzList.get(i).getId());
					List<RegBaseC> cList = regBaseCService.findList(c);
					for(int j=0;j<cList.size();j++){
						c = cList.get(j);
						
						retC+=RegUtils.CzhuanStr( c,regBusCSlsq.getQxdm());
						h = new RegBaseH();
						h.setCid(cList.get(j).getId());
						List<RegBaseH> hList = regBaseHService.findList(h);
						for(int k=0;k<hList.size();k++){
							h = hList.get(k);
							retH+=RegUtils.HzhuanStr( h,regBusCSlsq.getQxdm());
						}
						
					}
				}
			}
			  
			if(StringUtils.isNotBlank(regBusFdcq1.getId())){
				djjgStr=regBusFdcq1.getDjjg();
	        	retFdcq1=retFdcq1+RegUtils.Fdcq1zhuanStr(regBusFdcq1);
		    }else{
	        	tempReturnValue="房地产权不能为空!数据上报失败";           
	            return tempReturnValue;
		    }
		}else{
			 tempReturnValue="登记信息为空!数据上报失败!";           
	         return tempReturnValue;
		}
		//------------------------------------------
	    regBusSjhjtable.setPreestatenum(regBusBdcqzsdjxx.getBdcdyh());//set上次不动产单元号
	    if(StringUtils.isNotBlank(djjgStr)){
      	  regBusSjhjtable.setRegorgid(djjgStr);
        }else{
    	   String xzq=DictUtils.getDictLabels(Global.getAreaCode(), "reg_bus_xq", "");
           xzq="陕西省汉中市"+xzq+"不动产登记交易服务中心"; 
    	   regBusSjhjtable.setRegorgid(xzq);
        }

	    String strzb103="",retSlsq="";
		RegBaseZdjbxx regBaseZdjbxx=new RegBaseZdjbxx();
		regBaseZdjbxx.setZddm((regBusBdcqzsdjxx.getZddm()));
		List<RegBaseZdjbxx> findZdjbxxSJHJList = regBaseZdjbxxService.findList(regBaseZdjbxx);
		if(findZdjbxxSJHJList.size() > 0){
			regBaseZdjbxx = findZdjbxxSJHJList.get(0);							
		}
		
		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;
        		}
        	}
        }else{
        	tempReturnValue="坐标信息不能为空!数据上报失败";           
            return tempReturnValue;
        }
        
        if(StringUtils.isNotBlank(regBusCSlsq.getId())){
        	retSlsq=RegUtils.CSlsqzhuanStr(regBusCSlsq);
        }else{
       	   tempReturnValue="受理申请不能为空!数据上报失败";           
           return tempReturnValue;
        }
        
        RegBusSjmain regBusSjmain=new RegBusSjmain();
        regBusSjmain.setYwh(regBusCSlsq.getYwh());
		List<RegBusSjmain> findSjmainSJHJList = regBusSjmainService.findList(regBusSjmain);
		String id = "",retSj="",retSf="",retSh="",retSz="",retFz="",retGd="",retSqr="";
		if(findSjmainSJHJList.size()>0){
		   id = findSjmainSJHJList.get(0).getId();
		   regBusSjmain = regBusSjmainService.get(id);
	    }
		if(StringUtils.isNotBlank(regBusSjmain.getId())){
			retSj=RegUtils.SjzhuanStr(regBusSjmain,regBusCSlsq.getQxdm());
		}
		RegBusSf regBusSf=new RegBusSf();
		regBusSf.setYwh(regBusCSlsq.getYwh());
		List<RegBusSf> findSfSJHJList = regBusSfService.findList(regBusSf);
		if(findSfSJHJList.size() > 0)regBusSf = findSfSJHJList.get(0);
		if(StringUtils.isNotBlank(regBusSf.getId())){
			retSf=RegUtils.SfzhuanStr(regBusSf);
		}
		
		RegBusSh regBusSh=new RegBusSh();
		regBusSh.setYwh(regBusCSlsq.getYwh()); 
		List<RegBusSh> findShSJHJList = regBusShService.findList(regBusSh);
		if(findShSJHJList.size() > 0)regBusSh = findShSJHJList.get(0);
		if(StringUtils.isNotBlank(regBusCSlsq.getId())){
			 retSh=RegUtils.CShzhuanStr(list, regBusCSlsq);
        }
		RegBusSz regBusSz=new RegBusSz();
		regBusSz.setYwh(regBusCSlsq.getYwh());
		List<RegBusSz> findSzSJHJList = regBusSzService.findList(regBusSz);
		if(findSzSJHJList.size() > 0)regBusSz = findSzSJHJList.get(0);
		if(StringUtils.isNotBlank(regBusSz.getId())){
			retSz=RegUtils.SzzhuanStr(regBusSz,regBusCSlsq.getQxdm());
		}
		RegBusFz regBusFz=new RegBusFz();
		regBusFz.setYwh(regBusCSlsq.getYwh());
		List<RegBusFz> findFzSJHJList = regBusFzService.findList(regBusFz);
		if(findFzSJHJList.size() > 0)regBusFz = findFzSJHJList.get(0);
		if(StringUtils.isNotBlank(regBusFz.getId())){
			retFz=RegUtils.FzzhuanStr(regBusFz,regBusCSlsq.getQxdm());
		}
		RegBusGd regBusGd=new RegBusGd();
		regBusGd.setYwh(regBusCSlsq.getYwh());
	    List<RegBusGd> findGdSJHJList = regBusGdService.findList(regBusGd);
	    if(findGdSJHJList.size() > 0)regBusGd = findGdSJHJList.get(0);
	    if(StringUtils.isNotBlank(regBusGd.getId())){
			retGd=RegUtils.GdzhuanStr(regBusGd,regBusCSlsq.getQxdm());
		}
	    RegBusYwr regBusYwrSJHJ=new RegBusYwr();
		regBusYwrSJHJ.setYwh(regBusCSlsq.getYwh());
		List<RegBusYwr> findYwrSJHJList = regBusYwrService.findListSxh(regBusYwrSJHJ);
		if(findYwrSJHJList.size() > 0 ){
			regBusYwrSJHJ = findYwrSJHJList.get(0);
		}
        
	    if((StringUtils.isNotBlank(regBusQlrSJHJ.getId()))||(StringUtils.isNotBlank(regBusYwrSJHJ.getId()))){
			retSqr=RegUtils.SqrzhuanStr(regBusQlrSJHJ,regBusYwrSJHJ,regBusCSlsq.getQxdm());
		}else{
	       	 tempReturnValue="申请人不能为空!数据上报失败";           
	         return tempReturnValue;
	     }
	    
		/*原报文顺序号生成
		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);
		sbStr.append(retQlr);sbStr.append(retZrz);sbStr.append(retLjz);sbStr.append(retC);
		sbStr.append(retH);sbStr.append(strzb103);sbStr.append(retFdcq1);sbStr.append(retFdcqxm);
		sbStr.append(retSlsq);sbStr.append(retSj);sbStr.append(retSf);
		sbStr.append(retSh);sbStr.append(retSz);sbStr.append(retFz);
		sbStr.append(retGd);sbStr.append(retSqr);
		//赋值相关信息,准备上报省里
		String provincialstr = sbStr.toString();
		RegBusSjhjtable provincialSjhjtable = regBusSjhjtable;
	 	
		sbStr.append(JXmlUtils.dataEStr).append(JXmlUtils.messageEStr);
		//数字签名
	    String Filepath=Global.getUserfilesBaseDir() + Global.UP_DATA_URL+"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");
	    //---------------------------
		regBusSjhjtable.setEstatenum("");//set不动产单元号
	    regBusSjhjtable.setPreestatenum("");//set上次不动产单元号
	    String Filename="Biz"+regBusSjhjtable.getBizmsgid()+".xml";
	    
	    //上报省里
		//生成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;
	}
}