From 63f7df01bd069d5cd2372dafd5a7d1f387497390 Mon Sep 17 00:00:00 2001 From: chengqf <584883665@139.com> Date: Thu, 13 Apr 2023 21:58:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8B=89=E5=8F=960k=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/idc/service/impl/IdcServiceImpl.java | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 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 ec520942..01788796 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 @@ -197,9 +197,20 @@ public class IdcServiceImpl implements IdcService { } } } + //拉取失败文件 + fetchFailFile(host); } } + + private void fetchFailFile(String host) { + Map map = new HashMap(); + map.put("sql", "select * from idc_file where createTime> list = dbDao.list(map); + for(int i=0;i"+files[i]); + logger.info("file-->"+files[i]); } for (int z = 0; z < 30; z++) { if (list.get(i).get("data" + z) != null) { @@ -797,7 +808,7 @@ public class IdcServiceImpl implements IdcService { filePathColumn, List> list, boolean isUpload) { - String tName = DBAUtils.tableRealName(tableName); + String tName = DBAUtils.tableRealName(tableName); String sql = "replace " + tName + "("; String del = "delete from " + tName + " where "; String upd = "update " + tName + " set "; @@ -1013,31 +1024,39 @@ public class IdcServiceImpl implements IdcService { try { Response result = client.newCall(request).execute(); - - if (MediaType.parse("application/force-download").equals(result.body().contentType())) { + int total = 0; + if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) { try (InputStream inputStream = result.body().byteStream()) { - String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/"; - - FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + fileName); - - byte b[] = new byte[1024]; - - int len = 0; - - while ((len = inputStream.read(b)) != -1) { - - outputStream.write(b, 0, len); - - } - - outputStream.flush(); - outputStream.close(); - + + String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/"; + + FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + fileName); + + byte b[] = new byte[1024]; + + int len = 0; + while ((len = inputStream.read(b)) != -1) { + total += len; + outputStream.write(b, 0, len); + + } + + outputStream.flush(); + outputStream.close(); + if(!(total>0)) { + new File(filePath + filePathSlash + fileName).delete(); + executeSql("delete from idc_file where filePath='"+fileName+"'"); + } + } catch (Exception e) { } } + if(!(total>0)) { + String sql = "replace idc_file (filePath,createTime) values ('"+fileName+"',now())"; + executeSql(sql); + } } catch (IOException e) { // TODO Auto-generated catch block @@ -1201,6 +1220,7 @@ public class IdcServiceImpl implements IdcService { alterTable("idc_status", "create table idc_status (id varchar(100),statusTime datetime,PRIMARY KEY (id))"); alterTable("idc_record", "create table idc_record (id varchar(36),type varchar(60),fkId varchar(36),isEnd char(1),createTime datetime,primary key (id),INDEX i_idc_record_fk_id (fkId),INDEX i_idc_record_create_time (createTime))"); alterTable("idc_log", "create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))"); + alterTable("idc_file", "create table idc_file (filePath varchar(255),createTime datetime,PRIMARY KEY (filePath))"); dbDao.delete("delete from idc_record where createTime