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 cc3292a..fcfebe9 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 @@ -61,12 +61,12 @@ public class IdcServiceImpl implements IdcService { private String filePath; @Value("${back_file_path}") private String backFilePath; - + @Value("${API_KEY}") private String apiKey; @Value("${API_SECRET}") private String apiSecret; - + /*自助平台->UDI*/ private final String[] SPMS_TO_UDI_TABLES= { "basic_udirel/updateTime//耗材字典","basic_products///耗材字典信息详情","company_product_relevance/updateTime//供应商关联信息", @@ -90,19 +90,19 @@ public class IdcServiceImpl implements IdcService { "productinfo/updateTime//国家库UDI数据,udicompany/updateTime//国际库医疗器械注册人信息"}; private int orderNum=0; - + @Resource private SystemParamConfigService systemParamConfigService; - + @Resource private JdbcTemplate jdbcTemplate; - + @Resource private DbDao dbDao; - + @Resource private ScheduledDao scheduledDao; - + @Override public BaseResponse taskList(HttpServletRequest request,Map params) { Map map = new HashMap(); @@ -110,7 +110,7 @@ public class IdcServiceImpl implements IdcService { List> list = dbDao.list(map); return ResultVOUtils.success(list); } - + @Override public BaseResponse download(HttpServletRequest request,Map params) { Map map = dbDao.get("select * from basic_upload_status where taskId='"+params.get("taskId")+"'"); @@ -120,7 +120,7 @@ public class IdcServiceImpl implements IdcService { JSONObject object = JSON.parseObject(json); return ResultVOUtils.success(object); } - + /*拉取前一级中继服务数据*/ @Override public void pull() { @@ -138,14 +138,14 @@ public class IdcServiceImpl implements IdcService { } } } - + @Async @Override public void asyncIdcTask() { initTable(); String[] tNames= {}; String direction = getDirection(); - + if(direction.equals("I")) { tNames = SPMS_TO_UDI_TABLES; } else { @@ -161,7 +161,7 @@ public class IdcServiceImpl implements IdcService { uploadData(t); } } - + } private void uploadData(String t) { String[] tn = t.split("/"); @@ -196,7 +196,7 @@ public class IdcServiceImpl implements IdcService { } //} } - + private String pullData(String url,Map params) { OkHttpClient client = new OkHttpClient().newBuilder() .build(); @@ -220,7 +220,7 @@ public class IdcServiceImpl implements IdcService { } return result; } - + private String post(String url,Map params) { OkHttpClient client = new OkHttpClient().newBuilder() .build(); @@ -241,8 +241,8 @@ public class IdcServiceImpl implements IdcService { } return result; } - - + + public BaseResponse downlaodSuccess(HttpServletRequest request,Map params) { String sql = "update basic_upload_status set status='1' where taskId='"+params.get("taskId")+"'"; dbDao.update(sql); @@ -257,9 +257,9 @@ public class IdcServiceImpl implements IdcService { String secretKey = request.getHeader("secretKey"); /*******/ 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"; @@ -284,7 +284,7 @@ public class IdcServiceImpl implements IdcService { // TODO Auto-generated catch block e.printStackTrace(); } - + } saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName); /*解析入库*/ @@ -298,8 +298,8 @@ public class IdcServiceImpl implements IdcService { } return ResultVOUtils.success(); } - - + + /*数据同步,从数据库获取数据下发或上传下级中继服务*/ @Override public BaseResponse send(Map params) { @@ -307,12 +307,12 @@ public class IdcServiceImpl implements IdcService { } @Override public BaseResponse send(String messageType,String tableName,Map params) { - if(sendOnPage(messageType,tableName,params)) + if(sendOnPage(messageType,tableName,params)) return ResultVOUtils.success(); return ResultVOUtils.error(9999, ""); } - - + + private void saveUploadStatus(String messageType,String taskId,String fileName) { Map map = new HashMap(); map.put("id", CustomUtil.getId()); @@ -323,7 +323,7 @@ public class IdcServiceImpl implements IdcService { map.put("updateTime", new Date()); Map columns = getColumn("basic_upload_status"); String sql = "insert into basic_upload_status "+DBAUtils.parseInsert(map, columns); - + dbDao.save(sql); } private void saveDownloadStatus(String messageType,String taskId,String remark) { @@ -336,7 +336,7 @@ public class IdcServiceImpl implements IdcService { map.put("remark", remark); Map columns = getColumn("basic_download_status"); String sql = "insert into basic_download_status "+DBAUtils.parseInsert(map, columns); - + dbDao.save(sql); } private void saveIdcLog(String messageType,String taskId,String content,int offset,int total) { @@ -351,7 +351,7 @@ public class IdcServiceImpl implements IdcService { map.put("total", total); Map columns = getColumn("idc_log"); String sql = "insert into idc_log "+DBAUtils.parseInsert(map, columns); - + dbDao.save(sql); } private boolean sendOnPage(String messageType,String tableName,Map params) { @@ -359,10 +359,10 @@ public class IdcServiceImpl implements IdcService { Map table = dbDao.getMysql(tableName); if(!(table!=null&&table.get("tableName")!=null)) return false; - + String sql = "select count(*) from "+tableName; Map column = getColumn(tableName); - + Map map = new HashMap(); String where = DBAUtils.convertWhere(column,params,""); sql+=!StringUtils.isEmpty(where) ? " where "+where : ""; @@ -370,7 +370,7 @@ public class IdcServiceImpl implements IdcService { int total = dbDao.count(map); String direction = getDirection(); String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0"; - int limit = 50; + int limit = 50; String[] files = new String[limit]; String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : ""; orderNum++; @@ -386,7 +386,7 @@ public class IdcServiceImpl implements IdcService { orderNum++; saveIdcLog(messageType,"",tableName +">"+where,i *limit,total); if(data.get("data")!=null) { - + List list = JSONObject.parseArray(JSON.toJSONString(data.get("data")), Map.class); if(list!=null&&list.size()>0) { for(int m=0;m> list) { String tName = DBAUtils.tableRealName(tableName); @@ -455,7 +455,7 @@ public class IdcServiceImpl implements IdcService { } } sql+=") values "; - + if(list!=null&&list.size()>0) { int n = 0; int d = 0; @@ -470,10 +470,10 @@ public class IdcServiceImpl implements IdcService { updateWhere+=keyColumn[z]+" = "+(keyDataType[z].equals("C") ? "'" :"") +list.get(i).get(keyColumn[z]) +(keyDataType[z].equals("C") ? "'" :""); } } - if("A,D".contains(operateMode)&&!StringUtils.isEmpty(updateWhere)) + if("A,D".contains(operateMode)&&!StringUtils.isEmpty(updateWhere)) dbDao.delete(del+updateWhere); - } - + } + /*A 新增 U 更新*/ if("A,U".contains(operateMode)) { sql+=n>0 ? "," : ""; @@ -484,7 +484,7 @@ public class IdcServiceImpl implements IdcService { String extra = columnList.get(k).get("extra")!=null&&columnList.get(k).get("extra").toLowerCase().contains("auto") ? "A" : "N"; String attrName = columnList.get(k).get("attrName"); String value = list.get(i).get(attrName) !=null ? list.get(i).get(attrName).toString() : ""; - String dataType = columnList.get(k).get("dataType").toLowerCase().contains("char") || columnList.get(k).get("dataType").toLowerCase().contains("text") ? + String dataType = columnList.get(k).get("dataType").toLowerCase().contains("char") || columnList.get(k).get("dataType").toLowerCase().contains("text") ? "C" : columnList.get(k).get("dataType").toLowerCase().contains("date") ? "D" : "N" ; if(extra.equals("N")) { sql+=m>0 ? "," : ""; @@ -521,12 +521,12 @@ public class IdcServiceImpl implements IdcService { } if(n>0) dbDao.save(sql); - + } - + } - + /*转发下级或上级中继服务*/ private String relay(String direction,String reqNo,String content,String[] files) { String host = getNextHost(direction); @@ -540,20 +540,20 @@ public class IdcServiceImpl implements IdcService { .readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间 .build(); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); - + MultipartBody.Builder builder = new MultipartBody.Builder(); builder.setType(MultipartBody.FORM); String fileType = "application/octet-stream"; - for (int i = 0; i < files.length; i++) { + for (int i = 0; i < files.length; i++) { if(!StringUtils.isEmpty(files[i])) { - File file = new File(files[i]); - builder.addFormDataPart("files",files[i], + File file = new File(files[i]); + builder.addFormDataPart("files",files[i], RequestBody.create(MediaType.parse(fileType), file)); } } builder.addFormDataPart("content", content); RequestBody body = builder.build(); - + Request req = new Request.Builder() .url(host) .method("POST", body) @@ -573,13 +573,13 @@ public class IdcServiceImpl implements IdcService { // TODO Auto-generated catch block e.printStackTrace(); } - + } else { log.debug("未配置中继服务地址"); } return result; } - + /*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/ private String getNextHost(String direction) { SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("upper_server_ip","中继上传服务地址" , "",""); @@ -587,14 +587,14 @@ public class IdcServiceImpl implements IdcService { //getSystemParamConfig("sync_idc_lower_host","下级(下发)中继服务地址" , "","") ; return systemParamConfigEntity.getParamValue(); } - + /*判断是否最后一级*/ private boolean isLastLevel(String direction) { - SystemParamConfigEntity systemParamConfigEntity = + SystemParamConfigEntity systemParamConfigEntity = direction.equals("I") ? getSystemParamConfig("sync_idc_top","是否顶级中继服务(连接自助平台)" , "0","0:否;1:是(是,接收下级上传数据后解析入库)"): getSystemParamConfig("sync_idc_final","是否末级中继服务(连接UDI管理系统)" , "0","0:否;1:是(是,接收上级下发数据后解析入库)") ; return systemParamConfigEntity.getParamValue().equals("0") ? false : true ; - + } /*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/ private String getDirection() { @@ -606,13 +606,13 @@ public class IdcServiceImpl implements IdcService { return "U"; } return "I"; - + } - + /*是否需要转发*/ private boolean isRelay(String direction) { String relayStr = direction.equals("U") ? "sync_upstream_enable" : "sync_downstream_enable"; - + SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(relayStr); if (systemParamConfigEntity!=null&&systemParamConfigEntity.getParamValue()!=null&& systemParamConfigEntity.getParamValue().equals("0")) { @@ -620,8 +620,8 @@ public class IdcServiceImpl implements IdcService { } return true; } - - + + /*由表名获取数据*/ private Map getData(String messageType,String tableName,Map params) { String sql = "select "+tableName+".*,'A' as operateMode from "+tableName; @@ -641,10 +641,10 @@ public class IdcServiceImpl implements IdcService { map.put("data", list); return map; } - - - - + + + + private SystemParamConfigEntity getSystemParamConfig(String paramKey,String paramName,String defaultValue,String paramExplain) { SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey); if(systemParamConfigEntity==null||(systemParamConfigEntity!=null&&StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) { @@ -654,7 +654,7 @@ public class IdcServiceImpl implements IdcService { systemParamConfigEntity.setParentId(0); systemParamConfigEntity.setParamValue(defaultValue); systemParamConfigEntity.setParamExplain(paramExplain); - systemParamConfigEntity.setParamStatus(0); + systemParamConfigEntity.setParamStatus(1); systemParamConfigEntity.setParamType(0); systemParamConfigService.insert(systemParamConfigEntity); } @@ -671,8 +671,8 @@ public class IdcServiceImpl implements IdcService { out.flush(); out.close(); } - - + + /*把列数据转Map*/ private Map getColumn(String tableName) { Map map = new HashMap(); @@ -684,7 +684,7 @@ public class IdcServiceImpl implements IdcService { if(columnList!=null&&columnList.size()>0) { for(int i=0;i column = new HashMap(); - String dataType =columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text")? + String dataType =columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text")? "C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;; String attrName = columnList.get(i).get("columnName").toString(); if(map.get(attrName)==null) { @@ -707,8 +707,8 @@ public class IdcServiceImpl implements IdcService { } return map; } - - + + private String getUpdateTime(String id) { String updateTime = ""; Map map = dbDao.get("select * from idc_status where id='"+id+"'"); @@ -718,7 +718,7 @@ public class IdcServiceImpl implements IdcService { updateTime = "2000-01-01 00:00:00"; String sql = "insert into idc_status (id,statusTime) values ('"+id+"',cast('"+updateTime+"' as datetime))"; dbDao.save(sql); - } + } return updateTime; } private String setUpdateTime(String id,String updateTime) { @@ -730,7 +730,7 @@ public class IdcServiceImpl implements IdcService { } else { sql = "insert into idc_status (id,statusTime) values ('"+id+"',cast('"+updateTime+"' as datetime))"; dbDao.save(sql); - } + } return updateTime; } private void initTable() { @@ -744,7 +744,7 @@ public class IdcServiceImpl implements IdcService { if(!(map!=null&&map.get("tableName")!=null)) { jdbcTemplate.execute(sql); } - + } }