HomePageManager.java 12.4 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.*;
21 22
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
吴泽佳's avatar
吴泽佳 committed
23
import com.tanpu.community.feign.course.FeignClientForCourse;
24 25
import com.tanpu.community.feign.diagnose.FeignClientForDiagnose;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
吴泽佳's avatar
吴泽佳 committed
26 27
import com.tanpu.community.feign.product.FeignForFund;
import com.tanpu.community.feign.product.FeignForPublicFund;
刘基明's avatar
刘基明 committed
28
import com.tanpu.community.service.FollowRelService;
刘基明's avatar
刘基明 committed
29
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
30
import com.tanpu.community.util.PageUtils;
31
import org.apache.commons.collections.CollectionUtils;
32 33
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
张辰's avatar
张辰 committed
34 35
import org.springframework.stereotype.Service;

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

@Service
public class HomePageManager {

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

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

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

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


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

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

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

    }

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

176 177 178 179 180
    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
181

张辰's avatar
张辰 committed
182

刘基明's avatar
刘基明 committed
183 184
    /**
     * 用户关注列表
刘基明's avatar
刘基明 committed
185 186
     *
     * @param req    目标用户
刘基明's avatar
刘基明 committed
187 188 189
     * @param userId 当前用户
     * @return
     */
刘基明's avatar
刘基明 committed
190
    public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
刘基明's avatar
刘基明 committed
191 192 193 194 195 196 197
        //数据库分页
        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
198
        List<FollowQo> followQos = new ArrayList<>();
刘基明's avatar
刘基明 committed
199 200
        if (!CollectionUtils.isEmpty(userIdsPage.getContent())) {
            List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
刘基明's avatar
刘基明 committed
201
            List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
刘基明's avatar
刘基明 committed
202 203
            followQos = judgeFollowed(collect, userId);
        }
刘基明's avatar
刘基明 committed
204
        return PageUtils.page(userIdsPage,followQos);
张辰's avatar
张辰 committed
205 206
    }

刘基明's avatar
刘基明 committed
207

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

    }

刘基明's avatar
刘基明 committed
220 221 222 223 224 225
    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
226
    }
227 228


张辰's avatar
张辰 committed
229
}