CeDo
2021-04-22 be2d7ec232fbd22b5e46ec133485ea751520636d
Merge remote-tracking branch 'origin/master'
1个文件已添加
1个文件已修改
74 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DifferentLongListUtil.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DifferentLongListUtil.java
New file
@@ -0,0 +1,50 @@
package com.panzhihua.common.utlis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Author: llming
 * @Description: 获取不同两个list不同元素
 */
public class DifferentLongListUtil {
    public static List<Long> getDiffrent(List<Long> list1, List<Long> list2) {
        Map<Long, Integer> map = new HashMap<Long, Integer>(list1.size() + list2.size());
        List<Long> diff = new ArrayList<Long>();
        List<Long> maxList = list1;
        List<Long> minList = list2;
        if (list2.size() > list1.size()) {
            maxList = list2;
            minList = list1;
        }
        for (Long Long : maxList) {
            map.put(Long, 1);
        }
        for (Long Long : minList) {
            Integer cc = map.get(Long);
            if (cc != null) {
                map.put(Long, ++cc);
                continue;
            }
            map.put(Long, 1);
        }
        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            if (entry.getValue() == 1) {
                diff.add(entry.getKey());
            }
        }
        return diff;
    }
    public static void main(Long[] args) {
//        List<Long> Longs1 = Arrays.asList(1L, 2L, 2L, 3L, 4L);
//        List<Long> Longs2 = Arrays.asList(1L, 2L, 5L, 6L, 4L);
//        List<Long> diffrent = getDiffrent(Longs1, Longs2);
//        System.out.println(diffrent);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java
@@ -13,6 +13,7 @@
import com.panzhihua.common.model.vos.shop.AddShopGoodsAttrVO;
import com.panzhihua.common.model.vos.shop.PageShopGoodsVO;
import com.panzhihua.common.model.vos.shop.AddShopGoodsVO;
import com.panzhihua.common.utlis.DifferentLongListUtil;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
import com.panzhihua.common.model.vos.shop.ComShopGoodsAttrVO;
@@ -31,6 +32,7 @@
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @auther lyq
@@ -132,12 +134,8 @@
        if (update < 1) {
            throw new ServiceException("修改失败");
        }
        addShopGoodsVO.getGoodsAttrVOList().forEach(goodsAttr -> {
            ComShopGoodsAttrDO comShopGoodsAttrDO = shopGoodsAttrDAO.selectById(goodsAttr.getGoodsAttrId());
            comShopGoodsAttrDO.setPrice(goodsAttr.getAttrPrice());
            comShopGoodsAttrDO.setGoodsAttr(goodsAttr.getGoodsAttr());
            shopGoodsAttrDAO.updateById(comShopGoodsAttrDO);
        });
        //修改规格表
        List<ComShopGoodsAttrDO> comShopGoodsAttrDOS = shopGoodsAttrDAO.selectList(new LambdaQueryWrapper<ComShopGoodsAttrDO>().eq(ComShopGoodsAttrDO::getGoodsId, id));
        if (addShopGoodsVO.getGoodsAttrVOList().size() == 0) {
            shopGoodsAttrDAO.delete(new LambdaQueryWrapper<ComShopGoodsAttrDO>().eq(ComShopGoodsAttrDO::getGoodsId, id));
            ComShopGoodsAttrDO comShopGoodsAttrDO = new ComShopGoodsAttrDO();
@@ -149,6 +147,20 @@
            comShopGoodsAttrDO.setIsDefault(1);
            comShopGoodsAttrDO.setPrice(addShopGoodsVO.getPrice());
            shopGoodsAttrDAO.insert(comShopGoodsAttrDO);
        }else{
            List<Long> attrIds = comShopGoodsAttrDOS.stream().map(ComShopGoodsAttrDO::getId).collect(Collectors.toList());
            List<Long> voAttrIds = addShopGoodsVO.getGoodsAttrVOList().stream().map(AddShopGoodsAttrVO::getGoodsAttrId).collect(Collectors.toList());
            //需要删除的规格ID——针对编辑时删除了规格的情况
            List<Long> deleteIds = DifferentLongListUtil.getDiffrent(attrIds, voAttrIds);
            if(deleteIds.size()!=0){
                shopGoodsAttrDAO.deleteBatchIds(deleteIds);
            }
            addShopGoodsVO.getGoodsAttrVOList().forEach(goodsAttr -> {
                ComShopGoodsAttrDO comShopGoodsAttrDO = shopGoodsAttrDAO.selectById(goodsAttr.getGoodsAttrId());
                comShopGoodsAttrDO.setPrice(goodsAttr.getAttrPrice());
                comShopGoodsAttrDO.setGoodsAttr(goodsAttr.getGoodsAttr());
                shopGoodsAttrDAO.updateById(comShopGoodsAttrDO);
            });
        }
        return R.ok();
    }