|
|
@ -22,7 +22,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
@ -30,7 +33,9 @@ import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.BizPointTotalDetailDao; |
|
|
|
import com.epmet.dto.BizPointTotalDetailDTO; |
|
|
|
import com.epmet.dto.form.GroupPointFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.form.GroupFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.form.GroupPointDetailFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.result.GroupDetailResultDTO; |
|
|
|
import com.epmet.resi.group.dto.group.result.GroupPointDetailResultDTO; |
|
|
|
import com.epmet.dto.result.GroupPointRankingResultDTO; |
|
|
|
import com.epmet.entity.BizPointTotalDetailEntity; |
|
|
@ -39,6 +44,9 @@ import com.epmet.resi.group.feign.ResiGroupOpenFeignClient; |
|
|
|
import com.epmet.service.BizPointTotalDetailService; |
|
|
|
import com.epmet.service.BizPointUserTotalDetailService; |
|
|
|
import com.epmet.service.UserPointActionLogService; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -57,7 +65,7 @@ import java.util.stream.Collectors; |
|
|
|
* @since v1.0.0 2021-04-20 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTotalDetailDao, BizPointTotalDetailEntity> implements BizPointTotalDetailService { |
|
|
|
public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTotalDetailDao, BizPointTotalDetailEntity> implements BizPointTotalDetailService, ResultDataResolver { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ResiGroupOpenFeignClient resiGroupOpenFeignClient; |
|
|
@ -239,4 +247,122 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
return ConvertUtils.sourceToTarget(entity, BizPointTotalDetailDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<GroupPointRankingResultDTO> listGroupPointRandingInGridScope(String gridId, Integer pageNo, Integer pageSize) { |
|
|
|
|
|
|
|
// 1.查询有积分的小组得分排名
|
|
|
|
PageInfo<BizPointTotalDetailEntity> entityPageInfo = PageHelper.startPage(pageNo, pageSize).doSelectPageInfo(() -> { |
|
|
|
LambdaQueryWrapper<BizPointTotalDetailEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, gridId); |
|
|
|
query.eq(BizPointTotalDetailEntity::getBizType, "group"); |
|
|
|
//query.eq(BizPointTotalDetailEntity::getDelFlag, 0); #用mybatis plus不需要手动指定,框架会自动指定
|
|
|
|
query.orderByDesc(BizPointTotalDetailEntity::getTotalPoint); |
|
|
|
baseDao.selectList(query); |
|
|
|
}); |
|
|
|
|
|
|
|
List<BizPointTotalDetailEntity> groupList = entityPageInfo.getList(); |
|
|
|
|
|
|
|
List<String> groupIds = groupList.stream().map(g -> g.getObjectId()).collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 2.将列表填充基本信息并且转换为dto
|
|
|
|
List<GroupPointRankingResultDTO> rankingInfoDTOs = convertGroupRankingInfoEntity2DTOs(groupIds, groupList); |
|
|
|
|
|
|
|
Page page = new Page(pageNo, pageSize); |
|
|
|
|
|
|
|
// 3.如果不满一页,则填充分数为0的
|
|
|
|
if (pageSize > groupIds.size()) { |
|
|
|
// 查出网格下已有积分的小组id
|
|
|
|
LambdaQueryWrapper<BizPointTotalDetailEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, gridId); |
|
|
|
query.eq(BizPointTotalDetailEntity::getBizType, "group"); |
|
|
|
query.select(BizPointTotalDetailEntity::getObjectId); |
|
|
|
List<String> existingGroupIds = baseDao.selectObjs(query).stream().map(obj -> obj.toString()).collect(Collectors.toList()); |
|
|
|
|
|
|
|
int startRow = page.getStartRow() - existingGroupIds.size(); |
|
|
|
// 不足0的从0开始
|
|
|
|
startRow = Math.max(startRow, 0); |
|
|
|
List<GroupPointRankingResultDTO> gap; |
|
|
|
gap = fillGroupPageGap(existingGroupIds, gridId, startRow, pageSize - groupList.size()); |
|
|
|
rankingInfoDTOs.addAll(gap); |
|
|
|
} |
|
|
|
|
|
|
|
// 4.排名填充
|
|
|
|
Integer ranking = page.getStartRow() + 1; |
|
|
|
for (GroupPointRankingResultDTO g : rankingInfoDTOs) { |
|
|
|
g.setRanking(String.valueOf(ranking)); |
|
|
|
ranking ++; |
|
|
|
} |
|
|
|
PageData<GroupPointRankingResultDTO> pageData = new PageData<>(rankingInfoDTOs, entityPageInfo.getTotal()); |
|
|
|
return pageData; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 获取分页缺口group ranking信息 |
|
|
|
* |
|
|
|
* @param startRow |
|
|
|
* @param rowCount |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.07 16:30:28 |
|
|
|
*/ |
|
|
|
private List<GroupPointRankingResultDTO> fillGroupPageGap(List<String> existingGroupIds,String searchScopeObjectId, Integer startRow, Integer rowCount) { |
|
|
|
GroupFormDTO form = new GroupFormDTO(); |
|
|
|
form.setExcludeGroupIds(existingGroupIds); |
|
|
|
form.setOrder(GroupFormDTO.OrderTypeEnum.DESC); |
|
|
|
form.setSort(GroupFormDTO.SortTypeEnum.CREATE_TIME); |
|
|
|
form.setStartRow(startRow); |
|
|
|
form.setRowCount(rowCount); |
|
|
|
form.setSearchScopeType(GroupFormDTO.SearchScopeTypeEnum.GRID); |
|
|
|
form.setSearchScopeObjectId(searchScopeObjectId); |
|
|
|
|
|
|
|
Result<List<GroupDetailResultDTO>> result = resiGroupOpenFeignClient.listGroupDetailsExcludeGroupIds(form); |
|
|
|
List<GroupDetailResultDTO> groups = getResultDataOrThrowsException(result, ServiceConstant.RESI_GROUP_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【小组排名】网格内排名:查询积分为0的小组列表失败"); |
|
|
|
if (CollectionUtils.isEmpty(groups)) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
return groups.stream().map(g -> { |
|
|
|
GroupPointRankingResultDTO dto = new GroupPointRankingResultDTO(); |
|
|
|
dto.setGroupType(g.getGroupType()); |
|
|
|
dto.setPoint("0"); |
|
|
|
dto.setGroupHeadPhoto(g.getGroupHeadPhoto()); |
|
|
|
dto.setGroupName(g.getGroupName()); |
|
|
|
dto.setGroupId(g.getGroupId()); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 将小组排名信息Entity转化为dto |
|
|
|
* |
|
|
|
* @param groupList |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.07 15:52:17 |
|
|
|
*/ |
|
|
|
private List<GroupPointRankingResultDTO> convertGroupRankingInfoEntity2DTOs(List<String> groupIds, List<BizPointTotalDetailEntity> groupList) { |
|
|
|
if (CollectionUtils.isEmpty(groupIds)) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询这些小组的基本信息
|
|
|
|
Result<List<GroupDetailResultDTO>> listResult = resiGroupOpenFeignClient.listGroupDetailsByGroupIds(groupIds); |
|
|
|
List<GroupDetailResultDTO> groupInfos = getResultDataOrThrowsException(listResult, ServiceConstant.RESI_GROUP_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【小组排行】批量查询小组信息出错"); |
|
|
|
|
|
|
|
// 将小组基本信息转化为map
|
|
|
|
HashMap<String, GroupDetailResultDTO> groupMap = new HashMap<>(); |
|
|
|
groupInfos.stream().forEach(g -> groupMap.put(g.getGroupId(), g)); |
|
|
|
|
|
|
|
// 将小组信息填充到排名列表中
|
|
|
|
List<GroupPointRankingResultDTO> rankingDTOs = groupList.stream().map(g -> { |
|
|
|
GroupDetailResultDTO groupInfo = groupMap.get(g.getObjectId()); |
|
|
|
GroupPointRankingResultDTO dto = new GroupPointRankingResultDTO(); |
|
|
|
dto.setGroupId(g.getObjectId()); |
|
|
|
dto.setGroupName(groupInfo.getGroupName()); |
|
|
|
dto.setGroupType(groupInfo.getGroupType()); |
|
|
|
dto.setPoint(g.getTotalPoint().toString()); |
|
|
|
dto.setGroupHeadPhoto(groupInfo.getGroupHeadPhoto()); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
return rankingDTOs; |
|
|
|
} |
|
|
|
} |