|
|
@ -25,11 +25,14 @@ import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.UserPointStatisticalDailyDao; |
|
|
|
import com.epmet.dto.BizPointUserTotalDetailDTO; |
|
|
|
import com.epmet.dto.UserPointStatisticalDailyDTO; |
|
|
|
import com.epmet.dto.form.AllPartyFormDTO; |
|
|
|
import com.epmet.dto.form.GroupPointFormDTO; |
|
|
|
import com.epmet.dto.form.ResiAroundPartyPointRankFormDTO; |
|
|
|
import com.epmet.dto.form.ResiPointRankFormDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
@ -43,13 +46,14 @@ import com.epmet.utils.DimIdGenerator; |
|
|
|
import com.epmet.utils.ModuleConstant; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -326,6 +330,64 @@ public class UserPointStatisticalDailyServiceImpl extends BaseServiceImpl<UserPo |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param tokenDto |
|
|
|
* @param formDTO |
|
|
|
* @Description 个人当月积分在网格和客户中的排名 |
|
|
|
* @Param tokenDto |
|
|
|
* @Param formDTO |
|
|
|
* @Return {@link MyPointRankResultDTO} |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2021/9/10 14:18 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public MyPointRankResultDTO myPointRank(TokenDto tokenDto, GroupPointFormDTO formDTO) { |
|
|
|
List<String> userIds = new ArrayList<>(); |
|
|
|
userIds.add(tokenDto.getUserId()); |
|
|
|
//获取我的个人信息
|
|
|
|
Result<List<UserBaseInfoResultDTO>> myInfoResult = epmetUserOpenFeignClient.queryUserBaseInfo(userIds); |
|
|
|
if(!myInfoResult.success()){ |
|
|
|
throw new RenException(myInfoResult.getCode(), myInfoResult.getMsg()); |
|
|
|
} |
|
|
|
MyPointRankResultDTO result = new MyPointRankResultDTO(); |
|
|
|
result.setHeadPhoto(myInfoResult.getData().get(0).getHeadImgUrl()); |
|
|
|
//获取客户下用户积分
|
|
|
|
List<BizPointUserTotalDetailDTO> list = getUserPointList(tokenDto.getCustomerId(), null, null); |
|
|
|
result.setCustomerRank(getRank(list, tokenDto.getUserId())); |
|
|
|
//获取网格用户积分
|
|
|
|
List<BizPointUserTotalDetailDTO> gridRankList = getUserPointList(tokenDto.getCustomerId(), null, formDTO.getGridId()); |
|
|
|
result.setCustomerRank(getRank(gridRankList, tokenDto.getUserId())); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param tokenDto |
|
|
|
* @param formDTO |
|
|
|
* @Description 网格当月积分在组织和客户内排名 |
|
|
|
* @Param tokenDto |
|
|
|
* @Param formDTO |
|
|
|
* @Return {@link GridPointRankResultDTO} |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2021/9/10 14:18 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public GridPointRankResultDTO gridPointRank(TokenDto tokenDto, GroupPointFormDTO formDTO) { |
|
|
|
GridPointRankResultDTO result = new GridPointRankResultDTO(); |
|
|
|
//获取网格信息
|
|
|
|
Result<GridInfoResultDTO> gridInfoResult = govOrgOpenFeignClient.queryGridInfo(formDTO.getGridId()); |
|
|
|
if (!gridInfoResult.success()) { |
|
|
|
throw new RenException(gridInfoResult.getCode()); |
|
|
|
} |
|
|
|
result.setGridName(gridInfoResult.getData().getGridName()); |
|
|
|
String agencyId = gridInfoResult.getData().getParentAgencyId(); |
|
|
|
//获取客户下用户积分
|
|
|
|
List<BizPointUserTotalDetailDTO> list = getGridPointList(tokenDto.getCustomerId(), null); |
|
|
|
result.setCustomerRank(getGridRank(list, formDTO.getGridId())); |
|
|
|
List<BizPointUserTotalDetailDTO> agencyPointList = getGridPointList(tokenDto.getCustomerId(), agencyId); |
|
|
|
result.setAgencyRank(getGridRank(agencyPointList, formDTO.getGridId())); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取认证通过的党员的 用户id |
|
|
|
* |
|
|
@ -372,4 +434,84 @@ public class UserPointStatisticalDailyServiceImpl extends BaseServiceImpl<UserPo |
|
|
|
} |
|
|
|
return rankResultDTOS; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取客户下用户的当月积分 |
|
|
|
* |
|
|
|
* @Param customerId |
|
|
|
* @Return {@link List<BizPointUserTotalDetailDTO>} |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2021/9/10 15:04 |
|
|
|
*/ |
|
|
|
private List<BizPointUserTotalDetailDTO> getUserPointList(String customerId, String agencyId, String gridId) { |
|
|
|
return baseDao.selectUserPointByMonth(customerId, agencyId, gridId); |
|
|
|
} |
|
|
|
|
|
|
|
private List<BizPointUserTotalDetailDTO> getGridPointList(String customerId, String agencyId) { |
|
|
|
return baseDao.selectGridPointByMonth(customerId, agencyId); |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean havePoint(List<BizPointUserTotalDetailDTO> list, String userId) { |
|
|
|
Map<String, Integer> map = list.stream().collect(Collectors.toMap(BizPointUserTotalDetailDTO::getUserId, BizPointUserTotalDetailDTO::getTotalPoint)); |
|
|
|
return null != map.get(userId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getGridRank(List<BizPointUserTotalDetailDTO> list, String gridId) { |
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
return NumConstant.ONE_STR; |
|
|
|
} |
|
|
|
//如果当月网格没有积分变动,则积分为0
|
|
|
|
Map<String, Integer> map = list.stream().collect(Collectors.toMap(BizPointUserTotalDetailDTO::getGridId, BizPointUserTotalDetailDTO::getTotalPoint)); |
|
|
|
if (null == map.get(gridId)) { |
|
|
|
BizPointUserTotalDetailDTO dto = new BizPointUserTotalDetailDTO(); |
|
|
|
dto.setGridId(gridId); |
|
|
|
dto.setTotalPoint(NumConstant.ZERO); |
|
|
|
list.add(dto); |
|
|
|
} |
|
|
|
//排序
|
|
|
|
list = list.stream().sorted(Comparator.comparing(BizPointUserTotalDetailDTO :: getTotalPoint).reversed() |
|
|
|
.thenComparing(BizPointUserTotalDetailDTO::getGridId)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
AtomicInteger i = new AtomicInteger(1); |
|
|
|
AtomicInteger point = new AtomicInteger(0); |
|
|
|
list.forEach(item -> { |
|
|
|
if (item.getTotalPoint().equals(point.get())) { |
|
|
|
item.setRank(String.valueOf(i)); |
|
|
|
} else { |
|
|
|
item.setRank(String.valueOf(i.getAndIncrement())); |
|
|
|
} |
|
|
|
point.set(item.getTotalPoint()); |
|
|
|
}); |
|
|
|
Map<String, String> rankMap = list.stream().collect(Collectors.toMap(BizPointUserTotalDetailDTO::getGridId, BizPointUserTotalDetailDTO::getRank)); |
|
|
|
return rankMap.get(gridId); |
|
|
|
} |
|
|
|
|
|
|
|
private String getRank(List<BizPointUserTotalDetailDTO> list, String userId) { |
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
return NumConstant.ONE_STR; |
|
|
|
} |
|
|
|
if (!havePoint(list, userId)) { |
|
|
|
BizPointUserTotalDetailDTO dto = new BizPointUserTotalDetailDTO(); |
|
|
|
dto.setUserId(userId); |
|
|
|
dto.setTotalPoint(NumConstant.ZERO); |
|
|
|
list.add(dto); |
|
|
|
} |
|
|
|
//排序
|
|
|
|
list = list.stream().sorted(Comparator.comparing(BizPointUserTotalDetailDTO :: getTotalPoint).reversed() |
|
|
|
.thenComparing(BizPointUserTotalDetailDTO::getUserId)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
AtomicInteger i = new AtomicInteger(1); |
|
|
|
AtomicInteger point = new AtomicInteger(0); |
|
|
|
list.forEach(item -> { |
|
|
|
if (item.getTotalPoint().equals(point.get())) { |
|
|
|
item.setRank(String.valueOf(i)); |
|
|
|
} else { |
|
|
|
item.setRank(String.valueOf(i.getAndIncrement())); |
|
|
|
} |
|
|
|
point.set(item.getTotalPoint()); |
|
|
|
}); |
|
|
|
Map<String, String> map = list.stream().collect(Collectors.toMap(BizPointUserTotalDetailDTO::getUserId, BizPointUserTotalDetailDTO::getRank)); |
|
|
|
return map.get(userId); |
|
|
|
} |
|
|
|
} |
|
|
|