Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit edfa007
Author: Matt Magoffin <[email protected]>
Date:   Wed Jan 31 11:07:09 2024 +1300

    NET-359: add invoicing support for OSCP Capacity.

commit dc8bdec
Author: Matt Magoffin <[email protected]>
Date:   Tue Jan 30 18:41:55 2024 +1300

    NET-359: work on OSCP billing change DAO layer.
  • Loading branch information
msqr committed Jan 31, 2024
1 parent c9fd9a7 commit 4ea5cd5
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static net.solarnetwork.central.user.billing.snf.domain.NodeUsages.INSTRUCTIONS_ISSUED_KEY;
import static net.solarnetwork.central.user.billing.snf.domain.NodeUsages.OCPP_CHARGERS_KEY;
import static net.solarnetwork.central.user.billing.snf.domain.NodeUsages.OSCP_CAPACITY_GROUPS_KEY;
import static net.solarnetwork.central.user.billing.snf.domain.NodeUsages.OSCP_CAPACITY_KEY;
import static net.solarnetwork.central.user.billing.snf.domain.SnfInvoiceItem.META_AVAILABLE_CREDIT;
import static net.solarnetwork.central.user.billing.snf.domain.SnfInvoiceItem.newItem;
import static net.solarnetwork.util.ObjectUtils.requireNonNullArgument;
Expand Down Expand Up @@ -103,7 +104,7 @@
* Default implementation of {@link SnfInvoicingSystem}.
*
* @author matt
* @version 1.3
* @version 1.4
*/
public class DefaultSnfInvoicingSystem implements SnfInvoicingSystem, SnfTaxCodeResolver {

Expand Down Expand Up @@ -144,6 +145,7 @@ public class DefaultSnfInvoicingSystem implements SnfInvoicingSystem, SnfTaxCode
private String instructionsIssuedKey = INSTRUCTIONS_ISSUED_KEY;
private String ocppChargersKey = OCPP_CHARGERS_KEY;
private String oscpCapacityGroupsKey = OSCP_CAPACITY_GROUPS_KEY;
private String oscpCapacityKey = OSCP_CAPACITY_KEY;
private String dnp3DataPointsKey = DNP3_DATA_POINTS_KEY;
private String accountCreditKey = AccountBalance.ACCOUNT_CREDIT_KEY;
private int deliveryTimeoutSecs = DEFAULT_DELIVERY_TIMEOUT;
Expand Down Expand Up @@ -312,6 +314,15 @@ public SnfInvoice generateInvoice(Long userId, LocalDate startDate, LocalDate en
}
items.add(item);
}
if ( usage.getOscpCapacity().compareTo(BigInteger.ZERO) > 0 ) {
SnfInvoiceItem item = newItem(invoiceId.getId(), Usage, oscpCapacityKey,
new BigDecimal(usage.getOscpCapacity()), usage.getOscpCapacityCost());
item.setMetadata(usageMetadata(usageInfo, tiersBreakdown, OSCP_CAPACITY_KEY));
if ( !dryRun ) {
invoiceItemDao.save(item);
}
items.add(item);
}
if ( usage.getDnp3DataPoints().compareTo(BigInteger.ZERO) > 0 ) {
SnfInvoiceItem item = newItem(invoiceId.getId(), Usage, dnp3DataPointsKey,
new BigDecimal(usage.getDnp3DataPoints()), usage.getDnp3DataPointsCost());
Expand Down Expand Up @@ -756,6 +767,30 @@ public void setOscpCapacityGroupsKey(String oscpCapacityGroupsKey) {
"oscpCapacityGroupsKey");
}

/**
* Get the item key for OSCP Capacity.
*
* @return the key, never {@literal null}; defaults to
* {@link NodeUsages#OSCP_CAPACITY_KEY}
* @since 1.4
*/
public String getOscpCapacityKey() {
return oscpCapacityKey;
}

/**
* Set the item key for OSCP Capacity.
*
* @param oscpCapacityKey
* the oscpCapacityKey to set
* @throws IllegalArgumentException
* if the argument is {@literal null}
* @since 1.4
*/
public void setOscpCapacityKey(String oscpCapacityKey) {
this.oscpCapacityKey = requireNonNullArgument(oscpCapacityKey, "oscpCapacityKey");
}

/**
* Get the item key for DNP3 Data Points.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
* </p>
*
* @author matt
* @version 2.4
* @version 2.5
*/
public class NodeUsage extends BasicLongEntity
implements InvoiceUsageRecord<Long>, Differentiable<NodeUsage>, NodeUsages {

private static final long serialVersionUID = 5442178658317850821L;
private static final long serialVersionUID = 7976017078304093207L;

/**
* Comparator that sorts {@link NodeUsage} objects by {@code id} in
Expand All @@ -76,6 +76,7 @@ public class NodeUsage extends BasicLongEntity
private BigInteger instructionsIssued;
private BigInteger ocppChargers;
private BigInteger oscpCapacityGroups;
private BigInteger oscpCapacity;
private BigInteger dnp3DataPoints;
private final NodeUsageCost costs;
private BigDecimal totalCost;
Expand All @@ -86,6 +87,7 @@ public class NodeUsage extends BasicLongEntity
private BigInteger[] instructionsIssuedTiers;
private BigInteger[] ocppChargersTiers;
private BigInteger[] oscpCapacityGroupsTiers;
private BigInteger[] oscpCapacityTiers;
private BigInteger[] dnp3DataPointsTiers;
private NodeUsageCost[] costsTiers;

Expand Down Expand Up @@ -139,6 +141,7 @@ public NodeUsage(Long nodeId, Instant created) {
setInstructionsIssued(BigInteger.ZERO);
setOcppChargers(BigInteger.ZERO);
setOscpCapacityGroups(BigInteger.ZERO);
setOscpCapacity(BigInteger.ZERO);
setDnp3DataPoints(BigInteger.ZERO);
setTotalCost(BigDecimal.ZERO);
this.costs = new NodeUsageCost();
Expand All @@ -161,6 +164,10 @@ public String toString() {
builder.append(datumDaysStored);
builder.append(", instructionsIssued=");
builder.append(instructionsIssued);
builder.append(", oscpCapacityGroups=");
builder.append(oscpCapacityGroups);
builder.append(", oscpCapacity=");
builder.append(oscpCapacity);
builder.append(", datumPropertiesInCost=");
builder.append(costs.getDatumPropertiesInCost());
builder.append(", datumOutCost=");
Expand All @@ -173,6 +180,8 @@ public String toString() {
builder.append(costs.getOcppChargersCost());
builder.append(", oscpCapacityGroupsCost=");
builder.append(costs.getOscpCapacityGroupsCost());
builder.append(", oscpCapacityCost=");
builder.append(costs.getOscpCapacityCost());
builder.append(", dnp3DataPointsCost=");
builder.append(costs.getDnp3DataPointsCost());
builder.append(", totalCost=");
Expand Down Expand Up @@ -206,6 +215,7 @@ public boolean isSameAs(NodeUsage other) {
&& Objects.equals(instructionsIssued, other.instructionsIssued)
&& Objects.equals(ocppChargers, other.ocppChargers)
&& Objects.equals(oscpCapacityGroups, other.oscpCapacityGroups)
&& Objects.equals(oscpCapacity, other.oscpCapacity)
&& Objects.equals(dnp3DataPoints, other.dnp3DataPoints);
// @formatter:on
}
Expand Down Expand Up @@ -554,6 +564,7 @@ private static List<NamedCost> tiersCostBreakdown(BigInteger[] counts, NodeUsage
* <li>{@link #INSTRUCTIONS_ISSUED_KEY}</li>
* <li>{@link #OCPP_CHARGERS_KEY}</li>
* <li>{@link #OSCP_CAPACITY_GROUPS_KEY}</li>
* <li>{@link #OSCP_CAPACITY_KEY}</li>
* <li>{@link #DNP3_DATA_POINTS_KEY}</li>
* </ol>
*
Expand All @@ -567,6 +578,7 @@ public Map<String, List<NamedCost>> getTiersCostBreakdown() {
result.put(INSTRUCTIONS_ISSUED_KEY, getInstructionsIssuedTiersCostBreakdown());
result.put(OCPP_CHARGERS_KEY, getOcppChargersTiersCostBreakdown());
result.put(OSCP_CAPACITY_GROUPS_KEY, getOscpCapacityGroupsTiersCostBreakdown());
result.put(OSCP_CAPACITY_KEY, getOscpCapacityTiersCostBreakdown());
result.put(DNP3_DATA_POINTS_KEY, getDnp3DataPointsTiersCostBreakdown());
return result;
}
Expand All @@ -584,6 +596,7 @@ public Map<String, List<NamedCost>> getTiersCostBreakdown() {
* <li>{@link #INSTRUCTIONS_ISSUED_KEY}</li>
* <li>{@link #OCPP_CHARGERS_KEY}</li>
* <li>{@link #OSCP_CAPACITY_GROUPS_KEY}</li>
* <li>{@link #OSCP_CAPACITY_KEY}</li>
* <li>{@link #DNP3_DATA_POINTS_KEY}</li>
* </ol>
*
Expand All @@ -603,6 +616,8 @@ public Map<String, UsageInfo> getUsageInfo() {
costs.getOcppChargersCost()));
result.put(OSCP_CAPACITY_GROUPS_KEY, new UsageInfo(OSCP_CAPACITY_GROUPS_KEY,
new BigDecimal(oscpCapacityGroups), costs.getOscpCapacityGroupsCost()));
result.put(OSCP_CAPACITY_KEY, new UsageInfo(OSCP_CAPACITY_KEY, new BigDecimal(oscpCapacity),
costs.getOscpCapacityCost()));
result.put(DNP3_DATA_POINTS_KEY, new UsageInfo(DNP3_DATA_POINTS_KEY,
new BigDecimal(dnp3DataPoints), costs.getDnp3DataPointsCost()));
return result;
Expand Down Expand Up @@ -1182,4 +1197,120 @@ public void setInstructionsIssuedCostTiers(BigDecimal[] instructionsIssuedCostTi
costsTiers[i].setInstructionsIssuedCost(val);
}
}

/**
* Get the OSCP capacity.
*
* @return the count
* @since 2.5
*/
public BigInteger getOscpCapacity() {
return oscpCapacity;
}

/**
* Set the count of OSCP capacity .
*
* @param oscpCapacity
* the count to set; if {@literal null} then {@literal 0} will be
* stored
* @since 2.5
*/
public void setOscpCapacity(BigInteger oscpCapacity) {
if ( oscpCapacity == null ) {
oscpCapacity = BigInteger.ZERO;
}
this.oscpCapacity = oscpCapacity;
}

/**
* Get the cost of OSCP capacity.
*
* @return the cost
* @since 2.5
*/
public BigDecimal getOscpCapacityCost() {
return costs.getOscpCapacityCost();
}

/**
* Set the cost of OSCP capacity.
*
* @param oscpCapacityCost
* the cost to set
* @since 2.5
*/
public void setOscpCapacityCost(BigDecimal oscpCapacityCost) {
costs.setOscpCapacityCost(oscpCapacityCost);
}

/**
* Get the OSCP capacity tier cost breakdown.
*
* @return the costs, never {@literal null}
* @since 2.5
*/
@JsonIgnore
public List<NamedCost> getOscpCapacityTiersCostBreakdown() {
return tiersCostBreakdown(oscpCapacityTiers, costsTiers, NodeUsageCost::getOscpCapacityCost);
}

/**
* Get the OSCP capacity, per tier.
*
* @return the counts
* @since 2.5
*/
public BigInteger[] getOscpCapacityTiers() {
return oscpCapacityTiers;
}

/**
* Set the OSCP capacity, per tier.
*
* @param oscpCapacityTiers
* the counts to set
* @since 2.5
*/
public void setOscpCapacityTiers(BigInteger[] oscpCapacityTiers) {
this.oscpCapacityTiers = oscpCapacityTiers;
}

/**
* Set the OSCP capacity, per tier, as decimals.
*
* @param oscpCapacityTiers
* the counts to set
* @since 2.5
*/
public void setOscpCapacityTiersNumeric(BigDecimal[] oscpCapacityTiers) {
this.oscpCapacityTiers = decimalsToIntegers(oscpCapacityTiers);
}

/**
* Get the cost of OSCP capacity, per tier.
*
* @return the cost
* @since 2.5
*/
public BigDecimal[] getOscpCapacityCostTiers() {
return getTierCostValues(costsTiers, NodeUsageCost::getOscpCapacityCost);
}

/**
* Set the cost of OSCP capacity, per tier.
*
* @param oscpCapacityCostTiers
* the costs to set
* @since 2.5
*/
public void setOscpCapacityCostTiers(BigDecimal[] oscpCapacityCostTiers) {
prepCostsTiers(oscpCapacityCostTiers);
for ( int i = 0; i < costsTiers.length; i++ ) {
BigDecimal val = (oscpCapacityCostTiers != null && i < oscpCapacityCostTiers.length
? oscpCapacityCostTiers[i]
: null);
costsTiers[i].setOscpCapacityCost(val);
}
}
}
Loading

0 comments on commit 4ea5cd5

Please sign in to comment.