From b84461fb06f698f8f1115c0746eda323105432cb Mon Sep 17 00:00:00 2001 From: Shrey475 Date: Tue, 12 Sep 2023 09:41:48 +0530 Subject: [PATCH] API modification to fetch beneficiaries based on villageId list instead of single Id. (#5) * Modified API to sync beneficiaries based on villageId list instead of a single villageId. --- .../iemr/common/identity/controller/IdentityController.java | 4 ++-- .../java/com/iemr/common/identity/dto/SearchSyncDTO.java | 3 ++- .../java/com/iemr/common/identity/repo/BenMappingRepo.java | 4 ++-- .../com/iemr/common/identity/service/IdentityService.java | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/iemr/common/identity/controller/IdentityController.java b/src/main/java/com/iemr/common/identity/controller/IdentityController.java index 2e82b76..754bfcf 100644 --- a/src/main/java/com/iemr/common/identity/controller/IdentityController.java +++ b/src/main/java/com/iemr/common/identity/controller/IdentityController.java @@ -334,8 +334,8 @@ public class IdentityController { logger.info("IdentityController.getBeneficiary - end"); } catch (Exception e) { - logger.error("error in beneficiary search by Family Id : " + e.getLocalizedMessage()); - response = getErrorResponseString("error in beneficiary search by village Id and last sync date : " + e.getLocalizedMessage(), + logger.error("error in beneficiary search by village Ids and last sync date : " + e.getLocalizedMessage()); + response = getErrorResponseString("error in beneficiary search by village Ids and last sync date : " + e.getLocalizedMessage(), 5000, "failure", ""); } return response; diff --git a/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java b/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java index 1b73aa6..45bf61c 100644 --- a/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java +++ b/src/main/java/com/iemr/common/identity/dto/SearchSyncDTO.java @@ -22,11 +22,12 @@ package com.iemr.common.identity.dto; import lombok.Data; +import java.util.List; @Data public class SearchSyncDTO { private Long lastModifiedDate; - private Integer villageID; + private List villageID; } diff --git a/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java b/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java index 8c2facf..874492a 100644 --- a/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java +++ b/src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java @@ -126,9 +126,9 @@ public List getBenMappingByBenDetailsIds(@Param("benDetailsIds") List< public List getBenMappingByVanSerialNo(@Param("benMapIds") BigInteger benMapIds, @Param("vanID") Integer vanID); - @Query(value = "select m from MBeneficiarymapping m where m.mBeneficiaryaddress.permVillageId = :villageID and " + @Query(value = "select m from MBeneficiarymapping m where m.mBeneficiaryaddress.permVillageId IN :villageIDs and " + "(m.mBeneficiaryaddress.lastModDate > :lastModDate or m.mBeneficiarycontact.lastModDate > :lastModDate " + "or m.mBeneficiarydetail.lastModDate > :lastModDate ) order by m.benMapId Desc") - List findByBeneficiaryDetailsByVillageIDAndLastModifyDate(@Param("villageID") int villageID, @Param("lastModDate") Timestamp lastModifiedDate); + List findByBeneficiaryDetailsByVillageIDAndLastModifyDate(@Param("villageIDs") List villageID, @Param("lastModDate") Timestamp lastModifiedDate); } diff --git a/src/main/java/com/iemr/common/identity/service/IdentityService.java b/src/main/java/com/iemr/common/identity/service/IdentityService.java index ee2eb23..b75b4c6 100644 --- a/src/main/java/com/iemr/common/identity/service/IdentityService.java +++ b/src/main/java/com/iemr/common/identity/service/IdentityService.java @@ -507,12 +507,12 @@ public List searhBeneficiaryByFamilyId(String familyId) return beneficiaryList; } - public List searchBeneficiaryByVillageIdAndLastModifyDate(Integer villageID, Timestamp lastModifiedDate) { + public List searchBeneficiaryByVillageIdAndLastModifyDate(List villageIDs, Timestamp lastModifiedDate) { List beneficiaryList = new ArrayList(); try { // find benmap ids - List benMappingsList = mappingRepo.findByBeneficiaryDetailsByVillageIDAndLastModifyDate(villageID, lastModifiedDate); + List benMappingsList = mappingRepo.findByBeneficiaryDetailsByVillageIDAndLastModifyDate(villageIDs, lastModifiedDate); if (benMappingsList != null && !benMappingsList.isEmpty()){ for (MBeneficiarymapping benMapOBJ : benMappingsList) { @@ -521,7 +521,7 @@ public List searchBeneficiaryByVillageIdAndLastModifyDate(Inte } } catch (Exception e) { logger.error( - "error in beneficiary search to sync to CHO App with villageID: " + villageID + " error : " + e.getLocalizedMessage()); + "error in beneficiary search to sync to CHO App with villageIDs: " + villageIDs + " error : " + e.getLocalizedMessage()); } return beneficiaryList; }