|
@@ -1,20 +1,23 @@
|
|
|
package com.fjhx.fundAccount.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.fjhx.company.entity.Company;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fjhx.company.entity.CompanyBasics;
|
|
|
import com.fjhx.company.service.ICompanyBasicsService;
|
|
|
-import com.fjhx.company.service.ICompanyService;
|
|
|
import com.fjhx.fundAccount.FundAccount;
|
|
|
import com.fjhx.fundAccount.FundAccountDetail;
|
|
|
import com.fjhx.fundAccount.entity.FundAccountIntercourse;
|
|
|
+import com.fjhx.fundAccount.entity.MyCompanyBasics;
|
|
|
+import com.fjhx.fundAccount.entity.MyFundAccount;
|
|
|
import com.fjhx.fundAccount.service.IFundAccountDetailService;
|
|
|
import com.fjhx.fundAccount.service.IFundAccountIntercourseService;
|
|
|
import com.fjhx.fundAccount.service.IFundAccountService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class FundAccountIntercourseServiceImpl implements IFundAccountIntercourseService {
|
|
@@ -23,83 +26,59 @@ public class FundAccountIntercourseServiceImpl implements IFundAccountIntercours
|
|
|
@Autowired
|
|
|
private IFundAccountService fundAccountService;
|
|
|
@Autowired
|
|
|
- private ICompanyService companyService;
|
|
|
- @Autowired
|
|
|
private ICompanyBasicsService companyBasicsService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public double getMoney(int type, String fromFundAccountId, String toAccountName) {
|
|
|
- QueryWrapper wrapper2 = new QueryWrapper();
|
|
|
- wrapper2.select("sum(money) as money_sum");
|
|
|
- wrapper2.eq("type", type);
|
|
|
- wrapper2.eq("capital_matter ", "45");
|
|
|
- wrapper2.eq("from_fund_account_id ", fromFundAccountId);
|
|
|
- wrapper2.eq("account_name", toAccountName);
|
|
|
- Map map = fundAccountDetailService.getMap(wrapper2);
|
|
|
- return map == null ? 0 : Double.parseDouble(map.get("money_sum").toString());
|
|
|
+ public BigDecimal getMoney(int type, List<FundAccountDetail> fundAccountDetailList, FundAccountDetail fundAccountDetail) {
|
|
|
+ BigDecimal money = fundAccountDetailList.stream().filter(item -> Objects.equals(item.getType(), type))
|
|
|
+ .filter(item -> Objects.equals(item.getFromFundAccountId(), fundAccountDetail.getFromFundAccountId()))
|
|
|
+ .filter(item -> Objects.equals(item.getAccountName(), fundAccountDetail.getAccountName()))
|
|
|
+ .map(FundAccountDetail::getMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return money;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List getFundAccountIntercourse() {
|
|
|
- List data = new ArrayList();
|
|
|
- Map<String, Set<String>> companyMap = new HashMap();
|
|
|
-
|
|
|
- QueryWrapper wrapper = new QueryWrapper();
|
|
|
- wrapper.select("distinct from_fund_account_id");
|
|
|
+ QueryWrapper<FundAccountDetail> wrapper = Wrappers.query();
|
|
|
wrapper.eq("capital_matter ", "45");
|
|
|
- //获取所有有往来款的资产账户对应的公司并分组
|
|
|
- List<FundAccountDetail> list = fundAccountDetailService.list(wrapper);
|
|
|
- for (FundAccountDetail fundAccountDetail : list) {
|
|
|
- List<FundAccountIntercourse> fundAccountIntercourses = new ArrayList<>();
|
|
|
- String fromFundAccountId = fundAccountDetail.getFromFundAccountId();
|
|
|
- FundAccount byId = fundAccountService.getById(fromFundAccountId);
|
|
|
+ //所有往来款记录
|
|
|
+ List<FundAccountDetail> fundAccountDetailList = fundAccountDetailService.list(wrapper);
|
|
|
+ //所有往来款记录账户信息
|
|
|
+ List<FundAccount> fundAccounts = fundAccountService.listByIds(fundAccountDetailList.stream().map(FundAccountDetail::getFromFundAccountId).distinct().collect(Collectors.toList()));
|
|
|
+ //所有往来款记录账户对应的公司信息
|
|
|
+ List<CompanyBasics> companyBasicss = companyBasicsService.listByIds(fundAccounts.stream().map(FundAccount::getCompanyId).distinct().collect(Collectors.toList()));
|
|
|
|
|
|
- Set accountSet = companyMap.get(byId.getCompanyId());
|
|
|
- if (accountSet == null) {
|
|
|
- accountSet = new HashSet<>();
|
|
|
- }
|
|
|
- accountSet.add(fromFundAccountId);
|
|
|
- companyMap.put(byId.getCompanyId(), accountSet);
|
|
|
- }
|
|
|
+ //将所有往来款根据账户id分组
|
|
|
+ Map<String, List<FundAccountIntercourse>> fundAccountDetailFromAccountIdList = fundAccountDetailList.stream().map(fundAccountDetail -> {
|
|
|
+ FundAccountIntercourse fundAccountIntercourse = new FundAccountIntercourse();
|
|
|
+ fundAccountIntercourse.setAccountName(fundAccountDetail.getAccountName());
|
|
|
+ fundAccountIntercourse.setIncome(getMoney(1,fundAccountDetailList,fundAccountDetail));
|
|
|
+ fundAccountIntercourse.setExpend(getMoney(2,fundAccountDetailList,fundAccountDetail));
|
|
|
+ fundAccountIntercourse.setSurplus(fundAccountIntercourse.getIncome().subtract(fundAccountIntercourse.getExpend()));
|
|
|
+ fundAccountIntercourse.setFromFundAccountId(fundAccountDetail.getFromFundAccountId());
|
|
|
+ return fundAccountIntercourse;
|
|
|
+ }).collect(Collectors.groupingBy(FundAccountIntercourse::getFromFundAccountId));
|
|
|
|
|
|
- for (Map.Entry<String, Set<String>> entry : companyMap.entrySet()) {
|
|
|
- CompanyBasics company = companyBasicsService.getById(entry.getKey());
|
|
|
-// Company company = companyBasicsService.getById(entry.getKey());
|
|
|
- Map map0 = new HashMap();
|
|
|
- map0.put("companyName", company.getNameChinese());
|
|
|
+ //将所有往来款账户根据公司id分组
|
|
|
+ Map<String, List<MyFundAccount>> fundAccountDetailFromCompanyIdList = fundAccounts.stream().map(fundAccount -> {
|
|
|
+ MyFundAccount myFundAccount = new MyFundAccount();
|
|
|
+ myFundAccount.setName(fundAccount.getName());
|
|
|
+ myFundAccount.setList(fundAccountDetailFromAccountIdList.get(fundAccount.getId()));
|
|
|
+ myFundAccount.setCompanyId(fundAccount.getCompanyId());
|
|
|
+ return myFundAccount;
|
|
|
+ }).collect(Collectors.groupingBy(MyFundAccount::getCompanyId));
|
|
|
|
|
|
- //遍历公司下的资产账户
|
|
|
- List list1 = new ArrayList();
|
|
|
- for (String fromFundAccountId : entry.getValue()) {
|
|
|
- FundAccount byId = fundAccountService.getById(fromFundAccountId);
|
|
|
- //------------------------------------------
|
|
|
- List<FundAccountIntercourse> fundAccountIntercourses1 = new ArrayList<>();
|
|
|
+ //将往来款所有信息组成树状
|
|
|
+ List<MyCompanyBasics> data = companyBasicss.stream().map(companyBasics -> {
|
|
|
+ MyCompanyBasics myCompanyBasics = new MyCompanyBasics();
|
|
|
+ myCompanyBasics.setCompanyName(companyBasics.getNameChinese());
|
|
|
+ myCompanyBasics.setList(fundAccountDetailFromCompanyIdList.get(companyBasics.getId()));
|
|
|
+ return myCompanyBasics;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
- QueryWrapper wrapper00 = new QueryWrapper();
|
|
|
- wrapper00.eq("capital_matter ", "45");
|
|
|
- wrapper00.eq("from_fund_account_id ", fromFundAccountId);
|
|
|
- wrapper00.groupBy("account_name");
|
|
|
- //根据资金账户查找往来账户
|
|
|
- List<FundAccountDetail> list00 = fundAccountDetailService.list(wrapper00);
|
|
|
- for (FundAccountDetail fundAccountDetail00 : list00) {
|
|
|
- FundAccountIntercourse fundAccountIntercourse = new FundAccountIntercourse();
|
|
|
- fundAccountIntercourse.setAccountName(fundAccountDetail00.getAccountName());
|
|
|
- fundAccountIntercourse.setIncome(getMoney(1, fromFundAccountId, fundAccountDetail00.getAccountName()));
|
|
|
- fundAccountIntercourse.setExpend(getMoney(2, fromFundAccountId, fundAccountDetail00.getAccountName()));
|
|
|
- fundAccountIntercourse.setSurplus(fundAccountIntercourse.getIncome() - fundAccountIntercourse.getExpend());
|
|
|
- fundAccountIntercourses1.add(fundAccountIntercourse);
|
|
|
- }
|
|
|
- //------------------------------------------
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("name", byId.getName());//资产账号名
|
|
|
- map.put("list", fundAccountIntercourses1);//对方账号列表
|
|
|
- list1.add(map);
|
|
|
- }
|
|
|
- map0.put("list", list1);
|
|
|
- data.add(map0);
|
|
|
- }
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|