bd903cf09ef584329e6730d0274075558ee7ec78.svn-base 7.77 KB
package com.thinkgem.jeesite.modules.reg.web.bus;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.FileUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSbtj;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSbtjService;
import com.thinkgem.jeesite.modules.reg.service.updata.RegBusSjhjtableService;
import com.thinkgem.jeesite.modules.reg.web.bus.registlog.JrrzService;
import com.thinkgem.jeesite.modules.reg.web.bus.registlog.JrrzServiceService;
import com.thinkgem.jeesite.modules.reg.web.httprest.httpRestService.HttpactivityService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import java.io.File;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;

@Lazy(false)
public class CommitLog
{

  @Autowired
  private RegBusSbtjService regBusSbtjService;

  @Autowired
  private RegBusSjhjtableService regBusSjhjtableService;

  @Autowired
  private RegBusBdcqzsdjxxService regBusBdcqzsdjxxService;

  @Autowired
  private HttpactivityService httpactivityService;
  protected Logger logger = LoggerFactory.getLogger(super.getClass());

  public synchronized void autoCommitLog()
  {
	String bz_dataup = System.getProperty("timeservice.dataup");
	logger.info("数据汇总标志:"+bz_dataup);
	if(StringUtils.isBlank(bz_dataup) || !bz_dataup.equals("1")) {
		logger.info("不是数据汇总服务器,登簿量上报直接返回");
		return;
	}   
	
 
    String[] qxdminfo = { "610702", "610721", "610722", "610723", "610724", "610725", "610726", "610727", "610728", "610729", "610730" };
    for (int i = 0; i < qxdminfo.length; ++i)
    {
      String areacode = qxdminfo[i];
      Map map = new HashMap();
      map.put("areacode", areacode);
      StringBuilder registrationLogXml = new StringBuilder();
      registrationLogXml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
      registrationLogXml.append("<AccessLogs>\n");
      registrationLogXml.append("<AccessLog>\n");
      Date date = new Date();
      RegBusSbtj regBusSbtj = new RegBusSbtj();
      String dbsj = DateUtils.getDate("yyyy-MM-dd");
      regBusSbtj.setAreacode(areacode);
      registrationLogXml.append("<AreaCode>" + areacode + "</AreaCode>\n");

      String areaName = DictUtils.getDictLabels(areacode, "reg_bus_xq", "");
      registrationLogXml.append("<AreaName>" + areaName + "</AreaName>\n");
      SimpleDateFormat myFmt = new SimpleDateFormat("yyyyMMdd");

      String accessDate = myFmt.format(date);
      registrationLogXml.append("<AccessDate>" + accessDate + "</AccessDate>\n");
      String remark = "";
      registrationLogXml.append("<Remark>" + remark + "</Remark>\n");

      String accessTotalNum = this.regBusSjhjtableService.findAllnum(map);
      String firstReg2 = this.regBusSjhjtableService.findScnum(map);
      String transferReg2 = this.regBusSjhjtableService.findZynum(map);
      String changeReg2 = this.regBusSjhjtableService.findBgnum(map);
      String logoutReg2 = this.regBusSjhjtableService.findZxnum(map);
      String riviseReg2 = this.regBusSjhjtableService.findGznum(map);
      String dissentingReg2 = this.regBusSjhjtableService.findYynum(map);
      String advanceReg2 = this.regBusSjhjtableService.findYgnum(map);
      String seizeReg2 = this.regBusSjhjtableService.findCfnum(map);
      String easementReg2 = this.regBusSjhjtableService.findDyiqnum(map);
      String mortgageReg2 = this.regBusSjhjtableService.findDyaqnum(map);

      String registerTotalNum = accessTotalNum;
      String firstReg1 = firstReg2;
      String transferReg1 = transferReg2;
      String changeReg1 = changeReg2;
      String logoutReg1 = logoutReg2;
      String riviseReg1 = riviseReg2;
      String dissentingReg1 = dissentingReg2;
      String advanceReg1 = advanceReg2;
      String seizeReg1 = seizeReg2;
      String easementReg1 = easementReg2;
      String mortgageReg1 = mortgageReg2;
      String businessTypeCount = this.regBusSjhjtableService.findTypeCount(map);

      regBusSbtj.setJrnum(accessTotalNum);
      regBusSbtj.setJrsc(firstReg2);
      regBusSbtj.setJrzy(transferReg2);
      regBusSbtj.setJrbg(changeReg2);
      regBusSbtj.setJrzx(logoutReg2);
      regBusSbtj.setJrgz(riviseReg2);
      regBusSbtj.setJryy(dissentingReg2);
      regBusSbtj.setJryg(advanceReg2);
      regBusSbtj.setJrcf(seizeReg2);
      regBusSbtj.setJrdyi(easementReg2);
      regBusSbtj.setJrdya(mortgageReg2);

      regBusSbtj.setDbnum(registerTotalNum);
      regBusSbtj.setDbsc(firstReg1);
      regBusSbtj.setDbzy(transferReg1);
      regBusSbtj.setDbbg(changeReg1);
      regBusSbtj.setDbzx(logoutReg1);
      regBusSbtj.setDbgz(riviseReg1);
      regBusSbtj.setDbyy(dissentingReg1);
      regBusSbtj.setDbyg(advanceReg1);
      regBusSbtj.setDbcf(seizeReg1);
      regBusSbtj.setDbdyi(easementReg1);
      regBusSbtj.setDbdya(mortgageReg1);
      regBusSbtj.setTjdate(dbsj);
      this.regBusSbtjService.save(regBusSbtj);

      registrationLogXml.append("<RegisterInfo totalNum=\"" + registerTotalNum + "\" firstReg=\"" + firstReg1 + "\" transferReg=\"" + 
        transferReg1 + "\" changeReg=\"" + changeReg1 + "\" logoutReg=\"" + logoutReg1 + "\" riviseReg=\"" + riviseReg1 + "\" dissentingReg=\"" + 
        dissentingReg1 + "\" advanceReg=\"" + advanceReg1 + "\" seizeReg=\"" + seizeReg1 + "\" easementReg=\"" + easementReg1 + "\" mortgageReg=\"" + 
        mortgageReg1 + "\" businessTypeCount=\"" + businessTypeCount + "\"" + "> </RegisterInfo>\n");
      registrationLogXml.append("<AccessInfo totalNum=\"" + accessTotalNum + "\" firstReg=\"" + firstReg2 + "\" transferReg=\"" + 
        transferReg2 + "\" changeReg=\"" + changeReg2 + "\" logoutReg=\"" + logoutReg2 + "\" riviseReg=\"" + riviseReg2 + "\" dissentingReg=\"" + 
        dissentingReg2 + "\" advanceReg=\"" + advanceReg2 + "\" seizeReg=\"" + seizeReg2 + "\" easementReg=\"" + easementReg2 + "\" mortgageReg=\"" + 
        mortgageReg2 + "\"" + "> </AccessInfo>\n");
      registrationLogXml.append("</AccessLog>\n");
      registrationLogXml.append("</AccessLogs>");
      String rzinfoXml = registrationLogXml.toString();

      String msg = "";
      try {
        System.out.println(rzinfoXml + "********");

        Date datenew = new Date();
        SimpleDateFormat myFmtnew = new SimpleDateFormat("yyyyMMdd");
        String accessDatenew = myFmtnew.format(datenew);
        System.out.println("开始发送********");
        JrrzServiceService jrrzsservice = new JrrzServiceService();
        JrrzService jrrzsb = jrrzsservice.getJrrzServicePort();
        msg = jrrzsb.exchangeInfo(rzinfoXml.toString());
        System.out.println("结束发送********");
        String filePath = Global.getUserfilesBaseDir() + "/booklogs/" + accessDatenew + System.currentTimeMillis() + ".txt";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        FileUtils.writeStringToFile(new File(filePath), rzinfoXml.toString() + "\n" + msg + "\n" + "当前上报日志日期为:" + df.format(new Date()) + ",返回结果为:" + msg, "UTF-8");
      } catch (Exception e) {
        System.out.println("日志上报失败 :" + e.getMessage());
        this.logger.error(errorTrackSpace(e));
      }
    }
     
  }

  public static String errorTrackSpace(Exception e)
  {
    StringBuffer sb = new StringBuffer();
    if (e != null) {
      for (StackTraceElement element : e.getStackTrace()) {
        sb.append("\r\n\t").append(element);
      }
    }
    return ((sb.length() == 0) ? null : sb.toString());
  }
}