diff --git a/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java b/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java index 2607fa4f8..9ec27868f 100644 --- a/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java +++ b/src/main/java/com/glxp/api/idc/service/impl/IdcServiceImpl.java @@ -67,18 +67,18 @@ public class IdcServiceImpl implements IdcService { @Value("${API_SECRET}") private String apiSecret; - /*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/ + /*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表唯一列(多列逗号分隔)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/ private final String[] SYNC_TABLES= { - "entrustAction////////委托验收,basicProducts//basic_udirel///updateTime///耗材字典","/basicProducts/basic_products//////耗材字典信息详情", - "//company_product_relevance///updateTime///供应商关联信息", - "basicCorp//basic_corp///updateTime///往来单位","typeThird//thr_bustype_origin///updateTime///第三方单据类型", - "basicThirdCorp//thr_corp///updateTime///第三方往来单位","//thr_dept///updateTime///第三方部门", - "//thr_inv_products///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse//////第三方仓库", - "basicThirdBusOrder//thr_order///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail///updateTime///第三方单据详情", - "basicThirdProducts//thr_products///updateTime///第三方产品信息","//sup_cert///updateTime/filePath//资质证书信息", - "//sup_cert_set///updateTime///供应商资质证书设置","companyCert//sup_company///updateTime///配送企业", - "manufacturerCert//sup_manufacturer///updateTime///生产企业","productCert//sup_product///updateTime///产品资质信息", - "dbDiProducts//productinfo///updateTime///DI产品信息,//udicompany///updateTime///国际库医疗器械注册人信息"}; + "entrustAction/////////委托验收","basicProducts//basic_udirel/uuid///updateTime///耗材字典","/basicProducts/basic_products/uuid,nameCode/uuid/uuid////耗材字典信息详情", + "//company_product_relevance////updateTime///供应商关联信息", + "basicCorp//basic_corp/erpId///updateTime///往来单位","typeThird//thr_bustype_origin/action,thirdSys///updateTime///第三方单据类型", + "basicThirdCorp//thr_corp/unitId,thirdSysFk///updateTime///第三方往来单位","//thr_dept/code,thirdSysFk///updateTime///第三方部门", + "//thr_inv_products/inventoryCode,batchNo,warehouseCode,spaceCode,thirdSysFk///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse/code,thirdSysFk//////第三方仓库", + "basicThirdBusOrder//thr_order/billNo,thirdSysFk///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail/productId,orderIdFk,thirdSysFk///updateTime///第三方单据详情", + "basicThirdProducts//thr_products/code,thirdSysFk///updateTime///第三方产品信息","//sup_cert////updateTime/filePath//资质证书信息", + "//sup_cert_set////updateTime///供应商资质证书设置","companyCert//sup_company////updateTime///配送企业", + "manufacturerCert//sup_manufacturer////updateTime///生产企业","productCert//sup_product/productId,manufacturerIdFk,customerId///updateTime///产品资质信息", + "dbDiProducts//productinfo/nameCode,uuiddiType///updateTime///DI产品信息//udicompany/tyshxydm///updateTime///国际库医疗器械注册人信息"}; private int orderNum=0; @@ -169,6 +169,7 @@ public class IdcServiceImpl implements IdcService { if(map!=null&&map.get("downstreamEnable")!=null&&map.get("downstreamEnable").toString().equals("1")) { for(int i=0;i> keyList = dbDao.listKeyMysql(tnames[2]); String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id"; Map map = new HashMap(); String sqlWhere = "not exists (select fkId from idc_record where type='"+tnames[2]+"' and fkId="+tnames[2]+"."+keyColumn+")"; - if(!StringUtils.isEmpty(tnames[5])) { - sqlWhere+=" and "+tnames[5]+">=cast('"+lastUpdateTime+"' as datetime)"; + if(!StringUtils.isEmpty(tnames[6])) { + sqlWhere+=" and "+tnames[6]+">=cast('"+lastUpdateTime+"' as datetime)"; } else { map.put("isEnd", "1"); } map.put("sqlWhere", sqlWhere); - map.put("dataWhere", tnames[7]); + map.put("tableKey", tnames[0]); map.put("tableName", tnames[2]); - map.put("masterLinkColumn", tnames[3]); - map.put("subLinkColumn", tnames[4]); - map.put("filePathColumn", tnames[6]); - map.put("messageType", tnames[8]); - map.put("messageName", tnames[8]); + map.put("uniqueColumn", tnames[3]); + map.put("masterLinkColumn", tnames[4]); + map.put("subLinkColumn", tnames[5]); + map.put("filePathColumn", tnames[7]); + map.put("dataWhere", tnames[8]); + map.put("messageType", tnames[9]); + map.put("messageName", tnames[9]); ScheduledRequest scheduledRequest = new ScheduledRequest(); scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", "")); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); @@ -406,7 +403,7 @@ public class IdcServiceImpl implements IdcService { boolean success=false; String tableName = params.get("tableName").toString(); String tableKey = params.get("tableKey").toString(); - String[] childs = {}; + String[] childs = new String[10]; int childNum = -1; /*子表*/ for(String str:SYNC_TABLES) { @@ -421,12 +418,12 @@ public class IdcServiceImpl implements IdcService { String sql = "select count(*) from "+tableName; Map column = getColumn(tableName); - Map whMap = new HashMap(); - whMap.put("sqlWhere", params.get("sqlWhere")); - whMap.put("dataWhere", params.get("dataWhere")); + Map whereParams = new HashMap(); + whereParams.put("sqlWhere", params.get("sqlWhere")); + whereParams.put("dataWhere", params.get("dataWhere")); Map map = new HashMap(); - String where = DBAUtils.convertWhere(column,whMap,""); + String where = DBAUtils.convertWhere(column,whereParams,""); sql+=!StringUtils.isEmpty(where) ? " where "+where : ""; map.put("sql", sql); int total = dbDao.count(map); @@ -441,14 +438,16 @@ public class IdcServiceImpl implements IdcService { if(total>0) { success = true; - params.put("page", 0); - params.put("limit", limit); + + whereParams.put("page", 0); + whereParams.put("limit", limit); + List> keyList = dbDao.listKeyMysql(tableName); String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id"; for(int i=0;i data = getData(messageType,tableName,params); + whereParams.replace("page", i *limit); + whereParams.replace("limit",limit); + Map data = getData(messageType,tableName,params,whereParams); String recordSql = ""; orderNum++; saveIdcLog(messageType,"",tableName +">"+where,i *limit,total); @@ -462,7 +461,8 @@ public class IdcServiceImpl implements IdcService { } recordSql+=!StringUtils.isEmpty(recordSql) ? "," : ""; recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())"; - if(childNum>-1&¶ms.get("masterLinkColumn")!=null&¶ms.get("subLinkColumn")!=null) { + if(childNum>-1&¶ms.get("masterLinkColumn")!=null&&!StringUtils.isEmpty(params.get("masterLinkColumn").toString())&& + params.get("subLinkColumn")!=null&&!StringUtils.isEmpty(params.get("subLinkColumn").toString())) { for(int z=0;z> list = jsonObject.getObject("data", List.class); - analyData(jsonObject.getString("tableName"),list); + analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list); //图片处理 } } /*按表名解析数据到数据库,子表暂未处理*/ - private void analyData(String tableName,List> list) { + private void analyData(String tableName,String uniqueColumn,List> list) { + String tName = DBAUtils.tableRealName(tableName); String sql="insert into "+tName +"("; String del="delete from "+tName+" where "; String upd="update "+tName+" set "; - String[] keyColumn=new String[10]; - String[] keyDataType=new String[10]; + String[] keyColumn=new String[30]; + String[] keyDataType=new String[30]; List> columnList = dbDao.listColumnsMysql(tName); int key=0; int col=0; @@ -562,11 +563,17 @@ public class IdcServiceImpl implements IdcService { String extra = columnList.get(i).get("extra")!=null&&columnList.get(i).get("extra").toLowerCase().contains("auto_i") ? "A" : "N"; sql+=extra.equals("N") ? columnList.get(i).get("columnName").toString() : ""; col+=extra.equals("N") ? 1 : 0; - if(columnList.get(i).get("columnKey")!=null&&!StringUtils.isEmpty(columnList.get(i).get("columnKey").toString())&& - ("PRI,UNI,MUL".contains(columnList.get(i).get("columnKey").toString()))&&extra.equals("N")) { + if(uniqueColumn!=null&&columnList.get(i).get("columnKey")!=null&&(","+uniqueColumn+",").contains(","+columnList.get(i).get("columnKey")+",")) { keyColumn[key] = columnList.get(i).get("columnName").toString(); - keyDataType[key]=columnList.get(i).get("dataType").toString().contains("char") ? "C" : "N"; + keyDataType[key]=columnList.get(i).get("dataType").toString().contains("char") ? "C" : columnList.get(i).get("dataType").toString().contains("date") ? "D" : "N"; key++; + } else { + if(columnList.get(i).get("columnKey")!=null&&!StringUtils.isEmpty(columnList.get(i).get("columnKey").toString())&& + ("PRI,UNI,MUL".contains(columnList.get(i).get("columnKey").toString()))&&extra.equals("N")) { + keyColumn[key] = columnList.get(i).get("columnName").toString(); + keyDataType[key]=columnList.get(i).get("dataType").toString().contains("char") ? "C" : columnList.get(i).get("dataType").toString().contains("date") ? "D" : "N"; + key++; + } } } sql+=") values "; @@ -582,7 +589,9 @@ public class IdcServiceImpl implements IdcService { for(int z=0;z) obj) { chList.add((Map)o); } - analyData(list.get(i).get("tableName"+m).toString(),chList); + analyData(list.get(i).get("tableName"+m).toString(),"",chList); } } @@ -739,13 +748,14 @@ public class IdcServiceImpl implements IdcService { return list; } /*由表名获取数据*/ - private Map getData(String messageType,String tableName,Map params) { - List> list = getList(tableName,params); + private Map getData(String messageType,String tableName,Map params,Map whereParams) { + List> list = getList(tableName,whereParams); Map map = new HashMap(); map.put("messageId", UUID.randomUUID().toString().replaceAll("-", "")); map.put("messageType", messageType); map.put("apiCode", "common"); map.put("tableName", DBAUtils.tableAliasName(tableName)); + map.put("uniqueColumn", params.get("uniqueColumn")); map.put("sendTime", new Date()); map.put("version", "1.0"); map.put("total", list.size()); diff --git a/src/main/java/com/glxp/api/task/AsyncUdiTask.java b/src/main/java/com/glxp/api/task/AsyncUdiTask.java index 4742af9f3..311ee0a54 100644 --- a/src/main/java/com/glxp/api/task/AsyncUdiTask.java +++ b/src/main/java/com/glxp/api/task/AsyncUdiTask.java @@ -37,7 +37,7 @@ public class AsyncUdiTask implements SchedulingConfigurer { scheduledRequest.setCronName("syncIdcUdi"); logger.info("syncIdcUdi----------------"); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); - String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 0/30 * * * ?"; + String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "35 * * * * ?"; if (cron.isEmpty()) { logger.error("cron is null");