|
@@ -16,7 +16,6 @@ import com.fjhx.account.service.account.StatementService;
|
|
|
import com.fjhx.common.entity.corporation.po.Corporation;
|
|
|
import com.fjhx.common.service.corporation.CorporationService;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
-import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -44,6 +43,13 @@ public class StatementServiceImpl implements StatementService {
|
|
|
@Override
|
|
|
public List<CapitalDailyVo> getCapitalDaily(CapitalDailyDto dto) {
|
|
|
|
|
|
+ List<CapitalDailyBo> capitalDailyBoList = getCapitalDailyBoList(dto);
|
|
|
+
|
|
|
+ // 格式化成vo
|
|
|
+ return formatVo(capitalDailyBoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CapitalDailyBo> getCapitalDailyBoList(CapitalDailyDto dto) {
|
|
|
Date beginDate, endDate;
|
|
|
|
|
|
Date date = new Date();
|
|
@@ -95,9 +101,124 @@ public class StatementServiceImpl implements StatementService {
|
|
|
|
|
|
// 赋值收支流水明细
|
|
|
setRunningWaterDetail(capitalDailyBoList, endDate, runningWaterList);
|
|
|
+ return capitalDailyBoList;
|
|
|
+ }
|
|
|
|
|
|
- // 格式化成vo
|
|
|
- return formatVo(capitalDailyBoList);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有账户统计
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CapitalDailyVo.Currency> getCurrencyList(CapitalDailyDto dto) {
|
|
|
+ List<CapitalDailyBo> capitalDailyBoList = getCapitalDailyBoList(dto);
|
|
|
+
|
|
|
+ //将结果根据币种分组
|
|
|
+ List<CapitalDailyVo.Currency> currencyList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String, List<CapitalDailyBo>> capitalDailyBoMap = capitalDailyBoList.stream().collect(Collectors.groupingBy(CapitalDailyBo::getCurrencyType));
|
|
|
+ for (Map.Entry<String, List<CapitalDailyBo>> entry : capitalDailyBoMap.entrySet()) {
|
|
|
+ List<CapitalDailyBo> value = entry.getValue();
|
|
|
+ List<Map<String, Object>> flowingWaterList = new ArrayList<>();
|
|
|
+ value.forEach(item -> flowingWaterList.addAll(item.getFlowingWaterList()));
|
|
|
+
|
|
|
+ Map<Integer, Map<String, Object>> map = new HashMap<>();
|
|
|
+ for (Map<String, Object> stringObjectMap : flowingWaterList) {
|
|
|
+ BigDecimal income = (BigDecimal) stringObjectMap.getOrDefault("income", BigDecimal.ZERO);
|
|
|
+ BigDecimal expenditure = (BigDecimal) stringObjectMap.getOrDefault("expenditure", BigDecimal.ZERO);
|
|
|
+ BigDecimal balance = (BigDecimal) stringObjectMap.getOrDefault("balance", BigDecimal.ZERO);
|
|
|
+
|
|
|
+ Integer day = (Integer) stringObjectMap.getOrDefault("day", 0);
|
|
|
+ Map<String, Object> dataItem = map.getOrDefault(day, new HashMap<>());
|
|
|
+ dataItem.put("income", ((BigDecimal) dataItem.getOrDefault("income", BigDecimal.ZERO)).add(income));
|
|
|
+ dataItem.put("expenditure", ((BigDecimal) dataItem.getOrDefault("expenditure", BigDecimal.ZERO)).add(expenditure));
|
|
|
+ dataItem.put("balance", ((BigDecimal) dataItem.getOrDefault("balance", BigDecimal.ZERO)).add(balance));
|
|
|
+ dataItem.put("day", day);
|
|
|
+ map.put(day, dataItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ CapitalDailyVo.Currency currency = new CapitalDailyVo.Currency();
|
|
|
+ currency.setCurrencyType(entry.getKey());
|
|
|
+ currency.setFlowingWaterList(map.values().stream().collect(Collectors.toList()));
|
|
|
+
|
|
|
+ currencyList.add(currency);
|
|
|
+ }
|
|
|
+
|
|
|
+ return currencyList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getTotalList(CapitalDailyDto dto) {
|
|
|
+ Date beginDate, endDate;
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ try {
|
|
|
+ Date parse = DateUtil.parse(dto.getDateBetween(), "yyyy-MM");
|
|
|
+ if (parse.after(DateUtil.endOfMonth(date))) {
|
|
|
+ throw new ServiceException("统计日期不能大于本月");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean sameMonth = DateUtil.isSameMonth(parse, date);
|
|
|
+
|
|
|
+ beginDate = DateUtil.beginOfMonth(parse);
|
|
|
+ endDate = sameMonth ? DateUtil.endOfDay(date) : DateUtil.endOfMonth(parse);
|
|
|
+ } catch (DateException dateException) {
|
|
|
+ throw new ServiceException("范围期间日期格式错误,应为 'yyyy-MM' 格式");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取归属公司
|
|
|
+ List<Corporation> corporationList = getCorporationList(dto.getCorporationId());
|
|
|
+ if (corporationList.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取账户
|
|
|
+ List<AccountManagement> managementList = getManagementList(dto.getManagementId(), corporationList);
|
|
|
+ if (managementList.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询流水记录
|
|
|
+ List<AccountRunningWater> runningWaterList = getRunningWaterList(beginDate, managementList);
|
|
|
+
|
|
|
+ List<CapitalDailyBo> capitalDailyBoList = getCapitalDailyBoList(dto);
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, BigDecimal> balanceMap = new HashMap<>();
|
|
|
+ for (CapitalDailyBo capitalDailyBo : capitalDailyBoList) {
|
|
|
+ BigDecimal balance = balanceMap.getOrDefault(capitalDailyBo.getCurrencyType(), BigDecimal.ZERO);
|
|
|
+ balanceMap.put(capitalDailyBo.getCurrencyType(), balance.add(capitalDailyBo.getRemainder()));
|
|
|
+
|
|
|
+
|
|
|
+ List<AccountRunningWater> itemRunningWaterList = runningWaterList.stream().filter(item -> Objects.equals(item.getCurrency(), capitalDailyBo.getCurrencyType())).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ //收入
|
|
|
+ BigDecimal income = itemRunningWaterList.stream()
|
|
|
+ .filter(item -> item.getTransactionTime().before(endDate))
|
|
|
+ .filter(item -> Objects.equals(item.getStatus(), "10"))
|
|
|
+ .map(AccountRunningWater::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ BigDecimal expenditure = itemRunningWaterList.stream()
|
|
|
+ .filter(item -> item.getTransactionTime().before(endDate))
|
|
|
+ .filter(item -> Objects.equals(item.getStatus(), "20"))
|
|
|
+ .map(AccountRunningWater::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+
|
|
|
+ //支出
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ map1.put("balance", balanceMap.getOrDefault(capitalDailyBo.getCurrencyType(), BigDecimal.ZERO).add(income).subtract(expenditure));
|
|
|
+ map1.put("income", income);
|
|
|
+ map1.put("expenditure", expenditure);
|
|
|
+ map1.put("currency", capitalDailyBo.getCurrencyType());
|
|
|
+
|
|
|
+ mapList.add(map1);
|
|
|
+ }
|
|
|
+ return mapList;
|
|
|
}
|
|
|
|
|
|
/**
|