Add last billed date

feature/traccar-sync
osh 3 years ago
parent 3658e8fad2
commit 7b1b8ecffd

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

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

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

@ -154,8 +154,10 @@ public final class DeviceManagementDAOUtil {
}
public static EnrolmentInfo loadEnrolmentBilling(ResultSet rs, Boolean removedDevices) throws SQLException {
System.out.println("-----------------DAOO 222------------------------------");
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
enrolmentInfo.setLastBilledDate(rs.getLong("LAST_BILLED_DATE"));
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
if (removedDevices) {
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 {
System.out.println("-----------------DAOO 111------------------------------");
DeviceBilling device = new DeviceBilling();
device.setName(rs.getString("DEVICE_NAME"));
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);
}
System.out.println("--------------------COREEEE LAYERR-------------------");
PaginationResult paginationResult = new PaginationResult();
Double totalCost = 0.0;
List<DeviceBilling> allDevices;
@ -988,8 +989,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
DeviceManagementDAOFactory.openConnection();
allDevices = deviceDAO.getDeviceBillList(request, tenantId);
allRemovedDevices = deviceDAO.getRemovedDeviceBillList(request,tenantId);
count = deviceDAO.getDeviceCount(request, tenantId);
System.out.println("-----------------HERE------------------------------");
String metaKey = "PER_DEVICE_COST";
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, metaKey);
@ -997,12 +1001,36 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Gson g = new Gson();
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) {
if (test.getTenantDomain().equals(tenantDomain)) {
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);
double cost = (test.getCost()/365)*dateInDays;
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);
} catch (DeviceManagementDAOException e) {
@ -1030,6 +1058,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection();
}
paginationResult.setData(allDevices);
paginationResult.setTotalCost(totalCost);
paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count);
return paginationResult;

Loading…
Cancel
Save