Map<String, List<Integer>> appNameUserMap = new HashMap<>();
//批量插入 (k,v)
appNameUserMap.forEach((group, userIds) -> this.save(group, userIds, appStartData, finalBegin));
//对list集合对象遍历放入list属性集合
List<BlackList> blacklist = list(queryWrapper);
if (!blacklist.isEmpty()) {
List<Integer> blackIdList;
if (isAnchor) {
blackIdList = blacklist.stream().map(BlackList::getUserId).collect(Collectors.toList());
//对list集合遍历放入set集合中
List<BlackList> blacklist = list(queryWrapper);
Set<Integer> blackIdList;
if (isAnchor) {
blackIdList = blacklist.stream().map(BlackList::getUserId).collect(Collectors.toSet());
//新老支付用户去重 分组
payUserIds.addAll(newUserIds);
List<Integer> collect = payUserIds.stream().distinct().collect(Collectors.toList());
appStartRecordList.forEach(appStartRecord -> {
if (v.contains(appStartRecord.getUserId())) {
//map集合遍历,判断k相等
billsMap.forEach((k, v) -> {
if (k.equals(brand)) {
//去重
List<User> distinctUsers = users.stream()
.filter(distinctByKey(User::getName))
.collect(Collectors.toList());
打印日志
CsLog.info("homeWallet, e: {}", ExceptionUtils.getStackTrace(e));
list集合转set集合并去重
List<OrderGoods> orderGoodsLists = super.list(queryWrapper);
List<GiftStatic> result = new ArrayList<>(orderGoodsLists.size());
if (CollectionUtils.isNotEmpty(orderGoodsLists)) {
LinkedHashSet<Integer> goodsIdSet = orderGoodsLists.stream().map(OrderGoods::getGoodsId)
.collect(Collectors.toCollection(LinkedHashSet::new));
Map<Integer, GiftStatic> giftStaticMap = new LinkedHashMap<>(goodsIdSet.size());
List<Goods> goodList = goodsService.getGoodListByIds(new ArrayList<>(goodsIdSet));
查询结果true或者false 用三元表达式最后判断
blackListNewService.isMyBlacklist(currentUserId,userParam.getUserId()) ? DBValue.PUBLIC_TYPE_ONE : DBValue.PUBLIC_TYPE_ZERO
public Integer getAnchorRecentCallTime(Integer anchorId) {
Object o = redisDao.hGet(ListCacheConstant.ANCHOR_LIST_SCORE, anchorId.toString());
int totalTime;
if (o == null) {
totalTime = 0;
} else {
List<Integer> callTimes = JSONObject.parseArray(o.toString(), Integer.class);
totalTime = callTimes.stream().mapToInt(Integer::intValue).sum();
}
return totalTime;
}
//对hashMap集合进行移除操作
topListAnchors.keySet().removeIf(anchorId -> !userStatusService.ifAnchorFree(anchorId));
//拿出按分数排序的指定区间的成员
Set<ZSetOperations.TypedTuple<Object>> anchorSet = redisDao.zReverseRangeWithScore(ListCacheConstant.ANCHOR_LIST_POPULAR, pageStart, pageEnd);
if (CollectionUtils.isNotEmpty(anchorSet)) {
Map<Integer, Integer> anchorStateMap = new LinkedHashMap<>(anchorSet.size());
List<Integer> anchorIds = new LinkedList<>();
for (ZSetOperations.TypedTuple<Object> typedTuple : anchorSet) {
Object value = typedTuple.getValue();
Double score = typedTuple.getScore();
if (value == null || score == null) {
continue;
}
Integer anchorId = Integer.valueOf(value.toString());
集合之间互相转换
JSONArray.parseArray(list.toString(),Long.class)
加事务
@Transactional(rollbackFor = Exception.class)
将大list集合分为几段小的list集合
// 业务拆分部分代码
// 1.假设从数据库查询的记录为orders
List<Order> orders = new ArrayList<>();
// 2.使用Lists进行拆分,拆分为每个10个Order(这里的10表示,拆分完每个‘内’List的个数,最后一个内集合个数可能不为10)
List<List<Order>> partition = Lists.partition(orders, 10);
// 3.对拆分完的集合进行遍历
for (List<Order> order : partition) {
// 4. 其他业务逻辑
}
//所有所有的key
Set<String> listKeys = redisDao.keysByPattern(ListCacheConstant.ANCHOR_LIST_AREA_RECOMMEND + "*");
当集合为空直接返回
Collections.emptyMap()
grep 20002138 mpsp.log | grep bindAccount
# 立即启动一个服务
$ sudo systemctl start apache.service
# 立即停止一个服务
$ sudo systemctl stop apache.service
# 重启一个服务
$ sudo systemctl restart apache.service
开发环境nacos 启动命令
./startup.sh -m standalone
//启动失败查看日志命令
journalctl -f -u video-api-v2
sudo systemctl restart job-admin.service
查询redis中:zset 的值 zrevrange anchorList:popular 0 -1 WITHSCORES
map集合遍历
Map<String, String> map = new HashMap<String, String>();
map.put("1", "value1");
map.put("2", "value2");
map.put("3", "value3");
//第一种:普遍使用,二次取值
System.out.println("通过Map.keySet遍历key和value:");
for (String key : map.keySet()) {
System.out.println("key= "+ key + " and value= " + map.get(key));
}
//第二种
System.out.println("通过Map.entrySet使用iterator遍历key和value:");
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
//第三种:推荐,尤其是容量大时
System.out.println("通过Map.entrySet遍历key和value");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
//第四种
System.out.println("通过Map.values()遍历所有的value,但不能遍历key");
for (String v : map.values()) {
System.out.println("value= " + v);
}
}
1、指定key-value,value是对象中的某个属性值。
Map<Integer,String> userMap1 = userList.stream().collect(Collectors.toMap(User::getId,User::getName));
2、指定key-value,value是对象本身,User->User 是一个返回本身的lambda表达式
Map<Integer,User> userMap2 = userList.stream().collect(Collectors.toMap(User::getId,User->User));
3、指定key-value,value是对象本身,Function.identity()是简洁写法,也是返回对象本身
Map<Integer,User> userMap3 = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
4、指定key-value,value是对象本身,Function.identity()是简洁写法,也是返回对象本身,key 冲突的解决办法,这里选择第二个key覆盖第一个key。
Map<Integer,User> userMap4 = userList.stream().collect(Collectors.toMap(User::getId, Function.identity(),(key1,key2)->key2));
redis中hash结构
Map<Integer, Integer> result = list.stream().collect(Collectors.toMap(Intimacy::getUserId, t -> Float.valueOf(t.getValue()).intValue()));
for (Map.Entry<Integer, Integer> entry : result.entrySet()) {
redisDao.hPut(key, entry.getKey().toString(), entry.getValue());
}
redisDao.expire(key, RedisCacheEnum.INTIMACY.getExpireTime());
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项 只能是string
* @param value 值
* @return true 成功 false失败
*/
public boolean hPut(String key, String item, Object value) {
try {
redisTemplate.opsForHash().put(key, item, value);
return true;
} catch (Exception e) {
CsLog.dingAtTechnicalGroup("redis hPut 异常! key: {}, item: {}, error: {}", key, item, e.getMessage());
return false;
}
}
public Map<String, Object> hGetAll(String key) {
try {
HashOperations<String, String, Object> hashOperations = redisTemplate.opsForHash();
return hashOperations.entries(key);
} catch (Exception e) {
CsLog.error("redis hGetAll 操作异常,key: {}, e:{}", key, ExceptionUtils.getStackTrace(e));
}
return null;
}