From 71c1d1bfb38526eb66e40be19d829adf003495b1 Mon Sep 17 00:00:00 2001 From: hecan <1718492867@qq.com> Date: Fri, 20 Dec 2024 11:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4OA=E5=AF=B9=E6=8E=A5BIP?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...erviceDataDistributePluginInitializer.java | 253 +++++++++++------- .../main/resources/application-hclocal.yml | 6 +- .../service/impl/ComparisonServiceImpl.java | 12 +- .../serviceData/dao/IServiceDataDao.java | 10 + .../dao/impl/ServiceDataDaoImpl.java | 7 + .../serviceData/entity/ServiceDataEntity.xml | 12 + .../service/impl/ServiceDataServiceImpl.java | 2 +- 7 files changed, 193 insertions(+), 109 deletions(-) diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/serviceData/plugin/ServiceDataDistributePluginInitializer.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/serviceData/plugin/ServiceDataDistributePluginInitializer.java index a103bdb1..f4de7c1a 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/serviceData/plugin/ServiceDataDistributePluginInitializer.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/serviceData/plugin/ServiceDataDistributePluginInitializer.java @@ -135,17 +135,30 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ String id = requestJson.getString("integration_task_living_details_id"); //执行重新发送 if (StrUtil.isNotEmpty(id)) { + logger.info("========开始执行业务数据下发重推接口,重推id为:{}=======", id); //查询日志表 IntegrationTaskLivingDetailsEntity taskDetailEntity = taskLivingDetailsService.get(id); - if (null != taskDetailEntity && JSONUtil.isTypeJSON(taskDetailEntity.getRootAppPk())){ + if (null != taskDetailEntity && JSONUtil.isTypeJSON(taskDetailEntity.getRootAppPk())) { + + + ServiceDataEntity zt = new ServiceDataEntity(); + zt.setBillCode(taskDetailEntity.getRootAppBill()); + List list = serviceDataDao.queryDataByVdef1(zt); + + if (list == null || list.size() == 0) { + logger.info("重试id:{}该数据下发状态已经为1,不再重推", id); + taskDetailEntity.setResult("发送成功"); + taskLivingDetailsService.saveLogFailToSuccess(taskDetailEntity); + return BaseResult.getFailureMessageEntity("发送成功"); + } else { //拿到这张表的源系统ID JSONObject jsonObject = JSONObject.parseObject(taskDetailEntity.getRootAppPk()); Long mdmCode = jsonObject.getLong("mdmCode");//主数据编码 String documentRule = jsonObject.getString("documentRule");//行数据的单据规则编码 String distributeId = jsonObject.getString("distributeId");//发送表id String type = jsonObject.getString("type");//发送类型,1、新增2、修改3、删除 - if(mdmCode == null || documentRule == null || distributeId == null || type == null - || "".equals(mdmCode) || "".equals(documentRule) || "".equals(distributeId) || "".equals(type)){ + if (mdmCode == null || documentRule == null || distributeId == null || type == null + || "".equals(mdmCode) || "".equals(documentRule) || "".equals(distributeId) || "".equals(type)) { taskDetailEntity.setResult("系统保存参数错误"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("系统保存参数错误"); @@ -156,7 +169,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ //获取主数据信息 MdmModuleEntity mdmModuleEntity = mdmServiceCache.getMdmModuleEntity(mdmCode); - if(mdmModuleEntity == null || mdmModuleEntity.getId() == null ){ + if (mdmModuleEntity == null || mdmModuleEntity.getId() == null) { taskDetailEntity.setResult("主数据不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("主数据不存在"); @@ -167,7 +180,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity(); mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId()); List mdmModuleDbEntities = mdmServiceCache.queryMdmModuleDb(mdmModuleDbEntity); - if(mdmModuleDbEntities == null || mdmModuleDbEntities.size() == 0){ + if (mdmModuleDbEntities == null || mdmModuleDbEntities.size() == 0) { taskDetailEntity.setResult("主数据数据源不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("主数据数据源不存在"); @@ -177,20 +190,20 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ //获取分发表 //获取分发的接口 MdmModuleDistributeEntity mdmModuleDistributeEntity = mdmModuleDistributeDao.get(distributeId); - if(mdmModuleDistributeEntity == null || mdmModuleDistributeEntity.getId() == null ){ + if (mdmModuleDistributeEntity == null || mdmModuleDistributeEntity.getId() == null) { taskDetailEntity.setResult("分发不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发不存在"); } // 启用停用 0、停用 - if("0".equals(mdmModuleDistributeEntity.getEnabledState())){ + if ("0".equals(mdmModuleDistributeEntity.getEnabledState())) { taskDetailEntity.setResult("分发已停用"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发已停用"); } - MdmModuleDistributeDetailEntity mdmModuleDistributeDetailEntity = new MdmModuleDistributeDetailEntity() ; + MdmModuleDistributeDetailEntity mdmModuleDistributeDetailEntity = new MdmModuleDistributeDetailEntity(); mdmModuleDistributeDetailEntity.setDistributeId(distributeId); mdmModuleDistributeDetailEntity.setSts("Y"); List mdmModuleDistributeDetailEntities = mdmModuleDistributeDetailDao.queryBase(mdmModuleDistributeDetailEntity); @@ -202,41 +215,41 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ // return BaseResult.getFailureMessageEntity("分发为手动下发"); //} //1、新增2、修改3、删除 - if("1".equals(type)){ + if ("1".equals(type)) { apiId = mdmModuleDistributeEntity.getAddApi(); scriptId = mdmModuleDistributeEntity.getAddScript(); - }else if("2".equals(type)){ + } else if ("2".equals(type)) { apiId = mdmModuleDistributeEntity.getUpdateApi(); scriptId = mdmModuleDistributeEntity.getUpdateScript(); - }else if("3".equals(type)){ + } else if ("3".equals(type)) { apiId = mdmModuleDistributeEntity.getDeleteApi(); scriptId = mdmModuleDistributeEntity.getDeleteScript(); } - if(apiId == null || "".equals(apiId)){ + if (apiId == null || "".equals(apiId)) { taskDetailEntity.setResult("分发接口未选择,请先选择"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发接口未选择,请先选择"); } SysApplicationScriptEntity scriptEntity = null; - if(scriptId != null && !"".equals(scriptId)){ + if (scriptId != null && !"".equals(scriptId)) { scriptEntity = sysApplicationScriptDao.get(scriptId); - if(scriptEntity == null || scriptEntity.getId() == null ){ + if (scriptEntity == null || scriptEntity.getId() == null) { taskDetailEntity.setResult("分发接口脚本不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发接口脚本不存在"); } } SysApplicationApiEntity apiEntity = sysApplicationApiDao.get(apiId); - if(apiEntity == null || apiEntity.getId() == null ){ + if (apiEntity == null || apiEntity.getId() == null) { taskDetailEntity.setResult("分发接口不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发接口不存在"); } SysApplicationEntity sysApplicationEntity = sysApplicationDao.get(apiEntity.getAppId()); - if(sysApplicationEntity == null || sysApplicationEntity.getId() == null ){ + if (sysApplicationEntity == null || sysApplicationEntity.getId() == null) { taskDetailEntity.setResult("应用不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("应用不存在"); @@ -251,50 +264,58 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ queryFildRule.setRuleCode("service"); List mdmModuleDbFiledsRuleEntities = mdmModuleDbFiledsRuleDao.queryBase(queryFildRule); + String mainDb = null; + String mainId = null; + //获取主数据db对应的实体表的数据 JSONObject object = new JSONObject(); for (int i = 0; i < mdmModuleDbEntities.size(); i++) { - if("1".equals(mdmModuleDbEntities.get(i).getDbType())){ - Map map = new HashMap<>(); - map.put("tableName",mdmModuleDbEntities.get(i).getDbName()); - map.put("documentRule",documentRule); + if ("1".equals(mdmModuleDbEntities.get(i).getDbType())) { + + mainDb = mdmModuleDbEntities.get(i).getDbName(); + + + Map map = new HashMap<>(); + map.put("tableName", mdmModuleDbEntities.get(i).getDbName()); + map.put("documentRule", documentRule); object = mdmModuleDao.queryMdmST(map); object = toLowerCaseKeys(object); - if(object.getString("id") == null || "".equals(object.getString("id")) ){ + mainId = object.getString("id"); + if (object.getString("id") == null || "".equals(object.getString("id"))) { taskDetailEntity.setResult("当前数据不存在"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("当前数据不存在"); } - if(mdmModuleDistributeDetailEntities != null && mdmModuleDistributeDetailEntities.size() > 0){ - Map checkData = new HashMap<>(); - checkData.put("tableName",mdmModuleDbEntities.get(i).getDbName()); - checkData.put("documentRule",documentRule); - checkData.put("mdmModuleDistributeDetailEntities",mdmModuleDistributeDetailEntities); + if (mdmModuleDistributeDetailEntities != null && mdmModuleDistributeDetailEntities.size() > 0) { + Map checkData = new HashMap<>(); + checkData.put("tableName", mdmModuleDbEntities.get(i).getDbName()); + checkData.put("documentRule", documentRule); + checkData.put("mdmModuleDistributeDetailEntities", mdmModuleDistributeDetailEntities); JSONObject object1 = mdmModuleDao.queryMdmST(checkData); object1 = toLowerCaseKeys(object1); - if(object1.getString("id") == null || "".equals(object1.getString("id")) ){ + if (object1.getString("id") == null || "".equals(object1.getString("id"))) { taskDetailEntity.setResult("当前数据不符合规则不发送"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("当前数据不符合规则不发送"); } } //查看主表是否有字段是关联的 - if(mdmModuleDbFiledsRuleEntities != null && mdmModuleDbFiledsRuleEntities.size() > 0){ + if (mdmModuleDbFiledsRuleEntities != null && mdmModuleDbFiledsRuleEntities.size() > 0) { for (int i1 = 0; i1 < mdmModuleDbFiledsRuleEntities.size(); i1++) { - if(mdmModuleDbFiledsRuleEntities.get(i1).getDbId().equals(mdmModuleDbEntities.get(i).getId())){ - if(mdmModuleDbFiledsEntities != null && mdmModuleDbFiledsEntities.size() > 0){ + if (mdmModuleDbFiledsRuleEntities.get(i1).getDbId().equals(mdmModuleDbEntities.get(i).getId())) { + if (mdmModuleDbFiledsEntities != null && mdmModuleDbFiledsEntities.size() > 0) { for (int i2 = 0; i2 < mdmModuleDbFiledsEntities.size(); i2++) { - if(mdmModuleDbFiledsRuleEntities.get(i1).getFiledId().equals(mdmModuleDbFiledsEntities.get(i2).getId())){ - if(object.getString(mdmModuleDbFiledsEntities.get(i2).getEnName()) != null){ - Map mapDetail = new HashMap<>(); - mapDetail.put("tableName",mdmModuleDbFiledsRuleEntities.get(i1).getRuleValue()); - String ids = object.getString(mdmModuleDbFiledsEntities.get(i2).getEnName()); + if (mdmModuleDbFiledsRuleEntities.get(i1).getFiledId().equals(mdmModuleDbFiledsEntities.get(i2).getId())) { + if (object.getString(mdmModuleDbFiledsEntities.get(i2).getEnName()) != null) { + Map mapDetail = new HashMap<>(); + mapDetail.put("tableName", mdmModuleDbFiledsRuleEntities.get(i1).getRuleValue()); + String ids = object.getString(mdmModuleDbFiledsEntities.get(i2).getEnName()); String[] idss = ids.split(","); - mapDetail.put("id", idss[idss.length-1]); + mapDetail.put("id", idss[idss.length - 1]); JSONObject objectDetail = mdmModuleDao.queryMdmST(mapDetail); objectDetail = toLowerCaseKeys(objectDetail); - object.put(mdmModuleDbFiledsEntities.get(i2).getEnName(),objectDetail); + object.put(mdmModuleDbFiledsEntities.get(i2).getEnName(), objectDetail); } } } @@ -306,33 +327,33 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ } for (int i = 0; i < mdmModuleDbEntities.size(); i++) { - if("2".equals(mdmModuleDbEntities.get(i).getDbType())){ - Map map = new HashMap<>(); - map.put("tableName",mdmModuleDbEntities.get(i).getDbName()); - map.put("formmainId",object.getString("id")); + if ("2".equals(mdmModuleDbEntities.get(i).getDbType())) { + Map map = new HashMap<>(); + map.put("tableName", mdmModuleDbEntities.get(i).getDbName()); + map.put("formmainId", object.getString("id")); List detail = mdmModuleDao.queryMdmSTDetail(map); detail = toLowerCaseKeys(detail); //查看主表是否有字段是关联的 - if(detail != null && detail.size() > 0){ - if(mdmModuleDbFiledsRuleEntities != null && mdmModuleDbFiledsRuleEntities.size() > 0){ + if (detail != null && detail.size() > 0) { + if (mdmModuleDbFiledsRuleEntities != null && mdmModuleDbFiledsRuleEntities.size() > 0) { for (int i1 = 0; i1 < mdmModuleDbFiledsRuleEntities.size(); i1++) { - if(mdmModuleDbFiledsRuleEntities.get(i1).getDbId().equals(mdmModuleDbEntities.get(i).getId())){ - if(mdmModuleDbFiledsEntities != null && mdmModuleDbFiledsEntities.size() > 0){ + if (mdmModuleDbFiledsRuleEntities.get(i1).getDbId().equals(mdmModuleDbEntities.get(i).getId())) { + if (mdmModuleDbFiledsEntities != null && mdmModuleDbFiledsEntities.size() > 0) { for (int i2 = 0; i2 < mdmModuleDbFiledsEntities.size(); i2++) { - if(mdmModuleDbFiledsRuleEntities.get(i1).getFiledId().equals(mdmModuleDbFiledsEntities.get(i2).getId())){ + if (mdmModuleDbFiledsRuleEntities.get(i1).getFiledId().equals(mdmModuleDbFiledsEntities.get(i2).getId())) { for (int i3 = 0; i3 < detail.size(); i3++) { - if(detail.get(i3).getString(mdmModuleDbFiledsEntities.get(i2).getEnName()) != null){ - Map mapDetail = new HashMap<>(); - mapDetail.put("tableName",mdmModuleDbFiledsRuleEntities.get(i1).getRuleValue()); + if (detail.get(i3).getString(mdmModuleDbFiledsEntities.get(i2).getEnName()) != null) { + Map mapDetail = new HashMap<>(); + mapDetail.put("tableName", mdmModuleDbFiledsRuleEntities.get(i1).getRuleValue()); String ids = detail.get(i3).getString(mdmModuleDbFiledsEntities.get(i2).getEnName()); String[] idss = ids.split(","); - mapDetail.put("id", idss[idss.length-1]); + mapDetail.put("id", idss[idss.length - 1]); JSONObject objectDetail = mdmModuleDao.queryMdmST(mapDetail); objectDetail = toLowerCaseKeys(objectDetail); - detail.get(i3).put(mdmModuleDbFiledsEntities.get(i2).getEnName(),objectDetail); + detail.get(i3).put(mdmModuleDbFiledsEntities.get(i2).getEnName(), objectDetail); } } @@ -343,16 +364,18 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ } } } - object.put(mdmModuleDbEntities.get(i).getDbName(),detail); + object.put(mdmModuleDbEntities.get(i).getDbName(), detail); } } + + logger.info("=========开始执行业务数据下发重试脚本,第一次=========="); //执行脚本 JSONObject groovy = new JSONObject(); JSONObject parameterJson = new JSONObject(); - parameterJson.put("header",apiEntity.getHeaderIn()); - parameterJson.put("body",apiEntity.getBodyIn()); - parameterJson.put("query",apiEntity.getQueryIn()); - parameterJson.put("data",object); + parameterJson.put("header", apiEntity.getHeaderIn()); + parameterJson.put("body", apiEntity.getBodyIn()); + parameterJson.put("query", apiEntity.getQueryIn()); + parameterJson.put("data", object); if (!"1".equals(type)) {//删除或者修改情况,查询三方id,有就设置,没有就设置空 //1、根据主数据id、数据id、应用ID默认查询主数据应用下发三方id表,只查询最新的一条数据 @@ -363,7 +386,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ mdmModuleDistributeTripartiteEntity.setAppId(sysApplicationEntity.getId()); mdmModuleDistributeTripartiteEntity = mdmModuleDistributeTripartiteDao.queryOneTripartite(mdmModuleDistributeTripartiteEntity); String tripartiteId = ""; - if(mdmModuleDistributeTripartiteEntity != null && mdmModuleDistributeTripartiteEntity.getTripartiteId() != null ){ + if (mdmModuleDistributeTripartiteEntity != null && mdmModuleDistributeTripartiteEntity.getTripartiteId() != null) { tripartiteId = mdmModuleDistributeTripartiteEntity.getTripartiteId(); } parameterJson.put("tripartiteId", tripartiteId); @@ -374,35 +397,36 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ String querys = null; /** body */ String bodys = object.toJSONString(); - if(scriptEntity != null && scriptEntity.getId() != null ){ - groovy.put("code",scriptEntity.getScriptCode()); - groovy.put("className",scriptEntity.getClassName()); - groovy.put("name",scriptEntity.getScriptName()); - groovy.put("methodStr",scriptEntity.getScriptData()); - groovy.put("parameterJson",parameterJson); + if (scriptEntity != null && scriptEntity.getId() != null) { + groovy.put("code", scriptEntity.getScriptCode()); + groovy.put("className", scriptEntity.getClassName()); + groovy.put("name", scriptEntity.getScriptName()); + groovy.put("methodStr", scriptEntity.getScriptData()); + groovy.put("parameterJson", parameterJson); JSONObject groovyStr = new JSONObject(); - groovyStr.put("jsonStr",groovy); + groovyStr.put("jsonStr", groovy); try { Object str = groovyIntegrationService.groovyScriptExecution(groovyStr); JSONObject jsonResultEntity = JSONObject.parseObject(str.toString()); header = (Map) jsonResultEntity.get("header"); querys = jsonResultEntity.getString("querys"); bodys = jsonResultEntity.getString("bodys"); - }catch (Exception e){ + } catch (Exception e) { taskDetailEntity.setResult("分发脚本转换错误"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("分发脚本转换错误"); } } Map headers = new HashMap<>(); - headers.put("publicKey","ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj"); - headers.put("secretKey","fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA="); - headers.put("appId",sysApplicationEntity.getAppId().toString()); - headers.put("apiCode",apiEntity.getApiCode().toString()); - if(header != null){ + headers.put("publicKey", "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj"); + headers.put("secretKey", "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA="); + headers.put("appId", sysApplicationEntity.getAppId().toString()); + headers.put("apiCode", apiEntity.getApiCode().toString()); + if (header != null) { headers.putAll(header); } if (SysEnum.NEED_LOGIN.getValue().equals(apiEntity.getNeedLogin())) { + logger.info("========业务数据下发重试开始执行登录接口=========="); //找到登陆接口 SysApplicationApiEntity loginApi = sysApplicationApiDao.get(apiEntity.getAuthenticationPort()); if (null == loginApi) { @@ -410,46 +434,50 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("发送错误,认证接口不存在"); } - String rzquerys = getQuery(loginApi,null,null); + String rzquerys = getQuery(loginApi, null, null); Map headersa = new HashMap<>(); headersa.put("publicKey", "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj"); headersa.put("secretKey", "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA="); headersa.put("appId", sysApplicationEntity.getAppId().toString()); headersa.put("apiCode", loginApi.getApiCode().toString()); - Map rzheaders = getHeaders(loginApi,headersa,null); - String rzbodys = getBodys(loginApi,null,null); - JsonResultEntity rzjsonResultEntity = sendData(loginApi,rzheaders,rzbodys,rzquerys); + Map rzheaders = getHeaders(loginApi, headersa, null); + String rzbodys = getBodys(loginApi, null, null); + JsonResultEntity rzjsonResultEntity = sendData(loginApi, rzheaders, rzbodys, rzquerys); if (!rzjsonResultEntity.isFlag()) { taskDetailEntity.setResult("发送错误,认证接口错误"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); - return BaseResult.getFailureMessageEntity("发送错误:"+rzjsonResultEntity.getMsg()); + return BaseResult.getFailureMessageEntity("发送错误:" + rzjsonResultEntity.getMsg()); } JSONObject attritube = JSONObject.parseObject(rzjsonResultEntity.getAttribute().toString()); - logger.info("认证接口返回信息:"+ attritube.toJSONString()); - querys = getQuery(apiEntity,querys,attritube); - headers = getHeaders(apiEntity,headers,attritube); + logger.info("=======业务数据下发重试登录返回数据:{}========", attritube.toJSONString()); + logger.info("认证接口返回信息:" + attritube.toJSONString()); + querys = getQuery(apiEntity, querys, attritube); + headers = getHeaders(apiEntity, headers, attritube); - bodys = getBodys(apiEntity,bodys,attritube); + bodys = getBodys(apiEntity, bodys, attritube); } + logger.info("=========开始执行业务数据下发重试脚本,第二次=========="); //组装数据发送 - JsonResultEntity jsonResultEntity = sendData(apiEntity,headers,bodys,querys); - if(jsonResultEntity.isFlag()){ + JsonResultEntity jsonResultEntity = sendData(apiEntity, headers, bodys, querys); + logger.info("=====业务数据下发重试调用BIP付款申请返回结果为:{}", JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString()); + if (jsonResultEntity.isFlag()) { if ("1".equals(type)) {//保存三方返回id - if (scriptEntity != null && scriptEntity.getId() != null && scriptEntity.getBackScriptData() != null ) { + if (scriptEntity != null && scriptEntity.getId() != null && scriptEntity.getBackScriptData() != null) { + logger.info("========开始执行业务数据下发重试返回脚本============="); JSONObject backScriptJson = new JSONObject(); backScriptJson.put("data", jsonResultEntity.getAttribute()); - groovy.put("code", scriptEntity.getScriptCode()+"back"); - groovy.put("className", scriptEntity.getClassName()+"back"); - groovy.put("name", scriptEntity.getScriptName()+"back"); + groovy.put("code", scriptEntity.getScriptCode() + "back"); + groovy.put("className", scriptEntity.getClassName() + "back"); + groovy.put("name", scriptEntity.getScriptName() + "back"); groovy.put("methodStr", scriptEntity.getBackScriptData()); groovy.put("parameterJson", backScriptJson); JSONObject groovyStr = new JSONObject(); groovyStr.put("jsonStr", groovy); try { Object str = groovyIntegrationService.groovyScriptExecution(groovyStr); - if(str != null){ + if (str != null) { JSONObject backJsonResultEntity = JSONObject.parseObject(str.toString()); - if(backJsonResultEntity != null && backJsonResultEntity.getString("success") != null && "true".equals(backJsonResultEntity.getString("success"))){ + if (backJsonResultEntity != null && backJsonResultEntity.getString("success") != null && "true".equals(backJsonResultEntity.getString("success"))) { MdmModuleDistributeTripartiteEntity mdmModuleDistributeTripartiteEntity = new MdmModuleDistributeTripartiteEntity(); mdmModuleDistributeTripartiteEntity.setCreate(); mdmModuleDistributeTripartiteEntity.setMdmId(mdmModuleEntity.getId()); @@ -461,26 +489,27 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ JSONObject jsonObjectBody = JSONObject.parseObject(bodys); String parent = jsonObjectBody.getString("parent"); JSONObject jsonObjectParent = JSONObject.parseObject(parent); - ServiceDataEntity serviceDataEntity=new ServiceDataEntity(); + ServiceDataEntity serviceDataEntity = new ServiceDataEntity(); serviceDataEntity.setBillCode(jsonObjectParent.getString("vdef1")); serviceDataEntity.setDataSourceCode("SW-OA"); + logger.info("========业务数据下发重试中开始根据单据编号:{}查询数据=============", jsonObjectParent.getString("vdef1")); List query = serviceDataDao.query(serviceDataEntity); - if(CollectionUtils.isNotEmpty(query)){ - logger.info("===下发时候,开始根据OA单据编号:{}更新BIP付款申请单号:{}",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); + if (CollectionUtils.isNotEmpty(query)) { + logger.info("===重试下发时候,开始根据OA单据编号:{}更新BIP付款申请单号:{}", jsonObjectParent.getString("vdef1"), backJsonResultEntity.getString("vbillno")); serviceDataEntity.setTabName(query.get(0).getTabName()); serviceDataEntity.setBipPaymentNumberField(query.get(0).getBipPaymentNumberField()); - serviceDataEntity.setBipPaymentNumber(query.get(0).getBipPaymentNumber()); + serviceDataEntity.setBipPaymentNumber(backJsonResultEntity.getString("vbillno")); serviceDataEntity.setId(query.get(0).getId()); serviceDataDao.updateBipPaymentNumber(serviceDataEntity); - logger.info("===下发时候,根据OA单据编号:{}更新BIP付款申请单号:{}完毕",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); - }else{ - logger.info("======下发时候根据单据编号:{}未能在三维OA查询到数据,Bip付款申请单号不回写",jsonObjectParent.getString("vdef1")); + logger.info("===重试下发时候,根据OA单据编号:{}更新BIP付款申请单号:{}完毕", jsonObjectParent.getString("vdef1"), backJsonResultEntity.getString("vbillno")); + } else { + logger.info("======重试下发时候根据单据编号:{}未能在三维OA查询到数据,Bip付款申请单号不回写", jsonObjectParent.getString("vdef1")); } } } } catch (Exception e) { - logger.info("执行异常错误原因:"+e); - logger.error("新增返回脚本解析保存三方id错误"+jsonResultEntity.getAttribute()); + logger.info("执行异常错误原因:" + e); + logger.error("新增返回脚本解析保存三方id错误" + jsonResultEntity.getAttribute()); taskDetailEntity.setResult("新增返回脚本解析保存三方id错误"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("发送错误"); @@ -489,15 +518,26 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ } taskDetailEntity.setResult("发送成功"); taskLivingDetailsService.saveLogFailToSuccess(taskDetailEntity); + + logger.info("=======业务数据重试完毕,开始根据id:{},表名称:{}更新新增下发状态============", mainId, mainDb); + if (StrUtil.isNotEmpty(mainId)) { + Map updateMap = new HashMap<>(); + updateMap.put("tableName", mainDb); + updateMap.put("addStatus", "1"); + updateMap.put("id", mainId); + mdmModuleDao.updateMdmSTs(updateMap); + } + return BaseResult.getFailureMessageEntity("发送成功"); - }else { + } else { taskDetailEntity.setResult("发送错误"); taskLivingDetailsService.updateLogFailToSuccess(taskDetailEntity); return BaseResult.getFailureMessageEntity("发送错误"); } } + } }else {//执行正常下发 - + logger.info("==========开始执行正常业务数据下发============="); //查询主数据 MdmModuleEntity queryMdmModuleEntity = new MdmModuleEntity(); queryMdmModuleEntity.setSts("Y"); @@ -1030,7 +1070,6 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ continue; } getDetailData(mdmModuleDbEntities,doObjects.get(i),mdmModuleDbFiledsRuleEntities,mdmModuleDbFiledsEntities); - //执行脚本 JSONObject groovy = new JSONObject(); JSONObject parameterJson = new JSONObject(); @@ -1057,6 +1096,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ /** body */ String bodys = doObjects.get(i).toJSONString(); if(scriptEntity != null && scriptEntity.getId() != null ){ + logger.info("=========开始执行正常业务数据下发脚本,第一次=============="); groovy.put("code",scriptEntity.getScriptCode()); groovy.put("className",scriptEntity.getClassName()); groovy.put("name",scriptEntity.getScriptName()); @@ -1084,7 +1124,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ headers.putAll(header); } if (SysEnum.NEED_LOGIN.getValue().equals(apiEntity.getNeedLogin())) { - + logger.info("=========正常业务数据开始执行登录接口=============="); //找到登陆接口 SysApplicationApiEntity loginApi = sysApplicationApiDao.get(apiEntity.getAuthenticationPort()); if (null == loginApi) { @@ -1105,15 +1145,19 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ continue; } JSONObject attritube = JSONObject.parseObject(rzjsonResultEntity.getAttribute().toString()); + logger.info("=======业务数据正常下发登录返回数据:{}========",attritube.toJSONString()); querys = getQuery(apiEntity,querys,attritube); headers = getHeaders(apiEntity,headers,attritube); bodys = getBodys(apiEntity,bodys,attritube); } //组装数据发送 + logger.info("=========开始执行正常业务数据下发脚本,第二次=============="); JsonResultEntity jsonResultEntity = sendData(apiEntity,headers,bodys,querys); + logger.info("=====业务数据下发重试调用BIP付款申请返回结果为:{}",JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString()); if(jsonResultEntity.isFlag()){ if (scriptEntity != null && scriptEntity.getId() != null && scriptEntity.getBackScriptData() != null ) { + logger.info("=========开始执行正常业务返回脚本=============="); JSONObject backScriptJson = new JSONObject(); backScriptJson.put("data", jsonResultEntity.getAttribute()); groovy.put("code", scriptEntity.getScriptCode()+"back"); @@ -1149,17 +1193,18 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ ServiceDataEntity serviceDataEntity=new ServiceDataEntity(); serviceDataEntity.setBillCode(jsonObjectParent.getString("vdef1")); serviceDataEntity.setDataSourceCode("SW-OA"); + logger.info("========正常业务数据下发开始根据单据编号:{}查询数据==========",jsonObjectParent.getString("vdef1")); List query = serviceDataDao.query(serviceDataEntity); if(CollectionUtils.isNotEmpty(query)){ - logger.info("===下发时候,开始根据OA单据编号:{}更新BIP付款申请单号:{}",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); + logger.info("===正常下发时候,开始根据OA单据编号:{}更新BIP付款申请单号:{}",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); serviceDataEntity.setTabName(query.get(0).getTabName()); serviceDataEntity.setBipPaymentNumberField(query.get(0).getBipPaymentNumberField()); serviceDataEntity.setBipPaymentNumber(backJsonResultEntity.getString("vbillno")); serviceDataEntity.setId(query.get(0).getId()); serviceDataDao.updateBipPaymentNumber(serviceDataEntity); - logger.info("===下发时候,根据OA单据编号:{}更新BIP付款申请单号:{}完毕",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); + logger.info("===正常下发时候,根据OA单据编号:{}更新BIP付款申请单号:{}完毕",jsonObjectParent.getString("vdef1"),backJsonResultEntity.getString("vbillno")); }else{ - logger.info("======下发时候根据单据编号:{}未能在三维OA查询到数据,Bip付款申请单号不回写",jsonObjectParent.getString("vdef1")); + logger.info("======正常下发时候根据单据编号:{}未能在三维OA查询到数据,Bip付款申请单号不回写",jsonObjectParent.getString("vdef1")); } } } @@ -1235,7 +1280,7 @@ public class ServiceDataDistributePluginInitializer extends PluginBaseEntity{ aa.put("distributeId",distributeId);//发送表id aa.put("type",option_type);//发送类型,1、新增2、修改3、删除 integrationTaskLivingDetailsEntity.setRootAppPk(aa.toJSONString()); - integrationTaskLivingDetailsEntity.setRootAppBill(jsonObject.getString("document_rule")); + integrationTaskLivingDetailsEntity.setRootAppBill(jsonObject.getString("vdef1")); integrationTaskLivingDetailsEntity.setPluginId("ServiceDataDistributePluginInitializer"); integrationTaskLivingDetailsEntity.setRootAppNewData(source_data); integrationTaskLivingDetailsEntity.setNewTransmitInfo(remark); diff --git a/base-buildpackage/src/main/resources/application-hclocal.yml b/base-buildpackage/src/main/resources/application-hclocal.yml index 48ed126d..f799a70d 100644 --- a/base-buildpackage/src/main/resources/application-hclocal.yml +++ b/base-buildpackage/src/main/resources/application-hclocal.yml @@ -3,7 +3,7 @@ logging: #日志级别 指定目录级别 level: root: info - encodings: UTF-8 + encodings: GBK file: # 日志保存路径 path: D:\yongansystem\kangarooDataCenter\v3\logs @@ -16,7 +16,7 @@ spring: # username: root # password: bd993088e8a7c3dc5f44441617f9b4bf # driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置 - url: jdbc:mysql://ufidahz.com.cn:9014/businesscenter?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true + url: jdbc:mysql://127.0.0.1:3307/businesscenter?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true username: root password: 62e4295b615a30dbf3b8ee96f41c820b driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置 @@ -27,4 +27,4 @@ savefile: # tomcatpath: D:\apache-tomcat-9.0.69\webapps\kangarooDataCenter\WEB-INF\classes\ tomcatpath: /home/webservice/zt/tomcatV3/webapps/kangarooDataCenterV3/WEB-INF/classes/ zt: - url: http://127.0.0.1:8901/kangarooDataCenterV3/entranceController/externalCallInterface + url: http://127.0.0.1:9011/kangarooDataCenterV3/entranceController/externalCallInterface diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/service/impl/ComparisonServiceImpl.java b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/service/impl/ComparisonServiceImpl.java index a4948dd0..781a325d 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/service/impl/ComparisonServiceImpl.java +++ b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/service/impl/ComparisonServiceImpl.java @@ -170,7 +170,7 @@ public class ComparisonServiceImpl extends BaseService JSONObject jsonObjectMain=new JSONObject(); JSONArray jsonArray=new JSONArray(); List arrayList=new ArrayList<>(); - + logger.info("=========通用新增接口中获取主表和明细表信息完成==============="); String tableName=null; //根据dbtype和dbname分组,拿到表名称和表类型 Map>> collect = comparisonEntities.stream().collect(Collectors.groupingBy(ComparisonEntity::getDbName, Collectors.groupingBy(ComparisonEntity::getDbType))); @@ -187,6 +187,7 @@ public class ComparisonServiceImpl extends BaseService if(main!=null){ jsonObjectMain = JSONObject.parseObject(main); if(!checkStr(jsonObjectMain.getString("data_id"))){ + logger.info("=======新增时候主表data_id不能为空============"); //保存操作日志 controlsLogDaoimpl.saveControlsLog(uuid,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),tableName+"_option_log","2"); return BaseResult.getFailureMessageEntity("新增时候主表data_id不能为空"); @@ -201,6 +202,7 @@ public class ComparisonServiceImpl extends BaseService JSONObject jsonObjectDetails = jsonArray.getJSONObject(i); jsonObjectDetails.put("table_name", keyPair.getKey()); if(!checkStr(jsonObjectDetails.getString("data_id"))){ + logger.info("=======新增时候明细data_id不能为空============"); //保存操作日志 controlsLogDaoimpl.saveControlsLog(uuid,jsonObject.getString("appName"),jsonObject.getString("appCode"),jsonObject.toJSONString(),"接口新增",jsonObject.getString("optionName"),tableName+"_option_log","2"); return BaseResult.getFailureMessageEntity("新增时候明细data_id不能为空"); @@ -210,6 +212,8 @@ public class ComparisonServiceImpl extends BaseService } } } + logger.info("=========根据dbtype和dbname分组,拿到表名称和表类型完成==============="); + if(jsonObjectMain!=null && jsonObjectMain.size()>0) { Map map = new HashMap<>();//将主表数据存到map中 List>> mapDetails = new ArrayList<>();//将子表数据存到map中 @@ -412,6 +416,7 @@ public class ComparisonServiceImpl extends BaseService logger.info("根据主数据编码查询信息错误:{}",e.getMessage()); return BaseResult.getFailureMessageEntity("更新失败"); } + logger.info("=========通用更新接口中获取主表和明细表信息完成==============="); JSONObject jsonObjectMain=new JSONObject(); JSONArray jsonArray=new JSONArray(); List arrayList=new ArrayList<>(); @@ -790,6 +795,7 @@ public class ComparisonServiceImpl extends BaseService //根据主数据编码获取主表和明细表表名称,表字段信息 public List getComparisonEntityCache(ComparisonEntity comparison,String type){ + try { List comparisonEntities = new ArrayList<>(); //根据主数据编号获取模板主表 MdmModuleEntity mdmModuleEntity = mdmServiceCache.getMdmModuleEntity(Long.valueOf(comparison.getMdmCode())); @@ -805,6 +811,7 @@ public class ComparisonServiceImpl extends BaseService mdmModuleViewEntity.setMdmId(mdmModuleEntity.getId()); List mdmModuleViewEntities = mdmModuleViewDao.query(mdmModuleViewEntity); + //根据mdm_id查询mdm_module_db的信息 MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity(); mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId()); @@ -891,6 +898,9 @@ public class ComparisonServiceImpl extends BaseService } return comparisonEntities; } + }catch (Exception e){ + logger.info("====通用数据中根据主数据编码获取主表和明细表表名称,表字段信息错误:{}",e.getMessage()); + } return null; } diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/IServiceDataDao.java b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/IServiceDataDao.java index b3a30953..165461c8 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/IServiceDataDao.java +++ b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/IServiceDataDao.java @@ -77,4 +77,14 @@ public interface IServiceDataDao extends IBaseDao { * @Date 2024-12-09 11:56 * **/ Integer updateElectronic(ServiceDataEntity entity); + + /** + * + * @content 根据单据编号查询中台中相关表的下发数据,避免重推时候将所有未下发数据都推送过去 + * @Param + * @Return + * @Author hecan + * @Date 2024-12-19 10:49 + * **/ + List queryDataByVdef1(ServiceDataEntity entity); } diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/impl/ServiceDataDaoImpl.java b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/impl/ServiceDataDaoImpl.java index c870cc31..dc8d734c 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/impl/ServiceDataDaoImpl.java +++ b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/dao/impl/ServiceDataDaoImpl.java @@ -63,8 +63,15 @@ public class ServiceDataDaoImpl extends MybatisGenericDao) super.selectList("queryServiceElectronic",entity); } + @DS("#entity.dataSourceCode") @Override public Integer updateElectronic(ServiceDataEntity entity) { return super.update("updateElectronic",entity); } + + @DS("#entity.dataSourceCode") + @Override + public List queryDataByVdef1(ServiceDataEntity entity) { + return super.query("queryDataByVdef1",entity); + } } diff --git a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/entity/ServiceDataEntity.xml b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/entity/ServiceDataEntity.xml index 99051fda..b763bc6e 100644 --- a/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/entity/ServiceDataEntity.xml +++ b/base-service/src/main/java/com/hzya/frame/sysnew/comparison/serviceData/entity/ServiceDataEntity.xml @@ -55,6 +55,18 @@ + + +