From 7321c957fec200e74b96866511f5ea7de34053c4 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 1 Apr 2023 21:53:24 +0800 Subject: [PATCH] =?UTF-8?q?UDI=E5=90=8C=E6=AD=A5=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=BD=BF=E7=94=A8syncIp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/idc/service/impl/IdcServiceImpl.java | 99 ++++++++++++------- 1 file changed, 63 insertions(+), 36 deletions(-) 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 db405d1e..f65edae6 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 @@ -15,7 +15,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.text.WordUtils; import org.apache.tools.ant.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,7 +78,8 @@ public class IdcServiceImpl implements IdcService { "basicThirdProducts//thr_products/id///updateTime///第三方产品信息","//sup_cert/id///updateTime/filePath//资质证书信息", "//sup_cert_set/id///updateTime///供应商资质证书设置","companyCert//sup_company/customerId///updateTime///配送企业", "manufacturerCert//sup_manufacturer/id///updateTime///生产企业","productCert//sup_product/id///updateTime///产品资质信息", - "dbDiProducts//productinfo/id///updateTime///DI产品信息","//udicompany/id///updateTime///国际库医疗器械注册人信息"}; + "//udicompany/id///updateTime///国际库医疗器械注册人信息"}; + //"dbDiProducts//productinfo/id///updateTime///DI产品信息", private int orderNum=0; @@ -167,16 +168,24 @@ public class IdcServiceImpl implements IdcService { initTable(); Map map = dbDao.get("select * from sync_data_set limit 1"); if(map!=null&&map.get("downstreamEnable")!=null&&map.get("downstreamEnable").toString().equals("1")) { + if(isUpload) { + if(!(map.get("syncIp")!=null&&!StringUtils.isEmpty(map.get("syncIp").toString()))) { + logger.error("中继服务地址未配置"); + return; + } + } for(int i=0;i params) { Map map = new HashMap(); - map.put("id", CustomUtil.getId()); - map.put("taskId", taskId); - map.put("cacheFilePath", fileName); map.put("status", "0"); - map.put("type", messageType); + map.putAll(params); + map.put("id", CustomUtil.getId()); map.put("updateTime", new Date()); Map columns = getColumn("basic_export_status"); String sql = "insert into basic_export_status "+DBAUtils.parseInsert(map, columns); @@ -399,7 +414,7 @@ public class IdcServiceImpl implements IdcService { } - private boolean syncMasterData(Map params,boolean isUplaod) { + private boolean syncMasterData(Map params,boolean isUplaod,String syncIp) { boolean success=false; String tableName = params.get("tableName").toString(); String tableKey = params.get("tableKey").toString(); @@ -481,7 +496,7 @@ public class IdcServiceImpl implements IdcService { if(isUplaod) { String result = ""; try { - result = relay("",JSON.toJSONString(data),files); + result = relay("",JSON.toJSONString(data),files,syncIp); } catch (Exception ex) { } @@ -503,12 +518,12 @@ public class IdcServiceImpl implements IdcService { saveIdcLog(messageType,"",tableName +">fail:上传地址未连通",i *limit,total); } } else { - syncAddTask(data); if(!StringUtils.isEmpty(recordSql)) { dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql); } saveIdcLog(messageType,"",tableName +">success",i *limit,total); } + syncAddTask(data,isUplaod); } } } @@ -519,42 +534,50 @@ public class IdcServiceImpl implements IdcService { } /*增加同步任务*/ - private void syncAddTask(Map json) { + private void syncAddTask(Map json,boolean isUpload) { String content = JSON.toJSONString(json); String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd"); - - FileUtils.makeDirectory(filePath +datePath+"/"); - FileUtils.makeDirectory(backFilePath +datePath+"/"); String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi"; + FileUtils.makeDirectory(fileName); + FileUtils.makeDirectory(backFileName); + FileUtils.SaveFileAs(content, fileName); FileUtils.SaveFileAs(content, backFileName); - - - saveExportStatus(json.get("messageType").toString(),json.get("messageId").toString(),fileName); + + //type,transportType,superiorService,subordinateService,cacheFilePath + Map map = new HashMap<>(); + map.put("type", json.get("messageType")); + map.put("transportType", isUpload ? "1" : "2"); + map.put("scheduleType", isUpload ? "1" : "0"); + map.put("taskId", json.get("messageId")); + map.put("cacheFilePath", fileName); + saveExportStatus(map); } /*解析到数据库*/ - private void analyToDB(JSONObject jsonObject,MultipartFile[] files) { + private boolean analyToDB(JSONObject jsonObject,MultipartFile[] files) { if(!StringUtils.isEmpty(jsonObject.getString("tableName"))) { List> list = jsonObject.getObject("data", List.class); - analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list); + return analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list); //图片处理 } + return false; } /*按表名解析数据到数据库,子表暂未处理*/ - private void analyData(String tableName,String uniqueColumn,List> list) { + private boolean analyData(String tableName,String uniqueColumn,List> list) { String tName = DBAUtils.tableRealName(tableName); - String sql="replace "+tName +"("; + String sql="replace "+tName +"("; String del="delete from "+tName+" where "; String upd="update "+tName+" set "; String[] keyColumn=new String[30]; String[] keyDataType=new String[30]; List> columnList = dbDao.listColumnsMysql(tName); + boolean result = false; int key=0; int col=0; for(int i=0;i0) - dbDao.save(sql); + if(n>0) { + result = (dbDao.save(sql)>0); + } } - + return result; } /*转发下级或上级中继服务*/ - private String relay(String reqNo,String content,String[] files) { - String host = getNextHost(); + private String relay(String reqNo,String content,String[] files,String ip) { + String host = ip; String result=""; if(StringUtils.isEmpty(reqNo)) reqNo = UUID.randomUUID().toString(); @@ -761,6 +785,7 @@ public class IdcServiceImpl implements IdcService { map.put("apiCode", "common"); map.put("tableName", DBAUtils.tableAliasName(tableName)); map.put("uniqueColumn", params.get("uniqueColumn")); + map.put("filePathColumn", params.get("filePathColumn")); map.put("sendTime", new Date()); map.put("version", "1.0"); map.put("total", list.size()); @@ -879,4 +904,6 @@ public class IdcServiceImpl implements IdcService { } } + + }