|  |  | @ -17,34 +17,27 @@ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 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.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | 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.UserPointTotalDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.UserPointTotalDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.CommonUserFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.ResiCommonUserIdFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.ResiPointRankFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.UserPointTotalEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.UserPointTotalService; | 
			
		
	
		
			
				
					|  |  |  | 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.apache.ibatis.annotations.Param; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | import java.util.function.Function; | 
			
		
	
		
			
				
					|  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | /** | 
			
		
	
	
		
			
				
					|  |  | @ -57,62 +50,9 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  | public class UserPointTotalServiceImpl extends BaseServiceImpl<UserPointTotalDao, UserPointTotalEntity> implements UserPointTotalService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<UserPointTotalDTO> page(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         IPage<UserPointTotalEntity> page = baseDao.selectPage( | 
			
		
	
		
			
				
					|  |  |  |                 getPage(params, FieldConstant.CREATED_TIME, false), | 
			
		
	
		
			
				
					|  |  |  |                 getWrapper(params) | 
			
		
	
		
			
				
					|  |  |  |         ); | 
			
		
	
		
			
				
					|  |  |  |         return getPageData(page, UserPointTotalDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public List<UserPointTotalDTO> list(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         List<UserPointTotalEntity> entityList = baseDao.selectList(getWrapper(params)); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return ConvertUtils.sourceToTarget(entityList, UserPointTotalDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     private QueryWrapper<UserPointTotalEntity> getWrapper(Map<String, Object> params){ | 
			
		
	
		
			
				
					|  |  |  |         String id = (String)params.get(FieldConstant.ID_HUMP); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         QueryWrapper<UserPointTotalEntity> wrapper = new QueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |         wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return wrapper; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public UserPointTotalDTO get(String id) { | 
			
		
	
		
			
				
					|  |  |  |         UserPointTotalEntity entity = baseDao.selectById(id); | 
			
		
	
		
			
				
					|  |  |  |         return ConvertUtils.sourceToTarget(entity, UserPointTotalDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void save(UserPointTotalDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         UserPointTotalEntity entity = ConvertUtils.sourceToTarget(dto, UserPointTotalEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         insert(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void update(UserPointTotalDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         UserPointTotalEntity entity = ConvertUtils.sourceToTarget(dto, UserPointTotalEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         updateById(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void delete(String[] ids) { | 
			
		
	
		
			
				
					|  |  |  |         // 逻辑删除(@TableLogic 注解)
 | 
			
		
	
		
			
				
					|  |  |  |         baseDao.deleteBatchIds(Arrays.asList(ids)); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description 获取指定居民的积分信息 | 
			
		
	
		
			
				
					|  |  |  |      * @param param | 
			
		
	
	
		
			
				
					|  |  | @ -145,8 +85,7 @@ public class UserPointTotalServiceImpl extends BaseServiceImpl<UserPointTotalDao | 
			
		
	
		
			
				
					|  |  |  |         //1.获取当前用户昵称以及当前用户所属客户Id
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> userIdParam = new LinkedList<>(); | 
			
		
	
		
			
				
					|  |  |  |         userIdParam.add(pointRankFormDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         Result<List<UserBaseInfoResultDTO>> myResiInfoResult = | 
			
		
	
		
			
				
					|  |  |  |                 epmetUserOpenFeignClient.queryUserBaseInfo(userIdParam); | 
			
		
	
		
			
				
					|  |  |  |         Result<List<UserBaseInfoResultDTO>> myResiInfoResult = epmetUserOpenFeignClient.queryUserBaseInfo(userIdParam); | 
			
		
	
		
			
				
					|  |  |  |         if(myResiInfoResult.success() && null != myResiInfoResult.getData() && !myResiInfoResult.getData().isEmpty()){ | 
			
		
	
		
			
				
					|  |  |  |             if(StringUtils.isBlank(pointRankFormDTO.getCustomerId())) { | 
			
		
	
		
			
				
					|  |  |  |                 //缓存中的customerId是不准确的,前端一定会传customerId,所以不会执行此代码
 | 
			
		
	
	
		
			
				
					|  |  | @ -204,19 +143,23 @@ public class UserPointTotalServiceImpl extends BaseServiceImpl<UserPointTotalDao | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> userIds = rankList.stream().map(ResiPointRankResultDTO::getUserId).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |         //查询用户昵称
 | 
			
		
	
		
			
				
					|  |  |  |         Result<List<UserBaseInfoResultDTO>> userInfo = | 
			
		
	
		
			
				
					|  |  |  |                 epmetUserOpenFeignClient.queryUserBaseInfo(userIds); | 
			
		
	
		
			
				
					|  |  |  |         boolean userRequestCallback = userInfo.success() && null != userInfo.getData() && !userInfo.getData().isEmpty(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         for (int i = NumConstant.ZERO; i < rankList.size(); i++) { | 
			
		
	
		
			
				
					|  |  |  |             ResiPointRankListResultDTO resultObj = ConvertUtils.sourceToTarget(o,ResiPointRankListResultDTO.class); | 
			
		
	
		
			
				
					|  |  |  |         Result<List<UserBaseInfoResultDTO>> userInfo = epmetUserOpenFeignClient.queryUserBaseInfo(userIds); | 
			
		
	
		
			
				
					|  |  |  |         Map<String,UserBaseInfoResultDTO> userInfoMap = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         if (userInfo.success() && CollectionUtils.isNotEmpty(userInfo.getData())){ | 
			
		
	
		
			
				
					|  |  |  |             userInfoMap = userInfo.getData().stream().collect(Collectors.toMap(UserBaseInfoResultDTO::getUserId, Function.identity(),(o1, o2)->o1)); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         for (ResiPointRankResultDTO resiPointRankResultDTO : rankList) { | 
			
		
	
		
			
				
					|  |  |  |             ResiPointRankListResultDTO resultObj = ConvertUtils.sourceToTarget(o, ResiPointRankListResultDTO.class); | 
			
		
	
		
			
				
					|  |  |  |             ResiPointRankingResultDTO target = new ResiPointRankingResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |             target.setRanking(rankList.get(i).getRank()); | 
			
		
	
		
			
				
					|  |  |  |             target.setPoint(rankList.get(i).getTotalPoint()); | 
			
		
	
		
			
				
					|  |  |  |             if(userRequestCallback) { | 
			
		
	
		
			
				
					|  |  |  |                 target.setNickname(null == userInfo.getData().get(i) ? "" : userInfo.getData().get(i).getNickname()); | 
			
		
	
		
			
				
					|  |  |  |                 target.setHeadImgUrl(null == userInfo.getData().get(i) ? "" : userInfo.getData().get(i).getHeadImgUrl()); | 
			
		
	
		
			
				
					|  |  |  |             target.setRanking(resiPointRankResultDTO.getRank()); | 
			
		
	
		
			
				
					|  |  |  |             target.setPoint(resiPointRankResultDTO.getTotalPoint()); | 
			
		
	
		
			
				
					|  |  |  |             target.setNickname(StrConstant.EPMETY_STR); | 
			
		
	
		
			
				
					|  |  |  |             target.setHeadImgUrl(StrConstant.EPMETY_STR); | 
			
		
	
		
			
				
					|  |  |  |             UserBaseInfoResultDTO infoResultDTO = userInfoMap.get(resiPointRankResultDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             if (infoResultDTO != null) { | 
			
		
	
		
			
				
					|  |  |  |                 target.setNickname(infoResultDTO.getNickname()); | 
			
		
	
		
			
				
					|  |  |  |                 target.setHeadImgUrl(infoResultDTO.getHeadImgUrl()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             resultObj.setRankList(target); | 
			
		
	
		
			
				
					|  |  |  |             result.add(resultObj); | 
			
		
	
	
		
			
				
					|  |  | @ -234,21 +177,6 @@ public class UserPointTotalServiceImpl extends BaseServiceImpl<UserPointTotalDao | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void insertOrUpdate(UserPointTotalEntity entity) { | 
			
		
	
		
			
				
					|  |  |  |         baseDao.insertOrUpdate(entity); | 
			
		
	
		
			
				
					|  |  |  |         /* | 
			
		
	
		
			
				
					|  |  |  |         UserPointTotalEntity existed = baseDao.selectIfExisted(entity.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if(null != existed && StringUtils.isNotBlank(existed.getId())){ | 
			
		
	
		
			
				
					|  |  |  |             existed.setUsedPoint(null == existed.getUsedPoint() ? entity.getUsedPoint() : entity.getUsedPoint() + existed.getUsedPoint()); | 
			
		
	
		
			
				
					|  |  |  |             existed.setUsablePoint(null == existed.getUsablePoint() ? entity.getUsablePoint() : entity.getUsablePoint() + existed.getUsablePoint()); | 
			
		
	
		
			
				
					|  |  |  |             existed.setTotalPoint(null == existed.getTotalPoint() ? entity.getTotalPoint() : entity.getTotalPoint() + existed.getTotalPoint()); | 
			
		
	
		
			
				
					|  |  |  |             updateById(existed); | 
			
		
	
		
			
				
					|  |  |  |         }else{ | 
			
		
	
		
			
				
					|  |  |  |             insert(entity); | 
			
		
	
		
			
				
					|  |  |  |         }*/ | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void testInsertOrUpdate(UserPointTotalEntity entity) { | 
			
		
	
		
			
				
					|  |  |  |         baseDao.insertOrUpdate(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -267,4 +195,4 @@ public class UserPointTotalServiceImpl extends BaseServiceImpl<UserPointTotalDao | 
			
		
	
		
			
				
					|  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |