Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ public class BatchCountersDTO {
private Long trxElaborated;
private Long trxRejected;

private BatchCountersDTO() {
@Override
public String toString() {
return "BatchCountersDTO{" +
"initialAmountCents=" + initialAmountCents +
", numberOfTransactions=" + numberOfTransactions +
", suspendedAmountCents=" + suspendedAmountCents +
", trxSuspended=" + trxSuspended +
", approvedAmountCents=" + approvedAmountCents +
", trxElaborated=" + trxElaborated +
", trxRejected=" + trxRejected +
'}';
}

private BatchCountersDTO() {
this.initialAmountCents = 0L;
this.numberOfTransactions = 0L;
this.approvedAmountCents = 0L;
Expand All @@ -31,12 +44,16 @@ public BatchCountersDTO incrementInitialAmountCents(Long amountCents) {
return this;
}


public BatchCountersDTO incrementNumberOfTransactions(Long number) {
this.numberOfTransactions = this.numberOfTransactions + number;
return this;
}

public BatchCountersDTO decrementNumberOfTransactions() {
this.numberOfTransactions = this.numberOfTransactions - 1;
return this;
}

public BatchCountersDTO incrementApprovedAmountCents(Long amountCents) {
this.approvedAmountCents = this.approvedAmountCents + amountCents;
return this;
Expand All @@ -57,6 +74,11 @@ public BatchCountersDTO decrementSuspendedAmountCents(Long amountCents) {
return this;
}

public BatchCountersDTO decrementTrxElaborated() {
this.trxElaborated = this.trxElaborated - 1L;
return this;
}

public BatchCountersDTO incrementTrxElaborated() {
this.trxElaborated = this.trxElaborated + 1L;
return this;
Expand All @@ -67,6 +89,11 @@ public BatchCountersDTO incrementTrxElaborated(Long number) {
return this;
}

public BatchCountersDTO decrementTrxElaborated(Long number) {
this.trxElaborated = this.trxElaborated - number;
return this;
}

public BatchCountersDTO incrementTrxSuspended() {
this.trxSuspended = this.trxSuspended + 1L;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public interface RewardBatchSpecificRepository {
Mono<RewardBatch> incrementTotalAmountCents(String batchId, long accruedAmountCents);
Mono<RewardBatch> decrementTotalAmountCents(String batchId, long accruedAmountCents);
Mono<RewardBatch> moveSuspendToNewBatch(String oldBatchId, String newBatchId, long accruedAmountCents);
Mono<RewardBatch> moveTrxToNewBatch(String oldBatchId, String newBatchId, long accruedAmountCents, boolean isSuspended);
Flux<RewardBatch> findRewardBatchesCombined(String merchantId, String status, String assigneeLevel, String month, boolean isOperator, Pageable pageable);
Mono<Long> getCountCombined(String merchantId, String status, String assigneeLevel, String month, boolean isOperator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Mono<Long> getCountCombined(String merchantId, String status, String assi
return mongoTemplate.count(Query.query(criteria), RewardBatch.class);
}

@Deprecated
@Override
public Mono<RewardBatch> incrementTotalAmountCents(String batchId, long accruedAmountCents) {
return mongoTemplate.findAndModify(
Expand All @@ -66,6 +67,7 @@ public Mono<RewardBatch> incrementTotalAmountCents(String batchId, long accruedA
);
}

@Deprecated
@Override
public Mono<RewardBatch> decrementTotalAmountCents(String batchId, long accruedAmountCents) {
return mongoTemplate.findAndModify(
Expand Down Expand Up @@ -117,42 +119,6 @@ public Mono<RewardBatch> moveTrxToNewBatch(String oldBatchId, String newBatchId,
.switchIfEmpty(Mono.error(new ClientExceptionNoBody(HttpStatus.BAD_REQUEST, REWARD_BATCH_NOT_FOUND)));
}

@Override
public Mono<RewardBatch> moveSuspendToNewBatch(String oldBatchId, String newBatchId, long accruedAmountCents) {

Update decOld = new Update()
//.inc(INITIAL_AMOUNT_CENTS, -accruedAmountCents)
.inc(NUMBER_OF_TRANSACTIONS, -1)
.inc(SUSPENDED_AMOUNT_CENTS, -accruedAmountCents)
.inc(NUMBER_OF_TRANSACTIONS_SUSPENDED, -1)
.inc(NUMBER_OF_TRANSACTIONS_ELABORATED, -1)
.set(RewardBatch.Fields.updateDate, LocalDateTime.now());

Update incNew = new Update()
.inc(INITIAL_AMOUNT_CENTS, accruedAmountCents)
.inc(NUMBER_OF_TRANSACTIONS, 1)
.inc(SUSPENDED_AMOUNT_CENTS, accruedAmountCents)
.inc(NUMBER_OF_TRANSACTIONS_SUSPENDED, 1)
.inc(NUMBER_OF_TRANSACTIONS_ELABORATED, 1)
.set(RewardBatch.Fields.updateDate, LocalDateTime.now());

return mongoTemplate.findAndModify(
Query.query(Criteria.where("_id").is(oldBatchId)),
decOld,
FindAndModifyOptions.options().returnNew(true),
RewardBatch.class
)
.switchIfEmpty(Mono.error(new ClientExceptionNoBody(HttpStatus.BAD_REQUEST, REWARD_BATCH_NOT_FOUND)))
.then(mongoTemplate.findAndModify(
Query.query(Criteria.where("_id").is(newBatchId)),
incNew,
FindAndModifyOptions.options().returnNew(true),
RewardBatch.class
))
.switchIfEmpty(Mono.error(new ClientExceptionNoBody(HttpStatus.BAD_REQUEST, REWARD_BATCH_NOT_FOUND)));
}


private Criteria buildCombinedCriteria(String merchantId, String status, String assigneeLevel, String month, boolean isOperator) {
List<Criteria> subCriteria = new ArrayList<>();

Expand Down Expand Up @@ -256,6 +222,12 @@ public Mono<RewardBatch> updateTotals(String rewardBatchId, BatchCountersDTO acc
if (acc.getSuspendedAmountCents() != 0) {
update.inc(RewardBatch.Fields.suspendedAmountCents, acc.getSuspendedAmountCents());
}
if (acc.getInitialAmountCents() != 0) {
update.inc(RewardBatch.Fields.initialAmountCents, acc.getInitialAmountCents());
}
if (acc.getNumberOfTransactions() != 0) {
update.inc(RewardBatch.Fields.numberOfTransactions, acc.getNumberOfTransactions());
}

update.currentDate(RewardBatch.Fields.updateDate);

Expand Down
Loading
Loading