|
|
@ -17,31 +17,48 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
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.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.BizPointTotalDetailDao; |
|
|
|
import com.epmet.dto.BizPointTotalDetailDTO; |
|
|
|
import com.epmet.dto.CustomerGridDTO; |
|
|
|
import com.epmet.dto.form.CustomerGridFormDTO; |
|
|
|
import com.epmet.dto.form.GroupPointFormDTO; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
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; |
|
|
|
import com.epmet.resi.group.dto.group.ResiGroupDTO; |
|
|
|
import com.epmet.resi.group.enums.SearchScopeTypeEnum; |
|
|
|
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; |
|
|
|
import org.springframework.data.redis.core.HashOperations; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
@ -57,7 +74,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; |
|
|
@ -65,6 +82,10 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
private BizPointUserTotalDetailService bizPointUserTotalDetailService; |
|
|
|
@Autowired |
|
|
|
private UserPointActionLogService userPointActionLogService; |
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String, ?> redisTemplate; |
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<BizPointTotalDetailDTO> page(Map<String, Object> params) { |
|
|
@ -239,4 +260,166 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
return ConvertUtils.sourceToTarget(entity, BizPointTotalDetailDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<GroupPointRankingResultDTO> listGroupPointRandingInGridScope(SearchScopeTypeEnum searchScopeType, String searchScopeId, Integer pageNo, Integer pageSize) { |
|
|
|
|
|
|
|
// 1.查询有积分的小组得分排名
|
|
|
|
PageInfo<BizPointTotalDetailEntity> entityPageInfo = PageHelper.startPage(pageNo, pageSize).doSelectPageInfo(() -> { |
|
|
|
LambdaQueryWrapper<BizPointTotalDetailEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
if (SearchScopeTypeEnum.CUSTOMER == searchScopeType) { |
|
|
|
query.eq(BizPointTotalDetailEntity::getCustomerId, searchScopeId); |
|
|
|
} else if (SearchScopeTypeEnum.GRID == searchScopeType) { |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, searchScopeId); |
|
|
|
} |
|
|
|
query.eq(BizPointTotalDetailEntity::getBizType, "group"); |
|
|
|
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<>(); |
|
|
|
if (SearchScopeTypeEnum.CUSTOMER == searchScopeType) { |
|
|
|
query.eq(BizPointTotalDetailEntity::getCustomerId, searchScopeId); |
|
|
|
} else if (SearchScopeTypeEnum.GRID == searchScopeType) { |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, searchScopeId); |
|
|
|
} |
|
|
|
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, searchScopeType, searchScopeId, startRow, pageSize - groupList.size()); |
|
|
|
rankingInfoDTOs.addAll(gap); |
|
|
|
} |
|
|
|
|
|
|
|
// 4.排名填充
|
|
|
|
Integer ranking = page.getStartRow() + 1; |
|
|
|
for (GroupPointRankingResultDTO g : rankingInfoDTOs) { |
|
|
|
GridInfoCache gridInfo = getGridInfo(g.getGridId()); |
|
|
|
g.setRanking(String.valueOf(ranking)); |
|
|
|
g.setGridId(g.getGridId()); |
|
|
|
g.setGridNamePath(gridInfo.getGridNamePath()); |
|
|
|
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, SearchScopeTypeEnum searchScopeType, 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(searchScopeType); |
|
|
|
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()); |
|
|
|
dto.setGridId(g.getGridId()); |
|
|
|
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()); |
|
|
|
dto.setGridId(g.getGridId()); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
return rankingDTOs; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 查询网格信息 |
|
|
|
* |
|
|
|
* @param gridId |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.08 11:17:17 |
|
|
|
*/ |
|
|
|
public GridInfoCache getGridInfo(String gridId) { |
|
|
|
HashOperations<String, String, Object> ope = redisTemplate.opsForHash(); |
|
|
|
Map<String, Object> entries = ope.entries(RedisKeys.getGridInfoKey(gridId)); |
|
|
|
if (entries.size() != 0) { |
|
|
|
return BeanUtil.mapToBean(entries, GridInfoCache.class, true); |
|
|
|
} |
|
|
|
|
|
|
|
CustomerGridFormDTO form = new CustomerGridFormDTO(); |
|
|
|
form.setGridId(gridId); |
|
|
|
Result<CustomerGridDTO> result = govOrgOpenFeignClient.getCustomerGridByGridId(form); |
|
|
|
if (result == null || !result.success() || result.getData() == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
GridInfoCache cache = new GridInfoCache(); |
|
|
|
cache.setCustomerId(result.getData().getCustomerId()); |
|
|
|
cache.setGridId(result.getData().getId()); |
|
|
|
cache.setGridNamePath(result.getData().getGridName()); |
|
|
|
cache.setPid(result.getData().getPid()); |
|
|
|
cache.setPids(result.getData().getPids()); |
|
|
|
ope.putAll(RedisKeys.getGridInfoKey(gridId), BeanUtil.beanToMap(cache)); |
|
|
|
return cache; |
|
|
|
} |
|
|
|
} |