fix: get group summary details

This commit is contained in:
Nayan Ambali
2013-02-27 19:24:52 +05:30
parent d322e70649
commit 6e60f5baf8
3 changed files with 22 additions and 12 deletions
@@ -26,6 +26,7 @@ public class GroupData {
private final Long groupLevel;
private final Long parentId;
private final String parentName;
private final String hierarchy;
@SuppressWarnings("unused")
private final GroupSummaryData groupSummaryData;
@SuppressWarnings("unused")
@@ -43,7 +44,7 @@ public class GroupData {
private final Collection<GroupLookupData> childGroups;
public GroupData(final Long id, final Long officeId, final String officeName, final String name, final String externalId,
final Long groupLevel, final Long parentId, final String parentName, final Long staffId, final String staffName) {
final Long groupLevel, final Long parentId, final String parentName, final Long staffId, final String staffName , final String hierarchy) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
@@ -54,6 +55,7 @@ public class GroupData {
this.parentName = parentName;
this.staffId = staffId;
this.staffName = staffName;
this.hierarchy = hierarchy;
this.groupSummaryData = null;
this.groupLevelData = null;
this.clientMembers = null;
@@ -77,6 +79,7 @@ public class GroupData {
this.parentName = group.getParentName();
this.staffId = group.getStaffId();
this.staffName = group.getStaffName();
this.hierarchy = group.getHierarchy();
this.groupSummaryData = groupSummaryData;
this.groupLevelData = groupLevelData;
@@ -102,6 +105,7 @@ public class GroupData {
this.parentName = null;
this.staffId = null;
this.staffName = null;
this.hierarchy = null;
this.groupSummaryData = null;
this.groupLevelData = groupLevelData;
this.allowedClients = allowedClients;
@@ -151,6 +155,11 @@ public class GroupData {
return this.parentName;
}
public String getHierarchy() {
return this.hierarchy;
}
public Collection<ClientLookup> clientMembers() {
return this.clientMembers;
}
@@ -40,9 +40,9 @@ public interface GroupReadPlatformService {
Collection<GroupLookupData> retrieveChildGroupsbyGroupId(Long groupId);
Long retrieveTotalClients(Long groupId);
Long retrieveTotalNoOfChildGroups(Long groupId);
Collection<MoneyData> retrieveGroupLoanPortfolio(Long groupId);
Long retrieveTotalClients(String hierarchy);
Collection<MoneyData> retrieveGroupLoanPortfolio(String hierarchy);
}
@@ -182,9 +182,9 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
Collection<StaffData> allowedStaffs = null;
Collection<GroupLookupData> childGroups = this.retrieveChildGroupsbyGroupId(groupId);
final Long totalActiveClients = this.retrieveTotalClients(groupId);
final Long totalActiveClients = this.retrieveTotalClients(group.getHierarchy());
final Long totalChildGroups = this.retrieveTotalNoOfChildGroups(groupId);
Collection<MoneyData> totalLoanPortfolio = this.retrieveGroupLoanPortfolio(groupId);
Collection<MoneyData> totalLoanPortfolio = this.retrieveGroupLoanPortfolio(group.getHierarchy());
GroupSummaryData groupSummaryData = new GroupSummaryData(totalActiveClients, totalChildGroups, totalLoanPortfolio, null);
@@ -230,11 +230,11 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
}
@Override
public Long retrieveTotalClients(final Long groupId) {
public Long retrieveTotalClients(final String hierarchy) {
this.context.authenticatedUser();
String groupHierarchy = "." + groupId + "%";
String groupHierarchy = hierarchy + "%";
String sqlTotalClients = "SELECT count(gc.client_id) FROM m_group_client gc JOIN m_group g "
+ "ON gc.group_id = g.id WHERE g.hierarchy LIKE ? ";
return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupHierarchy });
@@ -251,13 +251,13 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
}
@Override
public Collection<MoneyData> retrieveGroupLoanPortfolio(final Long groupId) {
public Collection<MoneyData> retrieveGroupLoanPortfolio(final String hierarchy) {
this.context.authenticatedUser();
MoneyDataMapper rm = new MoneyDataMapper();
String groupHierarchy = "." + groupId + "%";
String groupHierarchy = hierarchy + "%";
String sql = "select " + rm.moneyDataSchema() + " FROM m_group_client gc JOIN m_group g ON gc.group_id = g.id "
+ "JOIN m_loan l ON l.client_id = gc.client_id LEFT JOIN m_organisation_currency oc ON oc.code = l.currency_code "
+ " WHERE g.hierarchy LIKE ? GROUP BY l.currency_code ";
@@ -289,7 +289,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
public String groupSchema() {
return "g.office_id as officeId, g.level_id as groupLevel , g.parent_id as parentId , o.name as officeName,"
+ " g.id as id, g.external_id as externalId, g.name as name , s.display_name as staffName , pg.name as"
+ " parentName , g.staff_id as staffId from m_group g join m_office o on o.id = g.office_id left join "
+ " parentName , g.staff_id as staffId , g.hierarchy as hierarchy from m_group g join m_office o on o.id = g.office_id left join "
+ "m_staff s on s.id = g.staff_id left join m_group pg on pg.id = g.parent_id";
}
@@ -306,8 +306,9 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
String parentName = rs.getString("parentName");
Long staffId = rs.getLong("staffId");
String staffName = rs.getString("staffName");
String hierarchy =rs.getString("hierarchy");
return new GroupData(id, officeId, officeName, name, externalId, groupLevel, parentId, parentName, staffId, staffName);
return new GroupData(id, officeId, officeName, name, externalId, groupLevel, parentId, parentName, staffId, staffName , hierarchy);
}
}