|
|
@@ -68,14 +68,14 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
if (!checkXmlFileToSqlToEnterprise(file, enterprise)) {
|
|
|
continue;
|
|
|
}
|
|
|
- sqls = parseXmlFileToSqls(file, statement);
|
|
|
+ sqls = parseXmlFileToSqls(file, statement, sob);
|
|
|
if (sqls == null) {
|
|
|
//移动处理失败的文件到failed文件夹下
|
|
|
BaseUtil.getLogger().info("failed sqls is null:"+file.getName());
|
|
|
client.rename(file.getName(), "failed/" + file.getName());
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+ //System.out.println("sqls:"+sqls);
|
|
|
executeRes = executeSqls(connect, sqls);
|
|
|
|
|
|
if (executeRes) {
|
|
|
@@ -138,7 +138,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
/*
|
|
|
* 通过配置解析xml为sql语句
|
|
|
*/
|
|
|
- public static List<String> parseXmlFileToSqls(File file,Statement statement){
|
|
|
+ public static List<String> parseXmlFileToSqls(File file,Statement statement,String sob){
|
|
|
List<String> sqls = new ArrayList<String>();
|
|
|
Statement stm=statement;
|
|
|
String mainTableUpdateSql = null;
|
|
|
@@ -157,16 +157,38 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
if(detail!=null){
|
|
|
detailData = getDetailData(root); //获取明细数据
|
|
|
}
|
|
|
+
|
|
|
+ //
|
|
|
+ ResultSet set = null;
|
|
|
+ boolean allowSplitProdIn = false;
|
|
|
+ try{
|
|
|
+ set = statement.executeQuery("select count(1) from " + sob + ".configs where code='useInSplitOfEDI' and caller='sys' and data='1'");
|
|
|
+ while (set.next()){
|
|
|
+ int count = set.getInt(1);
|
|
|
+ if (count==1){
|
|
|
+ allowSplitProdIn=true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ set.close();
|
|
|
+ }catch(SQLException e){
|
|
|
+ BaseUtil.getLogger().info("getXmlConfigDetail():"+e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
docType = mainData.get("DOC_TYPE"); //文件类型
|
|
|
- Map<String,String> xmlConfig = getXmlConfig(statement,docType,filePrefix); //通过文件名前缀查找相应配置
|
|
|
+ Map<String,String> xmlConfig = getXmlConfig(statement,docType,filePrefix,allowSplitProdIn); //通过文件名前缀查找相应配置
|
|
|
if(xmlConfig.keySet().size()==0){
|
|
|
return null;
|
|
|
}
|
|
|
String caller=xmlConfig.get("xd_caller");
|
|
|
+
|
|
|
+// if(!"ProdiodetailSplitOfEDI".equals(caller)){
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
List<Map<String,String>> mainXmlConfig = getXmlConfigDetail(statement,xmlConfig.get("xd_id"),"0",xmlConfig.get("xd_main_conditiontag")); //获取主表的配置
|
|
|
if(xmlConfig.get("xd_detail_conditiontag")!=null&&detailData!=null){
|
|
|
- if("Packing".equals(caller)||"Invoice".equals(caller)){
|
|
|
+ if("Packing".equals(caller)||"Invoice".equals(caller) || "ProdiodetailSplitOfEDI".equals(caller)){
|
|
|
detailXmlConfig = getXmlConfigDetail(statement,xmlConfig.get("xd_id"),"1"); //获取明细表的配置
|
|
|
}else {
|
|
|
detailXmlConfig = getXmlConfigDetail(statement, xmlConfig.get("xd_id"), "1", xmlConfig.get("xd_detail_conditiontag")); //获取明细表的配置
|
|
|
@@ -185,8 +207,8 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
updateDetailConditon = getUpdateDetailConditionByMainTable(mainData,xmlConfig); //明细表跟主表关联更新条件
|
|
|
for(Map<String,String> data:detailData){
|
|
|
String sql = null;
|
|
|
- if("Packing".equals(caller)||"Invoice".equals(caller)){
|
|
|
- sql = getInsertDetailSql(maincode,data,xmlConfig,detailXmlConfig);
|
|
|
+ if("Packing".equals(caller)||"Invoice".equals(caller) || "ProdiodetailSplitOfEDI".equals(caller)){
|
|
|
+ sql = getInsertDetailSql(maincode,data,xmlConfig,detailXmlConfig,updateMainConditon);
|
|
|
}else{
|
|
|
sql = getUpdateDetailSql(data,xmlConfig,detailXmlConfig) + " and " + updateDetailConditon;
|
|
|
}
|
|
|
@@ -195,7 +217,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
|
|
|
//记录json数据
|
|
|
- logSql = getLogXmlDataAndInterceptorSql(mainData,detailData,xmlConfig,statement,fileName);
|
|
|
+ logSql = getLogXmlDataAndInterceptorSql(mainData,detailData,xmlConfig,statement,fileName,allowSplitProdIn);
|
|
|
sqls.addAll(logSql);
|
|
|
try {
|
|
|
stm.close();
|
|
|
@@ -208,7 +230,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("finally")
|
|
|
- private static List<String> getLogXmlDataAndInterceptorSql(Map<String, String> mainData,List<Map<String,String>> detailData,Map<String,String> xmlConfig,Statement statement,String fileName){
|
|
|
+ private static List<String> getLogXmlDataAndInterceptorSql(Map<String, String> mainData,List<Map<String,String>> detailData,Map<String,String> xmlConfig,Statement statement,String fileName,boolean allowSplitProdIn){
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
String jsonData = null;
|
|
|
String log = null;
|
|
|
@@ -246,13 +268,16 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
|
|
|
if(!("Packing".equals(caller)||"Invoice".equals(caller))){
|
|
|
+ if ("ProdiodetailSplitOfEDI".equals(caller) && allowSplitProdIn){
|
|
|
+ sqls.add("declare out varchar2(500);begin SP_XMLTEMPPARSEOFINEDI("+id+",'" + caller + "',out);end;");
|
|
|
+ }
|
|
|
//common interceptors 主要用于自动过账
|
|
|
rs = statement.executeQuery("select id from interceptors where caller='"+caller+"' "
|
|
|
+ "and class_='com.uas.erp.service.common.impl.CommonHandler' "
|
|
|
+ "and method='exec_handler' and type='xmltrans' and enable=1");
|
|
|
while(rs.next()){
|
|
|
sqls.add("declare out varchar2(500);begin SP_COMMONHANDLER("+id+"," + rs.getString("id") + ",out);end;");
|
|
|
- }
|
|
|
+ }
|
|
|
}else {
|
|
|
sqls.add("declare out varchar2(500);begin SP_XMLTEMPPARSE("+id+",'" + caller + "',out);end;");
|
|
|
}
|
|
|
@@ -288,7 +313,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
/*
|
|
|
* 获取添加临时表数据sql
|
|
|
*/
|
|
|
- public static String getInsertDetailSql(String maincode,Map<String, String> data,Map<String,String> xmlConfig,List<Map<String,String>> detailXmlConfig){
|
|
|
+ public static String getInsertDetailSql(String maincode,Map<String, String> data,Map<String,String> xmlConfig,List<Map<String,String>> detailXmlConfig,String updateMainConditon){
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
StringBuffer sb2 =new StringBuffer();
|
|
|
String sql = null;
|
|
|
@@ -298,7 +323,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
for(Map<String,String> map:detailXmlConfig){
|
|
|
sb.append("," + map.get("uasfield"));
|
|
|
}
|
|
|
- if("Packing".equals(caller)){
|
|
|
+ if("Packing".equals(caller) || "ProdiodetailSplitOfEDI".equals(caller)){
|
|
|
sb.append(",pdt_piid,pdt_id,pdt_status,pdt_indate) values (");
|
|
|
}else if ("Invoice".equals(caller)){
|
|
|
sb.append(",idt_inid,idt_id,idt_status,idt_indate) values (");
|
|
|
@@ -316,8 +341,13 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
sb2.append(",'" + data.get(map.get("xmltag")) + "'");
|
|
|
}
|
|
|
}
|
|
|
- sb2.append(",(select "+xmlConfig.get("xd_keyfield")+" from "+xmlConfig.get("xd_table")
|
|
|
- +" where "+xmlConfig.get("xd_main_conditionfield")+"='"+maincode+"')");
|
|
|
+ if ("ProdiodetailSplitOfEDI".equals(caller)){
|
|
|
+ sb2.append(",(select "+xmlConfig.get("xd_keyfield")+" from "+xmlConfig.get("xd_table")
|
|
|
+ +" where "+updateMainConditon+")");
|
|
|
+ }else {
|
|
|
+ sb2.append(",(select "+xmlConfig.get("xd_keyfield")+" from "+xmlConfig.get("xd_table")
|
|
|
+ +" where "+xmlConfig.get("xd_main_conditionfield")+"='"+maincode+"')");
|
|
|
+ }
|
|
|
sb2.append(","+xmlConfig.get("xd_detailtable")+"_seq.nextval,'UNPARSE',sysdate)");
|
|
|
resSql=sql+sb2.substring(1,sb2.length());
|
|
|
return resSql;
|
|
|
@@ -456,12 +486,14 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
/*
|
|
|
* 获取xmldataconfig配置
|
|
|
*/
|
|
|
- public static Map<String,String> getXmlConfig(Statement statement,String docType,String filePrefix){
|
|
|
+ public static Map<String,String> getXmlConfig(Statement statement,String docType,String filePrefix,boolean allowSplitProdIn){
|
|
|
Map<String,String> map = new HashMap<String,String>();
|
|
|
ResultSet rs = null;
|
|
|
try{
|
|
|
if(docType==null){
|
|
|
rs = statement.executeQuery("select * from xmldataconfig where xd_fileprefix='"+ filePrefix + "' and xd_type='DOWNLOAD'");
|
|
|
+ }else if (("采购验收单".equals(docType) || "销售退货单".equals(docType) || "拨入单".equals(docType)) && allowSplitProdIn){
|
|
|
+ rs = statement.executeQuery("select * from xmldataconfig where xd_caller='ProdiodetailSplitOfEDI' and xd_fileprefix='"+ filePrefix + "' and xd_type='DOWNLOAD'");
|
|
|
}else{
|
|
|
rs = statement.executeQuery("select * from xmldataconfig where xd_doctype='"+ docType + "' and xd_type='DOWNLOAD' and xd_fileprefix='"+ filePrefix + "'");
|
|
|
}
|