Add last billed date

temp
osh 3 years ago
parent 3658e8fad2
commit 7b1b8ecffd

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigInteger;
@ApiModel(value = "EnrolmentInfo", description = "This class carries all information related to a devices enrollment" + @ApiModel(value = "EnrolmentInfo", description = "This class carries all information related to a devices enrollment" +
" status.") " status.")
@ -48,6 +49,8 @@ public class EnrolmentInfo implements Serializable {
private Long dateOfEnrolment; private Long dateOfEnrolment;
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update. This value is not necessary.", required = false ) @ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update. This value is not necessary.", required = false )
private Long dateOfLastUpdate; private Long dateOfLastUpdate;
@ApiModelProperty(name = "lastBilledDate", value = "Date of the device's last update. This value is not necessary.", required = false )
private Long lastBilledDate;
@ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" + @ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" +
" following values.\n" + " following values.\n" +
"BYOD - Bring your own device (BYOD).\n" + "BYOD - Bring your own device (BYOD).\n" +
@ -100,6 +103,14 @@ public class EnrolmentInfo implements Serializable {
this.dateOfLastUpdate = dateOfLastUpdate; this.dateOfLastUpdate = dateOfLastUpdate;
} }
public Long getLastBilledDate() {
return lastBilledDate;
}
public void setLastBilledDate(Long lastBilledDate) {
this.lastBilledDate = lastBilledDate;
}
public OwnerShip getOwnership() { public OwnerShip getOwnership() {
return ownership; return ownership;
} }

