From 7a3d58fc3ccefc02509ff830095419ce22186f95 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 7 Apr 2023 14:42:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1id=E4=BF=9D=E6=8C=81=E4=B8=80?= =?UTF-8?q?=E8=87=B4=EF=BC=8C=E5=BC=80=E5=A7=8B=EF=BC=8C=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/idc/service/impl/IdcServiceImpl.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 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 0c7d0052..9094acb8 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 @@ -287,6 +287,7 @@ public class IdcServiceImpl implements IdcService { .build(); String result = ""; MultipartFile[] files = {}; + Date startTime = new Date(); try { boolean success=true; Response response = client.newCall(request).execute(); @@ -301,11 +302,11 @@ public class IdcServiceImpl implements IdcService { } else { success = false; } - syncAddTaskStatus(json.getJSONObject("data"),3,success); + syncAddTaskStatus(json.getJSONObject("data"),3,success,startTime,true); } else { if(json.get("code")!=null&&json.get("data")!=null) { - logger.info("res1-->"+JSON.toJSONString(json)); - syncAddTaskStatus(json.getJSONObject("data"),0,success); + //logger.info("res1-->"+JSON.toJSONString(json)); + syncAddTaskStatus(json.getJSONObject("data"),0,success,startTime,true); analyMiddle(host,json.getJSONObject("data"),files,false,false); } } @@ -348,7 +349,7 @@ public class IdcServiceImpl implements IdcService { public BaseResponse downlaodSuccess(HttpServletRequest request,Map params) { - String sql = "update basic_export_status set receiveStatus='1' where id='"+params.get("taskId")+"'"; + String sql = "update basic_export_status set receiveStatus='1',endTime=now() where id='"+params.get("taskId")+"'"; dbDao.update(sql); return ResultVOUtils.success(); } @@ -374,9 +375,9 @@ public class IdcServiceImpl implements IdcService { FileUtils.SaveFileAs(content, fileName); FileUtils.SaveFileAs(content, backFileName); ArrayList saveFiles = new ArrayList<>(); - + Date startTime = new Date(); if(files!=null) { - + int n=0; try { for(MultipartFile file:files) { @@ -401,7 +402,7 @@ public class IdcServiceImpl implements IdcService { boolean success = false; if(isLastLevel()) { success = analyMiddle("",json,files,true,true); - syncAddTaskStatus(json,2,success); + syncAddTaskStatus(json,2,success,startTime,true); if(!success) { return ResultVOUtils.error(9000, "解析失败"); @@ -412,11 +413,11 @@ public class IdcServiceImpl implements IdcService { String host = getNextHost(); String result = relay(request.getHeader("reqNo"),content,saveFiles,host); if(IDCUtils.isJson(result)) { - syncAddTaskStatus(json,1,true); + syncAddTaskStatus(json,1,true,startTime,true); BaseResponse object = JSON.parseObject(result,BaseResponse.class); return object; } else { - syncAddTaskStatus(json,1,false); + syncAddTaskStatus(json,1,false,startTime,false); return ResultVOUtils.error(9000, "转发失败"); } @@ -445,10 +446,8 @@ public class IdcServiceImpl implements IdcService { public void downloadFile(String fileName,HttpServletResponse response) { OutputStream os; String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : fileName.substring(0,1).equals("/") ? "" : "/"; - if(!FileUtils.isFileExist(filePath+filePathSlash+fileName)) - fileName = "11.jpg"; - logger.info(filePath+filePathSlash+fileName); - try { + + try { if(FileUtils.isFileExist(filePath+filePathSlash+fileName)) { byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName); os = response.getOutputStream(); @@ -465,23 +464,21 @@ public class IdcServiceImpl implements IdcService { private void saveUploadStatus(Map params) { Map map = new HashMap(); map.putAll(params); - map.put("id", CustomUtil.getId()); - map.put("updateTime", new Date()); + Map columns = getColumn("basic_upload_status"); - String sql = "insert into basic_upload_status "+DBAUtils.parseInsert(map, columns); + String sql = "replace basic_upload_status "+DBAUtils.parseInsert(map, columns); dbDao.save(sql); } private void saveExportStatus(Map params) { Map map = new HashMap(); - map.putAll(params); map.put("receiveStatus", "0"); - 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); + String sql = "replace basic_export_status "+DBAUtils.parseInsert(map, columns); dbDao.save(sql); } @@ -489,10 +486,9 @@ public class IdcServiceImpl implements IdcService { Map map = new HashMap(); map.put("receiveStatus", "0"); map.putAll(params); - map.put("id", CustomUtil.getId()); - map.put("updateTime", new Date()); + Map columns = getColumn("basic_download_status"); - String sql = "insert into basic_download_status "+DBAUtils.parseInsert(map, columns); + String sql = "replace basic_download_status "+DBAUtils.parseInsert(map, columns); dbDao.save(sql); } @@ -563,6 +559,7 @@ public class IdcServiceImpl implements IdcService { for(int i=0;i data = getData(messageType,tableName,params,whereParams); String recordSql = ""; orderNum++; @@ -583,6 +580,7 @@ public class IdcServiceImpl implements IdcService { } recordSql+=!StringUtils.isEmpty(recordSql) ? "," : ""; recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())"; + if(childNum>-1) { for(int z=0;zsuccess",i *limit,total); } - syncAddTaskStatus(data,isUpload ? 1 : 0 ,success); + syncAddTaskStatus(data,isUpload ? 1 : 0 ,success,startTime,isUpload); } } } @@ -652,7 +650,7 @@ public class IdcServiceImpl implements IdcService { } /*增加同步任务状态*/ - private void syncAddTaskStatus(Map json,int scheduleType,boolean success) { + private void syncAddTaskStatus(Map json,int scheduleType,boolean success,Date startTime,boolean isEnd) { try { String content = JSON.toJSONString(json); @@ -670,11 +668,18 @@ public class IdcServiceImpl implements IdcService { //type,transportType,superiorService,subordinateService,cacheFilePath Map map = new HashMap<>(); map.put("type", json.get("messageType")); + map.put("id", json.get("messageId")); + if(json.get("id")==null) + map.put("id", CustomUtil.getId()); map.put("transportType", scheduleType == 0 ? "1" : "2"); map.put("scheduleType", scheduleType); map.put("taskId", json.get("messageId")); map.put("cacheFilePath", fileName); map.put("status", success ? "1" : "0"); + map.put("startTime", startTime!=null ? startTime : new Date()); + map.put("updateTime", new Date()); + if(isEnd) + map.put("endTime", new Date()); if(scheduleType==2) { saveUploadStatus(map); } else if (scheduleType==3) { @@ -1032,7 +1037,6 @@ public class IdcServiceImpl implements IdcService { Map map = new HashMap(); map.putAll(params); map.put("sql", sql); - List> list = dbDao.list(map); return list; } @@ -1040,7 +1044,7 @@ public class IdcServiceImpl implements IdcService { private Map getData(String messageType,String tableName,Map params,Map whereParams) { List> list = getList(tableName,whereParams); Map map = new HashMap(); - map.put("messageId", UUID.randomUUID().toString().replaceAll("-", "")); + map.put("messageId", CustomUtil.getId()); map.put("messageType", messageType); map.put("apiCode", "common"); map.put("tableName", DBAUtils.tableAliasName(tableName));