Demo entry 6641052

卢广航

   

Submitted by 11 on Sep 15, 2017 at 07:01
Language: Java. Code size: 5.2 kB.

public class ImportData
{
  public void importData()
  {
    IEquipInfoService service = (IEquipInfoService)SpringContextUtils.getBean("equipInfoServiceImpl");
    EquipInfo info = new EquipInfo();
    try
    {
      String endpoint = "http://erpkf01.cc.sgcc.com.cn:8000/sap/bc/srt/rfc/sap/zpm_equi_to_iems/200/zpm_equi_to_iems/zpm_equi_to_iems";

      Service serv = new Service();
      Call call = (Call)serv.createCall();
      call.setUsername("ccgcpsrfc");
      call.setPassword("init12");
      call.setTargetEndpointAddress(new URL(endpoint));
      call.setOperationName(new QName("urn:sap-com:document:sap:soap:functions:mc-style", "ZpmEquiToIems"));
      call.addParameter(new QName("IXmlString"), XMLType.XSD_STRING, ParameterMode.IN);
      call.setReturnType(XMLType.XSD_STRING);
      try {
        String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Document><sourceSystem>IEMS</sourceSystem><sendTime>" + 
          new Date().toString() + 
          "</sendTime>" + "<workSheetContent>" + "<sdate>" + 
          "2011-01-01" + "</sdate>" + "<edate>" + "2011-11-22" + 
          "</edate>" + "</workSheetContent>" + "</Document>";

        Object res = call.invoke(new Object[] { s });

        String xmlBuf = res.toString();
        int i = xmlBuf.indexOf(62);
        String xml = xmlBuf.substring(i + 1);
        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xml;

        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        Iterator iter = root.elementIterator();
        Element link;
        while (iter.hasNext())
        {
          link = (Element)iter.next();
          if (!(link.getName().equals("CONTENT")))
            continue;
          iter = link.elementIterator();
          break;
        }

        while (iter.hasNext())
        {
          link = (Element)iter.next();

          info.setEqipCode(link.elementText("EQUNR"));
          int k = 0;
          if (service.loadEquipInfoById(info) == null)
          {
            ++k;
            info.setEqipName(link.elementText("SHTXT"));
            info.setEqipClass(link.elementText("EQART"));
            info.setEqipDesc(link.elementText("ESTAT"));
            info.setEqart(link.elementText("EQTYP"));
            info.setOrgId(link.elementText("BEGRU"));
            info.setEqipTotalNum(link.elementText("BRGEW"));
            info.setEqipReMainNum(link.elementText("GEWEI"));
            info.setGroes(link.elementText("GROES"));
            info.setInvnr(link.elementText("INVNR"));
            info.setOpTime(link.elementText("INBDT"));
            info.setOldValue(link.elementText("ANSWT"));
            info.setMoneyUnit(link.elementText("WAERS"));
            info.setOutTime(link.elementText("ANSDT"));
            info.setInComePart(link.elementText("ELIEF"));
            info.setCompany(link.elementText("HERST"));
            info.setCheckUser(link.elementText("HERLD"));
            info.setRuleClass(link.elementText("TYPBZ"));
            info.setInYear(link.elementText("BAUJJ"));
            info.setIncome(link.elementText("BAUMM"));
            info.setMapar(link.elementText("MAPAR"));
            info.setSerge(link.elementText("SERGE"));
            info.setWeiHuCompany(link.elementText("SWERK"));
            info.setOrgDutyUser(link.elementText("MSGRP"));
            info.setBeber(link.elementText("BEBER"));
            info.setArbpl(link.elementText("ARBPL"));
            info.setAbcId(link.elementText("ABCKZ"));
            info.setPosition(link.elementText("EQFNR"));
            info.setBukrs(link.elementText("BUKRS"));
            info.setCreateXt(link.elementText("ANLNR"));
            info.setCalUnit(link.elementText("ZPM_KOSTL"));
            info.setWbs(link.elementText("POSID"));
            info.setIwerk(link.elementText("IWERK"));
            info.setRate(link.elementText("INGRP"));
            info.setZpmzkostlv(link.elementText("ZPM_ZKOSTLV"));
            info.setBrand(link.elementText("EQUI-ANLUE"));
            info.setZiDuanFenLei(link.elementText("ZPM_ZSBLX"));
            info.setZpmzstadt(link.elementText("ZPM_ZSTADT"));
            info.setZpmzord41(link.elementText("ZPM_ZORD41"));
            info.setZpmzord43(link.elementText("ZPM_ZORD43"));
            info.setChannel(link.elementText("ZPM_ZORD44"));
            info.setWareHouseId(link.elementText("ZPM_ZCHANGE_WAY"));
            info.setChePaiHao(link.elementText("ZPM_ZKFZKZ"));
            info.setOpTime(link.elementText("ZPM_ZSWBH"));
            info.setZpmzgrbnd(link.elementText("ZPM_ZGRBND"));
            info.setZpmzupdate(link.elementText("ZPM_ZUPDATE"));
            info.setFunctionPos(link.elementText("TPLNR"));
            info.setHequi(link.elementText("HEQUI"));
            service.add(info);
          }
          if (k != 200) {
            continue;
          }
          service.flush();
          k = 0;
        }

        service.flush();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    catch (Exception localException1)
    {
    }
  }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).