Commit d8bd91f5 authored by Quxl's avatar Quxl

x

parent 0b5f4281
...@@ -9,36 +9,48 @@ import java.util.Map.Entry; ...@@ -9,36 +9,48 @@ import java.util.Map.Entry;
import javax.jws.WebService; import javax.jws.WebService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.egolm.sso.config.XRException;
import com.egolm.sso.services.CommonService; import com.egolm.sso.services.CommonService;
import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.HEADER_SENDING; import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.HEADER_SENDING;
import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.ITEM; import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.ITEM;
import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.RECORD; import com.egolm.sso.services.material_master.Z_MT_SD_001_MATERIAL_MASTER.RECORD;
import com.egolm.sso.util.DateUtil; import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.FileUtil;
import com.egolm.sso.util.StringUtil; import com.egolm.sso.util.StringUtil;
import com.egolm.sso.util.XMLUtil;
import com.google.gson.Gson; import com.google.gson.Gson;
@Component @Component
@WebService(serviceName = "MaterialMasterService", targetNamespace = "http://material_master.sso.egolm.com", endpointInterface = "com.egolm.sso.services.material_master.MaterialMasterService") @WebService(serviceName = "MaterialMasterService", targetNamespace = "http://material_master.sso.egolm.com", endpointInterface = "com.egolm.sso.services.material_master.MaterialMasterService")
public class MaterialMasterServiceImpl implements MaterialMasterService { public class MaterialMasterServiceImpl implements MaterialMasterService {
private static Log logger = LogFactory.getLog(MaterialMasterService.class);
@Autowired @Autowired
JdbcTemplate jdbcTemplate; JdbcTemplate jdbcTemplate;
@Autowired @Autowired
CommonService common; CommonService common;
@Value("${xmlRoot}")
private String xmlRoot;
@Override @Override
@Transactional @Transactional
public void execute(Z_MT_SD_001_MATERIAL_MASTER Z_MT_SD_001_MATERIAL_MASTER) { public void execute(Z_MT_SD_001_MATERIAL_MASTER Z_MT_SD_001_MATERIAL_MASTER) {
System.out.println(new Gson().toJson(Z_MT_SD_001_MATERIAL_MASTER));
Date now = new Date(); Date now = new Date();
String today = DateUtil.formatDate(now, DateUtil.FMT_DATE); boolean isSuccess = true;
System.out.println(new Gson().toJson(Z_MT_SD_001_MATERIAL_MASTER));
String dateString = DateUtil.formatDate(now, DateUtil.FMT_DATE);
try {
RECORD RECORD = Z_MT_SD_001_MATERIAL_MASTER.getRECORD(); RECORD RECORD = Z_MT_SD_001_MATERIAL_MASTER.getRECORD();
HEADER_SENDING h = RECORD.getHEADER_SENDING(); HEADER_SENDING h = RECORD.getHEADER_SENDING();
String DIS_CODE = h.getKUNNR(); String DIS_CODE = h.getKUNNR();
...@@ -97,8 +109,8 @@ public class MaterialMasterServiceImpl implements MaterialMasterService { ...@@ -97,8 +109,8 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
goods.put("DIS_UPDATE_STATUS", "N");// 分销商更新结果(Y成功,N失败) goods.put("DIS_UPDATE_STATUS", "N");// 分销商更新结果(Y成功,N失败)
*/ */
Long BATCHID = common.getNextval(today + "T_VEN_GOODS_BATCH_" + today); Long BATCHID = common.getNextval(dateString + "T_VEN_GOODS_BATCH_" + dateString);
String BATCH = today+"-"+BATCHID; String BATCH = dateString+"-"+BATCHID;
goods.put("TRACE_NO", "sapmaterialmaster" + DateUtil.formatDate(now, DateUtil.FMT_DATETIME)); goods.put("TRACE_NO", "sapmaterialmaster" + DateUtil.formatDate(now, DateUtil.FMT_DATETIME));
goods.put("BATCH", BATCH); goods.put("BATCH", BATCH);
goods.put("SEND_STATUS", "N"); goods.put("SEND_STATUS", "N");
...@@ -109,6 +121,18 @@ public class MaterialMasterServiceImpl implements MaterialMasterService { ...@@ -109,6 +121,18 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
insertGoods(goods); insertGoods(goods);
} }
} }
} catch (Exception e) {
isSuccess = false;
throw new XRException("数据保存失败", e);
} finally {
String xmlName = Z_MT_SD_001_MATERIAL_MASTER.getClass().getSimpleName() + ".xml";
try {
String xml = XMLUtil.toXml(Z_MT_SD_001_MATERIAL_MASTER);
FileUtil.writeText(xmlRoot + "/sap/" + xmlName + "/" + DateUtil.formatDate(new Date(), DateUtil.FMT_DATE) + "/" + (isSuccess?"success":"error") + "/" + xmlName + "-" + common.getNextval(dateString + "T_VEN_GOODS_BATCH_" + dateString) + ".XML" , xml);
} catch (Exception e) {
throw new XRException("报文保存失败", e);
}
}
} }
private void updateGoods(Map<String, Object> goods) { private void updateGoods(Map<String, Object> goods) {
......
...@@ -2,9 +2,11 @@ package com.egolm.sso.util; ...@@ -2,9 +2,11 @@ package com.egolm.sso.util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import com.egolm.sso.config.XRException; import com.egolm.sso.config.XRException;
...@@ -36,4 +38,13 @@ public class XMLUtil { ...@@ -36,4 +38,13 @@ public class XMLUtil {
} }
} }
public static String toXml(Object obj) throws JAXBException {
StringWriter sw = new StringWriter();
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(obj, sw);
return sw.toString();
}
} }
wsUsername: test wsUsername: test
wsPassword: 78258c537d6e4d5fb210a57d05619fb6 wsPassword: 78258c537d6e4d5fb210a57d05619fb6
xmlRoot: xmlHistory
SAP: SAP:
NO009: NO009:
CRON: 0 0 0 * * ? CRON: 0 0 0 * * ?
......
wsUsername: schneider wsUsername: schneider
wsPassword: f14d4a80f823438a875b1924384c944c wsPassword: f14d4a80f823438a875b1924384c944c
xmlRoot: xmlHistory
SAP: SAP:
NO009: NO009:
CRON: 0 0 0 * * ? CRON: 0 0 0 * * ?
......
wsUsername: test wsUsername: test
wsPassword: 78258c537d6e4d5fb210a57d05619fb6 wsPassword: 78258c537d6e4d5fb210a57d05619fb6
xmlRoot: xmlHistory
SAP: SAP:
NO009: NO009:
CRON: 0 0 0 * * ? CRON: 0 0 0 * * ?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment