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; + } }