HomePageManager.java 11.8 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 13
import com.tanpu.community.api.beans.resp.Customer;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew;
吴泽佳's avatar
吴泽佳 committed
14
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
15
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg;
吴泽佳's avatar
吴泽佳 committed
16
import com.tanpu.community.api.enums.*;
17 18 19 20 21 22 23 24 25 26
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.entity.fund.CompanyInfo;
import com.tanpu.community.dao.entity.fund.FundInfo;
import com.tanpu.community.dao.entity.jydb.MfAdvisorscalerank;
import com.tanpu.community.dao.entity.jydb.MfInvestadvisoroutline;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
import com.tanpu.community.dao.mapper.fund.CompanyInfoMapper;
import com.tanpu.community.dao.mapper.fund.FundInfoMapper;
import com.tanpu.community.dao.mapper.jydb.MfAdvisorscalerankMapper;
import com.tanpu.community.dao.mapper.jydb.MfInvestadvisoroutlineMapper;
吴泽佳's avatar
吴泽佳 committed
27
import com.tanpu.community.feign.course.FeignClientForCourse;
28 29
import com.tanpu.community.feign.diagnose.FeignClientForDiagnose;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
刘基明's avatar
刘基明 committed
30
import com.tanpu.community.service.FollowRelService;
刘基明's avatar
刘基明 committed
31
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
32
import com.tanpu.community.util.PageUtils;
33
import org.apache.commons.collections.CollectionUtils;
34 35
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
张辰's avatar
张辰 committed
36 37
import org.springframework.stereotype.Service;

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

@Service
public class HomePageManager {

吴泽佳's avatar
吴泽佳 committed
46
    @Resource
刘基明's avatar
刘基明 committed
47
    private FollowRelService followRelService;
吴泽佳's avatar
吴泽佳 committed
48
    @Resource
49 50 51 52 53 54 55 56 57 58 59 60 61
    private FeignClientForFatools feignClientForFatools;
    @Resource
    private FollowRelMapper followRelMapper;
    @Resource
    private MfInvestadvisoroutlineMapper mfInvestadvisoroutlineMapper;
    @Resource
    private MfAdvisorscalerankMapper mfAdvisorscalerankMapper;
    @Resource
    private CompanyInfoMapper companyInfoMapper;
    @Resource
    private FundInfoMapper fundInfoMapper;
    @Resource
    private FeignClientForDiagnose feignClientForDiagnose;
吴泽佳's avatar
吴泽佳 committed
62 63
    @Resource
    private FeignClientForCourse feignClientForCourse;
64 65 66

    //查询 个人中心 相关信息
    public UserInfoNew queryUsersListNew(String userIdMyself, String userId) {
吴泽佳's avatar
吴泽佳 committed
67
        CommonResp<UserInfoNew> queryUsersListNew = feignClientForFatools.queryUsersListNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself);
吴泽佳's avatar
吴泽佳 committed
68
        if (queryUsersListNew.isNotSuccess() || ObjectUtils.anyNotNull(queryUsersListNew.getData()))  new BizException("内部接口调用失败");
吴泽佳's avatar
吴泽佳 committed
69
        UserInfoNew 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 84 85 86 87
        } else {
            // 查询自己的主页
            userId = userIdMyself;
        }
        //设置粉丝数 关注数
        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
                }
刘基明's avatar
刘基明 committed
101

102
            }
刘基明's avatar
刘基明 committed
103
        } else if (UserTypeEnum.USER_ORG.getCode() == userInfoNew.getUserType()) {
104
            // 机构账号
吴泽佳's avatar
吴泽佳 committed
105
            userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.ORG.getCode());
