真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

spring中mybatis多表查詢(xún)處理的示例分析

這篇文章將為大家詳細(xì)講解有關(guān)spring中mybatis多表查詢(xún)處理的示例分析,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)主營(yíng)資溪網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都APP應(yīng)用開(kāi)發(fā),資溪h5成都微信小程序搭建,資溪網(wǎng)站營(yíng)銷(xiāo)推廣歡迎資溪等地區(qū)企業(yè)咨詢(xún)

package com.swhy.bw.advisor.center.comment;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swhy.bw.advisor.dal.mapper.ApCommentExtMapper;
import com.swhy.bw.advisor.dao.biz.response.theme.AdviserThemeDetailRes;
import com.swhy.bw.advisor.dao.biz.response.user.UserInfoRes;
import com.swhy.bw.advisor.dao.center.request.comment.CommentCenterListReq;
import com.swhy.bw.advisor.dao.center.request.comment.CommentCenterModifyReq;
import com.swhy.bw.advisor.dao.center.request.comment.SelectCommentReq;
import com.swhy.bw.advisor.dao.center.response.comment.CommentCenterListRes;
import com.swhy.bw.advisor.dao.center.response.comment.CommentDetailRes;
import com.swhy.bw.advisor.dao.entity.ApComment;
import com.swhy.bw.advisor.dao.entity.ApLiveRoom;
import com.swhy.bw.advisor.dao.entity.VdInvestAdviser;
import com.swhy.bw.advisor.elasticsearch.utils.AdviserEsUtils;
import com.swhy.bw.advisor.elasticsearch.utils.AdviserThemeEsUtils;
import com.swhy.bw.advisor.elasticsearch.utils.LiveRoomEsUtils;
import com.swhy.bw.advisor.elasticsearch.utils.UserEsUtils;
import com.swhy.bw.advisor.enums.CommentEnums;
import com.swhy.bw.advisor.util.CollectionUtils;
import com.swhy.bw.advisor.util.ExceptionUtil;
import com.swhy.bw.advisor.util.StringUtils;
import com.swhy.bw.advisor.util.date.DateFormat;
import com.swhy.bw.advisor.util.date.DateUtils;
import com.swhy.bw.advisor.util.exception.BusinessException;
import com.swhy.bw.advisor.util.log.LOG_TYPE;
import com.swhy.bw.advisor.util.log.LogUtil;
import com.swhy.bw.advisor.util.route.RouteUtil;
import com.swhy.bw.common.util.date.DateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ApCommentMgmtService {
    @Autowired
    private ApCommentExtMapper apCommentExtMapper;
    @Autowired
    private AdviserThemeEsUtils adviserThemeEsUtils;
    public PageInfo findApCommentList(CommentCenterListReq apCommentReq) throws BusinessException {
        final String METHOD = "findApCommentList";
        try {
            PageHelper.startPage(apCommentReq.getPageNum(), apCommentReq.getPageSize());
            LogUtil.logInput(LOG_TYPE.BIZ.val, this, METHOD, apCommentReq);
            // 請(qǐng)求參數(shù)
            if (apCommentReq.getEndDate() != null)
                apCommentReq.setEndDate(DateUtil.addDay(apCommentReq.getEndDate(), 1));
            // 查詢(xún)?cè)u(píng)論列表
            Page records = (Page) apCommentExtMapper.selectCommentListAll(apCommentReq);
            if (records == null) {
                return new PageInfo<>();
            }
            Page resPage = new Page<>();
            BeanUtils.copyProperties(records, resPage);
            // 查詢(xún)投顧信息
            HashMap adviserMap = getAdviserInfo(records);
            // 查詢(xún)標(biāo)題信息
            HashMap titleMap;
            if (apCommentReq.getCommentType().equals(CommentEnums.comment_type_theme.getValue())) {
                titleMap = getThemeInfo(records);
            } else {
                titleMap = getLiveroomInfo(records);
            }
            // 轉(zhuǎn)換
            records.forEach(record -> {
                CommentCenterListRes res = new CommentCenterListRes();
                BeanUtils.copyProperties(record, res);
                res.setTitle(titleMap.getOrDefault(record.getCommentId(), ""));
                res.setInvestAdviserName(adviserMap.getOrDefault(record.getAdviserId(), ""));
                res.setPublishTime(DateUtil.formateDate2Str(record.getPublishTime(), "yyyy-MM-dd HH:mm:ss"));
                res.setCommentContent(record.getContent());
                resPage.add(res);
            });
            return new PageInfo<>(resPage);
        } catch (Exception e) {
            LogUtil.logError(LOG_TYPE.BIZ.val, this, METHOD, e);
            throw ExceptionUtil.generateException("評(píng)論列表查詢(xún)異常", e);
        }
    }
    private HashMap getThemeInfo(Page records) {
        HashMap themeMap = new HashMap<>();
        List themeIds = records.stream().map(ApComment::getCommentId).distinct().collect(Collectors.toList());
        List themeDetailResList = adviserThemeEsUtils.findThemeByIds(themeIds);
        if (CollectionUtils.isNotEmpty(themeDetailResList))
            themeDetailResList.forEach(theme -> themeMap.put(theme.getId(), theme.getTitle()));
        return themeMap;
    }
    private HashMap getLiveroomInfo(Page records) {
        HashMap themeMap = new HashMap<>();
        List liveroomIds = records.stream().map(ApComment::getCommentId).distinct().collect(Collectors.toList());
        List liveRooms = LiveRoomEsUtils.findByIds(liveroomIds);
        if (CollectionUtils.isNotEmpty(liveRooms))
            liveRooms.forEach(liveRoom -> themeMap.put(liveRoom.getId(), liveRoom.getTitle()));
        return themeMap;
    }
    private HashMap getAdviserInfo(Page records) {
        HashMap adviserMap = new HashMap<>();
        List adviserIds = records.stream().map(ApComment::getAdviserId).distinct().collect(Collectors.toList());
        List advisers = AdviserEsUtils.findByIds(adviserIds);
        if (CollectionUtils.isNotEmpty(advisers))
            advisers.forEach(adviser -> adviserMap.put(adviser.getId(), adviser.getInvestAdviserName()));
        return adviserMap;
    }

}

關(guān)于“spring中mybatis多表查詢(xún)處理的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。


分享文章:spring中mybatis多表查詢(xún)處理的示例分析
當(dāng)前URL:http://weahome.cn/article/jjigpd.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部