Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
PFM-4085 Vendor Report (#667)
Browse files Browse the repository at this point in the history
* PFM-4085 Vendor Report
  • Loading branch information
Saloni-eGov authored Nov 29, 2023
1 parent 9250950 commit 1626b90
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -111,4 +116,39 @@ public int getExistingVenodrsCount(List<String> ownerIdList, String tenantId) {

}

public List<VendorReportData> getVendorReportData(Long monthStartDateTime, String tenantId, Integer offset, Integer limit)
{
StringBuilder vendor_report_query=new StringBuilder(vendorQueryBuilder.VENDOR_REPORT_QUERY);

List<Object> 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<VendorReportData> vendorReportDataList=jdbcTemplate.query(vendor_report_query.toString() , preparedStatement.toArray(), vendorReportRowMapper);

return vendorReportDataList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<VendorReportData>>
{
@Autowired
private ObjectMapper mapper;
@Autowired
private UserService userService;

@Override
public List<VendorReportData> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
List<VendorReportData> 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<VendorReportData> vendorReportDataList)
{
Set<String> 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<VendorReportData> vendorReportDataList)
{
List<User> connectionHolderInfos = userDetailResponse.getUser();
Map<String, User> 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());
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -30,9 +35,6 @@
@Slf4j
public class VendorService {

@Autowired
private VendorRepository vendorRepository;

@Autowired
private VendorValidator vendorValidator;

Expand Down Expand Up @@ -64,7 +66,7 @@ public Vendor create(VendorRequest vendorRequest) {

vendorValidator.validateCreate(vendorRequest);
enrichmentService.enrichCreate(vendorRequest);
vendorRepository.save(vendorRequest);
repository.save(vendorRequest);
return vendorRequest.getVendor();

}
Expand Down Expand Up @@ -159,4 +161,19 @@ private List<Vendor> getVendorPlainSearch(@Valid VendorSearchCriteria criteria,
return vendorList;
}

public List<VendorReportData> 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> vendorReportData=repository.getVendorReportData(monthStartDateTime,tenantId,offset,limit);
return vendorReportData;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,4 +66,19 @@ public ResponseEntity<VendorResponse> plainsearch(@Valid @RequestBody RequestInf
.build();
return new ResponseEntity<>(response, HttpStatus.OK);
}

@RequestMapping(value="/_vendorReport" ,method = RequestMethod.POST)
public ResponseEntity<VendorReportResponse> 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> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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> VendorReportData;

@JsonProperty("requestInfo")
private ResponseInfo responseInfo = null;
}

0 comments on commit 1626b90

Please sign in to comment.