diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/ShopGoodsProfitServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/ShopGoodsProfitServiceImpl.java index 4af3ae4..4f81a43 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/ShopGoodsProfitServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/ShopGoodsProfitServiceImpl.java @@ -2,6 +2,7 @@ package com.gxwebsoft.shop.service.impl; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.core.exception.enums.GlobalErrorCodeConstants; @@ -25,6 +26,7 @@ import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -52,10 +54,8 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl shopDealerUserList = shopDealerUserMapper.selectList(new LambdaQueryWrapper().in(ShopDealerUser::getUserId, userIdList)); List shopGoodsProfitVOS = BeanUtil.copyToList(list, ShopGoodsProfitVO.class); for(ShopGoodsProfitVO shopGoodsProfitVO : shopGoodsProfitVOS){ - ShopDealerUser dealerUser = shopDealerUserList.stream().filter(shopDealerUser -> shopGoodsProfitVO.getUserId().equals(shopDealerUser.getUserId())).findFirst().orElse(null); - if(dealerUser != null){ - shopGoodsProfitVO.setUserName(dealerUser.getRealName()); - } + shopDealerUserList.stream().filter(shopDealerUser -> shopGoodsProfitVO.getUserId().equals(shopDealerUser.getUserId())).findFirst() + .ifPresent(shopDealerUser -> shopGoodsProfitVO.setUserName(shopDealerUser.getRealName())); } return shopGoodsProfitVOS; } @@ -88,7 +88,16 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl> userMap = itemList.stream().collect(Collectors.groupingBy(ShopGoodsProfitUpdateItemDto::getUserId)).entrySet().stream() + .filter(entry -> entry.getValue().size() > 1).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + if(!userMap.isEmpty()){ + String userIds = String.join(",", userMap.keySet().stream().map(String::valueOf).toList()); + + throw new BusinessException("用户:【" + userIds + "】存在多条分红数据,请修改后重新提交!"); + } + + //3.查询商品原有分润数据并做超100%管控 ShopGoods shopGoods = shopGoodsMapper.selectById(entity.getGoodsId()); if(shopGoods == null){ throw new BusinessException(GlobalErrorCodeConstants.NOT_FOUND.getMsg()); @@ -102,10 +111,10 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl shopGoodsProfits = BeanUtil.copyToList(itemList, ShopGoodsProfit.class); shopGoodsProfits.forEach(shopGoodsProfit -> { shopGoodsProfit.setType(entity.getType()); @@ -122,16 +131,9 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl profitList = lambdaQuery().select(ShopGoodsProfit::getId).eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type).list(); - if(CollectionUtils.isNotEmpty(profitList)){ - profitList.forEach(profit -> { - profit.setDeleted(1); - profit.setUpdater(userId); - profit.setUpdateTime(date); - }); - updateBatchById(profitList); - } + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper().eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type) + .set(ShopGoodsProfit::getUpdater, userId).set(ShopGoodsProfit::getUpdateTime, date).set(ShopGoodsProfit::getDeleted, 1); + update(updateWrapper); } - }