@ -30,8 +30,8 @@ public class Costdata {
private String tenantDomain; private String tenantDomain;
private Double cost; private Double cost;
private Timestamp subscriptionBeginning; private long subscriptionBeginning;
private Timestamp subscriptionEnd; private long subscriptionEnd;
@XmlElement(name = "tenantDomain", required = true) @XmlElement(name = "tenantDomain", required = true)
public String getTenantDomain() { public String getTenantDomain() {
@ -52,20 +52,20 @@ public class Costdata {
} }
@XmlElement(name = "subscriptionBeginning", required = true) @XmlElement(name = "subscriptionBeginning", required = true)
public Timestamp getSubscriptionBeginning() { public long getSubscriptionBeginning() {
return subscriptionBeginning; return subscriptionBeginning;
} }
public void setSubscriptionBeginning(Timestamp subscriptionBeginning) { public void setSubscriptionBeginning(long subscriptionBeginning) {
this.subscriptionBeginning = subscriptionBeginning; this.subscriptionBeginning = subscriptionBeginning;
} }
@XmlElement(name = "subscriptionEnd", required = true) @XmlElement(name = "subscriptionEnd", required = true)
public Timestamp getSubscriptionEnd() { public long getSubscriptionEnd() {
return subscriptionEnd; return subscriptionEnd;
} }
public void setSubscriptionEnd(Timestamp subscriptionEnd) { public void setSubscriptionEnd(long subscriptionEnd) {
this.subscriptionEnd = subscriptionEnd; this.subscriptionEnd = subscriptionEnd;
} }

@ -191,8 +191,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
List<DeviceBilling> devices = new ArrayList<>(); List<DeviceBilling> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql ="select DEVICE_IDENTIFICATION, DESCRIPTION, NAME AS DEVICE_NAME, DATE_OF_ENROLMENT, STATUS,\n" + // String sql ="select DEVICE_IDENTIFICATION, DESCRIPTION, NAME AS DEVICE_NAME, DATE_OF_ENROLMENT, LAST_BILLED_DATE AS BILLED_DATE,STATUS,\n" +
"TIMESTAMPDIFF('DAY', CURDATE(), DATE_OF_ENROLMENT) as DAYS_SINCE_ENROLLED from DM_DEVICE d, DM_ENROLMENT e\n" + // "TIMESTAMPDIFF('DAY', CURDATE(), DATE_OF_ENROLMENT) as DAYS_SINCE_ENROLLED from DM_DEVICE d, DM_ENROLMENT e\n" +
// "where e.TENANT_ID= ? and d.ID=e.DEVICE_ID and STATUS !='REMOVED' LIMIT 10";
String sql ="select DEVICE_IDENTIFICATION, DESCRIPTION, NAME AS DEVICE_NAME, DATE_OF_ENROLMENT, LAST_BILLED_DATE,STATUS,\n" +
"TIMESTAMPDIFF('DAY', DATE_OF_ENROLMENT, CURDATE()) as DAYS_SINCE_ENROLLED from DM_DEVICE d, DM_ENROLMENT e\n" +
"where e.TENANT_ID= ? and d.ID=e.DEVICE_ID and STATUS !='REMOVED' LIMIT 10"; "where e.TENANT_ID= ? and d.ID=e.DEVICE_ID and STATUS !='REMOVED' LIMIT 10";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
@ -219,7 +222,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
List<DeviceBilling> devices = new ArrayList<>(); List<DeviceBilling> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "select DEVICE_IDENTIFICATION, DESCRIPTION, NAME AS DEVICE_NAME, DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, STATUS, " + String sql = "select DEVICE_IDENTIFICATION, DESCRIPTION, NAME AS DEVICE_NAME, DATE_OF_ENROLMENT, LAST_BILLED_DATE, DATE_OF_LAST_UPDATE, STATUS, " +
"TIMESTAMPDIFF('DAY', DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE) AS DAYS_USED from DM_DEVICE d, DM_ENROLMENT e" + "TIMESTAMPDIFF('DAY', DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE) AS DAYS_USED from DM_DEVICE d, DM_ENROLMENT e" +
" where e.TENANT_ID=? and d.ID=e.DEVICE_ID and STATUS ='REMOVED'\n"; " where e.TENANT_ID=? and d.ID=e.DEVICE_ID and STATUS ='REMOVED'\n";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -154,8 +154,10 @@ public final class DeviceManagementDAOUtil {
} }
public static EnrolmentInfo loadEnrolmentBilling(ResultSet rs, Boolean removedDevices) throws SQLException { public static EnrolmentInfo loadEnrolmentBilling(ResultSet rs, Boolean removedDevices) throws SQLException {
System.out.println("-----------------DAOO 222------------------------------");
EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime()); enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
enrolmentInfo.setLastBilledDate(rs.getLong("LAST_BILLED_DATE"));
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS"))); enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
if (removedDevices) { if (removedDevices) {
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime()); enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
@ -209,6 +211,7 @@ public final class DeviceManagementDAOUtil {
} }
public static DeviceBilling loadDeviceBilling(ResultSet rs, Boolean removedDevices) throws SQLException { public static DeviceBilling loadDeviceBilling(ResultSet rs, Boolean removedDevices) throws SQLException {
System.out.println("-----------------DAOO 111------------------------------");
DeviceBilling device = new DeviceBilling(); DeviceBilling device = new DeviceBilling();
device.setName(rs.getString("DEVICE_NAME")); device.setName(rs.getString("DEVICE_NAME"));
device.setDescription(rs.getString("DESCRIPTION")); device.setDescription(rs.getString("DESCRIPTION"));

@ -978,6 +978,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
log.debug("Get devices with pagination " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); log.debug("Get devices with pagination " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo);
} }
System.out.println("--------------------COREEEE LAYERR-------------------");
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
Double totalCost = 0.0; Double totalCost = 0.0;
List<DeviceBilling> allDevices; List<DeviceBilling> allDevices;
@ -988,8 +989,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
allDevices = deviceDAO.getDeviceBillList(request, tenantId); allDevices = deviceDAO.getDeviceBillList(request, tenantId);
allRemovedDevices = deviceDAO.getRemovedDeviceBillList(request,tenantId);
count = deviceDAO.getDeviceCount(request, tenantId); count = deviceDAO.getDeviceCount(request, tenantId);
System.out.println("-----------------HERE------------------------------");
String metaKey = "PER_DEVICE_COST"; String metaKey = "PER_DEVICE_COST";
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, metaKey); Metadata metadata = metadataDAO.getMetadata(tenantId, metaKey);
@ -997,12 +1001,36 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Gson g = new Gson(); Gson g = new Gson();
Type collectionType = new TypeToken<Collection<Costdata>>(){}.getType(); Type collectionType = new TypeToken<Collection<Costdata>>(){}.getType();
Collection<Costdata> costdata = g.fromJson(metadata.getMetaValue(), collectionType); Collection<Costdata> costdata = g.fromJson(metadata.getMetaValue(), collectionType); // change name
for (Costdata test: costdata) { for (Costdata test: costdata) {
if (test.getTenantDomain().equals(tenantDomain)) { if (test.getTenantDomain().equals(tenantDomain)) {
for (DeviceBilling device: allDevices) { for (DeviceBilling device: allDevices) {
long dateDiff = test.getSubscriptionEnd().getTime()-device.getEnrolmentInfo().getDateOfEnrolment(); long dateDiff;
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
dateDiff = test.getSubscriptionEnd()-device.getEnrolmentInfo().getDateOfEnrolment();
} else {
dateDiff = test.getSubscriptionEnd()-device.getEnrolmentInfo().getLastBilledDate();
}
// dateDiff = test.getSubscriptionEnd().getTime()-device.getEnrolmentInfo().getDateOfEnrolment();
long dateInDays = dateDiff / (1000*60*60*24);
double cost = (test.getCost()/365)*dateInDays;
totalCost = cost + totalCost;
device.setCost(cost);
}
}
}
for (Costdata test: costdata) {
if (test.getTenantDomain().equals(tenantDomain)) {
for (DeviceBilling device: allRemovedDevices) {
long dateDiff;
// long dateDiff = device.getEnrolmentInfo().getDateOfLastUpdate()-device.getEnrolmentInfo().getDateOfEnrolment();
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
dateDiff = test.getSubscriptionEnd()-device.getEnrolmentInfo().getDateOfEnrolment();
} else {
dateDiff = test.getSubscriptionEnd()-device.getEnrolmentInfo().getLastBilledDate();
}
long dateInDays = dateDiff / (1000*60*60*24); long dateInDays = dateDiff / (1000*60*60*24);
double cost = (test.getCost()/365)*dateInDays; double cost = (test.getCost()/365)*dateInDays;
totalCost = cost + totalCost; totalCost = cost + totalCost;
@ -1011,7 +1039,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
allRemovedDevices = this.getRemovedDeviceListWithCost(paginationResult, request, costdata, tenantDomain, totalCost); // allRemovedDevices = this.getRemovedDeviceListWithCost(paginationResult, request, costdata, tenantDomain, totalCost);
allDevices.addAll(allRemovedDevices); allDevices.addAll(allRemovedDevices);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
@ -1030,6 +1058,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
paginationResult.setData(allDevices); paginationResult.setData(allDevices);
paginationResult.setTotalCost(totalCost);
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count); paginationResult.setRecordsTotal(count);
return paginationResult; return paginationResult;

Loading…
Cancel
Save