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

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

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

@Service
public class HomePageManager {

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

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

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

        // 主页类型 显示逻辑
刘基明's avatar
刘基明 committed
81
        if (UserLevelEnum.USER_CHIEF_FINANCIAL_ADVISER.getCode() == userInfoNew.getLevelGrade()) {
吴泽佳's avatar
吴泽佳 committed
82
            // 首席投顾
吴泽佳's avatar
吴泽佳 committed
83
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.CHIEF.getCode());
84 85
            // 成功案例客户
            // 默认显示该投顾管理的客户里,总资产最高的客户
吴泽佳's avatar
吴泽佳 committed
86
            if (StringUtils.isBlank(userInfoNew.getUserInfoNewChief().getClientId())) {
87
                List<Customer> customers = queryUserCustomerList(userId);
吴泽佳's avatar
吴泽佳 committed
88
                Optional<Customer> first = customers.stream().max(Comparator.comparing(Customer::getTotalMarket));
89
                if (first.isPresent()) {
吴泽佳's avatar
吴泽佳 committed
90
                    userInfoNew.getUserInfoNewChief().setClientId(first.get().getCustomerId());
91
                } else {
吴泽佳's avatar
吴泽佳 committed
92
                    userInfoNew.getUserInfoNewChief().setClientId(null);
93 94
                }
            }
95 96 97
            // 查询首席投顾数量
            CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(1, 1);
            if (pageCommonResp.isSuccess()){
吴泽佳's avatar
吴泽佳 committed
98
                userInfoNew.getUserInfoNewChief().setChiefCount(pageCommonResp.getData().getTotalSize());
99
            } else {
吴泽佳's avatar
吴泽佳 committed
100
                userInfoNew.getUserInfoNewChief().setChiefCount(0L);
101
            }
102 103


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

        } else {
            //普通主页
吴泽佳's avatar
吴泽佳 committed
151
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.GENERAL.getCode());
吴泽佳's avatar
吴泽佳 committed
152 153
            //设置课程数(学习数)
            CommonResp<Integer> integerCommonResp = feignClientForCourse.getStudyCourseCount(userId);
154 155 156 157 158
            if (integerCommonResp.isSuccess()) userInfoNew.setCourseNumber(integerCommonResp.getData());
        }
        return userInfoNew;
    }

吴泽佳's avatar
吴泽佳 committed
159
    public Page<UserInfoNewChief> queryChiefFinancialAdviserList(Pageable page) {
吴泽佳's avatar
吴泽佳 committed
160
        CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(page.pageNumber, page.pageSize);
吴泽佳's avatar
吴泽佳 committed
161 162 163 164
        return pageCommonResp.getData();

    }

165
    private void getFansNUmAndFollowNum(UserInfoResp userInfoNew) {
刘基明's avatar
刘基明 committed
166
        Integer fansNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, userInfoNew.getUserId())
167
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
刘基明's avatar
刘基明 committed
168
        Integer followNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId, userInfoNew.getUserId())
169 170 171 172
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
        userInfoNew.setFollowNumber(followNumber);
        userInfoNew.setFansNumber(fansNumber);
    }
刘基明's avatar
刘基明 committed
173

174 175 176 177 178
    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
179

张辰's avatar
张辰 committed
180

刘基明's avatar
刘基明 committed
181 182 183 184 185 186
    /**
     * 用户关注列表
     * @param req  目标用户
     * @param userId 当前用户
     * @return
     */
刘基明's avatar
刘基明 committed
187
    public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
刘基明's avatar
刘基明 committed
188
        //TODO 数据库分页
刘基明's avatar
刘基明 committed
189
        List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
刘基明's avatar
刘基明 committed
190
                followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryIdolsByFollowerId(req.getUserId());
刘基明's avatar
刘基明 committed
191 192
        List<FollowQo> followQos = new ArrayList<>();
        if (!CollectionUtils.isEmpty(userIds)) {
193
            List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIds);
刘基明's avatar
刘基明 committed
194
            List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
刘基明's avatar
刘基明 committed
195 196
            followQos = judgeFollowed(collect, userId);
        }
刘基明's avatar
刘基明 committed
197
        //分页
刘基明's avatar
刘基明 committed
198
        return PageUtils.page(req.getPage(), followQos);
张辰's avatar
张辰 committed
199 200
    }

刘基明's avatar
刘基明 committed
201

刘基明's avatar
刘基明 committed
202
    //判断返回列表中的用户是否被当前用户关注
刘基明's avatar
刘基明 committed
203
    public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
刘基明's avatar
刘基明 committed
204
        Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFollowerId(followerId));
刘基明's avatar
刘基明 committed
205 206
        return followQos.stream().map(o -> {
            if (idolSet.contains(o.getUserId())) {
刘基明's avatar
刘基明 committed
207 208 209 210 211 212 213
                o.setFollowed(true);
            }
            return o;
        }).collect(Collectors.toList());

    }

刘基明's avatar
刘基明 committed
214 215 216 217 218 219
    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
220
    }
221 222


张辰's avatar
张辰 committed
223
}