加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

个人代码,自创循环套循环后输出Map数据结构的写法

发布时间:2020-12-15 04:50:22 所属栏目:百科 来源:网络整理
导读:@Override public HttpCommandResultWithData getSalesDataByUsersAndTransId(SalesQueryLogDataByUserCommand command) { HttpCommandResultWithData result = new HttpCommandResultWithData().fillResult(ReturnCode.OK); // 入参校验 List userIds = com

@Override

public HttpCommandResultWithData getSalesDataByUsersAndTransId(SalesQueryLogDataByUserCommand command) {

HttpCommandResultWithData result = new HttpCommandResultWithData().fillResult(ReturnCode.OK);

// 入参校验

List userIds = command.getUserIds();

if (CollectionUtils.isEmpty(userIds)) {

throw new SellAppCustomFailException(ErrorMsgEnum.SELL_APP_SERVICE_PARAMS_ERROR_USERS_NOT_FIND);

}

List transIds = command.getTransIds();

if (CollectionUtils.isEmpty(transIds)) {

throw new SellAppCustomFailException(ErrorMsgEnum.SELL_APP_SERVICE_PARAMS_ERROR_TRANS_ID_NOT_FIND);

}

// 获取redis数据方法

Function> getDataByRedis = userId -> {

Map beanMap = new HashMap<>();

transIds.forEach(transId -> {

String jsonLogArrays = Optional.ofNullable(

(String) redisTemplate.opsForHash().get(RedisStaticConst.QINGQI_LOG_REDIS_KEY_PREX + transId,userId))

.orElseGet(String::new);

List list = new ArrayList();

try {

list = JsonUtil.toList(jsonLogArrays,RedisLogSimplePojo.class);

} catch (IOException e) {

logger.warn("=== getSalesDataByUsers 查询云端redis数据 云端redis hkey : {} key: {} 转换json数组异常",RedisStaticConst.QINGQI_LOG_REDIS_KEY_PREX + transId,userId);

}

beanMap.put(transId,String.valueOf(list.size()));

});

return beanMap;

};

// 返回结果

AtomicInteger index = new AtomicInteger();

Map> retMap =

userIds.stream().collect(Collectors.toMap(key -> {

String userId = userIds.get(index.get());

index.incrementAndGet();

return userId;

},getDataByRedis));

result.setData(retMap);

return result;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读