刘基明's avatar
刘基明 committed
106
            if (FundCompanyTypeEnum.PUBLIC.getCode() == userInfoNew.getUserInfoNewOrg().getBelongOrgType() && StringUtils.isNotBlank(userInfoNew.getUserInfoNewOrg().getBelongOrgId())) { // 公募
107 108
                //设置 基金数
                MfAdvisorscalerank mfAdvisorscalerank = mfAdvisorscalerankMapper.selectOne(new LambdaQueryWrapper<MfAdvisorscalerank>()
吴泽佳's avatar
吴泽佳 committed
109
                        .eq(MfAdvisorscalerank::getInvestadvisorcode, userInfoNew.getUserInfoNewOrg().getBelongOrgId())
110 111 112 113
                        .last("limit 1"));
                userInfoNew.setFundNumber(ObjectUtils.anyNotNull(mfAdvisorscalerank) ? mfAdvisorscalerank.getTotalfundn() : null);
                //设置成立时间 和 备案编号(公募没有备案编号)
                MfInvestadvisoroutline mfInvestadvisoroutline = mfInvestadvisoroutlineMapper.selectOne(new LambdaQueryWrapper<MfInvestadvisoroutline>()
吴泽佳's avatar
吴泽佳 committed
114
                        .eq(MfInvestadvisoroutline::getInvestadvisorcode, userInfoNew.getUserInfoNewOrg().getBelongOrgId())
115 116 117
                        .last("limit 1"));
                userInfoNew.setFounded(ObjectUtils.anyNotNull(mfInvestadvisoroutline) ? mfInvestadvisoroutline.getEstablishmentdate().getTime() : null);
            }
刘基明's avatar
刘基明 committed
118
            if (FundCompanyTypeEnum.PRIVATE.getCode() == userInfoNew.getUserInfoNewOrg().getBelongOrgType() && StringUtils.isNotBlank(userInfoNew.getUserInfoNewOrg().getBelongOrgId())) { // 私募
119
                //设置 基金数
吴泽佳's avatar
吴泽佳 committed
120
                Integer integer = fundInfoMapper.selectCount(new LambdaQueryWrapper<FundInfo>().eq(FundInfo::getTrustId, userInfoNew.getUserInfoNewOrg().getBelongOrgId()));
121 122 123
                userInfoNew.setFundNumber(integer);

                //设置成立时间 和 备案编号
吴泽佳's avatar
吴泽佳 committed
124
                CompanyInfo companyInfo = companyInfoMapper.selectById(userInfoNew.getUserInfoNewOrg().getBelongOrgId());
125 126 127 128 129 130 131
                if (ObjectUtils.anyNotNull(companyInfo)) {
                    userInfoNew.setFounded(companyInfo.getEstablishDate().getTime());
                    userInfoNew.setRecordNumber(companyInfo.getRegisterNumber());
                }
            }
            //设置团队成员
            CommonResp<List<UserInfoOrg>> usetInfoByOrgUserId = feignClientForFatools.getUsetInfoByOrgUserId(userId);
吴泽佳's avatar
吴泽佳 committed
132
            if (usetInfoByOrgUserId.isSuccess() && CollectionUtils.isNotEmpty(usetInfoByOrgUserId.getData())) {
133 134 135 136 137 138 139 140 141
                List<UserInfoOrg> userInfoOrgs = usetInfoByOrgUserId.getData();
                // 设置关注列表
                List<String> collect = userInfoOrgs.stream().map(UserInfoOrg::getUserId).collect(Collectors.toList());
                List<FollowRelEntity> followRelEntities = followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
                        .eq(FollowRelEntity::getFollowerId, userId)
                        .in(FollowRelEntity::getFollowUserId, collect)
                        .eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
                Map<String, FollowRelEntity> collect1 = followRelEntities.stream().collect(Collectors.toMap(FollowRelEntity::getFollowUserId, Function.identity()));
                userInfoOrgs.forEach(userInfoOrg -> {
刘基明's avatar
刘基明 committed
142 143
                    if (collect1.containsKey(userInfoOrg.getUserId()))
                        userInfoOrg.setIsFollower(ShowFollowStatusEnum.FOLLOWED.getCode());//1已关注
144 145 146 147 148 149
                });
                userInfoNew.setUserInfoOrgList(userInfoOrgs);
            }

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

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

    }

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

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

张辰's avatar
张辰 committed
179

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

刘基明's avatar
刘基明 committed
195

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

    }

刘基明's avatar
刘基明 committed
208 209 210 211 212 213
    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
214
    }
215 216


张辰's avatar
张辰 committed
217
}