From f0a1f253bb5732ed9bf2ef7ba1495d65ba21da1c Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 30 Mar 2023 09:52:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=8B=E5=8F=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E7=BB=9F=E4=B8=80=E7=94=A8=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/idc/controller/IdcController.java | 36 +- .../sale/admin/idc/service/IdcService.java | 4 +- .../idc/service/impl/IdcServiceImpl.java | 370 +++++++++++------- 3 files changed, 239 insertions(+), 171 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java index ee31952..acd78d1 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java @@ -2,36 +2,24 @@ package com.glxp.sale.admin.idc.controller; import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import cn.hutool.core.io.IoUtil; -import com.glxp.sale.admin.idc.service.DownloadRestTemplate; -import lombok.extern.slf4j.Slf4j; -import org.apache.tomcat.util.http.fileupload.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.*; -import org.springframework.http.client.ClientHttpRequest; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RequestCallback; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; @@ -41,6 +29,9 @@ import com.glxp.sale.admin.idc.dao.DbDao; import com.glxp.sale.admin.idc.service.IdcService; import com.glxp.sale.common.res.BaseResponse; +import cn.hutool.core.io.IoUtil; +import lombok.extern.slf4j.Slf4j; + /** * 中继服务接口 @@ -60,19 +51,10 @@ public class IdcController { @RequestParam("content") String content, @RequestParam(value = "files", required = false) MultipartFile[] files) { // - return idcService.receive("U", request, content, files); - } - - /*通用下发接口*/ - //@Log("中继服务数据接收,上级往下级下发") - @RequestMapping(value = "/spssync/common/issued") - public BaseResponse issued(HttpServletRequest request, - @RequestParam("content") String content, - @RequestParam(value = "files", required = false) MultipartFile[] files) { - // - return idcService.receive("I", request, content, files); + return idcService.receive( request, content, files); } + //@Log("数据同步测试") @RequestMapping(value = "/spssync/common/test") public BaseResponse test(HttpServletRequest request, @RequestBody Map params) { diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/IdcService.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/IdcService.java index f532526..9f15813 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/IdcService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/IdcService.java @@ -12,7 +12,7 @@ import com.glxp.sale.common.res.BaseResponse; public interface IdcService { - BaseResponse receive(String direction,HttpServletRequest request, + BaseResponse receive(HttpServletRequest request, String content,MultipartFile[] files); @@ -28,5 +28,7 @@ public interface IdcService { BaseResponse downlaodSuccess(HttpServletRequest request,Map params); public void asyncIdcTask(); + void asyncUdiTask(); + void asyncSpsTask(); } 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 c7a69ea..3535dbf 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 @@ -67,28 +67,19 @@ public class IdcServiceImpl implements IdcService { @Value("${API_SECRET}") private String apiSecret; - /*自助平台->UDI*/ - private final String[] SPMS_TO_UDI_TABLES= { - "basic_udirel/updateTime//耗材字典","basic_products///耗材字典信息详情","company_product_relevance/updateTime//供应商关联信息", - "basic_corp/updateTime//往来单位","thr_bustype_origin/updateTime//第三方单据类型", - "thr_corp/updateTime//第三方往来单位","thr_dept/updateTime//第三方部门", - "thr_inv_products/updateTime//第三方库存","thr_inv_warehouse///第三方仓库", - "thr_order/updateTime//第三方单据","thr_order_detail/updateTime//第三方单据详情", - "thr_products/updateTime//第三方产品信息","sup_cert/updateTime/filePath/资质证书信息", - "sup_cert_set/updateTime//供应商资质证书设置","sup_company/updateTime//配送供应商资质信息", - "sup_manufacturer/updateTime//生产企业资质信息","sup_product/updateTime//产品资质信息"}; - /*UDI->自助平台*/ - private final String[] UDI_TO_SPMS_TABLES= { - "basic_udirel/updateTime//耗材字典","basic_products///耗材字典信息详情","company_product_relevance/updateTime//供应商关联信息", - "basic_corp/updateTime//往来单位","thr_bustype_origin/updateTime//第三方单据类型", - "thr_corp/updateTime//第三方往来单位","thr_dept/updateTime//第三方部门", - "thr_inv_products/updateTime//第三方库存","thr_inv_warehouse///第三方仓库", - "thr_order/updateTime//第三方单据","thr_order_detail/updateTime//第三方单据详情", - "thr_products/updateTime//第三方产品信息","sup_cert/updateTime/filePath/资质证书信息", - "sup_cert_set/updateTime//供应商资质证书设置","sup_company/updateTime//配送供应商资质信息", - "sup_manufacturer/updateTime//生产企业资质信息","sup_product/updateTime//产品资质信息", - "productinfo/updateTime//国家库UDI数据,udicompany/updateTime//国际库医疗器械注册人信息"}; - + /*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/ + private final String[] SYNC_TABLES= { + "entrustAction////////委托验收,basicProducts//basic_udirel///updateTime///耗材字典","/basicProducts/basic_products//////耗材字典信息详情", + "//company_product_relevance///updateTime///供应商关联信息", + "basicCorp//basic_corp///updateTime///往来单位","typeThird//thr_bustype_origin///updateTime///第三方单据类型", + "basicThirdCorp//thr_corp///updateTime///第三方往来单位","//thr_dept///updateTime///第三方部门", + "//thr_inv_products///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse//////第三方仓库", + "basicThirdBusOrder//thr_order///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail///updateTime///第三方单据详情", + "basicThirdProducts//thr_products///updateTime///第三方产品信息","//sup_cert///updateTime/filePath//资质证书信息", + "//sup_cert_set///updateTime///供应商资质证书设置","companyCert//sup_company///updateTime///配送企业", + "manufacturerCert//sup_manufacturer///updateTime///生产企业","productCert//sup_product///updateTime///产品资质信息", + "dbDiProducts//productinfo///updateTime///DI产品信息,//udicompany///updateTime///国际库医疗器械注册人信息"}; + private int orderNum=0; @Resource @@ -121,96 +112,117 @@ public class IdcServiceImpl implements IdcService { return ResultVOUtils.success(object); } + + /*UDI系统上传自助平台*/ + @Override + public void asyncUdiTask() { + asyncDataTask(true); + } + /*自助平台生成任务,不上传*/ + @Override + public void asyncSpsTask() { + asyncDataTask(false); + } + /*拉取前一级中继服务数据*/ @Async @Override public void asyncFetchTask() { - String[] directions = {"I","U"}; - for(String dir:directions) { - Map query = new HashMap(); - String host = getNextHost(dir); - if(!StringUtils.isEmpty(host)) { - String result = post(host+"/spssync/common/list",query); - if(IDCUtils.isJson(result)) { - JSONObject json = JSON.parseObject(result); - if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) { - List list = JSON.parseArray(json.getString("data"), Map.class); - if(list!=null) { - for(Map map:list) { - Map params = new HashMap(); - params.put("taskId", map.get("taskId")); - fetchData(host+"/spssync/common/list",params); - } + + Map query = new HashMap(); + String host = getNextHost(); + if(!StringUtils.isEmpty(host)) { + String result = post(host+"/spssync/common/list",query); + if(IDCUtils.isJson(result)) { + JSONObject json = JSON.parseObject(result); + if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) { + List list = JSON.parseArray(json.getString("data"), Map.class); + if(list!=null) { + for(Map map:list) { + Map params = new HashMap(); + params.put("taskId", map.get("taskId")); + fetchData(host+"/spssync/common/list",params); } } } } } + } @Async @Override public void asyncIdcTask() { initTable(); - String[] tNames= {}; - String direction = getDirection(); - - if(direction.equals("I")) { - tNames = SPMS_TO_UDI_TABLES; - } else if (direction.equals("U")) { - tNames = UDI_TO_SPMS_TABLES; + Map map = dbDao.get("select * from idc_var where code='system_type'"); + if(map==null) { + dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')"); } - /*为顶级或末级,以及下游或上游连通,可执行*/ - Boolean isLastLevel = isLastLevel(direction); - Boolean isRelay = isRelay(direction); - logger.info("-----数据传输任务开始----"+direction+"\n"); - logger.info("-----是否需要上传或下发数据:"+isLastLevel+",是否已配置接收地址:"+isRelay+"----\n"); - if(isLastLevel&&isRelay) { - for(String t:tNames) { - uploadData(t); - } - } - } - private void uploadData(String t) { - String[] tn = t.split("/"); - String lastUpdateTime = getUpdateTime(tn[0]); - Date nowUpdateTime = new Date(); - List> keyList = dbDao.listKeyMysql(tn[0]); - String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id"; - Map map = new HashMap(); - String sqlWhere = "not exists (select fkId from idc_record where type='"+tn[0]+"' and fkId="+tn[0]+"."+keyColumn+")"; - if(!StringUtils.isEmpty(tn[1])) { - sqlWhere+=" and "+tn[1]+">=cast('"+lastUpdateTime+"' as datetime)"; - } else { - map.put("isEnd", "1"); - } - if(tn[0].equals("thr_order")) - logger.info("-------------------"+sqlWhere); - map.put("sqlWhere", sqlWhere); - map.put("tableName", tn[0]); - map.put("filePathColumn", tn[2]); - map.put("messageType", tn[3]); - map.put("messageName", tn[3]); - ScheduledRequest scheduledRequest = new ScheduledRequest(); - scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tn[0], new char[]{'_'}).replace("_", "")); - ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); - String cron = scheduledEntity!=null ? scheduledEntity.getCron() : ""; - boolean send = true; - if(!StringUtils.isEmpty(cron)) { - CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron); - Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime)); - send = nextTimePoint.before(nowUpdateTime); + private void asyncDataTask(boolean isUpload) { + initTable(); + Map map = dbDao.get("select * from sync_data_set limit 1"); + if(map!=null&&map.get("downstreamEnable")!=null&&map.get("downstreamEnable").toString().equals("1")) + for(int i=0;i> keyList = dbDao.listKeyMysql(tnames[2]); + String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id"; + Map map = new HashMap(); + String sqlWhere = "not exists (select fkId from idc_record where type='"+tnames[2]+"' and fkId="+tnames[2]+"."+keyColumn+")"; + if(!StringUtils.isEmpty(tnames[2])) { + sqlWhere+=" and "+tnames[5]+">=cast('"+lastUpdateTime+"' as datetime)"; + } else { + map.put("isEnd", "1"); + } + map.put("sqlWhere", sqlWhere); + map.put("dataWhere", tnames[7]); + map.put("tableKey", tnames[0]); + map.put("tableName", tnames[2]); + map.put("masterLinkColumn", tnames[3]); + map.put("subLinkColumn", tnames[4]); + map.put("filePathColumn", tnames[6]); + map.put("messageType", tnames[8]); + map.put("messageName", tnames[8]); + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", "")); + ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); + String cron = scheduledEntity!=null ? scheduledEntity.getCron() : ""; + + if(!StringUtils.isEmpty(cron)) { + CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron); + Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime)); + sync = nextTimePoint.before(nowUpdateTime); + } + if(sync) { + if(syncMasterData(map,isUpload)) { + setUpdateTime(tnames[2],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss")); + } + } + } } + + private String fetchData(String url,Map params) { OkHttpClient client = new OkHttpClient().newBuilder() @@ -263,9 +275,9 @@ public class IdcServiceImpl implements IdcService { dbDao.update(sql); return ResultVOUtils.success(); } - /*direction方向 U 上传,I 下发,往自助平台为上传,往UDI管理系统为下发*/ + /****/ @Override - public BaseResponse receive(String direction,HttpServletRequest request, + public BaseResponse receive(HttpServletRequest request, String content,MultipartFile[] files) { /*授权检查,后续完善*/ String apiKey = request.getHeader("apiKey"); @@ -303,12 +315,12 @@ public class IdcServiceImpl implements IdcService { } saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName); /*解析入库*/ - if(isLastLevel(direction)) { + if(isLastLevel()) { analyToDB(json,files); } else { //需要转发 - if(isRelay(direction)) { - relay(direction,request.getHeader("reqNo"),content,saveFiles); + if(isRelay()) { + relay(request.getHeader("reqNo"),content,saveFiles); } } return ResultVOUtils.success(); @@ -325,13 +337,7 @@ public class IdcServiceImpl implements IdcService { } @Override public BaseResponse send(String messageType,String tableName,Map params) { - try - { - if(sendOnPage(messageType,tableName,params)) - return ResultVOUtils.success(); - } catch (Exception ex) { - logger.error(ex.getMessage()); - } + return ResultVOUtils.error(9999, ""); } @@ -349,6 +355,20 @@ public class IdcServiceImpl implements IdcService { dbDao.save(sql); } + + private void saveExportStatus(String messageType,String taskId,String fileName) { + 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.put("updateTime", new Date()); + Map columns = getColumn("basic_export_status"); + String sql = "insert into basic_export_status "+DBAUtils.parseInsert(map, columns); + + dbDao.save(sql); + } private void saveDownloadStatus(String messageType,String taskId,String remark) { Map map = new HashMap(); map.put("id", CustomUtil.getId()); @@ -377,29 +397,44 @@ public class IdcServiceImpl implements IdcService { dbDao.save(sql); } - private boolean sendOnPage(String messageType,String tableName,Map params) { + + + private boolean syncMasterData(Map params,boolean isUplaod) { boolean success=false; + String tableName = params.get("tableName").toString(); + String tableKey = params.get("tableKey").toString(); + String[] childs = {}; + int childNum = -1; + for(String str:SYNC_TABLES) { + if(str.contains("/"+tableKey+"/")) { + childNum++; + childs[childNum] = str; + } + } 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 whMap = new HashMap(); + whMap.put("sqlWhere", params.get("sqlWhere")); + whMap.put("dataWhere", params.get("dataWhere")); + Map map = new HashMap(); - String where = DBAUtils.convertWhere(column,params,""); + String where = DBAUtils.convertWhere(column,whMap,""); sql+=!StringUtils.isEmpty(where) ? " where "+where : ""; map.put("sql", sql); int total = dbDao.count(map); - String direction = getDirection(); + String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0"; int limit = 50; String[] files = new String[limit]; String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : ""; orderNum++; + String messageType = params.get("messageType").toString(); saveIdcLog(messageType,"",tableName +">"+where,0,total); - if(tableName.equals("thr_order")) - logger.info("tableName-->"+tableName+"-->row-->"+total+"-->sqlWhere-->"+where); + if(total>0) { success = true; params.put("page", 0); @@ -423,31 +458,65 @@ 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&¶ms.get("masterLinkColumn")!=null&¶ms.get("subLinkColumn")!=null) { + for(int z=0;z childMap = new HashMap<>(); + childMap.put(params.get("subLinkColumn").toString(), keyValue); + List> childList = getList(chidTnames[2],childMap); + list.get(m).put("tableName"+z, chidTnames[2]); + list.get(m).put("data"+z, childList); + } + } } orderNum++; - String result = relay(direction,"",JSON.toJSONString(data),files); - if(IDCUtils.isJson(result)) { - JSONObject json = JSON.parseObject(result); - if(json.getInteger("code")==20000) { - if(!StringUtils.isEmpty(recordSql)) { - dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql); + if(isUplaod) { + String result = relay("",JSON.toJSONString(data),files); + if(IDCUtils.isJson(result)) { + JSONObject json = JSON.parseObject(result); + if(json.getInteger("code")==20000) { + if(!StringUtils.isEmpty(recordSql)) { + dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql); + } + saveDownloadStatus(messageType,json.getString("reqNo"),messageType+" 记录数:"+list.size()+"/"+total); + saveIdcLog(messageType,"",tableName +">success",i *limit,total); + } else { + success = false; + logger.error(result); + saveIdcLog(messageType,"",tableName +">"+result,i *limit,total); } - saveDownloadStatus(messageType,json.getString("reqNo"),messageType+" 记录数:"+list.size()+"/"+total); - saveIdcLog(messageType,"",tableName +">success",i *limit,total); - } else { - success = false; - logger.error(result); - saveIdcLog(messageType,"",tableName +">"+result,i *limit,total); } + } else { + syncAddTask(data); } } } } - } + } + return success; } + + /*增加同步任务*/ + private void syncAddTask(Map json) { + 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.SaveFileAs(content, fileName); + FileUtils.SaveFileAs(content, backFileName); + + + saveExportStatus(json.get("messageType").toString(),json.get("messageId").toString(),fileName); + } + + /*解析到数据库*/ private void analyToDB(JSONObject jsonObject,MultipartFile[] files) { @@ -548,6 +617,18 @@ public class IdcServiceImpl implements IdcService { sql+=")"; n++; } + + for(int m=0;m<6;m++) { + if(list.get(i).get("tableName"+m)!=null&&list.get(i).get("data"+m)!=null) { + Object obj = list.get(i).get("data"+m); + List> chList = new ArrayList>(); + for (Object o : (List) obj) { + chList.add((Map)o); + } + analyData(list.get(i).get("tableName"+m).toString(),chList); + } + } + } if(n>0) dbDao.save(sql); @@ -558,13 +639,13 @@ public class IdcServiceImpl implements IdcService { /*转发下级或上级中继服务*/ - private String relay(String direction,String reqNo,String content,String[] files) { - String host = getNextHost(direction); + private String relay(String reqNo,String content,String[] files) { + String host = getNextHost(); String result=""; if(StringUtils.isEmpty(reqNo)) reqNo = UUID.randomUUID().toString(); if(!StringUtils.isEmpty(host)) { - host+=direction.equals("U") ? "/spssync/common/upload" : "/spssync/common/issued"; + host+="/spssync/common/upload" ; OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间 .readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间 @@ -611,41 +692,38 @@ public class IdcServiceImpl implements IdcService { } /*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/ - private String getNextHost(String direction) { - SystemParamConfigEntity systemParamConfigEntity = - direction.equals("U") ? getSystemParamConfig("upper_server_host","自助平台数据接收服务地址" , "","接收由UDI系统上传的数据") : - direction.equals("I") ? getSystemParamConfig("lower_server_host","UDI系统数据接收服务地址" , "","接收由自助平台下发的数据") : null; + private String getNextHost() { + SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip"); String host = systemParamConfigEntity!=null ? systemParamConfigEntity.getParamValue() : ""; host = !StringUtils.isEmpty(host)&&host.substring(host.length() -1).equals("/") ? host.substring(0,host.length() -1) : host; return host; } - /*判断是否上传或下发数据*/ - private boolean isLastLevel(String direction) { - return direction.equals("I") || direction.equals("U") ? true : false ; + /*判断是否需要解析入库,中继服务只转发*/ + private boolean isLastLevel() { + Map map = dbDao.get("select * from idc_var where code='system_type'"); + return !(map!=null&&map.get("content")!=null&&map.get("content").toString().equals("IDC")) ; } - /*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/ - private String getDirection() { - SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_system_type","系统类型" , "IDC","UDI(UDI管理系统,由UDI系统往自助平台上传数据),SPS(自助平台,由自助平台往UDI系统下发数据),IDC(中继服务,只接收,转发或暂存数据供下一级服务拉取数据)"); - return systemParamConfigEntity.getParamValue().equals("UDI") ? "U" : systemParamConfigEntity.getParamValue().equals("SPS") ? "I" : "N"; - } - + /*是否需要转发*/ - private boolean isRelay(String direction) { - String relayHost = getNextHost(direction); - + private boolean isRelay() { + String relayHost = getNextHost(); return !StringUtils.isEmpty(relayHost); } - /*由表名获取数据*/ - private Map getData(String messageType,String tableName,Map params) { + private List> getList(String tableName,Map params) { String sql = "select "+tableName+".*,'A' as operateMode from "+tableName; Map column = getColumn(tableName); String where = DBAUtils.convertWhere(column,params,""); sql+=!StringUtils.isEmpty(where) ? " where "+where : ""; params.put("sql", sql); List> list = dbDao.list(params); + return list; + } + /*由表名获取数据*/ + private Map getData(String messageType,String tableName,Map params) { + List> list = getList(tableName,params); Map map = new HashMap(); map.put("messageId", UUID.randomUUID().toString().replaceAll("-", "")); map.put("messageType", messageType); @@ -750,10 +828,17 @@ public class IdcServiceImpl implements IdcService { return updateTime; } private void initTable() { + alterTable("idc_var","create table idc_var (code varchar(60),content varchar(200),PRIMARY KEY (code))"); alterTable("idc_status","create table idc_status (id varchar(36),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))"); dbDao.delete("delete from idc_record where createTime map = dbDao.getMysql(tableName); @@ -762,5 +847,4 @@ public class IdcServiceImpl implements IdcService { } } - }