From 8d225280280eef707c98b8981eaa00a8f0dec996 Mon Sep 17 00:00:00 2001 From: 199901012 Date: Sat, 17 Apr 2021 23:43:50 +0800 Subject: [PATCH] =?UTF-8?q?'=E4=BF=AE=E5=A4=8D=E5=9C=B0=E5=8C=BA=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=97=A0=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cweb/controller/HighCouponController.java | 6 +++--- .../controller/HighMerchantStoreController.java | 6 +++--- .../main/java/com/hai/service/CommonService.java | 2 +- .../com/hai/service/impl/CommonServiceImpl.java | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index a6af5a78..40de384a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -77,9 +77,9 @@ public class HighCouponController { @RequestParam(name = "pageSize", required = true) Integer pageSize) { try { - SecRegion region = commonService.getRegionsById(Long.parseLong(regionId)); - if (region != null && region.getParentId() != null) { - BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getParentId().toString()); + SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId)); + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); if (bsCompany != null) { Map map = new HashMap<>(); map.put("companyId", bsCompany.getId()); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java b/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java index 31d81f60..51cf18ff 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java @@ -137,9 +137,9 @@ public class HighMerchantStoreController { @ApiOperation(value = "查询商户列表") public ResponseData getMerchantList(@RequestParam(name = "regionId", required = true) String regionId) { try { - SecRegion region = commonService.getRegionsById(Long.parseLong(regionId)); - if (region != null && region.getParentId() != null) { - BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getParentId().toString()); + SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId)); + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); Map map = new HashMap<>(); map.put("companyId", bsCompany.getId()); map.put("status", 1); diff --git a/hai-service/src/main/java/com/hai/service/CommonService.java b/hai-service/src/main/java/com/hai/service/CommonService.java index 86c4048b..90fd23e5 100644 --- a/hai-service/src/main/java/com/hai/service/CommonService.java +++ b/hai-service/src/main/java/com/hai/service/CommonService.java @@ -161,5 +161,5 @@ public interface CommonService { */ List findByName(String name); - + SecRegion getParentByRegion(Long regionId); } diff --git a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java index 6da4dbe5..aaf99a7d 100644 --- a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java @@ -391,4 +391,18 @@ public class CommonServiceImpl implements CommonService { example.createCriteria().andStatusEqualTo(1).andRegionNameEqualTo(name); return regionMapper.selectByExample(example); } + + @Override + public SecRegion getParentByRegion(Long regionId) { + SecRegion secRegion = getRegionsById(regionId); + if (secRegion != null && secRegion.getParentId() != null) { + while (true) { + secRegion = getRegionsById(secRegion.getParentId()); + if (secRegion.getParentId() == null) { + return secRegion; + } + } + } + return secRegion; + } }