HomePageManager.java 12.7 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;
9
import com.tanpu.common.util.DateUtils;
刘基明's avatar
刘基明 committed
10
import com.tanpu.community.api.beans.qo.FollowQo;
刘基明's avatar
刘基明 committed
11
import com.tanpu.community.api.beans.req.homepage.FollowRelReq;
刘基明's avatar
刘基明 committed
12 13
import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.page.Page;
吴泽佳's avatar
吴泽佳 committed
14
import com.tanpu.community.api.beans.req.page.Pageable;
15
import com.tanpu.community.api.beans.resp.Customer;
吴泽佳's avatar
吴泽佳 committed
16
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
17
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg;
18 19
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.fund.FundCompanySimpleVO;
吴泽佳's avatar
吴泽佳 committed
20
import com.tanpu.community.api.enums.*;
刘基明's avatar
刘基明 committed
21
import com.tanpu.community.cache.RedisCache;
22 23
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
吴泽佳's avatar
吴泽佳 committed
24
import com.tanpu.community.feign.course.FeignClientForCourse;
25 26
import com.tanpu.community.feign.diagnose.FeignClientForDiagnose;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
吴泽佳's avatar
吴泽佳 committed
27 28
import com.tanpu.community.feign.product.FeignForFund;
import com.tanpu.community.feign.product.FeignForPublicFund;
刘基明's avatar
刘基明 committed
29
import com.tanpu.community.service.FollowRelService;
刘基明's avatar
刘基明 committed
30
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
31
import com.tanpu.community.util.PageUtils;
32
import org.apache.commons.collections.CollectionUtils;
33 34
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
张辰's avatar
张辰 committed
35 36
import org.springframework.stereotype.Service;

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

刘基明's avatar
刘基明 committed
42 43
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_FEIGN_USER_INFO;

张辰's avatar
张辰 committed
44 45 46
@Service
public class HomePageManager {

吴泽佳's avatar
吴泽佳 committed
47
    @Resource
刘基明's avatar
刘基明 committed
48
    private FollowRelService followRelService;
吴泽佳's avatar
吴泽佳 committed
49
    @Resource
50 51 52 53 54
    private FeignClientForFatools feignClientForFatools;
    @Resource
    private FollowRelMapper followRelMapper;
    @Resource
    private FeignClientForDiagnose feignClientForDiagnose;
吴泽佳's avatar
吴泽佳 committed
55 56
    @Resource
    private FeignClientForCourse feignClientForCourse;
57
    @Resource
吴泽佳's avatar
吴泽佳 committed
58
    private FeignForFund feignForFund;
59
    @Resource
吴泽佳's avatar
吴泽佳 committed
60
    private FeignForPublicFund feignForPublicFund;
刘基明's avatar
刘基明 committed
61 62
    @Resource
    private RedisCache redisCache;
63 64

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

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

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


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

        } else {
            //普通主页
吴泽佳's avatar
吴泽佳 committed
158
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.GENERAL.getCode());
吴泽佳's avatar
吴泽佳 committed
159 160
            //设置课程数(学习数)
            CommonResp<Integer> integerCommonResp = feignClientForCourse.getStudyCourseCount(userId);
161 162
            if (integerCommonResp.isSuccess()) userInfoNew.setCourseNumber(integerCommonResp.getData());
        }
刘基明's avatar
刘基明 committed
163 164 165
        //刷新用户缓存
        redisCache.put(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, userId), userInfoNew, 60);

166 167 168
        return userInfoNew;
    }

吴泽佳's avatar
吴泽佳 committed
169
    public Page<UserInfoNewChief> queryChiefFinancialAdviserList(Pageable page) {
吴泽佳's avatar
吴泽佳 committed
170
        CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(page.pageNumber, page.pageSize);
吴泽佳's avatar
吴泽佳 committed
171 172 173 174
        return pageCommonResp.getData();

    }

175
    private void getFansNUmAndFollowNum(UserInfoResp userInfoNew) {
刘基明's avatar
刘基明 committed
176
        Integer fansNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, userInfoNew.getUserId())
177
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
刘基明's avatar
刘基明 committed
178
        Integer followNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId, userInfoNew.getUserId())
179 180 181 182
                .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
        userInfoNew.setFollowNumber(followNumber);
        userInfoNew.setFansNumber(fansNumber);
    }
刘基明's avatar
刘基明 committed
183

184 185 186 187 188
    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
189

张辰's avatar
张辰 committed
190

刘基明's avatar
刘基明 committed
191 192
    /**
     * 用户关注列表
刘基明's avatar
刘基明 committed
193 194
     *
     * @param req    目标用户
刘基明's avatar
刘基明 committed
195 196 197
     * @param userId 当前用户
     * @return
     */
刘基明's avatar
刘基明 committed
198
    public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
刘基明's avatar
刘基明 committed
199 200 201 202 203 204 205
        //数据库分页
        Integer pageSize = req.page.pageSize;
        Integer pageNumber = req.page.pageNumber;

        Page<String> userIdsPage = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
                followRelService.queryFansByIdolId(req.userId, pageNumber, pageSize)
                : followRelService.queryIdolsByFansId(req.userId, pageNumber, pageSize);
刘基明's avatar
刘基明 committed
206
        List<FollowQo> followQos = new ArrayList<>();
刘基明's avatar
刘基明 committed
207 208
        if (!CollectionUtils.isEmpty(userIdsPage.getContent())) {
            List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
刘基明's avatar
刘基明 committed
209
            List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
刘基明's avatar
刘基明 committed
210 211
            followQos = judgeFollowed(collect, userId);
        }
刘基明's avatar
刘基明 committed
212
        return PageUtils.page(userIdsPage,followQos);
张辰's avatar
张辰 committed
213 214
    }

刘基明's avatar
刘基明 committed
215

刘基明's avatar
刘基明 committed
216
    //判断返回列表中的用户是否被当前用户关注
刘基明's avatar
刘基明 committed
217
    public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
刘基明's avatar
刘基明 committed
218
        Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId));
刘基明's avatar
刘基明 committed
219 220
        return followQos.stream().map(o -> {
            if (idolSet.contains(o.getUserId())) {
刘基明's avatar
刘基明 committed
221 222 223 224 225 226 227
                o.setFollowed(true);
            }
            return o;
        }).collect(Collectors.toList());

    }

刘基明's avatar
刘基明 committed
228 229 230 231 232 233
    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
234
    }
235 236


张辰's avatar
张辰 committed
237
}