HomePageManager.java 11.4 KB
Newer Older
张辰's avatar
张辰 committed
1 2
package com.tanpu.community.manager;

3 4 5 6
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.constant.BizStatus;
import com.tanpu.common.exception.BizException;
刘基明's avatar
刘基明 committed
7
import com.tanpu.community.api.beans.qo.FollowQo;
刘基明's avatar
刘基明 committed
8
import com.tanpu.community.api.beans.req.homepage.FollowRelReq;
刘基明's avatar
刘基明 committed
9 10
import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.page.Page;
吴泽佳's avatar
吴泽佳 committed
11
import com.tanpu.community.api.beans.req.page.Pageable;
12
import com.tanpu.community.api.beans.resp.Customer;
吴泽佳's avatar
吴泽佳 committed
13
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
14
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg;
15 16
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.fund.FundCompanySimpleVO;
吴泽佳's avatar
吴泽佳 committed
17
import com.tanpu.community.api.enums.*;
18 19
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
吴泽佳's avatar
吴泽佳 committed
20
import com.tanpu.community.feign.course.FeignClientForCourse;
21 22
import com.tanpu.community.feign.diagnose.FeignClientForDiagnose;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
吴泽佳's avatar
吴泽佳 committed
23 24
import com.tanpu.community.feign.product.FeignForFund;
import com.tanpu.community.feign.product.FeignForPublicFund;
刘基明's avatar
刘基明 committed
25
import com.tanpu.community.service.FollowRelService;
刘基明's avatar
刘基明 committed
26
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
27
import com.tanpu.community.util.PageUtils;
28
import org.apache.commons.collections.CollectionUtils;
29 30
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
张辰's avatar
张辰 committed
31 32
import org.springframework.stereotype.Service;

33
import javax.annotation.Resource;
刘基明's avatar
刘基明 committed
34
import java.util.*;
35
import java.util.function.Function;
刘基明's avatar
刘基明 committed
36
import java.util.stream.Collectors;
张辰's avatar
张辰 committed
37 38 39 40

@Service
public class HomePageManager {

吴泽佳's avatar
吴泽佳 committed
41
    @Resource
刘基明's avatar
刘基明 committed
42
    private FollowRelService followRelService;
吴泽佳's avatar
吴泽佳 committed
43
    @Resource
44 45 46 47 48
    private FeignClientForFatools feignClientForFatools;
    @Resource
    private FollowRelMapper followRelMapper;
    @Resource
    private FeignClientForDiagnose feignClientForDiagnose;
吴泽佳's avatar
吴泽佳 committed
49 50
    @Resource
    private FeignClientForCourse feignClientForCourse;
51
    @Resource
吴泽佳's avatar
吴泽佳 committed
52
    private FeignForFund feignForFund;
53
    @Resource
吴泽佳's avatar
吴泽佳 committed
54
    private FeignForPublicFund feignForPublicFund;
55 56

    //查询 个人中心 相关信息
57 58
    public UserInfoResp queryUsersInfo(String userIdMyself, String userId) {
        CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUsersListNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself);
吴泽佳's avatar
吴泽佳 committed
59
        if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData())) throw new BizException("内部接口调用失败");
60
        UserInfoResp userInfoNew = queryUsersListNew.getData();
吴泽佳's avatar
吴泽佳 committed
61

吴泽佳's avatar
吴泽佳 committed
62
        if (StringUtils.isNotBlank(userId) && !StringUtils.equals(userIdMyself, userId)) { //查询别人的个人主页
吴泽佳's avatar
吴泽佳 committed
63
            // 关注 按钮的显示逻辑
64
            FollowRelEntity followRelEntity = followRelService.queryRecord(userId, userIdMyself);
刘基明's avatar
刘基明 committed
65
            if (ObjectUtils.allNotNull(followRelEntity) && BizStatus.DeleteTag.tag_init == followRelEntity.getDeleteTag()) {
吴泽佳's avatar
吴泽佳 committed
66
                userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.FOLLOWED.getCode()); // 已关注
67
            } else {
吴泽佳's avatar
吴泽佳 committed
68
                userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.NOT_FOLLOWED.getCode()); // 未关注
69
            }
吴泽佳's avatar
吴泽佳 committed
70
            if (userInfoNew.getWorkshopStatus() == 2) userInfoNew.setWorkshopStatus(1); //别人的主页不需要展示 工作室
71 72 73 74
        } else {
            // 查询自己的主页
            userId = userIdMyself;
        }
吴泽佳's avatar
吴泽佳 committed
75
        //获取粉丝数 关注数
76 77 78
        getFansNUmAndFollowNum(userInfoNew);

        // 主页类型 显示逻辑
