|
|
@ -17,6 +17,7 @@ |
|
|
|
|
|
|
|
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; |
|
|
@ -27,12 +28,17 @@ 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; |
|
|
@ -40,6 +46,7 @@ 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; |
|
|
@ -50,6 +57,8 @@ 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; |
|
|
|
|
|
|
@ -73,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) { |
|
|
@ -248,14 +261,17 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<GroupPointRankingResultDTO> listGroupPointRandingInGridScope(String gridId, Integer pageNo, Integer pageSize) { |
|
|
|
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<>(); |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, gridId); |
|
|
|
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.eq(BizPointTotalDetailEntity::getDelFlag, 0); #用mybatis plus不需要手动指定,框架会自动指定
|
|
|
|
query.orderByDesc(BizPointTotalDetailEntity::getTotalPoint); |
|
|
|
baseDao.selectList(query); |
|
|
|
}); |
|
|
@ -273,7 +289,11 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
if (pageSize > groupIds.size()) { |
|
|
|
// 查出网格下已有积分的小组id
|
|
|
|
LambdaQueryWrapper<BizPointTotalDetailEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(BizPointTotalDetailEntity::getGridId, gridId); |
|
|
|
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()); |
|
|
@ -282,14 +302,17 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
// 不足0的从0开始
|
|
|
|
startRow = Math.max(startRow, 0); |
|
|
|
List<GroupPointRankingResultDTO> gap; |
|
|
|
gap = fillGroupPageGap(existingGroupIds, gridId, startRow, pageSize - groupList.size()); |
|
|
|
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()); |
|
|
@ -305,18 +328,18 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
* @author wxz |
|
|
|
* @date 2021.09.07 16:30:28 |
|
|
|
*/ |
|
|
|
private List<GroupPointRankingResultDTO> fillGroupPageGap(List<String> existingGroupIds,String searchScopeObjectId, Integer startRow, Integer rowCount) { |
|
|
|
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(GroupFormDTO.SearchScopeTypeEnum.GRID); |
|
|
|
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的小组列表失败"); |
|
|
|
List<GroupDetailResultDTO> groups = getResultDataOrThrowsException(result, ServiceConstant.RESI_GROUP_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【小组排名】查询积分为0的小组列表失败"); |
|
|
|
if (CollectionUtils.isEmpty(groups)) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
@ -327,12 +350,13 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
dto.setGroupHeadPhoto(g.getGroupHeadPhoto()); |
|
|
|
dto.setGroupName(g.getGroupName()); |
|
|
|
dto.setGroupId(g.getGroupId()); |
|
|
|
dto.setGridId(g.getGridId()); |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 将小组排名信息Entity转化为dto |
|
|
|
* @description 将小组排名Entity转化为dto |
|
|
|
* |
|
|
|
* @param groupList |
|
|
|
* @return |
|
|
@ -361,8 +385,41 @@ public class BizPointTotalDetailServiceImpl extends BaseServiceImpl<BizPointTota |
|
|
|
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; |
|
|
|
} |
|
|
|
} |