|
@@ -1,23 +1,35 @@
|
|
|
package com.ydtech.modules.admin.service.impl;
|
|
package com.ydtech.modules.admin.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.modules.admin.dao.DeptBalanceMapper;
|
|
import com.ydtech.modules.admin.dao.DeptBalanceMapper;
|
|
|
|
|
+import com.ydtech.modules.admin.dao.SysPartnerMapper;
|
|
|
|
|
+import com.ydtech.modules.admin.dao.SysRelationPersonMapper;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysAgencyLeader;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysPartner;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysRelationPerson;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysUser;
|
|
|
import com.ydtech.modules.admin.model.dto.DeptBalanceDto;
|
|
import com.ydtech.modules.admin.model.dto.DeptBalanceDto;
|
|
|
-import com.ydtech.modules.admin.model.dto.EsmUserReferrerDTO;
|
|
|
|
|
-import com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto;
|
|
|
|
|
|
|
+import com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto;
|
|
|
import com.ydtech.modules.admin.model.vo.DeptBalanceVo;
|
|
import com.ydtech.modules.admin.model.vo.DeptBalanceVo;
|
|
|
|
|
+import com.ydtech.modules.admin.model.vo.PartnerBalanceVo;
|
|
|
|
|
+import com.ydtech.modules.admin.model.vo.SysAmountAuditingVo;
|
|
|
|
|
+import com.ydtech.modules.admin.model.vo.SysUserVO;
|
|
|
import com.ydtech.modules.admin.service.DeptBalanceService;
|
|
import com.ydtech.modules.admin.service.DeptBalanceService;
|
|
|
import com.ydtech.modules.admin.service.SysAgencyLeaderService;
|
|
import com.ydtech.modules.admin.service.SysAgencyLeaderService;
|
|
|
|
|
+import com.ydtech.modules.admin.service.SysAmountAuditingService;
|
|
|
|
|
+import com.ydtech.modules.admin.service.SysUserService;
|
|
|
import com.ydtech.modules.base.model.vo.PageVo;
|
|
import com.ydtech.modules.base.model.vo.PageVo;
|
|
|
-import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesSumEntity;
|
|
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
|
|
+import com.ydtech.modules.order.service.InsOrdersService;
|
|
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -29,12 +41,22 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeptBalanceMapper deptBalanceMapper;
|
|
private DeptBalanceMapper deptBalanceMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysRelationPersonMapper sysRelationPersonMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysPartnerMapper sysPartnerMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InsOrdersService insOrdersService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserService sysUserService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysAmountAuditingService sysAmountAuditingService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @version
|
|
|
|
|
- * @author: whp
|
|
|
|
|
- * @Date: 2024/08/14 9:04
|
|
|
|
|
- * @Description: 机构负责人统计
|
|
|
|
|
|
|
+ * @version
|
|
|
|
|
+ * @author: whp
|
|
|
|
|
+ * @Date: 2024/08/14 9:04
|
|
|
|
|
+ * @Description: 机构负责人统计
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public HttpResult<IPage<DeptBalanceDto>> queryDeptLeaderStatistics(DeptBalanceVo deptBalanceVo) {
|
|
public HttpResult<IPage<DeptBalanceDto>> queryDeptLeaderStatistics(DeptBalanceVo deptBalanceVo) {
|
|
@@ -51,4 +73,187 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @version
|
|
|
|
|
+ * @author: whp
|
|
|
|
|
+ * @Date: 2024/08/23 9:04
|
|
|
|
|
+ * @Description: 合伙人统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult<IPage<SysPartnerConsoleDto>> queryPartnerStatistics(DeptBalanceVo deptBalanceVo) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ PageVo<SysPartnerConsoleDto> pageVo = new PageVo<>();
|
|
|
|
|
+ Page page = new Page(deptBalanceVo.getPageNum(), deptBalanceVo.getPageSize());
|
|
|
|
|
+ pageVo.setPageNum(deptBalanceVo.getPageNum());
|
|
|
|
|
+ pageVo.setPageSize(deptBalanceVo.getPageSize());
|
|
|
|
|
+ SysUser sysUserQuery = new SysUser();
|
|
|
|
|
+ sysUserQuery.setDeptId(deptBalanceVo.getDeptId());
|
|
|
|
|
+ List<SysUserVO> listByDeptIdUser = this.sysUserService.findListByDeptIdNew(sysUserQuery);
|
|
|
|
|
+ List<String> userListDept = listByDeptIdUser.stream().map(SysUserVO::getId).collect(Collectors.toList());
|
|
|
|
|
+ if (userListDept.isEmpty()) {
|
|
|
|
|
+ userListDept.add("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ deptBalanceVo.setUserIdList(userListDept);
|
|
|
|
|
+ IPage<SysPartnerConsoleDto> sysPartnersPage = sysPartnerMapper.queryPage(page, deptBalanceVo);
|
|
|
|
|
+
|
|
|
|
|
+ List<SysPartnerConsoleDto> sysPartners = sysPartnersPage.getRecords();
|
|
|
|
|
+ for (SysPartnerConsoleDto item : sysPartners) {
|
|
|
|
|
+ BigDecimal allTotalIncome = BigDecimal.ZERO; // 总保费
|
|
|
|
|
+ BigDecimal allDeptManagementFee = BigDecimal.ZERO;//机构管理费
|
|
|
|
|
+ BigDecimal allWithdrawn = BigDecimal.ZERO;//已体现
|
|
|
|
|
+ BigDecimal allNotWithdrawn = BigDecimal.ZERO;//未提现
|
|
|
|
|
+// 查询机构负责人
|
|
|
|
|
+ List<SysRelationPerson> byUserIdList = this.sysRelationPersonMapper.getByAgencyLeaderId(item.getUserId());
|
|
|
|
|
+ List<String> collect = byUserIdList.stream().map(SysRelationPerson::getAgencyLeaderId).collect(Collectors.toList());
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+// 机构负责人
|
|
|
|
|
+ List<SysAgencyLeader> deptLeader = sysAgencyLeaderService.getByUserIdList(collect);
|
|
|
|
|
+ for (SysAgencyLeader itemLeader : deptLeader) {
|
|
|
|
|
+ String deptId = itemLeader.getDeptId();
|
|
|
|
|
+ if (StringUtils.isNotEmpty(deptId)) {
|
|
|
|
|
+ HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getByDeptId(deptId);
|
|
|
|
|
+ if (orderAmount != null && !orderAmount.isEmpty()) {
|
|
|
|
|
+ allTotalIncome = this.calculateTotal(orderAmount.get("totalIncome"), allTotalIncome, null); // 总保费
|
|
|
|
|
+ allDeptManagementFee = this.calculateTotal(orderAmount.get("deptManagementFee"), allDeptManagementFee, null);//机构管理费
|
|
|
|
|
+ }
|
|
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
|
|
+ sysUser.setDeptId(deptId);
|
|
|
|
|
+// 机构下的userId
|
|
|
|
|
+ List<SysUserVO> listByDeptId = sysUserService.findListByDeptId(sysUser);
|
|
|
|
|
+ List<String> institutionId = listByDeptId.stream().map(SysUserVO::getId).collect(Collectors.toList());
|
|
|
|
|
+// 已提现
|
|
|
|
|
+ SysAmountAuditingVo sysAmountAuditingVo = new SysAmountAuditingVo();
|
|
|
|
|
+ sysAmountAuditingVo.setUserIdList(institutionId);
|
|
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("3");
|
|
|
|
|
+ BigDecimal withdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
|
|
|
|
|
+ allWithdrawn = this.calculateTotal(withdrawn, allWithdrawn, null);
|
|
|
|
|
+// 未提现
|
|
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("2");
|
|
|
|
|
+ BigDecimal notWithdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
|
|
|
|
|
+ allNotWithdrawn = this.calculateTotal(notWithdrawn, allNotWithdrawn, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ item.setTotalIncome(allTotalIncome);
|
|
|
|
|
+ item.setDeptManagementFee(allDeptManagementFee);
|
|
|
|
|
+ item.setWithdrawn(allWithdrawn);
|
|
|
|
|
+ item.setNotWithdrawn(allNotWithdrawn);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.ok(sysPartnersPage);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return HttpResult.error("查询异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> recursion(String userId) {
|
|
|
|
|
+ QueryWrapper<SysRelationPerson> objectQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
+// 合伙人
|
|
|
|
|
+ QueryWrapper<SysRelationPerson> sysRelationPerson = objectQueryWrapper.eq("suggest_id", userId)
|
|
|
|
|
+ .eq("type", "0");
|
|
|
|
|
+ List<SysRelationPerson> sysRelationPeople = this.sysRelationPersonMapper.selectList(sysRelationPerson);
|
|
|
|
|
+ List<String> collect = sysRelationPeople.stream().map(SysRelationPerson::getAgencyLeaderId).collect(Collectors.toList());
|
|
|
|
|
+ collect.add(userId);
|
|
|
|
|
+
|
|
|
|
|
+ return collect;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
|
|
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
|
|
+
|
|
|
|
|
+ if (value1 != null) {
|
|
|
|
|
+ total = total.add(value1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (value2 != null) {
|
|
|
|
|
+ total = total.add(value2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (value3 != null) {
|
|
|
|
|
+ total = total.add(value3);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return total;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @version
|
|
|
|
|
+ * @author: whp
|
|
|
|
|
+ * @Date: 2024/08/26
|
|
|
|
|
+ * @Description: 机构树形
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<SysPartnerConsoleDto> getTreeDeptUser(PartnerBalanceVo deptBalanceVo) {
|
|
|
|
|
+// 所有最上级合伙人
|
|
|
|
|
+ List<SysPartnerConsoleDto> result = sysPartnerMapper.getTreeDeptUser(deptBalanceVo);
|
|
|
|
|
+// 合伙人的下级
|
|
|
|
|
+ for (SysPartnerConsoleDto item : result) {
|
|
|
|
|
+ this.treeRecursion(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void treeRecursion(SysPartnerConsoleDto item) {
|
|
|
|
|
+ String userId = item.getUserId();
|
|
|
|
|
+ if (StringUtils.isNotEmpty(userId)) {
|
|
|
|
|
+// 合伙人
|
|
|
|
|
+ SysPartnerConsoleDto sysPartnerConsoleDto = new SysPartnerConsoleDto();
|
|
|
|
|
+ sysPartnerConsoleDto.setUserId(userId);
|
|
|
|
|
+ sysPartnerConsoleDto.setType("0");
|
|
|
|
|
+ List<SysPartnerConsoleDto> sysPartnerList = this.sysRelationPersonMapper.getBySuggestId(sysPartnerConsoleDto);
|
|
|
|
|
+ item.setChildrenList(sysPartnerList);
|
|
|
|
|
+// 机构负责人
|
|
|
|
|
+ sysPartnerConsoleDto.setType("1");
|
|
|
|
|
+ List<SysPartnerConsoleDto> sysHeadList = this.sysRelationPersonMapper.getBySuggestId(sysPartnerConsoleDto);
|
|
|
|
|
+ List<SysPartnerConsoleDto> childrenList = item.getChildrenList();
|
|
|
|
|
+ childrenList.addAll(sysHeadList);
|
|
|
|
|
+ if (!sysPartnerList.isEmpty()) {
|
|
|
|
|
+ for (SysPartnerConsoleDto sysPartnerItem : sysPartnerList) {
|
|
|
|
|
+ this.treeRecursion(sysPartnerItem);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @version
|
|
|
|
|
+ * @author: whp
|
|
|
|
|
+ * @Date: 2024/08/26
|
|
|
|
|
+ * @Description: 钱包代理人
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<SysPartnerConsoleDto> getWalletAgent(DeptBalanceVo deptBalanceVo) {
|
|
|
|
|
+ PageVo<SysPartnerConsoleDto> pageVo = new PageVo<>();
|
|
|
|
|
+ Page page = new Page(deptBalanceVo.getPageNum(), deptBalanceVo.getPageSize());
|
|
|
|
|
+ pageVo.setPageNum(deptBalanceVo.getPageNum());
|
|
|
|
|
+ pageVo.setPageSize(deptBalanceVo.getPageSize());
|
|
|
|
|
+ IPage<SysPartnerConsoleDto> sysUserListPage = deptBalanceMapper.getWalletAgent(page, deptBalanceVo);
|
|
|
|
|
+ List<SysPartnerConsoleDto> records = sysUserListPage.getRecords();
|
|
|
|
|
+ if (!records.isEmpty()) {
|
|
|
|
|
+ for (SysPartnerConsoleDto record : records) {
|
|
|
|
|
+ String userId = record.getUserId();
|
|
|
|
|
+ HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getWalletAgentAmount(userId);
|
|
|
|
|
+// 总金额
|
|
|
|
|
+ if (orderAmount != null && !orderAmount.isEmpty()) {
|
|
|
|
|
+ record.setTotalIncome(orderAmount.get("totalIncome"));
|
|
|
|
|
+ }
|
|
|
|
|
+// 已提现
|
|
|
|
|
+ SysAmountAuditingVo sysAmountAuditingVo = new SysAmountAuditingVo();
|
|
|
|
|
+ sysAmountAuditingVo.setUserId(userId);
|
|
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("3");
|
|
|
|
|
+ BigDecimal withdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
|
|
|
|
|
+ record.setWithdrawn(withdrawn);
|
|
|
|
|
+// 未提现
|
|
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("2");
|
|
|
|
|
+ BigDecimal notWithdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
|
|
|
|
|
+ record.setNotWithdrawn(notWithdrawn);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return sysUserListPage;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|