刘基明's avatar
刘基明 committed
79
        if (UserLevelEnum.USER_CHIEF_FINANCIAL_ADVISER.getCode() == userInfoNew.getLevelGrade()) {
吴泽佳's avatar
吴泽佳 committed
80
            // 首席投顾
吴泽佳's avatar
吴泽佳 committed
81
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.CHIEF.getCode());
82 83
            // 成功案例客户
            // 默认显示该投顾管理的客户里,总资产最高的客户
吴泽佳's avatar
吴泽佳 committed
84
            if (StringUtils.isBlank(userInfoNew.getUserInfoNewChief().getClientId())) {
85
                List<Customer> customers = queryUserCustomerList(userId);
吴泽佳's avatar
吴泽佳 committed
86
                Optional<Customer> first = customers.stream().max(Comparator.comparing(Customer::getTotalMarket));
87
                if (first.isPresent()) {
吴泽佳's avatar
吴泽佳 committed
88
                    userInfoNew.getUserInfoNewChief().setClientId(first.get().getCustomerId());
89
                } else {
吴泽佳's avatar
吴泽佳 committed
90
                    userInfoNew.getUserInfoNewChief().setClientId(null);
91 92
                }
            }
93 94


刘基明's avatar
刘基明 committed
95
        } else if (UserTypeEnum.USER_ORG.getCode() == userInfoNew.getUserType()) {
96
            // 机构账号
吴泽佳's avatar
吴泽佳 committed
97
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.ORG.getCode());
刘基明's avatar
刘基明 committed
98
            if (FundCompanyTypeEnum.PUBLIC.getCode() == userInfoNew.getUserInfoNewOrg().getBelongOrgType() && StringUtils.isNotBlank(userInfoNew.getUserInfoNewOrg().getBelongOrgId())) { // 公募
99
                // 设置 基金数
吴泽佳's avatar
吴泽佳 committed
100
                CommonResp<FundCompanySimpleVO> companyFundCount = feignForPublicFund.getCompanyFundCount(userInfoNew.getUserInfoNewOrg().getBelongOrgId());
101 102
                userInfoNew.setFundNumber(companyFundCount.isSuccess() ? companyFundCount.getData().getFundCount() : 0);
                // 设置成立时间 和 备案编号(公募没有备案编号)
吴泽佳's avatar
吴泽佳 committed
103
                CommonResp<FundCompanySimpleVO> fundCompanyInfoSimple = feignForPublicFund.getFundCompanyInfoSimple(userInfoNew.getUserInfoNewOrg().getBelongOrgId());
104 105 106 107 108
                if (fundCompanyInfoSimple.isSuccess()) {
                    FundCompanySimpleVO data = fundCompanyInfoSimple.getData();
                    userInfoNew.setFounded(data.getEstablishDate());
                    userInfoNew.setRecordNumber(data.getRegisterNumber());
                }
109
            }
刘基明's avatar
刘基明 committed
110
            if (FundCompanyTypeEnum.PRIVATE.getCode() == userInfoNew.getUserInfoNewOrg().getBelongOrgType() && StringUtils.isNotBlank(userInfoNew.getUserInfoNewOrg().getBelongOrgId())) { // 私募
111
                // 设置成立时间 和 备案编号
吴泽佳's avatar
吴泽佳 committed
112
                CommonResp<FundCompanySimpleVO> fundCompanyInfoSimple = feignForFund.getFundCompanyInfoSimple(userInfoNew.getUserInfoNewOrg().getBelongOrgId());
113 114 115 116
                if (fundCompanyInfoSimple.isSuccess()) {
                    FundCompanySimpleVO data = fundCompanyInfoSimple.getData();
                    userInfoNew.setFounded(data.getEstablishDate());
                    userInfoNew.setRecordNumber(data.getRegisterNumber());
117
                }
118
                // 设置 基金数
吴泽佳's avatar
吴泽佳 committed
119
                CommonResp<FundCompanySimpleVO> companyFundCount = feignForFund.getCompanyFundCount(userInfoNew.getUserInfoNewOrg().getBelongOrgId());
120
                userInfoNew.setFundNumber(companyFundCount.isSuccess() ? companyFundCount.getData().getFundCount() : 0);
121 122 123
            }
            //设置团队成员
            CommonResp<List<UserInfoOrg>> usetInfoByOrgUserId = feignClientForFatools.getUsetInfoByOrgUserId(userId);
