diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/repository/VendorRepository.java b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/VendorRepository.java index 9570480ad..e3bc835e8 100644 --- a/municipal-services/vendor/src/main/java/org/egov/vendor/repository/VendorRepository.java +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/VendorRepository.java @@ -9,8 +9,10 @@ import org.egov.vendor.config.VendorConfiguration; import org.egov.vendor.producer.Producer; import org.egov.vendor.repository.querybuilder.VendorQueryBuilder; +import org.egov.vendor.repository.rowmapper.VendorReportRowMapper; import org.egov.vendor.repository.rowmapper.VendorRowMapper; import org.egov.vendor.web.model.Vendor; +import org.egov.vendor.web.model.VendorReportData; import org.egov.vendor.web.model.VendorRequest; import org.egov.vendor.web.model.VendorSearchCriteria; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +41,9 @@ public class VendorRepository { @Autowired private VendorRowMapper vendorrowMapper; + @Autowired + private VendorReportRowMapper vendorReportRowMapper; + public void save(VendorRequest vendorRequest) { producer.push(configuration.getSaveTopic(), vendorRequest); } @@ -111,4 +116,39 @@ public int getExistingVenodrsCount(List ownerIdList, String tenantId) { } + public List getVendorReportData(Long monthStartDateTime, String tenantId, Integer offset, Integer limit) + { + StringBuilder vendor_report_query=new StringBuilder(vendorQueryBuilder.VENDOR_REPORT_QUERY); + + List preparedStatement=new ArrayList<>(); + preparedStatement.add(tenantId); + preparedStatement.add(monthStartDateTime); +// preparedStatement.add(monthEndDateTime); + + + Integer newlimit=configuration.getDefaultLimit(); + Integer newoffset= configuration.getDefaultOffset(); + + if(limit==null && offset==null) + newlimit=configuration.getMaxSearchLimit(); + if(limit!=null && limit<=configuration.getMaxSearchLimit()) + newlimit=limit; + if(limit!=null && limit>=configuration.getMaxSearchLimit()) + newlimit=configuration.getMaxSearchLimit(); + + if(offset!=null) + newoffset=offset; + + if (newlimit>0){ + vendor_report_query.append(" offset ? limit ? ;"); + preparedStatement.add(newoffset); + preparedStatement.add(newlimit); + } + + log.info("Query of vendor report : "+vendor_report_query.toString()+" prepared statement of vendor report "+ preparedStatement); + + List vendorReportDataList=jdbcTemplate.query(vendor_report_query.toString() , preparedStatement.toArray(), vendorReportRowMapper); + + return vendorReportDataList; + } } diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/repository/querybuilder/VendorQueryBuilder.java b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/querybuilder/VendorQueryBuilder.java index 7c2396ad9..c30edea4a 100644 --- a/municipal-services/vendor/src/main/java/org/egov/vendor/repository/querybuilder/VendorQueryBuilder.java +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/querybuilder/VendorQueryBuilder.java @@ -12,6 +12,11 @@ @Component public class VendorQueryBuilder { + public static final String VENDOR_REPORT_QUERY = "select echallan.challanno,echallan.typeofexpense as type_of_expense," + + " vendor.name,eg_user.uuid as owner_uuid from eg_echallan echallan INNER JOIN eg_vendor vendor on " + + " echallan.vendor=vendor.id INNER JOIN eg_user on eg_user.uuid=vendor.owner_id where " + + " echallan.applicationstatus!='CANCELLED' and echallan.tenantid =? " + + " and echallan.taxperiodfrom >= ? order by echallan.challanno desc "; @Autowired private VendorConfiguration config; diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/repository/rowmapper/VendorReportRowMapper.java b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/rowmapper/VendorReportRowMapper.java new file mode 100644 index 000000000..ccc815944 --- /dev/null +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/repository/rowmapper/VendorReportRowMapper.java @@ -0,0 +1,95 @@ +package org.egov.vendor.repository.rowmapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.vendor.service.UserService; +import org.egov.vendor.web.model.VendorReportData; +import org.egov.vendor.web.model.user.User; +import org.egov.vendor.web.model.user.UserDetailResponse; +import org.egov.vendor.web.model.user.UserSearchRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Slf4j +public class VendorReportRowMapper implements ResultSetExtractor> +{ + @Autowired + private ObjectMapper mapper; + @Autowired + private UserService userService; + + @Override + public List extractData(ResultSet resultSet) throws SQLException, DataAccessException { + List vendorReportDataList=new ArrayList<>(); + + while(resultSet.next()) + { + VendorReportData vendorReportData=new VendorReportData(); + vendorReportData.setVendor_name(resultSet.getString("name")); + vendorReportData.setBill_id(resultSet.getString("challanno")); + vendorReportData.setUuid(resultSet.getString("owner_uuid")); + vendorReportData.setType_of_expense(resultSet.getString("type_of_expense")); + vendorReportDataList.add(vendorReportData); + } + if(!vendorReportDataList.isEmpty()) + { + enrichVendorHolderDetails(vendorReportDataList); + } + return vendorReportDataList; + } + + private void enrichVendorHolderDetails(List vendorReportDataList) + { + Set lastModifiedByUuid= new HashSet<>(); + + for(VendorReportData vendorReportData:vendorReportDataList) + { + lastModifiedByUuid.add(vendorReportData.getUuid()); + } + + UserSearchRequest userSearchRequest=new UserSearchRequest(); + userSearchRequest.setUuid((new ArrayList<>(lastModifiedByUuid))); + + log.info(userSearchRequest.getUuid().toString()); + + UserDetailResponse userDetailResponse = userService.getUser(userSearchRequest); + + log.info(userDetailResponse.getUser().toString()); + + enrichConnectionHolderInfo(userDetailResponse, vendorReportDataList); + + } + + private void enrichConnectionHolderInfo(UserDetailResponse userDetailResponse, List vendorReportDataList) + { + List connectionHolderInfos = userDetailResponse.getUser(); + Map userIdToConnectionHolderMap = new HashMap<>(); + if(connectionHolderInfos.isEmpty()) + { + return; + } + connectionHolderInfos.forEach(user -> userIdToConnectionHolderMap.put(user.getUuid(), user)); + + log.info(userIdToConnectionHolderMap.toString()); + +// vendorReportDataList.forEach(vendorReportData-> vendorReportData.setMobile_no(userIdToConnectionHolderMap.get(vendorReportData.getUuid()).getMobileNumber())); + + vendorReportDataList.forEach(vendorReportData -> { + User connection = userIdToConnectionHolderMap.get(vendorReportData.getUuid()); + if (connection != null) { + vendorReportData.setMobile_no(connection.getMobileNumber()); + } else { + log.warn("User not found for UUID: " + vendorReportData.getUuid()); + } + }); + + } +} diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/service/UserService.java b/municipal-services/vendor/src/main/java/org/egov/vendor/service/UserService.java index d1ec6484c..ddf5d0400 100644 --- a/municipal-services/vendor/src/main/java/org/egov/vendor/service/UserService.java +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/service/UserService.java @@ -610,4 +610,12 @@ private Boolean isUserValid(User user) { return Boolean.TRUE; } + + + public UserDetailResponse getUser(UserSearchRequest userSearchRequest) { + StringBuilder uri = new StringBuilder(config.getUserHost()) + .append(config.getUserSearchEndpoint()); + UserDetailResponse userDetailResponse = userCall(userSearchRequest, uri); + return userDetailResponse; + } } diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/service/VendorService.java b/municipal-services/vendor/src/main/java/org/egov/vendor/service/VendorService.java index 5bde74895..6276a7ddf 100644 --- a/municipal-services/vendor/src/main/java/org/egov/vendor/service/VendorService.java +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/service/VendorService.java @@ -1,5 +1,9 @@ package org.egov.vendor.service; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; @@ -14,6 +18,7 @@ import org.egov.vendor.repository.VendorRepository; import org.egov.vendor.validator.VendorValidator; import org.egov.vendor.web.model.Vendor; +import org.egov.vendor.web.model.VendorReportData; import org.egov.vendor.web.model.VendorRequest; import org.egov.vendor.web.model.VendorSearchCriteria; import org.egov.vendor.web.model.user.User; @@ -30,9 +35,6 @@ @Slf4j public class VendorService { - @Autowired - private VendorRepository vendorRepository; - @Autowired private VendorValidator vendorValidator; @@ -64,7 +66,7 @@ public Vendor create(VendorRequest vendorRequest) { vendorValidator.validateCreate(vendorRequest); enrichmentService.enrichCreate(vendorRequest); - vendorRepository.save(vendorRequest); + repository.save(vendorRequest); return vendorRequest.getVendor(); } @@ -159,4 +161,19 @@ private List getVendorPlainSearch(@Valid VendorSearchCriteria criteria, return vendorList; } + public List vendorReport(String monthStartDate, String tenantId, Integer offset, Integer limit, RequestInfo requestInfo) + { + + DateTimeFormatter formatter=DateTimeFormatter.ofPattern("dd/MM/yyyy"); + LocalDate startDate= LocalDate.parse(monthStartDate,formatter); +// LocalDate endDate=LocalDate.parse(monthEndDate,formatter); + + Long monthStartDateTime= LocalDateTime.of(startDate.getYear(),startDate.getMonth(),startDate.getDayOfMonth(), + 0,0,0).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); +// Long monthEndDateTime=LocalDateTime.of(endDate, LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + + List vendorReportData=repository.getVendorReportData(monthStartDateTime,tenantId,offset,limit); + return vendorReportData; + + } } diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/web/controller/VendorController.java b/municipal-services/vendor/src/main/java/org/egov/vendor/web/controller/VendorController.java index 66971ebf7..2be2fa9f4 100644 --- a/municipal-services/vendor/src/main/java/org/egov/vendor/web/controller/VendorController.java +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/web/controller/VendorController.java @@ -9,20 +9,11 @@ import org.egov.vendor.service.VendorService; import org.egov.vendor.util.ResponseInfoFactory; import org.egov.vendor.util.VendorUtil; -import org.egov.vendor.web.model.RequestInfoWrapper; -import org.egov.vendor.web.model.Vendor; -import org.egov.vendor.web.model.VendorRequest; -import org.egov.vendor.web.model.VendorResponse; -import org.egov.vendor.web.model.VendorSearchCriteria; +import org.egov.vendor.web.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @@ -75,4 +66,19 @@ public ResponseEntity plainsearch(@Valid @RequestBody RequestInf .build(); return new ResponseEntity<>(response, HttpStatus.OK); } + + @RequestMapping(value="/_vendorReport" ,method = RequestMethod.POST) + public ResponseEntity vendorReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper, + @RequestParam(value="monthStartDate" , required = true) String monthStartDate, + @RequestParam ("tenantId") String tenantId, + @RequestParam ("offset") Integer offset, + @RequestParam ("limit") Integer limit) + { + + List vendorReportData=vendorService.vendorReport(monthStartDate,tenantId,offset,limit,requestInfoWrapper.getRequestInfo()); + VendorReportResponse vendorReportResponse= VendorReportResponse.builder().VendorReportData(vendorReportData).responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),true)).build(); + + return new ResponseEntity<>(vendorReportResponse,HttpStatus.OK); + } + } diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportData.java b/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportData.java new file mode 100644 index 000000000..8126fb4f0 --- /dev/null +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportData.java @@ -0,0 +1,31 @@ +package org.egov.vendor.web.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class VendorReportData { + + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("vendor_name") + private String vendor_name; + + @JsonProperty("mobile_no") + private String mobile_no; + + @JsonProperty("type_of_expense") + private String type_of_expense; + + @JsonProperty("bill_id") + private String bill_id; + + @JsonProperty("owner_uuid") + private String uuid; + +} diff --git a/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportResponse.java b/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportResponse.java new file mode 100644 index 000000000..021606a1a --- /dev/null +++ b/municipal-services/vendor/src/main/java/org/egov/vendor/web/model/VendorReportResponse.java @@ -0,0 +1,17 @@ +package org.egov.vendor.web.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import org.egov.common.contract.response.ResponseInfo; + +import java.util.List; + +@Builder +public class VendorReportResponse { + + @JsonProperty("VendorReportData") + private List VendorReportData; + + @JsonProperty("requestInfo") + private ResponseInfo responseInfo = null; +}