优化商品股东分红批量更新业务
This commit is contained in:
@@ -2,6 +2,7 @@ package com.gxwebsoft.shop.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||||
import com.gxwebsoft.common.core.exception.enums.GlobalErrorCodeConstants;
|
import com.gxwebsoft.common.core.exception.enums.GlobalErrorCodeConstants;
|
||||||
@@ -25,6 +26,7 @@ import java.math.BigDecimal;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,10 +54,8 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMappe
|
|||||||
List<ShopDealerUser> shopDealerUserList = shopDealerUserMapper.selectList(new LambdaQueryWrapper<ShopDealerUser>().in(ShopDealerUser::getUserId, userIdList));
|
List<ShopDealerUser> shopDealerUserList = shopDealerUserMapper.selectList(new LambdaQueryWrapper<ShopDealerUser>().in(ShopDealerUser::getUserId, userIdList));
|
||||||
List<ShopGoodsProfitVO> shopGoodsProfitVOS = BeanUtil.copyToList(list, ShopGoodsProfitVO.class);
|
List<ShopGoodsProfitVO> shopGoodsProfitVOS = BeanUtil.copyToList(list, ShopGoodsProfitVO.class);
|
||||||
for(ShopGoodsProfitVO shopGoodsProfitVO : shopGoodsProfitVOS){
|
for(ShopGoodsProfitVO shopGoodsProfitVO : shopGoodsProfitVOS){
|
||||||
ShopDealerUser dealerUser = shopDealerUserList.stream().filter(shopDealerUser -> shopGoodsProfitVO.getUserId().equals(shopDealerUser.getUserId())).findFirst().orElse(null);
|
shopDealerUserList.stream().filter(shopDealerUser -> shopGoodsProfitVO.getUserId().equals(shopDealerUser.getUserId())).findFirst()
|
||||||
if(dealerUser != null){
|
.ifPresent(shopDealerUser -> shopGoodsProfitVO.setUserName(shopDealerUser.getRealName()));
|
||||||
shopGoodsProfitVO.setUserName(dealerUser.getRealName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return shopGoodsProfitVOS;
|
return shopGoodsProfitVOS;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,16 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMappe
|
|||||||
throw new BusinessException("股东分红比例总和不能超过100%");
|
throw new BusinessException("股东分红比例总和不能超过100%");
|
||||||
}
|
}
|
||||||
|
|
||||||
//2.查询商品原有分润数据并做超100%管控
|
//2.检查分润对象是否有重复
|
||||||
|
Map<Integer, List<ShopGoodsProfitUpdateItemDto>> 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());
|
ShopGoods shopGoods = shopGoodsMapper.selectById(entity.getGoodsId());
|
||||||
if(shopGoods == null){
|
if(shopGoods == null){
|
||||||
throw new BusinessException(GlobalErrorCodeConstants.NOT_FOUND.getMsg());
|
throw new BusinessException(GlobalErrorCodeConstants.NOT_FOUND.getMsg());
|
||||||
@@ -102,10 +111,10 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMappe
|
|||||||
throw new BusinessException("股东分红比例与商品原有分销比例加总不能超过100!");
|
throw new BusinessException("股东分红比例与商品原有分销比例加总不能超过100!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//3.查询有分润数据并删除
|
//4.查询有分润数据并删除
|
||||||
removeByGoodsId(entity.getGoodsId(), entity.getType(), loginUser.getUserId(), now);
|
removeByGoodsId(entity.getGoodsId(), entity.getType(), loginUser.getUserId(), now);
|
||||||
|
|
||||||
//4.批量新增分润数据
|
//5.批量新增分润数据
|
||||||
List<ShopGoodsProfit> shopGoodsProfits = BeanUtil.copyToList(itemList, ShopGoodsProfit.class);
|
List<ShopGoodsProfit> shopGoodsProfits = BeanUtil.copyToList(itemList, ShopGoodsProfit.class);
|
||||||
shopGoodsProfits.forEach(shopGoodsProfit -> {
|
shopGoodsProfits.forEach(shopGoodsProfit -> {
|
||||||
shopGoodsProfit.setType(entity.getType());
|
shopGoodsProfit.setType(entity.getType());
|
||||||
@@ -122,16 +131,9 @@ public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeByGoodsId(Integer goodsId, Integer type, Integer userId, LocalDateTime date){
|
private void removeByGoodsId(Integer goodsId, Integer type, Integer userId, LocalDateTime date){
|
||||||
List<ShopGoodsProfit> profitList = lambdaQuery().select(ShopGoodsProfit::getId).eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type).list();
|
LambdaUpdateWrapper<ShopGoodsProfit> updateWrapper = new LambdaUpdateWrapper<ShopGoodsProfit>().eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type)
|
||||||
if(CollectionUtils.isNotEmpty(profitList)){
|
.set(ShopGoodsProfit::getUpdater, userId).set(ShopGoodsProfit::getUpdateTime, date).set(ShopGoodsProfit::getDeleted, 1);
|
||||||
profitList.forEach(profit -> {
|
update(updateWrapper);
|
||||||
profit.setDeleted(1);
|
|
||||||
profit.setUpdater(userId);
|
|
||||||
profit.setUpdateTime(date);
|
|
||||||
});
|
|
||||||
updateBatchById(profitList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user