Commit 99f2fee2 authored by 曲欣红's avatar 曲欣红

2.列表价接口

parent 17dc2517
......@@ -20,6 +20,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.egolm.sso.service.MaterialMasterService;
import com.egolm.sso.service.PriceListService;
@Configuration
......@@ -39,6 +40,14 @@ public class WsConfig {
return endpoint;
}
@Bean
public Endpoint getPriceListPoint(PriceListService priceListService) {
EndpointImpl endpoint = new EndpointImpl(bus, priceListService);
endpoint.setInInterceptors(Arrays.asList(authInterceptor));
endpoint.publish("/price_list");
return endpoint;
}
@Value("${wsUsername}")
private String wsUername;
......
......@@ -9,15 +9,11 @@ import java.util.Map.Entry;
import javax.jws.WebService;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
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.service.CommonService;
import com.egolm.sso.service.MaterialMasterService;
import com.egolm.sso.util.DateUtil;
......@@ -35,10 +31,7 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
@Override
public void execute(String xml) {
System.out.println(common.getNextval("Test"));
System.out.println(xml);
Element record = getRecordElement(xml);
Element record = StringUtil.getRecordElement(xml);
Element headerSending = record.element("HEADER_SENDING");
String DIS_CODE = headerSending.elementText("KUNNR");
......@@ -105,11 +98,10 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
goods.put("SEND_TIME", new Date());
goods.put("DIS_UPDATE_STATUS", "N");
/*********************缺*********************/
/*******************不知道填什么**********************/
goods.put("UPDATEDBY", "");
goods.put("CREATEDBY", "");
/*******************不知道填什么**********************/
/***************item**************/
/**
* 数据库没有数据追踪号对应字段TRACE_NO
*/
String BATCH = (String) goods.get("BATCH");
if(BATCH==null||"".equals(BATCH.trim())) {
......@@ -128,8 +120,6 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
goods.put("SEND_STATUS", "N");
goods.put("UPDATED", DateUtil.formatDate(new Date(), DateUtil.FMT_DATE_TIME)/*datetimef.format(new Date())*/);
System.out.println(JSON.toJSONString(goods));
if(goods.get("ID")!=null) {
updateGoods(goods);
}else {
......@@ -142,7 +132,7 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
}
private void updateGoods(Map<String, Object> goods) {
goods.put("UPDATEDBY", "");
goods.put("UPDATEDBY", "system");
String sql = "update t_ven_goods set ";
List<Object> args = new ArrayList<>();
......@@ -166,7 +156,8 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
String ID = System.currentTimeMillis() + StringUtil.prependZero(count+1, 5);
goods.put("ID", ID);
goods.put("CREATED", DateUtil.formatDate(new Date(), DateUtil.FMT_DATE_TIME)/*datetimef.format(new Date())*/);
goods.put("CREATEDBY", "");
goods.put("CREATEDBY", "system");
goods.put("UPDATEDBY", "");
String insertSql = "insert into t_ven_goods ";
......@@ -192,18 +183,4 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
}
return null;
}
public static Element getRecordElement(String xml) {
Document doc = null;
Element el = null;
try {
doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement();
el = root.element("RECORD");
} catch (DocumentException e) {
e.printStackTrace();
}
return el;
}
}
package com.egolm.sso.service.impl;
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.dom4j.Element;
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.service.CommonService;
import com.egolm.sso.service.PriceListService;
import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.StringUtil;
@Component
@WebService(serviceName = "PriceListService", targetNamespace = "http://service.sso.egolm.com", endpointInterface = "com.egolm.sso.service.PriceListService")
......@@ -21,8 +32,130 @@ public class PriceListServiceImpl implements PriceListService {
@Override
public void execute(String xml) {
// TODO Auto-generated method stub
Element record = StringUtil.getRecordElement(xml);
Element headerSending = record.element("HEADER_SENDING");
String KUNNR = headerSending.elementText("KUNNR");
String DATUM = headerSending.elementText("DATUM");
String UZEIT = headerSending.elementText("UZEIT");
List<Element> itemList = record.elements("ITEM");
try {
for (Element element : itemList) {
String MATNR = element.elementText("MATNR");
Map<String, Object> priceObj = getPriceObj(KUNNR, MATNR);
if(priceObj == null) {
priceObj = new HashMap<>();
}
/**********header***********/
priceObj.put("KUNNR", KUNNR);
priceObj.put("DATUM", DATUM);
priceObj.put("UZEIT", UZEIT);
/**********header***********/
/**********item***********/
priceObj.put("MATNR", MATNR);
priceObj.put("KBETR", StringUtil.toDouble(element.elementText("KBETR")));
priceObj.put("KONWA", element.elementText("KONWA"));
priceObj.put("KPEIN", element.elementText("KPEIN"));
priceObj.put("KMEIN", element.elementText("KMEIN"));
priceObj.put("UMREZ", element.elementText("UMREZ"));
priceObj.put("MAKTX", element.elementText("MAKTX"));
priceObj.put("PRSCH", StringUtil.toDouble(element.elementText("PRSCH")));
priceObj.put("DATAM", element.elementText("DATAM"));
Date DATBI;
String DATBIStr = element.elementText("DATBI");
if(DATBIStr==null||DATBIStr.equals("")) {
DATBI = new Date();
}else {
DATBI = DateUtil.parseDate(DATBIStr, DateUtil.FMT_DATE);
}
priceObj.put("DATBI", DATBI);
priceObj.put("PLINE", element.elementText("PLINE"));
priceObj.put("PRSCH_1", StringUtil.toDouble(element.elementText("PRSCH_1")));
/**********item***********/
/***********缺**************/
priceObj.put("SEND_DATE", new Date());
/***********缺**************/
priceObj.put("SEND_STATUS", "N");
String BATCH = (String) priceObj.get("BATCH");
if(BATCH==null||"".equals(BATCH.trim())) {
BATCH = DateUtil.formatDate(new Date(), DateUtil.FMT_DATE)+"-1"/*datef.format(new Date())+"-1"*/;
}else {
String[] ss = BATCH.split("-");
String newDate = DateUtil.formatDate(new Date(), DateUtil.FMT_DATE);
int v = 1;
if(ss[0].equals(newDate)) {
v = Integer.valueOf(ss[1])+1;
}
BATCH = newDate+"-"+v;
}
priceObj.put("BATCH", BATCH);
priceObj.put("UPDATED", DateUtil.formatDate(new Date(), DateUtil.FMT_DATE_TIME));
if(priceObj.get("ID")!=null) {
updatePriceObj(priceObj);
}else {
insertPriceObj(priceObj);
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
private void updatePriceObj(Map<String, Object> priceObj) {
priceObj.put("UPDATEDBY", "system");
String sql = "update t_price_list set ";
List<Object> args = new ArrayList<>();
for (Entry<String, Object> entry : priceObj.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if(!key.equals("ID")) {
sql = sql + key + " = ?, ";
args.add(value);
}
}
sql = sql.substring(0, sql.length()-2);
sql = sql + " where ID = ?";
args.add(priceObj.get("ID"));
jdbcTemplate.update(sql, args.toArray());
}
private void insertPriceObj(Map<String, Object> priceObj) {
String countSql = "select count(1) from t_price_list";
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
String ID = System.currentTimeMillis() + StringUtil.prependZero(count+1, 5);
priceObj.put("ID", ID);
priceObj.put("CREATED", DateUtil.formatDate(new Date(), DateUtil.FMT_DATE_TIME)/*datetimef.format(new Date())*/);
priceObj.put("CREATEDBY", "system");
priceObj.put("UPDATEDBY", "");
String insertSql = "insert into t_price_list ";
String fieldSql = "(";
String valuesSql = "(";
List<Object> values = new ArrayList<>();
for(Entry<String, Object> entry : priceObj.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());
}
private Map<String, Object> getPriceObj(String KUNNR, String MATNR){
String sql = "select * from t_price_list where KUNNR = ? and MATNR = ?";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, KUNNR, MATNR);
if(list!=null&&list.size()>0) {
return list.get(0);
}
return null;
}
}
......@@ -4,11 +4,12 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class DateUtil {
public static Map<String, DateFormat> fmtMap;
public static Map<String, DateFormat> fmtMap = new HashMap<>();
public static final String FMT_DATE = "yyyyMMdd";
public static final String FMT_TIME = "HHmmss";
......
package com.egolm.sso.util;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class StringUtil {
public static Double toDouble(String value) {
Double res;
if(value==null||value.equals("")) {
res = 0.0;
}else {
res = Double.valueOf(value);
}
return res;
}
public static String prependZero(int Num, int length) {
return prependZero(Num+"", length);
}
......@@ -13,4 +28,17 @@ public class StringUtil {
}
return prepend + Num;
}
public static Element getRecordElement(String xml) {
Document doc = null;
Element el = null;
try {
doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement();
el = root.element("RECORD");
} catch (DocumentException e) {
e.printStackTrace();
}
return el;
}
}
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 PriceListServiceTest {
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/price_list?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/002.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