|  |  |  | @ -27,7 +27,6 @@ import org.springframework.jdbc.core.JdbcTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.scheduling.annotation.Async; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.scheduling.support.CronSequenceGenerator; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.web.multipart.MultipartFile; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
	
		
			
				
					|  |  |  | @ -59,7 +58,6 @@ import okhttp3.Response; | 
			
		
	
		
			
				
					|  |  |  |  | /*数据中继数据中心(接收)*/ | 
			
		
	
		
			
				
					|  |  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  |  | @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |  | public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 	private static final Logger logger = LoggerFactory.getLogger(IdcServiceImpl.class); | 
			
		
	
		
			
				
					|  |  |  |  | 	@Value("${file_path}") | 
			
		
	
	
		
			
				
					|  |  |  | @ -75,16 +73,22 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  |     /*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表唯一列(多列逗号分隔)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private final String[] SYNC_TABLES= { | 
			
		
	
		
			
				
					|  |  |  |  |     		"entrustAction//basic_entrust_accept/id//////委托验收","basicProducts//basic_udirel/id///updateTime///耗材字典","/basicProducts/basic_products/id/uuid/uuid////耗材字典信息详情", | 
			
		
	
		
			
				
					|  |  |  |  | 			"//company_product_relevance////updateTime///供应商关联信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"/companyCert/company_product_relevance/id/customerId/unitFk/updateTime///供应商关联信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"basicCorp//basic_corp/id///updateTime///往来单位","typeThird//thr_bustype_origin/id///updateTime///第三方单据类型", | 
			
		
	
		
			
				
					|  |  |  |  | 			"basicThirdCorp//thr_corp/id///updateTime///第三方往来单位","//thr_dept/id///updateTime///第三方部门", | 
			
		
	
		
			
				
					|  |  |  |  | 			"//thr_inv_products/id///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse/id//////第三方仓库", | 
			
		
	
		
			
				
					|  |  |  |  | 			"basicThirdBusOrder//thr_order/id///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail/orderIdFk/id/orderIdFk/updateTime///第三方单据详情", | 
			
		
	
		
			
				
					|  |  |  |  | 			"basicThirdProducts//thr_products/id///updateTime///第三方产品信息","//sup_cert/id///updateTime/filePath//资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"basicThirdProducts//thr_products/id///updateTime///第三方产品信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"//sup_cert_set/id///updateTime///供应商资质证书设置","companyCert//sup_company/customerId///updateTime///配送企业", | 
			
		
	
		
			
				
					|  |  |  |  | 			"manufacturerCert//sup_manufacturer/id///updateTime///生产企业","productCert//sup_product/id///updateTime///产品资质信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"/companyCert/sup_cert/id/customerId/customerId/updateTime/filePath/type=1/配送企业资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"/manufacturerCert/sup_cert/id/manufacturerId/manufacturerIdFk/updateTime/filePath/type=2/生产企业资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"/productCert/sup_cert/id/productId/productIdFk/updateTime/filePath/type=3/产品资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  | 			"//udicompany/id///updateTime///国际库医疗器械注册人信息"}; | 
			
		
	
		
			
				
					|  |  |  |  |    //"dbDiProducts//productinfo/id///updateTime///DI产品信息",
 | 
			
		
	
		
			
				
					|  |  |  |  |     //"basicInv/////////仓库字典",
 | 
			
		
	
		
			
				
					|  |  |  |  |   //"typeBus/////////业务单据类型",
 | 
			
		
	
		
			
				
					|  |  |  |  |   //"typeScan/////////扫码单据类型",
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private int orderNum=0; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@Resource | 
			
		
	
	
		
			
				
					|  |  |  | @ -200,8 +204,10 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			for(int i=0;i<SYNC_TABLES.length;i++) { | 
			
		
	
		
			
				
					|  |  |  |  | 				String[] tnames = SYNC_TABLES[i].split("/"); | 
			
		
	
		
			
				
					|  |  |  |  | 				boolean sync = StringUtils.isEmpty(tnames[0]) ||  | 
			
		
	
		
			
				
					|  |  |  |  | 						(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1")); | 
			
		
	
		
			
				
					|  |  |  |  | 				saveIdcLog("---","",map.get(tnames[0])+SYNC_TABLES[i],0,0); | 
			
		
	
		
			
				
					|  |  |  |  | 				if(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1")) { | 
			
		
	
		
			
				
					|  |  |  |  | 				if(sync) { | 
			
		
	
		
			
				
					|  |  |  |  | 					String syncIp = map.get("syncIp")!=null ? map.get("syncIp").toString() : ""; | 
			
		
	
		
			
				
					|  |  |  |  | 					syncData(SYNC_TABLES[i],isUpload,syncIp); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
	
		
			
				
					|  |  |  | @ -213,7 +219,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 		boolean sync = true; | 
			
		
	
		
			
				
					|  |  |  |  | 		String[] tnames = t.split("/"); | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 		String lastUpdateTime = getUpdateTime(tnames[3]); | 
			
		
	
		
			
				
					|  |  |  |  | 		String lastUpdateTime = getUpdateTime(tnames[2]+"."+tnames[0]); | 
			
		
	
		
			
				
					|  |  |  |  | 		Date nowUpdateTime = new Date(); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(!StringUtils.isEmpty(tnames[0])) { | 
			
		
	
		
			
				
					|  |  |  |  | 			 | 
			
		
	
	
		
			
				
					|  |  |  | @ -251,7 +257,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 	        if(sync) { | 
			
		
	
		
			
				
					|  |  |  |  | 				if(syncMasterData(map,isUpload,syncIp)) { | 
			
		
	
		
			
				
					|  |  |  |  | 					setUpdateTime(tnames[2],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss")); | 
			
		
	
		
			
				
					|  |  |  |  | 					setUpdateTime(tnames[2]+"."+tnames[0],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss")); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  |  | 	        } | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
	
		
			
				
					|  |  |  | @ -279,9 +285,9 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 			 | 
			
		
	
		
			
				
					|  |  |  |  | 			if(isLastLevel()) { | 
			
		
	
		
			
				
					|  |  |  |  | 				if(json.get("code")!=null) { | 
			
		
	
		
			
				
					|  |  |  |  | 					success = analyToDB(host,json.getJSONObject("data"),files,false); | 
			
		
	
		
			
				
					|  |  |  |  | 					success = analyMiddle(host,json.getJSONObject("data"),files,false,true); | 
			
		
	
		
			
				
					|  |  |  |  | 				} else { | 
			
		
	
		
			
				
					|  |  |  |  | 					success = analyToDB(host,json,files,false); | 
			
		
	
		
			
				
					|  |  |  |  | 					success = analyMiddle(host,json,files,false,true); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  |  | 				if(!success) | 
			
		
	
		
			
				
					|  |  |  |  | 					logger.info("fetchData-->解析失败"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -380,7 +386,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  |         syncAddTaskStatus(json,true,true); | 
			
		
	
		
			
				
					|  |  |  |  |         /*解析入库*/ | 
			
		
	
		
			
				
					|  |  |  |  |         if(isLastLevel()) { | 
			
		
	
		
			
				
					|  |  |  |  |         	if(!analyToDB("",json,files,true)) | 
			
		
	
		
			
				
					|  |  |  |  |         	if(!analyMiddle("",json,files,true,true)) | 
			
		
	
		
			
				
					|  |  |  |  |         		return ResultVOUtils.error(9000, "解析失败"); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |         	//需要转发
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -629,11 +635,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/*解析到数据库*/ | 
			
		
	
		
			
				
					|  |  |  |  | 	private boolean analyToDB(String host,JSONObject jsonObject,MultipartFile[] files,boolean isUpload) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private boolean analyMiddle(String host,JSONObject jsonObject,MultipartFile[] files,boolean isUpload,boolean isToDB) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if(jsonObject.get("data")!=null) { | 
			
		
	
		
			
				
					|  |  |  |  | 			String tableName = ""; | 
			
		
	
		
			
				
					|  |  |  |  | 			String uniqueColumn = ""; | 
			
		
	
	
		
			
				
					|  |  |  | @ -653,7 +655,12 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 				filePathColumn = obj.getString("filePathColumn"); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			if(!StringUtils.isEmpty(tableName)) { | 
			
		
	
		
			
				
					|  |  |  |  | 				return analyData(host,tableName,uniqueColumn,filePathColumn,list,isUpload); | 
			
		
	
		
			
				
					|  |  |  |  | 				if(isToDB) { | 
			
		
	
		
			
				
					|  |  |  |  | 					return analyToDB(host,tableName,uniqueColumn,filePathColumn,list,isUpload); | 
			
		
	
		
			
				
					|  |  |  |  | 				} else { | 
			
		
	
		
			
				
					|  |  |  |  | 					logger.info("files-->"+tableName); | 
			
		
	
		
			
				
					|  |  |  |  | 					return analyToFile(host,filePathColumn,list); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  |  | 			} else { | 
			
		
	
		
			
				
					|  |  |  |  | 				logger.error("数据格式错误:无数据标记"); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
	
		
			
				
					|  |  |  | @ -662,8 +669,24 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 		return false; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private boolean analyToFile(String host,String filePathColumn,List<Map<String,Object>> list) { | 
			
		
	
		
			
				
					|  |  |  |  | 		 | 
			
		
	
		
			
				
					|  |  |  |  | 		if(list!=null&&list.size()>0&&!StringUtils.isEmpty(filePathColumn)) { | 
			
		
	
		
			
				
					|  |  |  |  | 			String[] files = new String[list.size()]; | 
			
		
	
		
			
				
					|  |  |  |  | 			logger.info("filePathColumn-->"+filePathColumn); | 
			
		
	
		
			
				
					|  |  |  |  | 			for(int i=0;i<list.size();i++) { | 
			
		
	
		
			
				
					|  |  |  |  | 				files[i] = list.get(i).get(filePathColumn) !=null ? list.get(i).get(filePathColumn).toString() : ""; | 
			
		
	
		
			
				
					|  |  |  |  | 				logger.info("file-->"+files[i]); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			 | 
			
		
	
		
			
				
					|  |  |  |  | 			batchDownloadFile(host,files); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return true; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	/*解析到数据库*/ | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 	/*按表名解析数据到数据库,子表暂未处理*/ | 
			
		
	
		
			
				
					|  |  |  |  | 	private boolean analyData(String host,String tableName,String uniqueColumn,String filePathColumn,List<Map<String,Object>> list,boolean isUpload) { | 
			
		
	
		
			
				
					|  |  |  |  | 	private boolean analyToDB(String host,String tableName,String uniqueColumn,String filePathColumn,List<Map<String,Object>> list,boolean isUpload) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 		String tName = DBAUtils.tableRealName(tableName); | 
			
		
	
		
			
				
					|  |  |  |  | 		String sql="replace "+tName +"("; | 
			
		
	
	
		
			
				
					|  |  |  | @ -774,7 +797,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 						for (Object o : (List<?>) obj) { | 
			
		
	
		
			
				
					|  |  |  |  | 							chList.add((Map<String,Object>)o); | 
			
		
	
		
			
				
					|  |  |  |  | 						} | 
			
		
	
		
			
				
					|  |  |  |  | 						analyData(host,list.get(i).get("tableName"+m).toString(),"","",chList,isUpload); | 
			
		
	
		
			
				
					|  |  |  |  | 						analyToDB(host,list.get(i).get("tableName"+m).toString(),"","",chList,isUpload); | 
			
		
	
		
			
				
					|  |  |  |  | 					} else { | 
			
		
	
		
			
				
					|  |  |  |  | 						break; | 
			
		
	
		
			
				
					|  |  |  |  | 					} | 
			
		
	
	
		
			
				
					|  |  |  | @ -787,6 +810,7 @@ public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  | 					logger.error(tableName+"-->fetchSave Fail"); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			if(!isUpload&&!StringUtils.isEmpty(filePathColumn)) { | 
			
		
	
		
			
				
					|  |  |  |  | 				logger.info("downloadFile-->"+files.toString()); | 
			
		
	
		
			
				
					|  |  |  |  | 				batchDownloadFile(host,files); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |