|
@@ -0,0 +1,101 @@
|
|
|
+package com.fjhx.fundAccount.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fjhx.company.entity.Company;
|
|
|
+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.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.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class FundAccountIntercourseServiceImpl implements IFundAccountIntercourseService {
|
|
|
+ @Autowired
|
|
|
+ private IFundAccountDetailService fundAccountDetailService;
|
|
|
+ @Autowired
|
|
|
+ private IFundAccountService fundAccountService;
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+
|
|
|
+ @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());
|
|
|
+ }
|
|
|
+
|
|
|
+ @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");
|
|
|
+ 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);
|
|
|
+
|
|
|
+ Set accountSet = companyMap.get(byId.getCompanyId());
|
|
|
+ if (accountSet == null) {
|
|
|
+ accountSet = new HashSet<>();
|
|
|
+ }
|
|
|
+ accountSet.add(fromFundAccountId);
|
|
|
+ companyMap.put(byId.getCompanyId(), accountSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<String, Set<String>> entry : companyMap.entrySet()) {
|
|
|
+ System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
|
|
|
+ Company company = companyService.getById(entry.getKey());
|
|
|
+ Map map0 = new HashMap();
|
|
|
+ map0.put("companyName", company.getNameChinese());
|
|
|
+
|
|
|
+ //遍历公司下的资产账户
|
|
|
+ List list1 = new ArrayList();
|
|
|
+ for (String fromFundAccountId : entry.getValue()) {
|
|
|
+ FundAccount byId = fundAccountService.getById(fromFundAccountId);
|
|
|
+ //------------------------------------------
|
|
|
+ List<FundAccountIntercourse> fundAccountIntercourses1 = new ArrayList<>();
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|