|
|
@@ -1,20 +1,38 @@
|
|
|
package com.ydtech.modules.admin.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ydtech.constants.enums.dict.DictionaryManagement;
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.modules.admin.dao.SysDeptMapper;
|
|
|
import com.ydtech.modules.admin.dao.SysUserMapper;
|
|
|
import com.ydtech.modules.admin.model.SysDept;
|
|
|
import com.ydtech.modules.admin.model.SysUser;
|
|
|
+import com.ydtech.modules.admin.model.dto.EmployeeIncreaseReportDto;
|
|
|
+import com.ydtech.modules.admin.model.dto.EsmUserReferrerDTO;
|
|
|
+import com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto;
|
|
|
import com.ydtech.modules.admin.model.dto.ReportDto;
|
|
|
import com.ydtech.modules.admin.model.report.user.*;
|
|
|
import com.ydtech.modules.admin.model.vo.HouLinePersonnelReportVo;
|
|
|
+import com.ydtech.modules.admin.model.vo.QxFrontlineAgentVo;
|
|
|
import com.ydtech.modules.admin.service.UserReportService;
|
|
|
+import com.ydtech.modules.base.model.vo.PageVo;
|
|
|
+import com.ydtech.modules.esm.dao.EsmUserReferrerMapper;
|
|
|
+import com.ydtech.modules.esm.model.EsmUserReferrer;
|
|
|
+import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesSumEntity;
|
|
|
+import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
|
|
|
+import com.ydtech.modules.order.service.InsAreaCompanyService;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @version
|
|
|
@@ -31,6 +49,12 @@ public class UserReportServiceImpl implements UserReportService {
|
|
|
@Autowired
|
|
|
private SysUserMapper sysUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EsmUserReferrerMapper esmUserReferrerMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsAreaCompanyService insAreaCompanyService;
|
|
|
+
|
|
|
/**
|
|
|
* @version
|
|
|
* @author: hxl
|
|
|
@@ -147,6 +171,198 @@ public class UserReportServiceImpl implements UserReportService {
|
|
|
SysUser user =sysUserMapper.selectOne(lqw);
|
|
|
return user;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: whp
|
|
|
+ * @Date: 2024/8/07
|
|
|
+ * @Description: 人员统计-前线人员-代理人统计
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpResult<IPage<QxFrontlineAgentDto>> queryQxFrontlineAgent(QxFrontlineAgentVo qxFrontlineAgentVo) {
|
|
|
+ try {
|
|
|
+ PageVo<SettlementDocumentaryFeesSumEntity> pageVo = new PageVo<>();
|
|
|
+ Page page = new Page(qxFrontlineAgentVo.getPageNum(), qxFrontlineAgentVo.getPageSize());
|
|
|
+
|
|
|
+ pageVo.setPageNum(qxFrontlineAgentVo.getPageNum());
|
|
|
+ pageVo.setPageSize(qxFrontlineAgentVo.getPageSize());
|
|
|
+
|
|
|
+
|
|
|
+ IPage<QxFrontlineAgentDto> sysUserListPage = sysUserMapper.queryQxFrontlineAgent(page, qxFrontlineAgentVo);
|
|
|
+ List<QxFrontlineAgentDto> sysUserList = sysUserListPage.getRecords();
|
|
|
+
|
|
|
+ HashMap<String, Integer> humanResources = new HashMap<>();
|
|
|
+ HashMap<String, List<String>> humanResourcesIdList = new HashMap<>();
|
|
|
+
|
|
|
+// 关系表
|
|
|
+ List<EsmUserReferrerDTO> employeeIncreaseReportDtos = esmUserReferrerMapper.getbyUserNextLevel(null);
|
|
|
+ Map<String, EsmUserReferrerDTO> collect = employeeIncreaseReportDtos.stream().collect(Collectors.toMap(EsmUserReferrerDTO::getId, Function.identity()));
|
|
|
+ Set<String> visited = new HashSet<>();
|
|
|
+ for (EsmUserReferrerDTO item : employeeIncreaseReportDtos) {
|
|
|
+ Integer count = this.nextLevelUser(item.getId(), collect, visited);
|
|
|
+ humanResources.put(item.getId(), count);
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ humanResourcesIdList.put(item.getId(), this.nextLevelUserList(item.getId(), collect, visited, ids));
|
|
|
+
|
|
|
+ }
|
|
|
+ for (QxFrontlineAgentDto userItem : sysUserList) {
|
|
|
+ String userId = userItem.getUserId();
|
|
|
+// 总人力
|
|
|
+ if (humanResources.containsKey(userId)) {
|
|
|
+ if (ObjectUtils.isNotEmpty(humanResources.get(userId))) {
|
|
|
+ userItem.setTotalManpower(humanResources.get(userId).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //出单人力 + 总保费 +单均保费
|
|
|
+ if (humanResourcesIdList.containsKey(userId)) {
|
|
|
+ if (!CollectionUtils.isEmpty(humanResourcesIdList.get(userId))) {
|
|
|
+ //出单人力
|
|
|
+ List<String> ids = humanResourcesIdList.get(userId);
|
|
|
+ QxFrontlineAgentDto orderManpower = insAreaCompanyService.getOrderManpower(ids);
|
|
|
+ userItem.setOrderManpower(orderManpower.getOrderManpower());
|
|
|
+ userItem.setTotalPremium(orderManpower.getTotalPremium());
|
|
|
+ userItem.setAveragePremium(orderManpower.getAveragePremium());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.ok(sysUserListPage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return HttpResult.error("查询异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: whp
|
|
|
+ * @Date: 2024/8/07
|
|
|
+ * @Description: 人员统计-前线人员-代理人统计-团队排名
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<QxFrontlineAgentDto> queryQxFrontlineAgentRanking(QxFrontlineAgentVo qxFrontlineAgentVo) {
|
|
|
+
|
|
|
+ PageVo<SettlementDocumentaryFeesSumEntity> pageVo = new PageVo<>();
|
|
|
+ Page page = new Page(1, 50);
|
|
|
+
|
|
|
+ pageVo.setPageNum(1);
|
|
|
+ pageVo.setPageSize(50);
|
|
|
+
|
|
|
+
|
|
|
+ IPage<QxFrontlineAgentDto> sysUserListPage = sysUserMapper.queryQxFrontlineAgent(page, qxFrontlineAgentVo);
|
|
|
+ List<QxFrontlineAgentDto> sysUserList = sysUserListPage.getRecords();
|
|
|
+
|
|
|
+ HashMap<String, Integer> humanResources = new HashMap<>();
|
|
|
+ HashMap<String, List<String>> humanResourcesIdList = new HashMap<>();
|
|
|
+
|
|
|
+// 关系表
|
|
|
+ List<EsmUserReferrerDTO> employeeIncreaseReportDtos = esmUserReferrerMapper.getbyUserNextLevel(null);
|
|
|
+ Map<String, EsmUserReferrerDTO> collect = employeeIncreaseReportDtos.stream().collect(Collectors.toMap(EsmUserReferrerDTO::getId, Function.identity()));
|
|
|
+ Set<String> visited = new HashSet<>();
|
|
|
+ for (EsmUserReferrerDTO item : employeeIncreaseReportDtos) {
|
|
|
+ Integer count = this.nextLevelUser(item.getId(), collect, visited);
|
|
|
+ humanResources.put(item.getId(), count);
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ humanResourcesIdList.put(item.getId(), this.nextLevelUserList(item.getId(), collect, visited, ids));
|
|
|
+
|
|
|
+ }
|
|
|
+ for (QxFrontlineAgentDto userItem : sysUserList) {
|
|
|
+ String userId = userItem.getUserId();
|
|
|
+// 总人力
|
|
|
+ if (humanResources.containsKey(userId)) {
|
|
|
+ if (ObjectUtils.isNotEmpty(humanResources.get(userId))) {
|
|
|
+ userItem.setTotalManpower(humanResources.get(userId).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //出单人力 + 总保费 +单均保费
|
|
|
+ if (humanResourcesIdList.containsKey(userId)) {
|
|
|
+ if (!CollectionUtils.isEmpty(humanResourcesIdList.get(userId))) {
|
|
|
+ //出单人力
|
|
|
+ List<String> ids = humanResourcesIdList.get(userId);
|
|
|
+ QxFrontlineAgentDto orderManpower = insAreaCompanyService.getOrderManpower(ids);
|
|
|
+ userItem.setOrderManpower(orderManpower.getOrderManpower());
|
|
|
+ userItem.setTotalPremium(orderManpower.getTotalPremium());
|
|
|
+ userItem.setAveragePremium(orderManpower.getAveragePremium());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //排序
|
|
|
+ if(StringUtils.isNotEmpty(qxFrontlineAgentVo.getOrderSort())){
|
|
|
+// 人员
|
|
|
+ this.sortBy(qxFrontlineAgentVo.getOrderSort(),sysUserList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return sysUserList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sortBy(String orderSort,List<QxFrontlineAgentDto> sysUserList) {
|
|
|
+ Collections.sort(sysUserList, new Comparator<QxFrontlineAgentDto>() {
|
|
|
+ @Override
|
|
|
+ public int compare(QxFrontlineAgentDto o1, QxFrontlineAgentDto o2) {
|
|
|
+ // 假设name是String类型,直接使用String的compareTo方法
|
|
|
+ if("1".equals(orderSort)) { // 人员
|
|
|
+ return o1.getTotalManpower().compareTo(o2.getTotalManpower());
|
|
|
+
|
|
|
+ }else {
|
|
|
+ return o1.getTotalPremium().compareTo(o2.getTotalPremium());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param collect
|
|
|
+ * @param visited
|
|
|
+ * @return 获取所有用户人力的统计
|
|
|
+ */
|
|
|
+ private Integer nextLevelUser(String id, Map<String, EsmUserReferrerDTO> collect, Set<String> visited) {
|
|
|
+ if (visited.contains(id)) {
|
|
|
+ return 0; // 如果已经访问过,返回0
|
|
|
+ }
|
|
|
+ visited.add(id); // 标记为已访问
|
|
|
+
|
|
|
+ EsmUserReferrerDTO esmUserReferrerDTO = collect.get(id);
|
|
|
+ if(esmUserReferrerDTO == null ){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ Integer count=0;
|
|
|
+
|
|
|
+ for (EsmUserReferrerDTO potentialSubordinate : collect.values()) {
|
|
|
+ if (potentialSubordinate.getReferrerId().equals(id)) {
|
|
|
+ count++; // 直接下级加1
|
|
|
+ count += nextLevelUser(potentialSubordinate.getId(),collect,visited); // 递归计算下级的下级
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param collect
|
|
|
+ * @param visited
|
|
|
+ * @param ids 存储用户下级ids
|
|
|
+ * @return 获取用户下级用户idList
|
|
|
+ */
|
|
|
+ private List<String> nextLevelUserList(String id, Map<String, EsmUserReferrerDTO> collect, Set<String> visited, List<String> ids) {
|
|
|
+ if (visited.contains(id)) {
|
|
|
+ return ids; // 如果已经访问过,返回0
|
|
|
+ }
|
|
|
+ visited.add(id); // 标记为已访问
|
|
|
+
|
|
|
+ EsmUserReferrerDTO esmUserReferrerDTO = collect.get(id);
|
|
|
+ if(esmUserReferrerDTO == null ){
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+ for (EsmUserReferrerDTO potentialSubordinate : collect.values()) {
|
|
|
+ if (potentialSubordinate.getReferrerId().equals(id)) {
|
|
|
+ ids.add(potentialSubordinate.getId());
|
|
|
+ this.nextLevelUserList(potentialSubordinate.getId(),collect,visited,ids); // 递归计算下级的下级
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|