Commit edb1ab1a authored by Quxl's avatar Quxl

Merge branch 'master' of http://gitlab.egolm.com/key/sso.git

parents b2db1ecd 2f8bc7e8
package com.egolm.sso.bean;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="Z_MT_SD_008_SO_CONFIRM_QUOTATION", namespace="http://schneider-distributor.com/")
public class Z_MT_SD_008_SO_CONFIRM_QUOTATION {
RESPONSE RESPONSE;
public RESPONSE getRESPONSE() {
return RESPONSE;
}
public void setRESPONSE(RESPONSE rESPONSE) {
RESPONSE = rESPONSE;
}
public static class RESPONSE{
String VBELN;
String MESSAGE;
HEADER HEADER;
List<ITEM_DATA> ITEM_DATA;
List<ITEM_PRICING> ITEM_PRICING;
public String getVBELN() {
return VBELN;
}
public void setVBELN(String vBELN) {
VBELN = vBELN;
}
public String getMESSAGE() {
return MESSAGE;
}
public void setMESSAGE(String mESSAGE) {
MESSAGE = mESSAGE;
}
public HEADER getHEADER() {
return HEADER;
}
public void setHEADER(HEADER hEADER) {
HEADER = hEADER;
}
public List<ITEM_DATA> getITEM_DATA() {
return ITEM_DATA;
}
public void setITEM_DATA(List<ITEM_DATA> iTEM_DATA) {
ITEM_DATA = iTEM_DATA;
}
public List<ITEM_PRICING> getITEM_PRICING() {
return ITEM_PRICING;
}
public void setITEM_PRICING(List<ITEM_PRICING> iTEM_PRICING) {
ITEM_PRICING = iTEM_PRICING;
}
}
public static class HEADER{
String BSTKD_E;
String VBELN;
String VKORG;
String VTWEG;
String SPART;
String ERNAM;
String BSTDK;
String ERZET;
String ERDAT;
String KUNNR;
String KGNNR;
String NAME1;
String NAME2;
String POSTL_COD1;
String CITY1;
String ZZPROM;
String BSTKD;
String AUART;
String CMGST;
String NETWRH;
String MWSTH;
String WAERK;
String DPFLAG;
public String getBSTKD_E() {
return BSTKD_E;
}
public void setBSTKD_E(String bSTKD_E) {
BSTKD_E = bSTKD_E;
}
public String getVBELN() {
return VBELN;
}
public void setVBELN(String vBELN) {
VBELN = vBELN;
}
public String getVKORG() {
return VKORG;
}
public void setVKORG(String vKORG) {
VKORG = vKORG;
}
public String getVTWEG() {
return VTWEG;
}
public void setVTWEG(String vTWEG) {
VTWEG = vTWEG;
}
public String getSPART() {
return SPART;
}
public void setSPART(String sPART) {
SPART = sPART;
}
public String getERNAM() {
return ERNAM;
}
public void setERNAM(String eRNAM) {
ERNAM = eRNAM;
}
public String getBSTDK() {
return BSTDK;
}
public void setBSTDK(String bSTDK) {
BSTDK = bSTDK;
}
public String getERZET() {
return ERZET;
}
public void setERZET(String eRZET) {
ERZET = eRZET;
}
public String getERDAT() {
return ERDAT;
}
public void setERDAT(String eRDAT) {
ERDAT = eRDAT;
}
public String getKUNNR() {
return KUNNR;
}
public void setKUNNR(String kUNNR) {
KUNNR = kUNNR;
}
public String getKGNNR() {
return KGNNR;
}
public void setKGNNR(String kGNNR) {
KGNNR = kGNNR;
}
public String getNAME1() {
return NAME1;
}
public void setNAME1(String nAME1) {
NAME1 = nAME1;
}
public String getNAME2() {
return NAME2;
}
public void setNAME2(String nAME2) {
NAME2 = nAME2;
}
public String getPOSTL_COD1() {
return POSTL_COD1;
}
public void setPOSTL_COD1(String pOSTL_COD1) {
POSTL_COD1 = pOSTL_COD1;
}
public String getCITY1() {
return CITY1;
}
public void setCITY1(String cITY1) {
CITY1 = cITY1;
}
public String getZZPROM() {
return ZZPROM;
}
public void setZZPROM(String zZPROM) {
ZZPROM = zZPROM;
}
public String getBSTKD() {
return BSTKD;
}
public void setBSTKD(String bSTKD) {
BSTKD = bSTKD;
}
public String getAUART() {
return AUART;
}
public void setAUART(String aUART) {
AUART = aUART;
}
public String getCMGST() {
return CMGST;
}
public void setCMGST(String cMGST) {
CMGST = cMGST;
}
public String getNETWRH() {
return NETWRH;
}
public void setNETWRH(String nETWRH) {
NETWRH = nETWRH;
}
public String getMWSTH() {
return MWSTH;
}
public void setMWSTH(String mWSTH) {
MWSTH = mWSTH;
}
public String getWAERK() {
return WAERK;
}
public void setWAERK(String wAERK) {
WAERK = wAERK;
}
public String getDPFLAG() {
return DPFLAG;
}
public void setDPFLAG(String dPFLAG) {
DPFLAG = dPFLAG;
}
}
public static class ITEM_DATA{
String POSNR;
String UEPOS;
String VTEXT;
String MATNR;
String KWMENG;
String VRKME;
String EDATU;
String CDATE;
String REFLAG;
String MWSTI;
String NETWRI;
String WAERK_I;
String WERKS;
String ZZCRDDATE;
String KGNNR_I;
String NAME1_I;
String NAME2_I;
String POSTL_COD1_I;
String CITY1_I;
public String getPOSNR() {
return POSNR;
}
public void setPOSNR(String pOSNR) {
POSNR = pOSNR;
}
public String getUEPOS() {
return UEPOS;
}
public void setUEPOS(String uEPOS) {
UEPOS = uEPOS;
}
public String getVTEXT() {
return VTEXT;
}
public void setVTEXT(String vTEXT) {
VTEXT = vTEXT;
}
public String getMATNR() {
return MATNR;
}
public void setMATNR(String mATNR) {
MATNR = mATNR;
}
public String getKWMENG() {
return KWMENG;
}
public void setKWMENG(String kWMENG) {
KWMENG = kWMENG;
}
public String getVRKME() {
return VRKME;
}
public void setVRKME(String vRKME) {
VRKME = vRKME;
}
public String getEDATU() {
return EDATU;
}
public void setEDATU(String eDATU) {
EDATU = eDATU;
}
public String getCDATE() {
return CDATE;
}
public void setCDATE(String cDATE) {
CDATE = cDATE;
}
public String getREFLAG() {
return REFLAG;
}
public void setREFLAG(String rEFLAG) {
REFLAG = rEFLAG;
}
public String getMWSTI() {
return MWSTI;
}
public void setMWSTI(String mWSTI) {
MWSTI = mWSTI;
}
public String getNETWRI() {
return NETWRI;
}
public void setNETWRI(String nETWRI) {
NETWRI = nETWRI;
}
public String getWAERK_I() {
return WAERK_I;
}
public void setWAERK_I(String wAERK_I) {
WAERK_I = wAERK_I;
}
public String getWERKS() {
return WERKS;
}
public void setWERKS(String wERKS) {
WERKS = wERKS;
}
public String getZZCRDDATE() {
return ZZCRDDATE;
}
public void setZZCRDDATE(String zZCRDDATE) {
ZZCRDDATE = zZCRDDATE;
}
public String getKGNNR_I() {
return KGNNR_I;
}
public void setKGNNR_I(String kGNNR_I) {
KGNNR_I = kGNNR_I;
}
public String getNAME1_I() {
return NAME1_I;
}
public void setNAME1_I(String nAME1_I) {
NAME1_I = nAME1_I;
}
public String getNAME2_I() {
return NAME2_I;
}
public void setNAME2_I(String nAME2_I) {
NAME2_I = nAME2_I;
}
public String getPOSTL_COD1_I() {
return POSTL_COD1_I;
}
public void setPOSTL_COD1_I(String pOSTL_COD1_I) {
POSTL_COD1_I = pOSTL_COD1_I;
}
public String getCITY1_I() {
return CITY1_I;
}
public void setCITY1_I(String cITY1_I) {
CITY1_I = cITY1_I;
}
}
public static class ITEM_PRICING{
String POSNR;
String KSCHL;
String VTEXT;
String KBETR;
String KWERT;
public String getPOSNR() {
return POSNR;
}
public void setPOSNR(String pOSNR) {
POSNR = pOSNR;
}
public String getKSCHL() {
return KSCHL;
}
public void setKSCHL(String kSCHL) {
KSCHL = kSCHL;
}
public String getVTEXT() {
return VTEXT;
}
public void setVTEXT(String vTEXT) {
VTEXT = vTEXT;
}
public String getKBETR() {
return KBETR;
}
public void setKBETR(String kBETR) {
KBETR = kBETR;
}
public String getKWERT() {
return KWERT;
}
public void setKWERT(String kWERT) {
KWERT = kWERT;
}
}
}
...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Configuration;
import com.egolm.sso.service.MaterialMasterService; import com.egolm.sso.service.MaterialMasterService;
import com.egolm.sso.service.PriceListService; import com.egolm.sso.service.PriceListService;
import com.egolm.sso.service.ProFormaInvoiceService; import com.egolm.sso.service.ProFormaInvoiceService;
import com.egolm.sso.service.SoConfirmQuotationService;
@Configuration @Configuration
...@@ -56,6 +57,14 @@ public class WsConfig { ...@@ -56,6 +57,14 @@ public class WsConfig {
endpoint.publish("/pro_forma_invoice"); endpoint.publish("/pro_forma_invoice");
return endpoint; return endpoint;
} }
@Bean
public Endpoint getSoConfirmQuotationPoint(SoConfirmQuotationService soConfirmQuotationService) {
EndpointImpl endpoint = new EndpointImpl(bus, soConfirmQuotationService);
endpoint.setInInterceptors(Arrays.asList(authInterceptor));
endpoint.publish("/so_confirm_quotation");
return endpoint;
}
@Value("${wsUsername}") @Value("${wsUsername}")
private String wsUername; private String wsUername;
......
package com.egolm.sso.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(targetNamespace = "http://price_list.sso.egolm.com")
public interface SoConfirmQuotationService {
@WebMethod
public void execute(String xml);
}
...@@ -31,7 +31,7 @@ public class MaterialMasterServiceImpl implements MaterialMasterService { ...@@ -31,7 +31,7 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
@Override @Override
public void execute(String xml) { public void execute(String xml) {
Element record = StringUtil.getRecordElement(xml); Element record = StringUtil.getDataElement(xml, "RECORD");
Element headerSending = record.element("HEADER_SENDING"); Element headerSending = record.element("HEADER_SENDING");
String DIS_CODE = headerSending.elementText("KUNNR"); String DIS_CODE = headerSending.elementText("KUNNR");
......
...@@ -31,7 +31,7 @@ public class PriceListServiceImpl implements PriceListService { ...@@ -31,7 +31,7 @@ public class PriceListServiceImpl implements PriceListService {
@Override @Override
public void execute(String xml) { public void execute(String xml) {
Element record = StringUtil.getRecordElement(xml); Element record = StringUtil.getDataElement(xml, "RECORD");
Element headerSending = record.element("HEADER_SENDING"); Element headerSending = record.element("HEADER_SENDING");
String KUNNR = headerSending.elementText("KUNNR"); String KUNNR = headerSending.elementText("KUNNR");
......
package com.egolm.sso.service.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.egolm.sso.bean.Z_MT_SD_008_SO_CONFIRM_QUOTATION;
import com.egolm.sso.bean.Z_MT_SD_008_SO_CONFIRM_QUOTATION.HEADER;
import com.egolm.sso.bean.Z_MT_SD_008_SO_CONFIRM_QUOTATION.ITEM_DATA;
import com.egolm.sso.bean.Z_MT_SD_008_SO_CONFIRM_QUOTATION.ITEM_PRICING;
import com.egolm.sso.bean.Z_MT_SD_008_SO_CONFIRM_QUOTATION.RESPONSE;
import com.egolm.sso.service.CommonService;
import com.egolm.sso.service.SoConfirmQuotationService;
import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.FileUtil;
import com.egolm.sso.util.StringUtil;
import com.egolm.sso.util.XMLUtil;
@Component
@WebService(serviceName = "SoConfirmQuotationService", targetNamespace = "http://price_list.sso.egolm.com", endpointInterface = "com.egolm.sso.service.SoConfirmQuotationService")
public class SoConfirmQuotationServiceImpl implements SoConfirmQuotationService{
@Autowired JdbcTemplate jdbcTemplate;
@Autowired CommonService common;
@Override
public void execute(String xml) {
try {
Date now = new Date();
String today = DateUtil.formatDate(now, DateUtil.FMT_DATE);
Long time = now.getTime();
Z_MT_SD_008_SO_CONFIRM_QUOTATION Z_MT_SD_008_SO_CONFIRM_QUOTATION = XMLUtil.toBeanByJxab(xml, Z_MT_SD_008_SO_CONFIRM_QUOTATION.class);
System.out.println(JSON.toJSONString(Z_MT_SD_008_SO_CONFIRM_QUOTATION));
Map<String, Object> header = new HashMap<>();
RESPONSE res = Z_MT_SD_008_SO_CONFIRM_QUOTATION.getRESPONSE();
HEADER h = res.getHEADER();
header.put("BSTKD_E", h.getBSTKD_E());
header.put("VKORG", h.getVKORG());
header.put("VTWEG", h.getVTWEG());
header.put("SPART", h.getSPART());
header.put("ERNAM", h.getERNAM());
header.put("BSTDK", DateUtil.parseDateNoEmpty(h.getBSTDK(), DateUtil.FMT_DATE));
header.put("ERZET", DateUtil.parseDateNoEmpty(h.getERZET(), DateUtil.FMT_TIME));
header.put("ERDAT", DateUtil.parseDateNoEmpty(h.getERDAT(), DateUtil.FMT_DATE));
header.put("KUNNR", h.getKUNNR());
header.put("KGNNR", h.getKGNNR());
header.put("NAME1", h.getNAME1());
header.put("NAME2", h.getNAME2());
header.put("POSTL_COD1", h.getPOSTL_COD1());
header.put("CITY1", h.getCITY1());
header.put("ZZPROM", h.getZZPROM());
header.put("BSTKD", h.getBSTKD());
header.put("AUART", h.getAUART());
header.put("CMGST", h.getCMGST());
header.put("NETWRH", StringUtil.toDouble(h.getNETWRH()));
header.put("MWSTH", StringUtil.toDouble(h.getMWSTH()));
header.put("WAERK", h.getWAERK());
header.put("DPFLAG", h.getDPFLAG());
header.put("SEND_STATUS", "N");
header.put("BATCH", today+"-1");
header.put("CREATED", now);
header.put("CREATEDBY", "system");
String idIndex = common.getNextval(today+"_t_so_confirmation_header")+"";
if(idIndex.length()<5) {
idIndex = StringUtil.prependZero(idIndex, 5);
}
Long hID = Long.valueOf(time+idIndex);
header.put("ID", hID);
insertTo(header, "t_so_confirmation_header");
List<ITEM_DATA> ids = res.getITEM_DATA();
Map<String, Map<String, Object>> itemDatas = new HashMap<>();
for(ITEM_DATA id : ids) {
Map<String, Object> itemData = new HashMap<>();
itemData.put("BSTKD_E", h.getBSTKD_E());
itemData.put("VBELN", h.getVBELN());
itemData.put("HEADER_ID", hID);
itemData.put("POSNR", id.getPOSNR());
itemData.put("UEPOS", id.getUEPOS());
itemData.put("VTEXT", id.getVTEXT());
itemData.put("MATNR", id.getMATNR());
itemData.put("KWMENG", StringUtil.toDouble(id.getKWMENG()));
itemData.put("VRKME", id.getVRKME());
itemData.put("EDATU", DateUtil.parseDateNoEmpty(id.getEDATU(), DateUtil.FMT_DATE));
itemData.put("CDATE", DateUtil.parseDateNoEmpty(id.getCDATE(), DateUtil.FMT_DATE));
itemData.put("REFLAG", id.getREFLAG());
itemData.put("MWSTI", StringUtil.toDouble(id.getMWSTI()));
itemData.put("NETWRI", StringUtil.toDouble(id.getNETWRI()));
itemData.put("WAERK_I", id.getWAERK_I());
itemData.put("WERKS", id.getWERKS());
itemData.put("ZZCRDDATE", DateUtil.parseDateNoEmpty(id.getZZCRDDATE(), DateUtil.FMT_DATE));
itemData.put("KGNNR_I", id.getKGNNR_I());
itemData.put("NAME1_I", id.getNAME1_I());
itemData.put("NAME2_I", id.getNAME2_I());
itemData.put("POSTL_CODE1_I", id.getPOSTL_COD1_I());
itemData.put("CITY1_I", id.getCITY1_I());
itemData.put("CREATED", new Date());
itemData.put("CREATEDBY", "system");
String iidIndex = common.getNextval(today+"_t_so_confirmation_item_data")+"";
if(iidIndex.length()<5) {
iidIndex = StringUtil.prependZero(iidIndex, 5);
}
Long iID = Long.valueOf(time+iidIndex);
itemData.put("ID", iID);
itemDatas.put(id.getPOSNR(), itemData);
insertTo(itemData, "t_so_confirmation_item_data");
}
List<ITEM_PRICING> ips = res.getITEM_PRICING();
for(ITEM_PRICING ip : ips) {
Map<String, Object> itemPricing = new HashMap<>();
itemPricing.put("HEADER_ID", hID);
String POSNR = ip.getPOSNR();
itemPricing.put("ITEM_DATA_ID", itemDatas.get(POSNR).get("ID"));
itemPricing.put("BSTKD_E", h.getBSTKD_E());
itemPricing.put("VBELN", h.getVBELN());
itemPricing.put("POSNR", POSNR);
itemPricing.put("KSCHL", ip.getKSCHL());
itemPricing.put("VTEXT", ip.getVTEXT());
itemPricing.put("KBETR", StringUtil.toDouble(ip.getKBETR()));
itemPricing.put("KWERT", StringUtil.toDouble(ip.getKWERT()));
itemPricing.put("CREATED", new Date());
itemPricing.put("CREATEDBY", "system");
String itemPricingID = common.getNextval(today+"_t_so_confirmation_item_pricing")+"";
if(itemPricingID.length()<5) {
itemPricingID = StringUtil.prependZero(itemPricingID, 5);
}
itemPricing.put("ID", Long.valueOf(time+itemPricingID));
insertTo(itemPricing, "t_so_confirmation_item_pricing");
}
}catch(Exception e) {
e.printStackTrace();
}
}
private void insertTo(Map<String, Object> obj, String table) {
String insertSql = "insert into "+table+" ";
String fieldSql = "(";
String valuesSql = "(";
List<Object> values = new ArrayList<>();
for(Entry<String, Object> entry : obj.entrySet()) {
fieldSql = fieldSql + entry.getKey() + ", ";
valuesSql = valuesSql + "?, ";
values.add(entry.getValue());
}
fieldSql = fieldSql.substring(0, fieldSql.length()-2);
valuesSql = valuesSql.substring(0, valuesSql.length()-2);
insertSql = insertSql + fieldSql + ") values " + valuesSql + ")";
jdbcTemplate.update(insertSql, values.toArray());
}
}
...@@ -35,6 +35,26 @@ public class DateUtil { ...@@ -35,6 +35,26 @@ public class DateUtil {
return fmt.parse(d); return fmt.parse(d);
} }
public static Date parseDateNoEmpty(String d, String fmt) throws ParseException {
Date res;
if(d!=null&&!d.equals("")) {
res = parseDate(d, fmt);
}else {
res = new Date(0);
}
return res;
}
public static Date parseDateNoEmpty(String d, DateFormat fmt) throws ParseException {
Date res;
if(d!=null&&!d.equals("")) {
res = parseDate(d, fmt);
}else {
res = new Date(0);
}
return res;
}
public static DateFormat getFmt(String fmt) { public static DateFormat getFmt(String fmt) {
DateFormat df = fmtMap.get(fmt); DateFormat df = fmtMap.get(fmt);
if(df == null) { if(df == null) {
......
...@@ -31,13 +31,13 @@ public class StringUtil { ...@@ -31,13 +31,13 @@ public class StringUtil {
return prepend + Num; return prepend + Num;
} }
public static Element getRecordElement(String xml) { public static Element getDataElement(String xml, String eName) {
Document doc = null; Document doc = null;
Element el = null; Element el = null;
try { try {
doc = DocumentHelper.parseText(xml); doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement(); Element root = doc.getRootElement();
el = root.element("RECORD"); el = root.element(eName);
} catch (DocumentException e) { } catch (DocumentException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import org.apache.cxf.endpoint.ClientImpl;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.wss4j.common.ext.WSPasswordCallback;
import com.alibaba.fastjson.JSON;
public class SoConfirmQuotationTest {
private static final String username = "test";
private static final String password = "78258c537d6e4d5fb210a57d05619fb6";
public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
ClientImpl client = (ClientImpl) factory.createClient("http://localhost:8080/sso/services/so_confirm_quotation?wsdl");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
properties.put(WSHandlerConstants.USER, username);
properties.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
properties.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
public void handle(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
pc.setPassword(password);
}
}
});
WSS4JOutInterceptor interceptor = new WSS4JOutInterceptor();
interceptor.setProperties(properties);
client.setOutInterceptors(Arrays.asList(interceptor));
String xml = readText("D:/data/sso/008.XML");
System.out.println(JSON.toJSONString(client.invoke("execute", xml)));
}
private static String readText(String path) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
return sb.toString();
} finally {
br.close();
}
}
}
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