From ac7a1ca8c26f3ce3a750b2f63761e894a3ab6650 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 1 Apr 2023 20:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idc/service/impl/IdcServiceImpl.java | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java index 0cf26a4..e5726fb 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java @@ -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; @@ -286,11 +287,11 @@ public class IdcServiceImpl implements IdcService { JSONObject json = JSONObject.parseObject(content); String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd"); - - FileUtils.makeDirectory(filePath +datePath+"/"); - FileUtils.makeDirectory(backFilePath +datePath+"/"); String fileName = filePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi"; String backFileName = backFilePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi"; + FileUtils.makeDirectory(fileName); + FileUtils.makeDirectory(backFileName); + FileUtils.SaveFileAs(content, fileName); FileUtils.SaveFileAs(content, backFileName); String[] saveFiles= {}; @@ -316,11 +317,18 @@ public class IdcServiceImpl implements IdcService { saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName); /*解析入库*/ if(isLastLevel()) { - analyToDB(json,files); + if(!analyToDB(json,files)) + return ResultVOUtils.error(9000, "解析失败"); } else { //需要转发 if(isRelay()) { - relay(request.getHeader("reqNo"),content,saveFiles); + String result = relay(request.getHeader("reqNo"),content,saveFiles); + if(IDCUtils.isJson(result)) { + JSONObject object = JSON.parseObject(result); + if(object.getInteger("code")!=20000) + return ResultVOUtils.error(9000, "转发失败"); + } + } } return ResultVOUtils.success(); @@ -356,13 +364,11 @@ public class IdcServiceImpl implements IdcService { dbDao.save(sql); } - private void saveExportStatus(String messageType,String taskId,String fileName) { + private void saveExportStatus(Map 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); @@ -503,12 +509,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,34 +525,41 @@ 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 +"("; @@ -555,6 +568,7 @@ public class IdcServiceImpl implements IdcService { 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; } @@ -761,6 +776,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 +895,6 @@ public class IdcServiceImpl implements IdcService { } } + + }