diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java index 12161508..0b3bddcc 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java @@ -114,75 +114,82 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { public AjaxResult syncBuyerMessage(List mdmGmfxxtbReqBOS, String requestBody) { // 存表 List list = new ArrayList<>(); - for (int i = 0; i < mdmGmfxxtbReqBOS.size(); i++) { MdmGmfxxtbReqBO tempMdmGmfxxtbReqBO = mdmGmfxxtbReqBOS.get(i); BuyerEntity entity = new BuyerEntity(); - entity.setId(DistributedKeyMaker.generateShotKey()); - entity.setTaxpayerCode(tempMdmGmfxxtbReqBO.getDESC14()); - entity.setPurchaseName(tempMdmGmfxxtbReqBO.getDESC1()); - String buyerAddress = ""; - buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC22()) ? "" : tempMdmGmfxxtbReqBO.getDESC22()); - buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC23()) ? "" : tempMdmGmfxxtbReqBO.getDESC23()); - buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC24()) ? "" : tempMdmGmfxxtbReqBO.getDESC24()); - entity.setAddress(buyerAddress); - entity.setPhone(tempMdmGmfxxtbReqBO.getDESC27()); - String bankList = "[]"; // 银行列表 - entity.setMdmMulticodeJson(bankList); - if (tempMdmGmfxxtbReqBO.getMULTICODE() != null && !CollectionUtils.isEmpty(tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST())) { - // 处理开户行银行 - List valuelistBOS = tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST(); - MdmGmfxxtbMulticodeValuelistBO firstValueList = valuelistBOS.get(0); - if (firstValueList != null) { - entity.setBankOfDeposit(firstValueList.getDESC3()); - entity.setBankNumber(firstValueList.getDESC4()); + BuyerEntity buyerEntity = buyerMapper.selectBuyerByCodeOrNameAndNsrsbh(tempMdmGmfxxtbReqBO.getCODE(), "", "-1"); + if(buyerEntity == null){ + log.info("MDM编码数据已存在;{}",tempMdmGmfxxtbReqBO.getCODE()); + entity.setSuccess(false); + if(mdmGmfxxtbReqBOS.size() == 1){ + return AjaxResult.success("9999", "MDM数据已存在,请勿重复同步"); } + } else { + entity.setId(DistributedKeyMaker.generateShotKey()); + entity.setTaxpayerCode(tempMdmGmfxxtbReqBO.getDESC14()); + entity.setPurchaseName(tempMdmGmfxxtbReqBO.getDESC1()); + String buyerAddress = ""; + buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC22()) ? "" : tempMdmGmfxxtbReqBO.getDESC22()); + buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC23()) ? "" : tempMdmGmfxxtbReqBO.getDESC23()); + buyerAddress = buyerAddress.concat(StringUtils.isEmpty(tempMdmGmfxxtbReqBO.getDESC24()) ? "" : tempMdmGmfxxtbReqBO.getDESC24()); + entity.setAddress(buyerAddress); + entity.setPhone(tempMdmGmfxxtbReqBO.getDESC27()); + String bankList = "[]"; // 银行列表 + entity.setMdmMulticodeJson(bankList); + if (tempMdmGmfxxtbReqBO.getMULTICODE() != null && !CollectionUtils.isEmpty(tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST())) { + // 处理开户行银行 + List valuelistBOS = tempMdmGmfxxtbReqBO.getMULTICODE().getVALUELIST(); + MdmGmfxxtbMulticodeValuelistBO firstValueList = valuelistBOS.get(0); + if (firstValueList != null) { + entity.setBankOfDeposit(firstValueList.getDESC3()); + entity.setBankNumber(firstValueList.getDESC4()); + } - List mdmBankListBOS = new ArrayList<>(); - String finalBuyerAddress = buyerAddress; - valuelistBOS.forEach(j -> { - MdmBankListBO temp = new MdmBankListBO(j, finalBuyerAddress, tempMdmGmfxxtbReqBO.getDESC27()); - mdmBankListBOS.add(temp); - }); + List mdmBankListBOS = new ArrayList<>(); + String finalBuyerAddress = buyerAddress; + valuelistBOS.forEach(j -> { + MdmBankListBO temp = new MdmBankListBO(j, finalBuyerAddress, tempMdmGmfxxtbReqBO.getDESC27()); + mdmBankListBOS.add(temp); + }); - bankList = JsonUtils.getInstance().toJsonStringNullToEmpty(mdmBankListBOS); - entity.setMdmMulticodeJson(bankList); - } + bankList = JsonUtils.getInstance().toJsonStringNullToEmpty(mdmBankListBOS); + entity.setMdmMulticodeJson(bankList); + } - entity.setSjh(tempMdmGmfxxtbReqBO.getDESC27()); - entity.setEmail(tempMdmGmfxxtbReqBO.getDESC29()); - // entity.setRemarks(); - entity.setCreateTime(new Date()); // TODO 记得修改Mapper - entity.setModifyTime(new Date()); - entity.setModifyUserId(null); // TODO - entity.setCreateUserId(null); // TODO - String idCardRegex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; - // 税号正则表达式 - String taxNoRegex = "^[a-zA-Z0-9]{15,20}$"; - entity.setGhfQylx(""); - if (StringUtils.isNotEmpty(tempMdmGmfxxtbReqBO.getDESC14())) { - if (tempMdmGmfxxtbReqBO.getDESC14().matches(idCardRegex)) { - entity.setGhfQylx("03"); // 有可能出现个人 + entity.setSjh(tempMdmGmfxxtbReqBO.getDESC27()); + entity.setEmail(tempMdmGmfxxtbReqBO.getDESC29()); + // entity.setRemarks(); + entity.setCreateTime(new Date()); // TODO 记得修改Mapper + entity.setModifyTime(new Date()); + entity.setModifyUserId(null); // TODO + entity.setCreateUserId(null); // TODO + String idCardRegex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; + // 税号正则表达式 + String taxNoRegex = "^[a-zA-Z0-9]{15,20}$"; + entity.setGhfQylx(""); + if (StringUtils.isNotEmpty(tempMdmGmfxxtbReqBO.getDESC14())) { + if (tempMdmGmfxxtbReqBO.getDESC14().matches(idCardRegex)) { + entity.setGhfQylx("03"); // 有可能出现个人 + } + if (tempMdmGmfxxtbReqBO.getDESC14().matches(taxNoRegex)) { + entity.setGhfQylx("01"); + } } - if (tempMdmGmfxxtbReqBO.getDESC14().matches(taxNoRegex)) { - entity.setGhfQylx("01"); + entity.setXhfNsrsbh("-1"); // 如果为-1,代表总表 + entity.setXhfMc(null); + entity.setBuyerCode(tempMdmGmfxxtbReqBO.getCODE()); + entity.setInvoiceName(tempMdmGmfxxtbReqBO.getDESC48()); + entity.setInvoiceTaxno(tempMdmGmfxxtbReqBO.getDESC49()); + // entity.setMdmMulticodeJson(JsonUtils.getInstance().toJsonStringNullToEmpty()); + entity.setUUID(tempMdmGmfxxtbReqBO.getUUID()); + entity.setStatus("0"); + + if (buyerMapper.insertBuyerOnDuplicateKey(entity) > 0) { + entity.setSuccess(true); + } else { + entity.setSuccess(false); } } - entity.setXhfNsrsbh("-1"); // 如果为-1,代表总表 - entity.setXhfMc(null); - entity.setBuyerCode(tempMdmGmfxxtbReqBO.getCODE()); - entity.setInvoiceName(tempMdmGmfxxtbReqBO.getDESC48()); - entity.setInvoiceTaxno(tempMdmGmfxxtbReqBO.getDESC49()); - // entity.setMdmMulticodeJson(JsonUtils.getInstance().toJsonStringNullToEmpty()); - entity.setUUID(tempMdmGmfxxtbReqBO.getUUID()); - entity.setStatus("0"); - - if (buyerMapper.insertBuyerOnDuplicateKey(entity) > 0) { - entity.setSuccess(true); - } else { - entity.setSuccess(false); - } - list.add(entity); } String respStr = ""; @@ -429,7 +436,7 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { "}"; // 发送POST请求 - log.info("[MDM主动同步物料]请求地址:{},请求参数:{}", buyerUrl, requestBody); + log.info("[MDM主动同步物料]请求地址:{},请求参数:{}", groupTaxCodeUrl, requestBody); HttpResponse response = HttpRequest.post(groupTaxCodeUrl) .timeout(20000) // 设置请求超时时间 .header("Content-Type", "application/json") @@ -439,8 +446,13 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { .execute(); String resp = response.body(); log.info("[MDM主动同步物料]响应结果:{}", resp); - + if(StringUtils.isBlank(resp)){ + return R.error("未查询到数据!"); + } SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(resp, SDEnergyMdmBaseBO.class); + if(baseBO == null || baseBO.getESB() == null || "S".equals(baseBO.getESB().getRESULT())){ + return R.error("未查询到数据!"); + } List mdmGmfxxtbReqBOS = (List) Optional.of(baseBO) .map(SDEnergyMdmBaseBO::getESB) .map(ESBBO::getDATA)