|
@@ -13,7 +13,11 @@ import jakarta.annotation.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -34,7 +38,51 @@ public class CapitalTransactionsServiceImpl implements CapitalTransactionsServic
|
|
|
|
|
|
@Override
|
|
|
public Page<CapitalTransactionsVo> getPage(CapitalTransactionsSelectDto dto) {
|
|
|
- return capitalTransactionsDao.getPage(dto);
|
|
|
+ Page<CapitalTransactionsVo> page = capitalTransactionsDao.getPage(dto);
|
|
|
+ List<CapitalTransactionsVo> records = page.getRecords();
|
|
|
+
|
|
|
+ Map<Long, Date> map = new HashMap<>();
|
|
|
+ Map<Long, BigDecimal> map2 = new HashMap<>();
|
|
|
+ Map<Long, Long> map3 = new HashMap<>();
|
|
|
+ records.forEach(item -> {
|
|
|
+ map.computeIfAbsent(item.getCapitalAccountId(), k -> item.getTradingTime());
|
|
|
+ map2.computeIfAbsent(item.getCapitalAccountId(), k -> item.getBalance());
|
|
|
+ map3.computeIfAbsent(item.getCapitalAccountId(), k -> item.getId());
|
|
|
+ });
|
|
|
+
|
|
|
+ map2.keySet().forEach(item -> {
|
|
|
+
|
|
|
+ List<CapitalTransactions> list = capitalTransactionsDao.list(q -> q
|
|
|
+ .eq(CapitalTransactions::getCapitalAccountId, item)
|
|
|
+ .orderByDesc(CapitalTransactions::getTradingTime)
|
|
|
+ .orderByDesc(CapitalTransactions::getId)
|
|
|
+ .ge(CapitalTransactions::getTradingTime, map.get(item))
|
|
|
+ );
|
|
|
+
|
|
|
+ BigDecimal decimal = BigDecimal.ZERO;
|
|
|
+ for (CapitalTransactions capitalTransactions : list) {
|
|
|
+ if (capitalTransactions.getId().equals(map3.get(item))) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (capitalTransactions.getType() == 0) {
|
|
|
+ decimal = decimal.add(capitalTransactions.getAmount());
|
|
|
+ } else {
|
|
|
+ decimal = decimal.subtract(capitalTransactions.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ decimal = map2.get(item).add(decimal);
|
|
|
+
|
|
|
+ for (CapitalTransactionsVo record : records) {
|
|
|
+ if (record.getCapitalAccountId().equals(item)) {
|
|
|
+ record.setDateAmount(decimal);
|
|
|
+ decimal = record.getType() == 0 ? decimal.add(record.getAmount()) : decimal.subtract(record.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
@Override
|