吴泽佳's avatar
吴泽佳 committed
124
            if (usetInfoByOrgUserId.isSuccess() && CollectionUtils.isNotEmpty(usetInfoByOrgUserId.getData())) {
125 126 127 128
                List<UserInfoOrg> userInfoOrgs = usetInfoByOrgUserId.getData();
                // 设置关注列表
                List<String> collect = userInfoOrgs.stream().map(UserInfoOrg::getUserId).collect(Collectors.toList());
                List<FollowRelEntity> followRelEntities = followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
刘基明's avatar
刘基明 committed
129 130
                        .eq(FollowRelEntity::getIdolId, userId)
                        .in(FollowRelEntity::getFansId, collect)
131
                        .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
刘基明's avatar
刘基明 committed
132
                Map<String, FollowRelEntity> collect1 = followRelEntities.stream().collect(Collectors.toMap(FollowRelEntity::getIdolId, Function.identity()));
133
                userInfoOrgs.forEach(userInfoOrg -> {
刘基明's avatar
刘基明 committed
134 135
                    if (collect1.containsKey(userInfoOrg.getUserId()))
                        userInfoOrg.setIsFollower(ShowFollowStatusEnum.FOLLOWED.getCode());//1已关注
136 137 138 139 140 141
                });
                userInfoNew.setUserInfoOrgList(userInfoOrgs);
            }

        } else {
            //普通主页
吴泽佳's avatar
吴泽佳 committed
142
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.GENERAL.getCode());
吴泽佳's avatar
吴泽佳 committed
143 144
            //设置课程数(学习数)
            CommonResp<Integer> integerCommonResp = feignClientForCourse.getStudyCourseCount(userId);
145 146 147 148 149
            if (integerCommonResp.isSuccess()) userInfoNew.setCourseNumber(integerCommonResp.getData());
        }
        return userInfoNew;
    }

吴泽佳's avatar
吴泽佳 committed
150
    public Page<UserInfoNewChief> queryChiefFinancialAdviserList(Pageable page) {
吴泽佳's avatar
吴泽佳 committed
151
        CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(page.pageNumber, page.pageSize);
吴泽佳's avatar
吴泽佳 committed
152 153 154 155
        return pageCommonResp.getData();

    }

156
    private void getFansNUmAndFollowNum(UserInfoResp userInfoNew) {
刘基明's avatar
刘基明 committed
157
        Integer fansNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, userInfoNew.getUserId())
158
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
刘基明's avatar
刘基明 committed
159
        Integer followNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId, userInfoNew.getUserId())
160 161 162 163
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
        userInfoNew.setFollowNumber(followNumber);
        userInfoNew.setFansNumber(fansNumber);
    }
刘基明's avatar
刘基明 committed
164

165 166 167 168 169
    public List<Customer> queryUserCustomerList(String userId) {
        CommonResp<List<Customer>> ifaCustomerList = feignClientForDiagnose.getIfaCustomerList(userId);
        if (ifaCustomerList.isSuccess()) return ifaCustomerList.getData();
        return new ArrayList<>();
    }
刘基明's avatar
刘基明 committed
170

张辰's avatar
张辰 committed
171

刘基明's avatar
刘基明 committed
172
    //获取用户关注、粉丝列表
刘基明's avatar
刘基明 committed
173
    public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
刘基明's avatar
刘基明 committed
174
        //TODO 数据库分页
刘基明's avatar
刘基明 committed
175 176
        List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
                followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId());
刘基明's avatar
刘基明 committed
177 178
        List<FollowQo> followQos = new ArrayList<>();
        if (!CollectionUtils.isEmpty(userIds)) {
179
            List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIds);
刘基明's avatar
刘基明 committed
180
            List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
刘基明's avatar
刘基明 committed
181 182
            followQos = judgeFollowed(collect, userId);
        }
刘基明's avatar
刘基明 committed
183
        //分页
刘基明's avatar
刘基明 committed
184
        return PageUtils.page(req.getPage(), followQos);
张辰's avatar
张辰 committed
185 186
    }

刘基明's avatar
刘基明 committed
187

刘基明's avatar
刘基明 committed
188
    //判断返回列表中的用户是否被当前用户关注
刘基明's avatar
刘基明 committed
189
    public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
刘基明's avatar
刘基明 committed
190
        Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId));
刘基明's avatar
刘基明 committed
191 192
        return followQos.stream().map(o -> {
            if (idolSet.contains(o.getUserId())) {
刘基明's avatar
刘基明 committed
193 194 195 196 197 198 199
                o.setFollowed(true);
            }
            return o;
        }).collect(Collectors.toList());

    }

刘基明's avatar
刘基明 committed
200 201 202 203 204 205
    public void addFollowRel(FollowRelReq req, String followerId) {
        if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
            followRelService.addFollowRel(req.getFollowUserId(), followerId);
        } else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
            followRelService.deleteFollowRel(req.getFollowUserId(), followerId);
        }
张辰's avatar
张辰 committed
206
    }
207 208


张辰's avatar
张辰 committed
209
}